/** @file ***************************************************************************** Declaration of bigint wrapper class around GMP's MPZ long integers. ***************************************************************************** * @author This file is part of libsnark, developed by SCIPR Lab * and contributors (see AUTHORS). * @copyright MIT license (see LICENSE file) *****************************************************************************/ #ifndef BIGINT_HPP_ #define BIGINT_HPP_ #include #include #include #include "common/serialization.hpp" namespace libsnark { template class bigint; template std::ostream& operator<<(std::ostream &, const bigint&); template std::istream& operator>>(std::istream &, bigint&); /** * Wrapper class around GMP's MPZ long integers. It supports arithmetic operations, * serialization and randomization. Serialization is fragile, see common/serialization.hpp. */ template class bigint { public: static const mp_size_t N = n; mp_limb_t data[n] = {0}; bigint() = default; bigint(const unsigned long x); /// Initialize from a small integer bigint(const char* s); /// Initialize from a string containing an integer in decimal notation bigint(const mpz_t r); /// Initialize from MPZ element void print() const; void print_hex() const; bool operator==(const bigint& other) const; bool operator!=(const bigint& other) const; void clear(); bool is_zero() const; size_t max_bits() const { return n * GMP_NUMB_BITS; } size_t num_bits() const; unsigned long as_ulong() const; /* return the last limb of the integer */ void to_mpz(mpz_t r) const; bool test_bit(const std::size_t bitno) const; template inline void operator+=(const bigint& other); template inline bigint operator*(const bigint& other) const; template static inline void div_qr(bigint& quotient, bigint& remainder, const bigint& dividend, const bigint& divisor); template inline bigint shorten(const bigint& q, const char *msg) const; inline void limit(const bigint& q, const char *msg) const; bool operator>(const bigint& other) const; bigint& randomize(); friend std::ostream& operator<< (std::ostream &out, const bigint &b); friend std::istream& operator>> (std::istream &in, bigint &b); }; } // libsnark #include "algebra/fields/bigint.tcc" #endif