fss_types/lib.rs
1// Copyright (C) myl7
2// SPDX-License-Identifier: Apache-2.0
3
4//! Some variable names still come from the paper corresponding to the crate dcf.
5
6extern crate group_math as group;
7
8pub use group::Group;
9
10/// Point function.
11/// Despite the name, it only ships an element of the domain and an element of the range.
12/// The actual meaning of the 2 elements is determined by the context.
13///
14/// - `N` is the **byte** size of the domain.
15/// - `LAMBDA` here is used as the **byte** size of the range, unlike the one in the paper.
16pub struct PointFn<const N: usize, const LAMBDA: usize, G>
17where
18 G: Group<LAMBDA>,
19{
20 /// `$\alpha$`, or say `x` in `y = f(x)`
21 pub alpha: [u8; N],
22 /// `$\beta$`, or say `y` in `y = f(x)`
23 pub beta: G,
24}
25
26#[macro_export]
27macro_rules! decl_prg_trait {
28 ($ret_elem:ty) => {
29 /// Pseudorandom generator
30 #[cfg(feature = "multithread")]
31 pub trait Prg<const LAMBDA: usize>: Sync {
32 fn gen(&self, seed: &[u8; LAMBDA]) -> [$ret_elem; 2];
33 }
34 #[cfg(not(feature = "multithread"))]
35 pub trait Prg<const LAMBDA: usize> {
36 fn gen(&self, seed: &[u8; LAMBDA]) -> [$ret_elem; 2];
37 }
38 };
39}
40
41/// `Cw`. Correclation word.
42#[derive(Clone)]
43pub struct Cw<const LAMBDA: usize, G>
44where
45 G: Group<LAMBDA>,
46{
47 pub s: [u8; LAMBDA],
48 pub v: G,
49 pub tl: bool,
50 pub tr: bool,
51}
52
53/// `k`.
54///
55/// `cws` and `cw_np1` is shared by the 2 parties.
56/// Only `s0s[0]` is different.
57#[derive(Clone)]
58pub struct Share<const LAMBDA: usize, G>
59where
60 G: Group<LAMBDA>,
61{
62 /// For the output of `gen`, its length is 2.
63 /// For the input of `eval`, the first one is used.
64 pub s0s: Vec<[u8; LAMBDA]>,
65 /// The length of `cws` must be `n = 8 * N`
66 pub cws: Vec<Cw<LAMBDA, G>>,
67 /// `$CW^{(n + 1)}$`
68 pub cw_np1: G,
69}