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

public Class Grain128AEADEngine

extends Object
implements AEADCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.modes.AEADCipher
Imports
java.io.ByteArrayOutputStream, org.bouncycastle.crypto.CipherParameters, .CryptoServicesRegistrar, .DataLengthException, .InvalidCipherTextException, .OutputLengthException, org.bouncycastle.crypto.constraints.DefaultServiceProperties, org.bouncycastle.crypto.modes.AEADCipher, org.bouncycastle.crypto.params.KeyParameter, .ParametersWithIV, 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 Grain128AEADEngine.ErasableOutputStream
private boolean
private int[]
private int[]
private boolean
private int[]
private byte[]
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

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 inOff, int len)

public String
getAlgorithmName()

Implements org.bouncycastle.crypto.modes.AEADCipher.getAlgorithmName.

Return the name of the algorithm.
private byte[]
getKeyStream(byte[] input, int inOff, int len, byte[] ciphertext, int outOff)

public byte[]
getMac()

Implements org.bouncycastle.crypto.modes.AEADCipher.getMac.

Return the value of the MAC associated with the last stream processed.
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.
public void
init(boolean
Whether or not we are for encryption.
forEncryption
,
CipherParameters
The parameters required to set up the cipher.
params
)

Implements org.bouncycastle.crypto.modes.AEADCipher.init.

Initialize a Grain-128AEAD cipher.
private void
initGrain()

320 clocks initialization phase.

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
processByte(byte
the byte to be processed.
input
,
byte[]
the output buffer the processed byte goes into.
output
,
int
the offset into the output byte array the processed data starts at.
outOff
)

Implements org.bouncycastle.crypto.modes.AEADCipher.processByte.

encrypt/decrypt a single byte.
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.
public void
private void
reset(boolean clearMac)

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aadDataback to summary
private 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
macback to summary
private byte[] mac
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 inOff, int len)
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.modes.AEADCipher.getAlgorithmName.

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

Return the name of the algorithm.

Returns:String

the algorithm name.

getKeyStreamback to summary
private byte[] getKeyStream(byte[] input, int inOff, int len, byte[] ciphertext, int outOff)
getMacback to summary
public byte[] getMac()

Implements org.bouncycastle.crypto.modes.AEADCipher.getMac.

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

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

Returns:byte[]

MAC for plaintext data.

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
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException

Implements org.bouncycastle.crypto.modes.AEADCipher.init.

Initialize a Grain-128AEAD cipher.

Parameters
forEncryption:boolean

Whether or not we are for encryption.

params:CipherParameters

The parameters required to set up the cipher.

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

320 clocks initialization phase.

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.

processByteback to summary
public int processByte(byte input, byte[] output, int outOff) throws DataLengthException

Implements org.bouncycastle.crypto.modes.AEADCipher.processByte.

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

encrypt/decrypt a single byte.

Parameters
input:byte

the byte to be processed.

output: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[] 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
public void reset()

Implements org.bouncycastle.crypto.modes.AEADCipher.reset.

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

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