Skip to content

Commit

Permalink
Rename *result* to finalize
Browse files Browse the repository at this point in the history
Implements the API changes from:

RustCrypto/traits#161

The `crypto-mac` crate now uses `update` and `finalize` nomenclature
ala the Initialize-Update-Finalize (IUF) interface naming scheme.
  • Loading branch information
tarcieri committed Jun 2, 2020
1 parent 6fe20b2 commit de40281
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cmac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//!
//! // `result` has type `Output` which is a thin wrapper around array of
//! // bytes for providing constant time equality check
//! let result = mac.result();
//! let result = mac.finalize();
//! // To get underlying array use the `into_bytes` method, but be careful,
//! // since incorrect use of the tag value may permit timing attacks which
//! // defeat the security provided by the `Output` wrapper
Expand All @@ -32,7 +32,7 @@
//!
//! mac.update(b"input message");
//!
//! # let tag_bytes = mac.clone().result().into_bytes();
//! # let tag_bytes = mac.clone().finalize().into_bytes();
//! // `verify` will return `Ok(())` if tag is correct, `Err(MacError)` otherwise
//! mac.verify(&tag_bytes).unwrap();
//! ```
Expand Down Expand Up @@ -156,7 +156,7 @@ where
}

#[inline]
fn result(self) -> Output<Self> {
fn finalize(self) -> Output<Self> {
let n = C::BlockSize::to_usize();
let mut buf = self.buffer.clone();
if self.pos == n {
Expand Down
2 changes: 1 addition & 1 deletion daa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Mac for Daa {
}

#[inline]
fn result(mut self) -> Output<Self> {
fn finalize(mut self) -> Output<Self> {
if self.pos != 0 {
self.cipher.encrypt_block(&mut self.buffer);
}
Expand Down
12 changes: 6 additions & 6 deletions hmac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//!
//! // `result` has type `Output` which is a thin wrapper around array of
//! // bytes for providing constant time equality check
//! let result = mac.result();
//! let result = mac.finalize();
//! // To get underlying array use `code` method, but be careful, since
//! // incorrect use of the code value may permit timing attacks which defeat
//! // the security provided by the `Output`
Expand All @@ -41,7 +41,7 @@
//!
//! mac.update(b"input message");
//!
//! # let code_bytes = mac.clone().result().into_bytes();
//! # let code_bytes = mac.clone().finalize().into_bytes();
//! // `verify` will return `Ok(())` if code is correct, `Err(MacError)` otherwise
//! mac.verify(&code_bytes).unwrap();
//! ```
Expand Down Expand Up @@ -144,7 +144,7 @@ where
} else {
let mut digest = D::default();
digest.update(key);
let output = digest.fixed_result();
let output = digest.finalize_fixed();
// `n` is calculated at compile time and will equal
// D::OutputSize. This is used to ensure panic-free code
let n = min(output.len(), hmac.i_key_pad.len());
Expand Down Expand Up @@ -175,11 +175,11 @@ where
}

#[inline]
fn result(self) -> Output<Self> {
fn finalize(self) -> Output<Self> {
let mut opad_digest = self.opad_digest.clone();
let hash = self.digest.fixed_result();
let hash = self.digest.finalize_fixed();
opad_digest.update(&hash);
Output::new(opad_digest.fixed_result())
Output::new(opad_digest.finalize_fixed())
}

#[inline]
Expand Down
6 changes: 3 additions & 3 deletions pmac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//!
//! // `result` has type `Output` which is a thin wrapper around array of
//! // bytes for providing constant time equality check
//! let result = mac.result();
//! let result = mac.finalize();
//! // To get underlying array use `into_bytes` method, but be careful, since
//! // incorrect use of the tag value may permit timing attacks which defeat
//! // the security provided by the `Output` wrapper
Expand All @@ -32,7 +32,7 @@
//!
//! mac.update(b"input message");
//!
//! # let tag_bytes = mac.clone().result().into_bytes();
//! # let tag_bytes = mac.clone().finalize().into_bytes();
//! // `verify` will return `Ok(())` if tag is correct, `Err(MacError)` otherwise
//! mac.verify(&tag_bytes).unwrap();
//! ```
Expand Down Expand Up @@ -229,7 +229,7 @@ where
}
}

fn result(self) -> Output<Self> {
fn finalize(self) -> Output<Self> {
let mut tag = self.tag.clone();
// Special case for empty input
if self.pos == 0 {
Expand Down

0 comments on commit de40281

Please sign in to comment.