diff options
author | lloyd <[email protected]> | 2010-10-12 16:19:56 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-12 16:19:56 +0000 |
commit | 4a6fd8c70d40f88c8b51127bfa055b66b18e0f7a (patch) | |
tree | d8c5697f8de1fff74c5b813fd83c08d310fa8ac0 /src/math/bigint | |
parent | c46a5e8d3dd8f07a92fc90027e6f7f70b989ea47 (diff) |
Use size_t in all of math, remove to_u32bit
Diffstat (limited to 'src/math/bigint')
-rw-r--r-- | src/math/bigint/big_code.cpp | 22 | ||||
-rw-r--r-- | src/math/bigint/big_io.cpp | 2 | ||||
-rw-r--r-- | src/math/bigint/big_ops2.cpp | 20 | ||||
-rw-r--r-- | src/math/bigint/big_ops3.cpp | 18 | ||||
-rw-r--r-- | src/math/bigint/big_rand.cpp | 4 | ||||
-rw-r--r-- | src/math/bigint/bigint.cpp | 102 | ||||
-rw-r--r-- | src/math/bigint/bigint.h | 71 | ||||
-rw-r--r-- | src/math/bigint/divide.cpp | 8 |
8 files changed, 111 insertions, 136 deletions
diff --git a/src/math/bigint/big_code.cpp b/src/math/bigint/big_code.cpp index 25c27bd33..99cf25aa0 100644 --- a/src/math/bigint/big_code.cpp +++ b/src/math/bigint/big_code.cpp @@ -30,8 +30,8 @@ void BigInt::encode(byte output[], const BigInt& n, Base base) else if(base == Octal) { BigInt copy = n; - const u32bit output_size = n.encoded_size(Octal); - for(u32bit j = 0; j != output_size; ++j) + const size_t output_size = n.encoded_size(Octal); + for(size_t j = 0; j != output_size; ++j) { output[output_size - 1 - j] = Charset::digit2char(copy % 8); copy /= 8; @@ -42,8 +42,8 @@ void BigInt::encode(byte output[], const BigInt& n, Base base) BigInt copy = n; BigInt remainder; copy.set_sign(Positive); - const u32bit output_size = n.encoded_size(Decimal); - for(u32bit j = 0; j != output_size; ++j) + const size_t output_size = n.encoded_size(Decimal); + for(size_t j = 0; j != output_size; ++j) { divide(copy, 10, copy, remainder); output[output_size - 1 - j] = @@ -64,7 +64,7 @@ SecureVector<byte> BigInt::encode(const BigInt& n, Base base) SecureVector<byte> output(n.encoded_size(base)); encode(&output[0], n, base); if(base != Binary) - for(u32bit j = 0; j != output.size(); ++j) + for(size_t j = 0; j != output.size(); ++j) if(output[j] == 0) output[j] = '0'; return output; @@ -73,13 +73,13 @@ SecureVector<byte> BigInt::encode(const BigInt& n, Base base) /* * Encode a BigInt, with leading 0s if needed */ -SecureVector<byte> BigInt::encode_1363(const BigInt& n, u32bit bytes) +SecureVector<byte> BigInt::encode_1363(const BigInt& n, size_t bytes) { - const u32bit n_bytes = n.bytes(); + const size_t n_bytes = n.bytes(); if(n_bytes > bytes) throw Encoding_Error("encode_1363: n is too large to encode properly"); - const u32bit leading_0s = bytes - n_bytes; + const size_t leading_0s = bytes - n_bytes; SecureVector<byte> output(bytes); encode(&output[leading_0s], n, Binary); @@ -97,7 +97,7 @@ BigInt BigInt::decode(const MemoryRegion<byte>& buf, Base base) /* * Decode a BigInt */ -BigInt BigInt::decode(const byte buf[], u32bit length, Base base) +BigInt BigInt::decode(const byte buf[], size_t length, Base base) { BigInt r; if(base == Binary) @@ -124,8 +124,8 @@ BigInt BigInt::decode(const byte buf[], u32bit length, Base base) } else if(base == Decimal || base == Octal) { - const u32bit RADIX = ((base == Decimal) ? 10 : 8); - for(u32bit j = 0; j != length; ++j) + const size_t RADIX = ((base == Decimal) ? 10 : 8); + for(size_t j = 0; j != length; ++j) { if(Charset::is_space(buf[j])) continue; diff --git a/src/math/bigint/big_io.cpp b/src/math/bigint/big_io.cpp index f3e7fb861..70e4a464a 100644 --- a/src/math/bigint/big_io.cpp +++ b/src/math/bigint/big_io.cpp @@ -28,7 +28,7 @@ std::ostream& operator<<(std::ostream& stream, const BigInt& n) if(n < 0) stream.write("-", 1); SecureVector<byte> buffer = BigInt::encode(n, base); - u32bit skip = 0; + size_t skip = 0; while(buffer[skip] == '0' && skip < buffer.size()) ++skip; stream.write(reinterpret_cast<const char*>(&buffer[0]) + skip, diff --git a/src/math/bigint/big_ops2.cpp b/src/math/bigint/big_ops2.cpp index 554fb1793..ff5cc7922 100644 --- a/src/math/bigint/big_ops2.cpp +++ b/src/math/bigint/big_ops2.cpp @@ -17,9 +17,9 @@ namespace Botan { */ BigInt& BigInt::operator+=(const BigInt& y) { - const u32bit x_sw = sig_words(), y_sw = y.sig_words(); + const size_t x_sw = sig_words(), y_sw = y.sig_words(); - const u32bit reg_size = std::max(x_sw, y_sw) + 1; + const size_t reg_size = std::max(x_sw, y_sw) + 1; grow_to(reg_size); if(sign() == y.sign()) @@ -52,11 +52,11 @@ BigInt& BigInt::operator+=(const BigInt& y) */ BigInt& BigInt::operator-=(const BigInt& y) { - const u32bit x_sw = sig_words(), y_sw = y.sig_words(); + const size_t x_sw = sig_words(), y_sw = y.sig_words(); s32bit relative_size = bigint_cmp(data(), x_sw, y.data(), y_sw); - const u32bit reg_size = std::max(x_sw, y_sw) + 1; + const size_t reg_size = std::max(x_sw, y_sw) + 1; grow_to(reg_size); if(relative_size < 0) @@ -94,7 +94,7 @@ BigInt& BigInt::operator-=(const BigInt& y) */ BigInt& BigInt::operator*=(const BigInt& y) { - const u32bit x_sw = sig_words(), y_sw = y.sig_words(); + const size_t x_sw = sig_words(), y_sw = y.sig_words(); set_sign((sign() == y.sign()) ? Positive : Negative); if(x_sw == 0 || y_sw == 0) @@ -165,7 +165,7 @@ word BigInt::operator%=(word mod) word remainder = 0; - for(u32bit j = sig_words(); j > 0; --j) + for(size_t j = sig_words(); j > 0; --j) remainder = bigint_modop(remainder, word_at(j-1), mod); clear(); grow_to(2); @@ -183,11 +183,11 @@ word BigInt::operator%=(word mod) /* * Left Shift Operator */ -BigInt& BigInt::operator<<=(u32bit shift) +BigInt& BigInt::operator<<=(size_t shift) { if(shift) { - const u32bit shift_words = shift / MP_WORD_BITS, + const size_t shift_words = shift / MP_WORD_BITS, shift_bits = shift % MP_WORD_BITS, words = sig_words(); @@ -201,11 +201,11 @@ BigInt& BigInt::operator<<=(u32bit shift) /* * Right Shift Operator */ -BigInt& BigInt::operator>>=(u32bit shift) +BigInt& BigInt::operator>>=(size_t shift) { if(shift) { - const u32bit shift_words = shift / MP_WORD_BITS, + const size_t shift_words = shift / MP_WORD_BITS, shift_bits = shift % MP_WORD_BITS; bigint_shr1(get_reg(), sig_words(), shift_words, shift_bits); diff --git a/src/math/bigint/big_ops3.cpp b/src/math/bigint/big_ops3.cpp index b92b71543..52472bc52 100644 --- a/src/math/bigint/big_ops3.cpp +++ b/src/math/bigint/big_ops3.cpp @@ -18,7 +18,7 @@ namespace Botan { */ BigInt operator+(const BigInt& x, const BigInt& y) { - const u32bit x_sw = x.sig_words(), y_sw = y.sig_words(); + const size_t x_sw = x.sig_words(), y_sw = y.sig_words(); BigInt z(x.sign(), std::max(x_sw, y_sw) + 1); @@ -47,7 +47,7 @@ BigInt operator+(const BigInt& x, const BigInt& y) */ BigInt operator-(const BigInt& x, const BigInt& y) { - const u32bit x_sw = x.sig_words(), y_sw = y.sig_words(); + const size_t x_sw = x.sig_words(), y_sw = y.sig_words(); s32bit relative_size = bigint_cmp(x.data(), x_sw, y.data(), y_sw); @@ -82,7 +82,7 @@ BigInt operator-(const BigInt& x, const BigInt& y) */ BigInt operator*(const BigInt& x, const BigInt& y) { - const u32bit x_sw = x.sig_words(), y_sw = y.sig_words(); + const size_t x_sw = x.sig_words(), y_sw = y.sig_words(); BigInt z(BigInt::Positive, x.size() + y.size()); @@ -142,7 +142,7 @@ word operator%(const BigInt& n, word mod) word remainder = 0; - for(u32bit j = n.sig_words(); j > 0; --j) + for(size_t j = n.sig_words(); j > 0; --j) remainder = bigint_modop(remainder, n.word_at(j-1), mod); if(remainder && n.sign() == BigInt::Negative) @@ -153,15 +153,15 @@ word operator%(const BigInt& n, word mod) /* * Left Shift Operator */ -BigInt operator<<(const BigInt& x, u32bit shift) +BigInt operator<<(const BigInt& x, size_t shift) { if(shift == 0) return x; - const u32bit shift_words = shift / MP_WORD_BITS, + const size_t shift_words = shift / MP_WORD_BITS, shift_bits = shift % MP_WORD_BITS; - const u32bit x_sw = x.sig_words(); + const size_t x_sw = x.sig_words(); BigInt y(x.sign(), x_sw + shift_words + (shift_bits ? 1 : 0)); bigint_shl2(y.get_reg(), x.data(), x_sw, shift_words, shift_bits); @@ -171,14 +171,14 @@ BigInt operator<<(const BigInt& x, u32bit shift) /* * Right Shift Operator */ -BigInt operator>>(const BigInt& x, u32bit shift) +BigInt operator>>(const BigInt& x, size_t shift) { if(shift == 0) return x; if(x.bits() <= shift) return 0; - const u32bit shift_words = shift / MP_WORD_BITS, + const size_t shift_words = shift / MP_WORD_BITS, shift_bits = shift % MP_WORD_BITS, x_sw = x.sig_words(); diff --git a/src/math/bigint/big_rand.cpp b/src/math/bigint/big_rand.cpp index 29fdf1de6..7cddb2de0 100644 --- a/src/math/bigint/big_rand.cpp +++ b/src/math/bigint/big_rand.cpp @@ -13,7 +13,7 @@ namespace Botan { /* * Construct a BigInt of a specific form */ -BigInt::BigInt(NumberType type, u32bit bits) +BigInt::BigInt(NumberType type, size_t bits) { set_sign(Positive); @@ -27,7 +27,7 @@ BigInt::BigInt(NumberType type, u32bit bits) * Randomize this number */ void BigInt::randomize(RandomNumberGenerator& rng, - u32bit bitsize) + size_t bitsize) { set_sign(Positive); diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp index 2ac387a97..6fa929b6d 100644 --- a/src/math/bigint/bigint.cpp +++ b/src/math/bigint/bigint.cpp @@ -23,19 +23,19 @@ BigInt::BigInt(u64bit n) if(n == 0) return; - const u32bit limbs_needed = sizeof(u64bit) / sizeof(word); + const size_t limbs_needed = sizeof(u64bit) / sizeof(word); reg.resize(4*limbs_needed); - for(u32bit j = 0; j != limbs_needed; ++j) + for(size_t j = 0; j != limbs_needed; ++j) reg[j] = ((n >> (j*MP_WORD_BITS)) & MP_WORD_MASK); } /* * Construct a BigInt of the specified size */ -BigInt::BigInt(Sign s, u32bit size) +BigInt::BigInt(Sign s, size_t size) { - reg.resize(round_up<u32bit>(size, 8)); + reg.resize(round_up<size_t>(size, 8)); signedness = s; } @@ -44,11 +44,11 @@ BigInt::BigInt(Sign s, u32bit size) */ BigInt::BigInt(const BigInt& b) { - const u32bit b_words = b.sig_words(); + const size_t b_words = b.sig_words(); if(b_words) { - reg.resize(round_up<u32bit>(b_words, 8)); + reg.resize(round_up<size_t>(b_words, 8)); reg.copy(b.data(), b_words); set_sign(b.sign()); } @@ -65,7 +65,7 @@ BigInt::BigInt(const BigInt& b) BigInt::BigInt(const std::string& str) { Base base = Decimal; - u32bit markers = 0; + size_t markers = 0; bool negative = false; if(str.length() > 0 && str[0] == '-') { markers += 1; negative = true; } @@ -85,7 +85,7 @@ BigInt::BigInt(const std::string& str) /* * Construct a BigInt from an encoded BigInt */ -BigInt::BigInt(const byte input[], u32bit length, Base base) +BigInt::BigInt(const byte input[], size_t length, Base base) { set_sign(Positive); *this = decode(input, length, base); @@ -94,7 +94,7 @@ BigInt::BigInt(const byte input[], u32bit length, Base base) /* * Construct a BigInt from an encoded BigInt */ -BigInt::BigInt(RandomNumberGenerator& rng, u32bit bits) +BigInt::BigInt(RandomNumberGenerator& rng, size_t bits) { set_sign(Positive); randomize(rng, bits); @@ -112,18 +112,18 @@ void BigInt::swap(BigInt& other) /* * Grow the internal storage */ -void BigInt::grow_reg(u32bit n) +void BigInt::grow_reg(size_t n) { - reg.resize(round_up<u32bit>(size() + n, 8)); + reg.resize(round_up<size_t>(size() + n, 8)); } /* * Grow the internal storage */ -void BigInt::grow_to(u32bit n) +void BigInt::grow_to(size_t n) { if(n > size()) - reg.resize(round_up<u32bit>(n, 8)); + reg.resize(round_up<size_t>(n, 8)); } /* @@ -142,28 +142,12 @@ s32bit BigInt::cmp(const BigInt& n, bool check_signs) const } /* -* Convert this number to a u32bit, if possible -*/ -u32bit BigInt::to_u32bit() const - { - if(is_negative()) - throw Encoding_Error("BigInt::to_u32bit: Number is negative"); - if(bits() >= 32) - throw Encoding_Error("BigInt::to_u32bit: Number is too big to convert"); - - u32bit out = 0; - for(u32bit j = 0; j != 4; ++j) - out = (out << 8) | byte_at(3-j); - return out; - } - -/* * Return byte n of this number */ -byte BigInt::byte_at(u32bit n) const +byte BigInt::byte_at(size_t n) const { - const u32bit WORD_BYTES = sizeof(word); - u32bit word_num = n / WORD_BYTES, byte_num = n % WORD_BYTES; + const size_t WORD_BYTES = sizeof(word); + size_t word_num = n / WORD_BYTES, byte_num = n % WORD_BYTES; if(word_num >= size()) return 0; else @@ -173,7 +157,7 @@ byte BigInt::byte_at(u32bit n) const /* * Return bit n of this number */ -bool BigInt::get_bit(u32bit n) const +bool BigInt::get_bit(size_t n) const { return ((word_at(n / MP_WORD_BITS) >> (n % MP_WORD_BITS)) & 1); } @@ -181,27 +165,27 @@ bool BigInt::get_bit(u32bit n) const /* * Return bits {offset...offset+length} */ -u32bit BigInt::get_substring(u32bit offset, u32bit length) const +size_t BigInt::get_substring(size_t offset, size_t length) const { if(length > 32) throw Invalid_Argument("BigInt::get_substring: Substring size too big"); u64bit piece = 0; - for(u32bit j = 0; j != 8; ++j) + for(size_t j = 0; j != 8; ++j) piece = (piece << 8) | byte_at((offset / 8) + (7-j)); u64bit mask = (1 << length) - 1; - u32bit shift = (offset % 8); + size_t shift = (offset % 8); - return static_cast<u32bit>((piece >> shift) & mask); + return static_cast<size_t>((piece >> shift) & mask); } /* * Set bit number n */ -void BigInt::set_bit(u32bit n) +void BigInt::set_bit(size_t n) { - const u32bit which = n / MP_WORD_BITS; + const size_t which = n / MP_WORD_BITS; const word mask = static_cast<word>(1) << (n % MP_WORD_BITS); if(which >= size()) grow_to(which + 1); reg[which] |= mask; @@ -210,9 +194,9 @@ void BigInt::set_bit(u32bit n) /* * Clear bit number n */ -void BigInt::clear_bit(u32bit n) +void BigInt::clear_bit(size_t n) { - const u32bit which = n / MP_WORD_BITS; + const size_t which = n / MP_WORD_BITS; const word mask = static_cast<word>(1) << (n % MP_WORD_BITS); if(which < size()) reg[which] &= ~mask; @@ -221,16 +205,16 @@ void BigInt::clear_bit(u32bit n) /* * Clear all but the lowest n bits */ -void BigInt::mask_bits(u32bit n) +void BigInt::mask_bits(size_t n) { if(n == 0) { clear(); return; } if(n >= bits()) return; - const u32bit top_word = n / MP_WORD_BITS; + const size_t top_word = n / MP_WORD_BITS; const word mask = (static_cast<word>(1) << (n % MP_WORD_BITS)) - 1; if(top_word < size()) - for(u32bit j = top_word + 1; j != size(); ++j) + for(size_t j = top_word + 1; j != size(); ++j) reg[j] = 0; reg[top_word] &= mask; @@ -239,7 +223,7 @@ void BigInt::mask_bits(u32bit n) /* * Count how many bytes are being used */ -u32bit BigInt::bytes() const +size_t BigInt::bytes() const { return (bits() + 7) / 8; } @@ -247,14 +231,14 @@ u32bit BigInt::bytes() const /* * Count how many bits are being used */ -u32bit BigInt::bits() const +size_t BigInt::bits() const { - const u32bit words = sig_words(); + const size_t words = sig_words(); if(words == 0) return 0; - u32bit full_words = words - 1, top_bits = MP_WORD_BITS; + size_t full_words = words - 1, top_bits = MP_WORD_BITS; word top_word = word_at(full_words), mask = MP_WORD_TOP_BIT; while(top_bits && ((top_word & mask) == 0)) @@ -266,7 +250,7 @@ u32bit BigInt::bits() const /* * Calcluate the size in a certain base */ -u32bit BigInt::encoded_size(Base base) const +size_t BigInt::encoded_size(Base base) const { static const double LOG_2_BASE_10 = 0.30102999566; @@ -277,7 +261,7 @@ u32bit BigInt::encoded_size(Base base) const else if(base == Octal) return ((bits() + 2) / 3); else if(base == Decimal) - return static_cast<u32bit>((bits() * LOG_2_BASE_10) + 1); + return static_cast<size_t>((bits() * LOG_2_BASE_10) + 1); else throw Invalid_Argument("Unknown base for BigInt encoding"); } @@ -336,28 +320,28 @@ BigInt BigInt::abs() const */ void BigInt::binary_encode(byte output[]) const { - const u32bit sig_bytes = bytes(); - for(u32bit j = 0; j != sig_bytes; ++j) + const size_t sig_bytes = bytes(); + for(size_t j = 0; j != sig_bytes; ++j) output[sig_bytes-j-1] = byte_at(j); } /* * Set this number to the value in buf */ -void BigInt::binary_decode(const byte buf[], u32bit length) +void BigInt::binary_decode(const byte buf[], size_t length) { - const u32bit WORD_BYTES = sizeof(word); + const size_t WORD_BYTES = sizeof(word); clear(); - reg.resize(round_up<u32bit>((length / WORD_BYTES) + 1, 8)); + reg.resize(round_up<size_t>((length / WORD_BYTES) + 1, 8)); - for(u32bit j = 0; j != length / WORD_BYTES; ++j) + for(size_t j = 0; j != length / WORD_BYTES; ++j) { - u32bit top = length - WORD_BYTES*j; - for(u32bit k = WORD_BYTES; k > 0; --k) + size_t top = length - WORD_BYTES*j; + for(size_t k = WORD_BYTES; k > 0; --k) reg[j] = (reg[j] << 8) | buf[top - k]; } - for(u32bit j = 0; j != length % WORD_BYTES; ++j) + for(size_t j = 0; j != length % WORD_BYTES; ++j) reg[length / WORD_BYTES] = (reg[length / WORD_BYTES] << 8) | buf[j]; } diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h index cd6997698..3fee70899 100644 --- a/src/math/bigint/bigint.h +++ b/src/math/bigint/bigint.h @@ -83,13 +83,13 @@ class BOTAN_DLL BigInt * Left shift operator * @param shift the number of bits to shift this left by */ - BigInt& operator<<=(u32bit shift); + BigInt& operator<<=(size_t shift); /** * Right shift operator * @param shift the number of bits to shift this right by */ - BigInt& operator>>=(u32bit shift); + BigInt& operator>>=(size_t shift); /** * Increment operator @@ -128,14 +128,14 @@ class BOTAN_DLL BigInt * @param i a word index * @return the word at index i */ - word& operator[](u32bit i) { return reg[i]; } + word& operator[](size_t i) { return reg[i]; } /** * [] operator (array access) * @param i a word index * @return the word at index i */ - word operator[](u32bit i) const { return reg[i]; } + word operator[](size_t i) const { return reg[i]; } /** * Zeroize the BigInt @@ -175,9 +175,9 @@ class BOTAN_DLL BigInt */ bool is_zero() const { - const u32bit sw = sig_words(); + const size_t sw = sig_words(); - for(u32bit i = 0; i != sw; ++i) + for(size_t i = 0; i != sw; ++i) if(reg[i]) return false; return true; @@ -187,26 +187,26 @@ class BOTAN_DLL BigInt * Set bit at specified position * @param n bit position to set */ - void set_bit(u32bit n); + void set_bit(size_t n); /** * Clear bit at specified position * @param n bit position to clear */ - void clear_bit(u32bit n); + void clear_bit(size_t n); /** * Clear all but the lowest n bits * @param n amount of bits to keep */ - void mask_bits(u32bit n); + void mask_bits(size_t n); /** * Return bit value at specified position * @param n the bit offset to test * @result true, if the bit at position n is set, false otherwise */ - bool get_bit(u32bit n) const; + bool get_bit(size_t n) const; /** * Return (a maximum of) 32 bits of the complete value @@ -215,32 +215,23 @@ class BOTAN_DLL BigInt * @result the integer extracted from the register starting at * offset with specified length */ - u32bit get_substring(u32bit offset, u32bit length) const; + size_t get_substring(size_t offset, size_t length) const; /** * @param n the offset to get a byte from * @result byte at offset n */ - byte byte_at(u32bit n) const; + byte byte_at(size_t n) const; /** * Return the word at a specified position of the internal register * @param n position in the register * @return value at position n */ - word word_at(u32bit n) const + word word_at(size_t n) const { return ((n < size()) ? reg[n] : 0); } /** - * Return the integer as an unsigned 32bit-integer-value. If the - * value is negative OR too big to be stored in a u32bit, this - * function will throw an exception. - * - * @result unsigned 32 bit representation of this - */ - u32bit to_u32bit() const; - - /** * Tests if the sign of the integer is negative * @result true, iff the integer has a negative sign */ @@ -283,16 +274,16 @@ class BOTAN_DLL BigInt * Give size of internal register * @result size of internal register in words */ - u32bit size() const { return get_reg().size(); } + size_t size() const { return get_reg().size(); } /** * Return how many words we need to hold this value * @result significant words of the represented integer value */ - u32bit sig_words() const + size_t sig_words() const { const word* x = ®[0]; - u32bit sig = reg.size(); + size_t sig = reg.size(); while(sig && (x[sig-1] == 0)) sig--; @@ -303,13 +294,13 @@ class BOTAN_DLL BigInt * Give byte length of the integer * @result byte length of the represented integer value */ - u32bit bytes() const; + size_t bytes() const; /** * Get the bit length of the integer * @result bit length of the represented integer value */ - u32bit bits() const; + size_t bits() const; /** * Return a pointer to the big integer word register @@ -337,16 +328,16 @@ class BOTAN_DLL BigInt * Increase internal register buffer by n words * @param n increase by n words */ - void grow_reg(u32bit n); + void grow_reg(size_t n); - void grow_to(u32bit n); + void grow_to(size_t n); /** * Fill BigInt with a random number with size of bitsize * @param rng the random number generator to use * @param bitsize number of bits the created random value should have */ - void randomize(RandomNumberGenerator& rng, u32bit bitsize = 0); + void randomize(RandomNumberGenerator& rng, size_t bitsize = 0); /** * Store BigInt-value in a given byte array @@ -359,7 +350,7 @@ class BOTAN_DLL BigInt * @param buf byte array buffer containing the integer * @param length size of buf */ - void binary_decode(const byte buf[], u32bit length); + void binary_decode(const byte buf[], size_t length); /** * Read integer value from a byte array (MemoryRegion<byte>) @@ -371,7 +362,7 @@ class BOTAN_DLL BigInt * @param base the base to measure the size for * @return size of this integer in base base */ - u32bit encoded_size(Base base = Binary) const; + size_t encoded_size(Base base = Binary) const; /** * @param rng a random number generator @@ -407,7 +398,7 @@ class BOTAN_DLL BigInt * @param base number-base of the integer in buf * @result BigInt representing the integer in the byte array */ - static BigInt decode(const byte buf[], u32bit length, + static BigInt decode(const byte buf[], size_t length, Base base = Binary); /** @@ -425,7 +416,7 @@ class BOTAN_DLL BigInt * @param bytes the length of the resulting SecureVector<byte> * @result a SecureVector<byte> containing the encoded BigInt */ - static SecureVector<byte> encode_1363(const BigInt& n, u32bit bytes); + static SecureVector<byte> encode_1363(const BigInt& n, size_t bytes); /** * Swap this value with another @@ -468,21 +459,21 @@ class BOTAN_DLL BigInt * @param length size of buf * @param base is the number base of the integer in buf */ - BigInt(const byte buf[], u32bit length, Base base = Binary); + BigInt(const byte buf[], size_t length, Base base = Binary); /** * Create a random BigInt of the specified size * @param rng random number generator * @param bits size in bits */ - BigInt(RandomNumberGenerator& rng, u32bit bits); + BigInt(RandomNumberGenerator& rng, size_t bits); /** * Create BigInt of specified size, all zeros * @param sign the sign * @param n size of the internal register in words */ - BigInt(Sign sign, u32bit n); + BigInt(Sign sign, size_t n); /** * Create a number of the specified type and size @@ -491,7 +482,7 @@ class BOTAN_DLL BigInt * @param n a size/length parameter, interpretation depends upon * the value of type */ - BigInt(NumberType type, u32bit n); + BigInt(NumberType type, size_t n); private: SecureVector<word> reg; @@ -507,8 +498,8 @@ BigInt BOTAN_DLL operator*(const BigInt& x, const BigInt& y); BigInt BOTAN_DLL operator/(const BigInt& x, const BigInt& d); BigInt BOTAN_DLL operator%(const BigInt& x, const BigInt& m); word BOTAN_DLL operator%(const BigInt& x, word m); -BigInt BOTAN_DLL operator<<(const BigInt& x, u32bit n); -BigInt BOTAN_DLL operator>>(const BigInt& x, u32bit n); +BigInt BOTAN_DLL operator<<(const BigInt& x, size_t n); +BigInt BOTAN_DLL operator>>(const BigInt& x, size_t n); /* * Comparison Operators diff --git a/src/math/bigint/divide.cpp b/src/math/bigint/divide.cpp index 2eb7538db..ba84aa7d9 100644 --- a/src/math/bigint/divide.cpp +++ b/src/math/bigint/divide.cpp @@ -37,7 +37,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r) throw BigInt::DivideByZero(); BigInt y = y_arg; - const u32bit y_words = y.sig_words(); + const size_t y_words = y.sig_words(); r = x; q = 0; @@ -54,13 +54,13 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r) } else if(compare > 0) { - u32bit shifts = 0; + size_t shifts = 0; word y_top = y[y.sig_words()-1]; while(y_top < MP_WORD_TOP_BIT) { y_top <<= 1; ++shifts; } y <<= shifts; r <<= shifts; - const u32bit n = r.sig_words() - 1, t = y_words - 1; + const size_t n = r.sig_words() - 1, t = y_words - 1; if(n < t) throw Internal_Error("BigInt division word sizes"); @@ -78,7 +78,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r) while(r >= temp) { r -= temp; ++q[n-t]; } - for(u32bit j = n; j != t; --j) + for(size_t j = n; j != t; --j) { const word x_j0 = r.word_at(j); const word x_j1 = r.word_at(j-1); |