Package DebTorrent :: Module BTcrypto :: Class Crypto
[hide private]
[frames] | no frames]

Class Crypto

source code

Instance Methods [hide private]
 
__init__(self, initiator, disable_crypto=True)
Initialize the instance.
source code
 
received_key(self, k)
Process a received key.
source code
 
_gen_block3b(self, SKEY) source code
boolean
test_skey(self, s, SKEY)
Check that the encoding matches the encoded value.
source code
 
set_skey(self, SKEY) source code
string
VC_pattern(self)
Unknown.
source code
 
read(self, s)
Decrypt and pass on the decrypted value.
source code
 
write(self, s)
Encrypt and pass on the encrypted value.
source code
 
setrawaccess(self, _read, _write)
Setup the methods to call for reading and writing.
source code
string
padding(self)
Generate a random amount of random padding.
source code
Instance Variables [hide private]
string S
the DH secret number, encoded as a byte array
string _VC_pattern
the encrypted verification constant to expect from the peer
method _read
the method to call to read decrypted data
method _write
the method to call to write encrypted data
string block3a
first encryption block
string block3b
seconf encryption block
string block3bkey
key used to generate the second encryption block
method decrypt
the method to call to decrypt data
boolean disable_crypto
whether crypto has been disabled
method encrypt
the method to call to encrypt data
boolean initiator
whether the connection was initiated locally
int keylength
the key length to use
long privkey
randomly generated private key
string pubkey
public key corresponding to the private key
Method Details [hide private]

__init__(self, initiator, disable_crypto=True)
(Constructor)

source code 
Initialize the instance.
Parameters:
  • initiator (boolean) - whether the connection was initiated locally
  • disable_crypto (boolean) - whether crypto has been disabled (optional, default is False)
Raises:
  • NotImplementedError - if encryption is not installed

received_key(self, k)

source code 
Process a received key.
Parameters:
  • k (string) - the key that was received

_gen_block3b(self, SKEY)

source code 
Parameters:
  • SKEY (string) - shared key (torrent info hash)

test_skey(self, s, SKEY)

source code 
Check that the encoding matches the encoded value.
Parameters:
  • s (string) - second received encryption block to verify
  • SKEY (string) - shared key (torrent info hash)
Returns: boolean
whether the encoding of SKEY matches s

set_skey(self, SKEY)

source code 
Parameters:
  • SKEY (string) - shared key (torrent info hash)

VC_pattern(self)

source code 
Unknown.
Returns: string
the encrypted verification constant to expect from the peer

read(self, s)

source code 
Decrypt and pass on the decrypted value.
Parameters:
  • s (string) - the string to decrypt

write(self, s)

source code 
Encrypt and pass on the encrypted value.
Parameters:
  • s (string) - the string to encrypt

setrawaccess(self, _read, _write)

source code 
Setup the methods to call for reading and writing.
Parameters:
  • _read (method) - the method to call for reading decrypted data
  • _write (method) - the method to call for writing encrypted data

padding(self)

source code 

Generate a random amount of random padding.

Generates random bytes, with a random length from 16 to PAD_MAX.
Returns: string
the randomly generated padding