From bfb0f5a9a94d698061fb5b94e4f0d07e3f15d330 Mon Sep 17 00:00:00 2001
From: Zhang Zhuo <mycinbrin@gmail.com>
Date: Thu, 27 Feb 2025 22:09:37 +0800
Subject: [PATCH] ecc: use p256::NistP256

---
 Cargo.lock                       | 12 +++++++++++-
 Cargo.toml                       |  1 +
 extensions/ecc/guest/Cargo.toml  |  6 +++---
 extensions/ecc/guest/src/p256.rs |  4 +---
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index b0b5a77e96..8d5f34fb8a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -578,7 +578,7 @@ dependencies = [
  "http 0.2.12",
  "http 1.2.0",
  "once_cell",
- "p256",
+ "p256 0.11.1",
  "percent-encoding",
  "ring",
  "sha2",
@@ -3814,6 +3814,7 @@ dependencies = [
  "openvm-ecc-sw-macros",
  "openvm-platform",
  "openvm-rv32im-guest",
+ "p256 0.13.2",
  "rand",
  "serde",
  "strum_macros",
@@ -4639,6 +4640,15 @@ dependencies = [
  "sha2",
 ]
 
+[[package]]
+name = "p256"
+version = "0.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b"
+dependencies = [
+ "elliptic-curve 0.13.8",
+]
+
 [[package]]
 name = "p3-air"
 version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
index cb4a23314a..d9b7fba482 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -240,6 +240,7 @@ bytemuck = { version = "1.20.0", default-features = false }
 # cryptography, default-features = false for no_std
 tiny-keccak = { version = "2.0.2", features = ["keccak"] }
 k256 = { version = "0.13.3", default-features = false }
+p256 = { version = "0.13.2", default-features = false }
 elliptic-curve = { version = "0.13.8", default-features = false }
 ecdsa = { version = "0.16.9", default-features = false }
 num-bigint = { version = "0.4.6", default-features = false }
diff --git a/extensions/ecc/guest/Cargo.toml b/extensions/ecc/guest/Cargo.toml
index c4d9420142..6ccb8e921d 100644
--- a/extensions/ecc/guest/Cargo.toml
+++ b/extensions/ecc/guest/Cargo.toml
@@ -17,6 +17,7 @@ strum_macros.workspace = true
 ecdsa = { workspace = true, features = ["verifying"] }
 elliptic-curve = { workspace = true, features = ["arithmetic", "sec1"] }
 k256 = { workspace = true, optional = true }
+p256 = { workspace = true, optional = true }
 hex-literal = { workspace = true }
 openvm-rv32im-guest = { workspace = true }
 openvm-algebra-guest = { workspace = true }
@@ -39,6 +40,5 @@ std = ["openvm/std"]
 # features to enable specific curves in guest programs
 # only enable for the curves you use as it affects the init! macro
 k256 = ["dep:k256"]
-halo2curves = ["dep:halo2curves-axiom", "openvm-algebra-guest/halo2curves"]
-
-p256 = []
+p256 = ["dep:p256"]
+halo2curves = ["dep:halo2curves-axiom", "openvm-algebra-guest/halo2curves"]
\ No newline at end of file
diff --git a/extensions/ecc/guest/src/p256.rs b/extensions/ecc/guest/src/p256.rs
index 886dab0ea6..dca7d17259 100644
--- a/extensions/ecc/guest/src/p256.rs
+++ b/extensions/ecc/guest/src/p256.rs
@@ -36,8 +36,6 @@ pub const CURVE_B: P256Coord = P256Coord::from_const_bytes(hex!(
     "4b60d2273e3cce3bf6b053ccb0061d65bc86987655bdebb3e7933aaad835c65a"
 ));
 
-pub struct P256;
-
 openvm_ecc_sw_macros::sw_declare! {
     P256Point { mod_type = P256Coord, a = CURVE_A, b = CURVE_B },
 }
@@ -76,7 +74,7 @@ impl CyclicGroup for P256Point {
     };
 }
 
-impl IntrinsicCurve for P256 {
+impl IntrinsicCurve for p256::NistP256 {
     type Scalar = P256Scalar;
     type Point = P256Point;