libsodium_crypto_sign_ed25519 (libsodium v3.0.1)
View SourceEd25519 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
-type curve25519_pk() :: <<_:256>>.
A crypto_scalarmult_curve25519_BYTES (32-byte) binary.
-type curve25519_sk() :: <<_:256>>.
A crypto_scalarmult_curve25519_BYTES (32-byte) binary.
-type ed25519_pk() :: <<_:256>>.
A crypto_sign_ed25519_PUBLICKEYBYTES (32-byte) binary.
-type ed25519_sk() :: <<_:512>>.
A crypto_sign_ed25519_SECRETKEYBYTES (64-byte) binary.
-type pk() :: <<_:256>>.
A crypto_sign_ed25519_PUBLICKEYBYTES (32-byte) binary.
-type seed() :: <<_:256>>.
A crypto_sign_ed25519_SEEDBYTES (32-byte) binary.
-type sig() :: <<_:512>>.
A crypto_sign_ed25519_BYTES (64-byte) binary.
-type sk() :: <<_:512>>.
A crypto_sign_ed25519_SECRETKEYBYTES (64-byte) binary.
-type state() :: libsodium_nif:crypto_sign_ed25519ph_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
-spec bytes() -> Result when Result :: 64.
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.
-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.
-spec init() -> Result when Result :: state() | -1.
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}.
-spec messagebytes_max() -> Result when Result :: non_neg_integer().
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.
-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).
-spec publickeybytes() -> Result when Result :: 32.
Return crypto_sign_ed25519_publickeybytes(), in bytes.
-spec secretkeybytes() -> Result when Result :: 64.
Return crypto_sign_ed25519_secretkeybytes(), in bytes.
Deterministically derive a key pair from the seedbytes/0 byte Seed.
Returns {PK, SK}.
-spec seedbytes() -> Result when Result :: 32.
Return crypto_sign_ed25519_seedbytes(), in bytes.
-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.
Extract the publickeybytes/0 byte public key from the secret key SK.
Extract the seedbytes/0 byte seed from the secret key SK.
-spec statebytes() -> Result when Result :: 208.
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.
-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.