Skip to content

Commit

Permalink
Fix type export of dpf
Browse files Browse the repository at this point in the history
  • Loading branch information
myl7 committed Oct 6, 2023
1 parent 15d22e2 commit e60a7c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 63 deletions.
3 changes: 1 addition & 2 deletions dpf-fss/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ required-features = ["prg"]
default = ["multithread"]
prg = ["aes"]
# Not including `dcf/multithread` because we only use its traits and types
# TODO: Standalone package for the traits and types
multithread = ["rayon", "dcf/multithread"]
multithread = ["rayon"]

[dependencies]
bitvec = "1.0.1"
Expand Down
67 changes: 6 additions & 61 deletions dpf-fss/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern crate group_math as group;
pub mod prg;

use bitvec::prelude::*;
pub use dcf::CmpFn as PointFn;
pub use dcf::{CmpFn, Cw, Prg, Share};
use group::byte::utils::{xor, xor_inplace};
pub use group::Group;
Expand All @@ -17,44 +18,18 @@ use rayon::prelude::*;

/// API of Distributed point function.
///
/// See [`CmpFn`] for `N` and `LAMBDA`.
/// See [`PointFn`] for `N` and `LAMBDA`.
pub trait Dpf<const N: usize, const LAMBDA: usize, G>
where
G: Group<LAMBDA>,
{
/// `s0s` is `$s^{(0)}_0$` and `$s^{(0)}_1$` which should be randomly sampled
fn gen(&self, f: &CmpFn<N, LAMBDA, G>, s0s: [&[u8; LAMBDA]; 2]) -> Share<LAMBDA, G>;
fn gen(&self, f: &PointFn<N, LAMBDA, G>, s0s: [&[u8; LAMBDA]; 2]) -> Share<LAMBDA, G>;

/// `b` is the party. `false` is 0 and `true` is 1.
fn eval(&self, b: bool, k: &Share<LAMBDA, G>, xs: &[&[u8; N]], ys: &mut [&mut G]);
}

/// Point function.
///
/// - `N` is the **byte** size of the domain.
/// - `LAMBDA` here is used as the **byte** size of the range, unlike the one in the paper.
// pub struct CmpFn<const N: usize, const LAMBDA: usize, G>
// where
// G: Group<LAMBDA>,
// {
// /// `$\alpha$`
// pub alpha: [u8; N],
// /// `$\beta$`
// pub beta: G,
// }

/// Pseudorandom generator used in the algorithm.
///
/// `$\{0, 1\}^{\lambda} \rightarrow \{0, 1\}^{2(2\lambda + 1)}$`.
// #[cfg(feature = "multithread")]
// pub trait Prg<const LAMBDA: usize>: Sync {
// fn gen(&self, seed: &[u8; LAMBDA]) -> [([u8; LAMBDA], [u8; LAMBDA], bool); 2];
// }
// #[cfg(not(feature = "multithread"))]
// pub trait Prg<const LAMBDA: usize> {
// fn gen(&self, seed: &[u8; LAMBDA]) -> [([u8; LAMBDA], [u8; LAMBDA], bool); 2];
// }

/// Implementation of [`Dpf`].
///
/// `$\alpha$` itself is not included, which means `$f(\alpha)$ = 0`.
Expand Down Expand Up @@ -82,7 +57,7 @@ where
PrgT: Prg<LAMBDA>,
G: Group<LAMBDA>,
{
fn gen(&self, f: &CmpFn<N, LAMBDA, G>, s0s: [&[u8; LAMBDA]; 2]) -> Share<LAMBDA, G> {
fn gen(&self, f: &PointFn<N, LAMBDA, G>, s0s: [&[u8; LAMBDA]; 2]) -> Share<LAMBDA, G> {
// The bit size of `$\alpha$`
let n = 8 * N;
// let mut v_alpha = G::zero();
Expand Down Expand Up @@ -179,36 +154,6 @@ where
}
}

/// `Cw`. Correclation word.
// #[derive(Clone)]
// pub struct Cw<const LAMBDA: usize, G>
// where
// G: Group<LAMBDA>,
// {
// pub s: [u8; LAMBDA],
// pub v: G,
// pub tl: bool,
// pub tr: bool,
// }

/// `k`.
///
/// `cws` and `cw_np1` is shared by the 2 parties.
/// Only `s0s[0]` is different.
// #[derive(Clone)]
// pub struct Share<const LAMBDA: usize, G>
// where
// G: Group<LAMBDA>,
// {
// /// For the output of `gen`, its length is 2.
// /// For the input of `eval`, the first one is used.
// pub s0s: Vec<[u8; LAMBDA]>,
// /// The length of `cws` must be `n = 8 * N`
// pub cws: Vec<Cw<LAMBDA, G>>,
// /// `$CW^{(n + 1)}$`
// pub cw_np1: G,
// }

#[cfg(all(test, feature = "prg"))]
mod tests {
use super::*;
Expand Down Expand Up @@ -236,7 +181,7 @@ mod tests {
let prg = Aes256HirosePrg::new(KEYS);
let dpf = DpfImpl::<16, 16, _>::new(prg);
let s0s: [[u8; 16]; 2] = thread_rng().gen();
let f = CmpFn {
let f = PointFn {
alpha: ALPHAS[2].to_owned(),
beta: BETA.clone().into(),
};
Expand Down Expand Up @@ -267,7 +212,7 @@ mod tests {
let prg = Aes256HirosePrg::new(KEYS);
let dpf = DpfImpl::<16, 16, _>::new(prg);
let s0s: [[u8; 16]; 2] = thread_rng().gen();
let f = CmpFn {
let f = PointFn {
alpha: ALPHAS[2].to_owned(),
beta: BETA.clone().into(),
};
Expand Down

0 comments on commit e60a7c6

Please sign in to comment.