| Index: third_party/tlslite/tlslite/utils/python_aes.py
|
| diff --git a/third_party/tlslite/tlslite/utils/python_aes.py b/third_party/tlslite/tlslite/utils/python_aes.py
|
| index 36735919638b319e4383e1fc200d352cb745fff2..cb8f87ed4012993591569722287a83e0b2035684 100644
|
| --- a/third_party/tlslite/tlslite/utils/python_aes.py
|
| +++ b/third_party/tlslite/tlslite/utils/python_aes.py
|
| @@ -1,9 +1,12 @@
|
| +# Author: Trevor Perrin
|
| +# See the LICENSE file for legal information regarding use of this file.
|
| +
|
| """Pure-Python AES implementation."""
|
|
|
| -from cryptomath import *
|
| +from .cryptomath import *
|
|
|
| -from aes import *
|
| -from rijndael import rijndael
|
| +from .aes import *
|
| +from .rijndael import rijndael
|
|
|
| def new(key, mode, IV):
|
| return Python_AES(key, mode, IV)
|
| @@ -17,20 +20,19 @@ class Python_AES(AES):
|
| def encrypt(self, plaintext):
|
| AES.encrypt(self, plaintext)
|
|
|
| - plaintextBytes = stringToBytes(plaintext)
|
| - chainBytes = stringToBytes(self.IV)
|
| + plaintextBytes = plaintext[:]
|
| + chainBytes = self.IV[:]
|
|
|
| #CBC Mode: For each block...
|
| - for x in range(len(plaintextBytes)/16):
|
| + for x in range(len(plaintextBytes)//16):
|
|
|
| #XOR with the chaining block
|
| blockBytes = plaintextBytes[x*16 : (x*16)+16]
|
| for y in range(16):
|
| blockBytes[y] ^= chainBytes[y]
|
| - blockString = bytesToString(blockBytes)
|
|
|
| #Encrypt it
|
| - encryptedBytes = stringToBytes(self.rijndael.encrypt(blockString))
|
| + encryptedBytes = self.rijndael.encrypt(blockBytes)
|
|
|
| #Overwrite the input with the output
|
| for y in range(16):
|
| @@ -39,22 +41,21 @@ class Python_AES(AES):
|
| #Set the next chaining block
|
| chainBytes = encryptedBytes
|
|
|
| - self.IV = bytesToString(chainBytes)
|
| - return bytesToString(plaintextBytes)
|
| + self.IV = chainBytes[:]
|
| + return plaintextBytes
|
|
|
| def decrypt(self, ciphertext):
|
| AES.decrypt(self, ciphertext)
|
|
|
| - ciphertextBytes = stringToBytes(ciphertext)
|
| - chainBytes = stringToBytes(self.IV)
|
| + ciphertextBytes = ciphertext[:]
|
| + chainBytes = self.IV[:]
|
|
|
| #CBC Mode: For each block...
|
| - for x in range(len(ciphertextBytes)/16):
|
| + for x in range(len(ciphertextBytes)//16):
|
|
|
| #Decrypt it
|
| blockBytes = ciphertextBytes[x*16 : (x*16)+16]
|
| - blockString = bytesToString(blockBytes)
|
| - decryptedBytes = stringToBytes(self.rijndael.decrypt(blockString))
|
| + decryptedBytes = self.rijndael.decrypt(blockBytes)
|
|
|
| #XOR with the chaining block and overwrite the input with output
|
| for y in range(16):
|
| @@ -64,5 +65,5 @@ class Python_AES(AES):
|
| #Set the next chaining block
|
| chainBytes = blockBytes
|
|
|
| - self.IV = bytesToString(chainBytes)
|
| - return bytesToString(ciphertextBytes)
|
| + self.IV = chainBytes[:]
|
| + return ciphertextBytes
|
|
|