aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography/hazmat/primitives/cmac.py
diff options
context:
space:
mode:
Diffstat (limited to 'cryptography/hazmat/primitives/cmac.py')
-rw-r--r--cryptography/hazmat/primitives/cmac.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/cryptography/hazmat/primitives/cmac.py b/cryptography/hazmat/primitives/cmac.py
index 7ae5c118..d5e26a57 100644
--- a/cryptography/hazmat/primitives/cmac.py
+++ b/cryptography/hazmat/primitives/cmac.py
@@ -59,9 +59,11 @@ class CMAC(object):
def verify(self, signature):
if not isinstance(signature, bytes):
raise TypeError("signature must be bytes.")
- digest = self.finalize()
- if not constant_time.bytes_eq(digest, signature):
- raise InvalidSignature("Signature did not match digest.")
+ if self._ctx is None:
+ raise AlreadyFinalized("Context was already finalized.")
+
+ ctx, self._ctx = self._ctx, None
+ ctx.verify(signature)
def copy(self):
if self._ctx is None: