File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 2727# **************************************************************************
2828
2929# Try to load M2Crypto/OpenSSL
30+ # pylint: disable=invalid-name
3031try :
3132 from M2Crypto import m2
3233 m2cryptoLoaded = True
34+ M2CRYPTO_AES_CTR = False
35+ if hasattr (m2 , 'aes_192_ctr' ):
36+ M2CRYPTO_AES_CTR = True
3337
3438 try :
3539 with open ('/proc/sys/crypto/fips_enabled' , 'r' ) as fipsFile :
3943 # looks like we're running in container, likely not FIPS mode
4044 m2cryptoLoaded = True
4145
46+ # If AES-CBC is not available, don't use m2crypto
47+ if not hasattr (m2 , 'aes_192_cbc' ):
48+ m2cryptoLoaded = False
49+
4250except ImportError :
4351 m2cryptoLoaded = False
52+ # pylint: enable=invalid-name
4453
4554#Try to load GMPY
4655try :
Original file line number Diff line number Diff line change 55
66from .cryptomath import *
77from .aes import *
8+ from .python_aes import Python_AES_CTR
89
910if m2cryptoLoaded :
1011
1112 def new (key , mode , IV ):
1213 # IV argument name is a part of the interface
1314 # pylint: disable=invalid-name
15+ """
16+ Try using AES CTR from m2crpyto,
17+ if it is not available fall back to the
18+ python implementation.
19+ """
1420 if mode == 2 :
1521 return OpenSSL_AES (key , mode , IV )
1622 elif mode == 6 :
17- return OpenSSL_CTR (key , mode , IV )
23+ if M2CRYPTO_AES_CTR :
24+ return OpenSSL_CTR (key , mode , IV )
25+ return Python_AES_CTR (key , mode , IV )
1826 else :
1927 raise NotImplementedError ()
2028
You can’t perform that action at this time.
0 commit comments