Table of Contents

Class CryptoRistretto

Namespace
LibSodium
Assembly
LibSodium.Net.dll

Constants and cryptographic operations for the Ristretto255 group.

public static class CryptoRistretto
Inheritance
CryptoRistretto
Inherited Members

Remarks

🧂 Based on libsodium’s Ristretto255 API: https://doc.libsodium.org/advanced/ristretto255

Fields

HashLen

Length of a hash input required for point derivation in bytes (64).

public const int HashLen = 64

Field Value

int

NonReducedScalarLen

Length of a non-reduced scalar input in bytes (64).

public const int NonReducedScalarLen = 64

Field Value

int

PointLen

Length of a Ristretto255 encoded point in bytes (32).

public const int PointLen = 32

Field Value

int

ScalarLen

Length of a Ristretto255 scalar in bytes (32).

public const int ScalarLen = 32

Field Value

int

Methods

AddPoints(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)

Adds two Ristretto255 points: resultPoint = point1 + point2.

public static void AddPoints(ReadOnlySpan<byte> point1, ReadOnlySpan<byte> point2, Span<byte> resultPoint)

Parameters

point1 ReadOnlySpan<byte>

The first input point (32 bytes).

point2 ReadOnlySpan<byte>

The second input point (32 bytes).

resultPoint Span<byte>

The buffer to receive the result (32 bytes).

Exceptions

ArgumentException

Thrown if any buffer is not exactly 32 bytes.

LibSodiumException

Thrown if the operation fails internally.

AddScalars(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)

Adds two scalars modulo the Ristretto255 group order: resultScalar = scalar1 + scalar2.

public static void AddScalars(ReadOnlySpan<byte> scalar1, ReadOnlySpan<byte> scalar2, Span<byte> resultScalar)

Parameters

scalar1 ReadOnlySpan<byte>

The first scalar operand (32 bytes).

scalar2 ReadOnlySpan<byte>

The second scalar operand (32 bytes).

resultScalar Span<byte>

The buffer to receive the sum (32 bytes).

Exceptions

ArgumentException

Thrown if any of the buffers are not exactly 32 bytes.

ComplementScalar(ReadOnlySpan<byte>, Span<byte>)

Computes the complement of a scalar modulo the Ristretto255 group order: resultScalar = l - inputScalar.

public static void ComplementScalar(ReadOnlySpan<byte> inputScalar, Span<byte> resultScalar)

Parameters

inputScalar ReadOnlySpan<byte>

The scalar to complement (32 bytes).

resultScalar Span<byte>

The buffer to receive the complemented scalar (32 bytes).

Exceptions

ArgumentException

Thrown if inputScalar or resultScalar is not exactly 32 bytes.

DerivePointFromHash(SecureMemory<byte>, SecureMemory<byte>)

Derives a Ristretto255 point from a 64-byte uniformly random hash input.

public static void DerivePointFromHash(SecureMemory<byte> hash, SecureMemory<byte> point)

Parameters

hash SecureMemory<byte>

A 64-byte uniformly random input.

point SecureMemory<byte>

The buffer to receive the resulting point. Must be exactly 32 bytes.

Exceptions

ArgumentException

Thrown if point is not 32 bytes or hash is not 64 bytes.

LibSodiumException

Thrown if the operation fails internally.

DerivePointFromHash(ReadOnlySpan<byte>, Span<byte>)

Derives a Ristretto255 point from a 64-byte uniformly random hash input.

public static void DerivePointFromHash(ReadOnlySpan<byte> hash, Span<byte> point)

Parameters

hash ReadOnlySpan<byte>

A 64-byte uniformly random input.

point Span<byte>

The buffer to receive the resulting point. Must be exactly 32 bytes.

Exceptions

ArgumentException

Thrown if point is not 32 bytes or hash is not 64 bytes.

LibSodiumException

Thrown if the operation fails internally.

GenerateRandomPoint(Span<byte>)

Generates a uniformly random valid Ristretto255 point.

public static void GenerateRandomPoint(Span<byte> point)

Parameters

point Span<byte>

The buffer to receive the generated point. Must be exactly 32 bytes.

Exceptions

ArgumentException

Thrown if point is not exactly 32 bytes.

LibSodiumException

Thrown if the operation fails internally.

GenerateRandomScalar(SecureMemory<byte>)

Generates a uniformly random scalar modulo the Ristretto255 group order (32 bytes). This is typically used to generate a random private key.

public static void GenerateRandomScalar(SecureMemory<byte> resultScalar)

Parameters

resultScalar SecureMemory<byte>

The buffer to receive the scalar (32 bytes, secret).

Exceptions

ArgumentException

Thrown if resultScalar is not 32 bytes.

LibSodiumException

Thrown if the operation fails internally.

GenerateRandomScalar(Span<byte>)

