tc_poly1305 0.1.0

The Poly1305 one-time message authentication code (RFC 8439), constant time, over the tc_macs traits.
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented1 out of 1 items with examples
  • Size
  • Source code size: 40.3 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 132.6 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • TomiCheng/tc_macs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TomiCheng

tc_poly1305

crates.io docs.rs CI license rustc

The Poly1305 one-time message authentication code (RFC 8439), constant time, over the Mac and MacInit contracts of tc_macs. Raw Poly1305 with a caller-supplied 32-byte one-time key; Poly1305-AES is not included. no_std, no allocator, no unsafe, Rust 1.85 or later.

Types

  • Poly1305 — the MAC; implements tc_macs::Mac and tc_macs::MacInit for any tc_macs::KeyParams.
  • BLOCK_BYTES, KEY_BYTES, TAG_BYTES — the block, key and tag lengths: 16, 32 and 16 bytes.

Usage

[dependencies]
tc_poly1305 = "0.1.0"
tc_macs = "0.1.0"
use tc_macs::{KeyRef, Mac, MacInit};
use tc_poly1305::{Poly1305, TAG_BYTES};

let mut mac = Poly1305::new();
mac.init(&KeyRef::new(&[0x42; 32])).expect("32-byte key");
mac.update(b"attack at dawn").expect("initialized");
let mut tag = [0; TAG_BYTES];
mac.do_final(&mut tag).expect("room for the tag");

Security

A Poly1305 key must never authenticate two messages, so do_final consumes it: the key is wiped and the MAC refuses input until it is initialized with a fresh one. This is stricter than Bouncy Castle, which keeps the key. Compare a received tag in constant time. Poly1305 is constant time, and it wipes the key and the message state on drop; a clone is another copy of the key.

License

Licensed under either the MIT license or the Apache License, Version 2.0, at your option.