Repository navigation
bcprov 1.57: JCA SM3withSM2 signatures appear to hash the message twice. Intended? #2524
|
Hello, This is a question about historical behaviour, not a vulnerability report. Current releases behave as I would expect. What we observe: in one JVM, with the GB/T 32918.5-2016 worked-example key pair and the same message: How we read the 1.57 source: DSABase.engineSign() passes digest.doFinal() = SM3(M) to SM2Signer.generateSignature(byte[]). That method then computes SM3(Z_A || message), so e = SM3(Z_A || SM3(M)) and the message is hashed twice. From 1.66, GMSignatureSpi streams the message into a Signer-style SM2Signer, giving e = SM3(Z_A || M), and the default ID changes from empty to "1234567812345678". We read this as a consequence of the DSA to Signer API change, and we are not claiming BC knowingly fixed a defect. Questions:
Environment: openjdk 17.0.20 (Temurin). Each probe ran on an isolated classpath with a single jar. What we are not claiming: no downstream impact was measured, no forgery or key recovery is involved, and the only observed effect is a verification failure. We have not tested SHA256withSM2 or bcprov-jdk15to18, and we have only narrowed the change to (1.57, 1.66]. Thanks for any insight. |
Replies: 2 comments
|
1.59 is the release you're looking for. 1.58 still has the extra provider prehash; 1.59 streams the message directly to there's a historical report for exactly what you found. #218 calls out both repeated sm3 hashing and the missing default id, with bcgit acknowledging the mistake. commit for your last question, the 1.57 source amounts to signing |
|
Thanks, Nicholas. That's very helpful, and you're right on all three points. I ran the test you suggested: for bcprov 1.57 and 1.58, 32 JCA SM3withSM2 signatures each verify 32/32 as (SM3(M), ID = "") under two independent SM2 verifiers (our GB/T 32918 reference and the 1.59 SM2Signer with explicit ParametersWithID), and 0/32 under every other combination; 1.59 signatures verify 32/32 only as (M, "1234567812345678"). So the mechanism is exactly sign(SM3(M), ID = ""). My earlier wording was wrong because I had only verified against M. Our write-up now credits #218 and b071aa1 as the original report and fix. Thanks for the quick and precise answer. Nothing further is needed from your side. |
1.59 is the release you're looking for. 1.58 still has the extra provider prehash; 1.59 streams the message directly to
SM2Signerthere's a historical report for exactly what you found. #218 calls out both repeated sm3 hashing and the missing default id, with bcgit acknowledging the mistake. commit
b071aa17addresses both. the 1.59 release note explicitly records the default-id fixfor your last question, the 1.57 source amounts to signing
SM3(M)as the message with an empty id. i'd try verifying those prehashed bytes, using the same public key and empty id. verification againstMchecks a different input, so those failures don't establish that no standard implementation could verify the …