|
8 | 8 |
|
9 | 9 | import binascii |
10 | 10 | import hashlib |
| 11 | +import sys |
| 12 | +from functools import partial |
11 | 13 |
|
12 | 14 | from commoncode.codec import bin_to_num |
13 | 15 | from commoncode.codec import urlsafe_b64encode |
@@ -51,12 +53,21 @@ def intdigest(self): |
51 | 53 | return hasher |
52 | 54 |
|
53 | 55 |
|
| 56 | +# for FIPS support |
| 57 | +sys_v0 = sys.version_info[0] |
| 58 | +sys_v1 = sys.version_info[1] |
| 59 | +if sys_v0 == 3 and sys_v1 >= 9: |
| 60 | + md5_hasher = partial(hashlib.md5, usedforsecurity=False) |
| 61 | +else: |
| 62 | + md5_hasher = hashlib.md5 |
| 63 | + |
| 64 | + |
54 | 65 | # Base hashers for each bit size |
55 | 66 | _hashmodules_by_bitsize = { |
56 | 67 | # md5-based |
57 | | - 32: _hash_mod(32, hashlib.md5), |
58 | | - 64: _hash_mod(64, hashlib.md5), |
59 | | - 128: _hash_mod(128, hashlib.md5), |
| 68 | + 32: _hash_mod(32, md5_hasher), |
| 69 | + 64: _hash_mod(64, md5_hasher), |
| 70 | + 128: _hash_mod(128, md5_hasher), |
60 | 71 | # sha-based |
61 | 72 | 160: _hash_mod(160, hashlib.sha1), |
62 | 73 | 256: _hash_mod(256, hashlib.sha256), |
|
0 commit comments