Home | History | Annotate | Download | only in utils
      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.block_size = 16
     16         self.implementation = implementation
     17         if len(key)==16:
     18             self.name = "aes128"
     19         elif len(key)==24:
     20             self.name = "aes192"
     21         elif len(key)==32:
     22             self.name = "aes256"
     23         else:
     24             raise AssertionError()
     25 
     26     #CBC-Mode encryption, returns ciphertext
     27     #WARNING: *MAY* modify the input as well
     28     def encrypt(self, plaintext):
     29         assert(len(plaintext) % 16 == 0)
     30 
     31     #CBC-Mode decryption, returns plaintext
     32     #WARNING: *MAY* modify the input as well
     33     def decrypt(self, ciphertext):
     34         assert(len(ciphertext) % 16 == 0)