java.lang.Object
com.southernstorm.noise.protocol.MLKEMDHState
- All Implemented Interfaces:
Destroyable, DHState, Cloneable
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final KeyFactoryThe HDHG factory that mixes the shared secret.private intWhether this side holds a key pair or not.private final byte[]The private key for the current mode.private final byte[]The public key for the current mode.private final EncTypeThe KEM variant in use.Constructor Summary
ModifierConstructorDescriptionMLKEMDHState(boolean isAlice, NoiseInit.PatternID patternId) Bob local/remote or Alice remote side, do not call generateKeyPair()privateMLKEMDHState(boolean isAlice, KeyFactory hdh, NoiseInit.PatternID patternId) Selects the ML-KEM parameter set from the handshake pattern and allocates the key buffers.MLKEMDHState(KeyFactory hdh, NoiseInit.PatternID patternId) Alice local sideMethod Summary
All MethodsModifier and TypeMethodDescriptionvoidSide effect: If we are Bob, copies the ciphertext to our public key so it may be written out in the message.voidclearKey()Clears the key pair.clone()I2PvoidCopies the key values from another DH object of the same type.voiddestroy()Destroys all sensitive state in the current object.voidAlice local side ONLYGets the Noise protocol name for this Diffie-Hellman algorithm.voidgetPublicKey(byte[] key, int offset) Gets the public key associated with this object.intNote: Alice/Bob sizes are differentintGets the length of shared keys for this algorithm.booleanDetermine if this object contains an optional encoded public key.booleanDetermine if this object contains a private key.booleanDetermine if this object contains a public key.booleanDetermine if the public key in this object is the special null value.voidsetPublicKey(byte[] key, int offset) Sets the public key for this object.voidSets this object to the null public key and clears the private key.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DHState
getEncodedPublicKey, getPrivateKey, getPrivateKeyLength, setKeysModifier and TypeMethodDescriptionvoidgetEncodedPublicKey(byte[] key, int offset) Gets the public key associated with this object.voidgetPrivateKey(byte[] key, int offset) Gets the private key associated with this object.intGets the length of private keys for this algorithm.voidsetKeys(byte[] privkey, int privoffset, byte[] pubkey, int puboffset) Sets the private and public keys for this object.
Field Details
type
The KEM variant in use.publicKey
private final byte[] publicKeyThe public key for the current mode.privateKey
private final byte[] privateKeyThe private key for the current mode.mode
private int modeWhether this side holds a key pair or not._hdh
The HDHG factory that mixes the shared secret.
Constructor Details
MLKEMDHState
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 sidepatternId- the handshake pattern selecting the ML-KEM parameter set
MLKEMDHState
Alice local side- Parameters:
hdh- the key factory used to generate and load this side's key pairpatternId- the handshake pattern selecting the ML-KEM parameter set
MLKEMDHState
Selects the ML-KEM parameter set from the handshake pattern and allocates the key buffers.- Parameters:
isAlice- true for the initiatorhdh- the key factory to clonepatternId- the handshake pattern selecting the set
Method Details
destroy
public void destroy()Description copied from interface:DestroyableDestroys all sensitive state in the current object.- Specified by:
destroyin interfaceDestroyable
getDHName
getPublicKeyLength
public int getPublicKeyLength()Note: Alice/Bob sizes are different- Specified by:
getPublicKeyLengthin interfaceDHState- Returns:
- The length of public keys in bytes.
generateKeyPair
getPublicKey
public void getPublicKey(byte[] key, int offset) Description copied from interface:DHStateGets the public key associated with this object.- Specified by:
getPublicKeyin interfaceDHState- 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:DHStateSets the public key for this object.- Specified by:
setPublicKeyin interfaceDHState- 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:DHStateSets this object to the null public key and clears the private key.- Specified by:
setToNullPublicKeyin interfaceDHState
clearKey
hasPublicKey
public boolean hasPublicKey()Description copied from interface:DHStateDetermine if this object contains a public key.- Specified by:
hasPublicKeyin interfaceDHState- 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:DHStateDetermine if this object contains a private key.- Specified by:
hasPrivateKeyin interfaceDHState- 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:DHStateDetermine if the public key in this object is the special null value.- Specified by:
isNullPublicKeyin interfaceDHState- Returns:
- Returns true if the public key is the special null value, or false otherwise.
hasEncodedPublicKey
public boolean hasEncodedPublicKey()Description copied from interface:DHStateDetermine if this object contains an optional encoded public key.- Specified by:
hasEncodedPublicKeyin interfaceDHState- Returns:
- Returns true if this object contains an encoded public key, or false if the public key has not yet been set.
calculate
Side effect: If we are Bob, copies the ciphertext to our public key so it may be written out in the message.- Specified by:
calculatein interfaceDHState- 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
clone