- All Superinterfaces:
Destroyable
- All Known Subinterfaces:
DHStateHybrid
Interface to a Diffie-Hellman algorithm for the Noise protocol.
-
Method Summary
Modifier and TypeMethodDescriptionvoidPerforms a Diffie-Hellman calculation with this object as the private key.voidclearKey()Clears the key pair.voidCopies the key values from another DH object of the same type.voidGenerates a new random keypair.Gets the Noise protocol name for this Diffie-Hellman algorithm.voidgetPrivateKey(byte[] key, int offset)Gets the private key associated with this object.intGets the length of private keys for this algorithm.voidgetPublicKey(byte[] key, int offset)Gets the public key associated with this object.intGets the length of public keys for this algorithm.intGets the length of shared keys for this algorithm.booleanDetermine if this object contains a private key.booleanDetermine if this object contains a public key.booleanDetermine 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.voidSets this object to the null public key and clears the private key.Methods inherited from interface com.southernstorm.noise.protocol.Destroyable
destroy
-
Method Details
-
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.
-
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
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
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.
-