Diffie Hellman Key Agreement using optional subprime q with DHParameterSpec in Java

406 Views Asked by At

I am trying to perform a Diffie Hellman Hey agreement, and as part of the parameter definition, I have 3 values:

a prime modulus p a base generator g a subprime q

looking at the various constructors for creating the keys necessary to perform this agreement, I don't seem to be able to set the q value:

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/javax/crypto/spec/DHParameterSpec.html

DHParameterSpec​(BigInteger p, BigInteger g)
Constructs a parameter set for Diffie-Hellman, using a prime modulus p and a base generator g. DHParameterSpec​(BigInteger p, BigInteger g, int l)
Constructs a parameter set for Diffie-Hellman, using a prime modulus p, a base generator g, and the size in bits, l, of the random exponent (private value).

and https://docs.oracle.com/javase/9/docs/api/javax/crypto/spec/DHPublicKeySpec.html

DHPublicKeySpec​(BigInteger y, BigInteger p, BigInteger g)
Constructor that takes a public value y, a prime modulus p, and a base generator g.

https://docs.oracle.com/javase/9/docs/api/javax/crypto/spec/DHPrivateKeySpec.html

DHPrivateKeySpec​(BigInteger x, BigInteger p, BigInteger g)
Constructor that takes a private value x, a prime modulus p, and a base generator g.

Now, I know that Bouncy Castle has an implementation that supports this:

https://people.eecs.berkeley.edu/~jonah/bc/org/bouncycastle/crypto/params/DHParameters.html

But I cannot use Bouncy Castle.

Is there a way to still use DHParameterSpec/DHPublicKey/DHPrivateKey with the q value that I am missing?

1

There are 1 best solutions below

0
Rakesh Nayak On

Use DSA BigInteger getG() Returns the base g. BigInteger getP() Returns the prime p. BigInteger getQ() Returns the sub-prime q. https://docs.oracle.com/javase/7/docs/api/java/security/spec/DSAParameterSpec.html