Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poly1305: Add Tag type #17

Merged
merged 1 commit into from
Sep 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions poly1305/src/lib.rs
Original file line number Diff line number Diff line change
@@ -39,6 +39,9 @@ pub const BLOCK_SIZE: usize = 16;
/// Poly1305 blocks (16-bytes)
pub type Block = [u8; BLOCK_SIZE];

/// Poly1305 tags (16-bytes)
pub type Tag = Output<U16>;

/// The Poly1305 universal hash function.
///
/// Note that Poly1305 is not a traditional MAC and is single-use only
@@ -97,7 +100,7 @@ impl UniversalHash for Poly1305 {
}

/// Get the hashed output
fn result(mut self) -> Output<U16> {
fn result(mut self) -> Tag {
if self.leftover > 0 {
self.buffer[self.leftover] = 1;

@@ -189,13 +192,13 @@ impl UniversalHash for Poly1305 {
f = u64::from(h3) + u64::from(self.pad[3]) + (f >> 32);
h3 = f as u32;

let mut output = GenericArray::default();
output[0..4].copy_from_slice(&h0.to_le_bytes());
output[4..8].copy_from_slice(&h1.to_le_bytes());
output[8..12].copy_from_slice(&h2.to_le_bytes());
output[12..16].copy_from_slice(&h3.to_le_bytes());
let mut tag = GenericArray::default();
tag[0..4].copy_from_slice(&h0.to_le_bytes());
tag[4..8].copy_from_slice(&h1.to_le_bytes());
tag[8..12].copy_from_slice(&h2.to_le_bytes());
tag[12..16].copy_from_slice(&h3.to_le_bytes());

Output::new(output)
Tag::new(tag)
}
}