Package com.southernstorm.noise.protocol
Interface DHState
-
- All Superinterfaces:
Destroyable
- All Known Implementing Classes:
Curve25519DHState
public interface DHState extends Destroyable
Interface to a Diffie-Hellman algorithm for the Noise protocol.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcalculate(byte[] sharedKey, int offset, DHState publicDH)Performs a Diffie-Hellman calculation with this object as the private key.voidclearKey()Clears the key pair.voidcopyFrom(DHState other)Copies the key values from another DH object of the same type.voidgenerateKeyPair()Generates a new random keypair.StringgetDHName()Gets the Noise protocol name for this Diffie-Hellman algorithm.voidgetPrivateKey(byte[] key, int offset)Gets the private key associated with this object.intgetPrivateKeyLength()Gets the length of private keys for this algorithm.voidgetPublicKey(byte[] key, int offset)Gets the public key associated with this object.intgetPublicKeyLength()Gets the length of public keys for this algorithm.intgetSharedKeyLength()Gets the length of shared keys for this algorithm.booleanhasPrivateKey()Determine if this object contains a private key.booleanhasPublicKey()Determine if this object contains a public key.booleanisNullPublicKey()Determine if the public key in this object is the special null value.voidsetPrivateKey(byte[] key, int offset)Sets the private key for this object.voidsetPublicKey(byte[] key, int offset)Sets the public key for this object.voidsetToNullPublicKey()Sets this object to the null public key and clears the private key.-
Methods inherited from interface com.southernstorm.noise.protocol.Destroyable
destroy
-
-
-
-
Method Detail
-
getDHName
String getDHName()
Gets the Noise protocol name for this Diffie-Hellman algorithm.- Returns:
- The algorithm name.
-
getPublicKeyLength
int getPublicKeyLength()
Gets the length of public keys for this algorithm.- Returns:
- The length of public keys in bytes.
-
getPrivateKeyLength
int getPrivateKeyLength()
Gets the length of private keys for this algorithm.- Returns:
- The length of private keys in bytes.
-
getSharedKeyLength
int getSharedKeyLength()
Gets the length of shared keys for this algorithm.- Returns:
- The length of shared keys in bytes.
-
generateKeyPair
void generateKeyPair()
Generates a new random keypair.
-
getPublicKey
void getPublicKey(byte[] key, int offset)Gets the public key associated with this object.- Parameters:
key- The buffer to copy the public key to.offset- The first offset in the key buffer to copy to.
-
setPublicKey
void setPublicKey(byte[] key, int offset)Sets the public key for this object.- Parameters:
key- The buffer containing the public key.offset- The first offset in the buffer that contains the key. If this object previously held a key pair, then this function will change it into a public key only object.
-
getPrivateKey
void getPrivateKey(byte[] key, int offset)Gets the private key associated with this object.- Parameters:
key- The buffer to copy the private key to.offset- The first offset in the key buffer to copy to.
-
setPrivateKey
void setPrivateKey(byte[] key, int offset)Sets the private key for this object.- Parameters:
key- The buffer containing the [rivate key.offset- The first offset in the buffer that contains the key. If this object previously held only a public key, then this function will change it into a key pair.
-
setToNullPublicKey
void setToNullPublicKey()
Sets this object to the null public key and clears the private key.
-
clearKey
void clearKey()
Clears the key pair.
-
hasPublicKey
boolean hasPublicKey()
Determine if this object contains a public key.- Returns:
- Returns true if this object contains a public key, or false if the public key has not yet been set.
-
hasPrivateKey
boolean hasPrivateKey()
Determine if this object contains a private key.- Returns:
- Returns true if this object contains a private key, or false if the private key has not yet been set.
-
isNullPublicKey
boolean isNullPublicKey()
Determine if the public key in this object is the special null value.- Returns:
- Returns true if the public key is the special null value, or false otherwise.
-
calculate
void calculate(byte[] sharedKey, int offset, DHState publicDH)Performs a Diffie-Hellman calculation with this object as the private key.- Parameters:
sharedKey- Buffer to put the shared key into.offset- Offset of the first byte for the shared key.publicDH- Object that contains the public key for the calculation.- Throws:
IllegalArgumentException- The publicDH object is not the same type as this object, or one of the objects does not contain a valid key.
-
copyFrom
void copyFrom(DHState other)
Copies the key values from another DH object of the same type.- Parameters:
other- The other DH object to copy from- Throws:
IllegalStateException- The other DH object does not have the same type as this object.
-
-