tlslite.utils.pycrypto_aes

Package tlslite :: Package utils :: Module pycrypto_aes |
[hide private]
[frames] | no frames]

# Source Code for Module tlslite.utils.pycrypto_aes

     1  # Author: Trevor Perrin
     2  # See the LICENSE file for legal information regarding use of this file.
     3
     4  """PyCrypto AES implementation."""
     5
     6  from .cryptomath import *
     7  from .aes import *
     8
     9  if pycryptoLoaded:
    10      import Crypto.Cipher.AES
    11
    12 -    def new(key, mode, IV):
    13          return PyCrypto_AES(key, mode, IV)
    14
    15 -    class PyCrypto_AES(AES):
    16
    17 -        def __init__(self, key, mode, IV):
    18              AES.__init__(self, key, mode, IV, "pycrypto")
    19              key = bytes(key)
    20              IV = bytes(IV)
    21              self.context = Crypto.Cipher.AES.new(key, mode, IV)
    22
    23 -        def encrypt(self, plaintext):
    24              plaintext = bytes(plaintext)
    25              return bytearray(self.context.encrypt(plaintext))
    26
    27 -        def decrypt(self, ciphertext):
    28              ciphertext = bytes(ciphertext)
    29              return bytearray(self.context.decrypt(ciphertext))
    30