Table of Contents

Class OcbBlockCipher

Namespace
Org.BouncyCastle.Crypto.Modes
Assembly
BouncyCastle.Cryptography.dll
public class OcbBlockCipher : IAeadBlockCipher, IAeadCipher
Inheritance
OcbBlockCipher
Implements
Inherited Members

Remarks

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<rogaway@cs.ucdavis.edu> Sat, 27 February 2021 02:46 UTC

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.

Constructors

OcbBlockCipher(IBlockCipher, IBlockCipher)

public OcbBlockCipher(IBlockCipher hashCipher, IBlockCipher mainCipher)

Parameters

hashCipher IBlockCipher
mainCipher IBlockCipher

Properties

AlgorithmName

The name of the algorithm this cipher implements.

public virtual string AlgorithmName { get; }

Property Value

string

UnderlyingCipher

The block cipher underlying this algorithm.

public virtual IBlockCipher UnderlyingCipher { get; }

Property Value

IBlockCipher

Methods

Clear(byte[])

protected virtual void Clear(byte[] bs)

Parameters

bs byte[]

DoFinal(byte[], int)

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

@param outBytes space for any resulting output data. @param outOff offset into out to start copying the data at. @return number of bytes written into out. @throws InvalidOperationException if the cipher is in an inappropriate state. @throws InvalidCipherTextException if the MAC fails to match.

public virtual int DoFinal(byte[] output, int outOff)

Parameters

output byte[]
outOff int

Returns

int

DoFinal(Span<byte>)

public virtual int DoFinal(Span<byte> output)

Parameters

output Span<byte>

Returns

int

GetBlockSize()

public virtual int GetBlockSize()

Returns

int

The block size for this cipher, in bytes.

GetLSub(int)

protected virtual byte[] GetLSub(int n)

Parameters

n int

Returns

byte[]

GetMac()

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

@return MAC for plaintext data.

public virtual byte[] GetMac()

Returns

byte[]

GetOutputSize(int)

Return the size of the output buffer required for a ProcessBytes plus a DoFinal with an input of len bytes.

@param len the length of the input. @return the space required to accommodate a call to ProcessBytes and DoFinal with len bytes of input.

public virtual int GetOutputSize(int len)

Parameters

len int

Returns

int

GetUpdateOutputSize(int)

Return the size of the output buffer required for a ProcessBytes an input of len bytes.

@param len the length of the input. @return the space required to accommodate a call to ProcessBytes with len bytes of input.

public virtual int GetUpdateOutputSize(int len)

Parameters

len int

Returns

int

Init(bool, ICipherParameters)

Initialise the cipher.

public virtual void Init(bool forEncryption, ICipherParameters parameters)

Parameters

forEncryption bool

Initialise for encryption if true, for decryption if false.

parameters ICipherParameters

The key or other data required by the cipher.

Remarks

Parameter can either be an AeadParameters or a ParametersWithIV object.

OCB_double(byte[])

protected static byte[] OCB_double(byte[] block)

Parameters

block byte[]

Returns

byte[]

OCB_extend(byte[], int)

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

Parameters

block byte[]
pos int

OCB_ntz(long)

protected static int OCB_ntz(long x)

Parameters

x long

Returns

int

ProcessAadByte(byte)

Add a single byte to the associated data check.

public virtual void ProcessAadByte(byte input)

Parameters

input byte

The byte to be processed.

Remarks

If the implementation supports it, this will be an online operation and will not retain the associated data.

ProcessAadBytes(byte[], int, int)

Add a sequence of bytes to the associated data check.

public virtual void ProcessAadBytes(byte[] input, int off, int len)

Parameters

input byte[]
off int
len int

The number of bytes to be processed.

Remarks

If the implementation supports it, this will be an online operation and will not retain the associated data.

ProcessAadBytes(ReadOnlySpan<byte>)

Add a span of bytes to the associated data check.

public virtual void ProcessAadBytes(ReadOnlySpan<byte> input)

Parameters

input ReadOnlySpan<byte>

the span containing the data.

Remarks

If the implementation supports it, this will be an online operation and will not retain the associated data.

ProcessByte(byte, byte[], int)

Encrypt/decrypt a single byte.

@param input the byte to be processed. @param outBytes the output buffer the processed byte goes into. @param outOff the offset into the output byte array the processed data starts at. @return the number of bytes written to out. @exception DataLengthException if the output buffer is too small.

public virtual int ProcessByte(byte input, byte[] output, int outOff)

Parameters

input byte
output byte[]
outOff int

Returns

int

ProcessByte(byte, Span<byte>)

public virtual int ProcessByte(byte input, Span<byte> output)

Parameters

input byte
output Span<byte>

Returns

int

ProcessBytes(byte[], int, int, byte[], int)

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

@param inBytes the input byte array. @param inOff the offset into the in array where the data to be processed starts. @param len the number of bytes to be processed. @param outBytes the output buffer the processed bytes go into. @param outOff the offset into the output byte array the processed data starts at. @return the number of bytes written to out. @exception DataLengthException if the output buffer is too small.

public virtual int ProcessBytes(byte[] input, int inOff, int len, byte[] output, int outOff)

Parameters

input byte[]
inOff int
len int
output byte[]
outOff int

Returns

int

ProcessBytes(ReadOnlySpan<byte>, Span<byte>)

public virtual int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output)

Parameters

input ReadOnlySpan<byte>
output Span<byte>

Returns

int

ProcessHashBlock()

protected virtual void ProcessHashBlock()

ProcessMainBlock(byte[], int)

protected virtual void ProcessMainBlock(byte[] output, int outOff)

Parameters

output byte[]
outOff int

ProcessMainBlock(Span<byte>)

protected virtual void ProcessMainBlock(Span<byte> output)

Parameters

output Span<byte>

ProcessNonce(byte[])

protected virtual int ProcessNonce(byte[] N)

Parameters

N byte[]

Returns

int

Reset()

Reset the cipher to the same state as it was after the last init (if there was one).

public virtual void Reset()

Reset(bool)

protected virtual void Reset(bool clearMac)

Parameters

clearMac bool

ShiftLeft(byte[], byte[])

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

Parameters

block byte[]
output byte[]

Returns

int

UpdateHASH(byte[])

protected virtual void UpdateHASH(byte[] LSub)

Parameters

LSub byte[]

Xor(byte[], byte[])

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

Parameters

block byte[]
val byte[]