java.lang.Object
com.southernstorm.noise.protocol.Curve25519DHState
- All Implemented Interfaces:
Destroyable, DHState, Cloneable
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final KeyFactoryFactory encoding the keys for display.private byte[]Cache of the public key in encoded form.private intWhich of the two keys are set.private final byte[]The raw 32-byte private key.private final byte[]The raw 32-byte public key.Constructor Summary
ConstructorsConstructorDescriptionConstructs a new Diffie-Hellman object for Curve25519.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidPerforms a Diffie-Hellman calculation with this object as the private key.voidclearKey()Clears the key pair.clone()I2PvoidCopies the key values from another DH object of the same type.voiddestroy()Destroys all sensitive state in the current object.voidGenerates a new random keypair.Gets the Noise protocol name for this Diffie-Hellman algorithm.voidgetEncodedPublicKey(byte[] key, int offset) I2PvoidgetPrivateKey(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.booleanI2PbooleanDetermine 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.voidsetKeys(byte[] privkey, int privoffset, byte[] pubkey, int puboffset) Sets the private and public keys 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.
Field Details
publicKey
private final byte[] publicKeyThe raw 32-byte public key.privateKey
private final byte[] privateKeyThe raw 32-byte private key.mode
private int modeWhich of the two keys are set._xdh
Factory encoding the keys for display.encodedPublicKey
private byte[] encodedPublicKeyCache of the public key in encoded form.
Constructor Details
Curve25519DHState
Constructs a new Diffie-Hellman object for Curve25519.- Parameters:
xdh- the key factory that supplies the Curve25519 key pair
Method Details
destroy
public void destroy()Description copied from interface:DestroyableDestroys all sensitive state in the current object.- Specified by:
destroyin interfaceDestroyable
getDHName
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.
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.
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:DHStateSets this object to the null public key and clears the private key.- Specified by:
setToNullPublicKeyin interfaceDHState
clearKey
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.
hasEncodedPublicKey
public boolean hasEncodedPublicKey()I2P- Specified by:
hasEncodedPublicKeyin interfaceDHState- Returns:
- Returns true if this object contains an encoded public key, or false if the public key has not yet been set.
getEncodedPublicKey
public void getEncodedPublicKey(byte[] key, int offset) I2P- Specified by:
getEncodedPublicKeyin interfaceDHState- Parameters:
key- The buffer to copy the public key to.offset- The first offset in the key buffer to copy to.
calculate
Description copied from interface:DHStatePerforms a Diffie-Hellman calculation with this object as the private key.copyFrom
clone
I2P- Specified by:
clonein interfaceDHState- Overrides:
clonein classObject- Returns:
- a copy of this DH state holding the same key material
- Throws:
CloneNotSupportedException- if this DH state does not implement Cloneable