Table of Contents

Class Kupyna

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

Computes the Kupyna (DSTU 7564:2014) hash for the input data.

public sealed class Kupyna : HashAlgorithm, ICryptoTransform, IDisposable, IResettable
Inheritance
Kupyna
Implements
Inherited Members

Remarks

This is a fully managed implementation of Kupyna that does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.

Kupyna is the Ukrainian national cryptographic hash standard defined in DSTU 7564:2014. It supports output sizes of 256, 384, or 512 bits.

The algorithm uses a Davies-Meyer compression function with two fixed permutations T⊕ (P) and T+ (Q), derived from the Kalyna block cipher (DSTU 7624:2014). Each round applies AddRoundConstant, SubBytes, ShiftBytes, and MixColumns.

Implementation follows the specification in the IACR ePrint 2015/885 paper and the official reference by Kiianchuk, Mordvinov, and Oliynykov.

Constructors

Kupyna()

Initializes a new instance of the Kupyna class with 512-bit output.

public Kupyna()

Kupyna(int)

Initializes a new instance of the Kupyna class.

public Kupyna(int hashSizeBytes)

Parameters

hashSizeBytes int

The desired output size in bytes (32, 48, or 64).

Exceptions

ArgumentException

Thrown when hashSizeBytes is not 32, 48, or 64.

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 with default 512-bit output.

public static Kupyna Create()

Returns

Kupyna

A new Kupyna instance.

Create(int)

Creates a new instance with specified output size.

public static Kupyna Create(int hashSizeBytes)

Parameters

hashSizeBytes int

The hash size in bytes (32, 48, or 64).

Returns

Kupyna

A new Kupyna instance.

Dispose(bool)

Releases the unmanaged resources used by the HashAlgorithm and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true 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

source ReadOnlySpan<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 Kupyna hash of source and returns it as a new byte array.

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

Parameters

source ReadOnlySequence<byte>

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

hashSizeBytes int

The desired output size in bytes (32, 48, or 64).

Returns

byte[]

A new byte array containing the Kupyna hash.

Exceptions

ArgumentException

Thrown when hashSizeBytes is not 32, 48, or 64.

HashData(ReadOnlySpan<byte>, int)

Computes the Kupyna hash of source and returns it as a new byte array.

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

Parameters

source ReadOnlySpan<byte>

The input data to hash.

hashSizeBytes int

The desired output size in bytes (32, 48, or 64).

Returns

byte[]

A new byte array containing the Kupyna hash.

Exceptions

ArgumentException

Thrown when hashSizeBytes is not 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 Kupyna 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

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.

hashSizeBytes int

The desired output size in bytes (32, 48, or 64).

bytesWritten int

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

Returns

bool

true if destination was large enough; otherwise, false.

Exceptions

ArgumentException

Thrown when hashSizeBytes is not 32, 48, or 64.

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

Computes the Kupyna hash of source and writes it into destination.

public static bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, int hashSizeBytes, 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.

hashSizeBytes int

The desired output size in bytes (32, 48, or 64).

bytesWritten int

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

Returns

bool

true if destination was large enough; otherwise, false.

Exceptions

ArgumentException

Thrown when hashSizeBytes is not 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

destination Span<byte>

The target buffer to write the hash to.

bytesWritten int

The number of bytes written into the buffer.

Returns

bool

true if the destination buffer was large enough; otherwise false.

Exceptions

ObjectDisposedException

Thrown when the instance has been disposed.