libsodium_crypto_scalarmult (libsodium v3.0.1)
View SourceElliptic curve point multiplication with the default primitive, X25519.
base/1 computes a bytes/0 byte public key from a scalarbytes/0 byte
secret key, and crypto_scalarmult/2 computes a shared secret from a
secret key and another party's public key.
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:scalarbytes()),
BobSK = libsodium_randombytes:buf(libsodium_crypto_scalarmult:scalarbytes()),
AlicePK = libsodium_crypto_scalarmult:base(AliceSK),
BobPK = libsodium_crypto_scalarmult:base(BobSK),
Shared = libsodium_crypto_scalarmult:crypto_scalarmult(AliceSK, BobPK),
Shared = libsodium_crypto_scalarmult:crypto_scalarmult(BobSK, AlicePK).
Summary
Types
A crypto_scalarmult_SCALARBYTES (32-byte) binary.
A crypto_scalarmult_BYTES (32-byte) binary.
A crypto_scalarmult_BYTES (32-byte) binary.
Functions
Compute the public key for the secret scalar N by multiplying the
base point. Returns -1 on failure.
Return crypto_scalarmult_bytes(), in bytes.
Multiply the point P by the secret scalar N, producing a shared
secret. Returns -1 when P is a low-order point.
Return crypto_scalarmult_primitive() as an atom.
Return crypto_scalarmult_scalarbytes(), in bytes.
Types
Functions
Compute the public key for the secret scalar N by multiplying the
base point. Returns -1 on failure.
-spec bytes() -> Result when Result :: 32.
Return crypto_scalarmult_bytes(), in bytes.
Multiply the point P by the secret scalar N, producing a shared
secret. Returns -1 when P is a low-order point.
-spec primitive() -> Result when Result :: curve25519.
Return crypto_scalarmult_primitive() as an atom.
-spec scalarbytes() -> Result when Result :: 32.
Return crypto_scalarmult_scalarbytes(), in bytes.