Implement initialize(int, SecureRandom)
fix setting of secureRandom initializer
package org.bouncycastle.jcajce.provider.asymmetric.edec;
import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidParameterException;
import java.security.KeyPair;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
public void initialize(int strength, SecureRandom secureRandom)
{
- // TODO: should we make sure strength makes sense?
this.secureRandom = secureRandom;
+
+ switch (strength)
+ {
+ case 255:
+ case 256:
+ switch (algorithm)
+ {
+ case EdDSA:
+ case Ed25519:
+ setupGenerator(Ed25519);
+ break;
+ case XDH:
+ case X25519:
+ setupGenerator(X25519);
+ break;
+ default:
+ throw new InvalidParameterException("key size not configurable.");
+ }
+ break;
+ case 448:
+ switch (algorithm)
+ {
+ case EdDSA:
+ case Ed448:
+ setupGenerator(Ed448);
+ break;
+ case XDH:
+ case X448:
+ setupGenerator(X448);
+ break;
+ default:
+ throw new InvalidParameterException("key size not configurable.");
+ }
+ break;
+ default:
+ throw new InvalidParameterException("unknown key size.");
+ }
}
public void initialize(AlgorithmParameterSpec paramSpec, SecureRandom secureRandom)
throws InvalidAlgorithmParameterException
{
+ this.secureRandom = secureRandom;
+
if (paramSpec instanceof ECGenParameterSpec)
{
initializeGenerator(((ECGenParameterSpec)paramSpec).getName());
@@ -72,8 +111,6 @@ else if (paramSpec instanceof XDHParameterSpec)
{
throw new InvalidAlgorithmParameterException("invalid parameterSpec: " + paramSpec);
}
-
- this.secureRandom = secureRandom;
}
private void algorithmCheck(int algorithm)
