stdKeys, MACs and passwords
std.poly1305
The Poly1305 one-time message authentication code.
import std.hash
import std.poly1305Poly1305 (RFC 8439) is a fast MAC whose 32-byte key must be used for one message only. It is normally taken from a ChaCha20 block, which is what std.aead does, so use that for messages. Use Poly1305 directly only when a protocol asks for it.
| Call | What it does |
|---|---|
poly1305.sign(key, msg) | The 16-byte tag. |
poly1305.verify(key, msg, tag) | Compares in constant time. |
poly.new(key), update!, finish | The streaming form, for a message in pieces. |
import std.hash
import std.poly1305
fn main() {
const key = hash.fromHex("0101010101010101010101010101010101010101010101010101010101010101") ?? []
const msg = "hello".bytes().toList()
const tag = poly1305.sign(key, msg)
print(hash.hex(tag))
print(poly1305.verify(key, msg, tag), poly1305.verify(key, "hellp".bytes().toList(), tag))
}b4684f74b0b2abab40b1abab40b1abab
true falseNo branch or index depends on the data. Checked against the cryptography package's Poly1305.