Skip to content

File syn_p256.h

FileList > crypto > syn_p256.h

Go to the source code of this file

NIST P-256 (secp256r1 / prime256v1) Elliptic Curve Cryptography. More...

  • #include "../common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Public Functions

Type Name
bool syn_p256_base_mul (const uint8_t scalar, uint8_t pub_x, uint8_t pub_y)
Multiply the P-256 base generator G by a 32-byte scalar.
bool syn_p256_ecdh (const uint8_t priv_key, const uint8_t peer_pub_x, const uint8_t peer_pub_y, uint8_t shared_secret)
Perform ECDH Key Agreement.
bool syn_p256_is_on_curve (const uint8_t px, const uint8_t py)
Validate if a point (x, y) lies on the NIST P-256 curve: y^2 = x^3 - 3x + b (mod p).
bool syn_p256_point_mul (const uint8_t scalar, const uint8_t px, const uint8_t py, uint8_t rx, uint8_t ry)
Multiply an arbitrary P-256 point by a 32-byte scalar.
bool syn_p256_sign_ecdsa (const uint8_t priv_key, const uint8_t nonce_k, const uint8_t hash, uint8_t r_out, uint8_t s_out)
Generate a NIST P-256 ECDSA signature (FIPS 186-4).
bool syn_p256_sign_ecdsa_deterministic (const uint8_t priv_key, const uint8_t hash, uint8_t r_out, uint8_t s_out)
Generate a deterministic NIST P-256 ECDSA signature (RFC 6979 / FIPS 186-4).
bool syn_p256_verify_ecdsa (const uint8_t hash, const uint8_t r, const uint8_t s, const uint8_t pub_x, const uint8_t pub_y)
Verify a NIST P-256 ECDSA signature (FIPS 186-4).

Macros

Type Name
define SYN_P256_BYTE_LEN 32U
NIST P-256 coordinate / scalar byte size (32 bytes).

Detailed Description

Provides zero-allocation, cleanroom NIST P-256 scalar multiplication, ECDH shared secret generation, and FIPS 186-4 ECDSA signature verification.

Public Functions Documentation

function syn_p256_base_mul

Multiply the P-256 base generator G by a 32-byte scalar.

bool syn_p256_base_mul (
    const uint8_t scalar,
    uint8_t pub_x,
    uint8_t pub_y
) 

Computes Q = scalar * G.

Parameters:

  • scalar 32-byte scalar in big-endian format.
  • pub_x [out] 32-byte X-coordinate of resulting point.
  • pub_y [out] 32-byte Y-coordinate of resulting point.

Returns:

true on success, false if scalar is 0 or >= curve order.


function syn_p256_ecdh

Perform ECDH Key Agreement.

bool syn_p256_ecdh (
    const uint8_t priv_key,
    const uint8_t peer_pub_x,
    const uint8_t peer_pub_y,
    uint8_t shared_secret
) 

Computes shared_secret = priv_key * peer_pub_point.

Parameters:

  • priv_key 32-byte private key scalar.
  • peer_pub_x 32-byte X-coordinate of peer's public key.
  • peer_pub_y 32-byte Y-coordinate of peer's public key.
  • shared_secret [out] 32-byte shared secret (X-coordinate of product point).

Returns:

true on success, false on invalid point or scalar.


function syn_p256_is_on_curve

Validate if a point (x, y) lies on the NIST P-256 curve: y^2 = x^3 - 3x + b (mod p).

bool syn_p256_is_on_curve (
    const uint8_t px,
    const uint8_t py
) 

Parameters:

  • px 32-byte X-coordinate.
  • py 32-byte Y-coordinate.

Returns:

true if point is on curve, false otherwise.


function syn_p256_point_mul

Multiply an arbitrary P-256 point by a 32-byte scalar.

bool syn_p256_point_mul (
    const uint8_t scalar,
    const uint8_t px,
    const uint8_t py,
    uint8_t rx,
    uint8_t ry
) 

Computes R = scalar * P.

Parameters:

  • scalar 32-byte scalar in big-endian format.
  • px 32-byte X-coordinate of input point P.
  • py 32-byte Y-coordinate of input point P.
  • rx [out] 32-byte X-coordinate of resulting point R.
  • ry [out] 32-byte Y-coordinate of resulting point R.

Returns:

true on success, false if point is invalid or scalar out of range.


function syn_p256_sign_ecdsa

Generate a NIST P-256 ECDSA signature (FIPS 186-4).

bool syn_p256_sign_ecdsa (
    const uint8_t priv_key,
    const uint8_t nonce_k,
    const uint8_t hash,
    uint8_t r_out,
    uint8_t s_out
) 

Computes signature (r, s) for a given message hash using a private key and nonce k.

Parameters:

  • priv_key 32-byte private key scalar.
  • nonce_k 32-byte ephemeral private nonce k (must be in [1, n-1]).
  • hash 32-byte message hash (typically SHA-256).
  • r_out [out] 32-byte signature component r.
  • s_out [out] 32-byte signature component s.

Returns:

true on success, false on invalid parameters.


function syn_p256_sign_ecdsa_deterministic

Generate a deterministic NIST P-256 ECDSA signature (RFC 6979 / FIPS 186-4).

bool syn_p256_sign_ecdsa_deterministic (
    const uint8_t priv_key,
    const uint8_t hash,
    uint8_t r_out,
    uint8_t s_out
) 

Derives the ephemeral nonce k deterministically using NIST SP 800-90A HMAC-DRBG (SHA-256) keyed with the private key and message hash.

Parameters:

  • priv_key 32-byte private key scalar.
  • hash 32-byte message hash (typically SHA-256).
  • r_out [out] 32-byte signature component r.
  • s_out [out] 32-byte signature component s.

Returns:

true on success, false on invalid parameters.


function syn_p256_verify_ecdsa

Verify a NIST P-256 ECDSA signature (FIPS 186-4).

bool syn_p256_verify_ecdsa (
    const uint8_t hash,
    const uint8_t r,
    const uint8_t s,
    const uint8_t pub_x,
    const uint8_t pub_y
) 

Parameters:

  • hash 32-byte message hash (typically SHA-256).
  • r 32-byte signature component r.
  • s 32-byte signature component s.
  • pub_x 32-byte public key X-coordinate.
  • pub_y 32-byte public key Y-coordinate.

Returns:

true if signature is mathematically valid, false otherwise.


Macro Definition Documentation

define SYN_P256_BYTE_LEN

NIST P-256 coordinate / scalar byte size (32 bytes).

#define SYN_P256_BYTE_LEN `32U`



The documentation for this class was generated from the following file src/syntropic/crypto/syn_p256.h