|
@@ -1,3 +1,4 @@
|
|
|
+use crate::fixed_key_aes::FixedKeyAes;
|
|
|
use blake3;
|
|
|
use ff::{Field, PrimeField};
|
|
|
use num;
|
|
@@ -36,6 +37,11 @@ pub trait FromPrf {
|
|
|
Self: Sized;
|
|
|
}
|
|
|
|
|
|
+pub trait FromPrg {
|
|
|
+ fn expand(input: u128) -> Self;
|
|
|
+ fn expand_bytes(input: &[u8]) -> Self;
|
|
|
+}
|
|
|
+
|
|
|
pub trait FromLimbs {
|
|
|
const NUM_LIMBS: usize;
|
|
|
type Limbs;
|
|
@@ -155,6 +161,30 @@ impl FromPrf for Fp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+impl FromPrg for Fp {
|
|
|
+ fn expand(input: u128) -> Self {
|
|
|
+ Self::expand_bytes(&input.to_be_bytes())
|
|
|
+ }
|
|
|
+
|
|
|
+ fn expand_bytes(input: &[u8]) -> Self {
|
|
|
+ assert_eq!(input.len(), 16);
|
|
|
+ // not really "fixed-key"
|
|
|
+ let aes = FixedKeyAes::new(input.try_into().unwrap());
|
|
|
+ let mut i = 0;
|
|
|
+ loop {
|
|
|
+ let val = aes.pi(i);
|
|
|
+ if val < Fp::MOD {
|
|
|
+ return Fp::from_limbs(&[
|
|
|
+ (val & 0xffffffffffffffff) as u64,
|
|
|
+ (val >> 64) as u64,
|
|
|
+ 0u64,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ i += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
impl FromHash for Fp {
|
|
|
/// Hash into Fp
|
|
|
fn hash(input: u64) -> Self {
|