Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: third_party/tlslite/tlslite/utils/python_aes.py

Issue 210323002: Update tlslite to 0.4.6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Executable bit and --similarity=80 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « third_party/tlslite/tlslite/utils/pycrypto_tripledes.py ('k') | third_party/tlslite/tlslite/utils/python_rc4.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698