PublicKey.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "PublicKey.hpp"
  2. PublicKey(const Bipoint<curvepoint_fp_t>& g, const Bipoint<twistpoint_fp2_t>& h, const Bipoint<curvepoint_fp_t>& g1, const Bipoint<twistpoint_fp2_t>& h1)
  3. {
  4. set(g, h, g1, h1);
  5. }
  6. void set(const Bipoint<curvepoint_fp_t>& g, const Bipoint<twistpoint_fp2_t>& h, const Bipoint<curvepoint_fp_t>& g1, const Bipoint<twistpoint_fp2_t>& h1)
  7. {
  8. bipoint_curvegen = g;
  9. bipoint_twistgen = h;
  10. bipoint_curve_subgroup_gen = g1;
  11. bipoint_twist_subgroup_gen = h1;
  12. }
  13. void PublicKey::encrypt(Bipoint<curvepoint_fp_t>& G_element, const Scalar& cleartext) const
  14. {
  15. Scalar lambda;
  16. lambda.set_random();
  17. Bipoint<curvepoint_fp_t> cleartext_as_element, random_mask;
  18. cleartext_as_element = get_bipoint_curvegen() * cleartext;
  19. random_mask = get_bipoint_curve_subgroup_gen() * lambda;
  20. G_element = cleartext_as_element + random_mask;
  21. }
  22. void PublicKey::encrypt(Bipoint<twistpoint_fp2_t>& H_element, const Scalar& cleartext) const
  23. {
  24. Scalar lambda;
  25. lambda.set_random();
  26. Bipoint<twistpoint_fp2_t> cleartext_as_element, random_mask;
  27. cleartext_as_element = get_bipoint_twistgen() * cleartext;
  28. random_mask = get_bipoint_twist_subgroup_gen() * lambda;
  29. H_element = cleartext_as_element + random_mask;
  30. }
  31. void PublicKey::encrypt(Bipoint<curvepoint_fp_t>& G_element, Bipoint<twistpoint_fp2_t>& H_element, const Scalar& cleartext) const
  32. {
  33. encrypt(G_element, cleartext);
  34. encrypt(H_element, cleartext);
  35. }
  36. Bipoint<curvepoint_fp_t> PublicKey::get_bipoint_curvegen() const
  37. {
  38. return bipoint_curvegen;
  39. }
  40. Bipoint<twistpoint_fp2_t> PublicKey::get_bipoint_twistgen() const
  41. {
  42. return bipoint_twistgen;
  43. }
  44. Bipoint<curvepoint_fp_t> PublicKey::get_bipoint_curve_subgroup_gen() const
  45. {
  46. return bipoint_curve_subgroup_gen;
  47. }
  48. Bipoint<twistpoint_fp2_t> PublicKey::get_bipoint_twist_subgroup_gen() const
  49. {
  50. return bipoint_twist_subgroup_gen;
  51. }