8096e8
From f73d993bcb03701f4e9146005a65eb482689140a Mon Sep 17 00:00:00 2001
8096e8
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
8096e8
Date: Mon, 26 Oct 2020 18:54:22 +0100
8096e8
Subject: [PATCH] TST: Make test suite work in FIPS (140-2) Mode
8096e8
MIME-Version: 1.0
8096e8
Content-Type: text/plain; charset=UTF-8
8096e8
Content-Transfer-Encoding: 8bit
8096e8
8096e8
Tests using MD5 algorithms fail in FIPS Mode because MD5 is not FIPS
8096e8
compliant.
8096e8
8096e8
Mark usages of MD5 in test suite as not being used for security
8096e8
purposes to overcome that.
8096e8
8096e8
Signed-off-by: Nikola Forró <nforro@redhat.com>
8096e8
---
8096e8
 numpy/core/tests/test_regression.py          |  2 +-
8096e8
 numpy/random/tests/test_generator_mt19937.py | 10 +++++-----
8096e8
 numpy/random/tests/test_random.py            |  4 ++--
8096e8
 numpy/random/tests/test_randomstate.py       |  6 +++---
8096e8
 4 files changed, 11 insertions(+), 11 deletions(-)
8096e8
8096e8
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
8096e8
index 2e731d4fa..4633174d9 100644
8096e8
--- a/numpy/core/tests/test_regression.py
8096e8
+++ b/numpy/core/tests/test_regression.py
8096e8
@@ -1509,7 +1509,7 @@ class TestRegression:
8096e8
         from hashlib import md5
8096e8
 
