Snarkey.Crypto (snarkey v0.1.0)

Copy Markdown View Source

Low-level cryptographic primitives for the Schnorr ZKP protocol.

Provides modular exponentiation, hash-to-scalar conversion, and compile-time safe default parameters (2048-bit safe prime from RFC 3526).

Summary

Functions

Returns the default 2048-bit Schnorr group parameters.

Computes SHA-256 of data and maps the digest to an integer in [1, q-1].

Computes base^exp mod mod using Erlang's NIF-backed modular exponentiation.

Functions

default_params()

Returns the default 2048-bit Schnorr group parameters.

  • p: 2048-bit safe prime (RFC 3526 MODP group)
  • g: generator 2
  • q: subgroup order (p-1)/2

Examples

iex> params = Snarkey.Crypto.default_params()
iex> params.p |> is_integer()
true
iex> params.g
2
iex> params.q |> is_integer()
true

hash_to_scalar(data, q)

Computes SHA-256 of data and maps the digest to an integer in [1, q-1].

The hash is interpreted as a big-endian unsigned integer, then reduced modulo q-1 and incremented by 1 to ensure a non-zero result.

Examples

iex> q = Snarkey.Crypto.default_params().q
iex> result = Snarkey.Crypto.hash_to_scalar("hello", q)
iex> is_integer(result)
true
iex> result > 0
true
iex> result < q
true

mod_pow(base, exp, mod)

Computes base^exp mod mod using Erlang's NIF-backed modular exponentiation.

Accepts integers (converts to binaries for OTP :crypto.mod_pow/3).