mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
impl ConditionallySelectable for Field
This commit is contained in:
@@ -14,6 +14,7 @@ edition = "2018"
|
||||
byteorder = "1"
|
||||
ff_derive = { version = "0.4.0", path = "ff_derive", optional = true }
|
||||
rand_core = "0.5"
|
||||
subtle = "2.2.1"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
@@ -833,6 +833,16 @@ fn prime_field_impl(
|
||||
}
|
||||
}
|
||||
|
||||
impl ::subtle::ConditionallySelectable for #name {
|
||||
fn conditional_select(a: &#name, b: &#name, choice: ::subtle::Choice) -> #name {
|
||||
let mut res = [0u64; #limbs];
|
||||
for i in 0..#limbs {
|
||||
res[i] = u64::conditional_select(&(a.0).0[i], &(b.0).0[i], choice);
|
||||
}
|
||||
#name(#repr(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Neg for #name {
|
||||
type Output = #name;
|
||||
|
||||
|
@@ -12,6 +12,7 @@ use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
use subtle::ConditionallySelectable;
|
||||
|
||||
/// This trait represents an element of a field.
|
||||
pub trait Field:
|
||||
@@ -24,6 +25,7 @@ pub trait Field:
|
||||
+ fmt::Debug
|
||||
+ fmt::Display
|
||||
+ 'static
|
||||
+ ConditionallySelectable
|
||||
+ Add<Output = Self>
|
||||
+ Sub<Output = Self>
|
||||
+ Mul<Output = Self>
|
||||
|
Reference in New Issue
Block a user