Description
Definition of Poly1305
Poly1305 takes a 16-byte secret key
and an
-byte message
and returns a 16-byte hash
.
To do this, Poly1305:[2][1]
- Interprets
as a little-endian 16-byte integer.
- Breaks the message
into consecutive 16-byte chunks.
- Interprets the 16-byte chunks as 17-byte little-endian integers by appending a 1 byte to every 16-byte chunk, to be used as coefficients of a polynomial.
- Evaluates the polynomial at the point
modulo the prime
.
- Reduces the result modulo
encoded in little-endian return a 16-byte hash.
The coefficients
of the polynomial
, where
, are:
![{\displaystyle c_{i}=m[16i-16]+2^{8}m[16i-15]+2^{16}m[16i-14]+\cdots +2^{120}m[16i-1]+2^{128},}](https://wikimedia.org/api/rest_v1/media/math/render/svg/420a14440f15ef5998356cd1761e02413ecd1358)
with the exception that, if
, then:
![{\displaystyle c_{q}=m[16q-16]+2^{8}m[16q-15]+\cdots +2^{8(L{\bmod {1}}6)-8}m[L-1]+2^{8(L{\bmod {1}}6)}.}](https://wikimedia.org/api/rest_v1/media/math/render/svg/fb3834d29f9dce2959375de095527e5c6f642cad)
The secret key
is restricted to have the bytes
, i.e., to have their top four bits clear; and to have the bytes
, i.e., to have their bottom two bits clear.
Thus there are
distinct possible values of
.
Use as a one-time authenticator
If
is a secret 16-byte string interpreted as a little-endian integer, then

is called the authenticator for the message
.
If a sender and recipient share the 32-byte secret key
in advance, chosen uniformly at random, then the sender can transmit an authenticated message
.
When the recipient receives an alleged authenticated message
(which may have been modified in transmit by an adversary), they can verify its authenticity by testing whether
Without knowledge of
, the adversary has probability
of finding any
that will pass verification.
However, the same key
must not be reused for two messages.
If the adversary learns

for
, they can subtract

and find a root of the resulting polynomial to recover a small list of candidates for the secret evaluation point
, and from that the secret pad
.
The adversary can then use this to forge additional messages with high probability.
Use in Poly1305-AES as a Carter–Wegman authenticator
The original Poly1305-AES proposal[2] uses the Carter–Wegman structure[4][5] to authenticate many messages by taking
to be the authenticator on the ith message
, where
is a universal hash family and
is an independent uniform random hash value that serves as a one-time pad to conceal it.
Poly1305-AES uses AES-128 to generate
, where
is encoded as a 16-byte little-endian integer.
Specifically, a Poly1305-AES key is a 32-byte pair
of a 16-byte evaluation point
, as above, and a 16-byte AES key
.
The Poly1305-AES authenticator on a message
is

where 16-byte strings and integers are identified by little-endian encoding.
Note that
is reused between messages.
Without knowledge of
, the adversary has low probability of forging any authenticated messages that the recipient will accept as genuine.
Suppose the adversary sees
authenticated messages and attempts
forgeries, and can distinguish
from a uniform random permutation with advantage at most
.
(Unless AES is broken,
is very small.)
The adversary's chance of success at a single forgery is at most:

The message number
must never be repeated with the same key
.
If it is, the adversary can recover a small list of candidates for
and
, as with the one-time authenticator, and use that to forge messages.
Use in NaCl and ChaCha20-Poly1305
The NaCl crypto_secretbox_xsalsa20poly1305 authenticated cipher uses a message number
with the XSalsa20 stream cipher to generate a per-message key stream, the first 32 bytes of which are taken as a one-time Poly1305 key
and the rest of which is used for encrypting the message.
It then uses Poly1305 as a one-time authenticator for the ciphertext of the message.[6]
ChaCha20-Poly1305 uses the first 32 bytes of the ChaCha stream cipher output to generate a one-time Poly1305 key, discards the next 32 bytes, and uses the rest to encrypt the message.[8]
XChaCha20-Poly1305 using XChaCha instead of ChaCha or XSalsa20 has also been described.[10]
Security
The security of Poly1305 and its derivatives against forgery follows from its bounded difference probability as a universal hash family:
If
and
are messages of up to
bytes each, and
is any 16-byte string interpreted as a little-endian integer, then
![{\displaystyle \Pr[\operatorname {Poly1305} _{r}(m_{1})-\operatorname {Poly1305} _{r}(m_{2})\equiv d{\pmod {2^{128}}}]\leq {\frac {8\lceil L/16\rceil }{2^{106}}},}](https://wikimedia.org/api/rest_v1/media/math/render/svg/3d9552ec1c6b9da0378912a80f8dcfab2cb8324a)
where
is a uniform random Poly1305 key.[2]: Theorem 3.3, p. 8
This property is sometimes called
-almost-Δ-universality over
, or
-AΔU,[11]
where
in this case.
Of Poly1305-AES
The security of Poly1305-AES against forgery follows from the Carter–Wegman–Shoup structure, which instantiates a Carter–Wegman authenticator with a permutation to generate the per-message pad.[12]
If an adversary sees
authenticated messages and attempts
forgeries of messages of up to
bytes, and if the adversary has distinguishing advantage at most
against AES-128 as a pseudorandom permutation, then the probability the adversary succeeds at any one of the
forgeries is at most:[2]

For instance, assuming that messages are packets up to 1024 bytes; that the attacker sees 264 messages authenticated under a Poly1305-AES key; that the attacker attempts a whopping 275 forgeries; and that the attacker cannot break AES with probability above δ; then, with probability at least 0.999999 − δ, all the 275 are rejected
— Bernstein, Daniel J. (2005)[2]