impl ConditionallySelectable for Field

This commit is contained in:
Jack Grigg 2019-12-12 23:15:48 +00:00
parent c716dfdd63
commit 0b35c60341
2 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,7 @@ crossbeam = { version = "0.7", optional = true }
pairing = { version = "0.16", 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;