Skip to content

Blind and fix the timing of DH, DSA and related scalar arithmetic - #219

Merged
Xor-el merged 2 commits into
masterfrom
feature/asymmetric-side-channel-hardening
Nov 24, 2026
Merged

Xor-el merged 2 commits into
masterfrom
feature/asymmetric-side-channel-hardening

Conversation

@Xor-el

@Xor-el Xor-el commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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.

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.
@Xor-el
Xor-el merged commit 401ada3 into master Nov 24, 2026
42 checks passed
@Xor-el
Xor-el deleted the feature/asymmetric-side-channel-hardening branch November 24, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant