123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #ifndef __FP_HPP
- #define __FP_HPP
- #include <ostream>
- #include <sstream>
- #include <random>
- #include <gmp.h>
- #include <gmpxx.h>
- #include "mydouble.h"
- extern "C" {
- #include "fpe.h"
- #include "scalar.h"
- }
- class Fp
- {
- // Necessary for private and public keys to have access to private members
- friend class PrivateKey;
- friend class PublicKey;
- public:
- Fp();
- Fp(const fpe_t& input);
- Fp(int input);
- void set(const fpe_t& input);
- void set(int input);
- void set_random();
- Fp operator-() const;
- Fp operator+(const Fp& b) const;
- Fp operator-(const Fp& b) const;
- Fp operator*(const Fp& b) const;
- Fp operator/(const Fp& b) const;
- bool operator==(const Fp& b) const;
- bool operator!=(const Fp & b) const;
- bool Fp::is_zero() const;
-
- // Problem: thanks to the magic of weird typedefs, scalar_t is actually an array, which complicates returning it
- // Solution: make the return value a reference
- const scalar_t& to_scalar() const;
-
- friend std::ostream& operator<<(std::ostream& os, const Fp& output);
-
- private:
- unsigned long long Fp::mpz2ull(const mpz_class& n) const;
- fpe_t element;
- scalar_t scalar;
- bool no_change;
- };
- #endif
|