Table of Contents

Class CryptoScalarMult

Namespace
LibSodium
Assembly
LibSodium.Net.dll

Provides low-level scalar multiplication on Curve25519. This class exposes the crypto_scalarmult and crypto_scalarmult_base functions from libsodium.

public static class CryptoScalarMult
Inheritance
CryptoScalarMult
Inherited Members

Fields

PrivateKeyLen

Length of a Curve25519 private key (scalar) in bytes (32).

public const int PrivateKeyLen = 32

Field Value

int

PublicKeyLen

Length of a Curve25519 public key (point) in bytes (32).

public const int PublicKeyLen = 32

Field Value

int

SharedPointLen

Represents the length, in bytes, of a shared point in cryptographic operations (32).

public const int SharedPointLen = 32

Field Value

int

Remarks

The shared point length is equivalent to the length of a public key, which is 32 bytes. This constant can be used to validate or configure cryptographic processes that involve shared points.

Methods

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

Computes the public key corresponding to a private scalar on Curve25519.

public static void CalculatePublicKey(Span<byte> publicKey, SecureMemory<byte> privateKey)

Parameters

publicKey Span<byte>

The output buffer where the public key (32 bytes) will be stored.

privateKey SecureMemory<byte>

The private scalar (32 bytes).

Remarks

This method wraps crypto_scalarmult_base.

Exceptions

ArgumentException

Thrown if any buffer has incorrect length.

LibSodiumException

Thrown if the operation fails.

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

Computes the public key corresponding to a private scalar on Curve25519.

public static void CalculatePublicKey(Span<byte> publicKey, ReadOnlySpan<byte> privateKey)

Parameters

publicKey Span<byte>

The output buffer where the public key (32 bytes) will be stored.

privateKey ReadOnlySpan<byte>

The private scalar (32 bytes).

Remarks

This method wraps crypto_scalarmult_base.

Exceptions

ArgumentException

Thrown if any buffer has incorrect length.

LibSodiumException

Thrown if the operation fails.

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

Computes the scalar multiplication of a private scalar and a public point on Curve25519.

public static void Compute(SecureMemory<byte> sharedPoint, SecureMemory<byte> privateKey, ReadOnlySpan<byte> publicKey)

Parameters

sharedPoint SecureMemory<byte>

The output buffer where the result (32 bytes) will be stored.

privateKey SecureMemory<byte>

The private scalar (32 bytes).

publicKey ReadOnlySpan<byte>

The public point (32 bytes).

Remarks

This method wraps crypto_scalarmult. Do not use the output directly as a symmetric key.

Exceptions

ArgumentException

Thrown if any input or output buffer has incorrect length.

LibSodiumException

Thrown if the operation fails.

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

Computes the scalar multiplication of a private scalar and a public point on Curve25519.

public static void Compute(Span<byte> sharedPoint, ReadOnlySpan<byte> privateKey, ReadOnlySpan<byte> publicKey)

Parameters

sharedPoint Span<byte>

The output buffer where the result (32 bytes) will be stored.

privateKey ReadOnlySpan<byte>

The private scalar (32 bytes).

publicKey ReadOnlySpan<byte>

The public point (32 bytes).

Remarks

This method wraps crypto_scalarmult. Do not use the output directly as a symmetric key.

Exceptions

ArgumentException

Thrown if any input or output buffer has incorrect length.

LibSodiumException

Thrown if the operation fails.