client.rs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. use std::collections::HashMap;
  2. use crate::{poly::*, params::*, discrete_gaussian::*};
  3. pub struct PublicParameters<'a> {
  4. v_packing: Vec<PolyMatrixNTT<'a>>, // Ws
  5. v_expansion_left: Vec<PolyMatrixNTT<'a>>,
  6. v_expansion_right: Vec<PolyMatrixNTT<'a>>,
  7. v_conversion: PolyMatrixNTT<'a>, // V
  8. }
  9. impl<'a> PublicParameters<'a> {
  10. fn init(params: &'a Params) -> Self {
  11. PublicParameters {
  12. v_packing: Vec::new(),
  13. v_expansion_left: Vec::new(),
  14. v_expansion_right: Vec::new(),
  15. v_conversion: PolyMatrixNTT::zero(params, 2, 2 * params.m_conv())
  16. }
  17. }
  18. }
  19. pub struct Client<'a> {
  20. params: &'a Params,
  21. sk_gsw: PolyMatrixRaw<'a>,
  22. sk_reg: PolyMatrixRaw<'a>,
  23. sk_gsw_full: PolyMatrixRaw<'a>,
  24. sk_reg_full: PolyMatrixRaw<'a>,
  25. }
  26. fn matrix_with_identity<'a> (p: &PolyMatrixRaw<'a>) -> PolyMatrixRaw<'a> {
  27. assert_eq!(p.cols, 1);
  28. let mut r = PolyMatrixRaw::zero(p.params, p.rows, p.rows + 1);
  29. r.copy_into(p, 0, 0);
  30. r.copy_into(&PolyMatrixRaw::identity(p.params, p.rows, p.rows), 0, 1);
  31. r
  32. }
  33. impl<'a> Client<'a> {
  34. fn init(params: &'a Params) -> Self {
  35. let sk_gsw_dims = params.get_sk_gsw();
  36. let sk_reg_dims = params.get_sk_reg();
  37. let sk_gsw = PolyMatrixRaw::zero(params, sk_gsw_dims.0, sk_gsw_dims.1);
  38. let sk_reg = PolyMatrixRaw::zero(params, sk_reg_dims.0, sk_reg_dims.1);
  39. let sk_gsw_full = matrix_with_identity(&sk_gsw);
  40. let sk_reg_full = matrix_with_identity(&sk_reg);
  41. Self {
  42. params,
  43. sk_gsw,
  44. sk_reg,
  45. sk_gsw_full,
  46. sk_reg_full,
  47. }
  48. }
  49. fn generate_keys(&mut self) -> PublicParameters {
  50. let params = self.params;
  51. let mut dg = DiscreteGaussian::init(params);
  52. dg.sample_matrix(&mut self.sk_gsw);
  53. dg.sample_matrix(&mut self.sk_reg);
  54. self.sk_gsw_full = matrix_with_identity(&self.sk_gsw);
  55. self.sk_reg_full = matrix_with_identity(&self.sk_reg);
  56. let sk_reg_ntt = to_ntt()
  57. let pp = PublicParameters::init(params);
  58. // For packing
  59. for i in 0..params.n {
  60. MatPoly scaled = from_scalar_multiply(sk_reg_ntt, )
  61. }
  62. pp
  63. }
  64. // fn generate_query(&self) -> Query<'a, Params>;
  65. }