diff options
Diffstat (limited to 'src/utils/loadstor.h')
-rw-r--r-- | src/utils/loadstor.h | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/utils/loadstor.h b/src/utils/loadstor.h index 77a6e846c..bd2acc87d 100644 --- a/src/utils/loadstor.h +++ b/src/utils/loadstor.h @@ -42,7 +42,9 @@ namespace Botan { */ template<typename T> inline byte get_byte(u32bit byte_num, T input) { - return (input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)); + return static_cast<byte>( + input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3) + ); } /* @@ -202,24 +204,22 @@ inline void load_le(T out[], const byte in[], u32bit count) { -#if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) +#if defined(BOTAN_TARGET_CPU_HAS_KNOWN_ENDIANNESS) std::memcpy(out, in, sizeof(T)*count); -#else + +#if defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) const u32bit blocks = count - (count % 4); const u32bit left = count - blocks; for(u32bit i = 0; i != blocks; i += 4) - { - out[0] = load_le<T>(in, 0); - out[1] = load_le<T>(in, 1); - out[2] = load_le<T>(in, 2); - out[3] = load_le<T>(in, 3); - - out += 4; - in += 4*sizeof(T); - } + bswap_4(out + i); for(u32bit i = 0; i != left; ++i) + out[blocks+i] = reverse_bytes(out[blocks+i]); +#endif + +#else + for(u32bit i = 0; i != count; ++i) out[i] = load_le<T>(in, i); #endif } @@ -261,24 +261,22 @@ inline void load_be(T out[], const byte in[], u32bit count) { -#if defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) +#if defined(BOTAN_TARGET_CPU_HAS_KNOWN_ENDIANNESS) std::memcpy(out, in, sizeof(T)*count); -#else + +#if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) const u32bit blocks = count - (count % 4); const u32bit left = count - blocks; for(u32bit i = 0; i != blocks; i += 4) - { - out[0] = load_be<T>(in, 0); - out[1] = load_be<T>(in, 1); - out[2] = load_be<T>(in, 2); - out[3] = load_be<T>(in, 3); - - out += 4; - in += 4*sizeof(T); - } + bswap_4(out + i); for(u32bit i = 0; i != left; ++i) + out[blocks+i] = reverse_bytes(out[blocks+i]); +#endif + +#else + for(u32bit i = 0; i != count; ++i) out[i] = load_be<T>(in, i); #endif } |