Skip to content

Commit

Permalink
Update minor changes, comments, error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sp717 committed Aug 27, 2024
1 parent 40c3f96 commit 3834860
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions csrc/ed_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using namespace AmazonCorrettoCryptoProvider;

void generateEdKey(raii_env* env, EVP_PKEY_auto& key)
void generateEdKey(EVP_PKEY_auto& key)
{
EVP_PKEY_CTX_auto ctx = EVP_PKEY_CTX_auto::from(EVP_PKEY_CTX_new_id(EVP_PKEY_ED25519, nullptr));
CHECK_OPENSSL(ctx.isInitialized());
Expand All @@ -20,7 +20,7 @@ JNIEXPORT jlong JNICALL Java_com_amazon_corretto_crypto_provider_EdGen_generateE
try {
raii_env env(pEnv);
EVP_PKEY_auto key;
generateEdKey(&env, key);
generateEdKey(key);
return reinterpret_cast<jlong>(key.take());
} catch (java_ex& ex) {
ex.throw_to_java(pEnv);
Expand Down
3 changes: 3 additions & 0 deletions csrc/java_evp_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ JNIEXPORT jbyteArray JNICALL Java_com_amazon_corretto_crypto_provider_EvpEdPriva
CHECK_OPENSSL(EVP_PKEY_get_raw_private_key(key, privateKeyBuffer, &bufSize) == 1);

result = env->NewByteArray(bufSize);
if (!result) {
throw_java_ex(EX_OOM, "Unable to allocate private key array");
}
env->SetByteArrayRegion(result, 0, bufSize, privateKeyBuffer);
} catch (java_ex& ex) {
ex.throw_to_java(pEnv);
Expand Down
1 change: 0 additions & 1 deletion csrc/keyutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/rsa.h>
#include <iostream>

namespace AmazonCorrettoCryptoProvider {

Expand Down
6 changes: 3 additions & 3 deletions src/com/amazon/corretto/crypto/provider/EdGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class EdGen extends KeyPairGeneratorSpi {
provider_ = provider;
try {
kf = KeyFactory.getInstance("EdDSA", "SunEC");
} catch (GeneralSecurityException e) {
} catch (final GeneralSecurityException e) {
throw new RuntimeException("Error setting up KeyPairGenerator", e);
}
}

public void initialize(int keysize, SecureRandom random) {
public void initialize(final int keysize, final SecureRandom random) {
throw new UnsupportedOperationException();
}

Expand All @@ -45,7 +45,7 @@ public KeyPair generateKeyPair() {
final PrivateKey jcePrivateKey = kf.generatePrivate(privateKeyPkcs8);
final PublicKey jcePublicKey = kf.generatePublic(publicKeyX509);
return new KeyPair(jcePublicKey, jcePrivateKey);
} catch (GeneralSecurityException e) {
} catch (final GeneralSecurityException e) {
throw new RuntimeException("Error generating key pair", e);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/com/amazon/corretto/crypto/provider/EvpKeyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,18 @@ static class EdDSA extends EvpKeyFactory {
}

@Override
protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
protected PrivateKey engineGeneratePrivate(final KeySpec keySpec)
throws InvalidKeySpecException {
return super.engineGeneratePrivate(keySpec);
}

@Override
protected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException {
protected PublicKey engineGeneratePublic(final KeySpec keySpec) throws InvalidKeySpecException {
return super.engineGeneratePublic(keySpec);
}

@Override
protected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec)
protected <T extends KeySpec> T engineGetKeySpec(final Key key, final Class<T> keySpec)
throws InvalidKeySpecException {
return super.engineGetKeySpec(key, keySpec);
}
Expand Down
4 changes: 2 additions & 2 deletions tst/com/amazon/corretto/crypto/provider/test/EdDSATest.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void jceInteropValidation() throws GeneralSecurityException {

@Test
public void bcInteropValidation() throws GeneralSecurityException {
// Generate keys with ACCP and use BC KeyFactory to get equivalent JCE Keys
// Generate keys with ACCP and use BC KeyFactory to get equivalent Keys
final Signature nativeSig = Signature.getInstance("Ed25519", NATIVE_PROVIDER);
final Signature bcSig = Signature.getInstance("Ed25519", BOUNCYCASTLE_PROVIDER);
final KeyPair keyPair = nativeGen.generateKeyPair();
Expand Down Expand Up @@ -192,7 +192,7 @@ public void bcInteropValidation() throws GeneralSecurityException {

@Test
public void bcKeyValidation() throws GeneralSecurityException {
// Generate keys with ACCP and use BC KeyFactory to get equivalent JCE Keys
// Generate keys with ACCP and use BC KeyFactory to get equivalent Keys
final KeyPair kp = nativeGen.generateKeyPair();
final byte[] pkACCP = kp.getPrivate().getEncoded();
final byte[] pbkACCP = kp.getPublic().getEncoded();
Expand Down

0 comments on commit 3834860

Please sign in to comment.