Ed25519 (Ed25519 v1.4.2)

View Source

Ed25519 signature functions

This is mostly suitable as part of a pure Elixir solution.

Configuration

No configuration is needed in most cases. However, if needed, a custom hash function can be configured. As per the specification - sha512 is the default.

config/config.exs

import Config

# The hash function will be invoked as 'Blake2.hash2b(payload, 16)'
config :ed25519,
  hash_fn: {Blake2, :hash2b, [], [16]}

# The hash function will be invoked as ':crypto.hash(:sha256, payload)'
config :ed25519,
  hash_fn: {:crypto, :hash, [:sha256], []}

Summary

Types

public or secret key

computed signature

Functions

derive the public signing key from the secret key

Generate a secret/public key pair

Generate a secret/public key pair from supplied secret

Returns whether a given key lies on the ed25519 curve.

Derive the x25519/curve25519 encryption key from the ed25519 signing key

validate a signed message

Types

key()

@type key() :: binary()

public or secret key

signature()

@type signature() :: binary()

computed signature

Functions

derive_public_key(sk)

@spec derive_public_key(key()) :: key()

derive the public signing key from the secret key

generate_key_pair()

@spec generate_key_pair() :: {key(), key()}

Generate a secret/public key pair

Returned tuple contains {random_secret_key, derived_public_key}

generate_key_pair(secret)

@spec generate_key_pair(key()) :: {key(), key()}

Generate a secret/public key pair from supplied secret

Returned tuple contains {secret_key, derived_public_key}

on_curve?(key)

@spec on_curve?(key()) :: boolean()

Returns whether a given key lies on the ed25519 curve.

signature(m, sk, pk \\ nil)

@spec signature(binary(), key(), key()) :: signature()

Sign a message

If only the secret key is provided, the public key will be derived therefrom. This adds significant overhead.

to_curve25519(key, which)

@spec to_curve25519(key(), atom()) :: key()

Derive the x25519/curve25519 encryption key from the ed25519 signing key

By converting an EdwardsPoint on the Edwards model to the corresponding MontgomeryPoint on the Montgomery model

Handles either :secret or :public keys as indicated in the call

May raise on an invalid input key or unknown atom

See: https://blog.filippo.io/using-ed25519-keys-for-encryption

valid_signature?(arg1, m, pk)

@spec valid_signature?(signature(), binary(), key()) :: boolean()

validate a signed message