mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Annotate docs with required feature flags
This commit is contained in:
parent
c052756831
commit
96116e20e5
6 changed files with 21 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ pub use fields::*;
|
|||
/// performed. This allows an FFT implementation (for example) to operate
|
||||
/// generically over either a field or elliptic curve group.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
pub trait Group: Copy + Clone + Send + Sync + 'static {
|
||||
/// The group is assumed to be of prime order $p$. `Scalar` is the
|
||||
/// associated scalar field of size $p$.
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use std::{
|
|||
/// Currently requires the `std` feature flag because of `hash_to_curve`, and
|
||||
/// `CurveAffine::{read, write}`.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
pub trait CurveExt:
|
||||
PrimeCurve<Affine = <Self as CurveExt>::AffineExt>
|
||||
+ group::Group<Scalar = <Self as CurveExt>::ScalarExt>
|
||||
|
|
@ -90,6 +91,7 @@ pub trait CurveExt:
|
|||
/// This trait is the affine counterpart to `Curve` and is used for
|
||||
/// serialization, storage in memory, and inspection of $x$ and $y$ coordinates.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
pub trait CurveAffine:
|
||||
PrimeCurveAffine<
|
||||
Scalar = <Self as CurveAffine>::ScalarExt,
|
||||
|
|
@ -145,6 +147,7 @@ pub trait CurveAffine:
|
|||
|
||||
/// The affine coordinates of a point on an elliptic curve.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Coordinates<C: CurveAffine> {
|
||||
pub(crate) x: C::Base,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ const_assert!(size_of::<usize>() >= 4);
|
|||
/// A trait that exposes additional operations related to calculating square roots of
|
||||
/// prime-order finite fields.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
pub trait SqrtRatio: ff::PrimeField {
|
||||
/// The value $(T-1)/2$ such that $2^S \cdot T = p - 1$ with $T$ odd.
|
||||
const T_MINUS1_OVER2: [u64; 4];
|
||||
|
|
@ -65,6 +66,7 @@ pub trait SqrtRatio: ff::PrimeField {
|
|||
/// This trait is a common interface for dealing with elements of a finite
|
||||
/// field.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
pub trait FieldExt: SqrtRatio + From<bool> + Ord + Group<Scalar = Self> {
|
||||
/// Modulus of the field written as a string for display purposes
|
||||
const MODULUS: &'static str;
|
||||
|
|
@ -119,6 +121,7 @@ pub trait FieldExt: SqrtRatio + From<bool> + Ord + Group<Scalar = Self> {
|
|||
///
|
||||
/// `tm1d2` should be set to `(t - 1) // 2`, where `t = (modulus - 1) >> F::S`.
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(not(feature = "std"))))]
|
||||
pub(crate) fn sqrt_tonelli_shanks<F: ff::PrimeField, S: AsRef<[u64]>>(
|
||||
f: &F,
|
||||
tm1d2: S,
|
||||
|
|
@ -165,6 +168,7 @@ pub(crate) fn sqrt_tonelli_shanks<F: ff::PrimeField, S: AsRef<[u64]>>(
|
|||
|
||||
/// Parameters for a perfect hash function used in square root computation.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
#[derive(Debug)]
|
||||
struct SqrtHasher<F: FieldExt> {
|
||||
hash_xor: u32,
|
||||
|
|
@ -186,6 +190,7 @@ impl<F: FieldExt> SqrtHasher<F> {
|
|||
|
||||
/// Tables used for square root computation.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
#[derive(Debug)]
|
||||
pub struct SqrtTables<F: FieldExt> {
|
||||
hasher: SqrtHasher<F>,
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ macro_rules! new_curve_impl {
|
|||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl group::WnafGroup for $name {
|
||||
fn recommended_wnaf_for_num_scalars(num_scalars: usize) -> usize {
|
||||
// Copied from bls12_381::g1, should be updated.
|
||||
|
|
|
|||
|
|
@ -225,6 +225,7 @@ const ROOT_OF_UNITY: Fp = Fp::from_raw([
|
|||
/// with t odd. In other words, this
|
||||
/// is a t root of unity.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
const DELTA: Fp = Fp::from_raw([
|
||||
0x6a6ccd20dd7b9ba2,
|
||||
0xf5e4f3f13eee5636,
|
||||
|
|
@ -464,6 +465,7 @@ impl<'a> From<&'a Fp> for [u8; 32] {
|
|||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl Group for Fp {
|
||||
type Scalar = Fp;
|
||||
|
||||
|
|
@ -623,6 +625,7 @@ type ReprBits = [u32; 8];
|
|||
type ReprBits = [u64; 4];
|
||||
|
||||
#[cfg(feature = "bits")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "bits")))]
|
||||
impl PrimeFieldBits for Fp {
|
||||
type ReprBits = ReprBits;
|
||||
|
||||
|
|
@ -666,10 +669,12 @@ impl PrimeFieldBits for Fp {
|
|||
#[cfg(feature = "std")]
|
||||
lazy_static! {
|
||||
// The perfect hash parameters are found by `squareroottab.sage` in zcash/pasta.
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
static ref FP_TABLES: SqrtTables<Fp> = SqrtTables::new(0x11BE, 1098);
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl SqrtRatio for Fp {
|
||||
const T_MINUS1_OVER2: [u64; 4] = T_MINUS1_OVER2;
|
||||
|
||||
|
|
@ -721,6 +726,7 @@ impl SqrtRatio for Fp {
|
|||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl FieldExt for Fp {
|
||||
const MODULUS: &'static str =
|
||||
"0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001";
|
||||
|
|
|
|||
|
|
@ -225,6 +225,7 @@ const ROOT_OF_UNITY: Fq = Fq::from_raw([
|
|||
/// with t odd. In other words, this
|
||||
/// is a t root of unity.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
const DELTA: Fq = Fq::from_raw([
|
||||
0x8494392472d1683c,
|
||||
0xe3ac3376541d1140,
|
||||
|
|
@ -464,6 +465,7 @@ impl<'a> From<&'a Fq> for [u8; 32] {
|
|||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl Group for Fq {
|
||||
type Scalar = Fq;
|
||||
|
||||
|
|
@ -666,10 +668,12 @@ impl PrimeFieldBits for Fq {
|
|||
#[cfg(feature = "std")]
|
||||
lazy_static! {
|
||||
// The perfect hash parameters are found by `squareroottab.sage` in zcash/pasta.
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
static ref FQ_TABLES: SqrtTables<Fq> = SqrtTables::new(0x116A9E, 1206);
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl SqrtRatio for Fq {
|
||||
const T_MINUS1_OVER2: [u64; 4] = T_MINUS1_OVER2;
|
||||
|
||||
|
|
@ -721,6 +725,7 @@ impl SqrtRatio for Fq {
|
|||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl FieldExt for Fq {
|
||||
const MODULUS: &'static str =
|
||||
"0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001";
|
||||
|
|
|
|||
Loading…
Reference in a new issue