diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:25 +0000 |
commit | 5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch) | |
tree | 35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /vendor/digest/src/mac.rs | |
parent | Adding debian version 1.66.0+dfsg1-1. (diff) | |
download | rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/digest/src/mac.rs')
-rw-r--r-- | vendor/digest/src/mac.rs | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/vendor/digest/src/mac.rs b/vendor/digest/src/mac.rs index 76f8df2c9..1c31359ea 100644 --- a/vendor/digest/src/mac.rs +++ b/vendor/digest/src/mac.rs @@ -11,7 +11,7 @@ use subtle::{Choice, ConstantTimeEq}; #[cfg_attr(docsrs, doc(cfg(feature = "mac")))] pub trait MacMarker {} -/// Convinience wrapper trait covering functionality of Message Authentication algorithms. +/// Convenience wrapper trait covering functionality of Message Authentication algorithms. /// /// This trait wraps [`KeyInit`], [`Update`], [`FixedOutput`], and [`MacMarker`] /// traits and provides additional convenience methods. @@ -59,6 +59,12 @@ pub trait Mac: OutputSizeUser + Sized { /// Check if tag/code value is correct for the processed input. fn verify(self, tag: &Output<Self>) -> Result<(), MacError>; + /// Check if tag/code value is correct for the processed input and reset + /// [`Mac`] instance. + fn verify_reset(&mut self, tag: &Output<Self>) -> Result<(), MacError> + where + Self: FixedOutputReset; + /// Check truncated tag correctness using all bytes /// of calculated tag. /// @@ -66,6 +72,15 @@ pub trait Mac: OutputSizeUser + Sized { /// to MAC's output. fn verify_slice(self, tag: &[u8]) -> Result<(), MacError>; + /// Check truncated tag correctness using all bytes + /// of calculated tag and reset [`Mac`] instance. + /// + /// Returns `Error` if `tag` is not valid or not equal in length + /// to MAC's output. + fn verify_slice_reset(&mut self, tag: &[u8]) -> Result<(), MacError> + where + Self: FixedOutputReset; + /// Check truncated tag correctness using left side bytes /// (i.e. `tag[..n]`) of calculated tag. /// @@ -138,13 +153,42 @@ impl<T: Update + FixedOutput + MacMarker> Mac for T { } #[inline] + fn verify_reset(&mut self, tag: &Output<Self>) -> Result<(), MacError> + where + Self: FixedOutputReset, + { + if self.finalize_reset() == tag.into() { + Ok(()) + } else { + Err(MacError) + } + } + + #[inline] fn verify_slice(self, tag: &[u8]) -> Result<(), MacError> { let n = tag.len(); if n != Self::OutputSize::USIZE { return Err(MacError); } let choice = self.finalize_fixed().ct_eq(tag); - if choice.unwrap_u8() == 1 { + if choice.into() { + Ok(()) + } else { + Err(MacError) + } + } + + #[inline] + fn verify_slice_reset(&mut self, tag: &[u8]) -> Result<(), MacError> + where + Self: FixedOutputReset, + { + let n = tag.len(); + if n != Self::OutputSize::USIZE { + return Err(MacError); + } + let choice = self.finalize_fixed_reset().ct_eq(tag); + if choice.into() { Ok(()) } else { Err(MacError) @@ -158,7 +202,7 @@ impl<T: Update + FixedOutput + MacMarker> Mac for T { } let choice = self.finalize_fixed()[..n].ct_eq(tag); - if choice.unwrap_u8() == 1 { + if choice.into() { Ok(()) } else { Err(MacError) @@ -173,7 +217,7 @@ impl<T: Update + FixedOutput + MacMarker> Mac for T { let m = Self::OutputSize::USIZE - n; let choice = self.finalize_fixed()[m..].ct_eq(tag); - if choice.unwrap_u8() == 1 { + if choice.into() { Ok(()) } else { Err(MacError) @@ -239,7 +283,7 @@ impl<T: OutputSizeUser> ConstantTimeEq for CtOutput<T> { impl<T: OutputSizeUser> PartialEq for CtOutput<T> { #[inline(always)] fn eq(&self, x: &CtOutput<T>) -> bool { - self.ct_eq(x).unwrap_u8() == 1 + self.ct_eq(x).into() } } |