5 Module N_ECC
gullradriel edited this page 2026-10-09 00:55:18 +02:00

ECC: Curve25519 (X25519 ECDH + Ed25519 EdDSA) over EVP

Functions

Name
int n_x25519_keypair(unsigned char * priv, unsigned char * pub)
generate an X25519 keypair as N_ECC_KEY_LEN-byte raw private and public keys.
int n_x25519_derive(const unsigned char * priv, const unsigned char * peer_pub, unsigned char * shared)
X25519 ECDH: derive the N_ECC_KEY_LEN-byte shared secret from our raw private key and the peer's raw public key.
int n_ed25519_verify(const unsigned char * pub, const unsigned char * msg, size_t len, const unsigned char * sig)
Ed25519 verify the N_ECC_SIG_LEN-byte sig over len bytes of msg under the N_ECC_KEY_LEN-byte raw public key.
int n_ed25519_sign(const unsigned char * priv, const unsigned char * msg, size_t len, unsigned char * sig)
Ed25519 sign len bytes of msg with the N_ECC_KEY_LEN-byte raw private key into sig (N_ECC_SIG_LEN bytes).
int n_ed25519_keypair(unsigned char * priv, unsigned char * pub)
generate an Ed25519 keypair as N_ECC_KEY_LEN-byte raw private and public keys.

Defines

Name
N_ECC_SIG_LEN
Ed25519 signature length in bytes.
N_ECC_KEY_LEN
raw X25519/Ed25519 key length in bytes
N_ECC_AVAILABLE
1 when the linked library provides Curve25519 through the raw-key EVP API (OpenSSL 1.1.1+, LibreSSL 3.7+), 0 otherwise.

Functions Documentation

function n_x25519_keypair

int n_x25519_keypair(
    unsigned char * priv,
    unsigned char * pub
)

generate an X25519 keypair as N_ECC_KEY_LEN-byte raw private and public keys.

Returns 0 on success, -1 on error.

function n_x25519_derive

int n_x25519_derive(
    const unsigned char * priv,
    const unsigned char * peer_pub,
    unsigned char * shared
)

X25519 ECDH: derive the N_ECC_KEY_LEN-byte shared secret from our raw private key and the peer's raw public key.

Returns 0 on success, -1 on error.

function n_ed25519_verify

int n_ed25519_verify(
    const unsigned char * pub,
    const unsigned char * msg,
    size_t len,
    const unsigned char * sig
)

Ed25519 verify the N_ECC_SIG_LEN-byte sig over len bytes of msg under the N_ECC_KEY_LEN-byte raw public key.

Returns 0 if the signature is valid, -1 otherwise.

function n_ed25519_sign

int n_ed25519_sign(
    const unsigned char * priv,
    const unsigned char * msg,
    size_t len,
    unsigned char * sig
)

Ed25519 sign len bytes of msg with the N_ECC_KEY_LEN-byte raw private key into sig (N_ECC_SIG_LEN bytes).

Returns 0 on success, -1 on error.

function n_ed25519_keypair

int n_ed25519_keypair(
    unsigned char * priv,
    unsigned char * pub
)

generate an Ed25519 keypair as N_ECC_KEY_LEN-byte raw private and public keys.

Returns 0 on success, -1 on error.

Macros Documentation

define N_ECC_SIG_LEN

#define N_ECC_SIG_LEN 64

Ed25519 signature length in bytes.

define N_ECC_KEY_LEN

#define N_ECC_KEY_LEN 32

raw X25519/Ed25519 key length in bytes

define N_ECC_AVAILABLE

#define N_ECC_AVAILABLE N_OSSL_HAVE_RAW_EVP_25519

1 when the linked library provides Curve25519 through the raw-key EVP API (OpenSSL 1.1.1+, LibreSSL 3.7+), 0 otherwise.

This one still builds against OpenSSL 1.0.2, which has neither EVP_PKEY_X25519/EVP_PKEY_ED25519 nor EVP_PKEY_new_raw_*_key(); there every entry point below compiles to a logged failure returning -1, so callers still link and can skip the call on this test. The threshold lives in n_openssl_compat.h, which knows that OPENSSL_VERSION_NUMBER is a fixed compatibility value under LibreSSL.