libsodium_crypto_scalarmult_curve25519 (libsodium v3.0.1)

View Source

X25519 (RFC 7748) point multiplication on Curve25519.

base/1 computes a bytes/0 byte public key from a scalarbytes/0 byte secret key, and crypto_scalarmult_curve25519/2 computes a shared secret from a secret key and another party's public key. Scalars are clamped.

Do not use the shared secret directly as a key: hash it together with both public keys, or use libsodium_crypto_kx instead.

AliceSK = libsodium_randombytes:buf(libsodium_crypto_scalarmult_curve25519:scalarbytes()),
BobSK = libsodium_randombytes:buf(libsodium_crypto_scalarmult_curve25519:scalarbytes()),
AlicePK = libsodium_crypto_scalarmult_curve25519:base(AliceSK),
BobPK = libsodium_crypto_scalarmult_curve25519:base(BobSK),
Shared = libsodium_crypto_scalarmult_curve25519:crypto_scalarmult_curve25519(AliceSK, BobPK),
Shared = libsodium_crypto_scalarmult_curve25519:crypto_scalarmult_curve25519(BobSK, AlicePK).

Summary

Types

n()

A crypto_scalarmult_curve25519_SCALARBYTES (32-byte) binary.

p()

A crypto_scalarmult_curve25519_BYTES (32-byte) binary.

q()

A crypto_scalarmult_curve25519_BYTES (32-byte) binary.

Functions

Compute the public key for the clamped secret scalar N by multiplying the base point. Returns -1 on failure.

Return crypto_scalarmult_curve25519_bytes(), in bytes.

Multiply the point P by the clamped secret scalar N, producing a shared secret. Returns -1 when P is a low-order point.

Return crypto_scalarmult_curve25519_scalarbytes(), in bytes.

Types

n()

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

A crypto_scalarmult_curve25519_SCALARBYTES (32-byte) binary.

p()

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

A crypto_scalarmult_curve25519_BYTES (32-byte) binary.

q()

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

A crypto_scalarmult_curve25519_BYTES (32-byte) binary.

Functions

base(N)

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

Compute the public key for the clamped secret scalar N by multiplying the base point. Returns -1 on failure.

bytes()

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

Return crypto_scalarmult_curve25519_bytes(), in bytes.

crypto_scalarmult_curve25519(N, P)

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

Multiply the point P by the clamped secret scalar N, producing a shared secret. Returns -1 when P is a low-order point.

scalarbytes()

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

Return crypto_scalarmult_curve25519_scalarbytes(), in bytes.