Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable unit tests for ES256KCC. #9

Merged
merged 2 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.danubetech.keyformats.crypto.PublicKeyVerifier;
import com.danubetech.keyformats.jose.JWSAlgorithm;
import org.bitcoinj.core.ECKey;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.crypto.signers.ECDSASigner;
import org.bouncycastle.crypto.signers.HMacDSAKCalculator;
import org.web3j.crypto.Hash;
import org.web3j.crypto.Sign;

import java.math.BigInteger;
Expand All @@ -31,7 +30,7 @@ public boolean verify(byte[] content, byte[] signature) throws GeneralSecurityEx
System.arraycopy(signature, 32, s, 0, s.length);
System.arraycopy(signature, 64, v, 0, v.length);

ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
ECDSASigner signer = new ECDSASigner();

ECKey ec = ECKey.fromPublicOnly(this.getPublicKey());

Expand All @@ -41,9 +40,7 @@ public boolean verify(byte[] content, byte[] signature) throws GeneralSecurityEx
Sign.SignatureData sig = new Sign.SignatureData(v, r, s);
Sign.signedMessageToKey(content, sig);

return signer.verifySignature(content,new BigInteger(1, r), new BigInteger(1, s));


return signer.verifySignature(Hash.sha3(content),new BigInteger(1, r), new BigInteger(1, s));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -46,7 +47,7 @@ KeyTypeName getKeyTypeName() {

@Override
List<String> getAlgorithms() {
return Collections.singletonList(JWSAlgorithm.ES256K);
return Arrays.asList(JWSAlgorithm.ES256K, JWSAlgorithm.ES256KCC);
}

@Override
Expand Down