- Every classical signer assembled the signature component s with plain BigInteger arithmetic over the signing key: ECDSASigner formed k^-1 \* (e + d \* r) mod n, SM2Signer (1 + d)^-1 \* (k - r \* d) mod n, DSASigner k^-1 \* (m + x \* r) mod q, GOST3410Signer k \* m + x \* r mod q, ECGOST3410Signer k \* e + d \* r mod n, ECNRSigner u - r \* x mod n, BIP340Signer k + e \* d mod n and DSTU4145Signer r \* d + e mod n, and while the inverse in each had already been moved to the constant-time BigIntegers.modOddInverse, the multiplications and reductions around it had not. BigInteger.mod does an amount of work set by the quotient, so the cost of forming s answered a question about the long-lived signing key once per signature, and since r and e (SM2: r and k) vary publicly from one signature to the next those answers combine over a run of signatures; the same reasoning moved the ECCSI and SAKKE arithmetic in this release. All eight now go through BigIntegers.modMult, modAdd and the new modSubtract (see Additional Features below), which need their operands already reduced. The five elliptic-curve signers take their key as an ECPrivateKeyParameters, so the signing key is in [1, n-1] by ECDomainParameters.validatePrivateScalar, and each nonce and each r is reduced where it is produced - EC-NR's ephemeral comes from a generated key pair, BIP 340's nonce and challenge are reduced and its two conditional negations leave both operands in range, and DSTU 4145 draws its e in [1, n-1] and truncates r below 2^(n.bitLength()-1). The hash-derived value is the one that needed handling in four of them: ECDSA's e, DSA's m, and the GOST 3410 and ECGOST 3410 digests can all sit at or past the order, and all four are public, so each is reduced on the way in at no cost. DSA and GOST 3410 needed one further thing. Unlike ECPrivateKeyParameters, neither DSAPrivateKeyParameters nor GOST3410PrivateKeyParameters checked the range of x, so a key outside [1, q-1] - which FIPS 186-4 sec. 4.1 does not permit - was silently reduced by the arithmetic that formed s. Both now reject such a key when it is constructed, which is where the check belongs: unlike the ECCSI signing key, which does not carry its curve and so has to be checked at the signer, a DSA or GOST key carries the parameters that bound it. A key with no parameters attached is left alone, as it cannot sign in any case. Signatures are unchanged: the RFC 6979 deterministic ECDSA vectors, the SM2 GM/T 0003.2 vectors, the BIP-340 vectors and the GOST R 34.10 fixed-nonce vectors reproduce byte for byte, EC-NR reproduces its fixed-nonce expected values, and DSTU 4145 still verifies what it signs. One behavioural edge: modMult requires an odd modulus, so a caller-built curve whose order is even - which no standard curve has, and which the group structure does not admit - is now refused rather than signed with. The substitutions preserve the result and so cannot be caught by any signing or verification test, and are covered instead by the class-file scan in ConstantTimeUsageTest, which gains rows for all eight signers.
0 commit comments