1
0
Fork 0
mirror of https://github.com/BLAKE3-team/BLAKE3 synced 2024-05-03 22:27:42 +02:00

Use fixed-size constant_time_eq

The generic constant_time_eq has several branches on the slice length,
which are not necessary when the slice length is known. However, the
optimizer is not allowed to look into the core of constant_time_eq, so
these branches cannot be elided.

Use instead a fixed-size variant of constant_time_eq, which has no
branches since the length is known.
This commit is contained in:
Cesar Eduardo Barros 2020-01-11 19:06:58 -03:00 committed by Jack O'Connor
parent b04974461a
commit 4690c5f14e
2 changed files with 3 additions and 3 deletions

View File

@ -24,7 +24,7 @@ std = []
[dependencies]
arrayref = "0.3.5"
arrayvec = { version = "0.5.1", default-features = false, features = ["array-sizes-33-128"] }
constant_time_eq = "0.1.4"
constant_time_eq = "0.1.5"
# A performance note for the "rayon" feature: Multi-threading can have
# significant overhead for small inputs, particularly on x86 where individual
# cores are very fast. On the other hand, on slower platforms like ARM,

View File

@ -180,14 +180,14 @@ impl From<Hash> for [u8; OUT_LEN] {
/// This implementation is constant-time.
impl PartialEq for Hash {
fn eq(&self, other: &Hash) -> bool {
constant_time_eq::constant_time_eq(&self.0[..], &other.0[..])
constant_time_eq::constant_time_eq_32(&self.0, &other.0)
}
}
/// This implementation is constant-time.
impl PartialEq<[u8; OUT_LEN]> for Hash {
fn eq(&self, other: &[u8; OUT_LEN]) -> bool {
constant_time_eq::constant_time_eq(&self.0[..], other)
constant_time_eq::constant_time_eq_32(&self.0, other)
}
}