Skip to content

Commit 2816c3e

Browse files
committed
Fix GH#875: Incorrect OIDs for BLAKE2
1 parent 4fd3013 commit 2816c3e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/Crypto/Hash/BLAKE2b.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(self, data, key, digest_bytes, update_after_digest):
8383

8484
# See https://tools.ietf.org/html/rfc7693
8585
if digest_bytes in (20, 32, 48, 64) and not key:
86-
self.oid = "1.3.6.1.4.1.1722.12.2.1." + str(digest_bytes)
86+
self.oid = "1.3.6.1.4.1.1722.12.2.1." + str(digest_bytes // 4)
8787

8888
state = VoidPointer()
8989
result = _raw_blake2b_lib.blake2b_init(state.address_of(),

lib/Crypto/Hash/BLAKE2s.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(self, data, key, digest_bytes, update_after_digest):
8383

8484
# See https://tools.ietf.org/html/rfc7693
8585
if digest_bytes in (16, 20, 28, 32) and not key:
86-
self.oid = "1.3.6.1.4.1.1722.12.2.2." + str(digest_bytes)
86+
self.oid = "1.3.6.1.4.1.1722.12.2.2." + str(digest_bytes // 4)
8787

8888
state = VoidPointer()
8989
result = _raw_blake2s_lib.blake2s_init(state.address_of(),

lib/Crypto/SelfTest/Hash/test_BLAKE2.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,18 @@ def test_oid(self):
158158

159159
prefix = "1.3.6.1.4.1.1722.12.2." + self.oid_variant + "."
160160

161+
suffix = {
162+
128: "4",
163+
160: "5",
164+
224: "7",
165+
256: "8",
166+
384: "12",
167+
512: "16"
168+
}
169+
161170
for digest_bits in self.digest_bits_oid:
162171
h = self.BLAKE2.new(digest_bits=digest_bits)
163-
self.assertEqual(h.oid, prefix + str(digest_bits // 8))
172+
self.assertEqual(h.oid, prefix + suffix[digest_bits])
164173

165174
h = self.BLAKE2.new(digest_bits=digest_bits, key=b"secret")
166175
self.assertRaises(AttributeError, lambda: h.oid)
@@ -477,6 +486,7 @@ def get_tests(config={}):
477486

478487
if __name__ == '__main__':
479488
import unittest
489+
480490
def suite():
481491
return unittest.TestSuite(get_tests())
482492
unittest.main(defaultTest='suite')

0 commit comments

Comments
 (0)