diff options
Diffstat (limited to 'chromium/third_party/tlslite/tlslite/utils/pycrypto_aes.py')
-rw-r--r-- | chromium/third_party/tlslite/tlslite/utils/pycrypto_aes.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/chromium/third_party/tlslite/tlslite/utils/pycrypto_aes.py b/chromium/third_party/tlslite/tlslite/utils/pycrypto_aes.py new file mode 100644 index 00000000000..b3425c047d7 --- /dev/null +++ b/chromium/third_party/tlslite/tlslite/utils/pycrypto_aes.py @@ -0,0 +1,29 @@ +# Author: Trevor Perrin +# See the LICENSE file for legal information regarding use of this file. + +"""PyCrypto AES implementation.""" + +from .cryptomath import * +from .aes import * + +if pycryptoLoaded: + import Crypto.Cipher.AES + + def new(key, mode, IV): + return PyCrypto_AES(key, mode, IV) + + class PyCrypto_AES(AES): + + def __init__(self, key, mode, IV): + AES.__init__(self, key, mode, IV, "pycrypto") + key = bytes(key) + IV = bytes(IV) + self.context = Crypto.Cipher.AES.new(key, mode, IV) + + def encrypt(self, plaintext): + plaintext = bytes(plaintext) + return bytearray(self.context.encrypt(plaintext)) + + def decrypt(self, ciphertext): + ciphertext = bytes(ciphertext) + return bytearray(self.context.decrypt(ciphertext)) |