com.southernstorm.noise.protocol

## Class MLKEMDHState

- java.lang.Object
- - com.southernstorm.noise.protocol.MLKEMDHState

- All Implemented Interfaces:
    Destroyable, DHState, Cloneable

      class MLKEMDHState
      extends Object
      implements DHState, Cloneable

  Implementation of the MLKEM algorithm for the Noise protocol.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MLKEMDHState(boolean isAlice, String patternId)` Bob local/remote or Alice remote side, do not call generateKeyPair()
    `MLKEMDHState(KeyFactory hdh, String patternId)` Alice local side

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `calculate(byte[] sharedKey, int offset, DHState publicDH)` Side effect: If we are Bob, copies the ciphertext to our public key so it may be written out in the message.
    `void` | `clearKey()` Clears the key pair.
    `MLKEMDHState` | `clone()` I2P
    `void` | `copyFrom(DHState other)` Copies the key values from another DH object of the same type.
    `void` | `destroy()` Destroys all sensitive state in the current object.
    `void` | `generateKeyPair()` Alice local side ONLY
    `String` | `getDHName()` Gets the Noise protocol name for this Diffie-Hellman algorithm.
    `void` | `getPublicKey(byte[] key, int offset)` Gets the public key associated with this object.
    `int` | `getPublicKeyLength()` Note: Alice/Bob sizes are different
    `int` | `getSharedKeyLength()` Gets the length of shared keys for this algorithm.
    `boolean` | `hasEncodedPublicKey()` I2P
    `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` | `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 class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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

      `getEncodedPublicKey, getPrivateKey, getPrivateKeyLength, setKeys`

- - ### Constructor Detail

    - #### MLKEMDHState

          public MLKEMDHState(boolean isAlice,
                              String patternId)

      Bob local/remote or Alice remote side, do not call generateKeyPair()
      Parameters:
        `isAlice` - true for Bob remote side, false for Bob local side and Alice remote side

    - #### MLKEMDHState

          public MLKEMDHState(KeyFactory hdh,
                              String patternId)

      Alice local side

  - ### Method Detail

    - #### calculate

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

      Side effect: If we are Bob, copies the ciphertext to our public key so it may be written out in the message.
      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.
      Throws:
        `IllegalArgumentException` - on bad public key modulus

    - #### clearKey

          public void clearKey()

      Description copied from interface: `DHState`
      Clears the key pair.
      Specified by:
        `clearKey` in interface `DHState`

    - #### clone

          public MLKEMDHState clone()
                             throws CloneNotSupportedException

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

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

    - #### destroy

          public void destroy()

      Description copied from interface: `Destroyable`
      Destroys all sensitive state in the current object.
      Specified by:
        `destroy` in interface `Destroyable`

    - #### generateKeyPair

          public void generateKeyPair()

      Alice local side ONLY
      Specified by:
        `generateKeyPair` in interface `DHState`

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

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

    - #### getPublicKeyLength

          public int getPublicKeyLength()

      Note: Alice/Bob sizes are different
      Specified by:
        `getPublicKeyLength` in interface `DHState`
      Returns:
        The length of public 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.

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

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

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

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

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

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