{"id":51578781,"url":"https://github.com/systemslibrarian/crypto-lab-poly1305-mac","last_synced_at":"2026-07-11T03:32:25.662Z","repository":{"id":365578864,"uuid":"1204636743","full_name":"systemslibrarian/crypto-lab-poly1305-mac","owner":"systemslibrarian","description":"Browser-based Poly1305 MAC demo — polynomial evaluation over GF(2¹³⁰−5), constant-time tag verification, key-reuse attack visualizer, and Polynomial Stepper. Part of crypto-lab.","archived":false,"fork":false,"pushed_at":"2026-06-28T02:13:05.000Z","size":105,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-28T02:18:50.783Z","etag":null,"topics":["aead","browser-demo","chacha20-poly1305","constant-time","crypto-lab","cryptography","gf2-130-5","key-reuse","mac","message-authentication","noble-ciphers","poly1305"],"latest_commit_sha":null,"homepage":"https://systemslibrarian.github.io/crypto-lab-poly1305-mac/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/systemslibrarian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-08T07:29:09.000Z","updated_at":"2026-06-28T02:13:09.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/systemslibrarian/crypto-lab-poly1305-mac","commit_stats":null,"previous_names":["systemslibrarian/crypto-lab-poly1305-mac"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/systemslibrarian/crypto-lab-poly1305-mac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-poly1305-mac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-poly1305-mac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-poly1305-mac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-poly1305-mac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/systemslibrarian","download_url":"https://codeload.github.com/systemslibrarian/crypto-lab-poly1305-mac/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemslibrarian%2Fcrypto-lab-poly1305-mac/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35350133,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-11T02:00:05.354Z","response_time":104,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aead","browser-demo","chacha20-poly1305","constant-time","crypto-lab","cryptography","gf2-130-5","key-reuse","mac","message-authentication","noble-ciphers","poly1305"],"created_at":"2026-07-11T03:32:25.569Z","updated_at":"2026-07-11T03:32:25.642Z","avatar_url":"https://github.com/systemslibrarian.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crypto-lab-poly1305-mac\n\n## What It Is\n\nPoly1305 is a one-time message authentication code (MAC) designed by Daniel J. Bernstein. It takes a 32-byte key and a variable-length message and produces a 128-bit authentication tag by evaluating a polynomial over the prime field GF(2^130 − 5). The security model is information-theoretic: as long as each key is used only once, no amount of computation gives an attacker better than a 2^−128 chance of forging a valid tag. This demo uses the standalone `poly1305` export from `@noble/ciphers/_poly1305.js` to compute and verify tags entirely in the browser.\n\n## When to Use It\n\n- **Authenticating a single message under a fresh key** — Poly1305's one-time guarantee makes it ideal when a higher-level protocol (such as ChaCha20-Poly1305) derives a unique key per message.\n- **High-throughput MAC in AEAD constructions** — Poly1305's arithmetic is simple enough for constant-time implementations on commodity hardware, making it a common choice inside TLS 1.3 and WireGuard.\n- **Replacing HMAC when polynomial MAC performance matters** — On platforms without AES-NI, Poly1305 can be faster than HMAC-SHA-256 while offering a strong forgery bound.\n- **When you need a MAC with a provable security bound** — Poly1305's forgery probability is at most the number of message blocks divided by the field size, a concrete bound absent from many hash-based MACs.\n- **Do NOT use standalone Poly1305 when you cannot guarantee one-time key usage** — reusing a key across two messages lets an attacker recover the secret r value and forge tags for any future message. This is a teaching demo, not a production MAC implementation.\n\n## Live Demo\n\n**[systemslibrarian.github.io/crypto-lab-poly1305-mac](https://systemslibrarian.github.io/crypto-lab-poly1305-mac/)**\n\nGenerate a random 32-byte key, type any message, and compute its Poly1305 authentication tag. Three verification scenarios let you confirm the original tag, tamper the message (a trailing space), or flip a single tag byte — all with constant-time comparison. The Polynomial Stepper section visualises the first four blocks as `(accumulator + block) × r mod p`, and the Key Reuse Warning computes two MACs under the same key to demonstrate why reuse is fatal.\n\n## What Can Go Wrong\n\n- **Key reuse** — Poly1305 is a one-time MAC. Authenticating two different messages under the same 32-byte key lets an attacker solve for the secret r and s values algebraically and forge tags for any message.\n- **Non-constant-time tag comparison** — Comparing tags with an early-exit `===` loop leaks how many leading bytes matched, giving an attacker a timing oracle to iteratively guess a valid tag.\n- **Unclamped r value** — The first 16 bytes of the key must have specific bits zeroed (clamping). Skipping this step permits classes of polynomial forgery that the clamping mask is designed to block.\n- **Using Poly1305 without an AEAD wrapper** — Standalone Poly1305 authenticates but does not encrypt. Sending a cleartext message with only a Poly1305 tag gives integrity without confidentiality, which is rarely the correct security goal.\n- **Nonce misuse in ChaCha20-Poly1305** — In the AEAD construction, repeating a nonce under the same encryption key re-derives the same Poly1305 sub-key, collapsing back to the key-reuse failure above.\n\n## Real-World Usage\n\n- **TLS 1.3** — The `TLS_CHACHA20_POLY1305_SHA256` cipher suite uses Poly1305 as the MAC inside its AEAD, protecting every record on connections that negotiate this suite.\n- **WireGuard** — All tunnel packets are authenticated with ChaCha20-Poly1305, relying on Poly1305 for per-packet integrity and authenticity.\n- **OpenSSH** — The `chacha20-poly1305@openssh.com` cipher uses Poly1305 to authenticate both the packet length and payload, replacing the older HMAC-based transport MACs.\n- **NaCl / libsodium `crypto_secretbox`** — The widely deployed `secretbox` construction pairs XSalsa20 encryption with Poly1305 authentication, used in applications from Signal to Keybase.\n- **IETF RFC 8439** — The canonical specification for ChaCha20-Poly1305, referenced by QUIC (RFC 9001), Noise Protocol Framework, and other modern protocols.\n\n## How to Run Locally\n\n```bash\ngit clone https://github.com/systemslibrarian/crypto-lab-poly1305-mac\ncd crypto-lab-poly1305-mac\nnpm install\nnpm run dev\n```\n\n## Related Demos\n- [crypto-lab-mac-race](https://systemslibrarian.github.io/crypto-lab-mac-race/) — head-to-head comparison of HMAC, CMAC, Poly1305, and GHASH.\n- [crypto-lab-chacha20-stream](https://systemslibrarian.github.io/crypto-lab-chacha20-stream/) — the ChaCha20 keystream that pairs with Poly1305 in the AEAD construction.\n- [crypto-lab-aes-modes](https://systemslibrarian.github.io/crypto-lab-aes-modes/) — AES-GCM and other authenticated-encryption modes for comparison.\n- [crypto-lab-nonce-guard](https://systemslibrarian.github.io/crypto-lab-nonce-guard/) — what nonce reuse does to AEAD constructions, the failure mode behind ChaCha20-Poly1305 misuse.\n- [crypto-lab-babel-hash](https://systemslibrarian.github.io/crypto-lab-babel-hash/) — SHA-256, BLAKE3, and HMAC, the hash-based MAC alternative to polynomial MACs.\n\n## Tests\n\nThe test suite verifies correctness against the canonical **RFC 8439 §2.5.2** Poly1305 test vector (key, message, clamped `r`, and tag), checks that tampering with either the message or the tag fails verification, and runs an automated [axe-core](https://github.com/dequelabs/axe-core) accessibility audit over the rendered UI. Color contrast for both themes meets WCAG 2.1 AA (≥ 4.5:1 for text).\n\n---\n\n*One of 120+ browser demos in the [Crypto Lab](https://crypto-lab.systemslibrarian.dev/) suite.*\n\n*\"So whether you eat or drink or whatever you do, do it all for the glory of God.\" — 1 Corinthians 10:31*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemslibrarian%2Fcrypto-lab-poly1305-mac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsystemslibrarian%2Fcrypto-lab-poly1305-mac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemslibrarian%2Fcrypto-lab-poly1305-mac/lists"}