{"id":501,"date":"2026-11-13T13:39:49","date_gmt":"2026-11-13T05:39:49","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-poly1305-authenticates-a-message-under-a-one-time-key\/"},"modified":"2026-11-13T21:59:14","modified_gmt":"2026-11-13T13:59:14","slug":"how-poly1305-authenticates-a-message-under-a-one-time-key","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-poly1305-authenticates-a-message-under-a-one-time-key\/","title":{"rendered":"How Poly1305 authenticates a message under a one-time key"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Poly1305<\/strong> computes a 16-byte tag under a one-time 32-byte key. The first 16 bytes, with selected bits cleared, are the evaluation point <code>r<\/code>. The last 16 bytes are the pad <code>s<\/code>. The message is read in 16-byte chunks. Each chunk gains a trailing <code>0x01<\/code> byte and is added into an accumulator, which is then multiplied by <code>r<\/code> modulo <code>2^130 - 5<\/code>. The tag is the low 128 bits of the accumulator plus <code>s<\/code>.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">A one-time authenticator has to be fast and has to fail if the key is used twice as though it were a long-term MAC key. Poly1305 is a polynomial hash over the prime field <code>2^130 - 5<\/code>, plus a one-time pad <code>s<\/code>. The bit clearing on <code>r<\/code> keeps the multiplications inside the shape the designers chose. ChaCha20-Poly1305 uses a fresh Poly1305 key for every message, taken from the ChaCha20 keystream. The fragment takes the key as an input. It does not derive that key.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">The same key and message reproduce the same tag. A receiver adds and multiplies the received message and compares the whole tag. The security statement is for one message per key. Reusing <code>r<\/code> and <code>s<\/code> across messages is outside that statement. The fragment checks the RFC 8439 message <code>Cryptographic Forum Research Group<\/code>.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Read <code>r<\/code> as a little-endian integer and keep only the bits in <code>0x0ffffffc0ffffffc0ffffffc0fffffff<\/code>.<\/li>\n<li>Read <code>s<\/code> as a little-endian integer from the last 16 key bytes.<\/li>\n<li>For each 16-byte chunk, append <code>0x01<\/code>, add it to the accumulator, and multiply by <code>r<\/code> modulo <code>2^130 - 5<\/code>.<\/li>\n<li>Add <code>s<\/code> and output the low 16 bytes.<\/li>\n<\/ol>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when the same key authenticates two messages<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Reuse one Poly1305 key for a second message<\/td>\n<td>The construction is one-time. A second message under the same <code>r<\/code> and <code>s<\/code> is not the stated authenticator.<\/td>\n<\/tr>\n<tr>\n<td>Skip the bit clearing on <code>r<\/code><\/td>\n<td>The published function clears those bits. Leaving them set is a different polynomial.<\/td>\n<\/tr>\n<tr>\n<td>Append <code>0x01<\/code> only on the last chunk<\/td>\n<td>Every chunk, including a partial last chunk, is marked with the extra byte.<\/td>\n<\/tr>\n<tr>\n<td>Use the tag as a cipher<\/td>\n<td>The tag detects a change. It does not hide the message.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">HMAC is a reusable message authentication code built from a hash. Poly1305 is the one-time polynomial tag.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment evaluates the RFC 8439 Poly1305 tag. It prints <code>a8061dc1305136c6c22b8baf0c0127a9<\/code>.<\/p>\n\n<pre><code class=\"language-python\">def poly1305(msg: bytes, key: bytes) -&gt; bytes:\n    r = int.from_bytes(key[:16], &quot;little&quot;) &amp; 0x0FFFFFFC0FFFFFFC0FFFFFFC0FFFFFFF\n    s = int.from_bytes(key[16:], &quot;little&quot;)\n    acc = 0\n    prime = (1 &lt;&lt; 130) - 5\n    for off in range(0, len(msg), 16):\n        block = msg[off : off + 16]\n        n = int.from_bytes(block + b&quot;\\x01&quot;, &quot;little&quot;)\n        acc = (acc + n) * r % prime\n    tag = (acc + s) &amp; ((1 &lt;&lt; 128) - 1)\n    return tag.to_bytes(16, &quot;little&quot;)\n\nkey = bytes.fromhex(&quot;85d6be7857556d337f4452fe42d506a80103808afb0db2fd4abff6af4149f51b&quot;)\ntag = poly1305(b&quot;Cryptographic Forum Research Group&quot;, key)\nassert tag.hex() == &quot;a8061dc1305136c6c22b8baf0c0127a9&quot;\nprint(tag.hex())\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Poly1305 is the tag in <strong>ChaCha20-Poly1305<\/strong>, the AEAD in TLS, WireGuard, and OpenSSH. Each message gets a fresh one-time key taken from the ChaCha20 keystream. HMAC is the reusable tag built from a hash.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop Poly1305 where the same 32-byte key would be reused. Keep it where each message gets a fresh key, as it does when that key is taken from a ChaCha20 block.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for Poly1305 returns the clamped <code>r<\/code>, the prime <code>2^130 - 5<\/code>, and the RFC tag. <strong>Poly1305 evaluates a polynomial modulo <code>2^130 - 5<\/code> at a clamped one-time point and adds a one-time pad to produce a 16-byte tag.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: Poly1305 computes a 16-byte tag under a one-time 32-byte key. The first 16 bytes, with selected bits cleared, are the evaluation point r. The last 16 bytes are the pad s. The message is read in 16-byte chunks. Each chunk gains a trailing 0x01 byte and is&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,49],"tags":[],"class_list":["post-501","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-cryptography"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=501"}],"version-history":[{"count":1,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/501\/revisions"}],"predecessor-version":[{"id":713,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/501\/revisions\/713"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}