Migrate to ff 0.10.0

This commit is contained in:
Jack Grigg 2021-06-01 23:31:00 +01:00
parent 45c57f9352
commit bc20c5826b
3 changed files with 57 additions and 44 deletions

View file

@ -39,12 +39,13 @@ harness = false
[dependencies] [dependencies]
subtle = "2.3" subtle = "2.3"
ff = "0.9" ff = "0.10"
group = "0.9" group = "0.10"
rand = "0.8" rand = "0.8"
blake2b_simd = "0.5" blake2b_simd = "0.5"
lazy_static = "1.4.0" lazy_static = "1.4.0"
static_assertions = "1.1.0" static_assertions = "1.1.0"
# Temporary workaround for https://github.com/myrrlyn/funty/issues/3 [features]
funty = "=1.1.0" default = ["bits"]
bits = ["ff/bits"]

View file

@ -1,11 +1,13 @@
use core::convert::TryInto; use core::convert::TryInto;
use core::fmt; use core::fmt;
use core::ops::{Add, Mul, Neg, Sub}; use core::ops::{Add, Mul, Neg, Sub};
use ff::FieldBits;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use rand::RngCore; use rand::RngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
#[cfg(feature = "bits")]
use ff::{FieldBits, PrimeFieldBits};
use crate::arithmetic::{adc, mac, sbb, FieldExt, Group, SqrtTables}; use crate::arithmetic::{adc, mac, sbb, FieldExt, Group, SqrtTables};
/// This represents an element of $\mathbb{F}_p$ where /// 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 { impl ff::PrimeField for Fp {
type Repr = [u8; 32]; type Repr = [u8; 32];
type ReprBits = ReprBits;
const NUM_BITS: u32 = 255; const NUM_BITS: u32 = 255;
const CAPACITY: u32 = 254; const CAPACITY: u32 = 254;
@ -551,6 +546,29 @@ impl ff::PrimeField for Fp {
self.to_bytes() 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<Self::ReprBits> { fn to_le_bits(&self) -> FieldBits<Self::ReprBits> {
let bytes = self.to_bytes(); let bytes = self.to_bytes();
@ -577,10 +595,6 @@ impl ff::PrimeField for Fp {
FieldBits::new(limbs) FieldBits::new(limbs)
} }
fn is_odd(&self) -> bool {
self.to_bytes()[0] & 1 == 1
}
fn char_le_bits() -> FieldBits<Self::ReprBits> { fn char_le_bits() -> FieldBits<Self::ReprBits> {
#[cfg(not(target_pointer_width = "64"))] #[cfg(not(target_pointer_width = "64"))]
{ {
@ -590,14 +604,6 @@ impl ff::PrimeField for Fp {
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
FieldBits::new(MODULUS.0) FieldBits::new(MODULUS.0)
} }
fn multiplicative_generator() -> Self {
GENERATOR
}
fn root_of_unity() -> Self {
Self::ROOT_OF_UNITY
}
} }
lazy_static! { lazy_static! {

View file

@ -1,11 +1,13 @@
use core::convert::TryInto; use core::convert::TryInto;
use core::fmt; use core::fmt;
use core::ops::{Add, Mul, Neg, Sub}; use core::ops::{Add, Mul, Neg, Sub};
use ff::FieldBits;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use rand::RngCore; use rand::RngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
#[cfg(feature = "bits")]
use ff::{FieldBits, PrimeFieldBits};
use crate::arithmetic::{adc, mac, sbb, FieldExt, Group, SqrtTables}; use crate::arithmetic::{adc, mac, sbb, FieldExt, Group, SqrtTables};
/// This represents an element of $\mathbb{F}_q$ where /// 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 { impl ff::PrimeField for Fq {
type Repr = [u8; 32]; type Repr = [u8; 32];
type ReprBits = ReprBits;
const NUM_BITS: u32 = 255; const NUM_BITS: u32 = 255;
const CAPACITY: u32 = 254; const CAPACITY: u32 = 254;
@ -551,6 +546,29 @@ impl ff::PrimeField for Fq {
self.to_bytes() 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<Self::ReprBits> { fn to_le_bits(&self) -> FieldBits<Self::ReprBits> {
let bytes = self.to_bytes(); let bytes = self.to_bytes();
@ -577,10 +595,6 @@ impl ff::PrimeField for Fq {
FieldBits::new(limbs) FieldBits::new(limbs)
} }
fn is_odd(&self) -> bool {
self.to_bytes()[0] & 1 == 1
}
fn char_le_bits() -> FieldBits<Self::ReprBits> { fn char_le_bits() -> FieldBits<Self::ReprBits> {
#[cfg(not(target_pointer_width = "64"))] #[cfg(not(target_pointer_width = "64"))]
{ {
@ -590,14 +604,6 @@ impl ff::PrimeField for Fq {
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
FieldBits::new(MODULUS.0) FieldBits::new(MODULUS.0)
} }
fn multiplicative_generator() -> Self {
GENERATOR
}
fn root_of_unity() -> Self {
Self::ROOT_OF_UNITY
}
} }
lazy_static! { lazy_static! {