Table of Contents

Class Poly1305

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

Poly1305 message authentication code, designed by D. J. Bernstein.

public class Poly1305 : IMac
Inheritance
Poly1305
Implements
Inherited Members

Remarks

Poly1305 computes a 128-bit (16 bytes) authenticator, using a 128 bit nonce and a 256 bit key consisting of a 128 bit key applied to an underlying cipher, and a 128 bit key (with 106 effective key bits) used in the authenticator.

The polynomial calculation in this implementation is adapted from the public domain poly1305-donna-unrolled C implementation by Andrew M (@floodyberry).

Constructors

Poly1305()

public Poly1305()

Poly1305(IBlockCipher)

public Poly1305(IBlockCipher cipher)

Parameters

cipher IBlockCipher

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 Poly1305 MAC.

public void Init(ICipherParameters parameters)

Parameters

parameters ICipherParameters

a {@link ParametersWithIV} containing a 128 bit nonce and a {@link KeyParameter} with a 256 bit key complying to the {@link Poly1305KeyGenerator Poly1305 key format}.

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.

See Also