p256/
lib.rs

1// Fork of RustCrypto's p256 crate https://docs.rs/p256/latest/p256/
2// that uses zkvm instructions
3
4#![no_std]
5extern crate alloc;
6
7use elliptic_curve::{
8    bigint::U256, consts::U32, point::PointCompression, Curve, CurveArithmetic, PrimeCurve,
9};
10
11mod coord;
12mod internal;
13mod point;
14mod scalar;
15
16#[cfg(feature = "ecdsa-core")]
17pub mod ecdsa;
18
19// Needs to be public so that the `sw_init` macro can access it
20pub use internal::{P256Coord, P256Point, P256Scalar};
21
22// -- Define the ZST for implementing the elliptic curve traits --
23#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
24pub struct NistP256;
25
26// --- Implement the Curve trait on P256 ---
27
28/// Order of the P256 elliptic curve in hexadecimal.
29const ORDER_HEX: &str = "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551";
30
31/// Order of the P256 elliptic curve.
32const ORDER: U256 = U256::from_be_hex(ORDER_HEX);
33
34impl Curve for NistP256 {
35    /// 32-byte serialized field elements.
36    type FieldBytesSize = U32;
37
38    // Perf: Use the U256 type from openvm_ruint here
39    type Uint = U256;
40
41    /// Curve order.
42    const ORDER: U256 = ORDER;
43}
44
45impl PrimeCurve for NistP256 {}
46
47impl CurveArithmetic for NistP256 {
48    type AffinePoint = P256Point;
49    /// The `ProjectivePoint` type is still internally represented as an affine point.
50    type ProjectivePoint = P256Point;
51    type Scalar = P256Scalar;
52}
53
54impl PointCompression for NistP256 {
55    /// P256 points are typically uncompressed.
56    const COMPRESS_POINTS: bool = false;
57}
58
59/// SEC1-encoded P256 curve point.
60pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<NistP256>;