Poly1305 is a universal hash family designed by Daniel J. Bernstein in 2002 for use in cryptography. 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, 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 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, and then using ChaCha in the ChaCha20-Poly1305 authenticated cipher deployed in TLS on the internet.
Description
Definition of Poly1305 Poly1305 takes a 16-byte secret key r and an L-byte message m and returns a 16-byte hash Poly1305r(m).
Steps:
Interpret r as a 16-byte little-endian integer. Break the message m of bytes m[0],m[1],m[2],…,m[L−1] into consecutive 16-byte chunks, possibly with a partial final chunk of fewer than 16 bytes. Append a 0x01 byte to each chunk and interpret it as an integer; take the integers as the coefficients of a polynomial. Evaluate the polynomial at the point r modulo the prime 2130−5. Reduce the result modulo 2128 encoded in little-endian return a 16-byte hash. The coefficients ci of the polynomial c1rq+c2rq−1+⋯+cqr, where q=⌈L/16⌉, are: ci=m[16i−16]+28m[16i−15]+216m[16i−14]+⋯+2120m[16i−1]+2128, with the exception that, if L≢0(mod16), then: cq=m[16q−16]+28m[16q−15]+⋯+28(Lmod16)−8m[L−1]+28(Lmod16). The secret key r=(r[0],r[1],r[2],…,r[15]) is restricted to have the bytes r[3],r[7],r[11],r[15]∈{0,1,2,…,15}, i.e., to have their top four bits clear; and to have the bytes r[4],r[8],r[12]∈{0,4,8,…,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:=(Poly1305r(m)+s)mod2128 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′=?(Poly1305r(m′)+s)mod2128. Without knowledge of (r,s), the adversary has probability 8⌈L/16⌉/2106 of finding any (a′,m′)≠(a,m) that will pass verification. However, the same key (r,s) must not be reused for two messages. If the adversary learns a1=(Poly1305r(m1)+s)mod2128,a2=(Poly1305r(m2)+s)mod2128, for m1≠m2, they can subtract a1−a2≡Poly1305r(m1)−Poly1305r(m2)(mod2128) 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 uses the Carter–Wegman structure to authenticate many messages by taking ai:=Hr(mi)+pi to be the authenticator on the ith 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:=AESk(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 ai:=(Poly1305r(mi)+AESk(i))mod2128, 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 AESk 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: δ+(1−C/2128)−(C+1)/2⋅8D⌈L/16⌉2106. 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 AESk(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. 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. XChaCha20-Poly1305 using XChaCha instead of ChaCha or XSalsa20 has also been described.
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[Poly1305r(m1)−Poly1305r(m2)≡d(mod2128)]≤8⌈L/16⌉2106, where r is a uniform random Poly1305 key. This property is sometimes called ϵ-almost-Δ-universality over ℤ/2128ℤ, or ϵ-AΔU, where ϵ=8⌈L/16⌉/2106 in this case.
Of one-time authenticator With a one-time authenticator a=(Poly1305r(m)+s)mod2128, the adversary's success probability for any forgery attempt (a′,m′) on a message m′ of up to L bytes is: Pr[a′=Poly1305r(m′)+s∣a=Poly1305r(m)+s]=Pr[a′=Poly1305r(m′)+a−Poly1305r(m)]=Pr[Poly1305r(m′)−Poly1305r(m)=a′−a]≤8⌈L/16⌉/2106. Here arithmetic inside the Pr[⋯] is taken to be in ℤ/2128ℤ for simplicity.
… excerpt ends here. Continue reading the full article.