Skip to content

Commit

Permalink
github bcgit#273: reset fix for SM2Signer
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Dec 22, 2017
1 parent 2e47a48 commit 2abfdbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public byte[] generateSignature()
throws CryptoException
{
byte[] eHash = digestDoFinal();
reset();

BigInteger n = ecParams.getN();
BigInteger e = calculateE(eHash);
Expand Down Expand Up @@ -225,6 +224,9 @@ private byte[] digestDoFinal()
{
byte[] result = new byte[digest.getDigestSize()];
digest.doFinal(result, 0);

reset();

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private void doSignerTestFp()

signer.setParameter(new SM2ParameterSpec(Strings.toByteArray("[email protected]")));

// repetition test
final int times = 2;
String random = "";
for (int i = 0; i < times; i++) {
Expand All @@ -59,6 +60,12 @@ private void doSignerTestFp()

byte[] msg = Strings.toByteArray("message digest");

Signature verifier = Signature.getInstance("SM3withSM2", "BC");

verifier.setParameter(new SM2ParameterSpec(Strings.toByteArray("[email protected]")));

verifier.initVerify(kp.getPublic());

for (int i = 0; i < times; i++) {
signer.update(msg, 0, msg.length);

Expand All @@ -69,10 +76,6 @@ private void doSignerTestFp()
isTrue("r wrong", rs[0].equals(new BigInteger("40F1EC59F793D9F49E09DCEF49130D4194F79FB1EED2CAA55BACDB49C4E755D1", 16)));
isTrue("s wrong", rs[1].equals(new BigInteger("6FC6DAC32C5D5CF10C77DFB20F7C2EB667A457872FB09EC56327A67EC7DEEBE7", 16)));

Signature verifier = Signature.getInstance("SM3withSM2", "BC");
verifier.setParameter(new SM2ParameterSpec(Strings.toByteArray("[email protected]")));
verifier.initVerify(kp.getPublic());

verifier.update(msg, 0, msg.length);

isTrue("verification failed i=" + i, verifier.verify(sig));
Expand Down

0 comments on commit 2abfdbf

Please sign in to comment.