diff options
author | lloyd <[email protected]> | 2015-01-08 13:10:56 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-01-08 13:10:56 +0000 |
commit | 89d6002286e4a1120fc544c70b0bb483e50bf634 (patch) | |
tree | 8922631c57695dabd036c45806b791821751ac73 /src/lib | |
parent | e1d118f4973e2d5f58971acfb8aa28f4fc3085e2 (diff) |
Inline BigInt::get_bit and byte_at
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/math/bigint/bigint.cpp | 21 | ||||
-rw-r--r-- | src/lib/math/bigint/bigint.h | 11 |
2 files changed, 9 insertions, 23 deletions
diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp index 90a319c5a..bb4b86f6b 100644 --- a/src/lib/math/bigint/bigint.cpp +++ b/src/lib/math/bigint/bigint.cpp @@ -124,27 +124,6 @@ s32bit BigInt::cmp(const BigInt& other, bool check_signs) const } /* -* Return byte n of this number -*/ -byte BigInt::byte_at(size_t n) const - { - 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 - return get_byte(WORD_BYTES - byte_num - 1, m_reg[word_num]); - } - -/* -* Return bit n of this number -*/ -bool BigInt::get_bit(size_t n) const - { - return ((word_at(n / MP_WORD_BITS) >> (n % MP_WORD_BITS)) & 1); - } - -/* * Return bits {offset...offset+length} */ u32bit BigInt::get_substring(size_t offset, size_t length) const diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h index 2205c7e83..779f5061d 100644 --- a/src/lib/math/bigint/bigint.h +++ b/src/lib/math/bigint/bigint.h @@ -275,7 +275,10 @@ class BOTAN_DLL BigInt * @param n the bit offset to test * @result true, if the bit at position n is set, false otherwise */ - bool get_bit(size_t n) const; + bool get_bit(size_t n) const + { + return ((word_at(n / MP_WORD_BITS) >> (n % MP_WORD_BITS)) & 1); + } /** * Return (a maximum of) 32 bits of the complete value @@ -297,7 +300,11 @@ class BOTAN_DLL BigInt * @param n the offset to get a byte from * @result byte at offset n */ - byte byte_at(size_t n) const; + byte byte_at(size_t n) const + { + return get_byte(sizeof(word) - (n % sizeof(word)) - 1, + word_at(n / sizeof(word))); + } /** * Return the word at a specified position of the internal register |