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

@@ -28,6 +28,7 @@ rand_core = "0.5.1"
ripemd160 = { version = "0.8", optional = true }
secp256k1 = { version = "=0.15.0", optional = true }
sha2 = "0.8"
subtle = "2.2.1"
[dev-dependencies]
hex-literal = "0.2"

View File

@@ -6,6 +6,7 @@ use ff::{
};
use rand_core::RngCore;
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use subtle::{Choice, ConditionallySelectable};
use super::ToUniform;
@@ -269,6 +270,17 @@ impl From<Fs> for FsRepr {
}
}
impl ConditionallySelectable for Fs {
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
Fs(FsRepr([
u64::conditional_select(&(a.0).0[0], &(b.0).0[0], choice),
u64::conditional_select(&(a.0).0[1], &(b.0).0[1], choice),
u64::conditional_select(&(a.0).0[2], &(b.0).0[2], choice),
u64::conditional_select(&(a.0).0[3], &(b.0).0[3], choice),
]))
}
}
impl Neg for Fs {
type Output = Self;