Skip to content

Commit 6355810

Browse files
authored
Merge pull request #408 from tomato42/pycryptodome
detect pycryptodome, don't use it
2 parents d324e95 + e92ba72 commit 6355810

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ jobs:
7676
# dist: xenial
7777
# sudo: true
7878
# env: PYCRYPTO=true
79+
- python: 3.7
80+
dist: xenial
81+
sudo: true
82+
env: PYCRYPTODOME=true
7983
- python: 2.7
8084
env: GMPY=true
8185
- python: 3.5
@@ -132,6 +136,7 @@ install:
132136
- if [[ $TACKPY == 'true' ]]; then travis_retry pip install tackpy; fi
133137
- if [[ $M2CRYPTO == 'true' ]]; then travis_retry pip install --pre m2crypto; fi
134138
- if [[ $PYCRYPTO == 'true' ]]; then travis_retry pip install pycrypto; fi
139+
- if [[ $PYCRYPTODOME == 'true' ]]; then travis_retry pip install pycryptodome; fi
135140
- if [[ $GMPY == 'true' ]]; then travis_retry pip install gmpy; fi
136141
- travis_retry pip install -r requirements.txt
137142
- if [[ $CC_COV == 'true' ]]; then ./cc-test-reporter before-build; fi

tlslite/utils/cryptomath.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@
5050
gmpyLoaded = False
5151

5252
#Try to load pycrypto
53+
# pylint: disable=invalid-name
5354
try:
5455
import Crypto.Cipher.AES
55-
pycryptoLoaded = True
56+
# check if we're not using pycryptodome
57+
try:
58+
# pycrypto defaults to ECB when just key is provided
59+
# pycryptodome requires specifying the mode of operation
60+
Crypto.Cipher.AES.AESCipher(b'2' * (128//8))
61+
pycryptoLoaded = True
62+
except AttributeError:
63+
pycryptoLoaded = False
5664
except ImportError:
5765
pycryptoLoaded = False
66+
# pylint: enable=invalid-name
5867

5968

6069
# **************************************************************************

0 commit comments

Comments
 (0)