Package com.southernstorm.noise.protocol
Class Curve25519DHState
java.lang.Object
com.southernstorm.noise.protocol.Curve25519DHState
- All Implemented Interfaces:
Destroyable
,DHState
,Cloneable
Implementation of the Curve25519 algorithm for the Noise protocol.
-
Constructor Summary
ConstructorDescriptionConstructs a new Diffie-Hellman object for Curve25519. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Performs a Diffie-Hellman calculation with this object as the private key.void
clearKey()
Clears the key pair.clone()
I2Pvoid
Copies the key values from another DH object of the same type.void
destroy()
Destroys all sensitive state in the current object.void
Generates a new random keypair.Gets the Noise protocol name for this Diffie-Hellman algorithm.void
getEncodedPublicKey
(byte[] key, int offset) I2Pvoid
getPrivateKey
(byte[] key, int offset) Gets the private key associated with this object.int
Gets the length of private keys for this algorithm.void
getPublicKey
(byte[] key, int offset) Gets the public key associated with this object.int
Gets the length of public keys for this algorithm.int
Gets the length of shared keys for this algorithm.boolean
I2Pboolean
Determine if this object contains a private key.boolean
Determine if this object contains a public key.boolean
Determine if the public key in this object is the special null value.void
setKeys
(byte[] privkey, int privoffset, byte[] pubkey, int puboffset) Sets the private and public keys for this object.void
setPrivateKey
(byte[] key, int offset) Deprecated.use setKeys()void
setPublicKey
(byte[] key, int offset) Sets the public key for this object.void
Sets this object to the null public key and clears the private key.
-
Constructor Details
-
Curve25519DHState
Constructs a new Diffie-Hellman object for Curve25519.
-
-
Method Details
-
destroy
public void destroy()Description copied from interface:Destroyable
Destroys all sensitive state in the current object.- Specified by:
destroy
in interfaceDestroyable
-
getDHName
Description copied from interface:DHState
Gets the Noise protocol name for this Diffie-Hellman algorithm. -
getPublicKeyLength
public int getPublicKeyLength()Description copied from interface:DHState
Gets the length of public keys for this algorithm.- Specified by:
getPublicKeyLength
in interfaceDHState
- Returns:
- The length of public keys in bytes.
-
getPrivateKeyLength
public int getPrivateKeyLength()Description copied from interface:DHState
Gets the length of private keys for this algorithm.- Specified by:
getPrivateKeyLength
in interfaceDHState
- Returns:
- The length of private keys in bytes.
-
generateKeyPair
public void generateKeyPair()Description copied from interface:DHState
Generates a new random keypair.- Specified by:
generateKeyPair
in interfaceDHState
-
getPublicKey
public void getPublicKey(byte[] key, int offset) Description copied from interface:DHState
Gets the public key associated with this object.- Specified by:
getPublicKey
in interfaceDHState
- Parameters:
key
- The buffer to copy the public key to.offset
- The first offset in the key buffer to copy to.
-
setPublicKey
public void setPublicKey(byte[] key, int offset) Description copied from interface:DHState
Sets the public key for this object.- Specified by:
setPublicKey
in interfaceDHState
- 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
public void getPrivateKey(byte[] key, int offset) Description copied from interface:DHState
Gets the private key associated with this object.- Specified by:
getPrivateKey
in interfaceDHState
- Parameters:
key
- The buffer to copy the private key to.offset
- The first offset in the key buffer to copy to.
-
setPrivateKey
Deprecated.use setKeys()Description copied from interface:DHState
Sets the private key for this object.- Specified by:
setPrivateKey
in interfaceDHState
- 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.
-
setKeys
public void setKeys(byte[] privkey, int privoffset, byte[] pubkey, int puboffset) Sets the private and public keys for this object. I2P for efficiency, since setPrivateKey() calculates the public key and overwrites it. Does NOT check that the two keys match. -
setToNullPublicKey
public void setToNullPublicKey()Description copied from interface:DHState
Sets this object to the null public key and clears the private key.- Specified by:
setToNullPublicKey
in interfaceDHState
-
clearKey
public void clearKey()Description copied from interface:DHState
Clears the key pair. -
hasPublicKey
public boolean hasPublicKey()Description copied from interface:DHState
Determine if this object contains a public key.- Specified by:
hasPublicKey
in interfaceDHState
- Returns:
- Returns true if this object contains a public key, or false if the public key has not yet been set.
-
hasPrivateKey
public boolean hasPrivateKey()Description copied from interface:DHState
Determine if this object contains a private key.- Specified by:
hasPrivateKey
in interfaceDHState
- Returns:
- Returns true if this object contains a private key, or false if the private key has not yet been set.
-
isNullPublicKey
public boolean isNullPublicKey()Description copied from interface:DHState
Determine if the public key in this object is the special null value.- Specified by:
isNullPublicKey
in interfaceDHState
- Returns:
- Returns true if the public key is the special null value, or false otherwise.
-
hasEncodedPublicKey
public boolean hasEncodedPublicKey()I2P- Specified by:
hasEncodedPublicKey
in interfaceDHState
- Returns:
- Returns true if this object contains an encoded public key, or false if the public key has not yet been set.
- Since:
- 0.9.44
-
getEncodedPublicKey
public void getEncodedPublicKey(byte[] key, int offset) I2P- Specified by:
getEncodedPublicKey
in interfaceDHState
- Parameters:
key
- The buffer to copy the public key to.offset
- The first offset in the key buffer to copy to.- Since:
- 0.9.44
-
calculate
Description copied from interface:DHState
Performs a Diffie-Hellman calculation with this object as the private key. -
copyFrom
Description copied from interface:DHState
Copies the key values from another DH object of the same type. -
clone
I2P- Specified by:
clone
in interfaceDHState
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
- Since:
- 0.9.44
-