Skip to content

Commit

Permalink
Merge pull request #268 from KostasTsiounis/eckeygen
Browse files Browse the repository at this point in the history
Always revert to Java impl when OpenSSL fails
  • Loading branch information
keithc-ca authored Oct 2, 2023
2 parents a2a7584 + e5c3409 commit d8e0f4d
Showing 1 changed file with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,13 @@ public KeyPair generateKeyPair() {
return this.javaImplementation.generateKeyPair();
}

boolean absent;
long nativePointer = NativeECUtil.encodeGroup(this.params);

if (nativePointer == -1) {
absent = NativeECUtil.putCurveIfAbsent(this.curve, Boolean.FALSE);
if (!absent) {
throw new ProviderException("Could not encode group");
}
NativeECUtil.putCurveIfAbsent(this.curve, Boolean.FALSE);
if (nativeCryptTrace) {
System.err.println(this.curve +
" is not supported by OpenSSL, using Java crypto implementation.");
System.err.println("Could not encode group for curve " + this.curve
+ " in OpenSSL, using Java crypto implementation.");
}
try {
this.initializeJavaImplementation();
Expand All @@ -193,13 +189,10 @@ public KeyPair generateKeyPair() {
} else if (field instanceof ECFieldF2m) {
fieldType = NativeCrypto.ECField_F2m;
} else {
absent = NativeECUtil.putCurveIfAbsent(this.curve, Boolean.FALSE);
if (!absent) {
throw new ProviderException("Field type not supported");
}
NativeECUtil.putCurveIfAbsent(this.curve, Boolean.FALSE);
if (nativeCryptTrace) {
System.err.println(this.curve +
" is not supported by OpenSSL, using Java crypto implementation.");
System.err.println("Field type not supported for curve " + this.curve
+ " by OpenSSL, using Java crypto implementation.");
}
try {
this.initializeJavaImplementation();
Expand All @@ -224,13 +217,10 @@ public KeyPair generateKeyPair() {
fieldType);

if (ret == -1) {
absent = NativeECUtil.putCurveIfAbsent(this.curve, Boolean.FALSE);
if (!absent) {
throw new ProviderException("Could not generate key pair");
}
NativeECUtil.putCurveIfAbsent(this.curve, Boolean.FALSE);
if (nativeCryptTrace) {
System.err.println(this.curve +
" is not supported by OpenSSL, using Java crypto implementation for key generation.");
System.err.println("Could not generate key pair for curve " + this.curve
+ " using OpenSSL, using Java crypto implementation for key generation.");
}
try {
this.initializeJavaImplementation();
Expand Down

0 comments on commit d8e0f4d

Please sign in to comment.