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