libsodium_crypto_scalarmult_ed25519 (libsodium v3.0.1)

View Source

Point multiplication on the Edwards25519 curve, for building custom protocols.

Points are bytes/0 byte encodings and scalars are scalarbytes/0 bytes (little-endian). crypto_scalarmult_ed25519/2 and base/1 clamp the scalar like X25519; noclamp/2 and base_noclamp/1 use it as is (reduced modulo the group order).

These functions return -1 when the input point is invalid or of small order, or when the result is the identity element (for example with a zero scalar).

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

Summary

Types

n()

A crypto_scalarmult_ed25519_SCALARBYTES (32-byte) binary.

p()

A crypto_scalarmult_ed25519_BYTES (32-byte) binary.

q()

A crypto_scalarmult_ed25519_BYTES (32-byte) binary.

Functions

Multiply the base point by the clamped scalar N. Returns -1 when N is zero.

Multiply the base point by the scalar N without clamping. Returns -1 when the result is the identity.

Return crypto_scalarmult_ed25519_bytes(), in bytes.

Multiply the point P by the clamped scalar N. Returns -1 when P is invalid or of small order, or when the result is the identity.

Multiply the point P by the scalar N without clamping. Returns -1 when P is invalid or of small order, or when the result is the identity.

Return crypto_scalarmult_ed25519_scalarbytes(), in bytes.

Types

n()

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

A crypto_scalarmult_ed25519_SCALARBYTES (32-byte) binary.

p()

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

A crypto_scalarmult_ed25519_BYTES (32-byte) binary.

q()

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

A crypto_scalarmult_ed25519_BYTES (32-byte) binary.

Functions

base(N)

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

Multiply the base point by the clamped scalar N. Returns -1 when N is zero.

base_noclamp(N)

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

Multiply the base point by the scalar N without clamping. Returns -1 when the result is the identity.

bytes()

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

Return crypto_scalarmult_ed25519_bytes(), in bytes.

crypto_scalarmult_ed25519(N, P)

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

Multiply the point P by the clamped scalar N. Returns -1 when P is invalid or of small order, or when the result is the identity.

noclamp(N, P)

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

Multiply the point P by the scalar N without clamping. Returns -1 when P is invalid or of small order, or when the result is the identity.

scalarbytes()

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

Return crypto_scalarmult_ed25519_scalarbytes(), in bytes.