Module p256

Module p256 

Source
Expand description

NIST P-256 Elliptic Curve Primitives

This module implements the NIST P-256 elliptic curve operations in constant time. The curve equation is y² = x³ - 3x + b over the prime field F_p where:

  • p = 2^256 - 2^224 + 2^192 + 2^96 - 1 (NIST P-256 prime)
  • The curve order n = 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551

All operations are implemented to be constant-time to prevent timing attacks. The implementation uses:

  • Montgomery reduction for field arithmetic
  • Jacobian projective coordinates for efficient point operations
  • Binary scalar multiplication with constant-time point selection

Structs§

FieldElement
P-256 field element representing values in F_p
Point
P-256 elliptic curve point in affine coordinates (x, y)
Scalar
P-256 scalar value for use in elliptic curve operations

Enums§

PointFormat
Format of a serialized elliptic curve point

Constants§

P256_FIELD_ELEMENT_SIZE
Size of a P-256 field element in bytes (32 bytes = 256 bits)
P256_KEM_SHARED_SECRET_KDF_OUTPUT_SIZE
Size of the KDF output for P-256 ECDH-KEM shared secret derivation
P256_POINT_COMPRESSED_SIZE
Size of a compressed P-256 point in bytes: format byte (0x02/0x03) + x-coordinate
P256_POINT_UNCOMPRESSED_SIZE
Size of an uncompressed P-256 point in bytes: format byte (0x04) + x-coordinate + y-coordinate
P256_SCALAR_SIZE
Size of a P-256 scalar in bytes (32 bytes = 256 bits)

Functions§

base_point_g
Get the standard base point G of the P-256 curve
generate_keypair
Generate a cryptographically secure ECDH keypair
kdf_hkdf_sha256_for_ecdh_kem
Key derivation function for ECDH shared secret using HKDF-SHA256
scalar_mult
General scalar multiplication: compute scalar * point
scalar_mult_base_g
Scalar multiplication with the base point: scalar * G