mirror of
https://github.com/Legrandin/pycryptodome.git
synced 2025-12-08 05:19:46 +00:00
Digest size 224 bits is 28 bytes (not 24)
This commit is contained in:
parent
203b3615cf
commit
ae25edc5c7
2 changed files with 10 additions and 6 deletions
|
|
@ -153,8 +153,12 @@ class Keccak_Hash(object):
|
||||||
|
|
||||||
return "".join(["%02x" % bord(x) for x in self.digest()])
|
return "".join(["%02x" % bord(x) for x in self.digest()])
|
||||||
|
|
||||||
def new(self):
|
def new(self, **kwargs):
|
||||||
return type(self)(None, self.digest_size, self._update_after_digest)
|
|
||||||
|
if "digest_bytes" not in kwargs and "digest_bits" not in kwargs:
|
||||||
|
kwargs["digest_bytes"] = self.digest_size
|
||||||
|
|
||||||
|
return new(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def new(**kwargs):
|
def new(**kwargs):
|
||||||
|
|
@ -165,7 +169,7 @@ def new(**kwargs):
|
||||||
Optional. The very first chunk of the message to hash.
|
Optional. The very first chunk of the message to hash.
|
||||||
It is equivalent to an early call to ``update()``.
|
It is equivalent to an early call to ``update()``.
|
||||||
digest_bytes : integer
|
digest_bytes : integer
|
||||||
The size of the digest, in bytes (24, 32, 48, 64).
|
The size of the digest, in bytes (28, 32, 48, 64).
|
||||||
digest_bits : integer
|
digest_bits : integer
|
||||||
The size of the digest, in bits (224, 256, 384, 512).
|
The size of the digest, in bits (224, 256, 384, 512).
|
||||||
update_after_digest : boolean
|
update_after_digest : boolean
|
||||||
|
|
@ -186,8 +190,8 @@ def new(**kwargs):
|
||||||
if (None, None) == (digest_bytes, digest_bits):
|
if (None, None) == (digest_bytes, digest_bits):
|
||||||
raise TypeError("Digest size (bits, bytes) not provided")
|
raise TypeError("Digest size (bits, bytes) not provided")
|
||||||
if digest_bytes is not None:
|
if digest_bytes is not None:
|
||||||
if digest_bytes not in (24, 32, 48, 64):
|
if digest_bytes not in (28, 32, 48, 64):
|
||||||
raise ValueError("'digest_bytes' must be: 24, 32, 48 or 64")
|
raise ValueError("'digest_bytes' must be: 28, 32, 48 or 64")
|
||||||
else:
|
else:
|
||||||
if digest_bits not in (224, 256, 384, 512):
|
if digest_bits not in (224, 256, 384, 512):
|
||||||
raise ValueError("'digest_bytes' must be: 224, 256, 384 or 512")
|
raise ValueError("'digest_bytes' must be: 224, 256, 384 or 512")
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class KeccakTest(unittest.TestCase):
|
||||||
hobj2 = hobj.new()
|
hobj2 = hobj.new()
|
||||||
self.assertEqual(hobj2.digest_size, digest_bits // 8)
|
self.assertEqual(hobj2.digest_size, digest_bits // 8)
|
||||||
|
|
||||||
for digest_bytes in (24, 32, 48, 64):
|
for digest_bytes in (28, 32, 48, 64):
|
||||||
hobj = keccak.new(digest_bytes=digest_bytes)
|
hobj = keccak.new(digest_bytes=digest_bytes)
|
||||||
self.assertEqual(hobj.digest_size, digest_bytes)
|
self.assertEqual(hobj.digest_size, digest_bytes)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue