ppad-poly1305-0.4.2: A fast Poly1305 MAC
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

Crypto.MAC.Poly1305

Description

A pure Poly1305 MAC implementation, as specified by RFC 8439.

Synopsis

Poly1305 message authentication code

newtype MAC Source #

A Poly1305 message authentication code.

Note that you should compare MACs for equality using the Eq instance, which performs the comparison in constant time, instead of unwrapping and comparing the underlying ByteStrings.

>>> let Just foo@(MAC bs0) = mac key "hi"
>>> let Just bar@(MAC bs1) = mac key "there"
>>> foo == bar -- do this
False
>>> bs0 == bs1 -- don't do this
False

Constructors

MAC ByteString 

Instances

Instances details
Show MAC Source # 
Instance details

Defined in Crypto.MAC.Poly1305

Methods

showsPrec :: Int -> MAC -> ShowS #

show :: MAC -> String #

showList :: [MAC] -> ShowS #

Eq MAC Source # 
Instance details

Defined in Crypto.MAC.Poly1305

Methods

(==) :: MAC -> MAC -> Bool #

(/=) :: MAC -> MAC -> Bool #

mac Source #

Arguments

:: ByteString

256-bit one-time key

-> ByteString

arbitrary-length message

-> Maybe MAC

128-bit message authentication code

Produce a Poly1305 MAC for the provided message, given the provided key.

Per RFC8439: the key, which is essentially a one-time key, should be unique, and MUST be unpredictable for each invocation.

The key must be exactly 256 bits in length.

>>> mac "i'll never use this key again!!!" "a message needing authentication"
Just "O'\231Z\224\149\148\246\203[}\210\203\b\200\207"