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

class MLKEMDHStateextends Object implements DHState, Cloneable
Implementation of the MLKEM algorithm for the Noise protocol.
  • Field Details

    • type

      private final EncType type
      The KEM variant in use.
    • publicKey

      private final byte[] publicKey
      The public key for the current mode.
    • privateKey

      private final byte[] privateKey
      The private key for the current mode.
    • mode

      private int mode
      Whether this side holds a key pair or not.
    • _hdh

      private final KeyFactory _hdh
      The HDHG factory that mixes the shared secret.
  • Constructor Details

    • MLKEMDHState

      public MLKEMDHState(boolean isAlice, NoiseInit.PatternID 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
      patternId - the handshake pattern selecting the ML-KEM parameter set
    • MLKEMDHState

      public MLKEMDHState(KeyFactory hdh, NoiseInit.PatternID patternId)
      Alice local side
      Parameters:
      hdh - the key factory used to generate and load this side's key pair
      patternId - the handshake pattern selecting the ML-KEM parameter set
    • MLKEMDHState

      private MLKEMDHState(boolean isAlice, KeyFactory hdh, NoiseInit.PatternID patternId)
      Selects the ML-KEM parameter set from the handshake pattern and allocates the key buffers.
      Parameters:
      isAlice - true for the initiator
      hdh - the key factory to clone
      patternId - the handshake pattern selecting the set
  • 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()
      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.
    • generateKeyPair

      public void generateKeyPair()
      Alice local side ONLY
      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.
    • 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()
      Description copied from interface: DHState
      Determine if this object contains an optional encoded public key.
      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.
    • 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
    • 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

      Description copied from interface: DHState
      I2P
      Specified by:
      clone in interface DHState
      Overrides:
      clone in class Object
      Returns:
      a copy of this DH state holding the same key material
      Throws:
      CloneNotSupportedException - if this DH state does not implement Cloneable