From: Mark Wooding Date: Sun, 17 Nov 2019 03:14:51 +0000 (+0000) Subject: catacomb/__init__.py: Make KMAC `copy' work. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/commitdiff_plain/688625b6d288ff893f5e96dd3bd7f10110e23639?ds=sidebyside catacomb/__init__.py: Make KMAC `copy' work. Two fixes needed: * Return the `new' object from `copy'. * Introduce a `_bare_new' class method to handle constructing the destination object, because `KMAC...' objects need a key argument. --- diff --git a/catacomb/__init__.py b/catacomb/__init__.py index ff771b9..8713ab7 100644 --- a/catacomb/__init__.py +++ b/catacomb/__init__.py @@ -237,7 +237,7 @@ class _ShakeBase (_HashBase): me._h = me._SHAKE(perso = perso, func = me._FUNC) ## Delegate methods... - def copy(me): new = me.__class__(); new._copy(me) + def copy(me): new = me.__class__._bare_new(); new._copy(me); return new def _copy(me, other): me._h = other._h.copy() def hash(me, m): me._h.hash(m); return me def xof(me): me._h.xof(); return me @@ -251,6 +251,8 @@ class _ShakeBase (_HashBase): def buffered(me): return me._h.buffered @property def rate(me): return me._h.rate + @classmethod + def _bare_new(cls): return cls() class _tmp: def check(me, h): @@ -289,6 +291,8 @@ class KMAC (_ShakeBase): def xof(me): me.rightenc(0) return super(KMAC, me).xof() + @classmethod + def _bare_new(cls): return cls("") class KMAC128 (KMAC): _SHAKE = Shake128; _TAGSZ = 16 class KMAC256 (KMAC): _SHAKE = Shake256; _TAGSZ = 32