public class JceChaCha20Poly1305 extends java.lang.Object implements TlsAEADCipherImpl
Modifier and Type | Field and Description |
---|---|
protected javax.crypto.Cipher |
cipher |
protected javax.crypto.SecretKey |
cipherKey |
protected int |
cipherMode |
protected JcaTlsCrypto |
crypto |
protected javax.crypto.Mac |
mac |
Constructor and Description |
---|
JceChaCha20Poly1305(JcaTlsCrypto crypto,
org.bouncycastle.jcajce.util.JcaJceHelper helper,
boolean isEncrypting) |
Modifier and Type | Method and Description |
---|---|
int |
doFinal(byte[] additionalData,
byte[] input,
int inputOffset,
int inputLength,
byte[] output,
int outputOffset)
Perform the cipher encryption/decryption returning the output in output.
|
int |
getOutputSize(int inputLength)
Return the maximum size of the output for input of inputLength bytes.
|
void |
init(byte[] nonce,
int macSize)
Initialise the parameters for the AEAD operator.
|
protected void |
initMAC(byte[] firstBlock) |
protected void |
runCipher(byte[] buf) |
void |
setKey(byte[] key,
int keyOff,
int keyLen)
Set the key to be used by the AEAD cipher implementation supporting this service.
|
protected void |
updateMAC(byte[] buf,
int off,
int len) |
protected final JcaTlsCrypto crypto
protected final javax.crypto.Cipher cipher
protected final javax.crypto.Mac mac
protected final int cipherMode
protected javax.crypto.SecretKey cipherKey
public JceChaCha20Poly1305(JcaTlsCrypto crypto, org.bouncycastle.jcajce.util.JcaJceHelper helper, boolean isEncrypting) throws java.security.GeneralSecurityException
java.security.GeneralSecurityException
public int doFinal(byte[] additionalData, byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) throws java.io.IOException
TlsAEADCipherImpl
Note: we have to use doFinal() here as it is the only way to guarantee output from the underlying cipher.
doFinal
in interface TlsAEADCipherImpl
additionalData
- any additional data to be included in the MAC calculation.input
- array holding input data to the cipher.inputOffset
- offset into input array data starts at.inputLength
- length of the input data in the array.output
- array to hold the cipher output.outputOffset
- offset into output array to start saving output.java.io.IOException
- in case of failure.public int getOutputSize(int inputLength)
TlsAEADCipherImpl
getOutputSize
in interface TlsAEADCipherImpl
inputLength
- the length (in bytes) of the proposed input.public void init(byte[] nonce, int macSize) throws java.io.IOException
TlsAEADCipherImpl
init
in interface TlsAEADCipherImpl
nonce
- the nonce.macSize
- MAC size in bytes.java.io.IOException
- if the parameters are inappropriate.public void setKey(byte[] key, int keyOff, int keyLen) throws java.io.IOException
TlsAEADCipherImpl
setKey
in interface TlsAEADCipherImpl
key
- array holding the AEAD cipher key.keyOff
- offset into the array the key starts at.keyLen
- length of the key in the array.java.io.IOException
protected void initMAC(byte[] firstBlock) throws java.security.InvalidKeyException
java.security.InvalidKeyException
protected void runCipher(byte[] buf) throws java.security.GeneralSecurityException
java.security.GeneralSecurityException
protected void updateMAC(byte[] buf, int off, int len)