com.jcraft.jsch

## Interface DH

• `public interface DH`
Usually not to be used by applications. The implementation of the cryptographic algorithms in the Diffie-Hellman key exchange.

The group in question here is the multiplicative group of the finite field with `p` elements. It (or at least a quite large subgroup of it) should be generated by `g`.

Here is a short view of the algorithm (which would work in any group which we could somehow encode as numbers, by the way):

• We generate a random number `x`, calculate `e = g^x` and send `e` to the server.
• The server generates a random number `y`, calculates `f = g^y` and sends us `f`.
• We can know calculate `{@code K = f^x}`, while the server calculates `K = e^y` (and since multiplication of integers is commutative, `e^y = (g^x)^y = g^(x*y) = g^(y*x) = (g^y)^x = f^x`, both have the same number.)

The methods of this interface will generally be called in the order defined here, each once.

The implementing class has to do the random number generation of x and the modular arithmetic.

The implementing class will be chosen by the configuration option `"dh"`, a default implementation is delivered with the library.

RFC 4253, section 8. Diffie-Hellman Key Exchange, RFC 4419, Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol
• ### Method Summary

All Methods
Modifier and Type Method and Description
`void` `checkRange()`
`byte[]` `getE()`
Retrieves the value `e`, that is the result of `g^x mod P`.
`byte[]` `getK()`
Retrieves the secret number K which was created by the key exchange and will be used to create the key.
`void` `init()`
initializes the algorithm object for a new exchange.
`void` `setF(byte[] f)`
Sets the value of `f`, that is the result of `g^y mod P`
`void` `setG(byte[] g)`
Sets the generator of the group.
`void` `setP(byte[] p)`
Sets the prime number, modulo which the calculations should be done.
• ### Method Detail

• #### init

```void init()
throws Exception```
initializes the algorithm object for a new exchange.
Throws:
`Exception`
• #### setP

`void setP(byte[] p)`
Sets the prime number, modulo which the calculations should be done.
• #### setG

`void setG(byte[] g)`
Sets the generator of the group. (This will be most often 2 or another small prime.)
• #### getE

```byte[] getE()
throws Exception```
Retrieves the value `e`, that is the result of `g^x mod P`.
Throws:
`Exception`
• #### setF

`void setF(byte[] f)`
Sets the value of `f`, that is the result of `g^y mod P`
• #### getK

```byte[] getK()
throws Exception```
Retrieves the secret number K which was created by the key exchange and will be used to create the key.
Throws:
`Exception`
• #### checkRange

```void checkRange()
throws Exception```
Throws:
`Exception`

This is an inofficial Javadoc created by Paŭlo Ebermann. Have a look at the official homepage.