Skip to content

Commit

Permalink
feat: implement EllipticCurveParameters & WeierstrassParameters t…
Browse files Browse the repository at this point in the history
…raits
  • Loading branch information
raghav-rama committed Mar 18, 2024
1 parent a266aab commit 5f3de8f
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions src/bin/secp256r1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use num::BigUint;
use num::{BigUint, Num};
use serde::{Deserialize, Serialize};
use sp1_core::utils::ec::field::{FieldParameters, MAX_NB_LIMBS};
use sp1_core::utils::ec::{
field::{FieldParameters, MAX_NB_LIMBS},
weierstrass::WeierstrassParameters,
EllipticCurveParameters,
};

#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct Secp256r1Parameters;
Expand All @@ -22,6 +26,50 @@ impl FieldParameters for Secp256r1BaseField {
];

const WITNESS_OFFSET: usize = 1usize << 14;

fn modulus() -> BigUint {
BigUint::from_bytes_le(&Self::MODULUS)
}
}

impl EllipticCurveParameters for Secp256r1Parameters {
type BaseField = Secp256r1BaseField;
}

impl WeierstrassParameters for Secp256r1Parameters {
const A: [u16; MAX_NB_LIMBS] = [
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,
];

const B: [u16; MAX_NB_LIMBS] = [
0x5AC6, 0x35D8, 0xAA3A, 0x93E7, 0xB3EB, 0xBD55, 0x7698, 0x86BC, 0x651D, 0x06B0, 0xCC53,
0xB0F6, 0x3BCE, 0x3C3E, 0x27D2, 0x604B, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
];

fn generator() -> (BigUint, BigUint) {
let x = BigUint::from_str_radix(
"6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296",
16,
)
.unwrap();
let y = BigUint::from_str_radix(
"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5",
16,
)
.unwrap();
(x, y)
}

fn prime_group_order() -> BigUint {
BigUint::from_str_radix(
"FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551",
16,
)
.unwrap()
}
}

fn main() {}

0 comments on commit 5f3de8f

Please sign in to comment.