Injectable RNG for the constant-time EC scalar multipliers - #202
Merged
Merged
Conversation
The constant-time scalar multipliers — the variable-base CT multiplier and the fixed-base comb — drew their scalar blind and projective randomizer from a TSecureRandom they lazily created, bypassing any caller-supplied ISecureRandom. Thread a caller-owned RNG through both so a caller can supply one DRBG for every constant-time multiplication instead of each multiplier instantiating its own. - IECCTMultiplierFactory gains CreateCTMultiplier(ARandom, ABlindBits) and CreateBasePointCTMultiplier(ARandom); the four Fp custom curves implement both. - TEphemeralECDHAgreement and TFpAffineCombMultiplier gain random-accepting constructors. - Key generation and ECDSA signing route the fixed-base blind through their injected RNG. Deterministic signing has no injected RNG, so it keeps the curve's shared multiplier rather than building a fresh DRBG-backed comb per signature. - The injected-RNG entry points reject a nil random instead of silently degrading, and the curve's lazily-cached multipliers are now built under the existing lock. The blind remains transparent to the result (checked against a WNAF reference on secp256r1, secp256k1, secp384r1 and secp521r1), and a counting RNG proves both randomness draws come from the injected source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The constant-time EC scalar multipliers lazily created their own
TSecureRandomfor the scalar blind and projective-coordinate randomizer, ignoring any
caller-supplied
ISecureRandom. This adds injectable-RNG overloads so a callercan own that randomness with a single DRBG rather than one instantiated per operation.
Changes
IECCTMultiplierFactory:CreateCTMultiplier(const ARandom: ISecureRandom; ABlindBits)(overload) and
CreateBasePointCTMultiplier(const ARandom: ISecureRandom); implemented bythe four Fp custom curves (secp256r1/k1, secp384r1, secp521r1).
TEphemeralECDHAgreementandTFpAffineCombMultiplier: random-accepting constructors.Deterministic (RFC 6979) signing has no injected RNG, so it keeps the curve's cached
multiplier instead of building a fresh DRBG per signature.
lock (pre-existing race on the interface field).
Behaviour
Additive and backward-compatible: the existing non-RNG constructors and factory methods are
unchanged; the blind stays transparent to the result.