Make Mac class prevent further updates or final after finalisation. Keep cached values for hashlib API.

This commit is contained in:
Leo Vasanko
2025-11-09 08:53:50 -06:00
parent 67c2958384
commit 62fc8fa855
10 changed files with 493 additions and 54 deletions
+1 -4
View File
@@ -57,14 +57,11 @@ def bench_mac(ciph) -> None:
buf = bytearray(MSG_LEN)
buf[:] = _random_bytes(len(buf))
mac0 = ciph.Mac(key, nonce, maclen=ciph.MACBYTES_LONG)
mac_out = bytearray(ciph.MACBYTES_LONG)
t0 = time.perf_counter()
for _ in range(ITERATIONS):
mac = mac0.clone()
mac.update(buf)
mac.final(into=mac_out)
m = ciph.mac(key, nonce, buf, maclen=ciph.MACBYTES_LONG, into=mac_out)
t1 = time.perf_counter()
_ = mac_out[0]