libsodium_crypto_sign_ed25519 (libsodium v3.0.1)

View Source

Ed25519 signatures (RFC 8032), plus conversions between Ed25519 and X25519 (Curve25519) keys.

Public keys are publickeybytes/0 bytes; secret keys are secretkeybytes/0 bytes, made of the seedbytes/0 byte seed followed by the public key (sk_to_seed/1 and sk_to_pk/1 extract them). Signatures are bytes/0 bytes and deterministic.

pk_to_curve25519/1 and sk_to_curve25519/1 convert a signing key pair into an X25519 key pair for libsodium_crypto_scalarmult_curve25519 or libsodium_crypto_box; reusing one key for both purposes is generally discouraged. The streaming functions compute Ed25519ph (pre-hashed) signatures and are the same as those in libsodium_crypto_sign_ed25519ph.

Seed = libsodium_randombytes:buf(libsodium_crypto_sign_ed25519:seedbytes()),
{PK, SK} = libsodium_crypto_sign_ed25519:seed_keypair(Seed),
Seed = libsodium_crypto_sign_ed25519:sk_to_seed(SK),
PK = libsodium_crypto_sign_ed25519:sk_to_pk(SK),
Sig = libsodium_crypto_sign_ed25519:detached(<<"message">>, SK),
0 = libsodium_crypto_sign_ed25519:verify_detached(Sig, <<"message">>, PK).

Summary

Types

A crypto_scalarmult_curve25519_BYTES (32-byte) binary.

A crypto_scalarmult_curve25519_BYTES (32-byte) binary.

A crypto_sign_ed25519_PUBLICKEYBYTES (32-byte) binary.

A crypto_sign_ed25519_SECRETKEYBYTES (64-byte) binary.

A crypto_sign_ed25519_PUBLICKEYBYTES (32-byte) binary.

A crypto_sign_ed25519_SEEDBYTES (32-byte) binary.

A crypto_sign_ed25519_BYTES (64-byte) binary.

A crypto_sign_ed25519_SECRETKEYBYTES (64-byte) binary.

An opaque native crypto_sign_ed25519ph_state.

Functions

Return crypto_sign_ed25519_bytes(), in bytes.

Sign M with the secret key SK, returning the bytes/0 byte signature followed by the message.

Sign M with the secret key SK, returning only the bytes/0 byte signature.

Finish the streaming message in State and sign it with the secret key SK, returning the bytes/0 byte Ed25519ph signature.

Finish the streaming message in State and verify its Ed25519ph signature Sig with the public key PK. Returns 0 when the signature is valid and -1 otherwise.

Start a streaming Ed25519ph signature, returning a new state. Same as libsodium_crypto_sign_ed25519ph:init/0.

Generate a random key pair. Returns {PK, SK}.

Return crypto_sign_ed25519_messagebytes_max(), in bytes.

Verify the signed message SM with the public key PK and return the message without its signature, or -1 when the signature is invalid.

Convert the Ed25519 public key Ed25519PK into an X25519 public key. Returns -1 when the key is not a valid point of prime order (for example a small-order point).

Return crypto_sign_ed25519_publickeybytes(), in bytes.

Return crypto_sign_ed25519_secretkeybytes(), in bytes.

Deterministically derive a key pair from the seedbytes/0 byte Seed. Returns {PK, SK}.

Return crypto_sign_ed25519_seedbytes(), in bytes.

Convert the Ed25519 secret key Ed25519SK into an X25519 secret key.

Extract the publickeybytes/0 byte public key from the secret key SK.

Extract the seedbytes/0 byte seed from the secret key SK.

Return crypto_sign_ed25519ph_statebytes(), the size of a streaming state, in bytes.

Absorb the message chunk M into State and return the updated state.

Verify the detached signature Sig of M with the public key PK. Returns 0 when the signature is valid and -1 otherwise.

Types

curve25519_pk()

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

A crypto_scalarmult_curve25519_BYTES (32-byte) binary.

curve25519_sk()

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

A crypto_scalarmult_curve25519_BYTES (32-byte) binary.

ed25519_pk()

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

A crypto_sign_ed25519_PUBLICKEYBYTES (32-byte) binary.

ed25519_sk()

-type ed25519_sk() :: <<_:512>>.

A crypto_sign_ed25519_SECRETKEYBYTES (64-byte) binary.

pk()

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

A crypto_sign_ed25519_PUBLICKEYBYTES (32-byte) binary.

seed()

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

A crypto_sign_ed25519_SEEDBYTES (32-byte) binary.

sig()

