1

I've seen various references on the web for generating Elliptic Curve KeyPairs in Java, and the two most commonly referenced examples (unsurprisingly) use the JDK default provider and BouncyCastle.

But what confuses me is that the JDK default provider supports a single KeyPairGenerator algorithm name of EC while BouncyCastle also supports that as well as two additional distinct algorithm names of ECDSA and ECDH:

JDK default provider example:

KeyPairGenerator g = KeyPairGenerator.getInstance("EC");
ECGenParameterSpec spec = new ECGenParameterSpec("secp256r1");
g.initialize(spec);
KeyPair keyPair = g.generateKeyPair();

BouncyCastle provider ECDSA example:

KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");
ECGenParameterSpec spec = new ECGenParameterSpec("secp256r1");
g.initialize(spec);
KeyPair keyPair = g.generateKeyPair();

BouncyCastle provider ECDH example:

KeyPairGenerator g = KeyPairGenerator.getInstance("ECDH", "BC");
ECGenParameterSpec spec = new ECGenParameterSpec("secp256r1");
g.initialize(spec);
KeyPair keyPair = g.generateKeyPair();

In summary, the BouncyCastle provider supports all three algorithm names, EC, ECDSA and ECDH while the JDK default provider supports only EC.

Why the discrepancy? Is there any meaningful difference in the resulting keys used in any of these approaches?

1

Oracle Java documentation is a little sparse on the topic, but it does look like with the SunJCE, a key generated asEC can be used with either ECDH or ECDSA. (source):

SunEC provider algorithm specs

(I'm not an Elliptic curve expert, but) Theoretically, I believe that the domain parameters for ECDH and ECDSA have the same form, that is the equation of the curve and a base point G

(CURVE, G)

(You'll often see the expanded form

(p, a, b, G, n, h)

where p, a, b are the equation of the curve, and n, h are values derived from G, provided to save computation)

And the keypairs for both algorithms are the same, namely:

priv_key: an integer d in [1, n-1]
pub_key: a point on the curve Q = (x,y) = d*G

Bottom line: Yes, keys are interchangeable between ECDH and ECDSA. Having dug through the Oracle documentation, I'm too lazy to go through Bouncy Castle too, but I would assume that EC, ECDH and ECDSA are all aliases to the same thing, put there to avoid confusion.

  • That was my assumption too - but the domain parameters explanation (and link) really helped clarify/settle this for me. Thanks for the answer Mike - it is much appreciated! – Les Hazlewood Aug 3 '18 at 1:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.