Table of Contents

Class SipHash

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

Implementation of SipHash as specified in "SipHash: a fast short-input PRF", by Jean-Philippe Aumasson and Daniel J. Bernstein (https://131002.net/siphash/siphash.pdf).

public class SipHash : IMac
Inheritance
SipHash
Implements
Inherited Members

Remarks

"SipHash is a family of PRFs SipHash-c-d where the integer parameters c and d are the number of compression rounds and the number of finalization rounds. A compression round is identical to a finalization round and this round function is called SipRound. Given a 128-bit key k and a (possibly empty) byte string m, SipHash-c-d returns a 64-bit value..."

Constructors

SipHash()

SipHash-2-4

public SipHash()

SipHash(int, int)

SipHash-c-d

public SipHash(int c, int d)

Parameters

c int

the number of compression rounds

d int

the number of finalization rounds

Fields

c

protected readonly int c

Field Value

int

d

protected readonly int d

Field Value

int

k0

protected long k0

Field Value

long

k1

protected long k1

Field Value

long

m

protected long m

Field Value

long

v0

protected long v0

Field Value

long

v1

protected long v1

Field Value

long

v2

protected long v2

Field Value

long

v3

protected long v3

Field Value

long

wordCount

protected int wordCount

Field Value

int

wordPos

protected int wordPos

Field Value

int

Properties

AlgorithmName

The algorithm name.

public virtual string AlgorithmName { get; }

Property Value

string

Methods

ApplySipRounds(int)

protected virtual void ApplySipRounds(int n)

Parameters

n int

BlockUpdate(byte[], int, int)

Update the MAC with a block of bytes.

public virtual void BlockUpdate(byte[] input, int offset, int length)

Parameters

input byte[]

the byte array containing the data.

offset int
length int

BlockUpdate(ReadOnlySpan<byte>)

Update the MAC with a span of bytes.

public virtual void BlockUpdate(ReadOnlySpan<byte> input)

Parameters

input ReadOnlySpan<byte>

the span containing the data.

DoFinal()

public virtual long DoFinal()

Returns

long

DoFinal(byte[], int)

Perform final calculations, producing the result MAC.

public virtual 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 virtual int GetMacSize()

Returns

int

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

Init(ICipherParameters)

Initialise the MAC.

public virtual void Init(ICipherParameters parameters)

Parameters

parameters ICipherParameters

The key or other data required by the MAC.

ProcessMessageWord()

protected virtual void ProcessMessageWord()

Reset()

Reset the MAC back to its initial state.

public virtual void Reset()

RotateLeft(long, int)

protected static long RotateLeft(long x, int n)

Parameters

x long
n int

Returns

long

Update(byte)

Update the MAC with a single byte.

public virtual void Update(byte input)

Parameters

input byte

the input byte to be entered.