aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/bswap.h25
-rw-r--r--src/utils/cpuid.cpp130
-rw-r--r--src/utils/cpuid.h8
-rw-r--r--src/utils/debug.h37
-rw-r--r--src/utils/exceptn.cpp62
-rw-r--r--src/utils/exceptn.h145
-rw-r--r--src/utils/get_byte.h27
-rw-r--r--src/utils/info.txt3
-rw-r--r--src/utils/loadstor.h11
-rw-r--r--src/utils/mlock.cpp8
-rw-r--r--src/utils/parsing.cpp4
-rw-r--r--src/utils/prefetch.h2
-rw-r--r--src/utils/simd_32/info.txt2
-rw-r--r--src/utils/simd_32/simd_32.h16
-rw-r--r--src/utils/simd_32/simd_altivec.h5
-rw-r--r--src/utils/simd_32/simd_scalar.h8
-rw-r--r--src/utils/simd_32/simd_sse.h5
17 files changed, 253 insertions, 245 deletions
diff --git a/src/utils/bswap.h b/src/utils/bswap.h
index 96ec4982a..fcb0fa7ea 100644
--- a/src/utils/bswap.h
+++ b/src/utils/bswap.h
@@ -16,10 +16,6 @@
#include <emmintrin.h>
#endif
-#if defined(BOTAN_TARGET_CPU_HAS_SSSE3)
- #include <tmmintrin.h>
-#endif
-
namespace Botan {
/*
@@ -32,8 +28,7 @@ inline u16bit reverse_bytes(u16bit input)
inline u32bit reverse_bytes(u32bit input)
{
-#if BOTAN_USE_GCC_INLINE_ASM && (defined(BOTAN_TARGET_ARCH_IS_IA32) || \
- defined(BOTAN_TARGET_ARCH_IS_AMD64))
+#if BOTAN_USE_GCC_INLINE_ASM && defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
// GCC-style inline assembly for x86 or x86-64
asm("bswapl %0" : "=r" (input) : "0" (input));
@@ -83,23 +78,7 @@ inline void bswap_4(T x[4])
x[3] = reverse_bytes(x[3]);
}
-#if defined(BOTAN_TARGET_CPU_HAS_SSSE3)
-
-template<>
-inline void bswap_4(u32bit x[4])
- {
- const __m128i bswap_mask = _mm_set_epi8(
- 12, 13, 14, 15,
- 8, 9, 10, 11,
- 4, 5, 6, 7,
- 0, 1, 2, 3);
-
- __m128i T = _mm_loadu_si128((const __m128i*)x);
- T = _mm_shuffle_epi8(T, bswap_mask);
- _mm_storeu_si128((__m128i*)x, T);
- }
-
-#elif defined(BOTAN_TARGET_CPU_HAS_SSE2)
+#if defined(BOTAN_TARGET_CPU_HAS_SSE2)
template<>
inline void bswap_4(u32bit x[4])
diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp
index 2ba7f9b77..8d801b75f 100644
--- a/src/utils/cpuid.cpp
+++ b/src/utils/cpuid.cpp
@@ -7,10 +7,14 @@
#include <botan/cpuid.h>
#include <botan/types.h>
-#include <botan/loadstor.h>
+#include <botan/get_byte.h>
#include <botan/mem_ops.h>
-#if defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64)
+#if defined(BOTAN_TARGET_OS_IS_DARWIN)
+ #include <sys/sysctl.h>
+#endif
+
+#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
#if defined(BOTAN_BUILD_COMPILER_IS_MSVC)
@@ -64,6 +68,73 @@ u32bit get_x86_cache_line_size()
return 32; // default cache line guess
}
+#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
+
+bool altivec_check_sysctl()
+ {
+#if defined(BOTAN_TARGET_OS_IS_DARWIN)
+
+ // From Apple's docs
+ int sels[2] = { CTL_HW, HW_VECTORUNIT };
+ int vector_type = 0;
+ size_t length = sizeof(vector_type);
+ int error = sysctl(sels, 2, &vector_type, &length, NULL, 0);
+
+ if(error == 0 && vector_type > 0)
+ return true;
+#endif
+
+ return false;
+ }
+
+bool altivec_check_pvr_emul()
+ {
+ bool altivec_capable = false;
+
+#if defined(BOTAN_TARGET_OS_IS_LINUX) || defined(BOTAN_TARGET_OS_IS_NETBSD)
+
+ /*
+ On PowerPC, MSR 287 is PVR, the Processor Version Number
+ Normally it is only accessible to ring 0, but Linux and NetBSD
+ (others, too, maybe?) will trap and emulate it for us.
+
+ PVR identifiers for various AltiVec enabled CPUs. Taken from
+ PearPC and Linux sources, mostly.
+ */
+
+ const u16bit PVR_G4_7400 = 0x000C;
+ const u16bit PVR_G5_970 = 0x0039;
+ const u16bit PVR_G5_970FX = 0x003C;
+ const u16bit PVR_G5_970MP = 0x0044;
+ const u16bit PVR_G5_970GX = 0x0045;
+ const u16bit PVR_POWER6 = 0x003E;
+ const u16bit PVR_CELL_PPU = 0x0070;
+
+ // Motorola produced G4s with PVR 0x800[0123C] (at least)
+ const u16bit PVR_G4_74xx_24 = 0x800;
+
+ u32bit pvr = 0;
+
+ asm volatile("mfspr %0, 287" : "=r" (pvr));
+
+ // Top 16 bit suffice to identify model
+ pvr >>= 16;
+
+ altivec_capable |= (pvr == PVR_G4_7400);
+ altivec_capable |= ((pvr >> 4) == PVR_G4_74xx_24);
+ altivec_capable |= (pvr == PVR_G5_970);
+ altivec_capable |= (pvr == PVR_G5_970FX);
+ altivec_capable |= (pvr == PVR_G5_970MP);
+ altivec_capable |= (pvr == PVR_G5_970GX);
+ altivec_capable |= (pvr == PVR_POWER6);
+ altivec_capable |= (pvr == PVR_CELL_PPU);
+#endif
+
+ return altivec_capable;
+ }
+
+#endif
+
}
/*
@@ -105,58 +176,9 @@ bool CPUID::has_altivec()
if(first_time)
{
-#if defined(BOTAN_TARGET_ARCH_IS_PPC) || defined(BOTAN_TARGET_ARCH_IS_PPC64)
-
- /*
- PVR identifiers for various AltiVec enabled CPUs. Taken from
- PearPC and Linux sources, mostly.
- */
- const u16bit PVR_G4_7400 = 0x000C;
- const u16bit PVR_G5_970 = 0x0039;
- const u16bit PVR_G5_970FX = 0x003C;
- const u16bit PVR_G5_970MP = 0x0044;
- const u16bit PVR_G5_970GX = 0x0045;
- const u16bit PVR_POWER6 = 0x003E;
- const u16bit PVR_CELL_PPU = 0x0070;
-
- // Motorola produced G4s with PVR 0x800[0123C] (at least)
- const u16bit PVR_G4_74xx_24 = 0x800;
-
- /*
- On PowerPC, MSR 287 is PVR, the Processor Version Number
-
- Normally it is only accessible to ring 0, but Linux and NetBSD
- (at least) will trap and emulate it for us. This is roughly 20x
- saner than every other approach I've seen for AltiVec detection
- (all of which are entirely OS specific, to boot).
-
- Apparently OS X doesn't support this, but then again OS X
- doesn't really support PPC anymore, so I'm not worrying about it.
-
- For OSes that aren't (known to) support the emulation, skip the
- call, leaving pvr as 0 which will cause all subsequent model
- number checks to fail (and we'll assume no AltiVec)
- */
-
-#if defined(BOTAN_TARGET_OS_IS_LINUX) || defined(BOTAN_TARGET_OS_IS_NETBSD)
- #define BOTAN_TARGET_OS_SUPPORTS_MFSPR_EMUL
-#endif
-
- u32bit pvr = 0;
-
-#if defined(BOTAN_TARGET_OS_SUPPORTS_MFSPR_EMUL)
- asm volatile("mfspr %0, 287" : "=r" (pvr));
-#endif
- // Top 16 bit suffice to identify model
- pvr >>= 16;
-
- altivec_capable |= (pvr == PVR_G4_7400);
- altivec_capable |= ((pvr >> 8) == PVR_G4_74xx_24);
- altivec_capable |= (pvr == PVR_G5_970);
- altivec_capable |= (pvr == PVR_G5_970FX);
- altivec_capable |= (pvr == PVR_G5_970MP);
- altivec_capable |= (pvr == PVR_G5_970GX);
- altivec_capable |= (pvr == PVR_CELL_PPU);
+#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
+ if(altivec_check_sysctl() || altivec_check_pvr_emul())
+ altivec_capable = true;
#endif
first_time = false;
diff --git a/src/utils/cpuid.h b/src/utils/cpuid.h
index 2c9599899..1de97f129 100644
--- a/src/utils/cpuid.h
+++ b/src/utils/cpuid.h
@@ -21,7 +21,7 @@ class BOTAN_DLL CPUID
CPUID_SSSE3_BIT = 41,
CPUID_SSE41_BIT = 51,
CPUID_SSE42_BIT = 52,
- CPUID_INTEL_AES_BIT = 57,
+ CPUID_INTEL_AES_BIT = 57
};
/**
@@ -66,12 +66,6 @@ class BOTAN_DLL CPUID
{ return ((x86_processor_flags() >> CPUID_INTEL_AES_BIT) & 1); }
/**
- * Check if the processor supports VIA's AES instructions
- * (not implemented)
- */
- static bool has_aes_via() { return false; }
-
- /**
* Check if the processor supports AltiVec/VMX
*/
static bool has_altivec();
diff --git a/src/utils/debug.h b/src/utils/debug.h
new file mode 100644
index 000000000..271e0047b
--- /dev/null
+++ b/src/utils/debug.h
@@ -0,0 +1,37 @@
+/**
+* Internal-use debugging functions for Botan
+* (C) 2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_DEBUG_H__
+#define BOTAN_DEBUG_H__
+
+#include <botan/secmem.h>
+#include <cstdio>
+
+namespace Botan {
+
+namespace Debug {
+
+inline void print_vec(const std::string& name,
+ const byte array[], size_t array_len)
+ {
+ std::printf("%s = ", name.c_str());
+ for(size_t i = 0; i != array_len; ++i)
+ std::printf("%02X", array[i]);
+ std::printf("\n");
+ }
+
+inline void print_vec(const std::string& name,
+ const MemoryRegion<byte>& vec)
+ {
+ print_vec(name, &vec[0], vec.size());
+ }
+
+}
+
+}
+
+#endif
diff --git a/src/utils/exceptn.cpp b/src/utils/exceptn.cpp
deleted file mode 100644
index 753d63424..000000000
--- a/src/utils/exceptn.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-* Exceptions
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/exceptn.h>
-#include <botan/parsing.h>
-
-namespace Botan {
-
-/*
-* Constructor for Invalid_Key_Length
-*/
-Invalid_Key_Length::Invalid_Key_Length(const std::string& name, u32bit length)
- {
- set_msg(name + " cannot accept a key of length " + to_string(length));
- }
-
-/*
-* Constructor for Invalid_Block_Size
-*/
-Invalid_Block_Size::Invalid_Block_Size(const std::string& mode,
- const std::string& pad)
- {
- set_msg("Padding method " + pad + " cannot be used with " + mode);
- }
-
-/*
-* Constructor for Invalid_IV_Length
-*/
-Invalid_IV_Length::Invalid_IV_Length(const std::string& mode, u32bit bad_len)
- {
- set_msg("IV length " + to_string(bad_len) + " is invalid for " + mode);
- }
-
-/*
-* Constructor for Algorithm_Not_Found
-*/
-Algorithm_Not_Found::Algorithm_Not_Found(const std::string& name)
- {
- set_msg("Could not find any algorithm named \"" + name + "\"");
- }
-
-/*
-* Constructor for Invalid_Algorithm_Name
-*/
-Invalid_Algorithm_Name::Invalid_Algorithm_Name(const std::string& name)
- {
- set_msg("Invalid algorithm name: " + name);
- }
-
-/*
-* Constructor for Config_Error
-*/
-Config_Error::Config_Error(const std::string& err, u32bit line)
- {
- set_msg("Config error at line " + to_string(line) + ": " + err);
- }
-
-}
diff --git a/src/utils/exceptn.h b/src/utils/exceptn.h
index a55d842bc..86efebc7c 100644
--- a/src/utils/exceptn.h
+++ b/src/utils/exceptn.h
@@ -1,6 +1,6 @@
/*
* Exceptions
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -9,32 +9,44 @@
#define BOTAN_EXCEPTION_H__
#include <botan/types.h>
+#include <botan/parsing.h>
#include <exception>
+#include <stdexcept>
#include <string>
namespace Botan {
+typedef std::runtime_error Exception;
+typedef std::invalid_argument Invalid_Argument;
+
/*
-* Exception Base Class
+* Invalid_State Exception
*/
-class BOTAN_DLL Exception : public std::exception
+struct BOTAN_DLL Invalid_State : public Exception
{
- public:
- const char* what() const throw() { return msg.c_str(); }
- Exception(const std::string& m = "Unknown error") { set_msg(m); }
- virtual ~Exception() throw() {}
- protected:
- void set_msg(const std::string& m) { msg = "Botan: " + m; }
- private:
- std::string msg;
+ Invalid_State(const std::string& err) :
+ Exception(err)
+ {}
};
/*
-* Invalid_Argument Exception
+* Lookup_Error Exception
*/
-struct BOTAN_DLL Invalid_Argument : public Exception
+struct BOTAN_DLL Lookup_Error : public Exception
{
- Invalid_Argument(const std::string& err = "") : Exception(err) {}
+ Lookup_Error(const std::string& err) :
+ Exception(err)
+ {}
+ };
+
+/*
+* Internal_Error Exception
+*/
+struct BOTAN_DLL Internal_Error : public Exception
+ {
+ Internal_Error(const std::string& err) :
+ Exception("Internal error: " + err)
+ {}
};
/*
@@ -42,7 +54,10 @@ struct BOTAN_DLL Invalid_Argument : public Exception
*/
struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument
{
- Invalid_Key_Length(const std::string&, u32bit);
+ Invalid_Key_Length(const std::string& name, u32bit length) :
+ Invalid_Argument(name + " cannot accept a key of length " +
+ to_string(length))
+ {}
};
/*
@@ -50,7 +65,11 @@ struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument
*/
struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument
{
- Invalid_Block_Size(const std::string&, const std::string&);
+ Invalid_Block_Size(const std::string& mode,
+ const std::string& pad) :
+ Invalid_Argument("Padding method " + pad +
+ " cannot be used with " + mode)
+ {}
};
/*
@@ -58,15 +77,10 @@ struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument
*/
struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument
{
- Invalid_IV_Length(const std::string&, u32bit);
- };
-
-/*
-* Invalid_State Exception
-*/
-struct BOTAN_DLL Invalid_State : public Exception
- {
- Invalid_State(const std::string& err) : Exception(err) {}
+ Invalid_IV_Length(const std::string& mode, u32bit bad_len) :
+ Invalid_Argument("IV length " + to_string(bad_len) +
+ " is invalid for " + mode)
+ {}
};
/*
@@ -75,7 +89,8 @@ struct BOTAN_DLL Invalid_State : public Exception
struct BOTAN_DLL PRNG_Unseeded : public Invalid_State
{
PRNG_Unseeded(const std::string& algo) :
- Invalid_State("PRNG not seeded: " + algo) {}
+ Invalid_State("PRNG not seeded: " + algo)
+ {}
};
/*
@@ -84,57 +99,46 @@ struct BOTAN_DLL PRNG_Unseeded : public Invalid_State
struct BOTAN_DLL Policy_Violation : public Invalid_State
{
Policy_Violation(const std::string& err) :
- Invalid_State("Policy violation: " + err) {}
- };
-
-/*
-* Lookup_Error Exception
-*/
-struct BOTAN_DLL Lookup_Error : public Exception
- {
- Lookup_Error(const std::string& err) : Exception(err) {}
+ Invalid_State("Policy violation: " + err)
+ {}
};
/*
* Algorithm_Not_Found Exception
*/
-struct BOTAN_DLL Algorithm_Not_Found : public Exception
+struct BOTAN_DLL Algorithm_Not_Found : public Lookup_Error
{
- Algorithm_Not_Found(const std::string&);
- };
-
-/*
-* Format_Error Exception
-*/
-struct BOTAN_DLL Format_Error : public Exception
- {
- Format_Error(const std::string& err = "") : Exception(err) {}
+ Algorithm_Not_Found(const std::string& name) :
+ Lookup_Error("Could not find any algorithm named \"" + name + "\"")
+ {}
};
/*
* Invalid_Algorithm_Name Exception
*/
-struct BOTAN_DLL Invalid_Algorithm_Name : public Format_Error
+struct BOTAN_DLL Invalid_Algorithm_Name : public Invalid_Argument
{
- Invalid_Algorithm_Name(const std::string&);
+ Invalid_Algorithm_Name(const std::string& name):
+ Invalid_Argument("Invalid algorithm name: " + name)
+ {}
};
/*
* Encoding_Error Exception
*/
-struct BOTAN_DLL Encoding_Error : public Format_Error
+struct BOTAN_DLL Encoding_Error : public Invalid_Argument
{
Encoding_Error(const std::string& name) :
- Format_Error("Encoding error: " + name) {}
+ Invalid_Argument("Encoding error: " + name) {}
};
/*
* Decoding_Error Exception
*/
-struct BOTAN_DLL Decoding_Error : public Format_Error
+struct BOTAN_DLL Decoding_Error : public Invalid_Argument
{
Decoding_Error(const std::string& name) :
- Format_Error("Decoding error: " + name) {}
+ Invalid_Argument("Decoding error: " + name) {}
};
/*
@@ -152,44 +156,27 @@ struct BOTAN_DLL Invalid_OID : public Decoding_Error
struct BOTAN_DLL Stream_IO_Error : public Exception
{
Stream_IO_Error(const std::string& err) :
- Exception("I/O error: " + err) {}
+ Exception("I/O error: " + err)
+ {}
};
/*
-* Configuration Error Exception
-*/
-struct BOTAN_DLL Config_Error : public Format_Error
- {
- Config_Error(const std::string& err) :
- Format_Error("Config error: " + err) {}
- Config_Error(const std::string&, u32bit);
- };
-
-/*
-* Integrity Failure Exception
-*/
-struct BOTAN_DLL Integrity_Failure : public Exception
- {
- Integrity_Failure(const std::string& err) :
- Exception("Integrity failure: " + err) {}
- };
-
-/*
-* Internal_Error Exception
+* Self Test Failure Exception
*/
-struct BOTAN_DLL Internal_Error : public Exception
+struct BOTAN_DLL Self_Test_Failure : public Internal_Error
{
- Internal_Error(const std::string& err) :
- Exception("Internal error: " + err) {}
+ Self_Test_Failure(const std::string& err) :
+ Internal_Error("Self test failed: " + err)
+ {}
};
/*
-* Self Test Failure Exception
+* Memory Allocation Exception
*/
-struct BOTAN_DLL Self_Test_Failure : public Internal_Error
+struct BOTAN_DLL Memory_Exhaustion : public std::bad_alloc
{
- Self_Test_Failure(const std::string& err) :
- Internal_Error("Self test failed: " + err) {}
+ const char* what() const throw()
+ { return "Ran out of memory, allocation failed"; }
};
}
diff --git a/src/utils/get_byte.h b/src/utils/get_byte.h
new file mode 100644
index 000000000..fce87af83
--- /dev/null
+++ b/src/utils/get_byte.h
@@ -0,0 +1,27 @@
+/*
+* Read out bytes
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_GET_BYTE_H__
+#define BOTAN_GET_BYTE_H__
+
+#include <botan/types.h>
+
+namespace Botan {
+
+/*
+* Byte Extraction Function
+*/
+template<typename T> inline byte get_byte(u32bit byte_num, T input)
+ {
+ return static_cast<byte>(
+ input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)
+ );
+ }
+
+}
+
+#endif
diff --git a/src/utils/info.txt b/src/utils/info.txt
index 93ece2e78..2fb3e79a5 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -5,7 +5,6 @@ load_on always
<source>
charset.cpp
cpuid.cpp
-exceptn.cpp
mlock.cpp
parsing.cpp
time.cpp
@@ -15,6 +14,7 @@ version.cpp
<header:internal>
bit_ops.h
+debug.h
mlock.h
prefetch.h
rounding.h
@@ -35,6 +35,7 @@ time.h
types.h
ui.h
version.h
+get_byte.h
</header:public>
<libs>
diff --git a/src/utils/loadstor.h b/src/utils/loadstor.h
index bd2acc87d..ffd27540d 100644
--- a/src/utils/loadstor.h
+++ b/src/utils/loadstor.h
@@ -11,6 +11,7 @@
#include <botan/types.h>
#include <botan/bswap.h>
+#include <botan/get_byte.h>
#include <cstring>
#if BOTAN_TARGET_UNALIGNED_MEMORY_ACCESS_OK
@@ -38,16 +39,6 @@
namespace Botan {
/*
-* Byte Extraction Function
-*/
-template<typename T> inline byte get_byte(u32bit byte_num, T input)
- {
- return static_cast<byte>(
- input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)
- );
- }
-
-/*
* Byte to Word Conversions
*/
inline u16bit make_u16bit(byte i0, byte i1)
diff --git a/src/utils/mlock.cpp b/src/utils/mlock.cpp
index bb3a38d4e..5d6fc3591 100644
--- a/src/utils/mlock.cpp
+++ b/src/utils/mlock.cpp
@@ -22,9 +22,9 @@ namespace Botan {
bool lock_mem(void* ptr, u32bit bytes)
{
#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
- return (mlock(ptr, bytes) == 0);
+ return (::mlock(ptr, bytes) == 0);
#elif defined(BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK)
- return (VirtualLock(ptr, bytes) != 0);
+ return (::VirtualLock(ptr, bytes) != 0);
#else
return false;
#endif
@@ -36,9 +36,9 @@ bool lock_mem(void* ptr, u32bit bytes)
void unlock_mem(void* ptr, u32bit bytes)
{
#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
- munlock(ptr, bytes);
+ ::munlock(ptr, bytes);
#elif defined(BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK)
- VirtualUnlock(ptr, bytes);
+ ::VirtualUnlock(ptr, bytes);
#endif
}
diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp
index 58a8e0b38..e8259ac52 100644
--- a/src/utils/parsing.cpp
+++ b/src/utils/parsing.cpp
@@ -8,7 +8,7 @@
#include <botan/parsing.h>
#include <botan/exceptn.h>
#include <botan/charset.h>
-#include <botan/loadstor.h>
+#include <botan/get_byte.h>
namespace Botan {
@@ -168,7 +168,7 @@ std::vector<std::string> split_on(const std::string& str, char delim)
}
if(substr == "")
- throw Format_Error("Unable to split string: " + str);
+ throw Invalid_Argument("Unable to split string: " + str);
elems.push_back(substr);
return elems;
diff --git a/src/utils/prefetch.h b/src/utils/prefetch.h
index 7afdbda0a..ede196692 100644
--- a/src/utils/prefetch.h
+++ b/src/utils/prefetch.h
@@ -32,7 +32,7 @@ inline void readwrite(const T* addr, u32bit length)
const u32bit Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T);
for(u32bit i = 0; i <= length; i += Ts_per_cache_line)
- __builtin_prefetch(addr + i, 0);
+ __builtin_prefetch(addr + i, 1);
#endif
}
diff --git a/src/utils/simd_32/info.txt b/src/utils/simd_32/info.txt
index 08cbdfa52..362e90235 100644
--- a/src/utils/simd_32/info.txt
+++ b/src/utils/simd_32/info.txt
@@ -1,7 +1,5 @@
define SIMD_32
-load_on always
-
<header:internal>
simd_32.h
simd_sse.h
diff --git a/src/utils/simd_32/simd_32.h b/src/utils/simd_32/simd_32.h
index 38ea078d0..4bd983f5e 100644
--- a/src/utils/simd_32/simd_32.h
+++ b/src/utils/simd_32/simd_32.h
@@ -27,4 +27,20 @@
#endif
+namespace Botan {
+
+inline SIMD_32 rotate_left(SIMD_32 x, u32bit rot)
+ {
+ x.rotate_left(rot);
+ return x;
+ }
+
+inline SIMD_32 rotate_right(SIMD_32 x, u32bit rot)
+ {
+ x.rotate_right(rot);
+ return x;
+ }
+
+}
+
#endif
diff --git a/src/utils/simd_32/simd_altivec.h b/src/utils/simd_32/simd_altivec.h
index 9cc5c1068..859a48a5f 100644
--- a/src/utils/simd_32/simd_altivec.h
+++ b/src/utils/simd_32/simd_altivec.h
@@ -145,6 +145,11 @@ class SIMD_Altivec
reg = vec_or(reg, other.reg);
}
+ SIMD_Altivec operator&(const SIMD_Altivec& other)
+ {
+ return vec_and(reg, other.reg);
+ }
+
void operator&=(const SIMD_Altivec& other)
{
reg = vec_and(reg, other.reg);
diff --git a/src/utils/simd_32/simd_scalar.h b/src/utils/simd_32/simd_scalar.h
index 148b76c35..5cf1a11c3 100644
--- a/src/utils/simd_32/simd_scalar.h
+++ b/src/utils/simd_32/simd_scalar.h
@@ -142,6 +142,14 @@ class SIMD_Scalar
R3 |= other.R3;
}
+ SIMD_Scalar operator&(const SIMD_Scalar& other)
+ {
+ return SIMD_Scalar(R0 & other.R0,
+ R1 & other.R1,
+ R2 & other.R2,
+ R3 & other.R3);
+ }
+
void operator&=(const SIMD_Scalar& other)
{
R0 &= other.R0;
diff --git a/src/utils/simd_32/simd_sse.h b/src/utils/simd_32/simd_sse.h
index 31bbce2c7..0189c2e4d 100644
--- a/src/utils/simd_32/simd_sse.h
+++ b/src/utils/simd_32/simd_sse.h
@@ -101,6 +101,11 @@ class SIMD_SSE2
reg = _mm_or_si128(reg, other.reg);
}
+ SIMD_SSE2 operator&(const SIMD_SSE2& other)
+ {
+ return _mm_and_si128(reg, other.reg);
+ }
+
void operator&=(const SIMD_SSE2& other)
{
reg = _mm_and_si128(reg, other.reg);