class SymmetricState extends Object implements Destroyable, Cloneable
| Modifier | Constructor and Description |
|---|---|
| SymmetricState(NoiseInit.PatternID patternId)Constructs a new symmetric state object. |
protected | SymmetricState(SymmetricState o)Copy constructor for cloning |
| Modifier and Type | Method and Description |
|---|---|
SymmetricState | clone()I2P |
int | decryptAndHash(byte[] ciphertext,
int ciphertextOffset,
byte[] plaintext,
int plaintextOffset,
int length)Decrypts a block of ciphertext and mixes it into the handshake hash. |
int | decryptOnly(byte[] ciphertext,
int ciphertextOffset,
byte[] plaintext,
int plaintextOffset,
int length)I2P - Same as decryptAndHash() but without the post-mixHash(), for N only. |
void | destroy()Destroys all sensitive state in the current object. |
int | encryptAndHash(byte[] plaintext,
int plaintextOffset,
byte[] ciphertext,
int ciphertextOffset,
int length)Encrypts a block of plaintext and mixes the ciphertext into the handshake hash. |
int | encryptOnly(byte[] plaintext,
int plaintextOffset,
byte[] ciphertext,
int ciphertextOffset,
int length)I2P - Same as encryptAndHash() but without the post-mixHash(), for N only. |
byte[] | getChainingKey()I2P for getting chaining key for siphash calculation |
byte[] | getHandshakeHash()Gets the current value of the handshake hash. |
int | getMACLength()Gets the length of MAC values in the current state. |
String | getProtocolName()Gets the name of the Noise protocol. |
void | mixHash(byte[] data,
int offset,
int length)Mixes data into the handshake hash. |
void | mixKey(byte[] data,
int offset,
int length)Mixes data into the chaining key. |
void | mixPreSharedKey(byte[] key)Mixes a pre-shared key into the chaining key and handshake hash. |
void | mixPublicKey(DHState dh)Mixes a pre-supplied public key into the handshake hash. |
void | mixPublicKeyIntoCK(DHState dh)Mixes a pre-supplied public key into the chaining key. |
CipherStatePair | split()Splits the symmetric state into two ciphers for session encryption. |
CipherStatePair | split(byte[] secondaryKey,
int offset,
int length)Splits the symmetric state into two ciphers for session encryption,
and optionally mixes in a secondary symmetric key. |
String | toString()I2P debug |
public SymmetricState(NoiseInit.PatternID patternId) throws NoSuchAlgorithmException
NoSuchAlgorithmException - The cipher or hash algorithm in the
protocol name is not supported.protected SymmetricState(SymmetricState o) throws CloneNotSupportedException
CloneNotSupportedExceptionpublic SymmetricState clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionpublic int decryptAndHash(byte[] ciphertext,
int ciphertextOffset,
byte[] plaintext,
int plaintextOffset,
int length)
throws ShortBufferException,
BadPaddingExceptionciphertext - The buffer containing the ciphertext to decrypt.ciphertextOffset - The offset within the ciphertext buffer of
the first byte of ciphertext data.plaintext - The buffer to place the plaintext in. This can be
the same as the ciphertext buffer.plaintextOffset - The first offset within the plaintext buffer
to place the plaintext.length - The length of the incoming ciphertext plus the MAC tag.ShortBufferException - There is not enough space in the plaintext
buffer for the decrypted data.BadPaddingException - The MAC value failed to verify.
The plaintext and ciphertext buffers can be the same for in-place
decryption. In that case, ciphertextOffset must be identical to
plaintextOffset.public int decryptOnly(byte[] ciphertext,
int ciphertextOffset,
byte[] plaintext,
int plaintextOffset,
int length)
throws ShortBufferException,
BadPaddingExceptionpublic void destroy()
Destroyabledestroy in interface Destroyablepublic int encryptAndHash(byte[] plaintext,
int plaintextOffset,
byte[] ciphertext,
int ciphertextOffset,
int length)
throws ShortBufferExceptionplaintext - The buffer containing the plaintext to encrypt.plaintextOffset - The offset within the plaintext buffer of the
first byte or plaintext data.ciphertext - The buffer to place the ciphertext in. This can
be the same as the plaintext buffer.ciphertextOffset - The first offset within the ciphertext buffer
to place the ciphertext and the MAC tag.length - The length of the plaintext.ShortBufferException - There is not enough space in the
ciphertext buffer for the encrypted data plus MAC value.
The plaintext and ciphertext buffers can be the same for in-place
encryption. In that case, plaintextOffset must be identical to
ciphertextOffset.
There must be enough space in the ciphertext buffer to accomodate
length + getMACLength() bytes of data starting at ciphertextOffset.public int encryptOnly(byte[] plaintext,
int plaintextOffset,
byte[] ciphertext,
int ciphertextOffset,
int length)
throws ShortBufferExceptionShortBufferExceptionpublic byte[] getChainingKey()
public byte[] getHandshakeHash()
public int getMACLength()
public String getProtocolName()
public void mixHash(byte[] data,
int offset,
int length)data - The buffer containing the data to mix in.offset - The offset of the first data byte to mix in.length - The number of bytes to mix in.public void mixKey(byte[] data,
int offset,
int length)data - The buffer containing the data to mix in.offset - The offset of the first data byte to mix in.length - The number of bytes to mix in.public void mixPreSharedKey(byte[] key)
key - The pre-shared key value.public void mixPublicKey(DHState dh)
dh - The object containing the public key.public void mixPublicKeyIntoCK(DHState dh)
dh - The object containing the public key.public CipherStatePair split()
public CipherStatePair split(byte[] secondaryKey, int offset, int length)
secondaryKey - The buffer containing the secondary key.offset - The offset of the first secondary key byte.length - The length of the secondary key in bytes, which
must be either 0 or 32.IllegalArgumentException - The length is not 0 or 32.