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 """Factory functions for symmetric cryptography.""" | 4 """Factory functions for symmetric cryptography.""" |
5 | 5 |
6 import os | 6 import os |
7 | 7 |
8 from tlslite.utils import python_aes | 8 from tlslite.utils import python_aes |
| 9 from tlslite.utils import python_aesgcm |
9 from tlslite.utils import python_rc4 | 10 from tlslite.utils import python_rc4 |
10 | 11 |
11 from tlslite.utils import cryptomath | 12 from tlslite.utils import cryptomath |
12 | 13 |
13 tripleDESPresent = False | 14 tripleDESPresent = False |
14 | 15 |
15 if cryptomath.m2cryptoLoaded: | 16 if cryptomath.m2cryptoLoaded: |
16 from tlslite.utils import openssl_aes | 17 from tlslite.utils import openssl_aes |
17 from tlslite.utils import openssl_rc4 | 18 from tlslite.utils import openssl_rc4 |
18 from tlslite.utils import openssl_tripledes | 19 from tlslite.utils import openssl_tripledes |
19 tripleDESPresent = True | 20 tripleDESPresent = True |
20 | 21 |
21 if cryptomath.pycryptoLoaded: | 22 if cryptomath.pycryptoLoaded: |
22 from tlslite.utils import pycrypto_aes | 23 from tlslite.utils import pycrypto_aes |
| 24 from tlslite.utils import pycrypto_aesgcm |
23 from tlslite.utils import pycrypto_rc4 | 25 from tlslite.utils import pycrypto_rc4 |
24 from tlslite.utils import pycrypto_tripledes | 26 from tlslite.utils import pycrypto_tripledes |
25 tripleDESPresent = True | 27 tripleDESPresent = True |
26 | 28 |
27 # ************************************************************************** | 29 # ************************************************************************** |
28 # Factory Functions for AES | 30 # Factory Functions for AES |
29 # ************************************************************************** | 31 # ************************************************************************** |
30 | 32 |
31 def createAES(key, IV, implList=None): | 33 def createAES(key, IV, implList=None): |
32 """Create a new AES object. | 34 """Create a new AES object. |
(...skipping 12 matching lines...) Expand all Loading... |
45 | 47 |
46 for impl in implList: | 48 for impl in implList: |
47 if impl == "openssl" and cryptomath.m2cryptoLoaded: | 49 if impl == "openssl" and cryptomath.m2cryptoLoaded: |
48 return openssl_aes.new(key, 2, IV) | 50 return openssl_aes.new(key, 2, IV) |
49 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: | 51 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: |
50 return pycrypto_aes.new(key, 2, IV) | 52 return pycrypto_aes.new(key, 2, IV) |
51 elif impl == "python": | 53 elif impl == "python": |
52 return python_aes.new(key, 2, IV) | 54 return python_aes.new(key, 2, IV) |
53 raise NotImplementedError() | 55 raise NotImplementedError() |
54 | 56 |
| 57 def createAESGCM(key, implList=None): |
| 58 """Create a new AESGCM object. |
| 59 |
| 60 @type key: bytearray |
| 61 @param key: A 16 or 32 byte byte array. |
| 62 |
| 63 @rtype: L{tlslite.utils.AESGCM} |
| 64 @return: An AESGCM object. |
| 65 """ |
| 66 if implList == None: |
| 67 implList = ["pycrypto", "python"] |
| 68 |
| 69 for impl in implList: |
| 70 if impl == "pycrypto" and cryptomath.pycryptoLoaded: |
| 71 return pycrypto_aesgcm.new(key) |
| 72 if impl == "python": |
| 73 return python_aesgcm.new(key) |
| 74 raise NotImplementedError() |
| 75 |
55 def createRC4(key, IV, implList=None): | 76 def createRC4(key, IV, implList=None): |
56 """Create a new RC4 object. | 77 """Create a new RC4 object. |
57 | 78 |
58 @type key: str | 79 @type key: str |
59 @param key: A 16 to 32 byte string. | 80 @param key: A 16 to 32 byte string. |
60 | 81 |
61 @type IV: object | 82 @type IV: object |
62 @param IV: Ignored, whatever it is. | 83 @param IV: Ignored, whatever it is. |
63 | 84 |
64 @rtype: L{tlslite.utils.RC4} | 85 @rtype: L{tlslite.utils.RC4} |
(...skipping 27 matching lines...) Expand all Loading... |
92 @return: A 3DES object. | 113 @return: A 3DES object. |
93 """ | 114 """ |
94 if implList == None: | 115 if implList == None: |
95 implList = ["openssl", "pycrypto"] | 116 implList = ["openssl", "pycrypto"] |
96 | 117 |
97 for impl in implList: | 118 for impl in implList: |
98 if impl == "openssl" and cryptomath.m2cryptoLoaded: | 119 if impl == "openssl" and cryptomath.m2cryptoLoaded: |
99 return openssl_tripledes.new(key, 2, IV) | 120 return openssl_tripledes.new(key, 2, IV) |
100 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: | 121 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: |
101 return pycrypto_tripledes.new(key, 2, IV) | 122 return pycrypto_tripledes.new(key, 2, IV) |
102 raise NotImplementedError() | 123 raise NotImplementedError() |
OLD | NEW |