pk-crypto.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. \file pk-crypto.h
  3. \author michael.zohner@ec-spride.de
  4. \copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
  5. Copyright (C) 2019 ENCRYPTO Group, TU Darmstadt
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. ABY is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. \brief Virtual class for public-key operations
  17. */
  18. #ifndef PK_CRYPTO_H_
  19. #define PK_CRYPTO_H_
  20. #include "../typedefs.h"
  21. #include "../constants.h"
  22. #include "../utils.h"
  23. class pk_crypto;
  24. class num;
  25. class fe;
  26. class brickexp;
  27. class pk_crypto {
  28. public:
  29. pk_crypto(seclvl sp) {
  30. fe_bytelen = 0;
  31. order = 0;
  32. secparam = sp;
  33. }
  34. ;
  35. virtual ~pk_crypto() {};
  36. virtual num* get_num() = 0;
  37. virtual num* get_rnd_num(uint32_t bitlen = 0) = 0;
  38. virtual fe* get_fe() = 0;
  39. virtual fe* get_rnd_fe() = 0;
  40. virtual fe* get_generator() = 0;
  41. virtual fe* get_rnd_generator() = 0;
  42. virtual uint32_t num_byte_size() = 0;
  43. virtual num* get_order() = 0;
  44. uint32_t fe_byte_size() {
  45. return fe_bytelen;
  46. }
  47. ;
  48. virtual uint32_t get_field_size() = 0;
  49. virtual brickexp* get_brick(fe* gen) = 0;
  50. protected:
  51. virtual void init(seclvl secparam, uint8_t* seed) = 0;
  52. uint32_t fe_bytelen;
  53. seclvl secparam;
  54. num* order;
  55. };
  56. //class number
  57. class num {
  58. public:
  59. num() {
  60. }
  61. ;
  62. virtual ~num() {};
  63. virtual void set(num* src) = 0;
  64. virtual void set_si(int32_t src) = 0;
  65. virtual void set_add(num* a, num* b) = 0;
  66. virtual void set_sub(num* a, num* b) = 0;
  67. virtual void set_mul(num* a, num* b) = 0;
  68. virtual void mod(num* modulus) = 0;
  69. virtual void set_mul_mod(num* a, num* b, num* modulus) = 0;
  70. virtual void export_to_bytes(uint8_t* buf, uint32_t field_size) = 0;
  71. virtual void import_from_bytes(uint8_t* buf, uint32_t field_size) = 0;
  72. virtual void print() = 0;
  73. };
  74. //class field_element
  75. class fe {
  76. public:
  77. fe() {
  78. }
  79. ;
  80. virtual ~fe() {};
  81. virtual void set(fe* src) = 0;
  82. virtual void set_mul(fe* a, fe* b) = 0;
  83. virtual void set_pow(fe* b, num* e) = 0;
  84. virtual void set_div(fe* a, fe* b) = 0;
  85. virtual void set_double_pow_mul(fe* b1, num* e1, fe* b2, num* e2) = 0;
  86. virtual void export_to_bytes(uint8_t* buf) = 0;
  87. virtual void import_from_bytes(uint8_t* buf) = 0;
  88. virtual void sample_fe_from_bytes(uint8_t* buf, uint32_t bytelen) = 0;
  89. virtual void print() = 0;
  90. virtual bool eq(fe* a) = 0;
  91. protected:
  92. virtual void init() = 0;
  93. };
  94. class brickexp {
  95. public:
  96. brickexp() {
  97. }
  98. ;
  99. virtual ~brickexp() {};
  100. virtual void pow(fe* result, num* e) = 0;
  101. };
  102. #endif /* PK_CRYPTO_H_ */