hss.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <gmp.h>
  3. #include <stdint.h>
  4. #include "elgamal.h"
  5. #define SK_SIZE 160
  6. #define SK_BLOCKS ((SK_SIZE)/(SS_BASE))
  7. #define hss_init() \
  8. do { \
  9. group_init(); \
  10. mpz_entropy_init(); \
  11. dlog_precompute(); \
  12. } while (0)
  13. #define hss_clear() \
  14. do { \
  15. group_clear(); \
  16. } while (0)
  17. void hss_del();
  18. /** A level-1 share is the El-Gamal encryption of a secretly-shared value,
  19. * plus the encryption of the product of each bit.
  20. */
  21. typedef struct ssl1 {
  22. elgamal_cipher_t w;
  23. elgamal_cipher_t cw[SK_BLOCKS];
  24. } ssl1_t[1];
  25. void ssl1_init(ssl1_t s);
  26. void ssl1_clear(ssl1_t s);
  27. void ssl1_share(ssl1_t r1, ssl1_t r2, const mpz_t v, const elgamal_key_t key);
  28. void ssl1_open(mpz_t rop, const ssl1_t r1, const ssl1_t r2, const elgamal_key_t key);
  29. /** A level-2 share are subractive shares.
  30. This shares have at most 192 bits.
  31. */
  32. typedef struct ssl2 {
  33. uint32_t x;
  34. mpz_t cx;
  35. } ssl2_t[1];
  36. #define ssl2_add(rop, a, b) mpz_add(rop, a, b)
  37. void ssl2_init(ssl2_t s);
  38. void ssl2_clear(ssl2_t s);
  39. void ssl2_share(ssl2_t s1, ssl2_t s2, const mpz_t v, const mpz_t sk);
  40. void ssl2_open(mpz_t rop, const ssl2_t s1, const ssl2_t s2);
  41. void hss_mul(ssl2_t rop, const ssl1_t sl1, const ssl2_t sl2);