summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-11-03 19:55:54 (GMT)
committerChristian Heimes <christian@python.org>2017-11-03 19:55:54 (GMT)
commita512493371a073e252a2e52b445aa2d66ddca7cb (patch)
treeb2aaa4eb48e135716f0b882c88adde3b5be51b5f /Lib/test
parentea80ae04e2ec68c7e289048d3224a24b3c3fb107 (diff)
downloadcpython-a512493371a073e252a2e52b445aa2d66ddca7cb.zip
cpython-a512493371a073e252a2e52b445aa2d66ddca7cb.tar.gz
cpython-a512493371a073e252a2e52b445aa2d66ddca7cb.tar.bz2
bpo-31933: fix blake2 multi-byte params on big endian platforms (GH-4250) (#4262)
All Blake2 params have to be encoded in little-endian byte order. For the two multi-byte integer params, leaf_length and node_offset, that means that assigning a native-endian integer to them appears to work on little-endian platforms, but gives the wrong result on big-endian. The current libb2 API doesn't make that very clear, and @sneves is working on new API functions in the GH issue above. In the meantime, we can work around the problem by explicitly assigning little-endian values to the parameter block. See https://github.com/BLAKE2/libb2/issues/12. (cherry picked from commit dcfb0e3c04f1b29a0d09bb0a81dcd5ee5a5fef1a)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_hashlib.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index 647719e..9817488 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -619,6 +619,24 @@ class HashLibTestCase(unittest.TestCase):
"7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923")
@requires_blake2
+ def test_case_blake2b_all_parameters(self):
+ # This checks that all the parameters work in general, and also that
+ # parameter byte order doesn't get confused on big endian platforms.
+ self.check('blake2b', b"foo",
+ "920568b0c5873b2f0ab67bedb6cf1b2b",
+ digest_size=16,
+ key=b"bar",
+ salt=b"baz",
+ person=b"bing",
+ fanout=2,
+ depth=3,
+ leaf_size=4,
+ node_offset=5,
+ node_depth=6,
+ inner_size=7,
+ last_node=True)
+
+ @requires_blake2
def test_blake2b_vectors(self):
for msg, key, md in read_vectors('blake2b'):
key = bytes.fromhex(key)
@@ -644,6 +662,24 @@ class HashLibTestCase(unittest.TestCase):
"508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982")
@requires_blake2
+ def test_case_blake2s_all_parameters(self):
+ # This checks that all the parameters work in general, and also that
+ # parameter byte order doesn't get confused on big endian platforms.
+ self.check('blake2s', b"foo",
+ "bf2a8f7fe3c555012a6f8046e646bc75",
+ digest_size=16,
+ key=b"bar",
+ salt=b"baz",
+ person=b"bing",
+ fanout=2,
+ depth=3,
+ leaf_size=4,
+ node_offset=5,
+ node_depth=6,
+ inner_size=7,
+ last_node=True)
+
+ @requires_blake2
def test_blake2s_vectors(self):
for msg, key, md in read_vectors('blake2s'):
key = bytes.fromhex(key)