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

This commit is contained in:
2025-11-09 20:53:19 +00:00
parent 7682d5bc8b
commit 0d63844201
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]