| OLD | NEW |
| 1 """OpenSSL/M2Crypto AES implementation.""" | 1 """OpenSSL/M2Crypto AES implementation.""" |
| 2 | 2 |
| 3 from cryptomath import * | 3 from cryptomath import * |
| 4 from AES import * | 4 from aes import * |
| 5 | 5 |
| 6 if m2cryptoLoaded: | 6 if m2cryptoLoaded: |
| 7 | 7 |
| 8 def new(key, mode, IV): | 8 def new(key, mode, IV): |
| 9 return OpenSSL_AES(key, mode, IV) | 9 return OpenSSL_AES(key, mode, IV) |
| 10 | 10 |
| 11 class OpenSSL_AES(AES): | 11 class OpenSSL_AES(AES): |
| 12 | 12 |
| 13 def __init__(self, key, mode, IV): | 13 def __init__(self, key, mode, IV): |
| 14 AES.__init__(self, key, mode, IV, "openssl") | 14 AES.__init__(self, key, mode, IV, "openssl") |
| (...skipping 25 matching lines...) Expand all Loading... |
| 40 #I think M2Crypto has a bug - it fails to decrypt and return the las
t block passed in. | 40 #I think M2Crypto has a bug - it fails to decrypt and return the las
t block passed in. |
| 41 #To work around this, we append sixteen zeros to the string, below: | 41 #To work around this, we append sixteen zeros to the string, below: |
| 42 plaintext = m2.cipher_update(context, ciphertext+('\0'*16)) | 42 plaintext = m2.cipher_update(context, ciphertext+('\0'*16)) |
| 43 | 43 |
| 44 #If this bug is ever fixed, then plaintext will end up having a garb
age | 44 #If this bug is ever fixed, then plaintext will end up having a garb
age |
| 45 #plaintext block on the end. That's okay - the below code will disc
ard it. | 45 #plaintext block on the end. That's okay - the below code will disc
ard it. |
| 46 plaintext = plaintext[:len(ciphertext)] | 46 plaintext = plaintext[:len(ciphertext)] |
| 47 m2.cipher_ctx_free(context) | 47 m2.cipher_ctx_free(context) |
| 48 self.IV = ciphertext[-self.block_size:] | 48 self.IV = ciphertext[-self.block_size:] |
| 49 return plaintext | 49 return plaintext |
| OLD | NEW |