Generates a uniformly random scalar modulo the Ristretto255 group order (32 bytes). This is typically used to generate a random private key.

public static void GenerateRandomScalar(Span<byte> resultScalar)

Parameters

resultScalar Span<byte>

The buffer to receive the scalar (32 bytes).

Exceptions

ArgumentException

Thrown if resultScalar is not exactly 32 bytes.

LibSodiumException

Thrown if the operation fails internally.

InvertScalar(ReadOnlySpan<byte>, Span<byte>)

Computes the multiplicative inverse of a scalar modulo the Ristretto255 group order: resultScalar = inverse(inputScalar).

public static void InvertScalar(ReadOnlySpan<byte> inputScalar, Span<byte> resultScalar)

Parameters

inputScalar ReadOnlySpan<byte>

The scalar to invert (32 bytes).

resultScalar Span<byte>

The buffer to receive the inverted scalar (32 bytes).

Exceptions

ArgumentException

Thrown if inputScalar or resultScalar is not exactly 32 bytes.

LibSodiumException

Thrown if the operation fails internally or the scalar is not invertible.

IsValidPoint(ReadOnlySpan<byte>)

Checks whether the given 32-byte buffer is a valid Ristretto255 encoded point.

public static bool IsValidPoint(ReadOnlySpan<byte> point)

Parameters

point ReadOnlySpan<byte>

The encoded point to validate. Must be exactly 32 bytes.

Returns

bool

true if the point is valid; otherwise, false.

Exceptions

ArgumentException

Thrown if point is not exactly 32 bytes.

MultiplyScalars(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)

Multiplies two scalars modulo the Ristretto255 group order: resultScalar = scalar1 Ă— scalar2.

public static void MultiplyScalars(ReadOnlySpan<byte> scalar1, ReadOnlySpan<byte> scalar2, Span<byte> resultScalar)

Parameters

scalar1 ReadOnlySpan<byte>

The first scalar operand (32 bytes).

scalar2 ReadOnlySpan<byte>

The second scalar operand (32 bytes).

resultScalar Span<byte>

The buffer to receive the product (32 bytes).

Exceptions

ArgumentException

Thrown if any of the buffers are not exactly 32 bytes.

NegateScalar(SecureMemory<byte>, SecureMemory<byte>)

Computes the additive inverse of a scalar modulo the Ristretto255 group order: resultScalar = -inputScalar.

public static void NegateScalar(SecureMemory<byte> inputScalar, SecureMemory<byte> resultScalar)

Parameters

inputScalar SecureMemory<byte>

The scalar to negate (32 bytes).

resultScalar SecureMemory<byte>

The buffer to receive the negated scalar (32 bytes).

Exceptions

ArgumentException

Thrown if inputScalar or resultScalar is not exactly 32 bytes.

NegateScalar(ReadOnlySpan<byte>, Span<byte>)

Computes the additive inverse of a scalar modulo the Ristretto255 group order: resultScalar = -inputScalar.

public static void NegateScalar(ReadOnlySpan<byte> inputScalar, Span<byte> resultScalar)

Parameters

inputScalar ReadOnlySpan<byte>

The scalar to negate (32 bytes).

resultScalar Span<byte>

The buffer to receive the negated scalar (32 bytes).

Exceptions

ArgumentException

Thrown if inputScalar or resultScalar is not exactly 32 bytes.

ReduceScalar(SecureMemory<byte>, SecureMemory<byte>)

Reduces a 64-byte non-reduced scalar to a canonical 32-byte scalar modulo the Ristretto255 group order. This is typically used after hashing or key derivation to produce a valid private key.

public static void ReduceScalar(SecureMemory<byte> nonReducedScalar, SecureMemory<byte> resultScalar)

Parameters

nonReducedScalar SecureMemory<byte>

The 64-byte input scalar to reduce (typically secret).

resultScalar SecureMemory<byte>

The buffer to receive the reduced scalar (also secret, 32 bytes).

Exceptions

ArgumentException

Thrown if the input or output buffers have incorrect length.

LibSodiumException

Thrown if the operation fails internally.

ReduceScalar(ReadOnlySpan<byte>, Span<byte>)

Reduces a 64-byte non-reduced scalar to a canonical 32-byte scalar modulo the Ristretto255 group order. This is typically used after hashing to produce a valid private key.

public static void ReduceScalar(ReadOnlySpan<byte> nonReducedScalar, Span<byte> resultScalar)

Parameters

nonReducedScalar ReadOnlySpan<byte>

The 64-byte input scalar to reduce.

resultScalar Span<byte>

The buffer to receive the reduced scalar (32 bytes).

Exceptions

ArgumentException

Thrown if nonReducedScalar is not 64 bytes or resultScalar is not 32 bytes.

LibSodiumException

Thrown if the operation fails internally.

ScalarMultiply(SecureMemory<byte>, SecureMemory<byte>, SecureMemory<byte>)

