public class ChaChaPolyCipherState extends Object implements CipherState
Modifier | Constructor and Description |
---|---|
|
ChaChaPolyCipherState()
Constructs a new cipher state for the "ChaChaPoly" algorithm.
|
protected |
ChaChaPolyCipherState(ChaChaPolyCipherState o)
Copy constructor for cloning
|
Modifier and Type | Method and Description |
---|---|
ChaChaPolyCipherState |
clone()
I2P
|
int |
decryptWithAd(byte[] ad,
byte[] ciphertext,
int ciphertextOffset,
byte[] plaintext,
int plaintextOffset,
int length)
Decrypts a ciphertext buffer using the cipher and a block of associated data.
|
int |
decryptWithAd(byte[] ad,
int adOffset,
int adLength,
byte[] ciphertext,
int ciphertextOffset,
byte[] plaintext,
int plaintextOffset,
int length)
I2P
|
void |
destroy()
Destroys all sensitive state in the current object.
|
int |
encryptWithAd(byte[] ad,
byte[] plaintext,
int plaintextOffset,
byte[] ciphertext,
int ciphertextOffset,
int length)
Encrypts a plaintext buffer using the cipher and a block of associated data.
|
int |
encryptWithAd(byte[] ad,
int adOffset,
int adLength,
byte[] plaintext,
int plaintextOffset,
byte[] ciphertext,
int ciphertextOffset,
int length)
I2P
|
CipherState |
fork(byte[] key,
int offset)
Creates a new instance of this cipher and initializes it with a key.
|
String |
getCipherName()
Gets the Noise protocol name for this cipher.
|
int |
getKeyLength()
Gets the length of the key values for this cipher.
|
int |
getMACLength()
Gets the length of the MAC values for this cipher.
|
boolean |
hasKey()
Determine if this cipher object has been configured with a key.
|
void |
initializeKey(byte[] key,
int offset)
Initializes the key on this cipher object.
|
void |
setNonce(long nonce)
Sets the nonce value.
|
String |
toString()
I2P debug
|
public ChaChaPolyCipherState()
protected ChaChaPolyCipherState(ChaChaPolyCipherState o) throws CloneNotSupportedException
CloneNotSupportedException
public void destroy()
Destroyable
destroy
in interface Destroyable
public String getCipherName()
CipherState
getCipherName
in interface CipherState
public int getKeyLength()
CipherState
getKeyLength
in interface CipherState
public int getMACLength()
CipherState
getMACLength
in interface CipherState
public void initializeKey(byte[] key, int offset)
CipherState
initializeKey
in interface CipherState
key
- Points to a buffer that contains the key.offset
- The offset of the key in the key buffer.
The key buffer must contain at least getKeyLength() bytes
starting at offset.CipherState.hasKey()
public boolean hasKey()
CipherState
hasKey
in interface CipherState
CipherState.initializeKey(byte[], int)
public int encryptWithAd(byte[] ad, byte[] plaintext, int plaintextOffset, byte[] ciphertext, int ciphertextOffset, int length) throws ShortBufferException
CipherState
encryptWithAd
in interface CipherState
ad
- The associated data, or null if there is none.plaintext
- 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
- The ciphertext buffer does not have
enough space to hold the ciphertext plus MAC.public int encryptWithAd(byte[] ad, int adOffset, int adLength, byte[] plaintext, int plaintextOffset, byte[] ciphertext, int ciphertextOffset, int length) throws ShortBufferException
encryptWithAd
in interface CipherState
ShortBufferException
public int decryptWithAd(byte[] ad, byte[] ciphertext, int ciphertextOffset, byte[] plaintext, int plaintextOffset, int length) throws ShortBufferException, BadPaddingException
CipherState
decryptWithAd
in interface CipherState
ad
- The associated data, or null if there is none.ciphertext
- 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
- The plaintext buffer does not have
enough space to store the decrypted data.BadPaddingException
- The MAC value failed to verify.public int decryptWithAd(byte[] ad, int adOffset, int adLength, byte[] ciphertext, int ciphertextOffset, byte[] plaintext, int plaintextOffset, int length) throws ShortBufferException, BadPaddingException
decryptWithAd
in interface CipherState
ShortBufferException
BadPaddingException
public CipherState fork(byte[] key, int offset)
CipherState
fork
in interface CipherState
key
- The buffer containing the key.offset
- The offset into the key buffer of the first key byte.public void setNonce(long nonce)
CipherState
setNonce
in interface CipherState
nonce
- The new nonce value, which must be greater than or equal
to the current value.
This function is intended for testing purposes only. If the nonce
value goes backwards then security may be compromised.public ChaChaPolyCipherState clone() throws CloneNotSupportedException
clone
in interface CipherState
clone
in class Object
CloneNotSupportedException