Top Description Methods
org.bouncycastle.crypto.modes

public Interface AEADCipher

Known Direct Subinterfaces
org.bouncycastle.crypto.modes.AEADBlockCipher
Known Direct Implementers
org.bouncycastle.crypto.modes.ChaCha20Poly1305, org.bouncycastle.crypto.engines.AsconEngine, org.bouncycastle.crypto.engines.Grain128AEADEngine, org.bouncycastle.crypto.engines.ISAPEngine, org.bouncycastle.crypto.engines.PhotonBeetleEngine, org.bouncycastle.crypto.engines.SparkleEngine, org.bouncycastle.crypto.engines.XoodyakEngine, org.bouncycastle.crypto.engines.ElephantEngine
Imports
org.bouncycastle.crypto.CipherParameters, .DataLengthException, .InvalidCipherTextException

A cipher mode that includes authenticated encryption with a streaming mode and optional associated data.

Implementations of this interface may operate in a packet mode (where all input data is buffered and processed during the call to doFinal(byte[], int)), or in a streaming mode (where output data is incrementally produced with each call to processByte(byte, byte[], int) or processBytes(byte[], int, int, byte[], int).

This is important to consider during decryption: in a streaming mode, unauthenticated plaintext data may be output prior to the call to doFinal(byte[], int) that results in an authentication failure. The higher level protocol utilising this cipher must ensure the plaintext data is handled appropriately until the end of data is reached and the entire ciphertext is authenticated.
See Also
org.bouncycastle.crypto.params.AEADParameters

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

number of bytes written into out.
doFinal
(byte[]
space for any resulting output data.
out
,
int
offset into out to start copying the data at.
outOff
)

Finish the operation either appending or verifying the MAC at the end of the data.

public String

Returns:

the algorithm name.
getAlgorithmName
()

Return the name of the algorithm.

public byte[]

Returns:

MAC for plaintext data.
getMac
()

Return the value of the MAC associated with the last stream processed.

public int

Returns:

the space required to accommodate a call to processBytes and doFinal with len bytes of input.
getOutputSize
(int
the length of the input.
len
)

return the size of the output buffer required for a processBytes plus a doFinal with an input of len bytes.

public int

Returns:

the space required to accommodate a call to processBytes with len bytes of input.
getUpdateOutputSize
(int
the length of the input.
len
)

return the size of the output buffer required for a processBytes an input of len bytes.

public void
init(boolean
true if we are setting up for encryption, false otherwise.
forEncryption
,
CipherParameters
the necessary parameters for the underlying cipher to be initialised.
params
)

initialise the underlying cipher.

public void
processAADByte(byte
the byte to be processed.
in
)

Add a single byte to the associated data check.

public void
processAADBytes(byte[]
the input byte array.
in
,
int
the offset into the in array where the data to be processed starts.
inOff
,
int
the number of bytes to be processed.
len
)

Add a sequence of bytes to the associated data check.

public int

Returns:

the number of bytes written to out.
processByte
(byte
the byte to be processed.
in
,
byte[]
the output buffer the processed byte goes into.
out
,
int
the offset into the output byte array the processed data starts at.
outOff
)

encrypt/decrypt a single byte.

public int

Returns:

the number of bytes written to out.
processBytes
(byte[]
the input byte array.
in
,
int
the offset into the in array where the data to be processed starts.
inOff
,
int
the number of bytes to be processed.
len
,
byte[]
the output buffer the processed bytes go into.
out
,
int
the offset into the output byte array the processed data starts at.
outOff
)

process a block of bytes from in putting the result into out.

public void
reset()

Reset the cipher.

Method Detail

doFinalback to summary
public int doFinal(byte[] out, int outOff) throws IllegalStateException, InvalidCipherTextException

Finish the operation either appending or verifying the MAC at the end of the data.

Parameters
out:byte[]

space for any resulting output data.

outOff:int

offset into out to start copying the data at.

Returns:int

number of bytes written into out.

Exceptions
IllegalStateException:
if the cipher is in an inappropriate state.
InvalidCipherTextException:
if the MAC fails to match.
getAlgorithmNameback to summary
public String getAlgorithmName()

Return the name of the algorithm.

Returns:String

the algorithm name.

getMacback to summary
public byte[] getMac()

Return the value of the MAC associated with the last stream processed.

Returns:byte[]

MAC for plaintext data.

getOutputSizeback to summary
public int getOutputSize(int len)

return the size of the output buffer required for a processBytes plus a doFinal with an input of len bytes.

The returned size may be dependent on the initialisation of this cipher and may not be accurate once subsequent input data is processed - this method should be invoked immediately prior to a call to final processing of input data and a call to doFinal(byte[], int).

Parameters
len:int

the length of the input.

Returns:int

the space required to accommodate a call to processBytes and doFinal with len bytes of input.

getUpdateOutputSizeback to summary
public int getUpdateOutputSize(int len)

return the size of the output buffer required for a processBytes an input of len bytes.

The returned size may be dependent on the initialisation of this cipher and may not be accurate once subsequent input data is processed - this method should be invoked immediately prior to input data being processed.

Parameters
len:int

the length of the input.

Returns:int

the space required to accommodate a call to processBytes with len bytes of input.

initback to summary
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException

initialise the underlying cipher. Parameter can either be an AEADParameters or a ParametersWithIV object.

Parameters
forEncryption:boolean

true if we are setting up for encryption, false otherwise.

params:CipherParameters

the necessary parameters for the underlying cipher to be initialised.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
processAADByteback to summary
public void processAADByte(byte in)

Add a single byte to the associated data check.
If the implementation supports it, this will be an online operation and will not retain the associated data.

Parameters
in:byte

the byte to be processed.

processAADBytesback to summary
public void processAADBytes(byte[] in, int inOff, int len)

Add a sequence of bytes to the associated data check.
If the implementation supports it, this will be an online operation and will not retain the associated data.

Parameters
in:byte[]

the input byte array.

inOff:int

the offset into the in array where the data to be processed starts.

len:int

the number of bytes to be processed.

processByteback to summary
public int processByte(byte in, byte[] out, int outOff) throws DataLengthException

encrypt/decrypt a single byte.

Parameters
in:byte

the byte to be processed.

out:byte[]

the output buffer the processed byte goes into.

outOff:int

the offset into the output byte array the processed data starts at.

Returns:int

the number of bytes written to out.

Exceptions
DataLengthException:
if the output buffer is too small.
processBytesback to summary
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException

process a block of bytes from in putting the result into out.

Parameters
in:byte[]

the input byte array.

inOff:int

the offset into the in array where the data to be processed starts.

len:int

the number of bytes to be processed.

out:byte[]

the output buffer the processed bytes go into.

outOff:int

the offset into the output byte array the processed data starts at.

Returns:int

the number of bytes written to out.

Exceptions
DataLengthException:
if the output buffer is too small.
resetback to summary
public void reset()

Reset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one).