impl ConditionallySelectable for Field

This commit is contained in:
Jack Grigg
2019-12-12 23:15:48 +00:00
parent cded08b0c5
commit 662be3551f
12 changed files with 74 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ crossbeam = { version = "0.7", optional = true }
pairing = { version = "0.15.0", path = "../pairing", optional = true }
rand_core = "0.5"
byteorder = "1"
subtle = "2.2.1"
[dev-dependencies]
hex-literal = "0.2"

View File

@@ -10,6 +10,7 @@ use std::cmp::Ordering;
use std::fmt;
use std::num::Wrapping;
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use subtle::{Choice, ConditionallySelectable};
const MODULUS_R: Wrapping<u32> = Wrapping(64513);
@@ -22,6 +23,16 @@ impl fmt::Display for Fr {
}
}
impl ConditionallySelectable for Fr {
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
Fr(Wrapping(u32::conditional_select(
&(a.0).0,
&(b.0).0,
choice,
)))
}
}
impl Neg for Fr {
type Output = Self;