Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
bignum.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_BIGNUM_H
6 #define BITCOIN_BIGNUM_H
7 
8 #include <stdexcept>
9 #include <vector>
10 #include <openssl/bn.h>
11 
12 #include "util.h" // for uint64
13 
15 class bignum_error : public std::runtime_error
16 {
17 public:
18  explicit bignum_error(const std::string& str) : std::runtime_error(str) {}
19 };
20 
21 
24 {
25 protected:
26  BN_CTX* pctx;
27  BN_CTX* operator=(BN_CTX* pnew) { return pctx = pnew; }
28 
29 public:
31  {
32  pctx = BN_CTX_new();
33  if (pctx == NULL)
34  throw bignum_error("CAutoBN_CTX : BN_CTX_new() returned NULL");
35  }
36 
38  {
39  if (pctx != NULL)
40  BN_CTX_free(pctx);
41  }
42 
43  operator BN_CTX*() { return pctx; }
44  BN_CTX& operator*() { return *pctx; }
45  BN_CTX** operator&() { return &pctx; }
46  bool operator!() { return (pctx == NULL); }
47 };
48 
49 
51 class CBigNum : public BIGNUM
52 {
53 public:
55  {
56  BN_init(this);
57  }
58 
59  CBigNum(const CBigNum& b)
60  {
61  BN_init(this);
62  if (!BN_copy(this, &b))
63  {
64  BN_clear_free(this);
65  throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed");
66  }
67  }
68 
70  {
71  if (!BN_copy(this, &b))
72  throw bignum_error("CBigNum::operator= : BN_copy failed");
73  return (*this);
74  }
75 
77  {
78  BN_clear_free(this);
79  }
80 
81  //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
82  CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
83  CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
84  CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
85  CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
86  CBigNum(int64 n) { BN_init(this); setint64(n); }
87  CBigNum(unsigned char n) { BN_init(this); setulong(n); }
88  CBigNum(unsigned short n) { BN_init(this); setulong(n); }
89  CBigNum(unsigned int n) { BN_init(this); setulong(n); }
90  CBigNum(unsigned long n) { BN_init(this); setulong(n); }
91  CBigNum(uint64 n) { BN_init(this); setuint64(n); }
92  explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); }
93 
94  explicit CBigNum(const std::vector<unsigned char>& vch)
95  {
96  BN_init(this);
97  setvch(vch);
98  }
99 
100  void setulong(unsigned long n)
101  {
102  if (!BN_set_word(this, n))
103  throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
104  }
105 
106  unsigned long getulong() const
107  {
108  return BN_get_word(this);
109  }
110 
111  unsigned int getuint() const
112  {
113  return BN_get_word(this);
114  }
115 
116  int getint() const
117  {
118  unsigned long n = BN_get_word(this);
119  if (!BN_is_negative(this))
120  return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
121  else
122  return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
123  }
124 
125  void setint64(int64 sn)
126  {
127  unsigned char pch[sizeof(sn) + 6];
128  unsigned char* p = pch + 4;
129  bool fNegative;
130  uint64 n;
131 
132  if (sn < (int64)0)
133  {
134  // Since the minimum signed integer cannot be represented as positive so long as its type is signed,
135  // and it's not well-defined what happens if you make it unsigned before negating it,
136  // we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
137  n = -(sn + 1);
138  ++n;
139  fNegative = true;
140  } else {
141  n = sn;
142  fNegative = false;
143  }
144 
145  bool fLeadingZeroes = true;
146  for (int i = 0; i < 8; i++)
147  {
148  unsigned char c = (n >> 56) & 0xff;
149  n <<= 8;
150  if (fLeadingZeroes)
151  {
152  if (c == 0)
153  continue;
154  if (c & 0x80)
155  *p++ = (fNegative ? 0x80 : 0);
156  else if (fNegative)
157  c |= 0x80;
158  fLeadingZeroes = false;
159  }
160  *p++ = c;
161  }
162  unsigned int nSize = p - (pch + 4);
163  pch[0] = (nSize >> 24) & 0xff;
164  pch[1] = (nSize >> 16) & 0xff;
165  pch[2] = (nSize >> 8) & 0xff;
166  pch[3] = (nSize) & 0xff;
167  BN_mpi2bn(pch, p - pch, this);
168  }
169 
171  {
172  unsigned char pch[sizeof(n) + 6];
173  unsigned char* p = pch + 4;
174  bool fLeadingZeroes = true;
175  for (int i = 0; i < 8; i++)
176  {
177  unsigned char c = (n >> 56) & 0xff;
178  n <<= 8;
179  if (fLeadingZeroes)
180  {
181  if (c == 0)
182  continue;
183  if (c & 0x80)
184  *p++ = 0;
185  fLeadingZeroes = false;
186  }
187  *p++ = c;
188  }
189  unsigned int nSize = p - (pch + 4);
190  pch[0] = (nSize >> 24) & 0xff;
191  pch[1] = (nSize >> 16) & 0xff;
192  pch[2] = (nSize >> 8) & 0xff;
193  pch[3] = (nSize) & 0xff;
194  BN_mpi2bn(pch, p - pch, this);
195  }
196 
198  {
199  unsigned char pch[sizeof(n) + 6];
200  unsigned char* p = pch + 4;
201  bool fLeadingZeroes = true;
202  unsigned char* pbegin = (unsigned char*)&n;
203  unsigned char* psrc = pbegin + sizeof(n);
204  while (psrc != pbegin)
205  {
206  unsigned char c = *(--psrc);
207  if (fLeadingZeroes)
208  {
209  if (c == 0)
210  continue;
211  if (c & 0x80)
212  *p++ = 0;
213  fLeadingZeroes = false;
214  }
215  *p++ = c;
216  }
217  unsigned int nSize = p - (pch + 4);
218  pch[0] = (nSize >> 24) & 0xff;
219  pch[1] = (nSize >> 16) & 0xff;
220  pch[2] = (nSize >> 8) & 0xff;
221  pch[3] = (nSize >> 0) & 0xff;
222  BN_mpi2bn(pch, p - pch, this);
223  }
224 
226  {
227  unsigned int nSize = BN_bn2mpi(this, NULL);
228  if (nSize < 4)
229  return 0;
230  std::vector<unsigned char> vch(nSize);
231  BN_bn2mpi(this, &vch[0]);
232  if (vch.size() > 4)
233  vch[4] &= 0x7f;
234  uint256 n = 0;
235  for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
236  ((unsigned char*)&n)[i] = vch[j];
237  return n;
238  }
239 
240  void setvch(const std::vector<unsigned char>& vch)
241  {
242  std::vector<unsigned char> vch2(vch.size() + 4);
243  unsigned int nSize = vch.size();
244  // BIGNUM's byte stream format expects 4 bytes of
245  // big endian size data info at the front
246  vch2[0] = (nSize >> 24) & 0xff;
247  vch2[1] = (nSize >> 16) & 0xff;
248  vch2[2] = (nSize >> 8) & 0xff;
249  vch2[3] = (nSize >> 0) & 0xff;
250  // swap data to big endian
251  reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
252  BN_mpi2bn(&vch2[0], vch2.size(), this);
253  }
254 
255  std::vector<unsigned char> getvch() const
256  {
257  unsigned int nSize = BN_bn2mpi(this, NULL);
258  if (nSize <= 4)
259  return std::vector<unsigned char>();
260  std::vector<unsigned char> vch(nSize);
261  BN_bn2mpi(this, &vch[0]);
262  vch.erase(vch.begin(), vch.begin() + 4);
263  reverse(vch.begin(), vch.end());
264  return vch;
265  }
266 
267  // The "compact" format is a representation of a whole
268  // number N using an unsigned 32bit number similar to a
269  // floating point format.
270  // The most significant 8 bits are the unsigned exponent of base 256.
271  // This exponent can be thought of as "number of bytes of N".
272  // The lower 23 bits are the mantissa.
273  // Bit number 24 (0x800000) represents the sign of N.
274  // N = (-1^sign) * mantissa * 256^(exponent-3)
275  //
276  // Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn().
277  // MPI uses the most significant bit of the first byte as sign.
278  // Thus 0x1234560000 is compact (0x05123456)
279  // and 0xc0de000000 is compact (0x0600c0de)
280  // (0x05c0de00) would be -0x40de000000
281  //
282  // Bitcoin only uses this "compact" format for encoding difficulty
283  // targets, which are unsigned 256bit quantities. Thus, all the
284  // complexities of the sign bit and using base 256 are probably an
285  // implementation accident.
286  //
287  // This implementation directly uses shifts instead of going
288  // through an intermediate MPI representation.
289  CBigNum& SetCompact(unsigned int nCompact)
290  {
291  unsigned int nSize = nCompact >> 24;
292  bool fNegative =(nCompact & 0x00800000) != 0;
293  unsigned int nWord = nCompact & 0x007fffff;
294  if (nSize <= 3)
295  {
296  nWord >>= 8*(3-nSize);
297  BN_set_word(this, nWord);
298  }
299  else
300  {
301  BN_set_word(this, nWord);
302  BN_lshift(this, this, 8*(nSize-3));
303  }
304  BN_set_negative(this, fNegative);
305  return *this;
306  }
307 
308  unsigned int GetCompact() const
309  {
310  unsigned int nSize = BN_num_bytes(this);
311  unsigned int nCompact = 0;
312  if (nSize <= 3)
313  nCompact = BN_get_word(this) << 8*(3-nSize);
314  else
315  {
316  CBigNum bn;
317  BN_rshift(&bn, this, 8*(nSize-3));
318  nCompact = BN_get_word(&bn);
319  }
320  // The 0x00800000 bit denotes the sign.
321  // Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
322  if (nCompact & 0x00800000)
323  {
324  nCompact >>= 8;
325  nSize++;
326  }
327  nCompact |= nSize << 24;
328  nCompact |= (BN_is_negative(this) ? 0x00800000 : 0);
329  return nCompact;
330  }
331 
332  void SetHex(const std::string& str)
333  {
334  // skip 0x
335  const char* psz = str.c_str();
336  while (isspace(*psz))
337  psz++;
338  bool fNegative = false;
339  if (*psz == '-')
340  {
341  fNegative = true;
342  psz++;
343  }
344  if (psz[0] == '0' && tolower(psz[1]) == 'x')
345  psz += 2;
346  while (isspace(*psz))
347  psz++;
348 
349  // hex string to bignum
350  static const signed char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 };
351  *this = 0;
352  while (isxdigit(*psz))
353  {
354  *this <<= 4;
355  int n = phexdigit[(unsigned char)*psz++];
356  *this += n;
357  }
358  if (fNegative)
359  *this = 0 - *this;
360  }
361 
362  std::string ToString(int nBase=10) const
363  {
364  CAutoBN_CTX pctx;
365  CBigNum bnBase = nBase;
366  CBigNum bn0 = 0;
367  std::string str;
368  CBigNum bn = *this;
369  BN_set_negative(&bn, false);
370  CBigNum dv;
371  CBigNum rem;
372  if (BN_cmp(&bn, &bn0) == 0)
373  return "0";
374  while (BN_cmp(&bn, &bn0) > 0)
375  {
376  if (!BN_div(&dv, &rem, &bn, &bnBase, pctx))
377  throw bignum_error("CBigNum::ToString() : BN_div failed");
378  bn = dv;
379  unsigned int c = rem.getulong();
380  str += "0123456789abcdef"[c];
381  }
382  if (BN_is_negative(this))
383  str += "-";
384  reverse(str.begin(), str.end());
385  return str;
386  }
387 
388  std::string GetHex() const
389  {
390  return ToString(16);
391  }
392 
393  unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const
394  {
395  return ::GetSerializeSize(getvch(), nType, nVersion);
396  }
397 
398  template<typename Stream>
399  void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const
400  {
401  ::Serialize(s, getvch(), nType, nVersion);
402  }
403 
404  template<typename Stream>
405  void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION)
406  {
407  std::vector<unsigned char> vch;
408  ::Unserialize(s, vch, nType, nVersion);
409  setvch(vch);
410  }
411 
412 
413  bool operator!() const
414  {
415  return BN_is_zero(this);
416  }
417 
419  {
420  if (!BN_add(this, this, &b))
421  throw bignum_error("CBigNum::operator+= : BN_add failed");
422  return *this;
423  }
424 
426  {
427  *this = *this - b;
428  return *this;
429  }
430 
432  {
433  CAutoBN_CTX pctx;
434  if (!BN_mul(this, this, &b, pctx))
435  throw bignum_error("CBigNum::operator*= : BN_mul failed");
436  return *this;
437  }
438 
440  {
441  *this = *this / b;
442  return *this;
443  }
444 
446  {
447  *this = *this % b;
448  return *this;
449  }
450 
451  CBigNum& operator<<=(unsigned int shift)
452  {
453  if (!BN_lshift(this, this, shift))
454  throw bignum_error("CBigNum:operator<<= : BN_lshift failed");
455  return *this;
456  }
457 
458  CBigNum& operator>>=(unsigned int shift)
459  {
460  // Note: BN_rshift segfaults on 64-bit if 2^shift is greater than the number
461  // if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL
462  CBigNum a = 1;
463  a <<= shift;
464  if (BN_cmp(&a, this) > 0)
465  {
466  *this = 0;
467  return *this;
468  }
469 
470  if (!BN_rshift(this, this, shift))
471  throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
472  return *this;
473  }
474 
475 
477  {
478  // prefix operator
479  if (!BN_add(this, this, BN_value_one()))
480  throw bignum_error("CBigNum::operator++ : BN_add failed");
481  return *this;
482  }
483 
484  const CBigNum operator++(int)
485  {
486  // postfix operator
487  const CBigNum ret = *this;
488  ++(*this);
489  return ret;
490  }
491 
493  {
494  // prefix operator
495  CBigNum r;
496  if (!BN_sub(&r, this, BN_value_one()))
497  throw bignum_error("CBigNum::operator-- : BN_sub failed");
498  *this = r;
499  return *this;
500  }
501 
502  const CBigNum operator--(int)
503  {
504  // postfix operator
505  const CBigNum ret = *this;
506  --(*this);
507  return ret;
508  }
509 
510 
511  friend inline const CBigNum operator-(const CBigNum& a, const CBigNum& b);
512  friend inline const CBigNum operator/(const CBigNum& a, const CBigNum& b);
513  friend inline const CBigNum operator%(const CBigNum& a, const CBigNum& b);
514 };
515 
516 
517 
518 inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
519 {
520  CBigNum r;
521  if (!BN_add(&r, &a, &b))
522  throw bignum_error("CBigNum::operator+ : BN_add failed");
523  return r;
524 }
525 
526 inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
527 {
528  CBigNum r;
529  if (!BN_sub(&r, &a, &b))
530  throw bignum_error("CBigNum::operator- : BN_sub failed");
531  return r;
532 }
533 
534 inline const CBigNum operator-(const CBigNum& a)
535 {
536  CBigNum r(a);
537  BN_set_negative(&r, !BN_is_negative(&r));
538  return r;
539 }
540 
541 inline const CBigNum operator*(const CBigNum& a, const CBigNum& b)
542 {
543  CAutoBN_CTX pctx;
544  CBigNum r;
545  if (!BN_mul(&r, &a, &b, pctx))
546  throw bignum_error("CBigNum::operator* : BN_mul failed");
547  return r;
548 }
549 
550 inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
551 {
552  CAutoBN_CTX pctx;
553  CBigNum r;
554  if (!BN_div(&r, NULL, &a, &b, pctx))
555  throw bignum_error("CBigNum::operator/ : BN_div failed");
556  return r;
557 }
558 
559 inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
560 {
561  CAutoBN_CTX pctx;
562  CBigNum r;
563  if (!BN_mod(&r, &a, &b, pctx))
564  throw bignum_error("CBigNum::operator% : BN_div failed");
565  return r;
566 }
567 
568 inline const CBigNum operator<<(const CBigNum& a, unsigned int shift)
569 {
570  CBigNum r;
571  if (!BN_lshift(&r, &a, shift))
572  throw bignum_error("CBigNum:operator<< : BN_lshift failed");
573  return r;
574 }
575 
576 inline const CBigNum operator>>(const CBigNum& a, unsigned int shift)
577 {
578  CBigNum r = a;
579  r >>= shift;
580  return r;
581 }
582 
583 inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); }
584 inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); }
585 inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); }
586 inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
587 inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); }
588 inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); }
589 
590 #endif
CBigNum(unsigned int n)
Definition: bignum.h:89
CBigNum(uint64 n)
Definition: bignum.h:91
const CBigNum operator-(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:526
BN_CTX ** operator&()
Definition: bignum.h:45
bool operator!=(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:584
CBigNum(unsigned long n)
Definition: bignum.h:90
bool operator==(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:583
uint256 getuint256() const
Definition: bignum.h:225
bool operator<(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:587
CBigNum(short n)
Definition: bignum.h:83
bignum_error(const std::string &str)
Definition: bignum.h:18
CBigNum & operator>>=(unsigned int shift)
Definition: bignum.h:458
bool operator!()
Definition: bignum.h:46
std::string GetHex() const
Definition: bignum.h:388
CBigNum & operator/=(const CBigNum &b)
Definition: bignum.h:439
const CBigNum operator%(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:559
void setuint256(uint256 n)
Definition: bignum.h:197
CBigNum & operator<<=(unsigned int shift)
Definition: bignum.h:451
unsigned long getulong() const
Definition: bignum.h:106
CBigNum(unsigned char n)
Definition: bignum.h:87
RAII encapsulated BN_CTX (OpenSSL bignum context)
Definition: bignum.h:23
unsigned long long uint64
Definition: serialize.h:26
CBigNum & operator++()
Definition: bignum.h:476
void setulong(unsigned long n)
Definition: bignum.h:100
void setint64(int64 sn)
Definition: bignum.h:125
CBigNum & operator%=(const CBigNum &b)
Definition: bignum.h:445
const CBigNum operator/(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:550
const CBigNum operator<<(const CBigNum &a, unsigned int shift)
Definition: bignum.h:568
BN_CTX * operator=(BN_CTX *pnew)
Definition: bignum.h:27
const CBigNum operator*(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:541
void Unserialize(Stream &s, int nType=0, int nVersion=PROTOCOL_VERSION)
Definition: bignum.h:405
CBigNum & SetCompact(unsigned int nCompact)
Definition: bignum.h:289
bool operator>(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:588
CBigNum(const std::vector< unsigned char > &vch)
Definition: bignum.h:94
bool operator!() const
Definition: bignum.h:413
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:106
const CBigNum operator>>(const CBigNum &a, unsigned int shift)
Definition: bignum.h:576
const CBigNum operator--(int)
Definition: bignum.h:502
CBigNum & operator*=(const CBigNum &b)
Definition: bignum.h:431
bool operator<=(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:585
~CAutoBN_CTX()
Definition: bignum.h:37
CBigNum(signed char n)
Definition: bignum.h:82
const CBigNum operator+(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:518
unsigned int getuint() const
Definition: bignum.h:111
C++ wrapper for BIGNUM (OpenSSL bignum)
Definition: bignum.h:51
BN_CTX * pctx
Definition: bignum.h:26
std::vector< unsigned char > getvch() const
Definition: bignum.h:255
CBigNum(int n)
Definition: bignum.h:84
friend const CBigNum operator%(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:559
CBigNum(long n)
Definition: bignum.h:85
CAutoBN_CTX()
Definition: bignum.h:30
Errors thrown by the bignum class.
Definition: bignum.h:15
unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const
Definition: bignum.h:393
bool operator>=(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:586
CBigNum & operator-=(const CBigNum &b)
Definition: bignum.h:425
void SetHex(const std::string &str)
Definition: bignum.h:332
CBigNum(int64 n)
Definition: bignum.h:86
int getint() const
Definition: bignum.h:116
256-bit unsigned integer
Definition: uint256.h:537
void setvch(const std::vector< unsigned char > &vch)
Definition: bignum.h:240
CBigNum(unsigned short n)
Definition: bignum.h:88
CBigNum & operator=(const CBigNum &b)
Definition: bignum.h:69
CBigNum & operator--()
Definition: bignum.h:492
unsigned int GetCompact() const
Definition: bignum.h:308
CBigNum & operator+=(const CBigNum &b)
Definition: bignum.h:418
const CBigNum operator++(int)
Definition: bignum.h:484
~CBigNum()
Definition: bignum.h:76
BN_CTX & operator*()
Definition: bignum.h:44
friend const CBigNum operator-(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:526
std::string ToString(int nBase=10) const
Definition: bignum.h:362
CBigNum(const CBigNum &b)
Definition: bignum.h:59
void setuint64(uint64 n)
Definition: bignum.h:170
CBigNum()
Definition: bignum.h:54
friend const CBigNum operator/(const CBigNum &a, const CBigNum &b)
Definition: bignum.h:550
CBigNum(uint256 n)
Definition: bignum.h:92
long long int64
Definition: serialize.h:25
void Serialize(Stream &s, int nType=0, int nVersion=PROTOCOL_VERSION) const
Definition: bignum.h:399