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.
Since:
0.9.67
  • Constructor Details

    • 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 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.
    • getPrivateKeyLength

      @Deprecated public int getPrivateKeyLength()
      Deprecated.
      Note: Alice/Bob sizes are different
      Specified by:
      getPrivateKeyLength in interface DHState
      Returns:
      0 for Bob
    • 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.
    • getPrivateKey

      @Deprecated public void getPrivateKey(byte[] key, int offset)
      Deprecated.
      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.
      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

      @Deprecated public void setKeys(byte[] privkey, int privoffset, byte[] pubkey, int puboffset)
      Deprecated.
      Description copied from interface: DHState
      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 private key.
      puboffset - The first offset in the buffer that contains the key.
    • 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.
    • getEncodedPublicKey

      @Deprecated public void getEncodedPublicKey(byte[] key, int offset)
      Deprecated.
      Description copied from interface: DHState
      Gets the public key associated with this object.
      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.
    • 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

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