mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Migrate to ff 0.10.0
This commit is contained in:
parent
45c57f9352
commit
bc20c5826b
3 changed files with 57 additions and 44 deletions
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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<Self::ReprBits> {
|
||||
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<Self::ReprBits> {
|
||||
#[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! {
|
||||
|
|
|
|||
|
|
@ -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<Self::ReprBits> {
|
||||
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<Self::ReprBits> {
|
||||
#[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! {
|
||||
|
|
|
|||
Loading…
Reference in a new issue