1use crate::core::{challenge_set::ChallengeSet, env_params::EnvironmentParameters};
2use crate::ring::poly::PolyVector;
3
4pub struct PublicPrams {
5 pub matrix_a: Vec<PolyVector>,
7 pub matrix_b: Vec<Vec<Vec<PolyVector>>>,
9 pub matrix_c: Vec<Vec<Vec<Vec<PolyVector>>>>,
11 pub matrix_d: Vec<Vec<Vec<Vec<PolyVector>>>>,
13}
14
15impl PublicPrams {
16 pub fn new(ep: &EnvironmentParameters) -> Self {
17 let d = ep.deg_bound_d;
18
19 let matrix_a = Self::challenge_matrix(ep.k, ep.n, d);
20
21 let matrix_b: Vec<Vec<Vec<PolyVector>>> = (0..ep.r)
22 .map(|_| {
23 (0..ep.t_1)
24 .map(|_| Self::challenge_matrix(ep.k_1, ep.k, d))
25 .collect()
26 })
27 .collect();
28
29 let matrix_c: Vec<Vec<Vec<Vec<PolyVector>>>> = (0..ep.r)
30 .map(|_| {
31 (0..ep.r)
32 .map(|_| {
33 (0..ep.t_2)
34 .map(|_| Self::challenge_matrix(ep.k_2, 1, d))
35 .collect()
36 })
37 .collect()
38 })
39 .collect();
40
41 let matrix_d: Vec<Vec<Vec<Vec<PolyVector>>>> = (0..ep.r)
42 .map(|_| {
43 (0..ep.r)
44 .map(|_| {
45 (0..ep.t_1)
46 .map(|_| Self::challenge_matrix(ep.k_2, 1, d))
47 .collect()
48 })
49 .collect()
50 })
51 .collect();
52
53 Self {
54 matrix_a,
55 matrix_b,
56 matrix_c,
57 matrix_d,
58 }
59 }
60
61 fn challenge_matrix(row: usize, col: usize, d: usize) -> Vec<PolyVector> {
62 (0..row)
63 .map(|_| {
64 (0..col)
65 .map(|_| ChallengeSet::new(d).get_challenges().clone())
66 .collect()
67 })
68 .collect()
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75 use std::time::Instant;
76
77 #[test]
78 fn test_crs() {
79 let ep_1 = EnvironmentParameters::default();
81
82 let total_start = Instant::now();
83 let _pp = PublicPrams::new(&ep_1);
85
86 println!(
87 "Total time for PublicPrams::new: {:?}",
88 total_start.elapsed()
89 );
90 }
91}