From bc20c5826b3755bbcaf8555b748aa4da32d024b6 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 1 Jun 2021 23:31:00 +0100 Subject: [PATCH] Migrate to ff 0.10.0 --- Cargo.toml | 9 +++++---- src/fields/fp.rs | 46 ++++++++++++++++++++++++++-------------------- src/fields/fq.rs | 46 ++++++++++++++++++++++++++-------------------- 3 files changed, 57 insertions(+), 44 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bdb9213..c0571f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,12 +39,13 @@ harness = false [dependencies] subtle = "2.3" -ff = "0.9" -group = "0.9" +ff = "0.10" +group = "0.10" rand = "0.8" blake2b_simd = "0.5" lazy_static = "1.4.0" static_assertions = "1.1.0" -# Temporary workaround for https://github.com/myrrlyn/funty/issues/3 -funty = "=1.1.0" +[features] +default = ["bits"] +bits = ["ff/bits"] diff --git a/src/fields/fp.rs b/src/fields/fp.rs index 406d76c..d72b0ee 100644 --- a/src/fields/fp.rs +++ b/src/fields/fp.rs @@ -1,11 +1,13 @@ use core::convert::TryInto; use core::fmt; use core::ops::{Add, Mul, Neg, Sub}; -use ff::FieldBits; use lazy_static::lazy_static; use rand::RngCore; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; +#[cfg(feature = "bits")] +use ff::{FieldBits, PrimeFieldBits}; + use crate::arithmetic::{adc, mac, sbb, FieldExt, Group, SqrtTables}; /// This represents an element of $\mathbb{F}_p$ where @@ -529,15 +531,8 @@ impl ff::Field for Fp { } } -#[cfg(not(target_pointer_width = "64"))] -type ReprBits = [u32; 8]; - -#[cfg(target_pointer_width = "64")] -type ReprBits = [u64; 4]; - impl ff::PrimeField for Fp { type Repr = [u8; 32]; - type ReprBits = ReprBits; const NUM_BITS: u32 = 255; const CAPACITY: u32 = 254; @@ -551,6 +546,29 @@ impl ff::PrimeField for Fp { self.to_bytes() } + fn is_odd(&self) -> bool { + self.to_bytes()[0] & 1 == 1 + } + + fn multiplicative_generator() -> Self { + GENERATOR + } + + fn root_of_unity() -> Self { + Self::ROOT_OF_UNITY + } +} + +#[cfg(all(feature = "bits", not(target_pointer_width = "64")))] +type ReprBits = [u32; 8]; + +#[cfg(all(feature = "bits", target_pointer_width = "64"))] +type ReprBits = [u64; 4]; + +#[cfg(feature = "bits")] +impl PrimeFieldBits for Fp { + type ReprBits = ReprBits; + fn to_le_bits(&self) -> FieldBits { let bytes = self.to_bytes(); @@ -577,10 +595,6 @@ impl ff::PrimeField for Fp { FieldBits::new(limbs) } - fn is_odd(&self) -> bool { - self.to_bytes()[0] & 1 == 1 - } - fn char_le_bits() -> FieldBits { #[cfg(not(target_pointer_width = "64"))] { @@ -590,14 +604,6 @@ impl ff::PrimeField for Fp { #[cfg(target_pointer_width = "64")] FieldBits::new(MODULUS.0) } - - fn multiplicative_generator() -> Self { - GENERATOR - } - - fn root_of_unity() -> Self { - Self::ROOT_OF_UNITY - } } lazy_static! { diff --git a/src/fields/fq.rs b/src/fields/fq.rs index cc8954a..3bf0b1f 100644 --- a/src/fields/fq.rs +++ b/src/fields/fq.rs @@ -1,11 +1,13 @@ use core::convert::TryInto; use core::fmt; use core::ops::{Add, Mul, Neg, Sub}; -use ff::FieldBits; use lazy_static::lazy_static; use rand::RngCore; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; +#[cfg(feature = "bits")] +use ff::{FieldBits, PrimeFieldBits}; + use crate::arithmetic::{adc, mac, sbb, FieldExt, Group, SqrtTables}; /// This represents an element of $\mathbb{F}_q$ where @@ -529,15 +531,8 @@ impl ff::Field for Fq { } } -#[cfg(not(target_pointer_width = "64"))] -type ReprBits = [u32; 8]; - -#[cfg(target_pointer_width = "64")] -type ReprBits = [u64; 4]; - impl ff::PrimeField for Fq { type Repr = [u8; 32]; - type ReprBits = ReprBits; const NUM_BITS: u32 = 255; const CAPACITY: u32 = 254; @@ -551,6 +546,29 @@ impl ff::PrimeField for Fq { self.to_bytes() } + fn is_odd(&self) -> bool { + self.to_bytes()[0] & 1 == 1 + } + + fn multiplicative_generator() -> Self { + GENERATOR + } + + fn root_of_unity() -> Self { + Self::ROOT_OF_UNITY + } +} + +#[cfg(all(feature = "bits", not(target_pointer_width = "64")))] +type ReprBits = [u32; 8]; + +#[cfg(all(feature = "bits", target_pointer_width = "64"))] +type ReprBits = [u64; 4]; + +#[cfg(feature = "bits")] +impl PrimeFieldBits for Fq { + type ReprBits = ReprBits; + fn to_le_bits(&self) -> FieldBits { let bytes = self.to_bytes(); @@ -577,10 +595,6 @@ impl ff::PrimeField for Fq { FieldBits::new(limbs) } - fn is_odd(&self) -> bool { - self.to_bytes()[0] & 1 == 1 - } - fn char_le_bits() -> FieldBits { #[cfg(not(target_pointer_width = "64"))] { @@ -590,14 +604,6 @@ impl ff::PrimeField for Fq { #[cfg(target_pointer_width = "64")] FieldBits::new(MODULUS.0) } - - fn multiplicative_generator() -> Self { - GENERATOR - } - - fn root_of_unity() -> Self { - Self::ROOT_OF_UNITY - } } lazy_static! {