Poly1305 Explained

Poly1305 is a universal hash family designed by Daniel J. Bernstein for use in cryptography.[1]

As with any universal hash family, Poly1305 can be used as a one-time message authentication code to authenticate a single message using a secret key shared between sender and recipient,[2] similar to the way that a one-time pad can be used to conceal the content of a single message using a secret key shared between sender and recipient.

Originally Poly1305 was proposed as part of Poly1305-AES,[3] a Carter - Wegman authenticator[4] [5] [1] that combines the Poly1305 hash with AES-128 to authenticate many messages using a single short key and distinct message numbers.Poly1305 was later applied with a single-use key generated for each message using XSalsa20 in the NaCl crypto_secretbox_xsalsa20poly1305 authenticated cipher,[6] and then using ChaCha in the ChaCha20-Poly1305 authenticated cipher[7] [8] [1] deployed in TLS on the internet.[9]

Description

Definition of Poly1305

Poly1305 takes a 16-byte secret key

r

and an

L

-byte message

m

and returns a 16-byte hash

\operatorname{Poly1305}r(m)

.To do this, Poly1305:[3] [1]
  1. Interprets

r

as a little-endian 16-byte integer.
  1. Breaks the message

m=(m[0],m[1],m[2],...c,m[L-1])

into consecutive 16-byte chunks.
  1. 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.
  2. Evaluates the polynomial at the point

r

modulo the prime

2130-5

.
  1. Reduces the result modulo

2128

encoded in little-endian return a 16-byte hash.

The coefficients

ci

of the polynomial

c1rq+c2rq++cqr

, where

q=\lceilL/16\rceil

, are:

c_i = m[16i - 16] + 2^8 m[16i - 15] + 2^ m[16i - 14] + \cdots + 2^ m[16i - 1] + 2^,

with the exception that, if

L\not\equiv0\pmod{16}

, then:

c_q = m[16q - 16] + 2^8 m[16q - 15] + \cdots + 2^ m[L - 1] + 2^.

The secret key

r=(r[0],r[1],r[2],...c,r[15])

is restricted to have the bytes

r[3],r[7],r[11],r[15]\in\{0,1,2,...c,15\}

, i.e., to have their top four bits clear; and to have the bytes

r[4],r[8],r[12]\in\{0,4,8,...c,252\}

, i.e., to have their bottom two bits clear.Thus there are

2106

distinct possible values of

r

.

Use as a one-time authenticator

If

s

is a secret 16-byte string interpreted as a little-endian integer, then

a := \bigl(\operatorname_r(m) + s\bigr) \bmod 2^

is called the authenticator for the message

m

.If a sender and recipient share the 32-byte secret key

(r,s)

in advance, chosen uniformly at random, then the sender can transmit an authenticated message

(a,m)

.When the recipient receives an alleged authenticated message

(a',m')

(which may have been modified in transmit by an adversary), they can verify its authenticity by testing whether

a' \mathrel \bigl(\operatorname_r(m') + s\bigr) \bmod 2^.Without knowledge of

(r,s)

, the adversary has probability

8\lceilL/16\rceil/2106

of finding any

(a',m')\ne(a,m)

that will pass verification.

However, the same key

(r,s)

must not be reused for two messages.If the adversary learns

\begin a_1 &= \bigl(\operatorname_r(m_1) + s\bigr) \bmod 2^, \\ a_2 &= \bigl(\operatorname_r(m_2) + s\bigr) \bmod 2^,\end

for

m1\nem2

, they can subtract

a_1 - a_2 \equiv \operatorname_r(m_1) - \operatorname_r(m_2) \pmod

and find a root of the resulting polynomial to recover a small list of candidates for the secret evaluation point

r

, and from that the secret pad

s

.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[3] uses the Carter–Wegman structure[4] [5] to authenticate many messages by taking

ai:=Hr(mi)+pi

to be the authenticator on the th message

mi

, where

Hr

is a universal hash family and

pi

is an independent uniform random hash value that serves as a one-time pad to conceal it.Poly1305-AES uses AES-128 to generate

pi:=\operatorname{AES}k(i)

, where

i

is encoded as a 16-byte little-endian integer.

Specifically, a Poly1305-AES key is a 32-byte pair

(r,k)

of a 16-byte evaluation point

r

, as above, and a 16-byte AES key

k

.The Poly1305-AES authenticator on a message

mi

is

a_i := \bigl(\operatorname_r(m_i) + \operatorname_k(i)\bigr) \bmod 2^,

where 16-byte strings and integers are identified by little-endian encoding.Note that

r

is reused between messages.

Without knowledge of

(r,k)

, the adversary has low probability of forging any authenticated messages that the recipient will accept as genuine.Suppose the adversary sees

C

authenticated messages and attempts

D

forgeries, and can distinguish

\operatorname{AES}k

from a uniform random permutation
with advantage at most

\delta

.(Unless AES is broken,

\delta

is very small.)The adversary's chance of success at a single forgery is at most:

\delta + \frac.

The message number

i

must never be repeated with the same key

(r,k)

.If it is, the adversary can recover a small list of candidates for

r

and

\operatorname{AES}k(i)

, 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

i

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

(ri,si)

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 does the same but with ChaCha instead of XSalsa20.[8]

Security

The security of Poly1305 and its derivatives against forgery follows from its bounded difference probability as a universal hash family:If

m1

and

m2

are messages of up to

L

bytes each, and

d

is any 16-byte string interpreted as a little-endian integer, then

