diff options
author | Jack Lloyd <[email protected]> | 2017-08-31 08:23:30 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-08-31 08:23:30 -0400 |
commit | 7fecb1254232311d5f2ca62f9cda1e12a4b2558c (patch) | |
tree | 2e2cd8ef8ca016310d4cc9aa6bee7abc96c39e2f | |
parent | df4287c3c763de14b262ed39d54b3de552adbefb (diff) |
More MSVC warnings fixes
-rw-r--r-- | src/cli/timing_tests.cpp | 4 | ||||
-rw-r--r-- | src/cli/utils.cpp | 10 | ||||
-rw-r--r-- | src/lib/ffi/ffi_kdf.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/par_hash/par_hash.cpp | 2 | ||||
-rw-r--r-- | src/lib/misc/rfc3394/rfc3394.cpp | 4 | ||||
-rw-r--r-- | src/lib/modes/aead/ccm/ccm.cpp | 5 | ||||
-rw-r--r-- | src/lib/passhash/bcrypt/bcrypt.cpp | 2 | ||||
-rw-r--r-- | src/lib/pbkdf/pgp_s2k/pgp_s2k.cpp | 4 | ||||
-rw-r--r-- | src/lib/pubkey/mce/mce_workfactor.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/pbes2/pbes2.cpp | 4 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_verification_operation.cpp | 2 | ||||
-rw-r--r-- | src/lib/tls/tls_cbc/tls_cbc.cpp | 10 | ||||
-rw-r--r-- | src/lib/tls/tls_seq_numbers.h | 2 | ||||
-rw-r--r-- | src/tests/test_ffi.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_gf2m.cpp | 2 |
15 files changed, 34 insertions, 25 deletions
diff --git a/src/cli/timing_tests.cpp b/src/cli/timing_tests.cpp index 4e90751ff..511eac8bc 100644 --- a/src/cli/timing_tests.cpp +++ b/src/cli/timing_tests.cpp @@ -156,7 +156,7 @@ class Manger_Timing_Test : public Timing_Test { m_dec.decrypt(input.data(), m_ctext_length); } - catch(Botan::Decoding_Error& e) + catch(Botan::Decoding_Error&) { } ticks end = get_ticks(); @@ -229,7 +229,7 @@ ticks Lucky13_Timing_Test::measure_critical_function(std::vector<uint8_t> input) { m_dec.finish(data); } - catch(Botan::TLS::TLS_Exception& e) + catch(Botan::TLS::TLS_Exception&) { } ticks end = get_ticks(); diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp index 2bf03c760..63e0fc7d6 100644 --- a/src/cli/utils.cpp +++ b/src/cli/utils.cpp @@ -328,7 +328,15 @@ class Generate_Bcrypt final : public Command const std::string password = get_arg("password"); const size_t wf = get_arg_sz("work-factor"); - output() << Botan::generate_bcrypt(password, rng(), wf) << "\n"; + if(wf < 4 || wf > 18) + { + error_output() << "Invalid bcrypt work factor\n"; + } + else + { + const uint16_t wf16 = static_cast<uint16_t>(wf); + output() << Botan::generate_bcrypt(password, rng(), wf16) << "\n"; + } } }; diff --git a/src/lib/ffi/ffi_kdf.cpp b/src/lib/ffi/ffi_kdf.cpp index 4eca31773..1a4c40893 100644 --- a/src/lib/ffi/ffi_kdf.cpp +++ b/src/lib/ffi/ffi_kdf.cpp @@ -72,7 +72,7 @@ int botan_bcrypt_generate(uint8_t* out, size_t* out_len, if(flags != 0) return BOTAN_FFI_ERROR_BAD_FLAG; - if(wf < 2 || wf > 30) + if(wf < 4 || wf > 18) throw FFI_Error("Bad bcrypt work factor " + std::to_string(wf)); Botan::RandomNumberGenerator& rng = safe_get(rng_obj); diff --git a/src/lib/hash/par_hash/par_hash.cpp b/src/lib/hash/par_hash/par_hash.cpp index af43d6d97..a0297dfe8 100644 --- a/src/lib/hash/par_hash/par_hash.cpp +++ b/src/lib/hash/par_hash/par_hash.cpp @@ -18,7 +18,7 @@ void Parallel::add_data(const uint8_t input[], size_t length) void Parallel::final_result(uint8_t out[]) { - uint32_t offset = 0; + size_t offset = 0; for(auto&& hash : m_hashes) { diff --git a/src/lib/misc/rfc3394/rfc3394.cpp b/src/lib/misc/rfc3394/rfc3394.cpp index 2ec49ac65..3bb792723 100644 --- a/src/lib/misc/rfc3394/rfc3394.cpp +++ b/src/lib/misc/rfc3394/rfc3394.cpp @@ -39,7 +39,7 @@ secure_vector<uint8_t> rfc3394_keywrap(const secure_vector<uint8_t>& key, { for(size_t i = 1; i <= n; ++i) { - const uint32_t t = (n * j) + i; + const uint32_t t = static_cast<uint32_t>((n * j) + i); copy_mem(&A[8], &R[8*i], 8); @@ -84,7 +84,7 @@ secure_vector<uint8_t> rfc3394_keyunwrap(const secure_vector<uint8_t>& key, { for(size_t i = n; i != 0; --i) { - const uint32_t t = (5 - j) * n + i; + const uint32_t t = static_cast<uint32_t>((5 - j) * n + i); uint8_t t_buf[4] = { 0 }; store_be(t, t_buf); diff --git a/src/lib/modes/aead/ccm/ccm.cpp b/src/lib/modes/aead/ccm/ccm.cpp index db0d2d58b..b7f81e5ab 100644 --- a/src/lib/modes/aead/ccm/ccm.cpp +++ b/src/lib/modes/aead/ccm/ccm.cpp @@ -136,7 +136,8 @@ secure_vector<uint8_t> CCM_Mode::format_b0(size_t sz) { secure_vector<uint8_t> B0(CCM_BS); - const uint8_t b_flags = (m_ad_buf.size() ? 64 : 0) + (((tag_size()/2)-1) << 3) + (L()-1); + const uint8_t b_flags = + static_cast<uint8_t>((m_ad_buf.size() ? 64 : 0) + (((tag_size()/2)-1) << 3) + (L()-1)); B0[0] = b_flags; copy_mem(&B0[1], m_nonce.data(), m_nonce.size()); @@ -149,7 +150,7 @@ secure_vector<uint8_t> CCM_Mode::format_c0() { secure_vector<uint8_t> C(CCM_BS); - const uint8_t a_flags = L()-1; + const uint8_t a_flags = static_cast<uint8_t>(L() - 1); C[0] = a_flags; copy_mem(&C[1], m_nonce.data(), m_nonce.size()); diff --git a/src/lib/passhash/bcrypt/bcrypt.cpp b/src/lib/passhash/bcrypt/bcrypt.cpp index 8cea34a97..4f3cda2ae 100644 --- a/src/lib/passhash/bcrypt/bcrypt.cpp +++ b/src/lib/passhash/bcrypt/bcrypt.cpp @@ -138,7 +138,7 @@ bool check_bcrypt(const std::string& pass, const std::string& hash) return false; } - const uint16_t workfactor = to_u32bit(hash.substr(4, 2)); + const uint16_t workfactor = to_uint16(hash.substr(4, 2)); const std::vector<uint8_t> salt = bcrypt_base64_decode(hash.substr(7, 22)); if(salt.size() != 16) diff --git a/src/lib/pbkdf/pgp_s2k/pgp_s2k.cpp b/src/lib/pbkdf/pgp_s2k/pgp_s2k.cpp index 21edb6afc..f298bb3e4 100644 --- a/src/lib/pbkdf/pgp_s2k/pgp_s2k.cpp +++ b/src/lib/pbkdf/pgp_s2k/pgp_s2k.cpp @@ -57,9 +57,9 @@ uint8_t OpenPGP_S2K::encode_count(size_t desired_iterations) */ for(size_t c = 0; c < 256; ++c) { - size_t decoded_iter = OPENPGP_S2K_ITERS[c]; + const uint32_t decoded_iter = OPENPGP_S2K_ITERS[c]; if(decoded_iter >= desired_iterations) - return c; + return static_cast<uint8_t>(c); } return 255; diff --git a/src/lib/pubkey/mce/mce_workfactor.cpp b/src/lib/pubkey/mce/mce_workfactor.cpp index 51cfcc269..f1dddeee9 100644 --- a/src/lib/pubkey/mce/mce_workfactor.cpp +++ b/src/lib/pubkey/mce/mce_workfactor.cpp @@ -106,7 +106,7 @@ size_t mceliece_work_factor(size_t n, size_t t) min = std::min(min, lwf); } - return min; + return static_cast<size_t>(min); } } diff --git a/src/lib/pubkey/pbes2/pbes2.cpp b/src/lib/pubkey/pbes2/pbes2.cpp index b0a7f336d..6bc7a23c3 100644 --- a/src/lib/pubkey/pbes2/pbes2.cpp +++ b/src/lib/pubkey/pbes2/pbes2.cpp @@ -125,7 +125,7 @@ pbes2_encrypt(const secure_vector<uint8_t>& key_bits, const std::string& digest, RandomNumberGenerator& rng) { - size_t msec_in_iterations_out = msec.count(); + size_t msec_in_iterations_out = static_cast<size_t>(msec.count()); return pbes2_encrypt_shared(key_bits, passphrase, &msec_in_iterations_out, 0, cipher, digest, rng); // return value msec_in_iterations_out discarded } @@ -139,7 +139,7 @@ pbes2_encrypt_msec(const secure_vector<uint8_t>& key_bits, const std::string& digest, RandomNumberGenerator& rng) { - size_t msec_in_iterations_out = msec.count(); + size_t msec_in_iterations_out = static_cast<size_t>(msec.count()); auto ret = pbes2_encrypt_shared(key_bits, passphrase, &msec_in_iterations_out, 0, cipher, digest, rng); diff --git a/src/lib/pubkey/xmss/xmss_verification_operation.cpp b/src/lib/pubkey/xmss/xmss_verification_operation.cpp index fe712d4c8..5f8c3a721 100644 --- a/src/lib/pubkey/xmss/xmss_verification_operation.cpp +++ b/src/lib/pubkey/xmss/xmss_verification_operation.cpp @@ -117,7 +117,7 @@ bool XMSS_Verification_Operation::is_valid_signature(const uint8_t sig[], m_msg_buf.clear(); return result; } - catch(Integrity_Failure& e) + catch(Integrity_Failure&) { m_msg_buf.clear(); return false; diff --git a/src/lib/tls/tls_cbc/tls_cbc.cpp b/src/lib/tls/tls_cbc/tls_cbc.cpp index 9e178a457..e63893d75 100644 --- a/src/lib/tls/tls_cbc/tls_cbc.cpp +++ b/src/lib/tls/tls_cbc/tls_cbc.cpp @@ -134,8 +134,8 @@ void TLS_CBC_HMAC_AEAD_Encryption::set_associated_data(const uint8_t ad[], size_ if(use_encrypt_then_mac()) { // AAD hack for EtM - size_t pt_size = make_uint16(assoc_data()[11], assoc_data()[12]); - size_t enc_size = round_up(iv_size() + pt_size + 1, block_size()); + const uint16_t pt_size = make_uint16(assoc_data()[11], assoc_data()[12]); + const uint16_t enc_size = round_up(iv_size() + pt_size + 1, block_size()); assoc_data()[11] = get_byte<uint16_t>(0, enc_size); assoc_data()[12] = get_byte<uint16_t>(1, enc_size); } @@ -344,11 +344,11 @@ void TLS_CBC_HMAC_AEAD_Decryption::perform_additional_compressions(size_t plen, max_bytes_in_first_block = 55; } // number of maximum MACed bytes - const uint16_t L1 = 13 + plen - tag_size(); + const uint16_t L1 = static_cast<uint16_t>(13 + plen - tag_size()); // number of current MACed bytes (L1 - padlen) // Here the Lucky 13 paper is different because the padlen length in the paper // does not count the last message byte. - const uint16_t L2 = 13 + plen - padlen - tag_size(); + const uint16_t L2 = static_cast<uint16_t>(13 + plen - padlen - tag_size()); // From the paper, for SHA-256/SHA-1 compute: ceil((L1-55)/64) and ceil((L2-55)/64) // ceil((L1-55)/64) = floor((L1+64-1-55)/64) // Here we compute number of compressions for SHA-* in general @@ -416,7 +416,7 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<uint8_t>& buffer, size_t } const uint8_t* plaintext_block = &record_contents[0]; - const uint16_t plaintext_length = enc_size - pad_size; + const size_t plaintext_length = enc_size - pad_size; buffer.insert(buffer.end(), plaintext_block, plaintext_block + plaintext_length); } diff --git a/src/lib/tls/tls_seq_numbers.h b/src/lib/tls/tls_seq_numbers.h index ece329494..c5741b998 100644 --- a/src/lib/tls/tls_seq_numbers.h +++ b/src/lib/tls/tls_seq_numbers.h @@ -102,7 +102,7 @@ class Datagram_Sequence_Numbers final : public Connection_Sequence_Numbers if(sequence > m_window_highest) { - const size_t offset = sequence - m_window_highest; + const uint64_t offset = sequence - m_window_highest; m_window_highest += offset; if(offset >= window_size) diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index d94fae7ba..41fa3a044 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -816,7 +816,7 @@ class FFI_Unit_Tests : public Test uint32_t x_32; TEST_FFI_OK(botan_mp_to_uint32, (x, &x_32)); - result.test_eq("botan_mp_to_uint32", x, 0x103); + result.test_eq("botan_mp_to_uint32", x, static_cast<size_t>(0x103)); TEST_FFI_RC(1, botan_mp_get_bit, (x, 1)); TEST_FFI_RC(0, botan_mp_get_bit, (x, 87)); @@ -1444,7 +1444,7 @@ class FFI_Unit_Tests : public Test TEST_FFI_OK(botan_pk_op_sign_destroy, (signer)); } - botan_pk_op_verify_t verifier; + botan_pk_op_verify_t verifier = nullptr; if(signature.size() > 0 && TEST_FFI_OK(botan_pk_op_verify_create, (&verifier, pub, sm2_ident.c_str(), 0))) { diff --git a/src/tests/test_gf2m.cpp b/src/tests/test_gf2m.cpp index c8110034e..9bb572c4e 100644 --- a/src/tests/test_gf2m.cpp +++ b/src/tests/test_gf2m.cpp @@ -45,7 +45,7 @@ class GF2m_Tests : public Test for(size_t i = 0; i <= field.gf_ord(); ++i) { - gf2m a = i; + gf2m a = static_cast<gf2m>(i); result.test_eq("square vs multiply", static_cast<size_t>(field.gf_square(a)), |