elgamal.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "config.h"
  3. #include <gmp.h>
  4. #include "entropy.h"
  5. #include "fbase.h"
  6. typedef struct elgamal_key {
  7. mpz_t sk;
  8. mpz_t pk;
  9. } elgamal_key_t[1];
  10. typedef struct elgamal_cipher {
  11. /* NOTE: the first part is already inverted! */
  12. mpz_t c1;
  13. mpz_t c2;
  14. mpz_t c1e64;
  15. mpz_t c1e128;
  16. fbase_ptr fb_c1;
  17. fbase_ptr fb_c1e64;
  18. fbase_ptr fb_c1e128;
  19. fbase_ptr fb_c2;
  20. } elgamal_cipher_t[1];
  21. void elgamal_encrypt(elgamal_cipher_t c, const elgamal_key_t k, const mpz_t m);
  22. void elgamal_decrypt(mpz_t rop, const elgamal_key_t k, const elgamal_cipher_t c);
  23. void elgamal_keygen(elgamal_key_t key);
  24. void elgamal_cipher_init(elgamal_cipher_t c);
  25. void elgamal_cipher_clear(elgamal_cipher_t c);
  26. void elgamal_cipher_set(elgamal_cipher_t rop, const elgamal_cipher_t op1);
  27. #define ELGAMAL_KEY(func, k) \
  28. mpz_ ## func ## s(k->pk, k->sk, NULL);
  29. /* we're not instantiating just mpz_t anymore :( */
  30. #define ELGAMAL_CIPHER(func, c) \
  31. elgamal_cipher_ ## func(c)
  32. #define elgamal_encrypt_shares(share1, share2, key, plaintext) \
  33. elgamal_encrypt(share1, key, plaintext); \
  34. elgamal_cipher_set(share2, share1)