20#include <openssl/bn.h>
29 : _bn(BN_dup(bn.BN()))
41 BN_set_negative(
_bn, 1);
46 BN_set_word(
_bn, val);
53 BN_add_word(
_bn, (
uint32)(val & 0xFFFFFFFF));
59 BN_lebin2bn(bytes, len,
_bn);
61 BN_bin2bn(bytes, len,
_bn);
66 int n = BN_hex2bn(&
_bn, str);
72 BN_rand(
_bn, numbits, 0, 1);
100 bnctx = BN_CTX_new();
111 bnctx = BN_CTX_new();
112 BN_div(
_bn,
nullptr,
_bn, bn.
_bn, bnctx);
122 bnctx = BN_CTX_new();
137 return BN_cmp(
_bn, bn.
_bn);
145 bnctx = BN_CTX_new();
157 bnctx = BN_CTX_new();
166 return BN_num_bytes(
_bn);
171 return BN_num_bits(
_bn);
181 return BN_is_zero(
_bn);
186 return BN_is_negative(
_bn);
191 int res = littleEndian ? BN_bn2lebinpad(
_bn, buf, bufsize) : BN_bn2binpad(
_bn, buf, bufsize);
192 ASSERT(res > 0,
"Buffer of size %zu is too small to hold bignum with %d bytes.\n", bufsize, BN_num_bytes(
_bn));
197 std::size_t length = std::max(
GetNumBytes(), minSize);
198 std::vector<uint8> v;
200 GetBytes(v.data(), length, littleEndian);
206 char* ch = BN_bn2hex(
_bn);
207 std::string ret = ch;
214 char* ch = BN_bn2dec(
_bn);
215 std::string ret = ch;
BigNumber & operator<<=(int n)
BigNumber Exp(BigNumber const &) const
BigNumber ModExp(BigNumber const &bn1, BigNumber const &bn2) const
std::string AsDecStr() const
std::vector< uint8 > ToByteVector(int32 minSize=0, bool littleEndian=true) const
BigNumber & operator/=(BigNumber const &bn)
void SetRand(int32 numbits)
void SetBinary(uint8 const *bytes, int32 len, bool littleEndian=true)
std::string AsHexStr() const
int32 CompareTo(BigNumber const &bn) const
BigNumber & operator*=(BigNumber const &bn)
BigNumber & operator%=(BigNumber const &bn)
int32 GetNumBytes() const
BigNumber & operator-=(BigNumber const &bn)
void GetBytes(uint8 *buf, size_t bufsize, bool littleEndian=true) const
BigNumber & operator+=(BigNumber const &bn)
BigNumber & operator=(BigNumber const &bn)
bool SetHexStr(char const *str)