Repository navigation
Blind and fix the timing of DH, DSA and related scalar arithmetic - #219
Merged
Merged
Conversation
Diffie-Hellman agreements and DSA/ECDSA/ECNR signing exponentiate a secret with a base the peer or verifier can choose, so their variable-time modular powers could be accumulated against the key over many runs. The base raised to a long-term key is now blinded, the DSA nonce exponent is blinded with a random multiple of q, and each signature's s is formed with fixed-time modular arithmetic kept off the value-dependent BigInteger.Mod. Adds fixed-time ModAdd, ModSubtract, ModMult and ModPowBaseBlinded to the BigInteger utilities, backed by a constant-time Montgomery multiply over a fixed number of words, and a CreateBlindedExponent helper. Also: - DsaPrivateKeyParameters requires x in [1, q-1]. - DH key generation refuses a private value length below twice the security strength of p (SP 800-56A), unless the new TCryptoLibConfig.DH.AllowShortPrivateValue opt-out is set; l may now equal the bit length of p, per PKCS#3. - DHBasicAgreement re-validates a subclassed peer public key by construction, so range and subgroup checks cannot be bypassed. - The binary-polynomial scalar multiply wipes its scratch table. - MiscPemGenerator fails closed when an algorithm is given with no password. - BigInteger.ModInversePow2 lifts the inverse a word at a time.
When a DH agreement re-validates a subclassed peer public key, the freshly constructed TDHPublicKeyParameters was read through a property on the constructor result without being assigned to an interface, so its reference count stayed at zero and the instance was never released. Bind it to an interface local first, then read Y from that. Covers both DHBasicAgreement and DHAgreement.
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.
Diffie-Hellman agreements and DSA/ECDSA/ECNR signing exponentiate a secret with a base the peer or verifier can choose, so their variable-time modular powers could be accumulated against the key over many runs. The base raised to a long-term key is now blinded, the DSA nonce exponent is blinded with a random multiple of q, and each signature's s is formed with fixed-time modular arithmetic kept off the value-dependent BigInteger.Mod.
Adds fixed-time ModAdd, ModSubtract, ModMult and ModPowBaseBlinded to the BigInteger utilities, backed by a constant-time Montgomery multiply over a fixed number of words, and a CreateBlindedExponent helper.
Also: