PaillierKeys.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (C) 2014 Carlos Aguilar Melchor, Joris Barrier, Marc-Olivier Killijian
  2. * This file is part of XPIR.
  3. *
  4. * XPIR is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * XPIR is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with XPIR. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef DEF_PAILLIER_STRUCT
  18. #define DEF_PAILLIER_STRUCT
  19. #include <cstddef>
  20. #include <gmp.h>
  21. // Maximum s such that encryption is donne from n^s to n^(s+1)
  22. #define MAX_S 7
  23. class paillier_prvkey
  24. {
  25. public:
  26. paillier_prvkey();
  27. void init_key();
  28. void clear_key();
  29. mpz_t d; /* use CRT, d = mod n^s and d = O mod lambda*/
  30. mpz_t inv_d;
  31. ~paillier_prvkey();
  32. };
  33. class paillier_pubkey
  34. {
  35. public:
  36. paillier_pubkey();
  37. paillier_pubkey(unsigned int bits, char* rawKey);
  38. ~paillier_pubkey();
  39. void init_key();
  40. void init_key(unsigned int bits, char* rawKey);
  41. void init_key(unsigned int key_bit_size);
  42. // Complete nj array up to index s
  43. void complete_key(unsigned int s);
  44. // Get nj[s] = n^s initializing it if needed
  45. mpz_t* getnj(int s);
  46. // Simple getters
  47. mpz_t* getg();
  48. int getinit_s();
  49. int getbits();
  50. // Simple setters
  51. void setinit_s(int init_s_);
  52. void setbits(int bits_);
  53. void clear_key();
  54. private:
  55. // Bit-size of the modulus
  56. int bits;
  57. // nj[s] is n^s, nj[0] is therefore 1 (should not be used)
  58. mpz_t nj[MAX_S+1];
  59. // Basic plaintext space is n^init_s and ciphertext space n^(init_s+1)
  60. unsigned int init_s;
  61. // Generator, i.e: n+1
  62. mpz_t g;
  63. // Function initializing nj[i] for i>=2 when needed
  64. void init_nj(int i);
  65. };
  66. #endif