|
@@ -1,23 +1,23 @@
|
|
|
|
+use crate::field::FromPrf;
|
|
use crate::permutation::Permutation;
|
|
use crate::permutation::Permutation;
|
|
-use crate::prf::{Prf, PrfKey};
|
|
|
|
use core::marker::PhantomData;
|
|
use core::marker::PhantomData;
|
|
-use ff::{Field, FromUniformBytes};
|
|
|
|
|
|
+use ff::Field;
|
|
|
|
|
|
-pub struct POTKeyParty<F, Perm> {
|
|
|
|
|
|
+pub struct POTKeyParty<F: FromPrf, Perm> {
|
|
/// log of the database size
|
|
/// log of the database size
|
|
log_domain_size: u32,
|
|
log_domain_size: u32,
|
|
/// if init was run
|
|
/// if init was run
|
|
is_initialized: bool,
|
|
is_initialized: bool,
|
|
/// PRF key of the Index Party
|
|
/// PRF key of the Index Party
|
|
- prf_key_i: Option<PrfKey>,
|
|
|
|
|
|
+ prf_key_i: Option<<F as FromPrf>::PrfKey>,
|
|
/// PRF key of the Receiver Party
|
|
/// PRF key of the Receiver Party
|
|
- prf_key_r: Option<PrfKey>,
|
|
|
|
|
|
+ prf_key_r: Option<<F as FromPrf>::PrfKey>,
|
|
/// Permutation
|
|
/// Permutation
|
|
permutation: Option<Perm>,
|
|
permutation: Option<Perm>,
|
|
_phantom: PhantomData<F>,
|
|
_phantom: PhantomData<F>,
|
|
}
|
|
}
|
|
|
|
|
|
-impl<F: Field + FromUniformBytes<{ Prf::OUT_LEN }>, Perm: Permutation> POTKeyParty<F, Perm> {
|
|
|
|
|
|
+impl<F: Field + FromPrf, Perm: Permutation> POTKeyParty<F, Perm> {
|
|
pub fn new(log_domain_size: u32) -> Self {
|
|
pub fn new(log_domain_size: u32) -> Self {
|
|
Self {
|
|
Self {
|
|
log_domain_size,
|
|
log_domain_size,
|
|
@@ -29,10 +29,10 @@ impl<F: Field + FromUniformBytes<{ Prf::OUT_LEN }>, Perm: Permutation> POTKeyPar
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn init(&mut self) -> ((PrfKey, Perm::Key), PrfKey) {
|
|
|
|
|
|
+ pub fn init(&mut self) -> ((F::PrfKey, Perm::Key), F::PrfKey) {
|
|
assert!(!self.is_initialized);
|
|
assert!(!self.is_initialized);
|
|
- self.prf_key_i = Some(Prf::key_gen());
|
|
|
|
- self.prf_key_r = Some(Prf::key_gen());
|
|
|
|
|
|
+ self.prf_key_i = Some(F::prf_key_gen());
|
|
|
|
+ self.prf_key_r = Some(F::prf_key_gen());
|
|
let permutation_key = Perm::sample(self.log_domain_size);
|
|
let permutation_key = Perm::sample(self.log_domain_size);
|
|
self.permutation = Some(Perm::from_key(permutation_key));
|
|
self.permutation = Some(Perm::from_key(permutation_key));
|
|
self.is_initialized = true;
|
|
self.is_initialized = true;
|
|
@@ -48,26 +48,25 @@ impl<F: Field + FromUniformBytes<{ Prf::OUT_LEN }>, Perm: Permutation> POTKeyPar
|
|
(0..n)
|
|
(0..n)
|
|
.map(|x| {
|
|
.map(|x| {
|
|
let pi_x = self.permutation.as_ref().unwrap().permute(x) as u64;
|
|
let pi_x = self.permutation.as_ref().unwrap().permute(x) as u64;
|
|
- Prf::eval::<F>(&self.prf_key_i.unwrap(), pi_x)
|
|
|
|
- + Prf::eval::<F>(&self.prf_key_r.unwrap(), pi_x)
|
|
|
|
|
|
+ F::prf(&self.prf_key_i.unwrap(), pi_x) + F::prf(&self.prf_key_r.unwrap(), pi_x)
|
|
})
|
|
})
|
|
.collect()
|
|
.collect()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-pub struct POTIndexParty<F, Perm> {
|
|
|
|
|
|
+pub struct POTIndexParty<F: FromPrf, Perm> {
|
|
/// log of the database size
|
|
/// log of the database size
|
|
log_domain_size: u32,
|
|
log_domain_size: u32,
|
|
/// if init was run
|
|
/// if init was run
|
|
is_initialized: bool,
|
|
is_initialized: bool,
|
|
/// PRF key of the Index Party
|
|
/// PRF key of the Index Party
|
|
- prf_key_i: Option<PrfKey>,
|
|
|
|
|
|
+ prf_key_i: Option<<F as FromPrf>::PrfKey>,
|
|
/// Permutation
|
|
/// Permutation
|
|
permutation: Option<Perm>,
|
|
permutation: Option<Perm>,
|
|
_phantom: PhantomData<F>,
|
|
_phantom: PhantomData<F>,
|
|
}
|
|
}
|
|
|
|
|
|
-impl<F: Field + FromUniformBytes<{ Prf::OUT_LEN }>, Perm: Permutation> POTIndexParty<F, Perm> {
|
|
|
|
|
|
+impl<F: Field + FromPrf, Perm: Permutation> POTIndexParty<F, Perm> {
|
|
pub fn new(log_domain_size: u32) -> Self {
|
|
pub fn new(log_domain_size: u32) -> Self {
|
|
Self {
|
|
Self {
|
|
log_domain_size,
|
|
log_domain_size,
|
|
@@ -78,30 +77,31 @@ impl<F: Field + FromUniformBytes<{ Prf::OUT_LEN }>, Perm: Permutation> POTIndexP
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn init(&mut self, prf_key_i: PrfKey, permutation_key: Perm::Key) {
|
|
|
|
|
|
+ pub fn init(&mut self, prf_key_i: F::PrfKey, permutation_key: Perm::Key) {
|
|
assert!(!self.is_initialized);
|
|
assert!(!self.is_initialized);
|
|
self.prf_key_i = Some(prf_key_i);
|
|
self.prf_key_i = Some(prf_key_i);
|
|
self.permutation = Some(Perm::from_key(permutation_key));
|
|
self.permutation = Some(Perm::from_key(permutation_key));
|
|
self.is_initialized = true;
|
|
self.is_initialized = true;
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn access(&self, index: u64) -> (F, u64) {
|
|
|
|
|
|
+ pub fn access(&self, index: u64) -> (u64, F) {
|
|
|
|
+ assert!(index < (1 << self.log_domain_size));
|
|
let pi_x = self.permutation.as_ref().unwrap().permute(index as usize) as u64;
|
|
let pi_x = self.permutation.as_ref().unwrap().permute(index as usize) as u64;
|
|
- (Prf::eval(&self.prf_key_i.unwrap(), pi_x), pi_x)
|
|
|
|
|
|
+ (pi_x, F::prf(&self.prf_key_i.unwrap(), pi_x))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-pub struct POTReceiverParty<F> {
|
|
|
|
|
|
+pub struct POTReceiverParty<F: FromPrf> {
|
|
/// log of the database size
|
|
/// log of the database size
|
|
log_domain_size: u32,
|
|
log_domain_size: u32,
|
|
/// if init was run
|
|
/// if init was run
|
|
is_initialized: bool,
|
|
is_initialized: bool,
|
|
/// PRF key of the Receiver Party
|
|
/// PRF key of the Receiver Party
|
|
- prf_key_r: Option<PrfKey>,
|
|
|
|
|
|
+ prf_key_r: Option<<F as FromPrf>::PrfKey>,
|
|
_phantom: PhantomData<F>,
|
|
_phantom: PhantomData<F>,
|
|
}
|
|
}
|
|
|
|
|
|
-impl<F: Field + FromUniformBytes<{ Prf::OUT_LEN }>> POTReceiverParty<F> {
|
|
|
|
|
|
+impl<F: Field + FromPrf> POTReceiverParty<F> {
|
|
pub fn new(log_domain_size: u32) -> Self {
|
|
pub fn new(log_domain_size: u32) -> Self {
|
|
Self {
|
|
Self {
|
|
log_domain_size,
|
|
log_domain_size,
|
|
@@ -111,13 +111,14 @@ impl<F: Field + FromUniformBytes<{ Prf::OUT_LEN }>> POTReceiverParty<F> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn init(&mut self, prf_key_r: PrfKey) {
|
|
|
|
|
|
+ pub fn init(&mut self, prf_key_r: F::PrfKey) {
|
|
assert!(!self.is_initialized);
|
|
assert!(!self.is_initialized);
|
|
self.prf_key_r = Some(prf_key_r);
|
|
self.prf_key_r = Some(prf_key_r);
|
|
self.is_initialized = true;
|
|
self.is_initialized = true;
|
|
}
|
|
}
|
|
|
|
|
|
pub fn access(&self, permuted_index: u64, output_share: F) -> F {
|
|
pub fn access(&self, permuted_index: u64, output_share: F) -> F {
|
|
- Prf::eval::<F>(&self.prf_key_r.unwrap(), permuted_index) + output_share
|
|
|
|
|
|
+ assert!(permuted_index < (1 << self.log_domain_size));
|
|
|
|
+ F::prf(&self.prf_key_r.unwrap(), permuted_index) + output_share
|
|
}
|
|
}
|
|
}
|
|
}
|