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

Side by Side Diff: third_party/tlslite/tlslite/utils/openssl_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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Author: Trevor Perrin
2 # See the LICENSE file for legal information regarding use of this file.
3
1 """OpenSSL/M2Crypto AES implementation.""" 4 """OpenSSL/M2Crypto AES implementation."""
2 5
3 from cryptomath import * 6 from .cryptomath import *
4 from aes import * 7 from .aes import *
5 8
6 if m2cryptoLoaded: 9 if m2cryptoLoaded:
7 10
8 def new(key, mode, IV): 11 def new(key, mode, IV):
9 return OpenSSL_AES(key, mode, IV) 12 return OpenSSL_AES(key, mode, IV)
10 13
11 class OpenSSL_AES(AES): 14 class OpenSSL_AES(AES):
12 15
13 def __init__(self, key, mode, IV): 16 def __init__(self, key, mode, IV):
14 AES.__init__(self, key, mode, IV, "openssl") 17 AES.__init__(self, key, mode, IV, "openssl")
(...skipping 10 matching lines...) Expand all
25 cipherType = m2.aes_256_cbc() 28 cipherType = m2.aes_256_cbc()
26 m2.cipher_init(context, cipherType, self.key, self.IV, encrypt) 29 m2.cipher_init(context, cipherType, self.key, self.IV, encrypt)
27 return context 30 return context
28 31
29 def encrypt(self, plaintext): 32 def encrypt(self, plaintext):
30 AES.encrypt(self, plaintext) 33 AES.encrypt(self, plaintext)
31 context = self._createContext(1) 34 context = self._createContext(1)
32 ciphertext = m2.cipher_update(context, plaintext) 35 ciphertext = m2.cipher_update(context, plaintext)
33 m2.cipher_ctx_free(context) 36 m2.cipher_ctx_free(context)
34 self.IV = ciphertext[-self.block_size:] 37 self.IV = ciphertext[-self.block_size:]
35 return ciphertext 38 return bytearray(ciphertext)
36 39
37 def decrypt(self, ciphertext): 40 def decrypt(self, ciphertext):
38 AES.decrypt(self, ciphertext) 41 AES.decrypt(self, ciphertext)
39 context = self._createContext(0) 42 context = self._createContext(0)
40 #I think M2Crypto has a bug - it fails to decrypt and return the las t block passed in. 43 #I think M2Crypto has a bug - it fails to decrypt and return the las t block passed in.
41 #To work around this, we append sixteen zeros to the string, below: 44 #To work around this, we append sixteen zeros to the string, below:
42 plaintext = m2.cipher_update(context, ciphertext+('\0'*16)) 45 plaintext = m2.cipher_update(context, ciphertext+('\0'*16))
43 46
44 #If this bug is ever fixed, then plaintext will end up having a garb age 47 #If this bug is ever fixed, then plaintext will end up having a garb age
45 #plaintext block on the end. That's okay - the below code will disc ard it. 48 #plaintext block on the end. That's okay - the below code will disc ard it.
46 plaintext = plaintext[:len(ciphertext)] 49 plaintext = plaintext[:len(ciphertext)]
47 m2.cipher_ctx_free(context) 50 m2.cipher_ctx_free(context)
48 self.IV = ciphertext[-self.block_size:] 51 self.IV = ciphertext[-self.block_size:]
49 return plaintext 52 return bytearray(plaintext)
OLDNEW
« no previous file with comments | « third_party/tlslite/tlslite/utils/keyfactory.py ('k') | third_party/tlslite/tlslite/utils/openssl_rc4.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698