libsodium_crypto_sign_ed25519ph (libsodium v3.0.1)

View Source

Streaming Ed25519ph signatures (RFC 8032), where the message is pre-hashed with SHA-512 so it can be signed or verified in chunks.

init/0 returns an opaque state/0, which update/2 threads through the message; each call returns a new state and leaves its argument unchanged. Keys are the same as for libsodium_crypto_sign_ed25519, but Ed25519ph signatures are not interchangeable with plain Ed25519 signatures of the same message.

{PK, SK} = libsodium_crypto_sign_ed25519:keypair(),
State0 = libsodium_crypto_sign_ed25519ph:init(),
State1 = libsodium_crypto_sign_ed25519ph:update(State0, <<"hello ">>),
State2 = libsodium_crypto_sign_ed25519ph:update(State1, <<"world">>),
Sig = libsodium_crypto_sign_ed25519ph:final_create(State2, SK),
0 = libsodium_crypto_sign_ed25519ph:final_verify(State2, Sig, PK).

Summary

Types

A crypto_sign_ed25519_PUBLICKEYBYTES (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

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

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

Start a streaming Ed25519ph signature, returning a new state.

Return crypto_sign_ed25519ph_statebytes(), in bytes.

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

Types

pk()

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

A crypto_sign_ed25519_PUBLICKEYBYTES (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

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 Ed25519 secret key SK, returning a libsodium_crypto_sign_ed25519:bytes/0 byte 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 signature Sig with the Ed25519 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.

statebytes()

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

Return crypto_sign_ed25519ph_statebytes(), 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.