Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::bigint Class Reference

#include <bigint.hpp>

Public Member Functions

 bigint (const std::vector< char > &bige)
 
 bigint (const char *bige, uint32_t l)
 
 bigint (uint64_t value)
 
 bigint ()
 
 bigint (const bigint &c)
 
 bigint (bigint &&c)
 
 bigint (BIGNUM *n)
 
 ~bigint ()
 
bigintoperator= (const bigint &a)
 
bigintoperator= (bigint &&a)
 
 operator bool () const
 
bool is_negative () const
 
int64_t to_int64 () const
 
int64_t log2 () const
 
bigint exp (const bigint &c) const
 
bool operator< (const bigint &c) const
 
bool operator> (const bigint &c) const
 
bool operator>= (const bigint &c) const
 
bool operator== (const bigint &c) const
 
bool operator!= (const bigint &c) const
 
bigint operator+ (const bigint &a) const
 
bigint operator* (const bigint &a) const
 
bigint operator/ (const bigint &a) const
 
bigint operator% (const bigint &a) const
 
bigint operator/= (const bigint &a)
 
bigint operator*= (const bigint &a)
 
bigintoperator+= (const bigint &a)
 
bigintoperator-= (const bigint &a)
 
bigintoperator<<= (uint32_t i)
 
bigintoperator>>= (uint32_t i)
 
bigint operator- (const bigint &a) const
 
bigint operator++ (int)
 
bigintoperator++ ()
 
bigint operator-- (int)
 
bigintoperator-- ()
 
 operator fc::string () const
 
 operator std::vector< char > () const
 
BIGNUMdup () const
 
BIGNUMget () const
 

Static Public Member Functions

static bigint random (uint32_t bits, int t, int)
 

Detailed Description

Definition at line 10 of file bigint.hpp.

Constructor & Destructor Documentation

◆ bigint() [1/7]

fc::bigint::bigint ( const std::vector< char > & bige)

Definition at line 15 of file bigint.cpp.

15 {
16 n = BN_bin2bn( (const unsigned char*)bige.data(), bige.size(), NULL );
17 FC_ASSERT( n != nullptr );
18 }
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.

◆ bigint() [2/7]

fc::bigint::bigint ( const char * bige,
uint32_t l )

Definition at line 11 of file bigint.cpp.

11 {
12 n = BN_bin2bn( (const unsigned char*)bige, l, NULL );
13 FC_ASSERT( n != nullptr );
14 }
int l

◆ bigint() [3/7]

fc::bigint::bigint ( uint64_t value)

Definition at line 32 of file bigint.cpp.

33 {
34 uint64_t big_endian_value = bswap_64(value);
35 n = BN_bin2bn((const unsigned char*)&big_endian_value, sizeof(big_endian_value), NULL);
36 }
#define value
Definition pkcs11.h:157
unsigned __int64 uint64_t
Definition stdint.h:136

◆ bigint() [4/7]

fc::bigint::bigint ( )

Definition at line 23 of file bigint.cpp.

24 :n(BN_new())
25 { }
Here is the caller graph for this function:

◆ bigint() [5/7]

fc::bigint::bigint ( const bigint & c)

Definition at line 38 of file bigint.cpp.

38 {
39 n = BN_dup( c.n );
40 }

◆ bigint() [6/7]

fc::bigint::bigint ( bigint && c)

Definition at line 42 of file bigint.cpp.

42 {
43 n = b.n;
44 b.n = 0;
45 }

◆ bigint() [7/7]

fc::bigint::bigint ( BIGNUM * n)
explicit

Definition at line 19 of file bigint.cpp.

20 {
21 n = BN_dup(in);
22 }

◆ ~bigint()

fc::bigint::~bigint ( )

Definition at line 47 of file bigint.cpp.

47 {
48 if(n!=0) BN_free(n);
49 }

Member Function Documentation

◆ dup()

BIGNUM * fc::bigint::dup ( ) const

Definition at line 27 of file bigint.cpp.

28 {
29 return BN_dup( n );
30 }

◆ exp()

bigint fc::bigint::exp ( const bigint & c) const

Definition at line 180 of file bigint.cpp.

