Skip to content

Commit b3d1fc8

Browse files
committed
Use array ct_eq from subtle instead of writing our own
1 parent 37054c9 commit b3d1fc8

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories = ["cryptography", "no-std"]
1010
[dependencies]
1111
rand_core = "0.6.4"
1212
sha3 = { version = "0.10.8", default-features = false }
13-
subtle = { version = "2.5.0", default-features = false }
13+
subtle = { version = "2.6.0", default-features = false, features = ["const-generics"] }
1414
zeroize = { version = "1.8.1", default-features = false, features = ["derive"] }
1515

1616
[dev-dependencies]

src/kem.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ pub fn decap<const L: usize, const MU: usize, const MODULUS_T_BITS: usize>(
225225

226226
// k_or_z = k if reconstruction matched, else z. We do this in constant time using `subtle`
227227
let reconstruction_matched = reconstructed_ct.ct_eq(ciphertext);
228-
let mut k_or_z = [0u8; 32];
229-
for ((z_byte, k_byte), k_or_z_byte) in sk.z.iter().zip(k.iter()).zip(k_or_z.iter_mut()) {
230-
*k_or_z_byte = u8::conditional_select(z_byte, k_byte, reconstruction_matched);
231-
}
228+
let k_or_z = <[u8; 32]>::conditional_select(&sk.z, &k, reconstruction_matched);
232229

233230
// session key = SHA3-256(k_or_z || r')
234231
// The spec has the hash input order switched, but we're following the reference impl

0 commit comments

Comments
 (0)