Skip to content

Commit 1c3000b

Browse files
committed
blake2: switch from constant_time_eq to subtle
This is more consistent with our other crates
1 parent c094b4c commit 1c3000b

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blake2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ categories = ["cryptography", "no-std"]
1414
[dependencies]
1515
arrayref = "0.3"
1616
arrayvec = { version = "0.5", default-features = false }
17-
constant_time_eq = "0.1"
17+
subtle = ">=2, <2.5"
1818
#digest = "0.9"
1919
#crypto-mac = "0.8"
2020
#opaque-debug = "0.3"

blake2/src/blake2b/hash.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::OUTBYTES;
22
use core::fmt;
3+
use subtle::{Choice, ConstantTimeEq};
34

45
type HexString = arrayvec::ArrayString<[u8; 2 * OUTBYTES]>;
56

@@ -43,17 +44,23 @@ fn bytes_to_hex(bytes: &[u8]) -> HexString {
4344
s
4445
}
4546

47+
impl ConstantTimeEq for Hash {
48+
fn ct_eq(&self, other: &Self) -> Choice {
49+
self.as_bytes().ct_eq(other.as_bytes())
50+
}
51+
}
52+
4653
/// This implementation is constant time, if the two hashes are the same length.
4754
impl PartialEq for Hash {
4855
fn eq(&self, other: &Hash) -> bool {
49-
constant_time_eq::constant_time_eq(self.as_bytes(), other.as_bytes())
56+
self.ct_eq(other).into()
5057
}
5158
}
5259

5360
/// This implementation is constant time, if the slice is the same length as the hash.
5461
impl PartialEq<[u8]> for Hash {
5562
fn eq(&self, other: &[u8]) -> bool {
56-
constant_time_eq::constant_time_eq(self.as_bytes(), other)
63+
self.as_bytes().ct_eq(other).into()
5764
}
5865
}
5966

blake2/src/blake2s/hash.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::OUTBYTES;
22
use core::fmt;
3+
use subtle::{Choice, ConstantTimeEq};
34

45
type HexString = arrayvec::ArrayString<[u8; 2 * OUTBYTES]>;
56

@@ -43,17 +44,23 @@ fn bytes_to_hex(bytes: &[u8]) -> HexString {
4344
s
4445
}
4546

47+
impl ConstantTimeEq for Hash {
48+
fn ct_eq(&self, other: &Self) -> Choice {
49+
self.as_bytes().ct_eq(other.as_bytes())
50+
}
51+
}
52+
4653
/// This implementation is constant time, if the two hashes are the same length.
4754
impl PartialEq for Hash {
4855
fn eq(&self, other: &Hash) -> bool {
49-
constant_time_eq::constant_time_eq(self.as_bytes(), other.as_bytes())
56+
self.ct_eq(other).into()
5057
}
5158
}
5259

5360
/// This implementation is constant time, if the slice is the same length as the hash.
5461
impl PartialEq<[u8]> for Hash {
5562
fn eq(&self, other: &[u8]) -> bool {
56-
constant_time_eq::constant_time_eq(self.as_bytes(), other)
63+
self.as_bytes().ct_eq(other).into()
5764
}
5865
}
5966

0 commit comments

Comments
 (0)