Bouncy Castle elliptic curve from explicit parameters (E-521) I'd like to use a curve that's not included in the Bouncy Castle EC named curves spec, specifically E-521.

According to the BC javadocs, you need a few values in order to do this: q, a, and b for the curve, then G and n for the parameter spec.



import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.jce.spec.ECParameterSpec;
...
ECCurve curve = new ECCurve.Fp(
            new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
            new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
            new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
ECParameterSpec ecSpec = new ECParameterSpec(
            curve,
            curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
            new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");
g.initialize(ecSpec, new SecureRandom());
KeyPair pair = g.generateKeyPair();


I think q is the field.

Would a and b be base points?

What should be used for G and n?
In order to do this, first convert the Edwards curve to Montgomery form, then to Weierstrass form, per this thread.

But, as the above thread explains, as well as CodesInChaos' comment, this will result in poor performance.

Thanks to CodesInChaos for pointing me in the right direction despite the stupid question.

Also see:


Elliptic Curves of different forms
http://samuelkerr.com/?p=431 which has a nice Python script for going from Montgomery to Weierstrass