aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Huff <mith@jrbobdobbs.org>2011-06-06 12:47:19 -0500
committerDoug Huff <mith@jrbobdobbs.org>2011-06-06 12:49:11 -0500
commita9d3af88214b37ea61394b0b5abee6d380f9a5f0 (patch)
tree7b263d01a517fd72c8e94161415abbc59f1577b8
parent352b4ea5b924412f3485290123fdf538cfdd8aa8 (diff)
Demystify a few magic numbers.
-rw-r--r--src/base58.h2
-rw-r--r--src/bignum.h3
2 files changed, 5 insertions, 0 deletions
diff --git a/src/base58.h b/src/base58.h
index 580bd3fc63..c2729d4770 100644
--- a/src/base58.h
+++ b/src/base58.h
@@ -38,6 +38,8 @@ inline std::string EncodeBase58(const unsigned char* pbegin, const unsigned char
// Convert bignum to std::string
std::string str;
+ // Expected size increase from base58 conversion is approximately 137%
+ // use 138% to be safe
str.reserve((pend - pbegin) * 138 / 100 + 1);
CBigNum dv;
CBigNum rem;
diff --git a/src/bignum.h b/src/bignum.h
index 5b4c78e7fa..5eaa4028b7 100644
--- a/src/bignum.h
+++ b/src/bignum.h
@@ -228,10 +228,13 @@ public:
{
std::vector<unsigned char> vch2(vch.size() + 4);
unsigned int nSize = vch.size();
+ // BIGNUM's byte stream format expects 4 bytes of
+ // big endian size data info at the front
vch2[0] = (nSize >> 24) & 0xff;
vch2[1] = (nSize >> 16) & 0xff;
vch2[2] = (nSize >> 8) & 0xff;
vch2[3] = (nSize >> 0) & 0xff;
+ // swap data to big endian
reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
BN_mpi2bn(&vch2[0], vch2.size(), this);
}