From 21295a58f15f2762b56ae2543ec95d573f5fff2e Mon Sep 17 00:00:00 2001 From: samuelraudabaugh <94862843+samuelraudabaugh@users.noreply.github.com> Date: Thu, 4 Aug 2022 18:00:20 -0400 Subject: [PATCH] Add usedforsecurity to md5 constructor This is required for using whoosh on a FIPS-compliant system. See http://blog.serindu.com/2019/11/12/django-in-fips-mode/ for context. --- src/whoosh/filedb/filetables.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/whoosh/filedb/filetables.py b/src/whoosh/filedb/filetables.py index 0a7d1337..6d0ae66c 100644 --- a/src/whoosh/filedb/filetables.py +++ b/src/whoosh/filedb/filetables.py @@ -30,7 +30,7 @@ D. J. Bernstein's CDB format (http://cr.yp.to/cdb.html). """ -import os, struct +import os, struct, sys from binascii import crc32 from hashlib import md5 # @UnresolvedImport @@ -56,7 +56,9 @@ def cdb_hash(key): def md5_hash(key): - return int(md5(key).hexdigest(), 16) & 0xffffffff + if sys.version_info[0] < 3 or sys.version_info[1] < 9: + return int(md5(key).hexdigest(), 16) & 0xffffffff + return int(md5(key, usedforsecurity=False).hexdigest(), 16) & 0xffffffff def crc_hash(key):