Package com.southernstorm.noise.protocol
Class Curve25519DHState
- java.lang.Object
-
- com.southernstorm.noise.protocol.Curve25519DHState
-
- All Implemented Interfaces:
Destroyable,DHState
class Curve25519DHState extends Object implements DHState
Implementation of the Curve25519 algorithm for the Noise protocol.
-
-
Constructor Summary
Constructors Constructor Description Curve25519DHState(X25519KeyFactory xdh)Constructs a new Diffie-Hellman object for Curve25519.
-
Method Summary
All Methods Instance Methods Concrete 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.voiddestroy()Destroys all sensitive state in the current object.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.
-
-
-
Constructor Detail
-
Curve25519DHState
public Curve25519DHState(X25519KeyFactory xdh)
Constructs a new Diffie-Hellman object for Curve25519.
-
-
Method Detail
-
destroy
public void destroy()
Description copied from interface:DestroyableDestroys all sensitive state in the current object.- Specified by:
destroyin interfaceDestroyable
-
getDHName
public String getDHName()
Description copied from interface:DHStateGets the Noise protocol name for this Diffie-Hellman algorithm.
-
getPublicKeyLength
public int getPublicKeyLength()
Description copied from interface:DHStateGets the length of public keys for this algorithm.- Specified by:
getPublicKeyLengthin interfaceDHState- Returns:
- The length of public keys in bytes.
-
getPrivateKeyLength
public int getPrivateKeyLength()
Description copied from interface:DHStateGets the length of private keys for this algorithm.- Specified by:
getPrivateKeyLengthin interfaceDHState- Returns:
- The length of private keys in bytes.
-
getSharedKeyLength
public int getSharedKeyLength()
Description copied from interface:DHStateGets the length of shared keys for this algorithm.- Specified by:
getSharedKeyLengthin interfaceDHState- Returns:
- The length of shared keys in bytes.
-
generateKeyPair
public void generateKeyPair()
Description copied from interface:DHStateGenerates a new random keypair.- Specified by:
generateKeyPairin interfaceDHState
-
getPublicKey
public void getPublicKey(byte[] key, int offset)Description copied from interface:DHStateGets the public key associated with this object.- Specified by:
getPublicKeyin 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:DHStateSets the public key for this object.- Specified by:
setPublicKeyin 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:DHStateGets the private key associated with this object.- Specified by:
getPrivateKeyin interfaceDHState- Parameters:
key- The buffer to copy the private key to.offset- The first offset in the key buffer to copy to.
-
setPrivateKey
public void setPrivateKey(byte[] key, int offset)Description copied from interface:DHStateSets the private key for this object.- Specified by:
setPrivateKeyin 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.
-
setToNullPublicKey
public void setToNullPublicKey()
Description copied from interface:DHStateSets this object to the null public key and clears the private key.- Specified by:
setToNullPublicKeyin interfaceDHState
-
clearKey
public void clearKey()
Description copied from interface:DHStateClears the key pair.
-
hasPublicKey
public boolean hasPublicKey()
Description copied from interface:DHStateDetermine if this object contains a public key.- Specified by:
hasPublicKeyin 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:DHStateDetermine if this object contains a private key.- Specified by:
hasPrivateKeyin 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:DHStateDetermine if the public key in this object is the special null value.- Specified by:
isNullPublicKeyin interfaceDHState- Returns:
- Returns true if the public key is the special null value, or false otherwise.
-
calculate
public void calculate(byte[] sharedKey, int offset, DHState publicDH)Description copied from interface:DHStatePerforms a Diffie-Hellman calculation with this object as the private key.
-
-