Module k256

Source
Expand description

Koblitz secp256k1 Elliptic Curve Primitives

This module implements the secp256k1 elliptic curve operations in constant time. The curve equation is y² = x³ + 7 over the prime field F_p where:

  • p = 2^256 - 2^32 - 977
  • The curve order n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141

All operations are implemented to be constant-time to prevent timing attacks.

Structs§

FieldElement
secp256k1 field element representing values in F_p
Point
A point on the secp256k1 elliptic curve in affine coordinates
Scalar
secp256k1 scalar value for use in elliptic curve operations

Enums§

PointFormat
Format of a serialized elliptic curve point

Constants§

K256_FIELD_ELEMENT_SIZE
Size of a secp256k1 field element in bytes (32 bytes = 256 bits)
K256_KEM_SHARED_SECRET_KDF_OUTPUT_SIZE
Size of the KDF output for secp256k1 ECDH-KEM shared secret derivation
K256_POINT_COMPRESSED_SIZE
Size of a compressed secp256k1 point in bytes: format byte (0x02/0x03) + x-coordinate
K256_POINT_UNCOMPRESSED_SIZE
Size of an uncompressed secp256k1 point in bytes: format byte (0x04) + x-coordinate + y-coordinate
K256_SCALAR_SIZE
Size of a secp256k1 scalar in bytes (32 bytes = 256 bits)

Functions§

base_point_g
Get the standard base point G of the secp256k1 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