Top Description Inners Fields Constructors Methods
org.bouncycastle.crypto.engines

public Class Grain128AEADEngine

extends AEADBaseEngine
Class Inheritance
Imports
java.io.ByteArrayOutputStream, org.bouncycastle.crypto.DataLengthException, .InvalidCipherTextException, .OutputLengthException, org.bouncycastle.util.Pack

Grain-128 AEAD, based on the current round 3 submission, https://grain-128aead.github.io/

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final Grain128AEADEngine.ErasableOutputStream
private boolean
private int[]
private int[]
private boolean
private int[]
private int[]
private static final int
STATE_SIZE

Constants

private byte[]
private byte[]
workingKey

Variables to hold the state of the engine during encryption and decryption

Inherited from org.bouncycastle.crypto.engines.AEADBaseEngine:
algorithmNameforEncryptioninitialAssociatedTextIV_SIZEKEY_SIZEmacMAC_SIZE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private void
authShift(int val)

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.modes.AEADCipher.doFinal.

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

private void
doProcessAADBytes(byte[] input, int len)

private void
getKeyStream(byte[] input, int inOff, int len, byte[] ciphertext, int outOff)

private int

Returns:

y_t.
getOutput
()

Get output from output function h(x).

private int

Returns:

Output from LFSR.
getOutputLFSR
()

Get output from linear function f(x).

private int

Returns:

Output from NFSR.
getOutputNFSR
()

Get output from non-linear function g(x).

public int
getOutputSize(int
the length of the input.
len
)

Implements org.bouncycastle.crypto.modes.AEADCipher.getOutputSize.

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

public int
getUpdateOutputSize(int
the length of the input.
len
)

Implements org.bouncycastle.crypto.modes.AEADCipher.getUpdateOutputSize.

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

protected void
init(byte[] key, byte[] iv)

Implements abstract org.bouncycastle.crypto.engines.AEADBaseEngine.init.

Initialize a Grain-128AEAD cipher.

private void
initGrain()

320 clocks initialization phase.

private void
initGrain(int[] auth)

private static int
len_length(int v)

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

Implements org.bouncycastle.crypto.modes.AEADCipher.processAADByte.

Add a single byte to the associated data check.

