Class Lsh512
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Hash
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
Computes the LSH-512 hash for the input data.
public sealed class Lsh512 : HashAlgorithm, ICryptoTransform, IDisposable, IResettable
- Inheritance
-
Lsh512
- Implements
- Inherited Members
Remarks
This is a fully managed implementation of LSH-512 that does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.
LSH is the Korean national cryptographic hash standard defined in KS X 3262. The LSH-512 family uses 64-bit words and supports output sizes of 224, 256, 384, or 512 bits.
The algorithm uses a wide-pipe Merkle-Damgård construction with 28 steps, each consisting of message addition, a mixing function with rotation-based diffusion, and a word permutation.
Implementation follows the specification published by KISA (Korea Internet & Security Agency) and the official reference implementation.
Constructors
Lsh512()
Initializes a new instance of the Lsh512 class with 512-bit output.
public Lsh512()
Lsh512(int)
Initializes a new instance of the Lsh512 class.
public Lsh512(int hashSizeBytes)
Parameters
hashSizeBytesintThe desired output size in bytes (28, 32, 48, or 64).
Exceptions
- ArgumentException
Thrown when
hashSizeBytesis not 28, 32, 48, or 64.
Properties
AlgorithmName
Gets the name of the hash algorithm.
public override string AlgorithmName { get; }
Property Value
BlockSize
Gets the block size in bytes used by the hash algorithm.
public override int BlockSize { get; }
Property Value
Methods
Create()
Creates a new instance with default 512-bit output.
public static Lsh512 Create()
Returns
Create(int)
Creates a new instance with specified output size.
public static Lsh512 Create(int hashSizeBytes)
Parameters
hashSizeBytesintThe hash size in bytes (28, 32, 48, or 64).
Returns
Dispose(bool)
Releases the unmanaged resources used by the HashAlgorithm and optionally releases the managed resources.
protected override void Dispose(bool disposing)
Parameters
disposingbooltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
HashCore(ReadOnlySpan<byte>)
When overridden in a derived class, routes data written to the object into the hash algorithm for computing the hash.
protected override void HashCore(ReadOnlySpan<byte> source)
Parameters
sourceReadOnlySpan<byte>The input to compute the hash code for.
Exceptions
- ObjectDisposedException
Thrown when the instance has been disposed.
HashData(in ReadOnlySequence<byte>, int)
Computes the LSH-512 hash of source and returns it as a new byte array.
public static byte[] HashData(in ReadOnlySequence<byte> source, int hashSizeBytes)
Parameters
sourceReadOnlySequence<byte>The (possibly multi-segment) input sequence to hash.
hashSizeBytesintThe desired output size in bytes (28, 32, 48, or 64).
Returns
- byte[]
A new byte array containing the LSH-512 hash.
Exceptions
- ArgumentException
Thrown when
hashSizeBytesis not 28, 32, 48, or 64.
HashData(ReadOnlySpan<byte>, int)
Computes the LSH-512 hash of source and returns it as a new byte array.
public static byte[] HashData(ReadOnlySpan<byte> source, int hashSizeBytes)
Parameters
sourceReadOnlySpan<byte>The input data to hash.
hashSizeBytesintThe desired output size in bytes (28, 32, 48, or 64).
Returns
- byte[]
A new byte array containing the LSH-512 hash.
Exceptions
- ArgumentException
Thrown when
hashSizeBytesis not 28, 32, 48, or 64.
Initialize()
Initializes an implementation of the HashAlgorithm class.
public override void Initialize()
Exceptions
- ObjectDisposedException
Thrown when the instance has been disposed.
TryHashData(in ReadOnlySequence<byte>, Span<byte>, int, out int)
Computes the LSH-512 hash of source and writes it into destination.
public static bool TryHashData(in ReadOnlySequence<byte> source, Span<byte> destination, int hashSizeBytes, out int bytesWritten)
Parameters
sourceReadOnlySequence<byte>The (possibly multi-segment) input sequence to hash.
destinationSpan<byte>The buffer to receive the hash value. Must be at least
hashSizeBytesbytes.hashSizeBytesintThe desired output size in bytes (28, 32, 48, or 64).
bytesWrittenintWhen this method returns, the number of bytes written into
destination.
Returns
Exceptions
- ArgumentException
Thrown when
hashSizeBytesis not 28, 32, 48, or 64.
TryHashData(ReadOnlySpan<byte>, Span<byte>, int, out int)
Computes the LSH-512 hash of source and writes it into destination.
public static bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, int hashSizeBytes, out int bytesWritten)
Parameters
sourceReadOnlySpan<byte>The input data to hash.
destinationSpan<byte>The buffer to receive the hash value. Must be at least
hashSizeBytesbytes.hashSizeBytesintThe desired output size in bytes (28, 32, 48, or 64).
bytesWrittenintWhen this method returns, the number of bytes written into
destination.
Returns
Exceptions
- ArgumentException
Thrown when
hashSizeBytesis not 28, 32, 48, or 64.
TryHashFinal(Span<byte>, out int)
When overridden in a derived class, finalizes the hash computation and writes the result into the provided buffer.
protected override bool TryHashFinal(Span<byte> destination, out int bytesWritten)
Parameters
destinationSpan<byte>The target buffer to write the hash to.
bytesWrittenintThe number of bytes written into the buffer.
Returns
Exceptions
- ObjectDisposedException
Thrown when the instance has been disposed.