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

Source Code for Module tlslite.utils.aes

 1  # Author: Trevor Perrin 
 2  # See the LICENSE file for legal information regarding use of this file. 
 3   
 4  """Abstract class for AES.""" 
 5   
6 -class AES(object):
7 - def __init__(self, key, mode, IV, implementation):
8 if len(key) not in (16, 24, 32): 9 raise AssertionError() 10 if mode != 2: 11 raise AssertionError() 12 if len(IV) != 16: 13 raise AssertionError() 14 self.isBlockCipher = True 15 self.isAEAD = False 16 self.block_size = 16 17 self.implementation = implementation 18 if len(key)==16: 19 self.name = "aes128" 20 elif len(key)==24: 21 self.name = "aes192" 22 elif len(key)==32: 23 self.name = "aes256" 24 else: 25 raise AssertionError()
26 27 #CBC-Mode encryption, returns ciphertext 28 #WARNING: *MAY* modify the input as well
29 - def encrypt(self, plaintext):
30 assert(len(plaintext) % 16 == 0)
31 32 #CBC-Mode decryption, returns plaintext 33 #WARNING: *MAY* modify the input as well
34 - def decrypt(self, ciphertext):
35 assert(len(ciphertext) % 16 == 0)
36