Top Description Fields Constructors Methods
org.bouncycastle.crypto.internal.modes

public Class EAXBlockCipher

extends Object
implements AEADBlockCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.internal.modes.AEADBlockCipher
Imports
org.bouncycastle.crypto.internal.BlockCipher, .CipherParameters, .DataLengthException, .InvalidCipherTextException, .Mac, .OutputLengthException, org.bouncycastle.crypto.internal.macs.CMac, org.bouncycastle.crypto.internal.params.AEADParameters, .ParametersWithIV, org.bouncycastle.util.Arrays

A Two-Pass Authenticated-Encryption Scheme Optimized for Simplicity and Efficiency - by M. Bellare, P. Rogaway, D. Wagner. http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf EAX is an AEAD scheme based on CTR and OMAC1/CMAC, that uses a single block cipher to encrypt and authenticate data. It's on-line (the length of a message isn't needed to begin processing it), has good performances, it's simple and provably secure (provided the underlying block cipher is secure). Of course, this implementations is NOT thread-safe.

Field Summary

Modifier and TypeField and Description
private byte[]
private int
private byte[]
private int
private SICBlockCipher
private boolean
private static final byte
private boolean
private static final byte
private byte[]
private Mac
private byte[]
private int
private byte[]
private static final byte

Constructor Summary

AccessConstructor and Description
public
EAXBlockCipher(BlockCipher
the engine to use
cipher
)

Constructor that accepts an instance of a block cipher engine.

Method Summary

Modifier and TypeMethod and Description
private void
public int
doFinal(byte[]
space for any resulting output data.
out
,
int
offset into out to start copying the data at.
outOff
)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.doFinal.

Finish the operation either appending or verifying the MAC at the end of the data.
public String
public int
public byte[]
getMac()

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getMac.

Return the value of the MAC associated with the last stream processed.
public int
getOutputSize(int
the length of the input.
len
)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getOutputSize.

return the size of the output buffer required for a processBytes plus a doFinal with an input of len bytes.
public BlockCipher
public int
getUpdateOutputSize(int
the length of the input.
len
)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getUpdateOutputSize.

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
)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.init.

initialize the underlying cipher.
private void
private int
process(byte b, byte[] out, int outOff)

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

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processAADByte.

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
)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processAADBytes.

Add a sequence of bytes to the associated data check.
public int
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
)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processByte.

encrypt/decrypt a single byte.
public int
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
)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processBytes.

process a block of bytes from in putting the result into out.
public void
private void
reset(boolean clearMac)

private boolean
verifyMac(byte[] mac, int off)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

associatedTextMacback to summary
private byte[] associatedTextMac
blockSizeback to summary
private int blockSize
bufBlockback to summary
private byte[] bufBlock
bufOffback to summary
private int bufOff
cipherback to summary
private SICBlockCipher cipher
cipherInitializedback to summary
private boolean cipherInitialized
cTAGback to summary
private static final byte cTAG
forEncryptionback to summary
private boolean forEncryption
hTAGback to summary
private static final byte hTAG
initialAssociatedTextback to summary
private byte[] initialAssociatedText
macback to summary
private Mac mac
macBlockback to summary
private byte[] macBlock
macSizeback to summary
private int macSize
nonceMacback to summary
private byte[] nonceMac
nTAGback to summary
private static final byte nTAG

Constructor Detail

EAXBlockCipherback to summary
public EAXBlockCipher(BlockCipher cipher)

Constructor that accepts an instance of a block cipher engine.

Parameters
cipher:BlockCipher

the engine to use

Method Detail

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

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.doFinal.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.doFinal.

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.
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getAlgorithmName.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getAlgorithmName.

Return the name of the algorithm.

Returns:String

the algorithm name.

getBlockSizeback to summary
public int getBlockSize()
getMacback to summary
public byte[] getMac()

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getMac.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.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)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getOutputSize.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getOutputSize.

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.

getUnderlyingCipherback to summary
public BlockCipher getUnderlyingCipher()

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getUnderlyingCipher.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getUnderlyingCipher.

return the cipher this object wraps.

Returns:BlockCipher

the cipher this object wraps.

getUpdateOutputSizeback to summary
public int getUpdateOutputSize(int len)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getUpdateOutputSize.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.getUpdateOutputSize.

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

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.init.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.init.

initialize 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.
initCipherback to summary
private void initCipher()
processback to summary
private int process(byte b, byte[] out, int outOff)
processAADByteback to summary
public void processAADByte(byte in)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processAADByte.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processAADByte.

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)

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processAADBytes.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processAADBytes.

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

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processByte.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processByte.

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

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processBytes.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.processBytes.

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()

Implements org.bouncycastle.crypto.internal.modes.AEADBlockCipher.reset.

Doc from org.bouncycastle.crypto.internal.modes.AEADBlockCipher.reset.

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

resetback to summary
private void reset(boolean clearMac)
verifyMacback to summary
private boolean verifyMac(byte[] mac, int off)