Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ECC: Curve25519 (X25519 ECDH + Ed25519 EdDSA) over EVP

Macros

#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.
#define N_ECC_KEY_LEN   32
 raw X25519/Ed25519 key length in bytes
#define N_ECC_SIG_LEN   64
 Ed25519 signature length in bytes.

Functions

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.
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_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_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_x25519_keypair (unsigned char *priv, unsigned char *pub)
 generate an X25519 keypair as N_ECC_KEY_LEN-byte raw private and public keys.

Detailed Description

Macro Definition Documentation

◆ 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.

Definition at line 57 of file n_ecc.h.

◆ N_ECC_KEY_LEN

#define N_ECC_KEY_LEN   32

raw X25519/Ed25519 key length in bytes

Examples
ex_ecc.c.

Definition at line 46 of file n_ecc.h.

Referenced by main().

◆ N_ECC_SIG_LEN

#define N_ECC_SIG_LEN   64

Ed25519 signature length in bytes.

Examples
ex_ecc.c.

Definition at line 48 of file n_ecc.h.

Referenced by main().

Function Documentation

◆ 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.

Definition at line 197 of file n_ecc.c.

References LOG_ERR, and n_log.

Referenced by main().

Here is the caller graph for this 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.

Definition at line 212 of file n_ecc.c.

References LOG_ERR, and n_log.

Referenced by main().

Here is the caller graph for this 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.

Definition at line 221 of file n_ecc.c.

References LOG_ERR, and n_log.

Referenced by main().

Here is the caller graph for this 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.

Definition at line 204 of file n_ecc.c.

References LOG_ERR, and n_log.

Referenced by main().

Here is the caller graph for this 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.

Definition at line 190 of file n_ecc.c.

References LOG_ERR, and n_log.

Referenced by main().

Here is the caller graph for this function: