17
17
import org .bouncycastle .jcajce .provider .config .ProviderConfiguration ;
18
18
import org .bouncycastle .jcajce .provider .util .AlgorithmProvider ;
19
19
import org .bouncycastle .jcajce .provider .util .AsymmetricKeyInfoConverter ;
20
+ import org .bouncycastle .tls .injection .InjectionPoint ;
20
21
21
22
public class BouncyCastlePQCProvider
22
23
extends Provider
@@ -43,6 +44,19 @@ public class BouncyCastlePQCProvider
43
44
"Dilithium" , "NTRUPrime" , "BIKE" , "HQC" , "Rainbow"
44
45
};
45
46
47
+ /**
48
+ * #tls-injection
49
+ * ALGORITHM_MAPPING_CLASSES contains real classes corresponding to the names given in ALGORITHMS.
50
+ * We rely on ALGORITHM_MAPPING_CLASSES when we are unable to load classes by names via reflection
51
+ * (important, since we cannot rely fully on reflection in NativeImage from GraalVM).
52
+ * #pqc-tls
53
+ */
54
+ private static final Class <?>[] ALGORITHM_MAPPING_CLASSES = {
55
+ SPHINCS .Mappings .class , LMS .Mappings .class , NH .Mappings .class , XMSS .Mappings .class , SPHINCSPlus .Mappings .class ,
56
+ CMCE .Mappings .class , Frodo .Mappings .class , SABER .Mappings .class , Picnic .Mappings .class , NTRU .Mappings .class , Falcon .Mappings .class , Kyber .Mappings .class ,
57
+ Dilithium .Mappings .class , NTRUPrime .Mappings .class , BIKE .Mappings .class , HQC .Mappings .class , Rainbow .Mappings .class
58
+ };
59
+
46
60
/**
47
61
* Construct a new provider. This should only be required when
48
62
* using runtime registration of the provider using the
@@ -71,21 +85,31 @@ private void loadAlgorithms(String packageName, String[] names)
71
85
{
72
86
for (int i = 0 ; i != names .length ; i ++)
73
87
{
74
- Class clazz = loadClass (BouncyCastlePQCProvider .class , packageName + names [i ] + "$Mappings" );
88
+ Class clazz ;
89
+ if (i <ALGORITHM_MAPPING_CLASSES .length && ALGORITHM_MAPPING_CLASSES [i ].getSimpleName ().equals (ALGORITHMS [i ])) {
90
+ // if ALGORITHM_CLASSES[i] indeed corresponds to ALGORITHM[i], we do not use reflection #pqc-tls
91
+ clazz = ALGORITHM_MAPPING_CLASSES [i ];
92
+ }
93
+ else
94
+ clazz = loadClass (BouncyCastlePQCProvider .class , packageName + names [i ] + "$Mappings" );
75
95
76
96
if (clazz != null )
77
97
{
78
98
try
79
99
{
80
- ((AlgorithmProvider )clazz .newInstance ()).configure (this );
100
+ ((AlgorithmProvider )clazz .getConstructor ().newInstance ()).configure (this );
101
+ // ^^^ replaces deprecated: ((AlgorithmProvider)clazz.newInstance()).configure(this);
81
102
}
82
103
catch (Exception e )
83
104
{ // this should never ever happen!!
84
105
throw new InternalError ("cannot create instance of "
85
106
+ packageName + names [i ] + "$Mappings : " + e );
86
107
}
87
108
}
109
+
88
110
}
111
+ // Add also injected algorithms to our provider: #tls-injection
112
+ InjectionPoint .configureProvider (this );
89
113
}
90
114
91
115
public void setParameter (String parameterName , Object parameter )
0 commit comments