Table of Contents

Class Keccak256

Namespace
CryptoHives.Foundation.Security.Cryptography.Hash
Assembly
CryptoHives.Foundation.Security.Cryptography.dll

Computes the Keccak-256 hash for the input data.

public sealed class Keccak256 : KeccakHashCore, ICryptoTransform, IDisposable, IResettable
Inheritance
Keccak256
Implements
Inherited Members

Remarks

This is the original Keccak-256 algorithm as used by Ethereum, which differs from SHA3-256 in the domain separator byte (0x01 vs 0x06).

Keccak-256 produces a 256-bit (32-byte) hash value.

Constructors

Keccak256()

Initializes a new instance of the Keccak256 class.

public Keccak256()

Fields

HashSizeBits

The hash size in bits.

public const int HashSizeBits = 256

Field Value

int

HashSizeBytes

The hash size in bytes.

public const int HashSizeBytes = 32

Field Value

int

RateBytes

The rate in bytes (1088 bits for Keccak-256).

public const int RateBytes = 136

Field Value

int

Properties

AlgorithmName

Gets the name of the hash algorithm.

public override string AlgorithmName { get; }

Property Value

string

BlockSize

Gets the block size in bytes used by the hash algorithm.

public override int BlockSize { get; }

Property Value

int

Methods

Create()

Creates a new instance of the Keccak256 class.

public static Keccak256 Create()

Returns

Keccak256

A new Keccak-256 hash algorithm instance.

HashData(in ReadOnlySequence<byte>)

Computes the Keccak-256 hash of source and returns it as a new byte array.

public static byte[] HashData(in ReadOnlySequence<byte> source)

Parameters

source ReadOnlySequence<byte>

The (possibly multi-segment) input sequence to hash.

Returns

byte[]

A new byte array containing the Keccak-256 hash.

HashData(ReadOnlySpan<byte>)

Computes the Keccak-256 hash of source and returns it as a new byte array.

public static byte[] HashData(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The input data to hash.

Returns

byte[]

A new byte array containing the Keccak-256 hash.

TryHashData(in ReadOnlySequence<byte>, Span<byte>, out int)

Computes the Keccak-256 hash of source and writes it into destination.

public static bool TryHashData(in ReadOnlySequence<byte> source, Span<byte> destination, out int bytesWritten)

Parameters

source ReadOnlySequence<byte>

The (possibly multi-segment) input sequence to hash.

destination Span<byte>

The buffer to receive the hash value. Must be at least HashSizeBytes bytes.

bytesWritten int

When this method returns, the number of bytes written into destination.

Returns

bool

true if destination was large enough; otherwise, false.

TryHashData(ReadOnlySpan<byte>, Span<byte>, out int)

Computes the Keccak-256 hash of source and writes it into destination.

public static bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)

Parameters

source ReadOnlySpan<byte>

The input data to hash.

destination Span<byte>

The buffer to receive the hash value. Must be at least HashSizeBytes bytes.

bytesWritten int

When this method returns, the number of bytes written into destination.

Returns

bool

true if destination was large enough; otherwise, false.