From 0b35c603410c16893ee6e7fa2b58fb2ada9f0495 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 12 Dec 2019 23:15:48 +0000 Subject: [PATCH] impl ConditionallySelectable for Field --- Cargo.toml | 1 + src/groth16/tests/dummy_engine.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index f329609..b056b6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/groth16/tests/dummy_engine.rs b/src/groth16/tests/dummy_engine.rs index c71df0d..280552b 100644 --- a/src/groth16/tests/dummy_engine.rs +++ b/src/groth16/tests/dummy_engine.rs @@ -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 = 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;