Clearmatics Libff  0.1
C++ library for Finite Fields and Elliptic Curves
bigint.hpp
Go to the documentation of this file.
1 
10 #ifndef BIGINT_HPP_
11 #define BIGINT_HPP_
12 #include <cstddef>
13 #include <gmp.h>
14 #include <iostream>
16 
17 namespace libff
18 {
19 
20 template<mp_size_t n> class bigint;
21 template<mp_size_t n>
22 std::ostream &operator<<(std::ostream &, const bigint<n> &);
23 template<mp_size_t n> std::istream &operator>>(std::istream &, bigint<n> &);
24 
28 template<mp_size_t n> class bigint
29 {
30 public:
31  static const mp_size_t N = n;
32 
33  mp_limb_t data[n] = {0};
34 
35  bigint() = default;
37  bigint(const unsigned long x);
39  bigint(const char *s);
41  bigint(const mpz_t r);
42 
43  void print() const;
44  void print_hex() const;
45  bool operator==(const bigint<n> &other) const;
46  bool operator!=(const bigint<n> &other) const;
47  void clear();
48  bool is_zero() const;
49 
51  static constexpr size_t max_bits() { return n * GMP_NUMB_BITS; };
52 
55  size_t num_bits() const;
56 
57  unsigned long as_ulong() const;
58  void to_mpz(mpz_t r) const;
59  bool test_bit(const std::size_t bitno) const;
60 
61  bigint &randomize();
62 
63  friend std::ostream &operator<<<n>(std::ostream &out, const bigint<n> &b);
64  friend std::istream &operator>><n>(std::istream &in, bigint<n> &b);
65 };
66 
67 } // namespace libff
68 
70 
71 #endif // BIGINT_HPP_
libff::bigint::is_zero
bool is_zero() const
libff
Definition: ffi.cpp:8
libff::bigint::to_mpz
void to_mpz(mpz_t r) const
Return the last limb of the integer.
libff::bigint::randomize
bigint & randomize()
bigint.tcc
libff::operator>>
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:446
libff::bigint::print_hex
void print_hex() const
libff::bigint::clear
void clear()
libff::bigint::bigint
bigint()=default
libff::bigint::max_bits
static constexpr size_t max_bits()
The number of bits representable by this bigint type.
Definition: bigint.hpp:51
libff::bigint::operator==
bool operator==(const bigint< n > &other) const
libff::bigint
Definition: bigint.hpp:20
libff::bigint::as_ulong
unsigned long as_ulong() const
libff::bigint::num_bits
size_t num_bits() const
libff::bigint::data
mp_limb_t data[n]
Definition: bigint.hpp:33
libff::bigint::operator!=
bool operator!=(const bigint< n > &other) const
libff::operator<<
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
Definition: alt_bn128_g1.cpp:436
serialization.hpp
libff::bigint::test_bit
bool test_bit(const std::size_t bitno) const
libff::bigint::N
static const mp_size_t N
Definition: bigint.hpp:31
libff::bigint::print
void print() const