Skip to content

Commit 8fd9785

Browse files
MagicalTuxclaude
andcommitted
common/hash_utils: clarify RejectionSample does modular reduction, not rejection
RejectionSample performs a bare Mod(eHash, q) with no rejection loop. Document that it is only (near-)uniform when q is within a small factor of the 256-bit digest width (safe for all current ~256-bit callers, bias <= 2^-128). No functional change; name kept for caller compatibility. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a831f22 commit 8fd9785

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎common/hash_utils.go‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@ import (
1010
"math/big"
1111
)
1212

13-
// RejectionSample reduces a hash value modulo q. The input eHash is a
14-
// 256-bit output of SHA-512/256. When q is close to or larger than 2^256
15-
// the bias from modular reduction is negligible. For smaller q values the
16-
// bias is at most 2^{-128} which is within acceptable security bounds.
13+
// RejectionSample maps a hash value into [0, q) via a single modular
14+
// reduction: e' = eHash mod q. Despite the name, it does NOT perform
15+
// rejection sampling — there is no retry loop and the result is simply the
16+
// reduced value. The name is retained for backwards compatibility with its
17+
// callers (crypto/modproof, facproof, mta, schnorr).
18+
//
19+
// Because this is a bare reduction, the output is only (near-)uniform when q
20+
// is within a small factor of the digest width. The input eHash is a 256-bit
21+
// SHA-512/256 output, so for the ~256-bit curve / RSA-modulus orders used by
22+
// all current callers the modular bias is at most ~2^{-128}, which is
23+
// negligible. Do NOT use this for a q whose bit length is materially smaller
24+
// than the digest (~256 bits): the reduction bias would then become
25+
// security-relevant and a true rejection-sampling routine would be required.
1726
func RejectionSample(q *big.Int, eHash *big.Int) *big.Int { // e' = eHash
1827
e := new(big.Int).Mod(eHash, q)
1928
return e

0 commit comments

Comments
 (0)