-type sig() :: <<_:512>>.

A crypto_sign_ed25519_BYTES (64-byte) binary.

sk()

-type sk() :: <<_:512>>.

A crypto_sign_ed25519_SECRETKEYBYTES (64-byte) binary.

state()

An opaque native crypto_sign_ed25519ph_state.

Operations never modify a state: each returns a new one, so earlier states remain valid and can be reused or shared between processes. States cannot be serialized; they exist only within the running VM.

Functions

bytes()

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

Return crypto_sign_ed25519_bytes(), in bytes.

crypto_sign_ed25519(M, SK)

-spec crypto_sign_ed25519(M, SK) -> Result when M :: binary(), SK :: sk(), Result :: binary() | -1.

Sign M with the secret key SK, returning the bytes/0 byte signature followed by the message.

detached(M, SK)

-spec detached(M, SK) -> Result when M :: binary(), SK :: sk(), Result :: sig() | -1.

Sign M with the secret key SK, returning only the bytes/0 byte signature.

final_create(State, SK)

-spec final_create(State, SK) -> Result when State :: state(), SK :: sk(), Result :: sig() | -1.

Finish the streaming message in State and sign it with the secret key SK, returning the bytes/0 byte Ed25519ph signature.

final_verify(State, Sig, PK)

-spec final_verify(State, Sig, PK) -> Result
                      when State :: state(), Sig :: sig(), PK :: pk(), Result :: 0 | -1.

Finish the streaming message in State and verify its Ed25519ph signature Sig with the public key PK. Returns 0 when the signature is valid and -1 otherwise.

init()

-spec init() -> Result when Result :: state() | -1.

Start a streaming Ed25519ph signature, returning a new state. Same as libsodium_crypto_sign_ed25519ph:init/0.

keypair()

-spec keypair() -> Result when Result :: {pk(), sk()} | -1.

Generate a random key pair. Returns {PK, SK}.

messagebytes_max()

-spec messagebytes_max() -> Result when Result :: non_neg_integer().

Return crypto_sign_ed25519_messagebytes_max(), in bytes.

open(SM, PK)

-spec open(SM, PK) -> Result when SM :: binary(), PK :: pk(), Result :: binary() | -1.

Verify the signed message SM with the public key PK and return the message without its signature, or -1 when the signature is invalid.

pk_to_curve25519(Ed25519PK)

-spec pk_to_curve25519(Ed25519PK) -> Result
                          when Ed25519PK :: ed25519_pk(), Result :: curve25519_pk() | -1.

Convert the Ed25519 public key Ed25519PK into an X25519 public key. Returns -1 when the key is not a valid point of prime order (for example a small-order point).

publickeybytes()

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

Return crypto_sign_ed25519_publickeybytes(), in bytes.

secretkeybytes()

-spec secretkeybytes() -> Result when Result :: 64.

Return crypto_sign_ed25519_secretkeybytes(), in bytes.

seed_keypair(Seed)

-spec seed_keypair(Seed) -> Result when Seed :: seed(), Result :: {pk(), sk()} | -1.

Deterministically derive a key pair from the seedbytes/0 byte Seed. Returns {PK, SK}.

seedbytes()

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

Return crypto_sign_ed25519_seedbytes(), in bytes.

sk_to_curve25519(Ed25519SK)

-spec sk_to_curve25519(Ed25519SK) -> Result
                          when Ed25519SK :: ed25519_sk(), Result :: curve25519_sk() | -1.

Convert the Ed25519 secret key Ed25519SK into an X25519 secret key.

sk_to_pk(SK)

-spec sk_to_pk(SK) -> Result when SK :: sk(), Result :: pk() | -1.

Extract the publickeybytes/0 byte public key from the secret key SK.

sk_to_seed(SK)

-spec sk_to_seed(SK) -> Result when SK :: sk(), Result :: seed() | -1.

Extract the seedbytes/0 byte seed from the secret key SK.

statebytes()

-spec statebytes() -> Result when Result :: 208.

Return crypto_sign_ed25519ph_statebytes(), the size of a streaming state, in bytes.

update(State, M)

-spec update(State, M) -> Result when State :: state(), M :: binary(), Result :: state() | -1.

Absorb the message chunk M into State and return the updated state.

verify_detached(Sig, M, PK)

-spec verify_detached(Sig, M, PK) -> Result
                         when Sig :: sig(), M :: binary(), PK :: pk(), Result :: 0 | -1.

Verify the detached signature Sig of M with the public key PK. Returns 0 when the signature is valid and -1 otherwise.