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

public Class OCBBlockCipher

extends Object
implements AEADBlockCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.modes.AEADBlockCipher, org.bouncycastle.crypto.modes.AEADCipher
Imports
java.util.Vector, org.bouncycastle.crypto.BlockCipher, .CipherParameters, .DataLengthException, .InvalidCipherTextException, .OutputLengthException, org.bouncycastle.crypto.params.AEADParameters, .KeyParameter, .ParametersWithIV, org.bouncycastle.util.Arrays, .Bytes, .Longs

An implementation of RFC 7253 on The OCB Authenticated-Encryption Algorithm. For those still concerned about the original patents around this, please see:

https://mailarchive.ietf.org/arch/msg/cfrg/qLTveWOdTJcLn4HP3ev-vrj05Vg/

Text reproduced below.
Phillip Rogaway >[email protected]< Sat, 27 February 2021 02:46 UTCShow header I can confirm that I have abandoned all OCB patents and placed into the public domain all OCB-related IP of mine. While I have been telling people this for quite some time, I don't think I ever made a proper announcement to the CFRG or on the OCB webpage. Consider that done.

Field Summary

Modifier and TypeField and Description
private static final int
private byte[]
private boolean
private byte[]
private long
private int
private BlockCipher
private byte[]
private byte[]
private Vector<E>
L

private byte[]
private byte[]
private byte[]
private int
private byte[]
private long
private int
private BlockCipher
private byte[]
private byte[]
private byte[]
private byte[]
private byte[]

Constructor Summary

AccessConstructor and Description
public
OCBBlockCipher(BlockCipher hashCipher, BlockCipher mainCipher)

Method Summary

Modifier and TypeMethod and Description
protected void
clear(byte[] bs)

public int
doFinal(byte[]
space for any resulting output data.
output
,
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.
public String
getAlgorithmName()

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

Return the name of the algorithm.
protected byte[]
getLSub(int n)

public byte[]
getMac()

Implements org.bouncycastle.crypto.modes.AEADCipher.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.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.
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.
parameters
)

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

initialise the underlying cipher.
protected static byte[]
OCB_double(byte[] block)

protected static void
OCB_extend(byte[] block, int pos)

protected static int
OCB_ntz(long x)

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

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.
off
,
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.
protected void
protected void
processMainBlock(byte[] output, int outOff)

protected int
processNonce(byte[] N)

public void
protected void
reset(boolean clearMac)

protected static int
shiftLeft(byte[] block, byte[] output)

protected void
updateHASH(byte[] LSub)

protected static void
xor(byte[] block, byte[] val)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BLOCK_SIZEback to summary
private static final int BLOCK_SIZE
Checksumback to summary
private byte[] Checksum
forEncryptionback to summary
private boolean forEncryption
hashBlockback to summary
private byte[] hashBlock
hashBlockCountback to summary
private long hashBlockCount
hashBlockPosback to summary
private int hashBlockPos
hashCipherback to summary
private BlockCipher hashCipher
initialAssociatedTextback to summary
private byte[] initialAssociatedText
KtopInputback to summary
private byte[] KtopInput
Lback to summary
private Vector<E> L
L_Asteriskback to summary
private byte[] L_Asterisk
L_Dollarback to summary
private byte[] L_Dollar
macBlockback to summary
private byte[] macBlock
macSizeback to summary
private int macSize
mainBlockback to summary
private byte[] mainBlock
mainBlockCountback to summary
private long mainBlockCount
mainBlockPosback to summary
private int mainBlockPos
mainCipherback to summary
private BlockCipher mainCipher
OffsetHASHback to summary
private byte[] OffsetHASH
OffsetMAINback to summary
private byte[] OffsetMAIN
OffsetMAIN_0back to summary
private byte[] OffsetMAIN_0
Stretchback to summary
private byte[] Stretch
Sumback to summary
private byte[] Sum

Constructor Detail

OCBBlockCipherback to summary
public OCBBlockCipher(BlockCipher hashCipher, BlockCipher mainCipher)

Method Detail

clearback to summary
protected void clear(byte[] bs)
doFinalback to summary
public int doFinal(byte[] output, 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
output: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()

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.

getLSubback to summary
protected byte[] getLSub(int n)
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.

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.

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

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

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

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.

parameters:CipherParameters

the necessary parameters for the underlying cipher to be initialised.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
OCB_doubleback to summary
protected static byte[] OCB_double(byte[] block)
OCB_extendback to summary
protected static void OCB_extend(byte[] block, int pos)
OCB_ntzback to summary
protected static int OCB_ntz(long x)
processAADByteback to summary
public void processAADByte(byte input)

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
input:byte

the byte to be processed.

processAADBytesback to summary
public void processAADBytes(byte[] input, int off, 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.

off: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.
processHashBlockback to summary
protected void processHashBlock()
processMainBlockback to summary
protected void processMainBlock(byte[] output, int outOff)
processNonceback to summary
protected int processNonce(byte[] N)
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
protected void reset(boolean clearMac)
shiftLeftback to summary
protected static int shiftLeft(byte[] block, byte[] output)
updateHASHback to summary
protected void updateHASH(byte[] LSub)
xorback to summary
protected static void xor(byte[] block, byte[] val)