@@ -64,6 +64,7 @@ public final class AmazonCorrettoCryptoProvider extends java.security.Provider {
64
64
private final boolean relyOnCachedSelfTestResults ;
65
65
private final boolean shouldRegisterEcParams ;
66
66
private final boolean shouldRegisterSecureRandom ;
67
+ private final boolean shouldRegisterEdKeyFactory ;
67
68
private final boolean shouldRegisterMLDSA ;
68
69
private final Utils .NativeContextReleaseStrategy nativeContextReleaseStrategy ;
69
70
@@ -100,8 +101,14 @@ private void buildServiceMap() {
100
101
addService ("KeyFactory" , "ML-DSA-87" , "EvpKeyFactory$MLDSA" );
101
102
}
102
103
103
- addService ("KeyFactory" , "EdDSA" , "EvpKeyFactory$EdDSA" );
104
- addService ("KeyFactory" , "Ed25519" , "EvpKeyFactory$EdDSA" );
104
+ // KeyFactories are used to convert key encodings to Java Key objects. ACCP's KeyFactory for
105
+ // Ed25519 returns keys of type EvpEdPublicKey and EvpEdPrivateKey that do not implement
106
+ // EdECKey interface. One should register the KeyFactories from ACCP if they only use the
107
+ // output of the factories with ACCP's services.
108
+ if (shouldRegisterEdKeyFactory ) {
109
+ addService ("KeyFactory" , "EdDSA" , "EvpKeyFactory$EdDSA" );
110
+ addService ("KeyFactory" , "Ed25519" , "EvpKeyFactory$EdDSA" );
111
+ }
105
112
addService ("KeyPairGenerator" , "EdDSA" , "EdGen" );
106
113
addService ("KeyPairGenerator" , "Ed25519" , "EdGen" );
107
114
@@ -498,6 +505,9 @@ public AmazonCorrettoCryptoProvider() {
498
505
this .shouldRegisterSecureRandom =
499
506
Utils .getBooleanProperty (PROPERTY_REGISTER_SECURE_RANDOM , true );
500
507
508
+ this .shouldRegisterEdKeyFactory =
509
+ Utils .getBooleanProperty (PROPERTY_REGISTER_ED_KEYFACTORY , false );
510
+
501
511
this .shouldRegisterMLDSA = (!isFips () || isExperimentalFips ());
502
512
503
513
this .nativeContextReleaseStrategy = Utils .getNativeContextReleaseStrategyProperty ();
@@ -731,7 +741,7 @@ KeyFactory getKeyFactory(EvpKeyType keyType) {
731
741
return ecFactory ;
732
742
case EdDSA :
733
743
if (edFactory == null ) {
734
- ecFactory = KeyFactory . getInstance ( keyType . jceName , this );
744
+ edFactory = new EdKeyFactory ( this );
735
745
}
736
746
return edFactory ;
737
747
case MLDSA :
@@ -760,4 +770,12 @@ EvpKey translateKey(Key key, EvpKeyType keyType) throws InvalidKeyException {
760
770
return (EvpKey ) getKeyFactory (keyType ).translateKey (key );
761
771
}
762
772
}
773
+
774
+ // In case the user does not register Ed25519 KeyFactories by ACCP, we still need one to be used
775
+ // internally.
776
+ private static class EdKeyFactory extends KeyFactory {
777
+ EdKeyFactory (final AmazonCorrettoCryptoProvider provider ) {
778
+ super (new EvpKeyFactory .EdDSA (provider ), provider , "Ed25519" );
779
+ }
780
+ }
763
781
}
0 commit comments