Skip to content

Commit

Permalink
Add native crypto trace for DefaultSignatureAlgorithm.java
Browse files Browse the repository at this point in the history
  • Loading branch information
JinhangZhang committed May 7, 2024
1 parent b8f6121 commit 754a945
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ private static void check(String keyAlg, int keySize,
String sigAlgParam = requestedSigAlg == null
? ""
: (" -sigalg " + requestedSigAlg);
System.out.println("starting...");
genkeypair(alias,
"-keyalg " + keyAlg + " -keysize " + keySize + sigAlgParam)
"-keyalg " + keyAlg + " -keysize " + keySize + sigAlgParam + " -debug -J-Djdk.nativeCryptoTrace=true")
.shouldHaveExitValue(0);

KeyStore ks = KeyStore.getInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.ECParameterSpec;
import java.security.spec.ECGenParameterSpec;
import java.security.spec.ECPoint;

import sun.security.util.ECUtil;
Expand All @@ -51,7 +52,28 @@ public void initialize(int keySize, SecureRandom random) {
@Override
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
throws InvalidAlgorithmParameterException {
throw new UnsupportedOperationException();
ECParameterSpec ecSpec = null;

if (params instanceof ECParameterSpec) {
ECParameterSpec ecParams = (ECParameterSpec) params;
ecSpec = ECUtil.getECParameterSpec(null, ecParams);
if (ecSpec == null) {
throw new InvalidAlgorithmParameterException(
"Unsupported curve: " + params);
}
} else if (params instanceof ECGenParameterSpec) {
String name = ((ECGenParameterSpec) params).getName();
ecSpec = ECUtil.getECParameterSpec(null, name);
if (ecSpec == null) {
throw new InvalidAlgorithmParameterException(
"Unknown curve name: " + name);
}
} else {
throw new InvalidAlgorithmParameterException(
"ECParameterSpec or ECGenParameterSpec required for EC");
}

this.keySize = ecSpec.getCurve().getField().getFieldSize();
}

@Override
Expand Down

0 comments on commit 754a945

Please sign in to comment.