diff options
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | src/lib/ffi/ffi_util.h | 2 | ||||
-rw-r--r-- | src/lib/tls/tls_extensions.cpp | 3 | ||||
-rw-r--r-- | src/lib/utils/cpuid.cpp | 18 | ||||
-rw-r--r-- | src/lib/utils/cpuid.h | 33 | ||||
-rw-r--r-- | src/tests/test_pbkdf.cpp | 53 | ||||
-rw-r--r-- | src/tests/test_rng.cpp | 1 | ||||
-rw-r--r-- | src/tests/unit_x509.cpp | 5 |
8 files changed, 97 insertions, 20 deletions
diff --git a/.travis.yml b/.travis.yml index c2e3b5914..d7092f01a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -105,6 +105,8 @@ after_success: branches: only: - master + - release-2 + - coverity_scan notifications: email: [email protected] diff --git a/src/lib/ffi/ffi_util.h b/src/lib/ffi/ffi_util.h index 919efdd75..883c1146c 100644 --- a/src/lib/ffi/ffi_util.h +++ b/src/lib/ffi/ffi_util.h @@ -29,7 +29,7 @@ struct botan_struct { public: botan_struct(T* obj) : m_magic(MAGIC), m_obj(obj) {} - ~botan_struct() { m_magic = 0; m_obj.reset(); } + virtual ~botan_struct() { m_magic = 0; m_obj.reset(); } bool magic_ok() const { return (m_magic == MAGIC); } diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp index dfd909c7c..c76128632 100644 --- a/src/lib/tls/tls_extensions.cpp +++ b/src/lib/tls/tls_extensions.cpp @@ -644,7 +644,8 @@ std::vector<uint8_t> Certificate_Status_Request::serialize() const } Certificate_Status_Request::Certificate_Status_Request(TLS_Data_Reader& reader, - uint16_t extension_size) + uint16_t extension_size) : + m_server_side(false) { if(extension_size > 0) { diff --git a/src/lib/utils/cpuid.cpp b/src/lib/utils/cpuid.cpp index 0a0a63a3b..59e8991ab 100644 --- a/src/lib/utils/cpuid.cpp +++ b/src/lib/utils/cpuid.cpp @@ -58,7 +58,7 @@ namespace Botan { uint64_t CPUID::g_processor_features = 0; size_t CPUID::g_cache_line_size = BOTAN_TARGET_CPU_DEFAULT_CACHE_LINE_SIZE; -bool CPUID::g_little_endian = false; +CPUID::Endian_status CPUID::g_endian_status = ENDIAN_UNKNOWN; namespace { @@ -410,6 +410,7 @@ void CPUID::print(std::ostream& o) o << "CPUID flags: " << CPUID::to_string() << "\n"; } +//static void CPUID::initialize() { g_processor_features = 0; @@ -423,18 +424,24 @@ void CPUID::initialize() #endif g_processor_features |= CPUID::CPUID_INITIALIZED_BIT; + } +//static +CPUID::Endian_status CPUID::runtime_check_endian() + { // Check runtime endian const uint32_t endian32 = 0x01234567; const uint8_t* e8 = reinterpret_cast<const uint8_t*>(&endian32); + Endian_status endian = ENDIAN_UNKNOWN; + if(e8[0] == 0x01 && e8[1] == 0x23 && e8[2] == 0x45 && e8[3] == 0x67) { - g_little_endian = false; + endian = ENDIAN_BIG; } else if(e8[0] == 0x67 && e8[1] == 0x45 && e8[2] == 0x23 && e8[3] == 0x01) { - g_little_endian = true; + endian = ENDIAN_LITTLE; } else { @@ -443,11 +450,12 @@ void CPUID::initialize() // If we were compiled with a known endian, verify it matches at runtime #if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) - BOTAN_ASSERT(g_little_endian == true, "Build and runtime endian match"); + BOTAN_ASSERT(endian == ENDIAN_LITTLE, "Build and runtime endian match"); #elif defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) - BOTAN_ASSERT(g_little_endian == false, "Build and runtime endian match"); + BOTAN_ASSERT(endian == ENDIAN_BIG, "Build and runtime endian match"); #endif + return endian; } } diff --git a/src/lib/utils/cpuid.h b/src/lib/utils/cpuid.h index 71dc24496..c27390729 100644 --- a/src/lib/utils/cpuid.h +++ b/src/lib/utils/cpuid.h @@ -73,20 +73,12 @@ class BOTAN_DLL CPUID static bool is_little_endian() { - if(g_processor_features == 0) - { - initialize(); - } - return g_little_endian; + return endian_status() == ENDIAN_LITTLE; } static bool is_big_endian() { - /* - * We do not support PDP endian, so the endian is - * always either big or little. - */ - return is_little_endian() == false; + return endian_status() == ENDIAN_BIG; } enum CPUID_bits : uint64_t { @@ -281,9 +273,26 @@ class BOTAN_DLL CPUID } private: - static bool g_little_endian; - static size_t g_cache_line_size; + enum Endian_status : uint32_t { + ENDIAN_UNKNOWN = 0x00000000, + ENDIAN_BIG = 0x01234567, + ENDIAN_LITTLE = 0x67452301, + }; + + static Endian_status runtime_check_endian(); + + static Endian_status endian_status() + { + if(g_endian_status == ENDIAN_UNKNOWN) + { + g_endian_status = runtime_check_endian(); + } + return g_endian_status; + } + static uint64_t g_processor_features; + static size_t g_cache_line_size; + static Endian_status g_endian_status; }; } diff --git a/src/tests/test_pbkdf.cpp b/src/tests/test_pbkdf.cpp index 32144bd9b..c45cc45de 100644 --- a/src/tests/test_pbkdf.cpp +++ b/src/tests/test_pbkdf.cpp @@ -10,6 +10,10 @@ #include <botan/pbkdf.h> #endif +#if defined(BOTAN_HAS_PGP_S2K) + #include <botan/pgp_s2k.h> +#endif + namespace Botan_Tests { namespace { @@ -53,6 +57,55 @@ BOTAN_REGISTER_TEST("pbkdf", PBKDF_KAT_Tests); #endif +#if defined(BOTAN_HAS_PGP_S2K) + +class PGP_S2K_Iter_Test : public Test + { + public: + std::vector<Test::Result> run() override + { + Test::Result result("PGP_S2K iteration encoding"); + + // The maximum representable iteration count + const size_t max_iter = 65011712; + + result.test_eq("Encoding of large value accepted", + Botan::OpenPGP_S2K::encode_count(max_iter * 2), size_t(255)); + result.test_eq("Encoding of small value accepted", + Botan::OpenPGP_S2K::encode_count(0), size_t(0)); + + for(size_t c = 0; c != 256; ++c) + { + const size_t dec = Botan::OpenPGP_S2K::decode_count(c); + const size_t comp_dec = (16 + (c & 0x0F)) << ((c >> 4) + 6); + result.test_eq("Decoded value matches PGP formula", dec, comp_dec); + } + + uint8_t last_enc = 0; + + for(size_t i = 0; i <= max_iter; i += 64) + { + const uint8_t enc = Botan::OpenPGP_S2K::encode_count(i); + result.test_lte("Encoded value non-decreasing", last_enc, enc); + + /* + The iteration count as encoded may not be exactly the + value requested, but should never be less + */ + const size_t dec = Botan::OpenPGP_S2K::decode_count(enc); + result.test_gte("Decoded value is >= requested", dec, i); + + last_enc = enc; + } + + return std::vector<Test::Result>{result}; + } + }; + +BOTAN_REGISTER_TEST("pgp_s2k_iter", PGP_S2K_Iter_Test); + +#endif + } } diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp index 8c82b023a..899ed0050 100644 --- a/src/tests/test_rng.cpp +++ b/src/tests/test_rng.cpp @@ -598,7 +598,6 @@ BOTAN_REGISTER_TEST("chacha_rng_unit", ChaCha_RNG_Unit_Tests); #endif - #if defined(BOTAN_HAS_AUTO_RNG) class AutoSeeded_RNG_Tests : public Test diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp index 89eef51d7..66cbddb36 100644 --- a/src/tests/unit_x509.cpp +++ b/src/tests/unit_x509.cpp @@ -60,6 +60,8 @@ Botan::X509_Cert_Options req_opts1(const std::string& algo) opts.not_before("160101200000Z"); opts.not_after("300101200000Z"); + opts.challenge = "zoom"; + if(algo == "RSA") { opts.constraints = Botan::Key_Constraints(Botan::KEY_ENCIPHERMENT); @@ -389,6 +391,9 @@ Test::Result test_x509_cert(const std::string& sig_algo, const std::string& hash hash_fn, Test::rng()); + result.test_eq("PKCS10 challenge password parsed", + user1_req.challenge_password(), "zoom"); + /* Create user #2's key and cert request */ std::unique_ptr<Botan::Private_Key> user2_key(make_a_private_key(sig_algo)); |