public void
processAADBytes(byte[]
the input byte array.
input
,
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.modes.AEADCipher.processAADBytes.

Add a sequence of bytes to the associated data check.

public int
processBytes(byte[]
the input byte array.
input
,
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.
output
,
int
the offset into the output byte array the processed data starts at.
outOff
)

Implements org.bouncycastle.crypto.modes.AEADCipher.processBytes.

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

protected void
private void
setKey(byte[]
The key.
keyBytes
,
byte[]
The IV.
ivBytes
)

Set keys, reset cipher.

private int[]

Returns:

The shifted array with val added to index.length - 1.
shift
(int[]
The array to shift.
array
,
int
The value to shift in.
val
)

Shift array 1 bit and add val to index.length - 1.

private void
updateInternalState(int input_i_j)

Inherited from org.bouncycastle.crypto.engines.AEADBaseEngine:
getAlgorithmNamegetIVBytesSizegetKeyBytesSizegetMacinitprocessBytereset

Field Detail

aadDataback to summary
private final Grain128AEADEngine.ErasableOutputStream aadData
aadFinishedback to summary
private boolean aadFinished
authAccback to summary
private int[] authAcc
authSrback to summary
private int[] authSr
initialisedback to summary
private boolean initialised
lfsrback to summary
private int[] lfsr
nfsrback to summary
private int[] nfsr
STATE_SIZEback to summary
private static final int STATE_SIZE

Constants

workingIVback to summary
private byte[] workingIV
workingKeyback to summary
private byte[] workingKey

Variables to hold the state of the engine during encryption and decryption

Constructor Detail

Grain128AEADEngineback to summary
public Grain128AEADEngine()

Method Detail

accumulateback to summary
private void accumulate()
authShiftback to summary
private void authShift(int val)
doFinalback to summary
public int doFinal(byte[] out, int outOff) throws IllegalStateException, InvalidCipherTextException

Implements org.bouncycastle.crypto.modes.AEADCipher.doFinal.

Doc from org.bouncycastle.crypto.modes.AEADCipher.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.
InvalidCipherTextException:
if the MAC fails to match.
doProcessAADBytesback to summary
private void doProcessAADBytes(byte[] input, int len)
getKeyStreamback to summary
private void getKeyStream(byte[] input, int inOff, int len, byte[] ciphertext, int outOff)
getOutputback to summary
private int getOutput()

Get output from output function h(x).

Returns:int

y_t.

getOutputLFSRback to summary
private int getOutputLFSR()

Get output from linear function f(x).

Returns:int

Output from LFSR.

getOutputNFSRback to summary
private int getOutputNFSR()

Get output from non-linear function g(x).

Returns:int

Output from NFSR.

getOutputSizeback to summary
public int getOutputSize(int len)

Implements org.bouncycastle.crypto.modes.AEADCipher.getOutputSize.

Doc from org.bouncycastle.crypto.modes.AEADCipher.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.

getUpdateOutputSizeback to summary
public int getUpdateOutputSize(int len)

Implements org.bouncycastle.crypto.modes.AEADCipher.getUpdateOutputSize.

Doc from org.bouncycastle.crypto.modes.AEADCipher.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
protected void init(byte[] key, byte[] iv) throws IllegalArgumentException

Implements abstract org.bouncycastle.crypto.engines.AEADBaseEngine.init.

Initialize a Grain-128AEAD cipher.

Exceptions
IllegalArgumentException:
If the params argument is inappropriate.
initGrainback to summary
private void initGrain()

320 clocks initialization phase.

initGrainback to summary
private void initGrain(int[] auth)
len_lengthback to summary
private static int len_length(int v)
processAADByteback to summary
public void processAADByte(byte in)

Implements org.bouncycastle.crypto.modes.AEADCipher.processAADByte.

Doc from org.bouncycastle.crypto.modes.AEADCipher.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[] input, int inOff, int len)

Implements org.bouncycastle.crypto.modes.AEADCipher.processAADBytes.

Doc from org.bouncycastle.crypto.modes.AEADCipher.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
input: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.

processBytesback to summary
public int processBytes(byte[] input, int inOff, int len, byte[] output, int outOff) throws DataLengthException

Implements org.bouncycastle.crypto.modes.AEADCipher.processBytes.

Doc from org.bouncycastle.crypto.modes.AEADCipher.processBytes.

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

Parameters
input: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.

output: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
protected void reset(boolean clearMac)

Overrides org.bouncycastle.crypto.engines.AEADBaseEngine.reset.

setKeyback to summary
private void setKey(byte[] keyBytes, byte[] ivBytes)

Set keys, reset cipher.

Parameters
keyBytes:byte[]

The key.

ivBytes:byte[]

The IV.

shiftback to summary
private int[] shift(int[] array, int val)

Shift array 1 bit and add val to index.length - 1.

Parameters
array:int[]

The array to shift.

val:int

The value to shift in.

Returns:int[]

The shifted array with val added to index.length - 1.

updateInternalStateback to summary
private void updateInternalState(int input_i_j)
org.bouncycastle.crypto.engines back to summary

private final Class Grain128AEADEngine.ErasableOutputStream

extends ByteArrayOutputStream
Class Inheritance

Field Summary

Inherited from java.io.ByteArrayOutputStream:
bufcount

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public byte[]
Inherited from java.io.ByteArrayOutputStream:
closeresetsizetoByteArraytoStringtoStringtoStringtoStringwritewritewriteByteswriteTo

Constructor Detail

ErasableOutputStreamback to summary
public ErasableOutputStream()

Method Detail

getBufback to summary
public byte[] getBuf()