BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
base58.cpp
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 
6 
7 //
8 // Why base-58 instead of standard base-64 encoding?
9 // - Don't want 0OIl characters that look the same in some fonts and
10 // could be used to create visually identical looking account numbers.
11 // - A string with non-alphanumeric characters is not as easily accepted as an account number.
12 // - E-mail usually won't line-break if there's no punctuation to break at.
13 // - Doubleclicking selects the whole number as one word if it's all alphanumeric.
14 //
15 #ifndef BITCOIN_BASE58_H
16 #define BITCOIN_BASE58_H
17 
18 #include <string>
19 #include <vector>
20 #include <limits>
21 #include <algorithm>
22 #include <string.h>
23 
24 #include <fc/log/logger.hpp>
26 
27 #include <stdexcept>
28 #include <vector>
29 #include <openssl/bn.h>
30 
31 namespace fc { namespace detail {
32 
34 class bignum_error : public std::runtime_error
35 {
36 public:
37  explicit bignum_error(const std::string& str) : std::runtime_error(str) {}
38 };
39 
40 
43 {
44 protected:
45  BN_CTX* pctx;
46  BN_CTX* operator=(BN_CTX* pnew) { return pctx = pnew; }
47 
48 public:
50  {
51  pctx = BN_CTX_new();
52  if (pctx == NULL)
53  throw bignum_error("CAutoBN_CTX : BN_CTX_new() returned NULL");
54  }
55 
57  {
58  if (pctx != NULL)
59  BN_CTX_free(pctx);
60  }
61 
62  operator BN_CTX*() { return pctx; }
63  BN_CTX& operator*() { return *pctx; }
64  BN_CTX** operator&() { return &pctx; }
65  bool operator!() { return (pctx == NULL); }
66 };
67 
68 
70 class CBigNum
71 {
72  BIGNUM* bn;
73 public:
75  : bn(BN_new()) {}
76 
77  CBigNum(const CBigNum& b)
78  : CBigNum()
79  {
80  if (!BN_copy(bn, b.bn))
81  {
82  BN_clear_free(bn);
83  throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed");
84  }
85  }
86 
88  {
89  if (!BN_copy(bn, b.bn))
90  throw bignum_error("CBigNum::operator= : BN_copy failed");
91  return (*this);
92  }
93 
95  {
96  BN_clear_free(bn);
97  }
98 
99  //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
100  CBigNum(signed char n) :CBigNum() { if (n >= 0) setulong(n); else setint64(n); }
101  CBigNum(short n) :CBigNum() { if (n >= 0) setulong(n); else setint64(n); }
102  CBigNum(int n) :CBigNum() { if (n >= 0) setulong(n); else setint64(n); }
103  CBigNum(int64_t n) :CBigNum() { setint64(n); }
104  CBigNum(unsigned char n) :CBigNum() { setulong(n); }
105  CBigNum(unsigned short n) :CBigNum() { setulong(n); }
106  CBigNum(unsigned int n) :CBigNum() { setulong(n); }
107  CBigNum(uint64_t n) :CBigNum() { setuint64(n); }
108 
109  explicit CBigNum(const std::vector<unsigned char>& vch)
110  : CBigNum()
111  {
112  setvch(vch);
113  }
114 
115  void setulong(unsigned long n)
116  {
117  if (!BN_set_word(bn, n))
118  throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
119  }
120 
121  unsigned long getulong() const
122  {
123  return BN_get_word(bn);
124  }
125 
126  unsigned int getuint() const
127  {
128  return BN_get_word(bn);
129  }
130 
131  int getint() const
132  {
133  unsigned long n = BN_get_word(bn);
134  if (!BN_is_negative(bn))
135  return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
136  else
137  return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
138  }
139 
140  void setint64(int64_t n)
141  {
142  unsigned char pch[sizeof(n) + 6];
143  unsigned char* p = pch + 4;
144  bool fNegative = false;
145  if (n < (int64_t)0)
146  {
147  n = -n;
148  fNegative = true;
149  }
150  bool fLeadingZeroes = true;
151  for (int i = 0; i < 8; i++)
152  {
153  unsigned char c = (n >> 56) & 0xff;
154  n <<= 8;
155  if (fLeadingZeroes)
156  {
157  if (c == 0)
158  continue;
159  if (c & 0x80)
160  *p++ = (fNegative ? 0x80 : 0);
161  else if (fNegative)
162  c |= 0x80;
163  fLeadingZeroes = false;
164  }
165  *p++ = c;
166  }
167  unsigned int nSize = p - (pch + 4);
168  pch[0] = (nSize >> 24) & 0xff;
169  pch[1] = (nSize >> 16) & 0xff;
170  pch[2] = (nSize >> 8) & 0xff;
171  pch[3] = (nSize) & 0xff;
172  BN_mpi2bn(pch, p - pch, bn);
173  }
174 
175  void setuint64(uint64_t n)
176  {
177  unsigned char pch[sizeof(n) + 6];
178  unsigned char* p = pch + 4;
179  bool fLeadingZeroes = true;
180  for (int i = 0; i < 8; i++)
181  {
182  unsigned char c = (n >> 56) & 0xff;
183  n <<= 8;
184  if (fLeadingZeroes)
185  {
186  if (c == 0)
187  continue;
188  if (c & 0x80)
189  *p++ = 0;
190  fLeadingZeroes = false;
191  }
192  *p++ = c;
193  }
194  unsigned int nSize = p - (pch + 4);
195  pch[0] = (nSize >> 24) & 0xff;
196  pch[1] = (nSize >> 16) & 0xff;
197  pch[2] = (nSize >> 8) & 0xff;
198  pch[3] = (nSize) & 0xff;
199  BN_mpi2bn(pch, p - pch, bn);
200  }
201 
202 
203  void setvch(const std::vector<unsigned char>& vch)
204  {
205  std::vector<unsigned char> vch2(vch.size() + 4);
206  unsigned int nSize = vch.size();
207  // BIGNUM's byte stream format expects 4 bytes of
208  // big endian size data info at the front
209  vch2[0] = (nSize >> 24) & 0xff;
210  vch2[1] = (nSize >> 16) & 0xff;
211  vch2[2] = (nSize >> 8) & 0xff;
212  vch2[3] = (nSize >> 0) & 0xff;
213  // swap data to big endian
214  reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
215  BN_mpi2bn(&vch2[0], vch2.size(), bn);
216  }
217 
218  std::vector<unsigned char> getvch() const
219  {
220  unsigned int nSize = BN_bn2mpi(bn, NULL);
221  if (nSize <= 4)
222  return std::vector<unsigned char>();
223  std::vector<unsigned char> vch(nSize);
224  BN_bn2mpi(bn, &vch[0]);
225  vch.erase(vch.begin(), vch.begin() + 4);
226  reverse(vch.begin(), vch.end());
227  return vch;
228  }
229 
230  CBigNum& SetCompact(unsigned int nCompact)
231  {
232  unsigned int nSize = nCompact >> 24;
233  std::vector<unsigned char> vch(4 + nSize);
234  vch[3] = nSize;
235  if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff;
236  if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff;
237  if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff;
238  BN_mpi2bn(&vch[0], vch.size(), bn);
239  return *this;
240  }
241 
242  unsigned int GetCompact() const
243  {
244  unsigned int nSize = BN_bn2mpi(bn, NULL);
245  std::vector<unsigned char> vch(nSize);
246  nSize -= 4;
247  BN_bn2mpi(bn, &vch[0]);
248  unsigned int nCompact = nSize << 24;
249  if (nSize >= 1) nCompact |= (vch[4] << 16);
250  if (nSize >= 2) nCompact |= (vch[5] << 8);
251  if (nSize >= 3) nCompact |= (vch[6] << 0);
252  return nCompact;
253  }
254 
255  void SetHex(const std::string& str)
256  {
257  // skip 0x
258  const char* psz = str.c_str();
259  while (isspace(*psz))
260  psz++;
261  bool fNegative = false;
262  if (*psz == '-')
263  {
264  fNegative = true;
265  psz++;
266  }
267  if (psz[0] == '0' && tolower(psz[1]) == 'x')
268  psz += 2;
269  while (isspace(*psz))
270  psz++;
271 
272  // hex string to bignum
273  static 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 };
274  *this = 0;
275  while (isxdigit(*psz))
276  {
277  *this <<= 4;
278  int n = phexdigit[(unsigned char)*psz++];
279  *this += n;
280  }
281  if (fNegative)
282  BN_set_negative(bn, 1);
283  }
284 
285  std::string ToString(int nBase=10) const
286  {
287  CAutoBN_CTX pctx;
288  CBigNum bnBase = nBase;
289  CBigNum bn0 = 0;
290  std::string str;
291  CBigNum bn = *this;
292  BN_set_negative(bn.bn, false);
293  CBigNum dv;
294  CBigNum rem;
295  if (BN_cmp(bn.bn, bn0.bn) == 0)
296  return "0";
297  while (BN_cmp(bn.bn, bn0.bn) > 0)
298  {
299  if (!BN_div(dv.bn, rem.bn, bn.bn, bnBase.bn, pctx))
300  throw bignum_error("CBigNum::ToString() : BN_div failed");
301  bn = dv;
302  unsigned int c = rem.getulong();
303  str += "0123456789abcdef"[c];
304  }
305  if (BN_is_negative(this->bn))
306  str += "-";
307  reverse(str.begin(), str.end());
308  return str;
309  }
310 
311  std::string GetHex() const
312  {
313  return ToString(16);
314  }
315 
316 
317 
318  bool operator!() const
319  {
320  return BN_is_zero(bn);
321  }
322 
324  {
325  if (!BN_add(bn, bn, b.bn))
326  throw bignum_error("CBigNum::operator+= : BN_add failed");
327  return *this;
328  }
329 
331  {
332  if (!BN_sub(bn, bn, b.bn))
333  throw bignum_error("CBigNum::operator-= : BN_sub failed");
334  return *this;
335  }
336 
338  {
339  CAutoBN_CTX pctx;
340  if (!BN_mul(bn, bn, b.bn, pctx))
341  throw bignum_error("CBigNum::operator*= : BN_mul failed");
342  return *this;
343  }
344 
346  {
347  CAutoBN_CTX pctx;
348  if (!BN_div(bn, NULL, bn, b.bn, pctx))
349  throw bignum_error("CBigNum::operator/= : BN_div failed");
350  return *this;
351  }
352 
354  {
355  CAutoBN_CTX pctx;
356  if (!BN_div(NULL, bn, bn, b.bn, pctx))
357  throw bignum_error("CBigNum::operator%= : BN_div failed");
358  return *this;
359  }
360 
361  CBigNum& operator<<=(unsigned int shift)
362  {
363  if (!BN_lshift(bn, bn, shift))
364  throw bignum_error("CBigNum:operator<<= : BN_lshift failed");
365  return *this;
366  }
367 
368  CBigNum& operator>>=(unsigned int shift)
369  {
370  // Note: BN_rshift segfaults on 64-bit if 2^shift is greater than the number
371  // if built on ubuntu 9.04 or 9.10, probably depends on version of openssl
372  CBigNum a = 1;
373  a <<= shift;
374  if (BN_cmp(a.bn, bn) > 0)
375  {
376  *this = 0;
377  return *this;
378  }
379 
380  if (!BN_rshift(bn, bn, shift))
381  throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
382  return *this;
383  }
384 
385 
387  {
388  // prefix operator
389  if (!BN_add(bn, bn, BN_value_one()))
390  throw bignum_error("CBigNum::operator++ : BN_add failed");
391  return *this;
392  }
393 
394  const CBigNum operator++(int)
395  {
396  // postfix operator
397  const CBigNum ret = *this;
398  ++(*this);
399  return ret;
400  }
401 
403  {
404  // prefix operator
405  CBigNum r;
406  if (!BN_sub(r.bn, bn, BN_value_one()))
407  throw bignum_error("CBigNum::operator-- : BN_sub failed");
408  *this = r;
409  return *this;
410  }
411 
412  const CBigNum operator--(int)
413  {
414  // postfix operator
415  const CBigNum ret = *this;
416  --(*this);
417  return ret;
418  }
419 
420  const BIGNUM* to_bignum() const {
421  return bn;
422  }
424  return bn;
425  }
426 };
427 
428 
429 
430 inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
431 {
432  CBigNum r;
433  if (!BN_add(r.to_bignum(), a.to_bignum(), b.to_bignum()))
434  throw bignum_error("CBigNum::operator+ : BN_add failed");
435  return r;
436 }
437 
438 inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
439 {
440  CBigNum r;
441  if (!BN_sub(r.to_bignum(), a.to_bignum(), b.to_bignum()))
442  throw bignum_error("CBigNum::operator- : BN_sub failed");
443  return r;
444 }
445 
446 inline const CBigNum operator-(const CBigNum& a)
447 {
448  CBigNum r(a);
449  BN_set_negative(r.to_bignum(), !BN_is_negative(r.to_bignum()));
450  return r;
451 }
452 
453 inline const CBigNum operator*(const CBigNum& a, const CBigNum& b)
454 {
455  CAutoBN_CTX pctx;
456  CBigNum r;
457  if (!BN_mul(r.to_bignum(), a.to_bignum(), b.to_bignum(), pctx))
458  throw bignum_error("CBigNum::operator* : BN_mul failed");
459  return r;
460 }
461 
462 inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
463 {
464  CAutoBN_CTX pctx;
465  CBigNum r;
466  if (!BN_div(r.to_bignum(), NULL, a.to_bignum(), b.to_bignum(), pctx))
467  throw bignum_error("CBigNum::operator/ : BN_div failed");
468  return r;
469 }
470 
471 inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
472 {
473  CAutoBN_CTX pctx;
474  CBigNum r;
475  if (!BN_mod(r.to_bignum(), a.to_bignum(), b.to_bignum(), pctx))
476  throw bignum_error("CBigNum::operator% : BN_div failed");
477  return r;
478 }
479 
480 inline const CBigNum operator<<(const CBigNum& a, unsigned int shift)
481 {
482  CBigNum r;
483  if (!BN_lshift(r.to_bignum(), a.to_bignum(), shift))
484  throw bignum_error("CBigNum:operator<< : BN_lshift failed");
485  return r;
486 }
487 
488 inline const CBigNum operator>>(const CBigNum& a, unsigned int shift)
489 {
490  CBigNum r = a;
491  r >>= shift;
492  return r;
493 }
494 
495 inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.to_bignum(), b.to_bignum()) == 0); }
496 inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.to_bignum(), b.to_bignum()) != 0); }
497 inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.to_bignum(), b.to_bignum()) <= 0); }
498 inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.to_bignum(), b.to_bignum()) >= 0); }
499 inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.to_bignum(), b.to_bignum()) < 0); }
500 inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.to_bignum(), b.to_bignum()) > 0); }
501 
502 
503 static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
504 
505 // Encode a byte sequence as a base58-encoded string
506 inline std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
507 {
508  CAutoBN_CTX pctx;
509  CBigNum bn58 = 58;
510  CBigNum bn0 = 0;
511 
512  // Convert big endian data to little endian
513  // Extra zero at the end make sure bignum will interpret as a positive number
514  std::vector<unsigned char> vchTmp(pend-pbegin+1, 0);
515  reverse_copy(pbegin, pend, vchTmp.begin());
516 
517  // Convert little endian data to bignum
518  CBigNum bn;
519  bn.setvch(vchTmp);
520 
521  // Convert bignum to std::string
522  std::string str;
523  // Expected size increase from base58 conversion is approximately 137%
524  // use 138% to be safe
525  str.reserve((pend - pbegin) * 138 / 100 + 1);
526  CBigNum dv;
527  CBigNum rem;
528  while (bn > bn0)
529  {
530  if (!BN_div(dv.to_bignum(), rem.to_bignum(), bn.to_bignum(), bn58.to_bignum(), pctx))
531  throw bignum_error("EncodeBase58 : BN_div failed");
532  bn = dv;
533  unsigned int c = rem.getulong();
534  str += pszBase58[c];
535  }
536 
537  // Leading zeroes encoded as base58 zeros
538  for (const unsigned char* p = pbegin; p < pend && *p == 0; p++)
539  str += pszBase58[0];
540 
541  // Convert little endian std::string to big endian
542  reverse(str.begin(), str.end());
543 // slog( "Encode '%s'", str.c_str() );
544  return str;
545 }
546 
547 // Encode a byte vector as a base58-encoded string
548 inline std::string EncodeBase58(const std::vector<unsigned char>& vch)
549 {
550  return EncodeBase58(&vch[0], &vch[0] + vch.size());
551 }
552 
553 // Decode a base58-encoded string psz into byte vector vchRet
554 // returns true if decoding is succesful
555 inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
556 {
557  CAutoBN_CTX pctx;
558  vchRet.clear();
559  CBigNum bn58 = 58;
560  CBigNum bn = 0;
561  CBigNum bnChar;
562  while (isspace(*psz))
563  psz++;
564 
565  // Convert big endian string to bignum
566  for (const char* p = psz; *p; p++)
567  {
568  const char* p1 = strchr(pszBase58, *p);
569  if (p1 == NULL)
570  {
571  while (isspace(*p))
572  p++;
573  if (*p != '\0') {
574  //slog( "%s '%c'", pszBase58,*p );
575  return false;
576  }
577  break;
578  }
579  bnChar.setulong(p1 - pszBase58);
580  if (!BN_mul(bn.to_bignum(), bn.to_bignum(), bn58.to_bignum(), pctx))
581  throw bignum_error("DecodeBase58 : BN_mul failed");
582  bn += bnChar;
583  }
584 
585  // Get bignum as little endian data
586  std::vector<unsigned char> vchTmp = bn.getvch();
587 
588  // Trim off sign byte if present
589  if (vchTmp.size() >= 2 && vchTmp.end()[-1] == 0 && vchTmp.end()[-2] >= 0x80)
590  vchTmp.erase(vchTmp.end()-1);
591 
592  // Restore leading zeros
593  int nLeadingZeros = 0;
594  for (const char* p = psz; *p == pszBase58[0]; p++)
595  nLeadingZeros++;
596  vchRet.assign(nLeadingZeros + vchTmp.size(), 0);
597 
598  // Convert little endian data to big endian
599  reverse_copy(vchTmp.begin(), vchTmp.end(), vchRet.end() - vchTmp.size());
600  return true;
601 }
602 
603 // Decode a base58-encoded string str into byte vector vchRet
604 // returns true if decoding is succesful
605 inline bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet)
606 {
607  return DecodeBase58(str.c_str(), vchRet);
608 }
609 
610 } // detail
611 
612 std::string to_base58( const char* d, size_t s ) {
613  return fc::detail::EncodeBase58( (const unsigned char*)d, (const unsigned char*)d+s ).c_str();
614 }
615 
616 std::string to_base58( const std::vector<char>& d )
617 {
618  if( d.size() )
619  return to_base58( d.data(), d.size() );
620  return std::string();
621 }
622 std::vector<char> from_base58( const std::string& base58_str ) {
623  std::vector<unsigned char> out;
624  if( !fc::detail::DecodeBase58( base58_str.c_str(), out ) ) {
625  FC_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}",
626  ("base58_str",base58_str) );
627  }
628  return std::vector<char>((const char*)out.data(), ((const char*)out.data())+out.size() );
629 }
633 size_t from_base58( const std::string& base58_str, char* out_data, size_t out_data_len ) {
634  std::vector<unsigned char> out;
635  if( !fc::detail::DecodeBase58( base58_str.c_str(), out ) ) {
636  FC_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}",
637  ("base58_str",base58_str) );
638  }
639  FC_ASSERT( out.size() <= out_data_len );
640  if (!out.empty()) {
641  memcpy( out_data, out.data(), out.size() );
642  }
643  return out.size();
644 }
645 
646 } // fc
647 
648 #endif
fc::detail::CBigNum::operator=
CBigNum & operator=(const CBigNum &b)
Definition: base58.cpp:87
fc::detail::CBigNum::getint
int getint() const
Definition: base58.cpp:131
fc::detail::CBigNum::getuint
unsigned int getuint() const
Definition: base58.cpp:126
fc::detail::CBigNum::operator<<=
CBigNum & operator<<=(unsigned int shift)
Definition: base58.cpp:361
fc::to_base58
std::string to_base58(const char *d, size_t s)
Definition: base58.cpp:612
fc::detail::CBigNum::setvch
void setvch(const std::vector< unsigned char > &vch)
Definition: base58.cpp:203
fc::detail::operator*
const CBigNum operator*(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:453
fc::detail::CBigNum::operator*=
CBigNum & operator*=(const CBigNum &b)
Definition: base58.cpp:337
fc::detail::CBigNum::GetHex
std::string GetHex() const
Definition: base58.cpp:311
fc::detail::CBigNum::setulong
void setulong(unsigned long n)
Definition: base58.cpp:115
fc::detail::CBigNum::SetHex
void SetHex(const std::string &str)
Definition: base58.cpp:255
fc::detail::operator>>
const CBigNum operator>>(const CBigNum &a, unsigned int shift)
Definition: base58.cpp:488
fc::detail::CAutoBN_CTX
Definition: base58.cpp:42
fc::detail::CBigNum::operator%=
CBigNum & operator%=(const CBigNum &b)
Definition: base58.cpp:353
fc::detail::CBigNum
Definition: base58.cpp:70
fc
Definition: api.hpp:15
fc::detail::CBigNum::operator--
CBigNum & operator--()
Definition: base58.cpp:402
fc::detail::CBigNum::operator--
const CBigNum operator--(int)
Definition: base58.cpp:412
fc::detail::CBigNum::CBigNum
CBigNum(int n)
Definition: base58.cpp:102
fc::from_base58
std::vector< char > from_base58(const std::string &base58_str)
Definition: base58.cpp:622
fc::detail::operator>=
bool operator>=(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:498
fc::detail::operator<<
const CBigNum operator<<(const CBigNum &a, unsigned int shift)
Definition: base58.cpp:480
fc::detail::operator!=
bool operator!=(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:496
fc::detail::CBigNum::CBigNum
CBigNum(unsigned char n)
Definition: base58.cpp:104
fc::detail::CBigNum::to_bignum
BIGNUM * to_bignum()
Definition: base58.cpp:423
fc::detail::CBigNum::CBigNum
CBigNum(const CBigNum &b)
Definition: base58.cpp:77
fc::detail::CBigNum::SetCompact
CBigNum & SetCompact(unsigned int nCompact)
Definition: base58.cpp:230
fc::detail::CAutoBN_CTX::operator&
BN_CTX ** operator&()
Definition: base58.cpp:64
fc::detail::CBigNum::operator>>=
CBigNum & operator>>=(unsigned int shift)
Definition: base58.cpp:368
fc::detail::CAutoBN_CTX::CAutoBN_CTX
CAutoBN_CTX()
Definition: base58.cpp:49
fc::detail::operator==
bool operator==(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:495
fc::detail::DecodeBase58
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vchRet)
Definition: base58.cpp:555
fc::detail::operator-
const CBigNum operator-(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:438
fc::detail::operator%
const CBigNum operator%(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:471
fc::detail::operator<
bool operator<(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:499
fc::detail::CBigNum::operator++
CBigNum & operator++()
Definition: base58.cpp:386
fc::detail::CAutoBN_CTX::operator!
bool operator!()
Definition: base58.cpp:65
fc::detail::operator+
const CBigNum operator+(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:430
fc::detail::CBigNum::CBigNum
CBigNum()
Definition: base58.cpp:74
fc::detail::CBigNum::getulong
unsigned long getulong() const
Definition: base58.cpp:121
fc::detail::operator<=
bool operator<=(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:497
fc::detail::CBigNum::~CBigNum
~CBigNum()
Definition: base58.cpp:94
fc::detail::CAutoBN_CTX::~CAutoBN_CTX
~CAutoBN_CTX()
Definition: base58.cpp:56
fc::detail::CBigNum::CBigNum
CBigNum(const std::vector< unsigned char > &vch)
Definition: base58.cpp:109
fc::detail::CAutoBN_CTX::operator*
BN_CTX & operator*()
Definition: base58.cpp:63
fc::detail::CBigNum::ToString
std::string ToString(int nBase=10) const
Definition: base58.cpp:285
fc::detail::CBigNum::CBigNum
CBigNum(uint64_t n)
Definition: base58.cpp:107
fc::detail::CBigNum::GetCompact
unsigned int GetCompact() const
Definition: base58.cpp:242
fc::detail::CBigNum::CBigNum
CBigNum(short n)
Definition: base58.cpp:101
fc::detail::CBigNum::operator+=
CBigNum & operator+=(const CBigNum &b)
Definition: base58.cpp:323
fc::detail::bignum_error::bignum_error
bignum_error(const std::string &str)
Definition: base58.cpp:37
fc::detail::operator/
const CBigNum operator/(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:462
fc::detail::CBigNum::CBigNum
CBigNum(unsigned int n)
Definition: base58.cpp:106
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
fc::detail::CBigNum::CBigNum
CBigNum(int64_t n)
Definition: base58.cpp:103
exception.hpp
Defines exception's used by fc.
std
Definition: zeroed_array.hpp:76
fc::detail::bignum_error
Definition: base58.cpp:34
fc::detail::CBigNum::setint64
void setint64(int64_t n)
Definition: base58.cpp:140
fc::detail::CBigNum::CBigNum
CBigNum(signed char n)
Definition: base58.cpp:100
logger.hpp
fc::detail::CBigNum::setuint64
void setuint64(uint64_t n)
Definition: base58.cpp:175
fc::detail::CBigNum::getvch
std::vector< unsigned char > getvch() const
Definition: base58.cpp:218
fc::detail::CBigNum::operator!
bool operator!() const
Definition: base58.cpp:318
fc::detail::CAutoBN_CTX::pctx
BN_CTX * pctx
Definition: base58.cpp:45
FC_THROW_EXCEPTION
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
Definition: exception.hpp:379
fc::detail::CAutoBN_CTX::operator=
BN_CTX * operator=(BN_CTX *pnew)
Definition: base58.cpp:46
fc::detail::operator>
bool operator>(const CBigNum &a, const CBigNum &b)
Definition: base58.cpp:500
fc::detail::CBigNum::operator-=
CBigNum & operator-=(const CBigNum &b)
Definition: base58.cpp:330
fc::detail::CBigNum::operator++
const CBigNum operator++(int)
Definition: base58.cpp:394
fc::detail::CBigNum::operator/=
CBigNum & operator/=(const CBigNum &b)
Definition: base58.cpp:345
fc::detail::CBigNum::to_bignum
const BIGNUM * to_bignum() const
Definition: base58.cpp:420
fc::detail::EncodeBase58
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
Definition: base58.cpp:506
fc::detail::CBigNum::CBigNum
CBigNum(unsigned short n)
Definition: base58.cpp:105
BIGNUM
bignum_st BIGNUM
Definition: bigint.hpp:6