You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a219442
Browse filesBrowse the repository at this point in the historyBrowse files
Every classical signer now assembles the signature component s through the constant-time BigIntegers.modMult, modAdd and the new modSubtract rather than BigInteger.multiply and mod, whose cost follows the quotient and which were being handed the signing key, covering ECDSA, SM2, DSA, GOST 3410, ECGOST 3410, DSTU 4145, EC-NR and BIP 340, with the public hash-derived value reduced on the way in wherever it could sit at or past the order, DSAPrivateKeyParameters and GOST3410PrivateKeyParameters now holding x to the [1, q-1] their own parameters imply, and the two GOST signers redrawing a nonce that is zero or at or past the order rather than leaving it to be folded by the reduction that followed.
Copy file name to clipboardExpand all lines: CONTRIBUTORS.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -547,3 +547,4 @@ We also wish to acknowledge financial and collaborative support from [CISCO](htt
547
547
- hannesa2 \<https://github.com/hannesa2\> - initial Dependabot configuration for the Gradle and GitHub Actions ecosystems (PR #883).
548
548
- vladhuma \<https://github.com/vladhuma\> - initial implementation of server-side OCSP stapling for the BCJSSE provider, on behalf of Thales Group (PR #1740).
549
549
- Bhargava Shastry \<bshastry@posteo.de\> - reporting, with a self-checking reproducer, that the C509 validity fields were read as unbounded seconds and then given two meanings: displacing a type-3 certificate's validityNotAfter by 2^61 seconds left the reconstructed DER TBSCertificate and the issuer signature untouched, while C509CertificateHolder.isValidOn took the raw value and read an expired certificate as valid.
550
+
- Rob Augustinus \<rob@opensolutions.nl\> - a constant-time analysis of the elliptic-curve and AES code paths, with proof-of-concept code, which independently reached the variable-point scalar multiplication exposure addressed in 1.86.
Copy file name to clipboardExpand all lines: core/src/main/java/org/bouncycastle/crypto/signers/BIP340Signer.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -321,7 +321,8 @@ private static byte[] sign(ECPrivateKeyParameters privateKey, byte[] m, byte[] a
321
321
322
322
// Steps 11-12: e = int(H_challenge(bytes(R) || bytes(P) || m)) mod n; sig = bytes(R) || bytes((k + e*d) mod n).
323
323
BigIntegere = challengeScalar(rBytes, pBytes, m);
324
-
BigIntegers = k.add(e.multiply(d)).mod(n);
324
+
// the secret d and nonce k are kept off BigInteger.mod, whose cost follows the quotient; both are in [1, n-1] after the conditional negations above, e is reduced by challengeScalar, and n is odd
325
+
BigIntegers = BigIntegers.modAdd(n, k, BigIntegers.modMult(n, e, d));
@@ -107,9 +108,9 @@ public BigInteger[] generateSignature(
107
108
// the randomizer is to conceal timing information related to k and x.
108
109
BigIntegerr = params.getG().modPow(BigIntegers.createBlindedExponent(k, q, CryptoServicesRegistrar.getSecureRandom(random)), params.getP()).mod(q);
109
110
110
-
k = BigIntegers.modOddInverse(q, k).multiply(m.add(x.multiply(r)));
111
-
112
-
BigIntegers = k.mod(q);
111
+
// s = k^-1 * (m + x * r) mod q, with the secret x and k^-1 kept off BigInteger.mod, whose cost follows the quotient; x is in [1, q-1] by DSAPrivateKeyParameters, r is reduced, and q is prime and so odd
Copy file name to clipboardExpand all lines: core/src/main/java/org/bouncycastle/crypto/signers/DSTU4145Signer.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -99,7 +99,8 @@ public BigInteger[] generateSignature(byte[] message)
99
99
}
100
100
while (r.signum() == 0);
101
101
102
-
s = r.multiply(d).add(e).mod(n);
102
+
// the secret d and ephemeral e are kept off BigInteger.mod, whose cost follows the quotient; d is in [1, n-1] by validatePrivateScalar, e is drawn in that range and r is truncated below 2^(n.bitLength()-1), and n is odd
103
+
s = BigIntegers.modAdd(n, BigIntegers.modMult(n, r, d), e);
@@ -128,7 +129,9 @@ public BigInteger[] generateSignature(
128
129
}
129
130
while (r.equals(ZERO));
130
131
131
-
s = BigIntegers.modOddInverse(n, k).multiply(e.add(d.multiply(r))).mod(n);
132
+
// s = k^-1 * (e + d * r) mod n, with the secret d and k^-1 kept off BigInteger.mod, whose cost follows the quotient; d is in [1, n-1] by validatePrivateScalar, r is reduced and non-zero, and n is odd
133
+
s = BigIntegers.modMult(n, BigIntegers.modOddInverse(n, k),
134
+
BigIntegers.modAdd(n, e, BigIntegers.modMult(n, d, r)));
// the secret d and nonce k are kept off BigInteger.mod, whose cost follows the quotient; d is in [1, n-1] by validatePrivateScalar, k is now redrawn until it is below n, r is reduced, and n is odd
101
+
s = BigIntegers.modAdd(n, BigIntegers.modMult(n, k, e), BigIntegers.modMult(n, d, r));
Copy file name to clipboardExpand all lines: core/src/main/java/org/bouncycastle/crypto/signers/ECNRSigner.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -122,7 +122,8 @@ public BigInteger[] generateSignature(
122
122
// generate s
123
123
BigIntegerx = privKey.getD(); // private key value
124
124
BigIntegeru = ((ECPrivateKeyParameters)tempPair.getPrivate()).getD(); // temp's private key value
125
-
s = u.subtract(r.multiply(x)).mod(n);
125
+
// the secret x and the ephemeral u are kept off BigInteger.mod, whose cost follows the quotient; x is in [1, n-1] by validatePrivateScalar, u comes from a generated key pair and r is reduced and non-zero, and n is odd
126
+
s = BigIntegers.modSubtract(n, u, BigIntegers.modMult(n, r, x));
// the secret x and nonce k are kept off BigInteger.mod, whose cost follows the quotient; x is in [1, q-1] by GOST3410PrivateKeyParameters, k is drawn below q above, r is reduced, and q is prime and so odd
0 commit comments