impl ConditionallySelectable for Field
This commit is contained in:
parent
575ea832f4
commit
b118a07633
|
@ -21,6 +21,7 @@ byteorder = "1"
|
|||
ff = { version = "0.6", path = "../ff", features = ["derive"] }
|
||||
group = { version = "0.6", path = "../group" }
|
||||
rand_core = "0.5"
|
||||
subtle = "2.2.1"
|
||||
|
||||
[dev-dependencies]
|
||||
rand_xorshift = "0.2"
|
||||
|
|
|
@ -4,6 +4,7 @@ use super::fq6::Fq6;
|
|||
use ff::Field;
|
||||
use rand_core::RngCore;
|
||||
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
use subtle::{Choice, ConditionallySelectable};
|
||||
|
||||
/// An element of Fq12, represented by c0 + c1 * w.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
|
@ -40,6 +41,15 @@ impl Fq12 {
|
|||
}
|
||||
}
|
||||
|
||||
impl ConditionallySelectable for Fq12 {
|
||||
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
|
||||
Fq12 {
|
||||
c0: Fq6::conditional_select(&a.c0, &b.c0, choice),
|
||||
c1: Fq6::conditional_select(&a.c1, &b.c1, choice),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for Fq12 {
|
||||
type Output = Self;
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ use ff::{Field, SqrtField};
|
|||
use rand_core::RngCore;
|
||||
use std::cmp::Ordering;
|
||||
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
use subtle::{Choice, ConditionallySelectable};
|
||||
|
||||
/// An element of Fq2, represented by c0 + c1 * u.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
|
@ -54,6 +55,15 @@ impl Fq2 {
|
|||
}
|
||||
}
|
||||
|
||||
impl ConditionallySelectable for Fq2 {
|
||||
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
|
||||
Fq2 {
|
||||
c0: Fq::conditional_select(&a.c0, &b.c0, choice),
|
||||
c1: Fq::conditional_select(&a.c1, &b.c1, choice),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for Fq2 {
|
||||
type Output = Self;
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ use super::fq2::Fq2;
|
|||
use ff::Field;
|
||||
use rand_core::RngCore;
|
||||
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
use subtle::{Choice, ConditionallySelectable};
|
||||
|
||||
/// An element of Fq6, represented by c0 + c1 * v + c2 * v^(2).
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
|
@ -100,6 +101,16 @@ impl Fq6 {
|
|||
}
|
||||
}
|
||||
|
||||
impl ConditionallySelectable for Fq6 {
|
||||
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
|
||||
Fq6 {
|
||||
c0: Fq2::conditional_select(&a.c0, &b.c0, choice),
|
||||
c1: Fq2::conditional_select(&a.c1, &b.c1, choice),
|
||||
c2: Fq2::conditional_select(&a.c2, &b.c2, choice),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for Fq6 {
|
||||
type Output = Self;
|
||||
|
||||
|
|
Loading…
Reference in New Issue