libsodium_crypto_scalarmult_ristretto255 (libsodium v3.0.1)

View Source

Point multiplication in the Ristretto255 prime-order group, for building custom protocols.

Elements are bytes/0 byte encodings and scalars are scalarbytes/0 bytes (little-endian, not clamped). Unlike Ed25519, every valid encoding represents an element of a prime-order group, so there are no small-order points to reject.

Both functions return -1 when the input element is invalid or when the result is the identity element (for example with a zero scalar).

Mod = libsodium_crypto_scalarmult_ristretto255,
A = libsodium_randombytes:buf(Mod:scalarbytes()),
B = libsodium_randombytes:buf(Mod:scalarbytes()),
PA = Mod:base(A),
PB = Mod:base(B),
Shared = Mod:crypto_scalarmult_ristretto255(A, PB),
Shared = Mod:crypto_scalarmult_ristretto255(B, PA).

Summary

Types

n()

A crypto_scalarmult_ristretto255_SCALARBYTES (32-byte) binary.

p()

A crypto_scalarmult_ristretto255_BYTES (32-byte) binary.

q()

A crypto_scalarmult_ristretto255_BYTES (32-byte) binary.

Functions

Multiply the generator by the scalar N. Returns -1 when the result is the identity.

Return crypto_scalarmult_ristretto255_bytes(), in bytes.

Multiply the element P by the scalar N. Returns -1 when P is not a valid encoding or when the result is the identity.

Return crypto_scalarmult_ristretto255_scalarbytes(), in bytes.

Types

n()

-type n() :: <<_:256>>.

A crypto_scalarmult_ristretto255_SCALARBYTES (32-byte) binary.

p()

-type p() :: <<_:256>>.

A crypto_scalarmult_ristretto255_BYTES (32-byte) binary.

q()

-type q() :: <<_:256>>.

A crypto_scalarmult_ristretto255_BYTES (32-byte) binary.

Functions

base(N)

-spec base(N) -> Result when N :: n(), Result :: q() | -1.

Multiply the generator by the scalar N. Returns -1 when the result is the identity.

bytes()

-spec bytes() -> Result when Result :: 32.

Return crypto_scalarmult_ristretto255_bytes(), in bytes.

crypto_scalarmult_ristretto255(N, P)

-spec crypto_scalarmult_ristretto255(N, P) -> Result when N :: n(), P :: p(), Result :: q() | -1.

Multiply the element P by the scalar N. Returns -1 when P is not a valid encoding or when the result is the identity.

scalarbytes()

-spec scalarbytes() -> Result when Result :: 32.

Return crypto_scalarmult_ristretto255_scalarbytes(), in bytes.