Table of Contents

Class GMac

Namespace
Org.BouncyCastle.Crypto.Macs
Assembly
BouncyCastle.Cryptography.dll

The GMAC specialisation of Galois/Counter mode (GCM) detailed in NIST Special Publication 800-38D.

public class GMac : IMac
Inheritance
GMac
Implements
Inherited Members

Remarks

GMac is an invocation of the GCM mode where no data is encrypted (i.e. all input data to the Mac is processed as additional authenticated data with the underlying GCM block cipher).

Constructors

GMac(GcmBlockCipher)

Creates a GMAC based on the operation of a block cipher in GCM mode.

public GMac(GcmBlockCipher cipher)

Parameters

cipher GcmBlockCipher

the cipher to be used in GCM mode to generate the MAC.

Remarks

This will produce an authentication code the length of the block size of the cipher.

GMac(GcmBlockCipher, int)

Creates a GMAC based on the operation of a 128 bit block cipher in GCM mode.

public GMac(GcmBlockCipher cipher, int macSizeBits)

Parameters

cipher GcmBlockCipher

the cipher to be used in GCM mode to generate the MAC.

macSizeBits int

the mac size to generate, in bits. Must be a multiple of 8, between 32 and 128 (inclusive). Sizes less than 96 are not recommended, but are supported for specialized applications.

Remarks

This will produce an authentication code the length of the block size of the cipher.

Properties

AlgorithmName

The algorithm name.

public string AlgorithmName { get; }

Property Value

string

Methods

BlockUpdate(byte[], int, int)

Update the MAC with a block of bytes.

public void BlockUpdate(byte[] input, int inOff, int len)

Parameters

input byte[]

the byte array containing the data.

inOff int

the offset into the byte array where the data starts.

len int

BlockUpdate(ReadOnlySpan<byte>)

Update the MAC with a span of bytes.

public void BlockUpdate(ReadOnlySpan<byte> input)

Parameters

input ReadOnlySpan<byte>

the span containing the data.

DoFinal(byte[], int)

Perform final calculations, producing the result MAC.

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

Parameters

output byte[]

the byte array the MAC is to be copied into.

outOff int

the offset into the byte array the MAC is to start at.

Returns

int

the number of bytes written

Remarks

This call leaves the MAC reset.

DoFinal(Span<byte>)

Perform final calculations, producing the result MAC.

public int DoFinal(Span<byte> output)

Parameters

output Span<byte>

the span the MAC is to be copied into.

Returns

int

the number of bytes written

Remarks

This call leaves the MAC reset.

GetMacSize()

Return the size, in bytes, of the MAC produced by this implementation.

public int GetMacSize()

Returns

int

the size, in bytes, of the MAC produced by this implementation.

Init(ICipherParameters)

Initialises the GMAC - requires a ParametersWithIV providing a KeyParameter and a nonce.

public void Init(ICipherParameters parameters)

Parameters

parameters ICipherParameters

Reset()

Reset the MAC back to its initial state.

public void Reset()

Update(byte)

Update the MAC with a single byte.

public void Update(byte input)

Parameters

input byte

the input byte to be entered.