Skip to Content
oxcrypto

Universal hashes

One-time-key authenticators used inside AEAD constructions.

Universal hashes are one-time-key primitives. A key must authenticate only one message; reusing it lets an attacker forge tags or recover the key. AEAD modes derive a fresh key per nonce. Use HMAC or CMAC when you need a reusable key.

The API matches the MAC family: one-shot mac(key, data) and verify(key, data, tag), and incremental new(key) returning a MacState. verify raises oxcrypto.InvalidTag; its tag comparison is the digest crate's, which is written to run in constant time.

The poly1305, ghash and polyval crates are written to zeroize the Poly1305 r, s and accumulator and the GHASH and POLYVAL H powers and accumulator when a state is dropped, and oxcrypto zeroizes the buffered partial block. oxcrypto has not verified this independently. The MAC zeroization notes on Python-owned keys and tags apply here too.

from oxcrypto.universal_hash.poly1305 import POLY1305

key = POLY1305.POLY1305.generate_key()
tag = POLY1305.POLY1305.mac(key, b"message")

Algorithms

  • Poly1305 RFC 8439 one-time authenticator.
  • GHASH The GCM hash from NIST SP 800-38D.
  • POLYVAL The AES-GCM-SIV hash from RFC 8452.

On this page