1#![doc = include_str!("../README.md")]
2#![no_std]
3#![deny(missing_docs)]
4
5pub use primeorder::{
6 self,
7 elliptic_curve::{
8 self,
9 bigint::{self, rand_core},
10 ff,
11 generic_array::{self, typenum},
12 },
13};
14
15use bigint::U256;
16use elliptic_curve::{
17 scalar::{FromUintUnchecked, ScalarPrimitive},
18 Curve, CurveArithmetic, PrimeCurve,
19};
20use primeorder::PrimeCurveParams;
21
22use self::core::{field_element::FieldElementCore, scalar::ScalarCore, W};
23
24pub mod constants;
25pub mod core;
26
27pub type FieldElement = W<FieldElementCore>;
29pub type Scalar = W<ScalarCore>;
31pub type AffinePoint = primeorder::AffinePoint<StarkCurve>;
33pub type ProjectivePoint = primeorder::ProjectivePoint<StarkCurve>;
35
36#[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Eq, Ord)]
38pub struct StarkCurve;
39
40impl Curve for StarkCurve {
41 type FieldBytesSize = typenum::U32;
42 type Uint = U256;
43
44 const ORDER: Self::Uint =
45 U256::from_be_hex("0800000000000010ffffffffffffffffb781126dcae7b2321e66a241adc64d2f");
46}
47
48impl PrimeCurve for StarkCurve {}
49
50impl CurveArithmetic for StarkCurve {
51 type Scalar = Scalar;
52 type AffinePoint = AffinePoint;
53 type ProjectivePoint = ProjectivePoint;
54}
55
56impl PrimeCurveParams for StarkCurve {
57 type FieldElement = FieldElement;
58 type PointArithmetic = primeorder::point_arithmetic::EquationAIsGeneric;
59
60 const EQUATION_A: Self::FieldElement = constants::EQUATION_A;
61 const EQUATION_B: Self::FieldElement = constants::EQUATION_B;
62
63 const GENERATOR: (Self::FieldElement, Self::FieldElement) = constants::GENERATOR;
64}
65
66impl elliptic_curve::FieldBytesEncoding<StarkCurve> for U256 {}
67
68impl From<Scalar> for ScalarPrimitive<StarkCurve> {
69 fn from(s: Scalar) -> Self {
70 ScalarPrimitive::from_uint_unchecked(s.to_uint())
71 }
72}
73
74impl From<&Scalar> for ScalarPrimitive<StarkCurve> {
75 fn from(s: &Scalar) -> Self {
76 ScalarPrimitive::from_uint_unchecked(s.to_uint())
77 }
78}