Computes the scalar multiplication of a Ristretto255 point by a scalar: resultPoint = scalar * point.

public static void ScalarMultiply(SecureMemory<byte> scalar, SecureMemory<byte> point, SecureMemory<byte> resultPoint)

Parameters

scalar SecureMemory<byte>

The scalar to multiply (32 bytes).

point SecureMemory<byte>

The Ristretto255 point to multiply (32 bytes).

resultPoint SecureMemory<byte>

The buffer to receive the resulting point (32 bytes).

Exceptions

ArgumentException

Thrown if scalar, point, or resultPoint do not have the correct length.

LibSodiumException

Thrown if the operation fails internally.

ScalarMultiply(SecureMemory<byte>, ReadOnlySpan<byte>, SecureMemory<byte>)

Computes the scalar multiplication of a Ristretto255 point by a scalar: resultPoint = scalar * point.

public static void ScalarMultiply(SecureMemory<byte> scalar, ReadOnlySpan<byte> point, SecureMemory<byte> resultPoint)

Parameters

scalar SecureMemory<byte>

The scalar to multiply (32 bytes).

point ReadOnlySpan<byte>

The Ristretto255 point to multiply (32 bytes).

resultPoint SecureMemory<byte>

The buffer to receive the resulting point (32 bytes).

Exceptions

ArgumentException

Thrown if scalar, point, or resultPoint do not have the correct length.

LibSodiumException

Thrown if the operation fails internally.

ScalarMultiply(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)

Computes the scalar multiplication of a Ristretto255 point by a scalar: resultPoint = scalar * point.

public static void ScalarMultiply(ReadOnlySpan<byte> scalar, ReadOnlySpan<byte> point, Span<byte> resultPoint)

Parameters

scalar ReadOnlySpan<byte>

The scalar to multiply (32 bytes).

point ReadOnlySpan<byte>

The Ristretto255 point to multiply (32 bytes).

resultPoint Span<byte>

The buffer to receive the resulting point (32 bytes).

Exceptions

ArgumentException

Thrown if scalar, point, or resultPoint do not have the correct length.

LibSodiumException

Thrown if the operation fails internally.

ScalarMultiplyBase(SecureMemory<byte>, Span<byte>)

Computes the scalar multiplication of the Ristretto255 base point by a scalar: resultPoint = scalar * base_point. Typically used to derive a public key from a private scalar.

public static void ScalarMultiplyBase(SecureMemory<byte> scalar, Span<byte> resultPoint)

Parameters

scalar SecureMemory<byte>

The private scalar (32 bytes).

resultPoint Span<byte>

The buffer to receive the resulting point (32 bytes).

Exceptions

ArgumentException

Thrown if scalar or resultPoint do not have the correct length.

LibSodiumException

Thrown if the operation fails internally.

ScalarMultiplyBase(ReadOnlySpan<byte>, Span<byte>)

Computes the scalar multiplication of the Ristretto255 base point by a scalar: resultPoint = scalar * base_point. Typically used to derive a public key from a private scalar.

public static void ScalarMultiplyBase(ReadOnlySpan<byte> scalar, Span<byte> resultPoint)

Parameters

scalar ReadOnlySpan<byte>

The scalar to multiply (32 bytes). This is typically a private key.

resultPoint Span<byte>

The buffer to receive the resulting point (32 bytes). This is typically the corresponding public key.

Exceptions

ArgumentException

Thrown if scalar or resultPoint do not have the correct length.

LibSodiumException

Thrown if the operation fails internally.

SubtractPoints(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)

Subtracts one Ristretto255 point from another: resultPoint = point1 - point2.

public static void SubtractPoints(ReadOnlySpan<byte> point1, ReadOnlySpan<byte> point2, Span<byte> resultPoint)

Parameters

point1 ReadOnlySpan<byte>

The point to subtract from (32 bytes).

point2 ReadOnlySpan<byte>

The point to subtract (32 bytes).

resultPoint Span<byte>

The buffer to receive the result (32 bytes).

Exceptions

ArgumentException

Thrown if any buffer is not exactly 32 bytes.

LibSodiumException

Thrown if the operation fails internally.

SubtractScalars(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)

Subtracts one scalar from another modulo the Ristretto255 group order: resultScalar = scalar1 - scalar2.

public static void SubtractScalars(ReadOnlySpan<byte> scalar1, ReadOnlySpan<byte> scalar2, Span<byte> resultScalar)

Parameters

scalar1 ReadOnlySpan<byte>

The scalar to subtract from (32 bytes).

scalar2 ReadOnlySpan<byte>

The scalar to subtract (32 bytes).

resultScalar Span<byte>

The buffer to receive the result (32 bytes).

Exceptions

ArgumentException

Thrown if any of the buffers are not exactly 32 bytes.