Table of Contents

Class Blake2sDigest

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

Implementation of the cryptographic hash function BLAKE2s. BLAKE2s is optimized for 32-bit platforms and produces digests of any size between 1 and 32 bytes.

public sealed class Blake2sDigest : IDigest
Inheritance
Blake2sDigest
Implements
Inherited Members

Remarks

BLAKE2s offers a built-in keying mechanism to be used directly for authentication ("Prefix-MAC") rather than a HMAC construction.

BLAKE2s is optimized for 32-bit platforms and produces digests of any size between 1 and 32 bytes.

Constructors

Blake2sDigest()

Initializes a new instance of Blake2sDigest.

public Blake2sDigest()

Blake2sDigest(Blake2sDigest)

Constructs a new instance of Blake2sDigest from another Blake2sDigest./>.

public Blake2sDigest(Blake2sDigest digest)

Parameters

digest Blake2sDigest

The original instance of Blake2sDigest that is copied.

Blake2sDigest(byte[])

Initializes a new instance of Blake2sDigest with a key.

Blake2s for authentication ("Prefix-MAC mode"). After calling the DoFinal(byte[], int) method, the key will remain to be used for further computations of this instance. The key can be cleared using the ClearKey() method.

public Blake2sDigest(byte[] key)

Parameters

key byte[]

A key up to 32 bytes or null.

Exceptions

ArgumentException

Blake2sDigest(byte[], int, byte[], byte[])

Initializes a new instance of Blake2sDigest with a key, required digest length (in bytes), salt and personalization.

After calling the DoFinal(byte[], int) method, the key, the salt and the personalization will remain and might be used for further computations with this instance. The key can be overwritten using the ClearKey() method, the salt (pepper) can be overwritten using the ClearSalt() method.

public Blake2sDigest(byte[] key, int digestBytes, byte[] salt, byte[] personalization)

Parameters

key byte[]

A key up to 32 bytes or null.

digestBytes int

Digest length from 1 to 32 bytes.

salt byte[]

A 8 bytes or nullable salt.

personalization byte[]

A 8 bytes or null personalization.

Exceptions

ArgumentException

Blake2sDigest(int)

Initializes a new instance of Blake2sDigest with a given digest size.

public Blake2sDigest(int digestBits)

Parameters

digestBits int

Digest size in bits.

Exceptions

ArgumentException

Properties

AlgorithmName

The algorithm name.

public string AlgorithmName { get; }

Property Value

string

Methods

BlockUpdate(byte[], int, int)

Update the message digest with a block of bytes.

public void BlockUpdate(byte[] message, int offset, int len)

Parameters

message byte[]
offset int
len int

BlockUpdate(ReadOnlySpan<byte>)

Update the message digest with a span of bytes.

public void BlockUpdate(ReadOnlySpan<byte> input)

Parameters

input ReadOnlySpan<byte>

The span containing the data.

ClearKey()

Clears the key.

public void ClearKey()

ClearSalt()

Clears the salt (pepper).

public void ClearSalt()

DoFinal(byte[], int)

Close the digest, producing the final digest value.

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

Parameters

output byte[]

The byte array the digest is to be copied into.

outOffset int

The offset into the byte array the digest is to start at.

Returns

int

The number of bytes written.

Remarks

The DoFinal(byte[], int) call leaves the digest reset. Key, salt and personal string remain.

DoFinal(Span<byte>)

Close the digest, producing the final digest value.

public int DoFinal(Span<byte> output)

Parameters

output Span<byte>

The span the digest is to be copied into.

Returns

int

The number of bytes written.

Remarks

The DoFinal(Span<byte>) call leaves the digest reset. Key, salt and personal string remain.

GetByteLength()

Return the size in bytes of the internal buffer the digest applies it's compression function to.

public int GetByteLength()

Returns

int

The byte length of the digests internal buffer.

GetDigestSize()

Return the size, in bytes, of the digest produced by this message digest.

public int GetDigestSize()

Returns

int

The size, in bytes, of the digest produced by this message digest.

Reset()

Reset the digest back to it's initial state. The key, the salt and the personalization will remain for further computations.

public void Reset()

Update(byte)

Update the message digest with a single byte.

public void Update(byte b)

Parameters

b byte