\Pr[\operatorname{Poly1305}_r(m_1) - \operatorname{Poly1305}_r(m_2) \equiv d \pmod{2^{128}}] \leq \frac,

where

r

is a uniform random Poly1305 key.[3]

This property is sometimes called

\epsilon

-almost-Δ-universality over

Z/2128Z

, or

\epsilon

-AΔU,[10] where

\epsilon=8\lceilL/16\rceil/2106

in this case.

Of one-time authenticator

With a one-time authenticator

a=l(\operatorname{Poly1305}r(m)+sr)\bmod2128

, the adversary's success probability for any forgery attempt

(a',m')

on a message

m'

of up to

L

bytes is:

\begin \Pr[&a' = \operatorname{Poly1305}_r(m') + s \mathrel\mid a = \operatorname{Poly1305}_r(m) + s] \\ &= \Pr[a' = \operatorname{Poly1305}_r(m') + a - \operatorname{Poly1305}_r(m)] \\ &= \Pr[\operatorname{Poly1305}_r(m') - \operatorname{Poly1305}_r(m) = a' - a] \\ &\leq 8\lceil L/16\rceil/2^.\end

Here arithmetic inside the

\Pr[]

is taken to be in

Z/2128Z

for simplicity.

Of NaCl and ChaCha20-Poly1305

For NaCl crypto_secretbox_xsalsa20poly1305 and ChaCha20-Poly1305, the adversary's success probability at forgery is the same for each message independently as for a one-time authenticator, plus the adversary's distinguishing advantage

\delta

against XSalsa20 or ChaCha as pseudorandom functions used to generate the per-message key.In other words, the probability that the adversary succeeds at a single forgery after

D

attempts of messages up to

L

bytes is at most:

\delta + \frac.

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.[11] If an adversary sees

C

authenticated messages and attempts

D

forgeries of messages of up to

L

bytes, and if the adversary has distinguishing advantage at most

\delta

against AES-128 as a pseudorandom permutation, then the probability the adversary succeeds at any one of the

D

forgeries is at most:[3]

\delta + \frac.

Speed

Poly1305-AES can be computed at high speed in various CPUs: for an n-byte message, no more than 3.1n + 780 Athlon cycles are needed,[3] for example.The author has released optimized source code for Athlon, Pentium Pro/II/III/M, PowerPC, and UltraSPARC, in addition to non-optimized reference implementations in C and C++ as public domain software.[12]

Implementations

Below is a list of cryptography libraries that support Poly1305:

See also

External links

Notes and References

  1. Book: Aumasson. Jean-Philippe. Serious Cryptography: A Practical Introduction to Modern Encryption. No Starch Press. 2018. 978-1-59327-826-7. Chapter 7: Keyed Hashing. 136–138.
  2. Book: Bernstein. Daniel J.. Daniel J. Bernstein. Protecting communications against forgery. Algorithmic number theory: lattices, number fields, curves and cryptography. Mathematical Sciences Research Institute Publications. 44. Buhler. Joe. Stevenhagen. Peter. Cambridge University Press. 978-0521808545. 535–549. 2008-05-01. 2022-10-14.
  3. Bernstein. Daniel J.. Daniel J. Bernstein. The Poly1305-AES message-authentication code. Fast Software Encryption: 12th international workshop. FSE 2005. Gilbert. Henri. Handschuh. Helena. Paris, France. Lecture Notes in Computer Science. 3557. Springer. 2005-03-29. 3-540-26541-4. 2022-10-14. 10.1007/11502760_3. free.
  4. Wegman. Mark N.. Carter. J. Lawrence. New Hash Functions and Their Use in Authentication and Set Equality. Journal of Computer and System Sciences. 1981. 22. 3. 265–279. 10.1016/0022-0000(81)90033-7.
  5. Book: Boneh. Dan. Dan Boneh. Shoup. Victor. Victor Shoup. A Graduate Course in Applied Cryptography. Version 0.5. January 2020. §7.4 The Carter-Wegman MAC, pp. 262 - 269. 2022-10-14.
  6. Bernstein. Daniel J.. Cryptography in NaCl. Document ID: 1ae6a0ecef3073622426b3ee56260d34. 2009-03-10.
  7. Nir. Y.. Langley. A.. ChaCha20 and Poly1305 for IETF Protocols. May 2015. 7539.
  8. Nir. Y.. Langley. A.. ChaCha20 and Poly1305 for IETF Protocols. June 2018. 8439.
  9. Langley. A.. Chang. W.. Mavrogiannopoulos. N.. Strombergson. J.. Josefsson. S.. ChaCha20-Poly1305 Cipher Suites for Transport Layer Security (TLS). June 2016. 7905.
  10. Halevi. Shai. Shai Halevi. Krawczyk. Hugo. Hugo Krawczyk. MMH: Software Message Authentication in the Gbit/Second Rates. Biham. Eli. Eli Biham. Fast Software Encryption. FSE 1997. Lecture Notes in Computer Science. 1267. Springer. 10.1007/BFb0052345. free. 978-3-540-63247-4.
  11. Bernstein. Daniel J.. Daniel J. Bernstein. Stronger security bounds for Wegman-Carter-Shoup authenticators. Advances in Cryptology - EUROCRYPT 2005, 24th annual international conference on the theory and applications of cryptographic techniques. EUROCRYPT 2005. Cramer. Ronald. Aarhus, Denmark. Lecture Notes in Computer Science. 3494. Springer. 3-540-25910-4. 2005-02-27. 10.1007/11426639_10. free.
  12. https://cr.yp.to/mac.html A state-of-the-art message-authentication code