Package org.apache.sshd.common.kex
Class AbstractDH
- java.lang.Object
-
- org.apache.sshd.common.kex.AbstractDH
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
e_array
private byte[]
k_array
protected javax.crypto.KeyAgreement
myKeyAgree
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDH()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract byte[]
calculateE()
Lazy-called bygetE()
if the public key data has not been generated yet.protected abstract byte[]
calculateK()
Lazy-called bygetK()
if the shared secret data has not been calculated yetprotected void
checkKeyAgreementNecessity()
Called after either public or private parts have been calculated in order to check if the key-agreement mediator is still required.byte[]
getE()
abstract Digest
getHash()
byte[]
getK()
boolean
isPublicDataAvailable()
boolean
isSharedSecretAvailable()
abstract void
setF(byte[] f)
static byte[]
stripLeadingZeroes(byte[] x)
The shared secret returned byKeyAgreement.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).java.lang.String
toString()
-
-
-
Method Detail
-
setF
public abstract void setF(byte[] f)
-
isPublicDataAvailable
public boolean isPublicDataAvailable()
-
calculateE
protected abstract byte[] calculateE() throws java.lang.Exception
Lazy-called bygetE()
if the public key data has not been generated yet.- Returns:
- The calculated public key data
- Throws:
java.lang.Exception
- If failed to generate the relevant data
-
getE
public byte[] getE() throws java.lang.Exception
- Returns:
- The local public key data
- Throws:
java.lang.Exception
- If failed to calculate it
-
isSharedSecretAvailable
public boolean isSharedSecretAvailable()
-
calculateK
protected abstract byte[] calculateK() throws java.lang.Exception
Lazy-called bygetK()
if the shared secret data has not been calculated yet- Returns:
- The shared secret data
- Throws:
java.lang.Exception
- If failed to calculate it
-
getK
public byte[] getK() throws java.lang.Exception
- Returns:
- The shared secret key
- Throws:
java.lang.Exception
- If failed to calculate it
-
checkKeyAgreementNecessity
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.
-
getHash
public abstract Digest getHash() throws java.lang.Exception
- Throws:
java.lang.Exception
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
stripLeadingZeroes
public static byte[] stripLeadingZeroes(byte[] x)
The shared secret returned byKeyAgreement.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
- The original array- Returns:
- An (possibly) sub-array guaranteed to start with a non-zero byte
- Throws:
java.lang.IllegalArgumentException
- If all zeroes array- See Also:
- SSHD-330
-
-