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