181 {
182 BN_CTX* ctx = BN_CTX_new();
183 bigint tmp;
184 BN_exp( tmp.n, n, a.n, ctx );
185 BN_CTX_free(ctx);
186 return tmp;
187 }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
Here is the caller graph for this function:

◆ get()

BIGNUM * fc::bigint::get ( ) const
inline

Definition at line 65 of file bigint.hpp.

65{ return n; }

◆ is_negative()

bool fc::bigint::is_negative ( ) const

Definition at line 51 of file bigint.cpp.

51{ return BN_is_negative(n); }

◆ log2()

int64_t fc::bigint::log2 ( ) const

Definition at line 62 of file bigint.cpp.

62{ return BN_num_bits(n); }

◆ operator bool()

fc::bigint::operator bool ( ) const
explicit

Definition at line 78 of file bigint.cpp.

79 {
80 return !BN_is_zero( n );
81 }

◆ operator fc::string()

fc::bigint::operator fc::string ( ) const

Definition at line 200 of file bigint.cpp.

200 {
201 return BN_bn2dec(n);
202 }

◆ operator std::vector< char >()

fc::bigint::operator std::vector< char > ( ) const

Definition at line 204 of file bigint.cpp.

204 {
205 std::vector<char> to(BN_num_bytes(n));
206 BN_bn2bin(n,(unsigned char*)to.data());
207 return to;
208 }

◆ operator!=()

bool fc::bigint::operator!= ( const bigint & c) const

Definition at line 75 of file bigint.cpp.

75 {
76 return BN_cmp( n, c.n ) != 0;
77 }

◆ operator%()

bigint fc::bigint::operator% ( const bigint & a) const

Definition at line 136 of file bigint.cpp.

136 {
137 BN_CTX* ctx = BN_CTX_new();
138 bigint tmp;//(*this);
139 BN_mod( tmp.n, n, a.n, ctx );
140 BN_CTX_free(ctx);
141 return tmp;
142 }

◆ operator*()

bigint fc::bigint::operator* ( const bigint & a) const

Definition at line 122 of file bigint.cpp.

122 {
123 BN_CTX* ctx = BN_CTX_new();
124 bigint tmp(*this);
125 BN_mul( tmp.n, n, a.n, ctx );
126 BN_CTX_free(ctx);
127 return tmp;
128 }

◆ operator*=()

bigint fc::bigint::operator*= ( const bigint & a)

Definition at line 152 of file bigint.cpp.

152 {
153 auto tmp = *this * a;
154 *this = std::move(tmp);
155 return *this;
156 }

◆ operator+()

bigint fc::bigint::operator+ ( const bigint & a) const

Definition at line 103 of file bigint.cpp.

103 {
104 bigint tmp(*this);
105 BN_add( tmp.n, n, a.n );
106 return tmp;
107 }

◆ operator++() [1/2]

bigint & fc::bigint::operator++ ( )

Definition at line 88 of file bigint.cpp.

89 {
90 return *this = *this + bigint(1);
91 }
Here is the call graph for this function:

◆ operator++() [2/2]

bigint fc::bigint::operator++ ( int )

Definition at line 82 of file bigint.cpp.

83 {
84 bigint tmp = *this;
85 *this = *this + bigint(1);
86 return tmp;
87 }
Here is the call graph for this function:

◆ operator+=()

bigint & fc::bigint::operator+= ( const bigint & a)

Definition at line 108 of file bigint.cpp.

108 {
109 bigint tmp(*this);
110 BN_add( tmp.n, n, a.n );
111 std::swap(*this,tmp);
112 return *this;
113 }
void swap(picojson::value &x, picojson::value &y)
Here is the call graph for this function:

◆ operator-()

bigint fc::bigint::operator- ( const bigint & a) const

Definition at line 175 of file bigint.cpp.

175 {
176 bigint tmp;
177 BN_sub( tmp.n, n, a.n );
178 return tmp;
179 }

◆ operator--() [1/2]

bigint & fc::bigint::operator-- ( )

Definition at line 98 of file bigint.cpp.

99 {
100 return *this = *this - bigint(1);
101 }
Here is the call graph for this function:

◆ operator--() [2/2]

bigint fc::bigint::operator-- ( int )

