8#include <botan/bigint.h>
9#include <botan/internal/divide.h>
17#if (BOTAN_MP_WORD_BITS == 64)
18 const word conversion_radix = 10000000000000000000U;
19 const word radix_digits = 19;
21 const word conversion_radix = 1000000000U;
22 const word radix_digits = 9;
26 const size_t digit_estimate =
static_cast<size_t>(1 + (this->
bits() / 3.32));
29 const size_t digit_blocks = (digit_estimate + radix_digits - 1) / radix_digits;
35 std::vector<word> digit_groups(digit_blocks);
37 for(
size_t i = 0; i != digit_blocks; ++i)
41 digit_groups[i] = remainder;
47 std::vector<uint8_t> digits(digit_blocks * radix_digits);
49 for(
size_t i = 0; i != digit_blocks; ++i)
51 word remainder = digit_groups[i];
52 for(
size_t j = 0; j != radix_digits; ++j)
55 const word digit = remainder % 10;
57 digits[radix_digits*i + j] =
static_cast<uint8_t
>(digit);
62 while(!digits.empty() && digits.back() == 0)
71 s.reserve(1 + digits.size());
77 for(
auto i = digits.rbegin(); i != digits.rend(); ++i)
79 s.push_back(*i +
'0');
109 throw Encoding_Error(
"encode_1363: n is too large to encode properly");
120 throw Encoding_Error(
"encode_1363: n is too large to encode properly");
131 throw Encoding_Error(
"encode_fixed_length_int_pair: values must be positive");
133 throw Encoding_Error(
"encode_fixed_length_int_pair: values too large to encode properly");
157 const char buf0_with_leading_0[2] =
158 {
'0',
static_cast<char>(buf[0]) };
175 for(
size_t i = 0; i != length; ++i)
177 const char c = buf[i];
179 if(c < '0' || c >
'9')
182 const uint8_t x = c -
'0';
#define BOTAN_ASSERT_NOMSG(expr)
void binary_decode(const uint8_t buf[], size_t length)
static BigInt decode(const uint8_t buf[], size_t length)
std::string to_dec_string() const
void binary_encode(uint8_t buf[]) const
std::string to_hex_string() const
static secure_vector< uint8_t > encode_fixed_length_int_pair(const BigInt &n1, const BigInt &n2, size_t bytes)
static std::vector< uint8_t > encode(const BigInt &n)
static secure_vector< uint8_t > encode_1363(const BigInt &n, size_t bytes)
secure_vector< uint8_t > hex_decode_locked(const char input[], size_t input_length, bool ignore_ws)
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
void ct_divide_word(const BigInt &x, word y, BigInt &q_out, word &r_out)
const char * cast_uint8_ptr_to_char(const uint8_t *b)
std::vector< T, secure_allocator< T > > secure_vector