Fp.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef __FP_HPP
  2. #define __FP_HPP
  3. #include <ostream>
  4. #include <sstream>
  5. #include <random>
  6. #include "mydouble.h"
  7. extern "C" {
  8. #include "fpe.h"
  9. #include "scalar.h"
  10. }
  11. class Fp
  12. {
  13. // Necessary for private and public keys to have access to private members
  14. friend class PrivateKey;
  15. friend class PublicKey;
  16. public:
  17. Fp();
  18. Fp(const fpe_t& input);
  19. Fp(int input);
  20. void set(const fpe_t& input);
  21. void set(int input);
  22. void set_random();
  23. Fp operator-() const;
  24. Fp operator+(const Fp& b) const;
  25. Fp operator-(const Fp& b) const;
  26. Fp operator*(const Fp& b) const;
  27. Fp operator/(const Fp& b) const;
  28. bool operator==(const Fp& b) const;
  29. bool operator!=(const Fp & b) const;
  30. bool Fp::is_zero() const;
  31. // Problem: thanks to the magic of weird typedefs, scalar_t is actually an array, which complicates returning it
  32. // Solution: make the return value a reference
  33. const scalar_t& to_scalar() const;
  34. friend std::ostream& operator<<(std::ostream& os, const Fp& output);
  35. private:
  36. unsigned long long Fp::mpz2ull(const mpz_class& n) const;
  37. fpe_t element;
  38. scalar_t scalar;
  39. bool no_change;
  40. };
  41. #endif