pub struct Poly1305<State: Poly1305State = Init> { /* private fields */ }allow-non-fips only.Expand description
The Poly1305 Message Authentication Code (MAC)
§Example
use wolf_crypto::{mac::{Poly1305, poly1305::Key}, aead::Tag};
let key: Key = [7u8; 32].into();
let tag = Poly1305::new(key.as_ref())
.aead_padding_ct()
.update_ct(b"hello world")
.update_ct(b", how are you")
.finalize()
.unwrap();
let o_tag = Poly1305::new(key.as_ref())
.mac(b"hello world, how are you", b"")
.unwrap();
assert_eq!(tag, o_tag);Implementations§
Source§impl Poly1305<Ready>
impl Poly1305<Ready>
Sourcepub fn mac<A: Aad>(self, input: &[u8], aad: A) -> Result<Tag, Unspecified>
pub fn mac<A: Aad>(self, input: &[u8], aad: A) -> Result<Tag, Unspecified>
Computes the MAC for the given input and additional data. This uses the TLS AEAD padding
scheme. If this is undesirable, consider calling update followed by finalize manually.
§Arguments
input- A byte slice representing the message to authenticate.aad- Any additional authenticated data.
§Returns
The associated authentication tag.
§Errors
§Example
use wolf_crypto::{mac::{Poly1305, poly1305::Key}, aead::Tag};
let key: Key = [42u8; 32].into();
let tag = Poly1305::new(key.as_ref())
.mac(b"message", b"aad")
.unwrap();Sourcepub const fn aead_padding(self) -> StreamPoly1305Aead
pub const fn aead_padding(self) -> StreamPoly1305Aead
Transitions the Poly1305 instance into the streaming state with the TLS AEAD padding
scheme.
§Returns
A StreamPoly1305Aead instance for continued updates.
§Example
use wolf_crypto::{mac::{Poly1305, poly1305::Key}, aead::Tag};
let key: Key = [42u8; 32].into();
let stream = Poly1305::new(key.as_ref())
.aead_padding()
.update(b"chunk1")?
.update(b"chunk2")?;Sourcepub const fn normal(self) -> StreamPoly1305
pub const fn normal(self) -> StreamPoly1305
Transitions the Poly1305 instance into the streaming state.
§Returns
A StreamPoly1305 instance for continued updates.
§Example
use wolf_crypto::{mac::{Poly1305, poly1305::Key}, aead::Tag};
let key: Key = [42u8; 32].into();
let stream = Poly1305::new(key.as_ref()).normal()
.update(b"chunk1")?
.update(b"chunk2")?;Sourcepub const fn aead_padding_ct(self) -> CtPoly1305Aead
pub const fn aead_padding_ct(self) -> CtPoly1305Aead
Transitions the Poly1305 instance into the streaming state with the TLS AEAD padding
scheme.
The distinction between this and the standard aead_padding is that this accumulates
errors up until the point of finalization in constant time.
§Returns
A CtPoly1305Aead instance for continued updates.
§Example
use wolf_crypto::{mac::{Poly1305, poly1305::Key}, aead::Tag};
let key: Key = [42u8; 32].into();
let stream = Poly1305::new(key.as_ref())
.aead_padding_ct()
.update_ct(b"chunk1")
.update_ct(b"chunk2");Sourcepub const fn normal_ct(self) -> CtPoly1305
pub const fn normal_ct(self) -> CtPoly1305
Transitions the Poly1305 instance into the streaming state.
The distinction between this and the standard normal is that this accumulates
errors up until the point of finalization in constant time.
§Returns
A CtPoly1305 instance for continued updates.
§Example
use wolf_crypto::{mac::{Poly1305, poly1305::Key}, aead::Tag};
let key: Key = [42u8; 32].into();
let stream = Poly1305::new(key.as_ref()).normal_ct()
.update_ct(b"chunk1")
.update_ct(b"chunk2");Sourcepub fn update(self, input: &[u8]) -> Result<StreamPoly1305, Unspecified>
pub fn update(self, input: &[u8]) -> Result<StreamPoly1305, Unspecified>
Updates the Poly1305 instance with additional input, transitioning it to a streaming
state.
§Arguments
input- A byte slice representing the data to include in the MAC computation.
§Returns
A StreamPoly1305 instance for continued updates.
§Errors
If the length of input is greater than u32::MAX.
§Example
use wolf_crypto::{mac::{Poly1305, poly1305::Key}, aead::Tag};
let key: Key = [42u8; 32].into();
let stream = Poly1305::new(key.as_ref())
.update(b"chunk1")?
.update(b"chunk2")?;Sourcepub fn update_ct(self, input: &[u8]) -> CtPoly1305
pub fn update_ct(self, input: &[u8]) -> CtPoly1305
Updates the Poly1305 instance with additional input in a constant-time manner.
§Arguments
input- A byte slice representing the data to include in the MAC computation.
§Returns
A CtPoly1305 instance containing the updated state.
§Example
use wolf_crypto::{mac::{Poly1305, poly1305::Key}, aead::Tag};
let key: Key = [42u8; 32].into();
let tag = Poly1305::new(key.as_ref())
.update_ct(b"sensitive ")
.update_ct(b"chunks")
.finalize()
.unwrap();
let o_tag = Poly1305::new(key.as_ref())
.update_ct(b"sensitive chunks")
.finalize().unwrap();
assert_eq!(tag, o_tag);