8096e8
         x = np.array([1, 2, 3], dtype=np.dtype('
8096e8
-        assert_equal(md5(x).hexdigest(), '2a1dd1e1e59d0a384c26951e316cd7e6')
8096e8
+        assert_equal(md5(x, usedforsecurity=False).hexdigest(), '2a1dd1e1e59d0a384c26951e316cd7e6')
8096e8
 
8096e8
     def test_0d_string_scalar(self):
8096e8
         # Bug #1436; the following should succeed
8096e8
diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py
8096e8
index 6be7d852b..9b166e3a2 100644
8096e8
--- a/numpy/random/tests/test_generator_mt19937.py
8096e8
+++ b/numpy/random/tests/test_generator_mt19937.py
8096e8
@@ -507,14 +507,14 @@ class TestIntegers:
8096e8
                 val = random.integers(0, 6 - endpoint, size=1000, endpoint=endpoint,
8096e8
                                  dtype=dt).byteswap()
8096e8
 
8096e8
-            res = hashlib.md5(val).hexdigest()
8096e8
+            res = hashlib.md5(val, usedforsecurity=False).hexdigest()
8096e8
             assert_(tgt[np.dtype(dt).name] == res)
8096e8
 
8096e8
         # bools do not depend on endianness
8096e8
         random = Generator(MT19937(1234))
8096e8
         val = random.integers(0, 2 - endpoint, size=1000, endpoint=endpoint,
8096e8
                          dtype=bool).view(np.int8)
8096e8
-        res = hashlib.md5(val).hexdigest()
8096e8
+        res = hashlib.md5(val, usedforsecurity=False).hexdigest()
8096e8
         assert_(tgt[np.dtype(bool).name] == res)
8096e8
 
8096e8
     def test_repeatability_broadcasting(self, endpoint):
8096e8
@@ -910,7 +910,7 @@ class TestRandomDist:
8096e8
         actual = random.choice(10000, 5000, replace=False)
8096e8
         if sys.byteorder != 'little':
8096e8
             actual = actual.byteswap()
8096e8
-        res = hashlib.md5(actual.view(np.int8)).hexdigest()
8096e8
+        res = hashlib.md5(actual.view(np.int8), usedforsecurity=False).hexdigest()
8096e8
         assert_(choice_hash == res)
8096e8
 
8096e8
     def test_bytes(self):
8096e8
@@ -2436,7 +2436,7 @@ def test_jumped(config):
8096e8
     key = mt19937.state["state"]["key"]
8096e8
     if sys.byteorder == 'big':
8096e8
         key = key.byteswap()
8096e8
-    md5 = hashlib.md5(key)
8096e8
+    md5 = hashlib.md5(key, usedforsecurity=False)
8096e8
     assert mt19937.state["state"]["pos"] == config["initial"]["pos"]
8096e8
     assert md5.hexdigest() == config["initial"]["key_md5"]
8096e8
 
8096e8
@@ -2444,7 +2444,7 @@ def test_jumped(config):
8096e8
     key = jumped.state["state"]["key"]
8096e8
     if sys.byteorder == 'big':
8096e8
         key = key.byteswap()
8096e8
-    md5 = hashlib.md5(key)
8096e8
+    md5 = hashlib.md5(key, usedforsecurity=False)
8096e8
     assert jumped.state["state"]["pos"] == config["jumped"]["pos"]
8096e8
     assert md5.hexdigest() == config["jumped"]["key_md5"]
8096e8
 
8096e8
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
8096e8
index 276b5bc81..e49251af3 100644
8096e8
--- a/numpy/random/tests/test_random.py
8096e8
+++ b/numpy/random/tests/test_random.py
8096e8
@@ -233,13 +233,13 @@ class TestRandint:
8096e8
             else:
8096e8
                 val = self.rfunc(0, 6, size=1000, dtype=dt).byteswap()
8096e8
 
8096e8
-            res = hashlib.md5(val.view(np.int8)).hexdigest()
8096e8
+            res = hashlib.md5(val.view(np.int8), usedforsecurity=False).hexdigest()
8096e8
             assert_(tgt[np.dtype(dt).name] == res)
8096e8
 
8096e8
         # bools do not depend on endianness
8096e8
         np.random.seed(1234)
8096e8
         val = self.rfunc(0, 2, size=1000, dtype=bool).view(np.int8)
8096e8
-        res = hashlib.md5(val).hexdigest()
8096e8
+        res = hashlib.md5(val, usedforsecurity=False).hexdigest()
8096e8
         assert_(tgt[np.dtype(bool).name] == res)
8096e8
 
8096e8
     def test_int64_uint64_corner_case(self):
8096e8
diff --git a/numpy/random/tests/test_randomstate.py b/numpy/random/tests/test_randomstate.py
8096e8
index 23dbbed6a..aa53d9322 100644
8096e8
--- a/numpy/random/tests/test_randomstate.py
8096e8
+++ b/numpy/random/tests/test_randomstate.py
8096e8
@@ -341,13 +341,13 @@ class TestRandint:
8096e8
             else:
8096e8
                 val = self.rfunc(0, 6, size=1000, dtype=dt).byteswap()
8096e8
 
8096e8
-            res = hashlib.md5(val.view(np.int8)).hexdigest()
8096e8
+            res = hashlib.md5(val.view(np.int8), usedforsecurity=False).hexdigest()
8096e8
             assert_(tgt[np.dtype(dt).name] == res)
8096e8
 
8096e8
         # bools do not depend on endianness
8096e8
         random.seed(1234)
8096e8
         val = self.rfunc(0, 2, size=1000, dtype=bool).view(np.int8)
8096e8
-        res = hashlib.md5(val).hexdigest()
8096e8
+        res = hashlib.md5(val, usedforsecurity=False).hexdigest()
8096e8
         assert_(tgt[np.dtype(bool).name] == res)
8096e8
 
8096e8
     @pytest.mark.skipif(np.iinfo('l').max < 2**32,
8096e8
@@ -1987,7 +1987,7 @@ def test_integer_repeat(int_func):
8096e8
     val = f(*args, size=1000000)
8096e8
     if sys.byteorder != 'little':
8096e8
         val = val.byteswap()
8096e8
-    res = hashlib.md5(val.view(np.int8)).hexdigest()
8096e8
+    res = hashlib.md5(val.view(np.int8), usedforsecurity=False).hexdigest()
8096e8
     assert_(res == md5)
8096e8
 
8096e8
 
8096e8
-- 
8096e8
2.26.2
8096e8