OLD | NEW |
1 """Factory functions for symmetric cryptography.""" | 1 """Factory functions for symmetric cryptography.""" |
2 | 2 |
3 import os | 3 import os |
4 | 4 |
5 import Python_AES | 5 import python_aes |
6 import Python_RC4 | 6 import python_rc4 |
7 | 7 |
8 import cryptomath | 8 import cryptomath |
9 | 9 |
10 tripleDESPresent = False | 10 tripleDESPresent = False |
11 | 11 |
12 if cryptomath.m2cryptoLoaded: | 12 if cryptomath.m2cryptoLoaded: |
13 import OpenSSL_AES | 13 import openssl_aes |
14 import OpenSSL_RC4 | 14 import openssl_rc4 |
15 import OpenSSL_TripleDES | 15 import openssl_tripledes |
16 tripleDESPresent = True | 16 tripleDESPresent = True |
17 | 17 |
18 if cryptomath.cryptlibpyLoaded: | 18 if cryptomath.cryptlibpyLoaded: |
19 import Cryptlib_AES | 19 import cryptlib_aes |
20 import Cryptlib_RC4 | 20 import cryptlib_rc4 |
21 import Cryptlib_TripleDES | 21 import cryptlib_tripledes |
22 tripleDESPresent = True | 22 tripleDESPresent = True |
23 | 23 |
24 if cryptomath.pycryptoLoaded: | 24 if cryptomath.pycryptoLoaded: |
25 import PyCrypto_AES | 25 import pycrypto_aes |
26 import PyCrypto_RC4 | 26 import pycrypto_rc4 |
27 import PyCrypto_TripleDES | 27 import pycrypto_tripledes |
28 tripleDESPresent = True | 28 tripleDESPresent = True |
29 | 29 |
30 # ************************************************************************** | 30 # ************************************************************************** |
31 # Factory Functions for AES | 31 # Factory Functions for AES |
32 # ************************************************************************** | 32 # ************************************************************************** |
33 | 33 |
34 def createAES(key, IV, implList=None): | 34 def createAES(key, IV, implList=None): |
35 """Create a new AES object. | 35 """Create a new AES object. |
36 | 36 |
37 @type key: str | 37 @type key: str |
38 @param key: A 16, 24, or 32 byte string. | 38 @param key: A 16, 24, or 32 byte string. |
39 | 39 |
40 @type IV: str | 40 @type IV: str |
41 @param IV: A 16 byte string | 41 @param IV: A 16 byte string |
42 | 42 |
43 @rtype: L{tlslite.utils.AES} | 43 @rtype: L{tlslite.utils.AES} |
44 @return: An AES object. | 44 @return: An AES object. |
45 """ | 45 """ |
46 if implList == None: | 46 if implList == None: |
47 implList = ["cryptlib", "openssl", "pycrypto", "python"] | 47 implList = ["cryptlib", "openssl", "pycrypto", "python"] |
48 | 48 |
49 for impl in implList: | 49 for impl in implList: |
50 if impl == "cryptlib" and cryptomath.cryptlibpyLoaded: | 50 if impl == "cryptlib" and cryptomath.cryptlibpyLoaded: |
51 return Cryptlib_AES.new(key, 2, IV) | 51 return cryptlib_aes.new(key, 2, IV) |
52 elif impl == "openssl" and cryptomath.m2cryptoLoaded: | 52 elif impl == "openssl" and cryptomath.m2cryptoLoaded: |
53 return OpenSSL_AES.new(key, 2, IV) | 53 return openssl_aes.new(key, 2, IV) |
54 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: | 54 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: |
55 return PyCrypto_AES.new(key, 2, IV) | 55 return pycrypto_aes.new(key, 2, IV) |
56 elif impl == "python": | 56 elif impl == "python": |
57 return Python_AES.new(key, 2, IV) | 57 return python_aes.new(key, 2, IV) |
58 raise NotImplementedError() | 58 raise NotImplementedError() |
59 | 59 |
60 def createRC4(key, IV, implList=None): | 60 def createRC4(key, IV, implList=None): |
61 """Create a new RC4 object. | 61 """Create a new RC4 object. |
62 | 62 |
63 @type key: str | 63 @type key: str |
64 @param key: A 16 to 32 byte string. | 64 @param key: A 16 to 32 byte string. |
65 | 65 |
66 @type IV: object | 66 @type IV: object |
67 @param IV: Ignored, whatever it is. | 67 @param IV: Ignored, whatever it is. |
68 | 68 |
69 @rtype: L{tlslite.utils.RC4} | 69 @rtype: L{tlslite.utils.RC4} |
70 @return: An RC4 object. | 70 @return: An RC4 object. |
71 """ | 71 """ |
72 if implList == None: | 72 if implList == None: |
73 implList = ["cryptlib", "openssl", "pycrypto", "python"] | 73 implList = ["cryptlib", "openssl", "pycrypto", "python"] |
74 | 74 |
75 if len(IV) != 0: | 75 if len(IV) != 0: |
76 raise AssertionError() | 76 raise AssertionError() |
77 for impl in implList: | 77 for impl in implList: |
78 if impl == "cryptlib" and cryptomath.cryptlibpyLoaded: | 78 if impl == "cryptlib" and cryptomath.cryptlibpyLoaded: |
79 return Cryptlib_RC4.new(key) | 79 return cryptlib_rc4.new(key) |
80 elif impl == "openssl" and cryptomath.m2cryptoLoaded: | 80 elif impl == "openssl" and cryptomath.m2cryptoLoaded: |
81 return OpenSSL_RC4.new(key) | 81 return openssl_rc4.new(key) |
82 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: | 82 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: |
83 return PyCrypto_RC4.new(key) | 83 return pycrypto_rc4.new(key) |
84 elif impl == "python": | 84 elif impl == "python": |
85 return Python_RC4.new(key) | 85 return python_rc4.new(key) |
86 raise NotImplementedError() | 86 raise NotImplementedError() |
87 | 87 |
88 #Create a new TripleDES instance | 88 #Create a new TripleDES instance |
89 def createTripleDES(key, IV, implList=None): | 89 def createTripleDES(key, IV, implList=None): |
90 """Create a new 3DES object. | 90 """Create a new 3DES object. |
91 | 91 |
92 @type key: str | 92 @type key: str |
93 @param key: A 24 byte string. | 93 @param key: A 24 byte string. |
94 | 94 |
95 @type IV: str | 95 @type IV: str |
96 @param IV: An 8 byte string | 96 @param IV: An 8 byte string |
97 | 97 |
98 @rtype: L{tlslite.utils.TripleDES} | 98 @rtype: L{tlslite.utils.TripleDES} |
99 @return: A 3DES object. | 99 @return: A 3DES object. |
100 """ | 100 """ |
101 if implList == None: | 101 if implList == None: |
102 implList = ["cryptlib", "openssl", "pycrypto"] | 102 implList = ["cryptlib", "openssl", "pycrypto"] |
103 | 103 |
104 for impl in implList: | 104 for impl in implList: |
105 if impl == "cryptlib" and cryptomath.cryptlibpyLoaded: | 105 if impl == "cryptlib" and cryptomath.cryptlibpyLoaded: |
106 return Cryptlib_TripleDES.new(key, 2, IV) | 106 return cryptlib_tripledes.new(key, 2, IV) |
107 elif impl == "openssl" and cryptomath.m2cryptoLoaded: | 107 elif impl == "openssl" and cryptomath.m2cryptoLoaded: |
108 return OpenSSL_TripleDES.new(key, 2, IV) | 108 return openssl_tripledes.new(key, 2, IV) |
109 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: | 109 elif impl == "pycrypto" and cryptomath.pycryptoLoaded: |
110 return PyCrypto_TripleDES.new(key, 2, IV) | 110 return pycrypto_tripledes.new(key, 2, IV) |
111 raise NotImplementedError() | 111 raise NotImplementedError() |
OLD | NEW |