Skip to content

Commit c46680e

Browse files
committed
signing: enforce necessary minimum bit-length for secret number
1 parent 4ff7547 commit c46680e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

dsa/src/signing_key.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ impl SigningKey {
8484

8585
let r = g.modpow(&k, p) % q;
8686

87-
let n = (q.bits() / 8) as usize;
87+
let n = q.bits() / 8;
8888
let block_size = hash.len(); // Hash function output size
89-
// FIXME shouldn't `hash.len() < n` be a hard error (bad API use)? According to DSA documentation: "An approved hash function, as specified in FIPS 180, shall be used during the generation of key pairs and digital signatures. When used during the generation of an RSA key pair (as specified in this Standard), the length in bits of the hash function output block shall meet or exceed the security strength associated with the bit length of the modulus n (see SP 800-57)."
89+
// FIPS 186-4: "An approved hash function, [..], the length in bits of the hash function
90+
// output block shall meet or exceed the security strength associated with the bit length of
91+
// the modulus n (see SP 800-57)."
92+
assert!(block_size >= n, "The block size of the hash function must be at least as strong as the modulus");
9093

9194
let z_len = min(n, block_size);
9295
let z = BigUint::from_bytes_be(&hash[..z_len]);

0 commit comments

Comments
 (0)