mirror of
https://github.com/pseXperiments/ff-Goldilocks.git
synced 2026-01-09 04:57:59 -05:00
impl TryInto<Goldilocks> for Ext2/3
This commit is contained in:
14
src/fp2.rs
14
src/fp2.rs
@@ -383,3 +383,17 @@ impl GoldilocksExt2 {
|
||||
Self(res)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<Goldilocks> for GoldilocksExt2 {
|
||||
/// The type returned in the event of a conversion error.
|
||||
type Error = &'static str;
|
||||
|
||||
/// Performs the conversion.
|
||||
fn try_into(self) -> Result<Goldilocks, Self::Error> {
|
||||
if self.0[1].is_zero_vartime() {
|
||||
Ok(self.0[0])
|
||||
} else {
|
||||
Err("extension field is not zero")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
src/fp3.rs
14
src/fp3.rs
@@ -369,3 +369,17 @@ impl FromUniformBytes<64> for GoldilocksExt3 {
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<Goldilocks> for GoldilocksExt3 {
|
||||
/// The type returned in the event of a conversion error.
|
||||
type Error = &'static str;
|
||||
|
||||
/// Performs the conversion.
|
||||
fn try_into(self) -> Result<Goldilocks, Self::Error> {
|
||||
if self.0[1].is_zero_vartime() && self.0[2].is_zero_vartime() {
|
||||
Ok(self.0[0])
|
||||
} else {
|
||||
Err("extension field is not zero")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ use rand_xorshift::XorShiftRng;
|
||||
|
||||
use crate::SmallField;
|
||||
|
||||
|
||||
pub fn random_small_field_tests<F: SmallField>(type_name: String) {
|
||||
let mut rng = XorShiftRng::from_seed([
|
||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||
@@ -41,7 +40,6 @@ pub fn random_small_field_tests<F: SmallField>(type_name: String) {
|
||||
assert_eq!(t1, t2);
|
||||
}
|
||||
end_timer!(start);
|
||||
|
||||
}
|
||||
|
||||
pub fn random_field_tests<F: Field>(type_name: String) {
|
||||
|
||||
Reference in New Issue
Block a user