parent
d5026cf5ef
commit
893f9099b3
3 changed files with 36 additions and 11 deletions
|
@ -155,9 +155,6 @@ class AeadCryptoBase(object):
|
|||
# n, n > 0, waiting data
|
||||
self._chunk = {'mlen': AEAD_MSG_LEN_UNKNOWN, 'data': b''}
|
||||
|
||||
self.encrypt_once = self.aead_encrypt
|
||||
self.decrypt_once = self.aead_decrypt
|
||||
|
||||
# load libsodium for nonce increment
|
||||
if not sodium_loaded:
|
||||
crypto_path = dict(crypto_path) if crypto_path else dict()
|
||||
|
|
|
@ -107,8 +107,11 @@ class OpenSSLCryptoBase(object):
|
|||
if not self._ctx:
|
||||
raise Exception('can not create cipher context')
|
||||
|
||||
self.encrypt_once = self.update
|
||||
self.decrypt_once = self.update
|
||||
def encrypt_once(self, data):
|
||||
return self.update(data)
|
||||
|
||||
def decrypt_once(self, data):
|
||||
return self.update(data)
|
||||
|
||||
def update(self, data):
|
||||
"""
|
||||
|
@ -136,6 +139,7 @@ class OpenSSLCryptoBase(object):
|
|||
if self._ctx:
|
||||
ctx_cleanup(self._ctx)
|
||||
libcrypto.EVP_CIPHER_CTX_free(self._ctx)
|
||||
self._ctx = None
|
||||
|
||||
|
||||
class OpenSSLAeadCrypto(OpenSSLCryptoBase, AeadCryptoBase):
|
||||
|
@ -267,6 +271,12 @@ class OpenSSLAeadCrypto(OpenSSLCryptoBase, AeadCryptoBase):
|
|||
self.cipher_ctx_init()
|
||||
return plaintext
|
||||
|
||||
def encrypt_once(self, data):
|
||||
return self.aead_encrypt(data)
|
||||
|
||||
def decrypt_once(self, data):
|
||||
return self.aead_decrypt(data)
|
||||
|
||||
|
||||
class OpenSSLStreamCrypto(OpenSSLCryptoBase):
|
||||
"""
|
||||
|
@ -281,8 +291,12 @@ class OpenSSLStreamCrypto(OpenSSLCryptoBase):
|
|||
if not r:
|
||||
self.clean()
|
||||
raise Exception('can not initialize cipher context')
|
||||
self.encrypt = self.update
|
||||
self.decrypt = self.update
|
||||
|
||||
def encrypt(self, data):
|
||||
return self.update(data)
|
||||
|
||||
def decrypt(self, data):
|
||||
return self.update(data)
|
||||
|
||||
|
||||
ciphers = {
|
||||
|
|
|
@ -192,10 +192,18 @@ class SodiumCrypto(object):
|
|||
raise Exception('Unknown cipher')
|
||||
# byte counter, not block counter
|
||||
self.counter = 0
|
||||
self.encrypt = self.update
|
||||
self.decrypt = self.update
|
||||
self.encrypt_once = self.update
|
||||
self.decrypt_once = self.update
|
||||
|
||||
def encrypt(self, data):
|
||||
return self.update(data)
|
||||
|
||||
def decrypt(self, data):
|
||||
return self.update(data)
|
||||
|
||||
def encrypt_once(self, data):
|
||||
return self.update(data)
|
||||
|
||||
def decrypt_once(self, data):
|
||||
return self.update(data)
|
||||
|
||||
def update(self, data):
|
||||
global buf_size, buf
|
||||
|
@ -300,6 +308,12 @@ class SodiumAeadCrypto(AeadCryptoBase):
|
|||
self.cipher_ctx_init()
|
||||
return buf.raw[:cipher_out_len.value]
|
||||
|
||||
def encrypt_once(self, data):
|
||||
return self.aead_encrypt(data)
|
||||
|
||||
def decrypt_once(self, data):
|
||||
return self.aead_decrypt(data)
|
||||
|
||||
|
||||
ciphers = {
|
||||
'salsa20': (32, 8, SodiumCrypto),
|
||||
|
|
Loading…
Reference in a new issue