diff options
Diffstat (limited to 'src/math')
-rw-r--r-- | src/math/bigint/big_code.cpp | 32 | ||||
-rw-r--r-- | src/math/bigint/bigint.h | 6 | ||||
-rw-r--r-- | src/math/bigint/info.txt | 2 | ||||
-rw-r--r-- | src/math/bigint/mp_msvc64/info.txt (renamed from src/math/bigint/mp_amd64_msvc/info.txt) | 0 | ||||
-rw-r--r-- | src/math/bigint/mp_msvc64/mp_asm.h (renamed from src/math/bigint/mp_amd64_msvc/mp_asm.h) | 2 |
5 files changed, 24 insertions, 18 deletions
diff --git a/src/math/bigint/big_code.cpp b/src/math/bigint/big_code.cpp index 74701e532..a8272390d 100644 --- a/src/math/bigint/big_code.cpp +++ b/src/math/bigint/big_code.cpp @@ -1,6 +1,6 @@ /* * BigInt Encoding/Decoding -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2010 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -23,8 +23,9 @@ void BigInt::encode(byte output[], const BigInt& n, Base base) { SecureVector<byte> binary(n.encoded_size(Binary)); n.binary_encode(binary); - for(u32bit j = 0; j != binary.size(); ++j) - Hex_Encoder::encode(binary[j], output + 2*j); + + hex_encode(reinterpret_cast<char*>(output), + &binary[0], binary.size()); } else if(base == Octal) { @@ -103,22 +104,23 @@ BigInt BigInt::decode(const byte buf[], u32bit length, Base base) r.binary_decode(buf, length); else if(base == Hexadecimal) { - SecureVector<byte> hex; - for(u32bit j = 0; j != length; ++j) - if(Hex_Decoder::is_valid(buf[j])) - hex.append(buf[j]); - - u32bit offset = (hex.size() % 2); - SecureVector<byte> binary(hex.size() / 2 + offset); + SecureVector<byte> binary; - if(offset) + if(length % 2) { - byte temp[2] = { '0', hex[0] }; - binary[0] = Hex_Decoder::decode(temp); + // Handle lack of leading 0 + const char buf0_with_leading_0[2] = { '0', buf[0] }; + binary = hex_decode(buf0_with_leading_0, 2); + + binary.append(hex_decode(reinterpret_cast<const char*>(&buf[1]), + length - 1, + false)); + } + else + binary = hex_decode(reinterpret_cast<const char*>(buf), + length, false); - for(u32bit j = offset; j != binary.size(); ++j) - binary[j] = Hex_Decoder::decode(hex+2*j-offset); r.binary_decode(binary, binary.size()); } else if(base == Decimal || base == Octal) diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h index 2b95bfc90..aa2e4347e 100644 --- a/src/math/bigint/bigint.h +++ b/src/math/bigint/bigint.h @@ -545,7 +545,11 @@ BOTAN_DLL std::istream& operator>>(std::istream&, BigInt&); namespace std { -inline void swap(Botan::BigInt& a, Botan::BigInt& b) { a.swap(b); } +template<> +inline void swap(Botan::BigInt& x, Botan::BigInt& y) + { + x.swap(y); + } } diff --git a/src/math/bigint/info.txt b/src/math/bigint/info.txt index 0511c2d8d..7892a6edf 100644 --- a/src/math/bigint/info.txt +++ b/src/math/bigint/info.txt @@ -30,7 +30,7 @@ mp_shift.cpp <requires> alloc hex -mp_amd64|mp_amd64_msvc|mp_asm64|mp_ia32|mp_ia32_msvc|mp_generic +mp_amd64|mp_msvc64|mp_asm64|mp_ia32|mp_ia32_msvc|mp_generic monty_generic mulop_generic rng diff --git a/src/math/bigint/mp_amd64_msvc/info.txt b/src/math/bigint/mp_msvc64/info.txt index 56ae05927..56ae05927 100644 --- a/src/math/bigint/mp_amd64_msvc/info.txt +++ b/src/math/bigint/mp_msvc64/info.txt diff --git a/src/math/bigint/mp_amd64_msvc/mp_asm.h b/src/math/bigint/mp_msvc64/mp_asm.h index 3acbe11bb..8e4535c35 100644 --- a/src/math/bigint/mp_amd64_msvc/mp_asm.h +++ b/src/math/bigint/mp_msvc64/mp_asm.h @@ -12,7 +12,7 @@ #include <intrin.h> #if (BOTAN_MP_WORD_BITS != 64) - #error The mp_amd64_msvc module requires that BOTAN_MP_WORD_BITS == 64 + #error The mp_msvc64 module requires that BOTAN_MP_WORD_BITS == 64 #endif #pragma intrinsic(_umul128) |