Top Description Fields Constructors Methods
org.apache.sshd.common.kex

public abstract Class AbstractDH

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.sshd.common.kex.DHG, org.apache.sshd.common.kex.ECDH, org.apache.sshd.common.kex.XDH
Imports
javax.crypto.KeyAgreement, org.apache.sshd.common.digest.Digest, org.apache.sshd.common.util.NumberUtils, org.apache.sshd.common.util.buffer.Buffer

Base class for the Diffie-Hellman key agreement.

Field Summary

Modifier and TypeField and Description
private byte[]
private byte[]
protected KeyAgreement

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected abstract byte[]

Returns:

The calculated public key data
calculateE
()

Lazy-called by getE() if the public key data has not been generated yet.

protected abstract byte[]

Returns:

The shared secret data
calculateK
()

Lazy-called by getK() if the shared secret data has not been calculated yet

protected void
checkKeyAgreementNecessity()

Called after either public or private parts have been calculated in order to check if the key-agreement mediator is still required.

public byte[]

Returns:

The local public key data
getE
()

public abstract Digest
public byte[]

Returns:

The shared secret key
getK
()

public KeyEncapsulationMethod
public boolean
public boolean
public void
putE(Buffer buffer, byte[] e)

public void
putF(Buffer buffer, byte[] f)

public abstract void
setF(byte[] f)

public static byte[]

Returns:

An (possibly) sub-array guaranteed to start with a non-zero byte
stripLeadingZeroes
(byte[]
The original array
x
)

The shared secret returned by javax.crypto.KeyAgreement#generateSecret() is a byte array, which can (by chance, roughly 1 out of 256 times) begin with zero byte (some JCE providers might strip this, though).

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

e_arrayback to summary
private byte[] e_array
k_arrayback to summary
private byte[] k_array
myKeyAgreeback to summary
protected KeyAgreement myKeyAgree

Constructor Detail

AbstractDHback to summary
protected AbstractDH()

Method Detail

calculateEback to summary
protected abstract byte[] calculateE() throws Exception

Lazy-called by getE() if the public key data has not been generated yet.

Returns:byte[]

The calculated public key data

Exceptions
Exception:
If failed to generate the relevant data
calculateKback to summary
protected abstract byte[] calculateK() throws Exception

Lazy-called by getK() if the shared secret data has not been calculated yet

Returns:byte[]

The shared secret data

Exceptions
Exception:
If failed to calculate it
checkKeyAgreementNecessityback to summary
protected void checkKeyAgreementNecessity()

Called after either public or private parts have been calculated in order to check if the key-agreement mediator is still required. By default, if both public and private parts have been calculated then key-agreement mediator is null-ified to enable GC for it.

See Also
getE(), getK()
getEback to summary
public byte[] getE() throws Exception
Returns:byte[]

The local public key data

Exceptions
Exception:
If failed to calculate it
getHashback to summary
public abstract Digest getHash() throws Exception
getKback to summary
public byte[] getK() throws Exception
Returns:byte[]

The shared secret key

Exceptions
Exception:
If failed to calculate it
getKeyEncapsulationback to summary
public KeyEncapsulationMethod getKeyEncapsulation()
isPublicDataAvailableback to summary
public boolean isPublicDataAvailable()
isSharedSecretAvailableback to summary
public boolean isSharedSecretAvailable()
putEback to summary
public void putE(Buffer buffer, byte[] e)
putFback to summary
public void putF(Buffer buffer, byte[] f)
setFback to summary
public abstract void setF(byte[] f)
stripLeadingZeroesback to summary
public static byte[] stripLeadingZeroes(byte[] x)

The shared secret returned by javax.crypto.KeyAgreement#generateSecret() is a byte array, which can (by chance, roughly 1 out of 256 times) begin with zero byte (some JCE providers might strip this, though). In SSH, the shared secret is an integer, so we need to strip the leading zero(es).

Parameters
x:byte[]

The original array

Returns:byte[]

An (possibly) sub-array guaranteed to start with a non-zero byte

Exceptions
IllegalArgumentException:
If all zeroes array
See Also
SSHD-330
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override