Skip to main content

Poly1305

Struct Poly1305 

Source
pub struct Poly1305 { /* private fields */ }
Expand description

Poly1305 MAC state.

Holds the accumulator acc, the precomputed r (and r * 5 for each limb, to absorb the * 5 mod p of the lazy reduction in the inner loop), the tag-finalisation key s, and a 16-byte buffer for handling messages whose length is not a multiple of 16.

Internally:

  • r[0..5] : r in 5 26-bit limbs
  • s[0..4] : the second half of the one-time key as 4 LE u32s
  • acc[0..5]: accumulator in 5 26-bit limbs
  • buffer : up to 16 bytes of pending data
  • buf_pos : 0..=16

Implementations§

Source§

impl Poly1305

Source

pub fn new(key: &[u8; 32]) -> Self

Initialise Poly1305 with a 32-byte one-time key key = r ‖ s.

r is clamped per RFC 8439 §2.5: bytes 3, 7, 11, 15 have their top 4 bits cleared (& 0x0f) and bytes 4, 8, 12 have their low 2 bits cleared (& 0xfc).

Source

pub fn update(&mut self, data: &[u8])

Absorb additional data into the accumulator.

Buffers up to 15 leftover bytes between calls so that arbitrary update sizes work the same as one big call.

Source

pub fn finalize(self) -> [u8; 16]

Finalise the MAC and write the 16-byte tag into tag. Consumes the state.

Source

pub fn mac(key: &[u8; 32], data: &[u8]) -> [u8; 16]

One-shot helper: feed the entire data and return the tag.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.