71 lines
3.3 KiB
C
71 lines
3.3 KiB
C
#pragma once
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
/* --- secp256k1 (Nostr, existing) --- */
|
|
int derive_nostr_key(const uint8_t seed[64], uint8_t privkey[32], uint8_t pubkey[32]);
|
|
int derive_nostr_key_index(const uint8_t seed[64], uint32_t nostr_index, uint8_t privkey[32], uint8_t pubkey[32]);
|
|
int schnorr_sign32(const uint8_t privkey[32], const uint8_t msg32[32], uint8_t sig64[64]);
|
|
|
|
/* --- ed25519 (SSH signatures) --- */
|
|
/* Derives an ed25519 keypair from the mnemonic seed using SLIP-0010
|
|
* all-hardened derivation: m/44'/102001'/<n>'/0'/0'
|
|
* privkey: 32-byte ed25519 private scalar
|
|
* pubkey: 32-byte ed25519 public key
|
|
* Returns 0 on success, -1 on error. */
|
|
int derive_ed25519_key(const uint8_t seed[64], uint32_t index,
|
|
uint8_t privkey[32], uint8_t pubkey[32]);
|
|
|
|
/* Signs a 32-byte message digest with ed25519 (PureEdDSA, raw message).
|
|
* sig: 64-byte ed25519 signature
|
|
* Returns 0 on success, -1 on error. */
|
|
int ed25519_sign32(const uint8_t privkey[32], const uint8_t msg32[32],
|
|
uint8_t sig64[64]);
|
|
|
|
/* Signs a variable-length message with ed25519 (PureEdDSA). */
|
|
int ed25519_sign_msg(const uint8_t privkey[32], const uint8_t *msg, size_t msg_len,
|
|
uint8_t sig64[64]);
|
|
|
|
/* Verifies an ed25519 signature over a variable-length message. */
|
|
int ed25519_verify_msg(const uint8_t *sig, size_t sig_len,
|
|
const uint8_t *msg, size_t msg_len,
|
|
const uint8_t pubkey[32]);
|
|
|
|
/* --- x25519 (age encryption / key agreement) --- */
|
|
/* Derives an x25519 keypair from the mnemonic seed using SLIP-0010
|
|
* all-hardened derivation: m/44'/102002'/<n>'/0'/0'
|
|
* privkey: 32-byte x25519 private scalar
|
|
* pubkey: 32-byte x25519 public key
|
|
* Returns 0 on success, -1 on error. */
|
|
int derive_x25519_key(const uint8_t seed[64], uint32_t index,
|
|
uint8_t privkey[32], uint8_t pubkey[32]);
|
|
|
|
/* --- ML-DSA-65 (post-quantum signatures, FIPS 204) --- */
|
|
/* Derives an ML-DSA-65 keypair from the mnemonic seed.
|
|
* Path: m/44'/102003'/<n>'/0'/0' -> 32-byte seed -> PQClean keygen
|
|
* pk: FW_ML_DSA_65_PUBKEY_LEN (1952) bytes — caller must allocate
|
|
* sk: FW_ML_DSA_65_PRIVKEY_LEN (4032) bytes — caller must allocate
|
|
* Returns 0 on success, -1 on error. */
|
|
int derive_ml_dsa_65_key(const uint8_t seed[64], uint32_t index,
|
|
uint8_t *pk, uint8_t *sk);
|
|
|
|
/* --- SLH-DSA-128s (post-quantum hash-based signatures, FIPS 205) --- */
|
|
/* Derives an SLH-DSA-128s keypair from the mnemonic seed.
|
|
* Path: m/44'/102004'/<n>'/0'/0' -> 32-byte seed -> PQClean keygen
|
|
* pk: FW_SLH_DSA_128S_PUBKEY_LEN (32) bytes
|
|
* sk: FW_SLH_DSA_128S_PRIVKEY_LEN (64) bytes
|
|
* WARNING: Takes 5-30 seconds on ESP32.
|
|
* Returns 0 on success, -1 on error. */
|
|
int derive_slh_dsa_128s_key(const uint8_t seed[64], uint32_t index,
|
|
uint8_t *pk, uint8_t *sk);
|
|
|
|
/* --- ML-KEM-768 (post-quantum KEM, FIPS 203) --- */
|
|
/* Derives an ML-KEM-768 keypair from the mnemonic seed.
|
|
* Path: m/44'/102005'/<n>'/0'/0' -> 32-byte seed -> PQClean keygen
|
|
* pk: FW_ML_KEM_768_PUBKEY_LEN (1184) bytes — caller must allocate
|
|
* sk: FW_ML_KEM_768_PRIVKEY_LEN (2400) bytes — caller must allocate
|
|
* Returns 0 on success, -1 on error. */
|
|
int derive_ml_kem_768_key(const uint8_t seed[64], uint32_t index,
|
|
uint8_t *pk, uint8_t *sk);
|