PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/gdata/tlslite/utils/AES.py

http://radioappz.googlecode.com/
Python | 31 lines | 23 code | 3 blank | 5 comment | 6 complexity | 09bf37bb2a48d0b0de4f8f539a750dbd MD5 | raw file
 1"""Abstract class for AES."""
 2
 3class AES:
 4    def __init__(self, key, mode, IV, implementation):
 5        if len(key) not in (16, 24, 32):
 6            raise AssertionError()
 7        if mode != 2:
 8            raise AssertionError()
 9        if len(IV) != 16:
10            raise AssertionError()
11        self.isBlockCipher = True
12        self.block_size = 16
13        self.implementation = implementation
14        if len(key)==16:
15            self.name = "aes128"
16        elif len(key)==24:
17            self.name = "aes192"
18        elif len(key)==32:
19            self.name = "aes256"
20        else:
21            raise AssertionError()
22
23    #CBC-Mode encryption, returns ciphertext
24    #WARNING: *MAY* modify the input as well
25    def encrypt(self, plaintext):
26        assert(len(plaintext) % 16 == 0)
27
28    #CBC-Mode decryption, returns plaintext
29    #WARNING: *MAY* modify the input as well
30    def decrypt(self, ciphertext):
31        assert(len(ciphertext) % 16 == 0)