diff options
author | Jack Lloyd <[email protected]> | 2017-01-24 19:38:02 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-01-24 19:38:02 -0500 |
commit | 53d69ce19b02051cbf732af00ab98bcf384561cd (patch) | |
tree | 9257233777f7ab0eb2f1f2411bd363700ad30429 /src | |
parent | b49eaee216142ad6eab5ad437aea44b7897baf84 (diff) |
Fix various SunCC and Solaris warnings and build problems.
Based on build output sent by @noloader.
If RLIMIT_MEMLOCK is not defined, assume regular user is not able to
call mlock. This probably also affected Clang/GCC on Solaris.
Work around resolution issue in SIMD_4x32 where it finds ambiguity
between arg taking uint32_t and __m128i. This is probably some
artifact of how SunCC represents vector types, and seems highly bogus
in general but is easy to work around here. Change constructor taking
a single value to instead be `SIMD_4x32::splat` function. The SIMD
class is internal, so no API implications.
Fix various warnings about lambda functions that were missing return
types and which were not a single return statement. AIUI C++11 doesn't
guarantee that lambda return type will be deduced in that situation,
though in practice every compiler including SunCC seems to handle it.
Disable AVX2 usage, since SunCC's intrinsics seem to be broken - its
_mm_loadu_si256 takes non-const pointer.
Rename a few variables in the tests to avoid shadowed var warnings.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/block/aes/aes.cpp | 4 | ||||
-rw-r--r-- | src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp | 24 | ||||
-rw-r--r-- | src/lib/block/serpent/serpent_simd/serpent_simd.cpp | 8 | ||||
-rw-r--r-- | src/lib/block/threefish/threefish_avx2/info.txt | 7 | ||||
-rw-r--r-- | src/lib/ffi/ffi.cpp | 2 | ||||
-rw-r--r-- | src/lib/utils/os_utils.cpp | 9 | ||||
-rw-r--r-- | src/lib/utils/simd/simd_32.h | 11 | ||||
-rw-r--r-- | src/lib/x509/x509path.cpp | 8 | ||||
-rw-r--r-- | src/tests/main.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_os_utils.cpp | 10 | ||||
-rw-r--r-- | src/tests/test_pkcs11_high_level.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_rng.cpp | 4 | ||||
-rw-r--r-- | src/tests/unit_ecc.cpp | 2 | ||||
-rw-r--r-- | src/tests/unit_tls.cpp | 4 |
14 files changed, 54 insertions, 43 deletions
diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp index 6b9d56665..21228e0c1 100644 --- a/src/lib/block/aes/aes.cpp +++ b/src/lib/block/aes/aes.cpp @@ -107,7 +107,7 @@ inline uint8_t xtime14(uint8_t s) { return xtime8(s) ^ xtime4(s) ^ xtime(s); } const std::vector<uint32_t>& AES_TE() { - auto compute_TE = []() { + auto compute_TE = []() -> std::vector<uint32_t> { std::vector<uint32_t> TE(1024); for(size_t i = 0; i != 256; ++i) { @@ -128,7 +128,7 @@ const std::vector<uint32_t>& AES_TE() const std::vector<uint32_t>& AES_TD() { - auto compute_TD = []() { + auto compute_TD = []() -> std::vector<uint32_t> { std::vector<uint32_t> TD(1024); for(size_t i = 0; i != 256; ++i) { diff --git a/src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp b/src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp index 03048ec9c..a77ba7b8c 100644 --- a/src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp +++ b/src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp @@ -65,10 +65,10 @@ namespace Botan { */ void Noekeon::simd_encrypt_4(const uint8_t in[], uint8_t out[]) const { - const SIMD_32 K0 = SIMD_32(m_EK[0]); - const SIMD_32 K1 = SIMD_32(m_EK[1]); - const SIMD_32 K2 = SIMD_32(m_EK[2]); - const SIMD_32 K3 = SIMD_32(m_EK[3]); + const SIMD_32 K0 = SIMD_32::splat(m_EK[0]); + const SIMD_32 K1 = SIMD_32::splat(m_EK[1]); + const SIMD_32 K2 = SIMD_32::splat(m_EK[2]); + const SIMD_32 K3 = SIMD_32::splat(m_EK[3]); SIMD_32 A0 = SIMD_32::load_be(in ); SIMD_32 A1 = SIMD_32::load_be(in + 16); @@ -79,7 +79,7 @@ void Noekeon::simd_encrypt_4(const uint8_t in[], uint8_t out[]) const for(size_t i = 0; i != 16; ++i) { - A0 ^= SIMD_32(RC[i]); + A0 ^= SIMD_32::splat(RC[i]); NOK_SIMD_THETA(A0, A1, A2, A3, K0, K1, K2, K3); @@ -94,7 +94,7 @@ void Noekeon::simd_encrypt_4(const uint8_t in[], uint8_t out[]) const A3.rotate_right(2); } - A0 ^= SIMD_32(RC[16]); + A0 ^= SIMD_32::splat(RC[16]); NOK_SIMD_THETA(A0, A1, A2, A3, K0, K1, K2, K3); SIMD_32::transpose(A0, A1, A2, A3); @@ -110,10 +110,10 @@ void Noekeon::simd_encrypt_4(const uint8_t in[], uint8_t out[]) const */ void Noekeon::simd_decrypt_4(const uint8_t in[], uint8_t out[]) const { - const SIMD_32 K0 = SIMD_32(m_DK[0]); - const SIMD_32 K1 = SIMD_32(m_DK[1]); - const SIMD_32 K2 = SIMD_32(m_DK[2]); - const SIMD_32 K3 = SIMD_32(m_DK[3]); + const SIMD_32 K0 = SIMD_32::splat(m_DK[0]); + const SIMD_32 K1 = SIMD_32::splat(m_DK[1]); + const SIMD_32 K2 = SIMD_32::splat(m_DK[2]); + const SIMD_32 K3 = SIMD_32::splat(m_DK[3]); SIMD_32 A0 = SIMD_32::load_be(in ); SIMD_32 A1 = SIMD_32::load_be(in + 16); @@ -126,7 +126,7 @@ void Noekeon::simd_decrypt_4(const uint8_t in[], uint8_t out[]) const { NOK_SIMD_THETA(A0, A1, A2, A3, K0, K1, K2, K3); - A0 ^= SIMD_32(RC[16-i]); + A0 ^= SIMD_32::splat(RC[16-i]); A1.rotate_left(1); A2.rotate_left(5); @@ -140,7 +140,7 @@ void Noekeon::simd_decrypt_4(const uint8_t in[], uint8_t out[]) const } NOK_SIMD_THETA(A0, A1, A2, A3, K0, K1, K2, K3); - A0 ^= SIMD_32(RC[0]); + A0 ^= SIMD_32::splat(RC[0]); SIMD_32::transpose(A0, A1, A2, A3); diff --git a/src/lib/block/serpent/serpent_simd/serpent_simd.cpp b/src/lib/block/serpent/serpent_simd/serpent_simd.cpp index f69d1f6f5..59ef46a6c 100644 --- a/src/lib/block/serpent/serpent_simd/serpent_simd.cpp +++ b/src/lib/block/serpent/serpent_simd/serpent_simd.cpp @@ -15,10 +15,10 @@ namespace { #define key_xor(round, B0, B1, B2, B3) \ do { \ - B0 ^= SIMD_32(m_round_key[4*round ]); \ - B1 ^= SIMD_32(m_round_key[4*round+1]); \ - B2 ^= SIMD_32(m_round_key[4*round+2]); \ - B3 ^= SIMD_32(m_round_key[4*round+3]); \ + B0 ^= SIMD_32::splat(m_round_key[4*round ]); \ + B1 ^= SIMD_32::splat(m_round_key[4*round+1]); \ + B2 ^= SIMD_32::splat(m_round_key[4*round+2]); \ + B3 ^= SIMD_32::splat(m_round_key[4*round+3]); \ } while(0); /* diff --git a/src/lib/block/threefish/threefish_avx2/info.txt b/src/lib/block/threefish/threefish_avx2/info.txt index 1612ce390..8e7db6455 100644 --- a/src/lib/block/threefish/threefish_avx2/info.txt +++ b/src/lib/block/threefish/threefish_avx2/info.txt @@ -1,3 +1,10 @@ define THREEFISH_512_AVX2 20160903 need_isa avx2 + +<cc> +gcc +clang +msvc +icc +</cc> diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index 5c4cba4e7..80d7ec611 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -168,7 +168,7 @@ inline int write_str_output(char out[], size_t* out_len, const std::string& str) return write_str_output(reinterpret_cast<uint8_t*>(out), out_len, str); } -#define BOTAN_FFI_DO(T, obj, param, block) apply_fn(obj, BOTAN_CURRENT_FUNCTION, [=](T& param) { do { block } while(0); return 0; }) +#define BOTAN_FFI_DO(T, obj, param, block) apply_fn(obj, BOTAN_CURRENT_FUNCTION, [=](T& param) -> int { do { block } while(0); return 0; }) } diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 87cbcfd0f..c6d99237c 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -182,6 +182,7 @@ size_t get_memory_locking_limit() catch(std::exception&) { /* ignore it */ } } +#if defined(RLIMIT_MEMLOCK) if(mlock_requested > 0) { struct ::rlimit limits; @@ -197,6 +198,14 @@ size_t get_memory_locking_limit() return std::min<size_t>(limits.rlim_cur, mlock_requested * 1024); } +#else + /* + * If RLIMIT_MEMLOCK is not defined, likely the OS does not support + * unprivileged mlock calls. + */ + return 0; +#endif + #elif defined(BOTAN_TARGET_OS_HAS_VIRTUAL_LOCK) && defined(BOTAN_BUILD_COMPILER_IS_MSVC) SIZE_T working_min = 0, working_max = 0; DWORD working_flags = 0; diff --git a/src/lib/utils/simd/simd_32.h b/src/lib/utils/simd/simd_32.h index 591e0e9c9..2308da652 100644 --- a/src/lib/utils/simd/simd_32.h +++ b/src/lib/utils/simd/simd_32.h @@ -74,17 +74,12 @@ class SIMD_4x32 #endif } - explicit SIMD_4x32(uint32_t B) + static SIMD_4x32 splat(uint32_t B) { #if defined(BOTAN_SIMD_USE_SSE2) - m_reg = _mm_set1_epi32(B); -#elif defined(BOTAN_SIMD_USE_ALTIVEC) - m_reg = (__vector unsigned int){B, B, B, B}; + return SIMD_4x32(_mm_set1_epi32(B)); #else - m_reg[0] = B; - m_reg[1] = B; - m_reg[2] = B; - m_reg[3] = B; + return SIMD_4x32(B, B, B, B); #endif } diff --git a/src/lib/x509/x509path.cpp b/src/lib/x509/x509path.cpp index 2fa1adbd6..c70ecae7a 100644 --- a/src/lib/x509/x509path.cpp +++ b/src/lib/x509/x509path.cpp @@ -267,14 +267,14 @@ PKIX::check_ocsp_online(const std::vector<std::shared_ptr<const X509_Certificate if(subject->ocsp_responder() == "") { - ocsp_response_futures.emplace_back(std::async(std::launch::deferred, [&]{ + ocsp_response_futures.emplace_back(std::async(std::launch::deferred, [&]() -> std::shared_ptr<const OCSP::Response> { throw Exception("No OCSP responder URL set for this certificate"); return std::shared_ptr<const OCSP::Response>(); })); } else { - ocsp_response_futures.emplace_back(std::async(std::launch::async, [&]{ + ocsp_response_futures.emplace_back(std::async(std::launch::async, [&]() -> std::shared_ptr<const OCSP::Response> { OCSP::Request req(*issuer, *subject); auto http = HTTP::POST_sync(subject->ocsp_responder(), @@ -356,14 +356,14 @@ PKIX::check_crl_online(const std::vector<std::shared_ptr<const X509_Certificate> else if(cert_path[i]->crl_distribution_point() == "") { // Avoid creating a thread for this case - future_crls.emplace_back(std::async(std::launch::deferred, [&]{ + future_crls.emplace_back(std::async(std::launch::deferred, [&]() -> std::shared_ptr<const X509_CRL> { throw Exception("No CRL distribution point for this certificate"); return std::shared_ptr<const X509_CRL>(); })); } else { - future_crls.emplace_back(std::async(std::launch::async, [&]() { + future_crls.emplace_back(std::async(std::launch::async, [&]() -> std::shared_ptr<const X509_CRL> { auto http = HTTP::GET_sync(cert_path[i]->crl_distribution_point()); http.throw_unless_ok(); // check the mime type? diff --git a/src/tests/main.cpp b/src/tests/main.cpp index f2c8f7eb0..7f46ab733 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -255,7 +255,7 @@ class Test_Runner : public Botan_CLI::Command for(auto&& test_name : tests_to_run) { - auto run_it = [test_name] { + auto run_it = [test_name]() -> std::vector<Botan_Tests::Test::Result> { try { return Botan_Tests::Test::run_test(test_name, false); } diff --git a/src/tests/test_os_utils.cpp b/src/tests/test_os_utils.cpp index e7313256e..bdcbf2a90 100644 --- a/src/tests/test_os_utils.cpp +++ b/src/tests/test_os_utils.cpp @@ -25,7 +25,7 @@ int run_cpu_instruction_probe(std::function<int ()> probe_fn); class OS_Utils_Tests : public Test { public: - std::vector<Test::Result> run() + std::vector<Test::Result> run() override { std::vector<Test::Result> results; @@ -106,11 +106,11 @@ class OS_Utils_Tests : public Test #if defined(BOTAN_TARGET_OS_TYPE_IS_UNIX) // OS::run_cpu_instruction_probe only implemented for Unix signals right now - std::function<int ()> ok_fn = []() { return 5; }; + std::function<int ()> ok_fn = []() -> int { return 5; }; const int run_rc = Botan::OS::run_cpu_instruction_probe(ok_fn); result.confirm("Correct result returned by working probe fn", run_rc == 5); - std::function<int ()> throw_fn = []() { throw 3.14159; return 5; }; + std::function<int ()> throw_fn = []() -> int { throw 3.14159; return 5; }; const int throw_rc = Botan::OS::run_cpu_instruction_probe(throw_fn); result.confirm("Error return if probe function threw exception", throw_rc < 0); @@ -119,11 +119,11 @@ class OS_Utils_Tests : public Test std::function<int ()> crash_probe; #if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) - crash_probe = []() { asm volatile("ud2"); return 3; }; + crash_probe = []() -> int { asm volatile("ud2"); return 3; }; #elif defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY) //ARM: asm volatile (".word 0xf7f0a000\n"); // illegal instruction in both ARM and Thumb modes - crash_probe = []() { asm volatile(".word 0xe7f0def0\n"); return 3; }; + crash_probe = []() -> int { asm volatile(".word 0xe7f0def0\n"); return 3; }; #else /* PPC: "The instruction with primary opcode 0, when the instruction does not consist diff --git a/src/tests/test_pkcs11_high_level.cpp b/src/tests/test_pkcs11_high_level.cpp index 10723d6b2..e66201d2b 100644 --- a/src/tests/test_pkcs11_high_level.cpp +++ b/src/tests/test_pkcs11_high_level.cpp @@ -102,7 +102,7 @@ Test::Result test_module_ctor() result.test_throws("Module ctor fails for non existent path", []() { - Module module("/a/b/c"); + Module failing_module("/a/b/c"); }); Module module(Test::pkcs11_lib()); diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp index 1b51b2fad..0ebc091e2 100644 --- a/src/tests/test_rng.cpp +++ b/src/tests/test_rng.cpp @@ -223,13 +223,13 @@ class HMAC_DRBG_Unit_Tests : public Test result.test_throws("HMAC_DRBG does not accept 0 for max_number_of_bytes_per_request", [&mac_string, &counting_rng ]() { - Botan::HMAC_DRBG rng(Botan::MessageAuthenticationCode::create(mac_string), counting_rng, 2, 0); + Botan::HMAC_DRBG failing_rng(Botan::MessageAuthenticationCode::create(mac_string), counting_rng, 2, 0); }); result.test_throws("HMAC_DRBG does not accept values higher than 64KB for max_number_of_bytes_per_request", [ &mac_string, &counting_rng ]() { - Botan::HMAC_DRBG rng(Botan::MessageAuthenticationCode::create(mac_string), counting_rng, 2, 64 * 1024 + 1); + Botan::HMAC_DRBG failing_rng(Botan::MessageAuthenticationCode::create(mac_string), counting_rng, 2, 64 * 1024 + 1); }); // set reseed_interval to 1 so we can test that a long request is split diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp index dca93f57f..3ab22e57e 100644 --- a/src/tests/unit_ecc.cpp +++ b/src/tests/unit_ecc.cpp @@ -61,7 +61,7 @@ Botan::BigInt test_integer(Botan::RandomNumberGenerator& rng, size_t bits, BigIn */ Botan::BigInt x = 0; - auto flip_prob = [](size_t i) { + auto flip_prob = [](size_t i) -> double { if(i % 64 == 0) return .5; if(i % 32 == 0) diff --git a/src/tests/unit_tls.cpp b/src/tests/unit_tls.cpp index 35effc5a2..b910e3e0b 100644 --- a/src/tests/unit_tls.cpp +++ b/src/tests/unit_tls.cpp @@ -248,7 +248,7 @@ Test::Result test_tls_handshake(Botan::TLS::Protocol_Version offer_version, return false; }; - auto next_protocol_chooser = [&](std::vector<std::string> protos) { + auto next_protocol_chooser = [&](std::vector<std::string> protos) -> std::string { if(r <= 2) { result.test_eq("protocol count", protos.size(), 2); @@ -559,7 +559,7 @@ Test::Result test_dtls_handshake(Botan::TLS::Protocol_Version offer_version, return true; }; - auto next_protocol_chooser = [&](std::vector<std::string> protos) { + auto next_protocol_chooser = [&](std::vector<std::string> protos) -> std::string { if(r <= 2) { result.test_eq("protocol count", protos.size(), 2); |