Skip to main content

primeorder/
lib.rs

1#![no_std]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3#![doc(
4    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
5    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
6)]
7#![forbid(unsafe_code)]
8#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
9#![doc = include_str!("../README.md")]
10
11#[cfg(feature = "alloc")]
12#[macro_use]
13extern crate alloc;
14#[cfg(feature = "std")]
15extern crate std;
16
17pub mod mul_backend;
18#[cfg(feature = "hash2curve")]
19pub mod osswu;
20pub mod point_arithmetic;
21
22mod affine;
23#[cfg(feature = "dev")]
24mod dev;
25mod projective;
26mod tables;
27
28pub use crate::{
29    affine::AffinePoint,
30    mul_backend::MulBackend,
31    projective::ProjectivePoint,
32    tables::{LookupTable, Radix16Decomposition, Radix16Digits},
33};
34pub use elliptic_curve::{
35    self, Field, FieldBytes, PrimeCurve, PrimeField, Scalar,
36    array::{self, ArraySize, sizes::U1},
37    bigint::{ByteOrder, modular::Retrieve},
38    hazmat::FieldArithmetic,
39    ops::Double,
40};
41pub use primefield::{FieldExt, PrimeFieldExt};
42
43use elliptic_curve::{Curve, CurveArithmetic, sec1};
44
45#[cfg(feature = "basepoint-table")]
46pub use crate::tables::BasepointTable;
47
48/// Parameters for elliptic curves of prime order which can be described by the short Weierstrass
49/// equation.
50pub trait PrimeCurveParams:
51    Curve<FieldBytesSize: sec1::ModulusSize>
52    + CurveArithmetic<
53        AffinePoint = AffinePoint<Self>,
54        ProjectivePoint = ProjectivePoint<Self>,
55        Scalar: PrimeFieldExt,
56    > + FieldArithmetic<FieldElement: PrimeFieldExt>
57    + PrimeCurve
58{
59    /// [Point arithmetic](point_arithmetic) implementation, might be optimized for this specific curve
60    type PointArithmetic: point_arithmetic::PointArithmetic<Self>;
61
62    /// Scalar arithmetic backend implementation.
63    type Backend: MulBackend<Self>;
64
65    /// Coefficient `a` in the curve equation.
66    const EQUATION_A: Self::FieldElement;
67
68    /// Coefficient `b` in the curve equation.
69    const EQUATION_B: Self::FieldElement;
70
71    /// Generator point's affine coordinates: (x, y).
72    const GENERATOR: (Self::FieldElement, Self::FieldElement);
73}
74
75/// Trait for specifying a constant-time basepoint table for a given curve.
76#[cfg(feature = "basepoint-table")]
77pub trait PrimeCurveWithBasepointTable<const WINDOW_SIZE: usize>:
78    PrimeCurve + CurveArithmetic
79{
80    /// Basepoint table for this curve.
81    const BASEPOINT_TABLE: &'static BasepointTable<
82        <Self as CurveArithmetic>::ProjectivePoint,
83        WINDOW_SIZE,
84    >;
85}