Poly1305
{{Short description|Universal hash family used for message authentication in cryptography}}
Poly1305 is a universal hash family designed by Daniel J. Bernstein in 2002 for use in cryptography.{{cite book
|author-last=Aumasson
|author-first=Jean-Philippe
|title=Serious Cryptography: A Practical Introduction to Modern Encryption
|publisher=No Starch Press
|year=2018
|isbn=978-1-59327-826-7
|chapter=Chapter 7: Keyed Hashing
|pages=136–138
|last=Bernstein
|first=Daniel J.
|author-link=Daniel J. Bernstein
|title=The Poly1305-AES message-authentication code
|book-title=Fast Software Encryption: 12th international workshop
|conference=FSE 2005
|editor-last1=Gilbert
|editor-first1=Henri
|editor-last2=Handschuh
|editor-first2=Helena
|location=Paris, France
|series=Lecture Notes in Computer Science
|issue=3557
|publisher=Springer
|date=2005-03-29
|isbn=3-540-26541-4
|url=https://cr.yp.to/papers.html#poly1305
|access-date=2022-10-14
|doi=10.1007/11502760_3
|doi-access=free
}}
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,{{cite book
|author-last=Bernstein
|author-first=Daniel J.
|author-link=Daniel J. Bernstein
|chapter=Protecting communications against forgery
|title=Algorithmic number theory: lattices, number fields, curves and cryptography
|series=Mathematical Sciences Research Institute Publications
|volume=44
|editor-last1=Buhler
|editor-first1=Joe
|editor-last2=Stevenhagen
|editor-first2=Peter
|publisher=Cambridge University Press
|isbn=978-0521808545
|pages=535–549
|url=https://cr.yp.to/papers.html#forgery
|date=2008-05-01
|access-date=2022-10-14
}}
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, a Carter–Wegman authenticator{{cite journal
|author-last1=Wegman
|author-first1=Mark N.
|author-last2=Carter
|author-first2=J. Lawrence
|title=New Hash Functions and Their Use in Authentication and Set Equality
|journal=Journal of Computer and System Sciences
|year=1981
|volume=22
|issue=3
|pages=265–279
|doi=10.1016/0022-0000(81)90033-7
|doi-access=
|author-last1=Boneh
|author-first1=Dan
|author-link1=Dan Boneh
|author-last2=Shoup
|author-first2=Victor
|author-link2=Victor Shoup
|title=A Graduate Course in Applied Cryptography
|edition=Version 0.5
|date=January 2020
|at=§7.4 The Carter-Wegman MAC, pp. 262–269
|url=https://crypto.stanford.edu/~dabo/cryptobook/BonehShoup_0_5.pdf#page=276
|access-date=2022-10-14
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,{{cite tech report
|author-last=Bernstein
|author-first=Daniel J.
|title=Cryptography in NaCl
|number=Document ID: 1ae6a0ecef3073622426b3ee56260d34
|date=2009-03-10
|url=https://cr.yp.to/papers.html#naclcrypto
}}
and then using ChaCha in the ChaCha20-Poly1305 authenticated cipher{{cite ietf
|author-last1=Nir
|author-first1=Y.
|author-last2=Langley
|author-first2=A.
|title=ChaCha20 and Poly1305 for IETF Protocols
|date=May 2015
|rfc=7539
|author-last1=Nir
|author-first1=Y.
|author-last2=Langley
|author-first2=A.
|title=ChaCha20 and Poly1305 for IETF Protocols
|date=June 2018
|rfc=8439
deployed in TLS on the internet.{{cite ietf
|author-last1=Langley
|author-first1=A.
|author-last2=Chang
|author-first2=W.
|author-last3=Mavrogiannopoulos
|author-first3=N.
|author-last4=Strombergson
|author-first4=J.
|author-last5=Josefsson
|author-first5=S.
|title=ChaCha20-Poly1305 Cipher Suites for Transport Layer Security (TLS)
|date=June 2016
|rfc=7905
}}
Description
=Definition of Poly1305=
Poly1305 takes a 16-byte secret key and an -byte message and returns a 16-byte hash .
- 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:
c_i = m[16i - 16] + 2^8 m[16i - 15] + 2^{16} m[16i - 14] + \cdots + 2^{120} m[16i - 1] + 2^{128},
with the exception that, if , then:
c_q = m[16q - 16] + 2^8 m[16q - 15] + \cdots + 2^{8(L \bmod 16) - 8} m[L - 1] + 2^{8 (L \bmod 16)}.
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
a := \bigl(\operatorname{Poly1305}_r(m) + s\bigr) \bmod 2^{128}
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
a' \mathrel{\stackrel?=} \bigl(\operatorname{Poly1305}_r(m') + s\bigr) \bmod 2^{128}.
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
\begin{align}
a_1 &= \bigl(\operatorname{Poly1305}_r(m_1) + s\bigr) \bmod 2^{128}, \\
a_2 &= \bigl(\operatorname{Poly1305}_r(m_2) + s\bigr) \bmod 2^{128},
\end{align}
for , they can subtract
a_1 - a_2 \equiv \operatorname{Poly1305}_r(m_1) - \operatorname{Poly1305}_r(m_2) \pmod{2^{128}}
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 uses the Carter–Wegman structure to authenticate many messages by taking to be the authenticator on the {{math|i}}th 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
a_i := \bigl(\operatorname{Poly1305}_r(m_i) + \operatorname{AES}_k(i)\bigr) \bmod 2^{128},
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:
\delta + \frac{(1 - C/2^{128})^{-(C + 1)/2} \cdot 8 D \lceil L/16\rceil}{2^{106}}.
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.
ChaCha20-Poly1305 does the same but with ChaCha instead of XSalsa20.
XChaCha20-Poly1305 using XChaCha20 instead of XSalsa20 has also been described.{{cite journal |last1=Arciszewski |first1=Scott |title=XChaCha: eXtended-nonce ChaCha and AEAD_XChaCha20_Poly1305 (Expired Internet-Draft)|url=https://tools.ietf.org/html/draft-irtf-cfrg-xchacha-03 |newspaper=Ietf Datatracker |date=10 January 2020 |language=en}}
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
\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}},
where is a uniform random Poly1305 key.{{rp|at=Theorem 3.3, p. 8}}
This property is sometimes called -almost-Δ-universality over , or -AΔU,{{cite conference
|author-last1=Halevi
|author-first1=Shai
|author-link1=Shai Halevi
|author-last2=Krawczyk
|author-first2=Hugo
|author-link2=Hugo Krawczyk
|title=MMH: Software Message Authentication in the Gbit/Second Rates
|editor-last=Biham
|editor-first=Eli
|editor-link=Eli Biham
|book-title=Fast Software Encryption
|conference=FSE 1997
|series=Lecture Notes in Computer Science
|issue=1267
|publisher=Springer
|doi=10.1007/BFb0052345
|doi-access=free
|isbn=978-3-540-63247-4
}}
where in this case.
=Of one-time authenticator=
With a one-time authenticator , the adversary's success probability for any forgery attempt on a message of up to bytes is:
\begin{align}
\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^{106}.
\end{align}
Here arithmetic inside the is taken to be in 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 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 attempts of messages up to bytes is at most:
\delta + \frac{8D \lceil L/16\rceil}{2^{106}}.
=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.{{cite conference
|author-last=Bernstein
|author-first=Daniel J.
|author-link=Daniel J. Bernstein
|title=Stronger security bounds for Wegman-Carter-Shoup authenticators
|book-title=Advances in Cryptology—EUROCRYPT 2005, 24th annual international conference on the theory and applications of cryptographic techniques
|conference=EUROCRYPT 2005
|editor-last=Cramer
|editor-first=Ronald
|location=Aarhus, Denmark
|series=Lecture Notes in Computer Science
|issue=3494
|publisher=Springer
|isbn=3-540-25910-4
|date=2005-02-27
|url=https://cr.yp.to/papers.html#securitywcs
|doi=10.1007/11426639_10
|doi-access=free
}}
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:
\delta + \frac{(1 - C/2^{128})^{-(C + 1)/2} \cdot 8 D \lceil L/16\rceil}{2^{106}}.
{{quote|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)}}
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, 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.[https://cr.yp.to/mac.html A state-of-the-art message-authentication code] on cr.yp.to
Implementations
See also
- ChaCha20-Poly1305 – an AEAD scheme combining the stream cipher ChaCha20 with a variant of Poly1305
References
{{Reflist|30em}}
External links
- [https://cr.yp.to/mac.html Poly1305-AES] reference and optimized implementation by author D. J. Bernstein
- [https://github.com/floodyberry/poly1305-donna Fast Poly1305 implementation in C] on github.com
- NaCl [https://nacl.cr.yp.to/onetimeauth.html one-time authenticator] and [https://nacl.cr.yp.to/secretbox.html authenticated cipher] using Poly1305
{{Cryptography navbox | hash}}
Category:Advanced Encryption Standard