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

public Class GCMBlockCipher

extends Object
implements GCMModeCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.modes.GCMModeCipher, org.bouncycastle.crypto.modes.AEADBlockCipher, org.bouncycastle.crypto.modes.AEADCipher
Imports
org.bouncycastle.crypto.BlockCipher, .CipherParameters, .DataLengthException, .InvalidCipherTextException, .OutputLengthException, org.bouncycastle.crypto.modes.gcm.BasicGCMExponentiator, .GCMExponentiator, .GCMMultiplier, .GCMUtil, .Tables4kGCMMultiplier, org.bouncycastle.crypto.params.AEADParameters, .KeyParameter, .ParametersWithIV, org.bouncycastle.util.Arrays, .Pack

Implements the Galois/Counter mode (GCM) detailed in NIST Special Publication 800-38D.

Field Summary

Modifier and TypeField and Description
private byte[]
private int
private long
private long
private static final int
private int
private byte[]
private int
private BlockCipher
private byte[]
private GCMExponentiator
private boolean
private byte[]
H

private byte[]
private boolean
private byte[]
private byte[]
private byte[]
private int
private GCMMultiplier
private byte[]
private byte[]
S

private byte[]
private byte[]
private long

Constructor Summary

AccessConstructor and Description
public
GCMBlockCipher(BlockCipher
the base cipher.
c
)
Deprecated use the GCMBlockCipher.newInstance() static method.

Base constructor - GCM mode over base cipher c.

public
GCMBlockCipher(BlockCipher
the base cipher.
c
,
GCMMultiplier
the GCM multiplier to use.
m
)
Deprecated use the CBCBlockCipher.newInstance() static method.

Base constructor - GCM mode over base cipher c over base multiplier m.

Method Summary

Modifier and TypeMethod and Description
private void
private void
decryptBlock(byte[] buf, int bufOff, byte[] out, int outOff)

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
encryptBlock(byte[] buf, int bufOff, byte[] out, int outOff)

public String
getAlgorithmName()

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

Return the name of the algorithm.

public byte[]
getMac()

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

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

private void
getNextCTRBlock(byte[] block)

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 BlockCipher
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.

private void
gHASH(byte[] Y, byte[] b, int len)

private void
gHASHBlock(byte[] Y, byte[] b)

private void
gHASHBlock(byte[] Y, byte[] b, int off)

private void
gHASHPartial(byte[] Y, byte[] b, int off, int len)

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

Note

MAC sizes from 32 bits to 128 bits (must be a multiple of 8) are supported.

private void
public static GCMModeCipher
newInstance(BlockCipher
the base cipher for the GCM mode.
cipher
)

Return a new GCM mode cipher based on the passed in base cipher

public static GCMModeCipher
newInstance(BlockCipher
the base cipher for the GCM mode.
cipher
,
GCMMultiplier
the GCM multiplier to use.
m
)

Return a new GCM mode cipher based on the passed in base cipher and multiplier.

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

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

private void
processPartial(byte[] buf, int off, int len, byte[] out, int outOff)

public void
private void
reset(boolean clearMac)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

atBlockback to summary
private byte[] atBlock
atBlockPosback to summary
private int atBlockPos
atLengthback to summary
private long atLength
atLengthPreback to summary
private long atLengthPre
BLOCK_SIZEback to summary
private static final int BLOCK_SIZE
blocksRemainingback to summary
private int blocksRemaining
bufBlockback to summary
private byte[] bufBlock
bufOffback to summary
private int bufOff
cipherback to summary
private BlockCipher cipher
counterback to summary
private byte[] counter
expback to summary
private GCMExponentiator exp
forEncryptionback to summary
private boolean forEncryption
Hback to summary
private byte[] H
initialAssociatedTextback to summary
private byte[] initialAssociatedText
initialisedback to summary
private boolean initialised
J0back to summary
private byte[] J0
lastKeyback to summary
private byte[] lastKey
macBlockback to summary
private byte[] macBlock
macSizeback to summary
private int macSize
multiplierback to summary
private GCMMultiplier multiplier
nonceback to summary
private byte[] nonce
Sback to summary
private byte[] S
S_atback to summary
private byte[] S_at
S_atPreback to summary
private byte[] S_atPre
totalLengthback to summary
private long totalLength

Constructor Detail

GCMBlockCipherback to summary
public GCMBlockCipher(BlockCipher c)

Deprecated

use the GCMBlockCipher.newInstance() static method.

Base constructor - GCM mode over base cipher c.

Parameters
c:BlockCipher

the base cipher.

GCMBlockCipherback to summary
public GCMBlockCipher(BlockCipher c, GCMMultiplier m)

Deprecated

use the CBCBlockCipher.newInstance() static method.

Base constructor - GCM mode over base cipher c over base multiplier m.

Parameters
c:BlockCipher

the base cipher.

m:GCMMultiplier

the GCM multiplier to use.

Method Detail

checkStatusback to summary
private void checkStatus()
decryptBlockback to summary
private void decryptBlock(byte[] buf, int bufOff, byte[] out, int outOff)
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.
encryptBlockback to summary
private void encryptBlock(byte[] buf, int bufOff, byte[] out, int outOff)
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.

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.

getNextCTRBlockback to summary
private void getNextCTRBlock(byte[] block)
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.

getUnderlyingCipherback to summary
public BlockCipher getUnderlyingCipher()

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

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

return the BlockCipher this object wraps.

Returns:BlockCipher

the BlockCipher this object wraps.

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.

gHASHback to summary
private void gHASH(byte[] Y, byte[] b, int len)
gHASHBlockback to summary
private void gHASHBlock(byte[] Y, byte[] b)
gHASHBlockback to summary
private void gHASHBlock(byte[] Y, byte[] b, int off)
gHASHPartialback to summary
private void gHASHPartial(byte[] Y, byte[] b, int off, int len)
initback to summary
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException

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

Note

MAC sizes from 32 bits to 128 bits (must be a multiple of 8) are supported. The default is 128 bits. Sizes less than 96 are not recommended, but are supported for specialized applications.

Parameters
forEncryption:boolean

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

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

params:CipherParameters

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

the necessary parameters for the underlying cipher to be initialised.

Exceptions
IllegalArgumentException:

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

if the params argument is inappropriate.

initCipherback to summary
private void initCipher()
newInstanceback to summary
public static GCMModeCipher newInstance(BlockCipher cipher)

Return a new GCM mode cipher based on the passed in base cipher

Parameters
cipher:BlockCipher

the base cipher for the GCM mode.

newInstanceback to summary
public static GCMModeCipher newInstance(BlockCipher cipher, GCMMultiplier m)

Return a new GCM mode cipher based on the passed in base cipher and multiplier.

Parameters
cipher:BlockCipher

the base cipher for the GCM mode.

m:GCMMultiplier

the GCM multiplier to use.

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[] in, 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
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.modes.AEADCipher.processByte.

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

Doc from org.bouncycastle.crypto.modes.AEADCipher.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.
processPartialback to summary
private void processPartial(byte[] buf, int off, int len, byte[] out, int outOff)
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)