Definition at line 92 of file bigint.cpp.

93 {
94 bigint tmp = *this;
95 *this = *this - bigint(1);
96 return tmp;
97 }
Here is the call graph for this function:

◆ operator-=()

bigint & fc::bigint::operator-= ( const bigint & a)

Definition at line 114 of file bigint.cpp.

114 {
115 bigint tmp(*this);
116 BN_sub( tmp.n, n, a.n );
117 std::swap(*this,tmp);
118 return *this;
119 }
Here is the call graph for this function:

◆ operator/()

bigint fc::bigint::operator/ ( const bigint & a) const

Definition at line 129 of file bigint.cpp.

129 {
130 BN_CTX* ctx = BN_CTX_new();
131 bigint tmp;//(*this);
132 BN_div( tmp.n, NULL, n, a.n, ctx );
133 BN_CTX_free(ctx);
134 return tmp;
135 }

◆ operator/=()

bigint fc::bigint::operator/= ( const bigint & a)

Definition at line 144 of file bigint.cpp.

144 {
145 BN_CTX* ctx = BN_CTX_new();
146 bigint tmp;//*this);
147 BN_div( tmp.n, NULL, n, a.n, ctx );
148 fc_swap( tmp.n, n );
149 BN_CTX_free(ctx);
150 return tmp;
151 }
void fc_swap(T &a, T &b)
Definition utility.hpp:211
Here is the call graph for this function:

◆ operator<()

bool fc::bigint::operator< ( const bigint & c) const

Definition at line 63 of file bigint.cpp.

63 {
64 return BN_cmp( n, c.n ) < 0;
65 }

◆ operator<<=()

bigint & fc::bigint::operator<<= ( uint32_t i)

Definition at line 165 of file bigint.cpp.

166 {
167 bigint tmp;
168 FC_ASSERT( tmp.n != nullptr );
169 FC_ASSERT( n != nullptr );
170 BN_lshift( tmp.n, n, i );
171 std::swap(*this,tmp);
172 return *this;
173 }
Here is the call graph for this function:

◆ operator=() [1/2]

bigint & fc::bigint::operator= ( bigint && a)

Definition at line 190 of file bigint.cpp.

190 {
191 fc_swap( a.n, n );
192 return *this;
193 }
Here is the call graph for this function:

◆ operator=() [2/2]

bigint & fc::bigint::operator= ( const bigint & a)

Definition at line 194 of file bigint.cpp.

194 {
195 if( &a == this )
196 return *this;
197 BN_copy( n, a.n );
198 return *this;
199 }

◆ operator==()

bool fc::bigint::operator== ( const bigint & c) const

Definition at line 72 of file bigint.cpp.

72 {
73 return BN_cmp( n, c.n ) == 0;
74 }

◆ operator>()

bool fc::bigint::operator> ( const bigint & c) const

Definition at line 66 of file bigint.cpp.

66 {
67 return BN_cmp( n, c.n ) > 0;
68 }

◆ operator>=()

bool fc::bigint::operator>= ( const bigint & c) const

Definition at line 69 of file bigint.cpp.

69 {
70 return BN_cmp( n, c.n ) >= 0;
71 }

◆ operator>>=()

bigint & fc::bigint::operator>>= ( uint32_t i)

Definition at line 157 of file bigint.cpp.

158 {
159 bigint tmp;
160 BN_rshift( tmp.n, n, i );
161 std::swap(*this,tmp);
162 return *this;
163 }
Here is the call graph for this function:

◆ random()

static bigint fc::bigint::random ( uint32_t bits,
int t,
int  )
static

◆ to_int64()

int64_t fc::bigint::to_int64 ( ) const

Definition at line 53 of file bigint.cpp.

54 {
55 FC_ASSERT(BN_num_bits(n) <= 63);
56 size_t size = BN_num_bytes(n);
57 uint64_t abs_value = 0;
58 BN_bn2bin(n, (unsigned char*)&abs_value + (sizeof(uint64_t) - size));
59 return BN_is_negative(n) ? -(int64_t)bswap_64(abs_value) : bswap_64(abs_value);
60 }
signed __int64 int64_t
Definition stdint.h:135

The documentation for this class was generated from the following files: