aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/asn1/oid_lookup/oids.cpp16
-rw-r--r--src/lib/base/algo_registry.h16
-rw-r--r--src/lib/base/scan_name.cpp6
-rw-r--r--src/lib/base/scan_name.h4
-rw-r--r--src/lib/block/aes_ni/aes_ni.cpp12
-rw-r--r--src/lib/block/aes_ssse3/aes_ssse3.cpp18
-rw-r--r--src/lib/block/idea_sse2/idea_sse2.cpp4
-rw-r--r--src/lib/block/threefish_avx2/threefish_avx2.cpp5
-rw-r--r--src/lib/cert/x509/certstor.cpp2
-rw-r--r--src/lib/cert/x509/certstor_sql/certstor_sql.h2
-rw-r--r--src/lib/cert/x509/pkcs10.cpp6
-rw-r--r--src/lib/cert/x509/pkcs10.h2
-rw-r--r--src/lib/cert/x509/x509_crl.cpp6
-rw-r--r--src/lib/cert/x509/x509_crl.h2
-rw-r--r--src/lib/cert/x509/x509_obj.cpp2
-rw-r--r--src/lib/cert/x509/x509_obj.h5
-rw-r--r--src/lib/cert/x509/x509cert.cpp6
-rw-r--r--src/lib/cert/x509/x509cert.h2
-rw-r--r--src/lib/cert/x509/x509path.cpp1
-rw-r--r--src/lib/entropy/egd/es_egd.cpp2
-rw-r--r--src/lib/entropy/egd/es_egd.h4
-rw-r--r--src/lib/entropy/proc_walk/proc_walk.cpp2
-rw-r--r--src/lib/entropy/proc_walk/proc_walk.h4
-rw-r--r--src/lib/entropy/rdseed/rdseed.cpp1
-rw-r--r--src/lib/entropy/unix_procs/unix_procs.cpp2
-rw-r--r--src/lib/entropy/unix_procs/unix_procs.h4
-rw-r--r--src/lib/ffi/ffi.cpp4
-rw-r--r--src/lib/filters/basefilt.h6
-rw-r--r--src/lib/filters/data_snk.cpp7
-rw-r--r--src/lib/filters/data_snk.h4
-rw-r--r--src/lib/filters/threaded_fork.cpp5
-rw-r--r--src/lib/hash/sha1_sse2/sha1_sse2.cpp1
-rw-r--r--src/lib/misc/srp6/srp6_files.cpp5
-rw-r--r--src/lib/misc/srp6/srp6_files.h7
-rw-r--r--src/lib/modes/aead/gcm/clmul/clmul.cpp1
-rw-r--r--src/lib/pubkey/dsa/dsa.cpp15
-rw-r--r--src/lib/pubkey/pkcs8.cpp3
-rw-r--r--src/lib/pubkey/pkcs8.h2
-rw-r--r--src/lib/pubkey/rsa/rsa.cpp11
-rw-r--r--src/lib/pubkey/x509_key.cpp2
-rw-r--r--src/lib/pubkey/x509_key.h2
-rw-r--r--src/lib/rng/rdrand_rng/rdrand_rng.cpp1
-rw-r--r--src/lib/rng/rng.cpp2
-rw-r--r--src/lib/rng/rng.h20
-rw-r--r--src/lib/stream/chacha/chacha_sse2/chacha_sse2.cpp1
-rw-r--r--src/lib/tls/tls_session_manager.h4
-rw-r--r--src/lib/tls/tls_session_manager_memory.cpp8
-rw-r--r--src/lib/utils/calendar.cpp4
-rw-r--r--src/lib/utils/data_src.cpp9
-rw-r--r--src/lib/utils/data_src.h4
-rw-r--r--src/lib/utils/http_util/http_util.cpp5
-rw-r--r--src/lib/utils/http_util/http_util.h4
-rw-r--r--src/lib/utils/info.txt1
-rw-r--r--src/lib/utils/locking_allocator/locking_allocator.cpp6
-rw-r--r--src/lib/utils/locking_allocator/locking_allocator.h4
-rw-r--r--src/lib/utils/mutex.h61
-rw-r--r--src/lib/utils/os_utils.cpp4
-rw-r--r--src/lib/utils/semaphore.cpp8
-rw-r--r--src/lib/utils/semaphore.h9
59 files changed, 281 insertions, 85 deletions
diff --git a/src/lib/asn1/oid_lookup/oids.cpp b/src/lib/asn1/oid_lookup/oids.cpp
index cdb863494..8ee10b75a 100644
--- a/src/lib/asn1/oid_lookup/oids.cpp
+++ b/src/lib/asn1/oid_lookup/oids.cpp
@@ -7,7 +7,7 @@
#include <botan/oids.h>
#include <botan/parsing.h>
-#include <mutex>
+#include <botan/mutex.h>
#include <sstream>
namespace Botan {
@@ -27,7 +27,7 @@ class OID_Map
void add_str2oid(const OID& oid, const std::string& str)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_str2oid.find(str);
if(i == m_str2oid.end())
m_str2oid.insert(std::make_pair(str, oid));
@@ -35,7 +35,7 @@ class OID_Map
void add_oid2str(const OID& oid, const std::string& str)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_oid2str.find(oid);
if(i == m_oid2str.end())
m_oid2str.insert(std::make_pair(oid, str));
@@ -43,7 +43,7 @@ class OID_Map
std::string lookup(const OID& oid)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_oid2str.find(oid);
if(i != m_oid2str.end())
@@ -54,7 +54,7 @@ class OID_Map
OID lookup(const std::string& str)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_str2oid.find(str);
if(i != m_str2oid.end())
@@ -72,7 +72,7 @@ class OID_Map
bool have_oid(const std::string& str)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
return m_str2oid.find(str) != m_str2oid.end();
}
@@ -92,14 +92,14 @@ class OID_Map
read_cfg(cfg, "builtin");
}
- std::mutex m_mutex;
+ mutex_type m_mutex;
std::map<std::string, OID> m_str2oid;
std::map<OID, std::string> m_oid2str;
};
void OID_Map::read_cfg(std::istream& cfg, const std::string& source)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
size_t line = 0;
diff --git a/src/lib/base/algo_registry.h b/src/lib/base/algo_registry.h
index f7e66b3e2..bca3715b6 100644
--- a/src/lib/base/algo_registry.h
+++ b/src/lib/base/algo_registry.h
@@ -13,7 +13,7 @@
#include <botan/exceptn.h>
#include <botan/scan_name.h>
#include <functional>
-#include <mutex>
+#include <botan/mutex.h>
#include <vector>
#include <map>
#include <string>
@@ -77,14 +77,14 @@ class Algo_Registry
void add(const std::string& name, const std::string& provider, maker_fn fn, byte pref)
{
- std::lock_guard<mutex> lock(m_mutex);
+ lock_guard_type<af_mutex_type> lock(m_mutex);
if(!m_algo_info[name].add_provider(provider, fn, pref))
throw Exception("Duplicated registration of " + name + "/" + provider);
}
std::vector<std::string> providers_of(const Spec& spec)
{
- std::lock_guard<mutex> lock(m_mutex);
+ lock_guard_type<af_mutex_type> lock(m_mutex);
auto i = m_algo_info.find(spec.algo_name());
if(i != m_algo_info.end())
return i->second.providers();
@@ -93,7 +93,7 @@ class Algo_Registry
void set_provider_preference(const Spec& spec, const std::string& provider, byte pref)
{
- std::lock_guard<mutex> lock(m_mutex);
+ lock_guard_type<af_mutex_type> lock(m_mutex);
auto i = m_algo_info.find(spec.algo_name());
if(i != m_algo_info.end())
i->second.set_pref(provider, pref);
@@ -137,16 +137,16 @@ class Algo_Registry
private:
#if defined(BOTAN_WORKAROUND_GH_321)
- using mutex = WinCS_Mutex;
+ using af_mutex_type = WinCS_Mutex;
#else
- using mutex = std::mutex;
+ using af_mutex_type = mutex_type;
#endif
Algo_Registry() { }
std::vector<maker_fn> get_makers(const Spec& spec, const std::string& provider)
{
- std::lock_guard<mutex> lock(m_mutex);
+ lock_guard_type<af_mutex_type> lock(m_mutex);
return m_algo_info[spec.algo_name()].get_makers(provider);
}
@@ -208,7 +208,7 @@ class Algo_Registry
std::unordered_map<std::string, maker_fn> m_maker_fns;
};
- mutex m_mutex;
+ af_mutex_type m_mutex;
std::unordered_map<std::string, Algo_Info> m_algo_info;
};
diff --git a/src/lib/base/scan_name.cpp b/src/lib/base/scan_name.cpp
index 08f5e8702..76d9b1a17 100644
--- a/src/lib/base/scan_name.cpp
+++ b/src/lib/base/scan_name.cpp
@@ -172,7 +172,7 @@ size_t SCAN_Name::arg_as_integer(size_t i, size_t def_value) const
return to_u32bit(m_args[i]);
}
-std::mutex SCAN_Name::g_alias_map_mutex;
+mutex_type SCAN_Name::g_alias_map_mutex;
std::map<std::string, std::string> SCAN_Name::g_alias_map = {
{ "3DES", "TripleDES" },
{ "ARC4", "RC4" },
@@ -197,7 +197,7 @@ std::map<std::string, std::string> SCAN_Name::g_alias_map = {
void SCAN_Name::add_alias(const std::string& alias, const std::string& basename)
{
- std::lock_guard<std::mutex> lock(g_alias_map_mutex);
+ lock_guard_type<mutex_type> lock(g_alias_map_mutex);
if(g_alias_map.find(alias) == g_alias_map.end())
g_alias_map[alias] = basename;
@@ -205,7 +205,7 @@ void SCAN_Name::add_alias(const std::string& alias, const std::string& basename)
std::string SCAN_Name::deref_alias(const std::string& alias)
{
- std::lock_guard<std::mutex> lock(g_alias_map_mutex);
+ lock_guard_type<mutex_type> lock(g_alias_map_mutex);
std::string name = alias;
diff --git a/src/lib/base/scan_name.h b/src/lib/base/scan_name.h
index c19bbf50f..75f7d1089 100644
--- a/src/lib/base/scan_name.h
+++ b/src/lib/base/scan_name.h
@@ -11,7 +11,7 @@
#include <botan/types.h>
#include <string>
#include <vector>
-#include <mutex>
+#include <botan/mutex.h>
#include <map>
namespace Botan {
@@ -117,7 +117,7 @@ class BOTAN_DLL SCAN_Name
*/
static std::string deref_alias(const std::string& alias);
private:
- static std::mutex g_alias_map_mutex;
+ static mutex_type g_alias_map_mutex;
static std::map<std::string, std::string> g_alias_map;
std::string m_orig_algo_spec;
diff --git a/src/lib/block/aes_ni/aes_ni.cpp b/src/lib/block/aes_ni/aes_ni.cpp
index 3377f9d61..7518a6cf2 100644
--- a/src/lib/block/aes_ni/aes_ni.cpp
+++ b/src/lib/block/aes_ni/aes_ni.cpp
@@ -13,6 +13,7 @@ namespace Botan {
namespace {
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_128_key_expansion(__m128i key, __m128i key_with_rcon)
{
key_with_rcon = _mm_shuffle_epi32(key_with_rcon, _MM_SHUFFLE(3,3,3,3));
@@ -22,6 +23,7 @@ __m128i aes_128_key_expansion(__m128i key, __m128i key_with_rcon)
return _mm_xor_si128(key, key_with_rcon);
}
+BOTAN_FUNC_ISA("ssse3")
void aes_192_key_expansion(__m128i* K1, __m128i* K2, __m128i key2_with_rcon,
u32bit out[], bool last)
{
@@ -51,6 +53,7 @@ void aes_192_key_expansion(__m128i* K1, __m128i* K2, __m128i key2_with_rcon,
/*
* The second half of the AES-256 key expansion (other half same as AES-128)
*/
+BOTAN_FUNC_ISA("ssse3,aes")
__m128i aes_256_key_expansion(__m128i key, __m128i key2)
{
__m128i key_with_rcon = _mm_aeskeygenassist_si128(key2, 0x00);
@@ -103,6 +106,7 @@ __m128i aes_256_key_expansion(__m128i key, __m128i key2)
/*
* AES-128 Encryption
*/
+BOTAN_FUNC_ISA("ssse3,aes")
void AES_128::aesni_encrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -179,6 +183,7 @@ void AES_128::aesni_encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-128 Decryption
*/
+BOTAN_FUNC_ISA("ssse3,aes")
void AES_128::aesni_decrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -255,6 +260,7 @@ void AES_128::aesni_decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-128 Key Schedule
*/
+BOTAN_FUNC_ISA("ssse3,aes")
void AES_128::aesni_key_schedule(const byte key[], size_t)
{
m_EK.resize(44);
@@ -307,6 +313,7 @@ void AES_128::aesni_key_schedule(const byte key[], size_t)
/*
* AES-192 Encryption
*/
+BOTAN_FUNC_ISA("ssse3,aes")
void AES_192::aesni_encrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -389,6 +396,7 @@ void AES_192::aesni_encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-192 Decryption
*/
+BOTAN_FUNC_ISA("ssse3,aes")
void AES_192::aesni_decrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -471,6 +479,7 @@ void AES_192::aesni_decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-192 Key Schedule
*/
+BOTAN_FUNC_ISA("ssse3,aes")
void AES_192::aesni_key_schedule(const byte key[], size_t)
{
m_EK.resize(52);
@@ -520,6 +529,7 @@ void AES_192::aesni_key_schedule(const byte key[], size_t)
/*
* AES-256 Encryption
*/
+BOTAN_FUNC_ISA("ssse3,aes")
void AES_256::aesni_encrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -608,6 +618,7 @@ void AES_256::aesni_encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-256 Decryption
*/
+BOTAN_FUNC_ISA("ssse3,aes")
void AES_256::aesni_decrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -696,6 +707,7 @@ void AES_256::aesni_decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-256 Key Schedule
*/
+BOTAN_FUNC_ISA("ssse3,aes")
void AES_256::aesni_key_schedule(const byte key[], size_t)
{
m_EK.resize(60);
diff --git a/src/lib/block/aes_ssse3/aes_ssse3.cpp b/src/lib/block/aes_ssse3/aes_ssse3.cpp
index eda39a7cc..ef24795bb 100644
--- a/src/lib/block/aes_ssse3/aes_ssse3.cpp
+++ b/src/lib/block/aes_ssse3/aes_ssse3.cpp
@@ -51,6 +51,7 @@ const __m128i sr[4] = {
#define mm_xor3(x, y, z) _mm_xor_si128(x, _mm_xor_si128(y, z))
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_schedule_transform(__m128i input,
__m128i table_1,
__m128i table_2)
@@ -63,6 +64,7 @@ __m128i aes_schedule_transform(__m128i input,
_mm_shuffle_epi8(table_2, i_2));
}
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_schedule_mangle(__m128i k, byte round_no)
{
__m128i t = _mm_shuffle_epi8(_mm_xor_si128(k, _mm_set1_epi8(0x5B)),
@@ -77,6 +79,7 @@ __m128i aes_schedule_mangle(__m128i k, byte round_no)
return _mm_shuffle_epi8(t2, sr[round_no % 4]);
}
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_schedule_192_smear(__m128i x, __m128i y)
{
return mm_xor3(y,
@@ -84,6 +87,7 @@ __m128i aes_schedule_192_smear(__m128i x, __m128i y)
_mm_shuffle_epi32(y, 0x80));
}
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_schedule_mangle_dec(__m128i k, byte round_no)
{
const __m128i dsk[8] = {
@@ -112,6 +116,7 @@ __m128i aes_schedule_mangle_dec(__m128i k, byte round_no)
return _mm_shuffle_epi8(output, sr[round_no % 4]);
}
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_schedule_mangle_last(__m128i k, byte round_no)
{
const __m128i out_tr1 = _mm_set_epi32(
@@ -124,6 +129,7 @@ __m128i aes_schedule_mangle_last(__m128i k, byte round_no)
return aes_schedule_transform(k, out_tr1, out_tr2);
}
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_schedule_mangle_last_dec(__m128i k)
{
const __m128i deskew1 = _mm_set_epi32(
@@ -135,6 +141,7 @@ __m128i aes_schedule_mangle_last_dec(__m128i k)
return aes_schedule_transform(k, deskew1, deskew2);
}
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_schedule_round(__m128i* rcon, __m128i input1, __m128i input2)
{
if(rcon)
@@ -170,6 +177,7 @@ __m128i aes_schedule_round(__m128i* rcon, __m128i input1, __m128i input2)
smeared);
}
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_ssse3_encrypt(__m128i B, const __m128i* keys, size_t rounds)
{
const __m128i sb2u = _mm_set_epi32(
@@ -239,6 +247,7 @@ __m128i aes_ssse3_encrypt(__m128i B, const __m128i* keys, size_t rounds)
}
}
+BOTAN_FUNC_ISA("ssse3")
__m128i aes_ssse3_decrypt(__m128i B, const __m128i* keys, size_t rounds)
{
const __m128i k_dipt1 = _mm_set_epi32(
@@ -336,6 +345,7 @@ __m128i aes_ssse3_decrypt(__m128i B, const __m128i* keys, size_t rounds)
/*
* AES-128 Encryption
*/
+BOTAN_FUNC_ISA("ssse3")
void AES_128::ssse3_encrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -358,6 +368,7 @@ void AES_128::ssse3_encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-128 Decryption
*/
+BOTAN_FUNC_ISA("ssse3")
void AES_128::ssse3_decrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -380,6 +391,7 @@ void AES_128::ssse3_decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-128 Key Schedule
*/
+BOTAN_FUNC_ISA("ssse3")
void AES_128::ssse3_key_schedule(const byte keyb[], size_t)
{
__m128i rcon = _mm_set_epi32(0x702A9808, 0x4D7C7D81,
@@ -418,6 +430,7 @@ void AES_128::ssse3_key_schedule(const byte keyb[], size_t)
/*
* AES-192 Encryption
*/
+BOTAN_FUNC_ISA("ssse3")
void AES_192::ssse3_encrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -440,6 +453,7 @@ void AES_192::ssse3_encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-192 Decryption
*/
+BOTAN_FUNC_ISA("ssse3")
void AES_192::ssse3_decrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -462,6 +476,7 @@ void AES_192::ssse3_decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-192 Key Schedule
*/
+BOTAN_FUNC_ISA("ssse3")
void AES_192::ssse3_key_schedule(const byte keyb[], size_t)
{
__m128i rcon = _mm_set_epi32(0x702A9808, 0x4D7C7D81,
@@ -529,6 +544,7 @@ void AES_192::ssse3_key_schedule(const byte keyb[], size_t)
/*
* AES-256 Encryption
*/
+BOTAN_FUNC_ISA("ssse3")
void AES_256::ssse3_encrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -551,6 +567,7 @@ void AES_256::ssse3_encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-256 Decryption
*/
+BOTAN_FUNC_ISA("ssse3")
void AES_256::ssse3_decrypt_n(const byte in[], byte out[], size_t blocks) const
{
const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
@@ -573,6 +590,7 @@ void AES_256::ssse3_decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* AES-256 Key Schedule
*/
+BOTAN_FUNC_ISA("ssse3")
void AES_256::ssse3_key_schedule(const byte keyb[], size_t)
{
__m128i rcon = _mm_set_epi32(0x702A9808, 0x4D7C7D81,
diff --git a/src/lib/block/idea_sse2/idea_sse2.cpp b/src/lib/block/idea_sse2/idea_sse2.cpp
index 4debfc95a..1e63a8332 100644
--- a/src/lib/block/idea_sse2/idea_sse2.cpp
+++ b/src/lib/block/idea_sse2/idea_sse2.cpp
@@ -13,6 +13,7 @@ namespace Botan {
namespace {
+BOTAN_FUNC_ISA("sse2")
inline __m128i mul(__m128i X, u16bit K_16)
{
const __m128i zeros = _mm_set1_epi16(0);
@@ -61,6 +62,7 @@ inline __m128i mul(__m128i X, u16bit K_16)
* that extra unpack could easily save 3-4 cycles per block, and would
* also help a lot with register pressure on 32-bit x86
*/
+BOTAN_FUNC_ISA("sse2")
void transpose_in(__m128i& B0, __m128i& B1, __m128i& B2, __m128i& B3)
{
__m128i T0 = _mm_unpackhi_epi32(B0, B1);
@@ -97,6 +99,7 @@ void transpose_in(__m128i& B0, __m128i& B1, __m128i& B2, __m128i& B3)
/*
* 4x8 matrix transpose (reverse)
*/
+BOTAN_FUNC_ISA("sse2")
void transpose_out(__m128i& B0, __m128i& B1, __m128i& B2, __m128i& B3)
{
__m128i T0 = _mm_unpacklo_epi64(B0, B1);
@@ -130,6 +133,7 @@ void transpose_out(__m128i& B0, __m128i& B1, __m128i& B2, __m128i& B3)
/*
* 8 wide IDEA encryption/decryption in SSE2
*/
+BOTAN_FUNC_ISA("sse2")
void IDEA::sse2_idea_op_8(const byte in[64], byte out[64], const u16bit EK[52]) const
{
CT::poison(in, 64);
diff --git a/src/lib/block/threefish_avx2/threefish_avx2.cpp b/src/lib/block/threefish_avx2/threefish_avx2.cpp
index e0321812a..e4a46e3de 100644
--- a/src/lib/block/threefish_avx2/threefish_avx2.cpp
+++ b/src/lib/block/threefish_avx2/threefish_avx2.cpp
@@ -12,6 +12,7 @@ namespace Botan {
namespace {
+BOTAN_FUNC_ISA("avx2")
inline void interleave_epi64(__m256i& X0, __m256i& X1)
{
// interleave X0 and X1 qwords
@@ -24,6 +25,7 @@ inline void interleave_epi64(__m256i& X0, __m256i& X1)
X1 = _mm256_permute4x64_epi64(T1, _MM_SHUFFLE(3,1,2,0));
}
+BOTAN_FUNC_ISA("avx2")
inline void deinterleave_epi64(__m256i& X0, __m256i& X1)
{
const __m256i T0 = _mm256_permute4x64_epi64(X0, _MM_SHUFFLE(3,1,2,0));
@@ -33,6 +35,7 @@ inline void deinterleave_epi64(__m256i& X0, __m256i& X1)
X1 = _mm256_unpackhi_epi64(T0, T1);
}
+BOTAN_FUNC_ISA("avx2")
inline void rotate_keys(__m256i& R0, __m256i& R1, __m256i R2)
{
/*
@@ -71,6 +74,7 @@ inline void rotate_keys(__m256i& R0, __m256i& R1, __m256i R2)
}
+BOTAN_FUNC_ISA("avx2")
void Threefish_512::avx2_encrypt_n(const byte in[], byte out[], size_t blocks) const
{
const u64bit* K = &get_K()[0];
@@ -245,6 +249,7 @@ void Threefish_512::avx2_encrypt_n(const byte in[], byte out[], size_t blocks) c
#undef THREEFISH_INJECT_KEY_2
}
+BOTAN_FUNC_ISA("avx2")
void Threefish_512::avx2_decrypt_n(const byte in[], byte out[], size_t blocks) const
{
const u64bit* K = &get_K()[0];
diff --git a/src/lib/cert/x509/certstor.cpp b/src/lib/cert/x509/certstor.cpp
index 28b46ef1a..24cd84de7 100644
--- a/src/lib/cert/x509/certstor.cpp
+++ b/src/lib/cert/x509/certstor.cpp
@@ -114,6 +114,7 @@ Certificate_Store_In_Memory::Certificate_Store_In_Memory(const X509_Certificate&
add_certificate(cert);
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
Certificate_Store_In_Memory::Certificate_Store_In_Memory(const std::string& dir)
{
if(dir.empty())
@@ -131,6 +132,7 @@ Certificate_Store_In_Memory::Certificate_Store_In_Memory(const std::string& dir)
}
}
}
+#endif
std::shared_ptr<const X509_Certificate>
Certificate_Store_Overlay::find_cert(const X509_DN& subject_dn,
diff --git a/src/lib/cert/x509/certstor_sql/certstor_sql.h b/src/lib/cert/x509/certstor_sql/certstor_sql.h
index c1168b827..0025884f9 100644
--- a/src/lib/cert/x509/certstor_sql/certstor_sql.h
+++ b/src/lib/cert/x509/certstor_sql/certstor_sql.h
@@ -97,7 +97,7 @@ class BOTAN_DLL Certificate_Store_In_SQL : public Certificate_Store
std::shared_ptr<SQL_Database> m_database;
std::string m_prefix;
std::string m_password;
- std::mutex m_mutex;
+ mutex_type m_mutex;
};
}
diff --git a/src/lib/cert/x509/pkcs10.cpp b/src/lib/cert/x509/pkcs10.cpp
index 40a9894cc..ccd22454b 100644
--- a/src/lib/cert/x509/pkcs10.cpp
+++ b/src/lib/cert/x509/pkcs10.cpp
@@ -25,14 +25,16 @@ PKCS10_Request::PKCS10_Request(DataSource& in) :
do_decode();
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/*
* PKCS10_Request Constructor
*/
-PKCS10_Request::PKCS10_Request(const std::string& in) :
- X509_Object(in, "CERTIFICATE REQUEST/NEW CERTIFICATE REQUEST")
+PKCS10_Request::PKCS10_Request(const std::string& fsname) :
+ X509_Object(fsname, "CERTIFICATE REQUEST/NEW CERTIFICATE REQUEST")
{
do_decode();
}
+#endif
/*
* PKCS10_Request Constructor
diff --git a/src/lib/cert/x509/pkcs10.h b/src/lib/cert/x509/pkcs10.h
index 8c9f49d84..c7a9ec300 100644
--- a/src/lib/cert/x509/pkcs10.h
+++ b/src/lib/cert/x509/pkcs10.h
@@ -86,12 +86,14 @@ class BOTAN_DLL PKCS10_Request final : public X509_Object
*/
explicit PKCS10_Request(DataSource& source);
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/**
* Create a PKCS#10 Request from a file.
* @param filename the name of the file containing the DER or PEM
* encoded request file
*/
explicit PKCS10_Request(const std::string& filename);
+#endif
/**
* Create a PKCS#10 Request from binary data.
diff --git a/src/lib/cert/x509/x509_crl.cpp b/src/lib/cert/x509/x509_crl.cpp
index 3c75825c1..8eb4c01db 100644
--- a/src/lib/cert/x509/x509_crl.cpp
+++ b/src/lib/cert/x509/x509_crl.cpp
@@ -24,14 +24,16 @@ X509_CRL::X509_CRL(DataSource& in, bool touc) :
do_decode();
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/*
* Load a X.509 CRL
*/
-X509_CRL::X509_CRL(const std::string& in, bool touc) :
- X509_Object(in, "CRL/X509 CRL"), m_throw_on_unknown_critical(touc)
+X509_CRL::X509_CRL(const std::string& fsname, bool touc) :
+ X509_Object(fsname, "CRL/X509 CRL"), m_throw_on_unknown_critical(touc)
{
do_decode();
}
+#endif
X509_CRL::X509_CRL(const std::vector<byte>& in, bool touc) :
X509_Object(in, "CRL/X509 CRL"), m_throw_on_unknown_critical(touc)
diff --git a/src/lib/cert/x509/x509_crl.h b/src/lib/cert/x509/x509_crl.h
index 7373e9936..e11ea8f48 100644
--- a/src/lib/cert/x509/x509_crl.h
+++ b/src/lib/cert/x509/x509_crl.h
@@ -82,6 +82,7 @@ class BOTAN_DLL X509_CRL final : public X509_Object
*/
X509_CRL(DataSource& source, bool throw_on_unknown_critical = false);
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/**
* Construct a CRL from a file containing the DER or PEM encoded CRL.
* @param filename the name of the CRL file
@@ -90,6 +91,7 @@ class BOTAN_DLL X509_CRL final : public X509_Object
*/
X509_CRL(const std::string& filename,
bool throw_on_unknown_critical = false);
+#endif
/**
* Construct a CRL from a binary vector
diff --git a/src/lib/cert/x509/x509_obj.cpp b/src/lib/cert/x509/x509_obj.cpp
index 983be40b2..3c5d2a9b4 100644
--- a/src/lib/cert/x509/x509_obj.cpp
+++ b/src/lib/cert/x509/x509_obj.cpp
@@ -25,6 +25,7 @@ X509_Object::X509_Object(DataSource& stream, const std::string& labels)
init(stream, labels);
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/*
* Create a generic X.509 object
*/
@@ -33,6 +34,7 @@ X509_Object::X509_Object(const std::string& file, const std::string& labels)
DataSource_Stream stream(file, true);
init(stream, labels);
}
+#endif
/*
* Create a generic X.509 object
diff --git a/src/lib/cert/x509/x509_obj.h b/src/lib/cert/x509/x509_obj.h
index 8b561a142..40324775c 100644
--- a/src/lib/cert/x509/x509_obj.h
+++ b/src/lib/cert/x509/x509_obj.h
@@ -96,9 +96,12 @@ class BOTAN_DLL X509_Object : public ASN1_Object
virtual ~X509_Object() {}
protected:
X509_Object(DataSource& src, const std::string& pem_labels);
- X509_Object(const std::string& file, const std::string& pem_labels);
X509_Object(const std::vector<byte>& vec, const std::string& labels);
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+ X509_Object(const std::string& file, const std::string& pem_labels);
+#endif
+
void do_decode();
X509_Object() {}
AlgorithmIdentifier m_sig_algo;
diff --git a/src/lib/cert/x509/x509cert.cpp b/src/lib/cert/x509/x509cert.cpp
index 5765214ae..f56495a79 100644
--- a/src/lib/cert/x509/x509cert.cpp
+++ b/src/lib/cert/x509/x509cert.cpp
@@ -50,16 +50,18 @@ X509_Certificate::X509_Certificate(DataSource& in) :
do_decode();
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/*
* X509_Certificate Constructor
*/
-X509_Certificate::X509_Certificate(const std::string& in) :
- X509_Object(in, "CERTIFICATE/X509 CERTIFICATE"),
+X509_Certificate::X509_Certificate(const std::string& fsname) :
+ X509_Object(fsname, "CERTIFICATE/X509 CERTIFICATE"),
m_self_signed(false),
m_v3_extensions(false)
{
do_decode();
}
+#endif
/*
* X509_Certificate Constructor
diff --git a/src/lib/cert/x509/x509cert.h b/src/lib/cert/x509/x509cert.h
index 12e99c44e..acdba7e02 100644
--- a/src/lib/cert/x509/x509cert.h
+++ b/src/lib/cert/x509/x509cert.h
@@ -267,12 +267,14 @@ class BOTAN_DLL X509_Certificate : public X509_Object
*/
explicit X509_Certificate(DataSource& source);
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/**
* Create a certificate from a file containing the DER or PEM
* encoded certificate.
* @param filename the name of the certificate file
*/
explicit X509_Certificate(const std::string& filename);
+#endif
/**
* Create a certificate from a buffer
diff --git a/src/lib/cert/x509/x509path.cpp b/src/lib/cert/x509/x509path.cpp
index 65ab3eac1..29853bb4a 100644
--- a/src/lib/cert/x509/x509path.cpp
+++ b/src/lib/cert/x509/x509path.cpp
@@ -15,6 +15,7 @@
#include <chrono>
#include <vector>
#include <set>
+#include <future>
namespace Botan {
diff --git a/src/lib/entropy/egd/es_egd.cpp b/src/lib/entropy/egd/es_egd.cpp
index 384516aa8..fdc1c9a0f 100644
--- a/src/lib/entropy/egd/es_egd.cpp
+++ b/src/lib/entropy/egd/es_egd.cpp
@@ -136,7 +136,7 @@ EGD_EntropySource::~EGD_EntropySource()
*/
size_t EGD_EntropySource::poll(RandomNumberGenerator& rng)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
secure_vector<byte> buf(BOTAN_SYSTEM_RNG_POLL_REQUEST);
diff --git a/src/lib/entropy/egd/es_egd.h b/src/lib/entropy/egd/es_egd.h
index 04b4591e3..e0fb9c2d5 100644
--- a/src/lib/entropy/egd/es_egd.h
+++ b/src/lib/entropy/egd/es_egd.h
@@ -11,7 +11,7 @@
#include <botan/entropy_src.h>
#include <string>
#include <vector>
-#include <mutex>
+#include <botan/mutex.h>
namespace Botan {
@@ -42,7 +42,7 @@ class EGD_EntropySource final : public Entropy_Source
int m_fd; // cached fd
};
- std::mutex m_mutex;
+ mutex_type m_mutex;
std::vector<EGD_Socket> m_sockets;
secure_vector<uint8_t> m_io_buf;
};
diff --git a/src/lib/entropy/proc_walk/proc_walk.cpp b/src/lib/entropy/proc_walk/proc_walk.cpp
index beaa57308..5132ac951 100644
--- a/src/lib/entropy/proc_walk/proc_walk.cpp
+++ b/src/lib/entropy/proc_walk/proc_walk.cpp
@@ -114,7 +114,7 @@ size_t ProcWalking_EntropySource::poll(RandomNumberGenerator& rng)
{
const size_t MAX_FILES_READ_PER_POLL = 2048;
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
if(!m_dir)
m_dir.reset(new Directory_Walker(m_path));
diff --git a/src/lib/entropy/proc_walk/proc_walk.h b/src/lib/entropy/proc_walk/proc_walk.h
index 369b52699..4e9562c88 100644
--- a/src/lib/entropy/proc_walk/proc_walk.h
+++ b/src/lib/entropy/proc_walk/proc_walk.h
@@ -9,7 +9,7 @@
#define BOTAN_ENTROPY_SRC_PROC_WALK_H__
#include <botan/entropy_src.h>
-#include <mutex>
+#include <botan/mutex.h>
namespace Botan {
@@ -35,7 +35,7 @@ class ProcWalking_EntropySource final : public Entropy_Source
private:
const std::string m_path;
- std::mutex m_mutex;
+ mutex_type m_mutex;
std::unique_ptr<File_Descriptor_Source> m_dir;
secure_vector<byte> m_buf;
};
diff --git a/src/lib/entropy/rdseed/rdseed.cpp b/src/lib/entropy/rdseed/rdseed.cpp
index 325edfd41..01cab3a7e 100644
--- a/src/lib/entropy/rdseed/rdseed.cpp
+++ b/src/lib/entropy/rdseed/rdseed.cpp
@@ -15,6 +15,7 @@
namespace Botan {
+BOTAN_FUNC_ISA("rdseed")
size_t Intel_Rdseed::poll(RandomNumberGenerator& rng) {
if(CPUID::has_rdseed())
{
diff --git a/src/lib/entropy/unix_procs/unix_procs.cpp b/src/lib/entropy/unix_procs/unix_procs.cpp
index 8f885cfcf..d8dceba52 100644
--- a/src/lib/entropy/unix_procs/unix_procs.cpp
+++ b/src/lib/entropy/unix_procs/unix_procs.cpp
@@ -209,7 +209,7 @@ size_t Unix_EntropySource::poll(RandomNumberGenerator& rng)
if((getuid() != geteuid()) || (getgid() != getegid()) || (geteuid() == 0))
return 0;
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
if(m_sources.empty())
{
diff --git a/src/lib/entropy/unix_procs/unix_procs.h b/src/lib/entropy/unix_procs/unix_procs.h
index 27f7ab5bb..f87881d54 100644
--- a/src/lib/entropy/unix_procs/unix_procs.h
+++ b/src/lib/entropy/unix_procs/unix_procs.h
@@ -10,7 +10,7 @@
#include <botan/entropy_src.h>
#include <vector>
-#include <mutex>
+#include <botan/mutex.h>
namespace Botan {
@@ -67,7 +67,7 @@ class Unix_EntropySource final : public Entropy_Source
const std::vector<std::string>& next_source();
- std::mutex m_mutex;
+ mutex_type m_mutex;
const std::vector<std::string> m_trusted_paths;
const size_t m_concurrent;
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index cc27f485a..aaa89ff5d 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -1211,6 +1211,7 @@ int botan_x509_cert_load_file(botan_x509_cert_t* cert_obj, const char* cert_path
if(!cert_obj || !cert_path)
return -1;
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(cert_path));
if(c)
@@ -1218,6 +1219,9 @@ int botan_x509_cert_load_file(botan_x509_cert_t* cert_obj, const char* cert_path
*cert_obj = new botan_x509_cert_struct(c.release());
return 0;
}
+#else
+ return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
+#endif
}
catch(std::exception& e)
{
diff --git a/src/lib/filters/basefilt.h b/src/lib/filters/basefilt.h
index c065fae0e..d803542a1 100644
--- a/src/lib/filters/basefilt.h
+++ b/src/lib/filters/basefilt.h
@@ -10,7 +10,10 @@
#define BOTAN_BASEFILT_H__
#include <botan/filter.h>
+
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
#include <thread>
+#endif
namespace Botan {
@@ -78,6 +81,8 @@ class BOTAN_DLL Fork : public Fanout_Filter
Fork(Filter* filter_arr[], size_t length);
};
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
+
/**
* This class is a threaded version of the Fork filter. While this uses
* threads, the class itself is NOT thread-safe. This is meant as a drop-
@@ -113,6 +118,7 @@ class BOTAN_DLL Threaded_Fork : public Fork
std::vector<std::shared_ptr<std::thread>> m_threads;
std::unique_ptr<struct Threaded_Fork_Data> m_thread_data;
};
+#endif
}
diff --git a/src/lib/filters/data_snk.cpp b/src/lib/filters/data_snk.cpp
index df35b12bf..efedef268 100644
--- a/src/lib/filters/data_snk.cpp
+++ b/src/lib/filters/data_snk.cpp
@@ -8,10 +8,14 @@
#include <botan/data_snk.h>
#include <botan/exceptn.h>
-#include <fstream>
+
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+ #include <fstream>
+#endif
namespace Botan {
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/*
* Write to a stream
*/
@@ -58,5 +62,6 @@ DataSink_Stream::~DataSink_Stream()
{
delete m_sink_p;
}
+#endif
}
diff --git a/src/lib/filters/data_snk.h b/src/lib/filters/data_snk.h
index 56b292e46..2405fdf98 100644
--- a/src/lib/filters/data_snk.h
+++ b/src/lib/filters/data_snk.h
@@ -27,6 +27,8 @@ class BOTAN_DLL DataSink : public Filter
DataSink(const DataSink&) = delete;
};
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+
/**
* This class represents a data sink which writes its output to a stream.
*/
@@ -62,6 +64,8 @@ class BOTAN_DLL DataSink_Stream : public DataSink
std::ostream& m_sink;
};
+#endif
+
}
#endif
diff --git a/src/lib/filters/threaded_fork.cpp b/src/lib/filters/threaded_fork.cpp
index 5ee802593..f558ac9c2 100644
--- a/src/lib/filters/threaded_fork.cpp
+++ b/src/lib/filters/threaded_fork.cpp
@@ -7,6 +7,9 @@
*/
#include <botan/basefilt.h>
+
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
+
#include <botan/internal/semaphore.h>
namespace Botan {
@@ -144,3 +147,5 @@ void Threaded_Fork::thread_entry(Filter* filter)
}
}
+
+#endif
diff --git a/src/lib/hash/sha1_sse2/sha1_sse2.cpp b/src/lib/hash/sha1_sse2/sha1_sse2.cpp
index 2ece541b0..0f88bb4c2 100644
--- a/src/lib/hash/sha1_sse2/sha1_sse2.cpp
+++ b/src/lib/hash/sha1_sse2/sha1_sse2.cpp
@@ -152,6 +152,7 @@ inline void F4(u32bit A, u32bit& B, u32bit C, u32bit D, u32bit& E, u32bit msg)
* SHA-160 Compression Function using SSE for message expansion
*/
//static
+BOTAN_FUNC_ISA("sse2")
void SHA_160::sse2_compress_n(secure_vector<uint32_t>& digest, const byte input[], size_t blocks)
{
using namespace SHA1_SSE2_F;
diff --git a/src/lib/misc/srp6/srp6_files.cpp b/src/lib/misc/srp6/srp6_files.cpp
index 14ab1ac61..606c12ad7 100644
--- a/src/lib/misc/srp6/srp6_files.cpp
+++ b/src/lib/misc/srp6/srp6_files.cpp
@@ -8,14 +8,11 @@
#include <botan/srp6_files.h>
#include <botan/parsing.h>
#include <botan/base64.h>
-#include <fstream>
namespace Botan {
-SRP6_Authenticator_File::SRP6_Authenticator_File(const std::string& filename)
+SRP6_Authenticator_File::SRP6_Authenticator_File(std::istream& in)
{
- std::ifstream in(filename);
-
if(!in)
return; // no entries
diff --git a/src/lib/misc/srp6/srp6_files.h b/src/lib/misc/srp6/srp6_files.h
index 2b20de7a3..db128727e 100644
--- a/src/lib/misc/srp6/srp6_files.h
+++ b/src/lib/misc/srp6/srp6_files.h
@@ -9,6 +9,7 @@
#define BOTAN_SRP6A_FILES_H__
#include <botan/bigint.h>
+#include <iosfwd>
#include <string>
#include <map>
@@ -20,11 +21,11 @@ namespace Botan {
class BOTAN_DLL SRP6_Authenticator_File
{
public:
+
/**
- * @param filename will be opened and processed as a SRP
- * authenticator file
+ * @param input will be read and processed as SRP authenticator file
*/
- explicit SRP6_Authenticator_File(const std::string& filename);
+ explicit SRP6_Authenticator_File(std::istream& input);
bool lookup_user(const std::string& username,
BigInt& v,
diff --git a/src/lib/modes/aead/gcm/clmul/clmul.cpp b/src/lib/modes/aead/gcm/clmul/clmul.cpp
index 6e1db7012..725ef3da3 100644
--- a/src/lib/modes/aead/gcm/clmul/clmul.cpp
+++ b/src/lib/modes/aead/gcm/clmul/clmul.cpp
@@ -11,6 +11,7 @@
namespace Botan {
+BOTAN_FUNC_ISA("pclmul,ssse3")
void gcm_multiply_clmul(byte x[16], const byte H[16])
{
/*
diff --git a/src/lib/pubkey/dsa/dsa.cpp b/src/lib/pubkey/dsa/dsa.cpp
index 15dc45373..9c8ae0821 100644
--- a/src/lib/pubkey/dsa/dsa.cpp
+++ b/src/lib/pubkey/dsa/dsa.cpp
@@ -17,7 +17,9 @@
#include <botan/rfc6979.h>
#endif
-#include <future>
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
+ #include <future>
+#endif
namespace Botan {
@@ -124,11 +126,17 @@ DSA_Signature_Operation::raw_sign(const byte msg[], size_t msg_len,
const BigInt k = BigInt::random_integer(rng, 1, m_q);
#endif
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
auto future_r = std::async(std::launch::async,
[&]() { return m_mod_q.reduce(m_powermod_g_p(k)); });
BigInt s = inverse_mod(k, m_q);
const BigInt r = future_r.get();
+#else
+ BigInt s = inverse_mod(k, m_q);
+ const BigInt r = m_mod_q.reduce(m_powermod_g_p(k));
+#endif
+
s = m_mod_q.multiply(s, mul_add(m_x, r, i));
// With overwhelming probability, a bug rather than actual zero r/s
@@ -184,11 +192,16 @@ bool DSA_Verification_Operation::verify(const byte msg[], size_t msg_len,
s = inverse_mod(s, m_q);
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
auto future_s_i = std::async(std::launch::async,
[&]() { return m_powermod_g_p(m_mod_q.multiply(s, i)); });
BigInt s_r = m_powermod_y_p(m_mod_q.multiply(s, r));
BigInt s_i = future_s_i.get();
+#else
+ BigInt s_r = m_powermod_y_p(m_mod_q.multiply(s, r));
+ BigInt s_i = m_powermod_g_p(m_mod_q.multiply(s, i));
+#endif
s = m_mod_p.multiply(s_i, s_r);
diff --git a/src/lib/pubkey/pkcs8.cpp b/src/lib/pubkey/pkcs8.cpp
index ddf9be2f0..96dfd5e44 100644
--- a/src/lib/pubkey/pkcs8.cpp
+++ b/src/lib/pubkey/pkcs8.cpp
@@ -262,6 +262,8 @@ Private_Key* load_key(DataSource& source,
throw PKCS8_Exception( "Internal error: Attempt to read password for unencrypted key" );}, false);
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+
/*
* Extract an encrypted private key and return it
*/
@@ -293,6 +295,7 @@ Private_Key* load_key(const std::string& fsname,
return load_key(source, rng, []() -> std::string {
throw PKCS8_Exception( "Internal error: Attempt to read password for unencrypted key" );}, false);
}
+#endif
/*
* Make a copy of this private key
diff --git a/src/lib/pubkey/pkcs8.h b/src/lib/pubkey/pkcs8.h
index 791a612df..9cc350285 100644
--- a/src/lib/pubkey/pkcs8.h
+++ b/src/lib/pubkey/pkcs8.h
@@ -108,6 +108,7 @@ BOTAN_DLL Private_Key* load_key(DataSource& source,
BOTAN_DLL Private_Key* load_key(DataSource& source,
RandomNumberGenerator& rng);
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/**
* Load an encrypted key from a file.
* @param filename the path to the file containing the encoded key
@@ -136,6 +137,7 @@ BOTAN_DLL Private_Key* load_key(const std::string& filename,
*/
BOTAN_DLL Private_Key* load_key(const std::string& filename,
RandomNumberGenerator& rng);
+#endif
/**
* Copy an existing encoded key object.
diff --git a/src/lib/pubkey/rsa/rsa.cpp b/src/lib/pubkey/rsa/rsa.cpp
index b40f485e3..d201ca277 100644
--- a/src/lib/pubkey/rsa/rsa.cpp
+++ b/src/lib/pubkey/rsa/rsa.cpp
@@ -14,12 +14,16 @@
#include <botan/workfactor.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
-#include <future>
#if defined(BOTAN_HAS_OPENSSL)
#include <botan/internal/openssl.h>
#endif
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
+#include <future>
+#endif
+
+
namespace Botan {
size_t RSA_PublicKey::estimated_strength() const
@@ -218,9 +222,14 @@ class RSA_Private_Operation
BigInt private_op(const BigInt& m) const
{
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
auto future_j1 = std::async(std::launch::async, m_powermod_d1_p, m);
BigInt j2 = m_powermod_d2_q(m);
BigInt j1 = future_j1.get();
+#else
+ BigInt j1 = m_powermod_d1_p(m);
+ BigInt j2 = m_powermod_d2_q(m);
+#endif
j1 = m_mod_p.reduce(sub_mul(j1, j2, m_c));
diff --git a/src/lib/pubkey/x509_key.cpp b/src/lib/pubkey/x509_key.cpp
index ccb94cea7..08e17bfed 100644
--- a/src/lib/pubkey/x509_key.cpp
+++ b/src/lib/pubkey/x509_key.cpp
@@ -78,6 +78,7 @@ Public_Key* load_key(DataSource& source)
}
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/*
* Extract a public key and return it
*/
@@ -86,6 +87,7 @@ Public_Key* load_key(const std::string& fsname)
DataSource_Stream source(fsname, true);
return X509::load_key(source);
}
+#endif
/*
* Extract a public key and return it
diff --git a/src/lib/pubkey/x509_key.h b/src/lib/pubkey/x509_key.h
index cbb0412d2..7162b338e 100644
--- a/src/lib/pubkey/x509_key.h
+++ b/src/lib/pubkey/x509_key.h
@@ -46,12 +46,14 @@ BOTAN_DLL std::string PEM_encode(const Public_Key& key);
*/
BOTAN_DLL Public_Key* load_key(DataSource& source);
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
/**
* Create a public key from a file
* @param filename pathname to the file to load
* @return new public key object
*/
BOTAN_DLL Public_Key* load_key(const std::string& filename);
+#endif
/**
* Create a public key from a memory region.
diff --git a/src/lib/rng/rdrand_rng/rdrand_rng.cpp b/src/lib/rng/rdrand_rng/rdrand_rng.cpp
index 4d2e51cf8..1ee857c6c 100644
--- a/src/lib/rng/rdrand_rng/rdrand_rng.cpp
+++ b/src/lib/rng/rdrand_rng/rdrand_rng.cpp
@@ -36,6 +36,7 @@ uint32_t RDRAND_RNG::rdrand()
}
//static
+BOTAN_FUNC_ISA("rdrnd")
uint32_t RDRAND_RNG::rdrand_status(bool& ok)
{
ok = false;
diff --git a/src/lib/rng/rng.cpp b/src/lib/rng/rng.cpp
index 8c2982312..a2dd3d3a4 100644
--- a/src/lib/rng/rng.cpp
+++ b/src/lib/rng/rng.cpp
@@ -57,6 +57,8 @@ RandomNumberGenerator* RandomNumberGenerator::make_rng()
#endif
}
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
Serialized_RNG::Serialized_RNG() : m_rng(RandomNumberGenerator::make_rng()) {}
+#endif
}
diff --git a/src/lib/rng/rng.h b/src/lib/rng/rng.h
index d1cdcfff2..e3640a32f 100644
--- a/src/lib/rng/rng.h
+++ b/src/lib/rng/rng.h
@@ -11,9 +11,9 @@
#include <botan/entropy_src.h>
#include <botan/secmem.h>
#include <botan/exceptn.h>
+#include <botan/mutex.h>
#include <chrono>
#include <string>
-#include <mutex>
namespace Botan {
@@ -193,6 +193,7 @@ class BOTAN_DLL Null_RNG final : public RandomNumberGenerator
std::string name() const override { return "Null_RNG"; }
};
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
/**
* Wraps access to a RNG in a mutex
*/
@@ -201,25 +202,25 @@ class BOTAN_DLL Serialized_RNG final : public RandomNumberGenerator
public:
void randomize(byte out[], size_t len) override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
m_rng->randomize(out, len);
}
bool is_seeded() const override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
return m_rng->is_seeded();
}
void clear() override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
m_rng->clear();
}
std::string name() const override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
return m_rng->name();
}
@@ -227,23 +228,24 @@ class BOTAN_DLL Serialized_RNG final : public RandomNumberGenerator
size_t poll_bits = BOTAN_RNG_RESEED_POLL_BITS,
std::chrono::milliseconds poll_timeout = BOTAN_RNG_RESEED_DEFAULT_TIMEOUT) override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
return m_rng->reseed(src, poll_bits, poll_timeout);
}
void add_entropy(const byte in[], size_t len) override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
m_rng->add_entropy(in, len);
}
- BOTAN_DEPRECATED("Create an AutoSeeded_RNG for other constructor") Serialized_RNG();
+ BOTAN_DEPRECATED("Use Serialized_RNG(new AutoSeeded_RNG)") Serialized_RNG();
explicit Serialized_RNG(RandomNumberGenerator* rng) : m_rng(rng) {}
private:
- mutable std::mutex m_mutex;
+ mutable mutex_type m_mutex;
std::unique_ptr<RandomNumberGenerator> m_rng;
};
+#endif
}
diff --git a/src/lib/stream/chacha/chacha_sse2/chacha_sse2.cpp b/src/lib/stream/chacha/chacha_sse2/chacha_sse2.cpp
index e39b285b3..a7261a522 100644
--- a/src/lib/stream/chacha/chacha_sse2/chacha_sse2.cpp
+++ b/src/lib/stream/chacha/chacha_sse2/chacha_sse2.cpp
@@ -11,6 +11,7 @@
namespace Botan {
//static
+BOTAN_FUNC_ISA("sse2")
void ChaCha::chacha_sse2_x4(byte output[64], u32bit input[16], size_t rounds)
{
BOTAN_ASSERT(rounds % 2 == 0, "Valid rounds");
diff --git a/src/lib/tls/tls_session_manager.h b/src/lib/tls/tls_session_manager.h
index e01462f66..49f4925d8 100644
--- a/src/lib/tls/tls_session_manager.h
+++ b/src/lib/tls/tls_session_manager.h
@@ -9,7 +9,7 @@
#define BOTAN_TLS_SESSION_MANAGER_H__
#include <botan/tls_session.h>
-#include <mutex>
+#include <botan/mutex.h>
#include <chrono>
#include <map>
@@ -138,7 +138,7 @@ class BOTAN_DLL Session_Manager_In_Memory : public Session_Manager
bool load_from_session_str(const std::string& session_str,
Session& session);
- std::mutex m_mutex;
+ mutex_type m_mutex;
size_t m_max_sessions;
diff --git a/src/lib/tls/tls_session_manager_memory.cpp b/src/lib/tls/tls_session_manager_memory.cpp
index 37019c943..d0866b37a 100644
--- a/src/lib/tls/tls_session_manager_memory.cpp
+++ b/src/lib/tls/tls_session_manager_memory.cpp
@@ -57,7 +57,7 @@ bool Session_Manager_In_Memory::load_from_session_str(
bool Session_Manager_In_Memory::load_from_session_id(
const std::vector<byte>& session_id, Session& session)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
return load_from_session_str(hex_encode(session_id), session);
}
@@ -65,7 +65,7 @@ bool Session_Manager_In_Memory::load_from_session_id(
bool Session_Manager_In_Memory::load_from_server_info(
const Server_Information& info, Session& session)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_info_sessions.find(info);
@@ -87,7 +87,7 @@ bool Session_Manager_In_Memory::load_from_server_info(
void Session_Manager_In_Memory::remove_entry(
const std::vector<byte>& session_id)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_sessions.find(hex_encode(session_id));
@@ -106,7 +106,7 @@ size_t Session_Manager_In_Memory::remove_all()
void Session_Manager_In_Memory::save(const Session& session)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
if(m_max_sessions != 0)
{
diff --git a/src/lib/utils/calendar.cpp b/src/lib/utils/calendar.cpp
index 2ed90486a..4f6c835d1 100644
--- a/src/lib/utils/calendar.cpp
+++ b/src/lib/utils/calendar.cpp
@@ -11,7 +11,7 @@
#include <ctime>
#include <sstream>
#include <iomanip>
-#include <mutex>
+#include <botan/mutex.h>
#include <stdlib.h>
#if defined(BOTAN_HAS_BOOST_DATETIME)
@@ -72,7 +72,7 @@ std::time_t boost_timegm(std::tm *tm)
#pragma message "Caution! A fallback version of timegm() is used which is not thread-safe"
-std::mutex ENV_TZ;
+mutex_type ENV_TZ;
std::time_t fallback_timegm(std::tm *tm)
{
diff --git a/src/lib/utils/data_src.cpp b/src/lib/utils/data_src.cpp
index 0c06f2fe4..7da94d7c0 100644
--- a/src/lib/utils/data_src.cpp
+++ b/src/lib/utils/data_src.cpp
@@ -8,9 +8,12 @@
#include <botan/data_src.h>
#include <botan/exceptn.h>
-#include <fstream>
#include <algorithm>
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+ #include <fstream>
+#endif
+
namespace Botan {
/*
@@ -98,6 +101,8 @@ DataSource_Memory::DataSource_Memory(const std::string& in) :
{
}
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+
/*
* Read from a stream
*/
@@ -209,4 +214,6 @@ DataSource_Stream::~DataSource_Stream()
delete m_source_p;
}
+#endif
+
}
diff --git a/src/lib/utils/data_src.h b/src/lib/utils/data_src.h
index 6a100ce63..b24fd75a4 100644
--- a/src/lib/utils/data_src.h
+++ b/src/lib/utils/data_src.h
@@ -138,6 +138,8 @@ class BOTAN_DLL DataSource_Memory : public DataSource
size_t m_offset;
};
+#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+
/**
* This class represents a Stream-Based DataSource.
*/
@@ -175,6 +177,8 @@ class BOTAN_DLL DataSource_Stream : public DataSource
size_t m_total_read;
};
+#endif
+
}
#endif
diff --git a/src/lib/utils/http_util/http_util.cpp b/src/lib/utils/http_util/http_util.cpp
index 1286e4026..5624f2e4f 100644
--- a/src/lib/utils/http_util/http_util.cpp
+++ b/src/lib/utils/http_util/http_util.cpp
@@ -226,11 +226,6 @@ Response POST_sync(const std::string& url,
return http_sync("POST", url, content_type, body, allowable_redirects);
}
-std::future<Response> GET_async(const std::string& url, size_t allowable_redirects)
- {
- return std::async(std::launch::async, GET_sync, url, allowable_redirects);
- }
-
}
}
diff --git a/src/lib/utils/http_util/http_util.h b/src/lib/utils/http_util/http_util.h
index 6688285c6..918dfc269 100644
--- a/src/lib/utils/http_util/http_util.h
+++ b/src/lib/utils/http_util/http_util.h
@@ -10,7 +10,6 @@
#include <botan/types.h>
#include <botan/exceptn.h>
-#include <future>
#include <vector>
#include <map>
#include <chrono>
@@ -88,9 +87,6 @@ BOTAN_DLL Response POST_sync(const std::string& url,
const std::vector<byte>& body,
size_t allowable_redirects = 1);
-std::future<Response> BOTAN_DLL GET_async(const std::string& url,
- size_t allowable_redirects = 1);
-
BOTAN_DLL std::string url_encode(const std::string& url);
}
diff --git a/src/lib/utils/info.txt b/src/lib/utils/info.txt
index 511e6b0e8..189b2da1f 100644
--- a/src/lib/utils/info.txt
+++ b/src/lib/utils/info.txt
@@ -14,6 +14,7 @@ exceptn.h
loadstor.h
mem_ops.h
mul128.h
+mutex.h
parsing.h
rotate.h
types.h
diff --git a/src/lib/utils/locking_allocator/locking_allocator.cpp b/src/lib/utils/locking_allocator/locking_allocator.cpp
index c6181d4c0..770464d92 100644
--- a/src/lib/utils/locking_allocator/locking_allocator.cpp
+++ b/src/lib/utils/locking_allocator/locking_allocator.cpp
@@ -11,7 +11,7 @@
#include <algorithm>
#include <cstdlib>
#include <string>
-#include <mutex>
+#include <botan/mutex.h>
namespace Botan {
@@ -58,7 +58,7 @@ void* mlock_allocator::allocate(size_t num_elems, size_t elem_size)
if(n < BOTAN_MLOCK_ALLOCATOR_MIN_ALLOCATION || n > BOTAN_MLOCK_ALLOCATOR_MAX_ALLOCATION)
return nullptr;
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
auto best_fit = m_freelist.end();
@@ -146,7 +146,7 @@ bool mlock_allocator::deallocate(void* p, size_t num_elems, size_t elem_size)
if(!ptr_in_pool(m_pool, m_poolsize, p, n))
return false;
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
const size_t start = static_cast<byte*>(p) - m_pool;
diff --git a/src/lib/utils/locking_allocator/locking_allocator.h b/src/lib/utils/locking_allocator/locking_allocator.h
index db75bc02a..5c19852c0 100644
--- a/src/lib/utils/locking_allocator/locking_allocator.h
+++ b/src/lib/utils/locking_allocator/locking_allocator.h
@@ -10,7 +10,7 @@
#include <botan/types.h>
#include <vector>
-#include <mutex>
+#include <botan/mutex.h>
namespace Botan {
@@ -32,7 +32,7 @@ class BOTAN_DLL mlock_allocator
~mlock_allocator();
- std::mutex m_mutex;
+ mutex_type m_mutex;
std::vector<std::pair<size_t, size_t>> m_freelist;
byte* m_pool = nullptr;
size_t m_poolsize = 0;
diff --git a/src/lib/utils/mutex.h b/src/lib/utils/mutex.h
new file mode 100644
index 000000000..0daea3148
--- /dev/null
+++ b/src/lib/utils/mutex.h
@@ -0,0 +1,61 @@
+/*
+* (C) 2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#ifndef BOTAN_UTIL_MUTEX_H__
+#define BOTAN_UTIL_MUTEX_H__
+
+#include <botan/build.h>
+#include <botan/types.h>
+
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
+
+#include <mutex>
+
+namespace Botan {
+
+template<typename T> using lock_guard_type = std::lock_guard<T>;
+typedef std::mutex mutex_type;
+
+}
+
+#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL)
+
+// No threads
+
+namespace Botan {
+
+template<typename Mutex>
+class lock_guard
+ {
+ public:
+ explicit lock_guard(Mutex& m) : m_mutex(m)
+ { m_mutex.lock(); }
+
+ ~lock_guard() { m_mutex.unlock(); }
+
+ lock_guard(const lock_guard& other) = delete;
+ lock_guard& operator=(const lock_guard& other) = delete;
+ private:
+ Mutex& m_mutex;
+ };
+
+class noop_mutex
+ {
+ public:
+ void lock() {}
+ void unlock() {}
+ };
+
+typedef noop_mutex mutex_type;
+template<typename T> using lock_guard_type = lock_guard<T>;
+
+}
+
+#else
+ #error "Threads unexpectedly disabled in non unikernel build"
+#endif
+
+#endif
diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp
index 2f17da952..4020a4be3 100644
--- a/src/lib/utils/os_utils.cpp
+++ b/src/lib/utils/os_utils.cpp
@@ -33,8 +33,10 @@ uint32_t get_process_id()
return ::getpid();
#elif defined(BOTAN_TARGET_OS_IS_WINDOWS) || defined(BOTAN_TARGET_OS_IS_MINGW)
return ::GetCurrentProcessId();
+#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL)
+ return 0; // truly no meaningful value
#else
- throw Exception("get_process_id not supported");
+ #error "Missing get_process_id"
#endif
}
diff --git a/src/lib/utils/semaphore.cpp b/src/lib/utils/semaphore.cpp
index f30c43661..62c31d3e3 100644
--- a/src/lib/utils/semaphore.cpp
+++ b/src/lib/utils/semaphore.cpp
@@ -7,6 +7,8 @@
#include <botan/internal/semaphore.h>
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
+
// Based on code by Pierre Gaston (http://p9as.blogspot.com/2012/06/c11-semaphores.html)
namespace Botan {
@@ -15,7 +17,7 @@ void Semaphore::release(size_t n)
{
for(size_t i = 0; i != n; ++i)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
++m_value;
@@ -29,7 +31,7 @@ void Semaphore::release(size_t n)
void Semaphore::acquire()
{
- std::unique_lock<std::mutex> lock(m_mutex);
+ std::unique_lock<mutex_type> lock(m_mutex);
--m_value;
if(m_value < 0)
{
@@ -39,3 +41,5 @@ void Semaphore::acquire()
}
}
+
+#endif
diff --git a/src/lib/utils/semaphore.h b/src/lib/utils/semaphore.h
index 994a15f21..87e6b84fe 100644
--- a/src/lib/utils/semaphore.h
+++ b/src/lib/utils/semaphore.h
@@ -8,11 +8,15 @@
#ifndef BOTAN_SEMAPHORE_H__
#define BOTAN_SEMAPHORE_H__
-#include <mutex>
+#include <botan/mutex.h>
+
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
#include <condition_variable>
+#endif
namespace Botan {
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
class Semaphore
{
public:
@@ -25,9 +29,10 @@ class Semaphore
private:
int m_value;
int m_wakeups;
- std::mutex m_mutex;
+ mutex_type m_mutex;
std::condition_variable m_cond;
};
+#endif
}