12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #ifndef __SCALAR_HPP
- #define __SCALAR_HPP
- #include <ostream>
- #include <stdlib.h>
- #include <sstream>
- #include <gmpxx.h>
- #include "Bipoint.hpp"
- #include "Quadripoint.hpp"
- #include "scalar.h"
- class Scalar
- {
- public:
- Scalar();
- Scalar(const scalar_t& input);
- Scalar(mpz_class input);
- void set(const scalar_t& input);
- void set(mpz_class input);
- void set_random();
- Scalar operator-() const;
- Scalar operator+(const Scalar& b) const;
- Scalar operator-(const Scalar& b) const;
- Scalar operator*(const Scalar& b) const;
- Scalar operator/(const Scalar& b) const;
- Scalar& operator++();
- Scalar operator++(int);
- Scalar& operator--();
- Scalar operator--(int);
- curvepoint_fp_t operator*(const curvepoint_fp_t& b) const;
- twistpoint_fp2_t operator*(const twistpoint_fp2_t& b) const;
- fp12e_t operator*(const fp12e_t& b) const;
- Bipoint<curvepoint_fp_t> operator*(const Bipoint<curvepoint_fp_t>& b) const;
- Bipoint<twistpoint_fp2_t> operator*(const Bipoint<twistpoint_fp2_t>& b) const;
- Quadripoint operator*(const Quadripoint& b) const;
- bool operator==(const Scalar& b) const;
- bool operator!=(const Scalar& b) const;
-
- friend std::ostream& operator<<(std::ostream& os, const Scalar& output);
-
- private:
- class SecretScalar
- {
- SecretScalar();
- SecretScalar(const Scalar& input);
- SecretScalar(mpz_class input);
- // 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
- // This feels bad, I know, but it will only be used in places where the variable remains in scope for the duration of usage
- const scalar_t& expose() const;
- private:
- void set(mpz_class input);
- scalar_t element;
- };
- SecretScalar to_scalar_t() const;
- static const mpz_class mpz_bn_n("8FB501E34AA387F9AA6FECB86184DC212E8D8E12F82B39241A2EF45B57AC7261", 16);
- mpz_class element;
- };
- #endif
|