Class Curve25519DHState

java.lang.Object
com.southernstorm.noise.protocol.Curve25519DHState
All Implemented Interfaces:
Destroyable, DHState, Cloneable

class Curve25519DHState extends Object implements DHState, Cloneable
Implementation of the Curve25519 algorithm for the Noise protocol.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Diffie-Hellman object for Curve25519.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    calculate(byte[] sharedKey, int offset, DHState publicDH)
    Performs a Diffie-Hellman calculation with this object as the private key.
    void
    Clears the key pair.
    I2P
    void
    Copies the key values from another DH object of the same type.
    void
    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)
    I2P
    void
    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
    I2P
    boolean
    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.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Curve25519DHState

      public Curve25519DHState(KeyFactory xdh)
      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 interface Destroyable
    • getDHName

      public String getDHName()
      Description copied from interface: DHState
      Gets the Noise protocol name for this Diffie-Hellman algorithm.
      Specified by:
      getDHName in interface DHState
      Returns:
      The algorithm name.
    • getPublicKeyLength

      public int getPublicKeyLength()
      Description copied from interface: DHState
      Gets the length of public keys for this algorithm.
      Specified by:
      getPublicKeyLength in interface DHState
      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 interface DHState
      Returns:
      The length of private keys in bytes.
    • getSharedKeyLength

      public int getSharedKeyLength()
      Description copied from interface: DHState
      Gets the length of shared keys for this algorithm.
      Specified by:
      getSharedKeyLength in interface DHState
      Returns:
      The length of shared keys in bytes.
    • generateKeyPair

      public void generateKeyPair()
      Description copied from interface: DHState
      Generates a new random keypair.
      Specified by:
      generateKeyPair in interface DHState
    • 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 interface DHState
      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 interface DHState
      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 interface DHState
      Parameters:
      key - The buffer to copy the private key to.
      offset - The first offset in the key buffer to copy to.
    • setPrivateKey

      @Deprecated public void setPrivateKey(byte[] key, int offset)
      Deprecated.
      use setKeys()
      Description copied from interface: DHState
      Sets the private key for this object.
      Specified by:
      setPrivateKey in interface DHState
      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.
      Specified by:
      setKeys in interface DHState
      Parameters:
      privkey - The buffer containing the private key.
      privoffset - The first offset in the buffer that contains the key.
      pubkey - The buffer containing the public key.
      puboffset - The first offset in the buffer that contains the key.
      Since:
      0.9.48
    • 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 interface DHState
    • clearKey

      public void clearKey()
      Description copied from interface: DHState
      Clears the key pair.
      Specified by:
      clearKey in interface DHState
    • hasPublicKey

      public boolean hasPublicKey()
      Description copied from interface: DHState
      Determine if this object contains a public key.
      Specified by:
      hasPublicKey in interface DHState
      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 interface DHState
      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 interface DHState
      Returns:
      Returns true if the public key is the special null value, or false otherwise.
    • hasEncodedPublicKey

      public boolean hasEncodedPublicKey()
      I2P
      Specified by:
      hasEncodedPublicKey in interface DHState
      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 interface DHState
      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

      public void calculate(byte[] sharedKey, int offset, DHState publicDH)
      Description copied from interface: DHState
      Performs a Diffie-Hellman calculation with this object as the private key.
      Specified by:
      calculate in interface DHState
      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.
    • copyFrom

      public void copyFrom(DHState other)
      Description copied from interface: DHState
      Copies the key values from another DH object of the same type.
      Specified by:
      copyFrom in interface DHState
      Parameters:
      other - The other DH object to copy from
    • clone

      I2P
      Specified by:
      clone in interface DHState
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
      Since:
      0.9.44