diff options
author | Jack Lloyd <[email protected]> | 2016-12-11 15:28:38 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-12-18 16:48:24 -0500 |
commit | f3cb3edb512bdcab498d825886c3366c341b3f78 (patch) | |
tree | 645c73ec295a5a34f25d99903b6d9fa9751e86d3 /src/lib/math/bigint | |
parent | c1dd21253c1f3188ff45d3ad47698efd08235ae8 (diff) |
Convert to using standard uintN_t integer types
Renames a couple of functions for somewhat better name consistency,
eg make_u32bit becomes make_uint32. The old typedefs remain for now
since probably lots of application code uses them.
Diffstat (limited to 'src/lib/math/bigint')
-rw-r--r-- | src/lib/math/bigint/big_code.cpp | 30 | ||||
-rw-r--r-- | src/lib/math/bigint/big_io.cpp | 2 | ||||
-rw-r--r-- | src/lib/math/bigint/big_ops2.cpp | 4 | ||||
-rw-r--r-- | src/lib/math/bigint/big_ops3.cpp | 4 | ||||
-rw-r--r-- | src/lib/math/bigint/big_rand.cpp | 2 | ||||
-rw-r--r-- | src/lib/math/bigint/bigint.cpp | 30 | ||||
-rw-r--r-- | src/lib/math/bigint/bigint.h | 48 | ||||
-rw-r--r-- | src/lib/math/bigint/divide.cpp | 2 |
8 files changed, 61 insertions, 61 deletions
diff --git a/src/lib/math/bigint/big_code.cpp b/src/lib/math/bigint/big_code.cpp index c8687715d..f7ab53291 100644 --- a/src/lib/math/bigint/big_code.cpp +++ b/src/lib/math/bigint/big_code.cpp @@ -15,7 +15,7 @@ namespace Botan { /* * Encode a BigInt */ -void BigInt::encode(byte output[], const BigInt& n, Base base) +void BigInt::encode(uint8_t output[], const BigInt& n, Base base) { if(base == Binary) { @@ -23,7 +23,7 @@ void BigInt::encode(byte output[], const BigInt& n, Base base) } else if(base == Hexadecimal) { - secure_vector<byte> binary(n.encoded_size(Binary)); + secure_vector<uint8_t> binary(n.encoded_size(Binary)); n.binary_encode(binary.data()); hex_encode(reinterpret_cast<char*>(output), @@ -39,7 +39,7 @@ void BigInt::encode(byte output[], const BigInt& n, Base base) { divide(copy, 10, copy, remainder); output[output_size - 1 - j] = - Charset::digit2char(static_cast<byte>(remainder.word_at(0))); + Charset::digit2char(static_cast<uint8_t>(remainder.word_at(0))); if(copy.is_zero()) break; } @@ -51,9 +51,9 @@ void BigInt::encode(byte output[], const BigInt& n, Base base) /* * Encode a BigInt */ -std::vector<byte> BigInt::encode(const BigInt& n, Base base) +std::vector<uint8_t> BigInt::encode(const BigInt& n, Base base) { - std::vector<byte> output(n.encoded_size(base)); + std::vector<uint8_t> output(n.encoded_size(base)); encode(output.data(), n, base); if(base != Binary) for(size_t j = 0; j != output.size(); ++j) @@ -65,9 +65,9 @@ std::vector<byte> BigInt::encode(const BigInt& n, Base base) /* * Encode a BigInt */ -secure_vector<byte> BigInt::encode_locked(const BigInt& n, Base base) +secure_vector<uint8_t> BigInt::encode_locked(const BigInt& n, Base base) { - secure_vector<byte> output(n.encoded_size(base)); + secure_vector<uint8_t> output(n.encoded_size(base)); encode(output.data(), n, base); if(base != Binary) for(size_t j = 0; j != output.size(); ++j) @@ -79,15 +79,15 @@ secure_vector<byte> BigInt::encode_locked(const BigInt& n, Base base) /* * Encode a BigInt, with leading 0s if needed */ -secure_vector<byte> BigInt::encode_1363(const BigInt& n, size_t bytes) +secure_vector<uint8_t> BigInt::encode_1363(const BigInt& n, size_t bytes) { - secure_vector<byte> output(bytes); + secure_vector<uint8_t> output(bytes); BigInt::encode_1363(output.data(), output.size(), n); return output; } //static -void BigInt::encode_1363(byte output[], size_t bytes, const BigInt& n) +void BigInt::encode_1363(uint8_t output[], size_t bytes, const BigInt& n) { const size_t n_bytes = n.bytes(); if(n_bytes > bytes) @@ -100,9 +100,9 @@ void BigInt::encode_1363(byte output[], size_t bytes, const BigInt& n) /* * Encode two BigInt, with leading 0s if needed, and concatenate */ -secure_vector<byte> BigInt::encode_fixed_length_int_pair(const BigInt& n1, const BigInt& n2, size_t bytes) +secure_vector<uint8_t> BigInt::encode_fixed_length_int_pair(const BigInt& n1, const BigInt& n2, size_t bytes) { - secure_vector<byte> output(2 * bytes); + secure_vector<uint8_t> output(2 * bytes); BigInt::encode_1363(output.data(), bytes, n1); BigInt::encode_1363(output.data() + bytes, bytes, n2); return output; @@ -111,14 +111,14 @@ secure_vector<byte> BigInt::encode_fixed_length_int_pair(const BigInt& n1, const /* * Decode a BigInt */ -BigInt BigInt::decode(const byte buf[], size_t length, Base base) +BigInt BigInt::decode(const uint8_t buf[], size_t length, Base base) { BigInt r; if(base == Binary) r.binary_decode(buf, length); else if(base == Hexadecimal) { - secure_vector<byte> binary; + secure_vector<uint8_t> binary; if(length % 2) { @@ -149,7 +149,7 @@ BigInt BigInt::decode(const byte buf[], size_t length, Base base) throw Invalid_Argument("BigInt::decode: " "Invalid character in decimal input"); - const byte x = Charset::char2digit(buf[i]); + const uint8_t x = Charset::char2digit(buf[i]); if(x >= 10) throw Invalid_Argument("BigInt: Invalid decimal string"); diff --git a/src/lib/math/bigint/big_io.cpp b/src/lib/math/bigint/big_io.cpp index 779f8ccb7..088b1daf7 100644 --- a/src/lib/math/bigint/big_io.cpp +++ b/src/lib/math/bigint/big_io.cpp @@ -27,7 +27,7 @@ std::ostream& operator<<(std::ostream& stream, const BigInt& n) { if(n < 0) stream.write("-", 1); - const std::vector<byte> buffer = BigInt::encode(n, base); + const std::vector<uint8_t> buffer = BigInt::encode(n, base); size_t skip = 0; while(skip < buffer.size() && buffer[skip] == '0') ++skip; diff --git a/src/lib/math/bigint/big_ops2.cpp b/src/lib/math/bigint/big_ops2.cpp index 6e234f036..48d547af0 100644 --- a/src/lib/math/bigint/big_ops2.cpp +++ b/src/lib/math/bigint/big_ops2.cpp @@ -27,7 +27,7 @@ BigInt& BigInt::operator+=(const BigInt& y) bigint_add2(mutable_data(), reg_size - 1, y.data(), y_sw); else { - s32bit relative_size = bigint_cmp(data(), x_sw, y.data(), y_sw); + int32_t relative_size = bigint_cmp(data(), x_sw, y.data(), y_sw); if(relative_size < 0) { @@ -55,7 +55,7 @@ BigInt& BigInt::operator-=(const BigInt& y) { const size_t x_sw = sig_words(), y_sw = y.sig_words(); - s32bit relative_size = bigint_cmp(data(), x_sw, y.data(), y_sw); + int32_t relative_size = bigint_cmp(data(), x_sw, y.data(), y_sw); const size_t reg_size = std::max(x_sw, y_sw) + 1; grow_to(reg_size); diff --git a/src/lib/math/bigint/big_ops3.cpp b/src/lib/math/bigint/big_ops3.cpp index 24927b4fc..a864fa96c 100644 --- a/src/lib/math/bigint/big_ops3.cpp +++ b/src/lib/math/bigint/big_ops3.cpp @@ -27,7 +27,7 @@ BigInt operator+(const BigInt& x, const BigInt& y) bigint_add3(z.mutable_data(), x.data(), x_sw, y.data(), y_sw); else { - s32bit relative_size = bigint_cmp(x.data(), x_sw, y.data(), y_sw); + int32_t relative_size = bigint_cmp(x.data(), x_sw, y.data(), y_sw); if(relative_size < 0) { @@ -50,7 +50,7 @@ BigInt operator-(const BigInt& x, const BigInt& y) { 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); + int32_t relative_size = bigint_cmp(x.data(), x_sw, y.data(), y_sw); BigInt z(BigInt::Positive, std::max(x_sw, y_sw) + 1); diff --git a/src/lib/math/bigint/big_rand.cpp b/src/lib/math/bigint/big_rand.cpp index 73f3cf070..506e9776a 100644 --- a/src/lib/math/bigint/big_rand.cpp +++ b/src/lib/math/bigint/big_rand.cpp @@ -25,7 +25,7 @@ void BigInt::randomize(RandomNumberGenerator& rng, } else { - secure_vector<byte> array = rng.random_vec(round_up(bitsize, 8) / 8); + secure_vector<uint8_t> array = rng.random_vec(round_up(bitsize, 8) / 8); // Always cut unwanted bits if(bitsize % 8) diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp index 2acfabb99..a91a685e0 100644 --- a/src/lib/math/bigint/bigint.cpp +++ b/src/lib/math/bigint/bigint.cpp @@ -17,12 +17,12 @@ namespace Botan { /* * Construct a BigInt from a regular number */ -BigInt::BigInt(u64bit n) +BigInt::BigInt(uint64_t n) { if(n == 0) return; - const size_t limbs_needed = sizeof(u64bit) / sizeof(word); + const size_t limbs_needed = sizeof(uint64_t) / sizeof(word); m_reg.resize(4*limbs_needed); for(size_t i = 0; i != limbs_needed; ++i) @@ -69,7 +69,7 @@ BigInt::BigInt(const std::string& str) base = Hexadecimal; } - *this = decode(reinterpret_cast<const byte*>(str.data()) + markers, + *this = decode(reinterpret_cast<const uint8_t*>(str.data()) + markers, str.length() - markers, base); if(negative) set_sign(Negative); @@ -79,7 +79,7 @@ BigInt::BigInt(const std::string& str) /* * Construct a BigInt from an encoded BigInt */ -BigInt::BigInt(const byte input[], size_t length, Base base) +BigInt::BigInt(const uint8_t input[], size_t length, Base base) { *this = decode(input, length, base); } @@ -95,7 +95,7 @@ BigInt::BigInt(RandomNumberGenerator& rng, size_t bits, bool set_high_bit) /* * Comparison Function */ -s32bit BigInt::cmp(const BigInt& other, bool check_signs) const +int32_t BigInt::cmp(const BigInt& other, bool check_signs) const { if(check_signs) { @@ -117,35 +117,35 @@ s32bit BigInt::cmp(const BigInt& other, bool check_signs) const /* * Return bits {offset...offset+length} */ -u32bit BigInt::get_substring(size_t offset, size_t length) const +uint32_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; + uint64_t piece = 0; for(size_t i = 0; i != 8; ++i) { - const byte part = byte_at((offset / 8) + (7-i)); + const uint8_t part = byte_at((offset / 8) + (7-i)); piece = (piece << 8) | part; } - const u64bit mask = (static_cast<u64bit>(1) << length) - 1; + const uint64_t mask = (static_cast<uint64_t>(1) << length) - 1; const size_t shift = (offset % 8); - return static_cast<u32bit>((piece >> shift) & mask); + return static_cast<uint32_t>((piece >> shift) & mask); } /* -* Convert this number to a u32bit, if possible +* Convert this number to a uint32_t, if possible */ -u32bit BigInt::to_u32bit() const +uint32_t 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; + uint32_t out = 0; for(size_t i = 0; i != 4; ++i) out = (out << 8) | byte_at(3-i); return out; @@ -267,7 +267,7 @@ void BigInt::grow_to(size_t n) /* * Encode this number into bytes */ -void BigInt::binary_encode(byte output[]) const +void BigInt::binary_encode(uint8_t output[]) const { const size_t sig_bytes = bytes(); for(size_t i = 0; i != sig_bytes; ++i) @@ -277,7 +277,7 @@ void BigInt::binary_encode(byte output[]) const /* * Set this number to the value in buf */ -void BigInt::binary_decode(const byte buf[], size_t length) +void BigInt::binary_decode(const uint8_t buf[], size_t length) { const size_t WORD_BYTES = sizeof(word); diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h index a61bee39c..42fe60e41 100644 --- a/src/lib/math/bigint/bigint.h +++ b/src/lib/math/bigint/bigint.h @@ -48,7 +48,7 @@ class BOTAN_DLL BigInt * Create BigInt from 64 bit integer * @param n initial value of this BigInt */ - BigInt(u64bit n); + BigInt(uint64_t n); /** * Copy Constructor @@ -71,7 +71,7 @@ class BOTAN_DLL BigInt * @param length size of buf * @param base is the number base of the integer in buf */ - BigInt(const byte buf[], size_t length, Base base = Binary); + BigInt(const uint8_t buf[], size_t length, Base base = Binary); /** * \brief Create a random BigInt of the specified size @@ -223,7 +223,7 @@ class BOTAN_DLL BigInt * @result if (this<n) return -1, if (this>n) return 1, if both * values are identical return 0 [like Perl's <=> operator] */ - s32bit cmp(const BigInt& n, bool check_signs = true) const; + int32_t cmp(const BigInt& n, bool check_signs = true) const; /** * Test if the integer has an even value @@ -308,20 +308,20 @@ class BOTAN_DLL BigInt * @result the integer extracted from the register starting at * offset with specified length */ - u32bit get_substring(size_t offset, size_t length) const; + uint32_t get_substring(size_t offset, size_t length) const; /** - * Convert this value into a u32bit, if it is in the range + * Convert this value into a uint32_t, if it is in the range * [0 ... 2**32-1], or otherwise throw an exception. - * @result the value as a u32bit if conversion is possible + * @result the value as a uint32_t if conversion is possible */ - u32bit to_u32bit() const; + uint32_t to_u32bit() const; /** * @param n the offset to get a byte from * @result byte at offset n */ - byte byte_at(size_t n) const + uint8_t byte_at(size_t n) const { return get_byte(sizeof(word) - (n % sizeof(word)) - 1, word_at(n / sizeof(word))); @@ -450,20 +450,20 @@ class BOTAN_DLL BigInt * Store BigInt-value in a given byte array * @param buf destination byte array for the integer value */ - void binary_encode(byte buf[]) const; + void binary_encode(uint8_t buf[]) const; /** * Read integer value from a byte array with given size * @param buf byte array buffer containing the integer * @param length size of buf */ - void binary_decode(const byte buf[], size_t length); + void binary_decode(const uint8_t buf[], size_t length); /** - * Read integer value from a byte array (secure_vector<byte>) + * Read integer value from a byte array (secure_vector<uint8_t>) * @param buf the array to load from */ - void binary_decode(const secure_vector<byte>& buf) + void binary_decode(const secure_vector<uint8_t>& buf) { binary_decode(buf.data(), buf.size()); } @@ -502,7 +502,7 @@ class BOTAN_DLL BigInt * @param base number-base of resulting byte array representation * @result secure_vector of bytes containing the integer with given base */ - static std::vector<byte> encode(const BigInt& n, Base base = Binary); + static std::vector<uint8_t> encode(const BigInt& n, Base base = Binary); /** * Encode the integer value from a BigInt to a secure_vector of bytes @@ -510,7 +510,7 @@ class BOTAN_DLL BigInt * @param base number-base of resulting byte array representation * @result secure_vector of bytes containing the integer with given base */ - static secure_vector<byte> encode_locked(const BigInt& n, + static secure_vector<uint8_t> encode_locked(const BigInt& n, Base base = Binary); /** @@ -520,7 +520,7 @@ class BOTAN_DLL BigInt * @param n the BigInt to use as integer source * @param base number-base of resulting byte array representation */ - static void encode(byte buf[], const BigInt& n, Base base = Binary); + static void encode(uint8_t buf[], const BigInt& n, Base base = Binary); /** * Create a BigInt from an integer in a byte array @@ -529,7 +529,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[], size_t length, + static BigInt decode(const uint8_t buf[], size_t length, Base base = Binary); /** @@ -538,7 +538,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 secure_vector<byte>& buf, + static BigInt decode(const secure_vector<uint8_t>& buf, Base base = Binary) { return BigInt::decode(buf.data(), buf.size(), base); @@ -550,7 +550,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 std::vector<byte>& buf, + static BigInt decode(const std::vector<uint8_t>& buf, Base base = Binary) { return BigInt::decode(buf.data(), buf.size(), base); @@ -559,21 +559,21 @@ class BOTAN_DLL BigInt /** * Encode a BigInt to a byte array according to IEEE 1363 * @param n the BigInt to encode - * @param bytes the length of the resulting secure_vector<byte> - * @result a secure_vector<byte> containing the encoded BigInt + * @param bytes the length of the resulting secure_vector<uint8_t> + * @result a secure_vector<uint8_t> containing the encoded BigInt */ - static secure_vector<byte> encode_1363(const BigInt& n, size_t bytes); + static secure_vector<uint8_t> encode_1363(const BigInt& n, size_t bytes); - static void encode_1363(byte out[], size_t bytes, const BigInt& n); + static void encode_1363(uint8_t out[], size_t bytes, const BigInt& n); /** * Encode two BigInt to a byte array according to IEEE 1363 * @param n1 the first BigInt to encode * @param n2 the second BigInt to encode * @param bytes the length of the encoding of each single BigInt - * @result a secure_vector<byte> containing the concatenation of the two encoded BigInt + * @result a secure_vector<uint8_t> containing the concatenation of the two encoded BigInt */ - static secure_vector<byte> encode_fixed_length_int_pair(const BigInt& n1, const BigInt& n2, size_t bytes); + static secure_vector<uint8_t> encode_fixed_length_int_pair(const BigInt& n1, const BigInt& n2, size_t bytes); private: secure_vector<word> m_reg; diff --git a/src/lib/math/bigint/divide.cpp b/src/lib/math/bigint/divide.cpp index ec4ba3f9f..13696d6d3 100644 --- a/src/lib/math/bigint/divide.cpp +++ b/src/lib/math/bigint/divide.cpp @@ -69,7 +69,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r) r.set_sign(BigInt::Positive); y.set_sign(BigInt::Positive); - s32bit compare = r.cmp(y); + int32_t compare = r.cmp(y); if(compare == 0) { |