20#include <openssl/bn.h>
30 : _bn(BN_dup(bn.BN()))
42 BN_set_negative(
_bn, 1);
47 BN_set_word(
_bn, val);
54 BN_add_word(
_bn, (
uint32)(val & 0xFFFFFFFF));
60 BN_lebin2bn(bytes, len,
_bn);
62 BN_bin2bn(bytes, len,
_bn);
67 int n = BN_hex2bn(&
_bn, str);
73 BN_rand(
_bn, numbits, 0, 1);
101 bnctx = BN_CTX_new();
112 bnctx = BN_CTX_new();
113 BN_div(
_bn,
nullptr,
_bn, bn.
_bn, bnctx);
123 bnctx = BN_CTX_new();
138 return BN_cmp(
_bn, bn.
_bn);
146 bnctx = BN_CTX_new();
158 bnctx = BN_CTX_new();
167 return BN_num_bytes(
_bn);
177 return BN_is_zero(
_bn);
182 return BN_is_negative(
_bn);
187 int res = littleEndian ? BN_bn2lebinpad(
_bn, buf, bufsize) : BN_bn2binpad(
_bn, buf, bufsize);
188 ASSERT(res > 0,
"Buffer of size %zu is too small to hold bignum with %d bytes.\n", bufsize, BN_num_bytes(
_bn));
193 std::size_t length = std::max(
GetNumBytes(), minSize);
194 std::vector<uint8> v;
196 GetBytes(v.data(), length, littleEndian);
202 char* ch = BN_bn2hex(
_bn);
203 std::string ret = ch;
210 char* ch = BN_bn2dec(
_bn);
211 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)