mirror of
https://github.com/pseXperiments/ff-Goldilocks.git
synced 2026-01-09 13:07:59 -05:00
[feat] impl FromUniformBytes for ext fields
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -400,9 +400,9 @@ checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.11"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829"
|
||||
checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
@@ -636,15 +636,15 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.25"
|
||||
version = "0.38.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e"
|
||||
checksum = "9470c4bf8246c8daf25f9598dca807fb6510347b1e1cfa55749113850c79d88a"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -124,6 +124,13 @@ impl FromUniformBytes<32> for Goldilocks {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromUniformBytes<16> for Goldilocks {
|
||||
fn from_uniform_bytes(bytes: &[u8; 16]) -> Self {
|
||||
// FIXME: this is also biased.
|
||||
Goldilocks(u64::from_le_bytes(bytes[..8].try_into().unwrap()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Field for Goldilocks {
|
||||
/// The zero element of the field, the additive identity.
|
||||
const ZERO: Self = Self(0);
|
||||
|
||||
15
src/fp2.rs
15
src/fp2.rs
@@ -2,7 +2,7 @@
|
||||
|
||||
use core::iter::{Product, Sum};
|
||||
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
use ff::{Field, PrimeField};
|
||||
use ff::{Field, FromUniformBytes, PrimeField};
|
||||
use halo2curves::serde::SerdeObject;
|
||||
use rand_core::RngCore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -320,3 +320,16 @@ impl PrimeField for GoldilocksExt2 {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromUniformBytes<64> for GoldilocksExt2 {
|
||||
fn from_uniform_bytes(bytes: &[u8; 64]) -> Self {
|
||||
Self([
|
||||
<Goldilocks as FromUniformBytes<32>>::from_uniform_bytes(
|
||||
bytes[..32].try_into().unwrap(),
|
||||
),
|
||||
<Goldilocks as FromUniformBytes<32>>::from_uniform_bytes(
|
||||
bytes[32..].try_into().unwrap(),
|
||||
),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
18
src/fp3.rs
18
src/fp3.rs
@@ -2,7 +2,7 @@
|
||||
|
||||
use core::iter::{Product, Sum};
|
||||
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
use ff::{Field, PrimeField};
|
||||
use ff::{Field, FromUniformBytes, PrimeField};
|
||||
use halo2curves::serde::SerdeObject;
|
||||
use rand_core::RngCore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -353,3 +353,19 @@ impl PrimeField for GoldilocksExt3 {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromUniformBytes<64> for GoldilocksExt3 {
|
||||
fn from_uniform_bytes(bytes: &[u8; 64]) -> Self {
|
||||
Self([
|
||||
<Goldilocks as FromUniformBytes<16>>::from_uniform_bytes(
|
||||
bytes[..16].try_into().unwrap(),
|
||||
),
|
||||
<Goldilocks as FromUniformBytes<16>>::from_uniform_bytes(
|
||||
bytes[16..32].try_into().unwrap(),
|
||||
),
|
||||
<Goldilocks as FromUniformBytes<16>>::from_uniform_bytes(
|
||||
bytes[32..48].try_into().unwrap(),
|
||||
),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user