Table of Contents

Elf64 Class

Definition

Namespace
Bodu.IO.Hashing
Assembly
Bodu.IO.Hashing.dll
Package
Bodu.IO.Hashing 1.0.0
Source
Elf64.cs

Computes a 64-bit non-cryptographic hash using the ELF (Executable and Linkable Format) hash algorithm originally used in UNIX System V object files. This class cannot be inherited.

public sealed class Elf64 : NonCryptographicHashAlgorithm
Inheritance
Elf64
Inherited Members
Extension Methods

Remarks

ELF hashing shifts and folds the running hash for each byte of input, periodically XORing the high bits back into the low bits. An optional Seed may be supplied to alter the initial state and is reconfigurable only while the algorithm has not yet consumed any input. Reset() returns the instance to the reconfigurable state.

When to choose ELF64. The ELF hash is the symbol-table hash baked into UNIX System V object files and the GNU dynamic linker's .gnu.hash section - pick it when interoperating with ELF-format tooling or when reproducing a digest computed by the system linker. For general-purpose hash-table keying prefer Fnv1a64 (better avalanche on the same per-byte cost) or MurmurHash3_128 (much better distribution on inputs longer than ~16 bytes). The 64-bit width makes ELF64 a reasonable choice for medium-sized identifier maps where 32 bits would invite collisions.

Output and lifecycle. Produces a 64-bit (8-byte) digest in little-endian byte order. GetCurrentHash() is non-destructive; instances are not thread-safe.

important

This algorithm is not cryptographically secure and should not be used for password hashing, digital signatures, or integrity validation in security-sensitive applications.

using Bodu.IO.Hashing;
using Bodu.IO.Hashing.Extensions;

var elf = new Elf64();
byte[] digest = elf.ComputeHash(System.Text.Encoding.ASCII.GetBytes("symbol_name"));

Constructors

Elf64()

Initializes a new instance of the Elf64 class with a seed of 0.

public Elf64()

Elf64(ulong)

Initializes a new instance of the Elf64 class using the specified initial seed.

public Elf64(ulong seed)

Parameters

seed ulong

The initial seed applied to the running hash accumulator.

Properties

Seed

Gets or sets the initial seed applied to the running hash accumulator.

public ulong Seed { get; set; }

Property Value

ulong

The seed value applied before hashing begins.

Exceptions

CryptographicUnexpectedOperationException

The algorithm has already consumed input and cannot be reconfigured until Reset() is invoked.

Methods

Append(ReadOnlySpan<byte>)

When overridden in a derived class, appends the contents of source to the data already processed for the current hash computation.

public override void Append(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The data to process.

GetCurrentHashCore(Span<byte>)

When overridden in a derived class, writes the computed hash value to destination without modifying accumulated state.

protected override void GetCurrentHashCore(Span<byte> destination)

Parameters

destination Span<byte>

The buffer that receives the computed hash value.

Reset()

When overridden in a derived class, resets the hash computation to the initial state.

public override void Reset()

Applies to

ProductVersions
.NET8, 10