Skip to content

Commit

Permalink
Implement the ECKeyPairGenerator initialize func
Browse files Browse the repository at this point in the history
Aim to solve openj9 issue 18320.
DefaultSignatureAlgorithm test run in those
Redhat OS based machines, FIPS version of
openssl is used in those machines. So, a 192
size of EC key pair generator is not allowed
by the native code in FIPS version of openssl
, then a Java implementation is used.

However, there are lacking of implementation
of initialize function in ECKeyPairGenerator
file.

This PR implements the initialize function in
ECKeyPairGenerator file.
  • Loading branch information
JinhangZhang committed May 7, 2024
1 parent b8f6121 commit 884dc58
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 884dc58

Please sign in to comment.