From d12bc90d8f51fc4be2dcdc49e03954f4781ce4bb Mon Sep 17 00:00:00 2001 From: brycx Date: Sat, 23 Mar 2019 14:53:42 +0100 Subject: [PATCH] Use subtles From for bool impl instead of using unwrap_u8 to avoid short-circuits. --- src/typedefs.rs | 11 +++++------ src/util/mod.rs | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/typedefs.rs b/src/typedefs.rs index f6b1c363..da138d3b 100644 --- a/src/typedefs.rs +++ b/src/typedefs.rs @@ -46,9 +46,9 @@ macro_rules! impl_ct_partialeq_trait (($name:ident) => ( impl PartialEq for $name { fn eq(&self, other: &$name) -> bool { use subtle::ConstantTimeEq; - self.unprotected_as_bytes() - .ct_eq(&other.unprotected_as_bytes()) - .unwrap_u8() == 1 + + (self.unprotected_as_bytes() + .ct_eq(other.unprotected_as_bytes())).into() } } )); @@ -639,9 +639,8 @@ macro_rules! construct_digest { impl PartialEq for $name { fn eq(&self, other: &$name) -> bool { use subtle::ConstantTimeEq; - self.as_bytes() - .ct_eq(&other.as_bytes()) - .unwrap_u8() == 1 + + (self.as_bytes().ct_eq(other.as_bytes())).into() } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 059c645b..74c2e0a9 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -99,7 +99,7 @@ pub fn secure_cmp(a: &[u8], b: &[u8]) -> Result