com.southernstorm.noise.protocol

## Interface DHState

- All Superinterfaces:
    Cloneable, Destroyable
  All Known Implementing Classes:
    Curve25519DHState, MLKEMDHState

      public interface DHState
      extends Destroyable, Cloneable

  Interface to a Diffie-Hellman algorithm for the Noise protocol.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `calculate(byte[] sharedKey, int offset, DHState publicDH)` Performs a Diffie-Hellman calculation with this object as the private key.
    `void` | `clearKey()` Clears the key pair.
    `DHState` | `clone()` I2P
    `void` | `copyFrom(DHState other)` Copies the key values from another DH object of the same type.
    `void` | `generateKeyPair()` Generates a new random keypair.
    `String` | `getDHName()` Gets the Noise protocol name for this Diffie-Hellman algorithm.
    `void` | `getEncodedPublicKey(byte[] key, int offset)` Gets the public key associated with this object.
    `void` | `getPrivateKey(byte[] key, int offset)` Gets the private key associated with this object.
    `int` | `getPrivateKeyLength()` Gets the length of private keys for this algorithm.
    `void` | `getPublicKey(byte[] key, int offset)` Gets the public key associated with this object.
    `int` | `getPublicKeyLength()` Gets the length of public keys for this algorithm.
    `int` | `getSharedKeyLength()` Gets the length of shared keys for this algorithm.
    `boolean` | `hasEncodedPublicKey()` Determine if this object contains an optional encoded public key.
    `boolean` | `hasPrivateKey()` Determine if this object contains a private key.
    `boolean` | `hasPublicKey()` Determine if this object contains a public key.
    `boolean` | `isNullPublicKey()` 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` | `setPublicKey(byte[] key, int offset)` Sets the public key for this object.
    `void` | `setToNullPublicKey()` Sets this object to the null public key and clears the private key.

    - ### Methods inherited from interface com.southernstorm.noise.protocol.Destroyable

      `destroy`

- - ### Method Detail

    - #### calculate

          void calculate(byte[] sharedKey,
                         int offset,
                         DHState publicDH)

      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.

    - #### clearKey

          void clearKey()

      Clears the key pair.

    - #### clone

          DHState clone()
                 throws CloneNotSupportedException

      I2P
      Throws:
        `CloneNotSupportedException`

    - #### copyFrom

          void copyFrom(DHState other)

      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.

    - #### generateKeyPair

          void generateKeyPair()

      Generates a new random keypair.

    - #### getDHName

          String getDHName()

      Gets the Noise protocol name for this Diffie-Hellman algorithm.
      Returns:
        The algorithm name.

    - #### getEncodedPublicKey

          void getEncodedPublicKey(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.

    - #### 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.

    - #### getPrivateKeyLength

          int getPrivateKeyLength()

      Gets the length of private keys for this algorithm.
      Returns:
        The length of private keys in bytes.

    - #### 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.

    - #### getPublicKeyLength

          int getPublicKeyLength()

      Gets the length of public keys for this algorithm.
      Returns:
        The length of public keys in bytes.

    - #### getSharedKeyLength

          int getSharedKeyLength()

      Gets the length of shared keys for this algorithm.
      Returns:
        The length of shared keys in bytes.

    - #### hasEncodedPublicKey

          boolean hasEncodedPublicKey()

      Determine if this object contains an optional encoded public key.
      Returns:
        Returns true if this object contains an encoded 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.

    - #### 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.

    - #### 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.

    - #### setKeys

          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.
      Parameters:
        `privkey` - The buffer containing the private key.
        `privoffset` - The first offset in the buffer that contains the key.
        `pubkey` - The buffer containing the private key.
        `puboffset` - The first offset in the buffer that contains the key.

    - #### 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.

    - #### setToNullPublicKey

          void setToNullPublicKey()

      Sets this object to the null public key and clears the private key.