Skip to content

Commit f8f9698

Browse files
committed
Fix Sha3.copy() losing digest_size for non-384 variants
1 parent f68ac28 commit f8f9698

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

wolfcrypt/hashes.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,7 @@ class Sha3(_Hash):
209209
SHA3_384_DIGEST_SIZE = 48
210210
SHA3_512_DIGEST_SIZE = 64
211211

212-
def __init__(self): # pylint: disable=W0231
213-
self._native_object = _ffi.new(self._native_type)
214-
self.digest_size = SHA3_384_DIGEST_SIZE
215-
ret = self._init()
216-
if ret < 0: # pragma: no cover
217-
raise WolfCryptError("Sha3 init error (%d)" % ret)
218-
219-
def __init__(self, string, size=SHA3_384_DIGEST_SIZE): # pylint: disable=W0231
212+
def __init__(self, string=None, size=SHA3_384_DIGEST_SIZE): # pylint: disable=W0231
220213
self._native_object = _ffi.new(self._native_type)
221214
self.digest_size = size
222215
ret = self._init()
@@ -225,6 +218,15 @@ def __init__(self, string, size=SHA3_384_DIGEST_SIZE): # pylint: disable=W0231
225218
if string:
226219
self.update(string)
227220

221+
@classmethod
222+
def new(cls, string=None, size=SHA3_384_DIGEST_SIZE):
223+
return cls(string, size)
224+
225+
def copy(self):
226+
c = Sha3(size=self.digest_size)
227+
_ffi.memmove(c._native_object, self._native_object, self._native_size)
228+
return c
229+
228230
def _init(self):
229231
if (self.digest_size != Sha3.SHA3_224_DIGEST_SIZE and
230232
self.digest_size != Sha3.SHA3_256_DIGEST_SIZE and

0 commit comments

Comments
 (0)