aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-06-29 18:15:33 -0400
committerJack Lloyd <[email protected]>2019-06-29 18:15:33 -0400
commit5b435d11d32046062f23c0b69495631f5455ef6b (patch)
tree2361fe3c901bf83f20469ca80e208aae0ac75fe3 /src
parent692ca2118f77ad1c035e05ee495e3a21a9a99cbc (diff)
parent8b8745236368c70a82db2b19feeed5e9f9b59c5b (diff)
Merge GH #2010 Fix MSVC warnings
Diffstat (limited to 'src')
-rw-r--r--src/cli/speed.cpp3
-rw-r--r--src/cli/tls_client.cpp2
-rw-r--r--src/lib/compat/sodium/sodium.h2
-rw-r--r--src/lib/compat/sodium/sodium_utils.cpp2
-rw-r--r--src/lib/pbkdf/argon2/argon2.h2
-rw-r--r--src/lib/pbkdf/argon2/argon2fmt.cpp4
-rw-r--r--src/lib/pbkdf/argon2/argon2pwhash.cpp4
-rw-r--r--src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.cpp4
-rw-r--r--src/lib/pbkdf/pbkdf2/pbkdf2.cpp2
-rw-r--r--src/lib/pbkdf/scrypt/scrypt.cpp2
-rw-r--r--src/lib/pk_pad/iso9796/iso9796.cpp25
-rw-r--r--src/lib/pubkey/mce/code_based_key_gen.cpp14
-rw-r--r--src/lib/pubkey/mce/code_based_util.h4
-rw-r--r--src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp4
-rw-r--r--src/lib/pubkey/mce/gf2m_small_m.cpp7
-rw-r--r--src/lib/pubkey/mce/goppa_code.cpp4
-rw-r--r--src/lib/pubkey/mce/mceliece_key.cpp20
-rw-r--r--src/lib/pubkey/xmss/xmss_signature.h2
-rw-r--r--src/lib/utils/mem_pool/mem_pool.cpp6
-rw-r--r--src/lib/utils/socket/socket.cpp11
20 files changed, 65 insertions, 59 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index a481ec16a..f198c3e63 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -2211,6 +2211,8 @@ class Speed final : public Command
void bench_argon2(const std::string& /*provider*/,
std::chrono::milliseconds msec)
{
+ const uint8_t mode = 2; // Argon2id
+
for(size_t M : { 8*1024, 64*1024, 256*1024 })
{
for(size_t t : { 1, 2, 4 })
@@ -2220,7 +2222,6 @@ class Speed final : public Command
std::unique_ptr<Timer> timer = make_timer(
"Argon2id M=" + std::to_string(M) + " t=" + std::to_string(t) + " p=" + std::to_string(p));
- const size_t mode = 2;
uint8_t out[64];
uint8_t salt[16];
rng().randomize(salt, sizeof(salt));
diff --git a/src/cli/tls_client.cpp b/src/cli/tls_client.cpp
index f2fc40210..26e1f4b25 100644
--- a/src/cli/tls_client.cpp
+++ b/src/cli/tls_client.cpp
@@ -91,7 +91,7 @@ class TLS_Client final : public Command, public Botan::TLS::Callbacks
const std::string sessions_db = get_arg("session-db");
const std::string host = get_arg("host");
- const uint16_t port = get_arg_sz("port");
+ const uint16_t port = static_cast<uint16_t>(get_arg_sz("port"));
const std::string transport = get_arg("type");
const std::string next_protos = get_arg("next-protocols");
std::string policy_file = get_arg("policy");
diff --git a/src/lib/compat/sodium/sodium.h b/src/lib/compat/sodium/sodium.h
index 4bb37e974..f43b88abb 100644
--- a/src/lib/compat/sodium/sodium.h
+++ b/src/lib/compat/sodium/sodium.h
@@ -18,7 +18,7 @@ namespace Botan {
namespace Sodium {
// sodium/randombytes.h
-enum Sodium_Constants {
+enum Sodium_Constants : size_t {
SODIUM_SIZE_MAX = 0xFFFFFFFF,
crypto_aead_chacha20poly1305_ABYTES = 16,
diff --git a/src/lib/compat/sodium/sodium_utils.cpp b/src/lib/compat/sodium/sodium_utils.cpp
index 208355583..4b7afdb3d 100644
--- a/src/lib/compat/sodium/sodium_utils.cpp
+++ b/src/lib/compat/sodium/sodium_utils.cpp
@@ -133,7 +133,7 @@ void Sodium::sodium_free(void* ptr)
uint8_t* p = static_cast<uint8_t*>(ptr) - 8;
const uint64_t len = load_le<uint64_t>(p, 0);
- secure_scrub_memory(ptr, len);
+ secure_scrub_memory(ptr, static_cast<size_t>(len));
std::free(p);
}
diff --git a/src/lib/pbkdf/argon2/argon2.h b/src/lib/pbkdf/argon2/argon2.h
index 15bda45cc..a6fa03314 100644
--- a/src/lib/pbkdf/argon2/argon2.h
+++ b/src/lib/pbkdf/argon2/argon2.h
@@ -95,7 +95,7 @@ std::string BOTAN_PUBLIC_API(2,11)
argon2_generate_pwhash(const char* password, size_t password_len,
RandomNumberGenerator& rng,
size_t p, size_t M, size_t t,
- size_t y = 2, size_t salt_len = 16, size_t output_len = 32);
+ uint8_t y = 2, size_t salt_len = 16, size_t output_len = 32);
/**
* Check a previously created password hash
diff --git a/src/lib/pbkdf/argon2/argon2fmt.cpp b/src/lib/pbkdf/argon2/argon2fmt.cpp
index f64cd2bbd..480be5fa3 100644
--- a/src/lib/pbkdf/argon2/argon2fmt.cpp
+++ b/src/lib/pbkdf/argon2/argon2fmt.cpp
@@ -26,7 +26,7 @@ std::string strip_padding(std::string s)
std::string argon2_generate_pwhash(const char* password, size_t password_len,
RandomNumberGenerator& rng,
size_t p, size_t M, size_t t,
- size_t y, size_t salt_len, size_t output_len)
+ uint8_t y, size_t salt_len, size_t output_len)
{
std::vector<uint8_t> salt(salt_len);
rng.randomize(salt.data(), salt.size());
@@ -62,7 +62,7 @@ bool argon2_check_pwhash(const char* password, size_t password_len,
if(parts.size() != 5)
return false;
- size_t family = 0;
+ uint8_t family = 0;
if(parts[0] == "argon2d")
family = 0;
diff --git a/src/lib/pbkdf/argon2/argon2pwhash.cpp b/src/lib/pbkdf/argon2/argon2pwhash.cpp
index 25788c0bb..4eb2570f6 100644
--- a/src/lib/pbkdf/argon2/argon2pwhash.cpp
+++ b/src/lib/pbkdf/argon2/argon2pwhash.cpp
@@ -115,14 +115,14 @@ std::unique_ptr<PasswordHash> Argon2_Family::tune(size_t /*output_length*/,
const uint64_t mem_headroom = max_kib / M;
const uint64_t M_mult = std::min(desired_cost_increase, mem_headroom);
- M *= M_mult;
+ M *= static_cast<size_t>(M_mult);
est_nsec *= M_mult;
}
if(est_nsec < target_nsec)
{
const uint64_t desired_cost_increase = (target_nsec + est_nsec - 1) / est_nsec;
- t *= desired_cost_increase;
+ t *= static_cast<size_t>(desired_cost_increase);
}
return this->from_params(M, t, p);
diff --git a/src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.cpp b/src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.cpp
index f4e7676bd..36501b4cb 100644
--- a/src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.cpp
+++ b/src/lib/pbkdf/bcrypt_pbkdf/bcrypt_pbkdf.cpp
@@ -57,12 +57,12 @@ std::unique_ptr<PasswordHash> Bcrypt_PBKDF_Family::tune(size_t output_length,
const uint64_t target_nsec = msec.count() * static_cast<uint64_t>(1000000);
- const size_t desired_increase = target_nsec / measured_time;
+ const uint64_t desired_increase = target_nsec / measured_time;
if(desired_increase == 0)
return this->from_iterations(starting_iter);
- return this->from_iterations(desired_increase * starting_iter);
+ return this->from_iterations(static_cast<size_t>(desired_increase * starting_iter));
}
std::unique_ptr<PasswordHash> Bcrypt_PBKDF_Family::default_params() const
diff --git a/src/lib/pbkdf/pbkdf2/pbkdf2.cpp b/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
index 6b036f6e0..aa0081917 100644
--- a/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
+++ b/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
@@ -92,7 +92,7 @@ size_t tune_pbkdf2(MessageAuthenticationCode& prf,
const size_t blocks_needed = (output_length + prf_sz - 1) / prf_sz;
- const size_t multiplier = (desired_nsec / duration_nsec / blocks_needed);
+ const size_t multiplier = static_cast<size_t>(desired_nsec / duration_nsec / blocks_needed);
if(multiplier == 0)
return trial_iterations;
diff --git a/src/lib/pbkdf/scrypt/scrypt.cpp b/src/lib/pbkdf/scrypt/scrypt.cpp
index d493c17e1..8275ac956 100644
--- a/src/lib/pbkdf/scrypt/scrypt.cpp
+++ b/src/lib/pbkdf/scrypt/scrypt.cpp
@@ -97,7 +97,7 @@ std::unique_ptr<PasswordHash> Scrypt_Family::tune(size_t output_length,
// If we have extra runtime budget, increment p
if(target_nsec / est_nsec > 2)
- p *= std::min<uint64_t>(1024, (target_nsec / est_nsec));
+ p *= std::min<size_t>(1024, static_cast<size_t>(target_nsec / est_nsec));
return std::unique_ptr<PasswordHash>(new Scrypt(N, r, p));
}
diff --git a/src/lib/pk_pad/iso9796/iso9796.cpp b/src/lib/pk_pad/iso9796/iso9796.cpp
index 28a603bf9..9fdb87e3b 100644
--- a/src/lib/pk_pad/iso9796/iso9796.cpp
+++ b/src/lib/pk_pad/iso9796/iso9796.cpp
@@ -18,7 +18,11 @@ namespace Botan {
namespace {
secure_vector<uint8_t> iso9796_encoding(const secure_vector<uint8_t>& msg,
- size_t output_bits, std::unique_ptr<HashFunction>& hash, size_t SALT_SIZE, bool implicit, RandomNumberGenerator& rng)
+ size_t output_bits,
+ std::unique_ptr<HashFunction>& hash,
+ size_t SALT_SIZE,
+ bool implicit,
+ RandomNumberGenerator& rng)
{
const size_t output_length = (output_bits + 7) / 8;
@@ -36,16 +40,15 @@ secure_vector<uint8_t> iso9796_encoding(const secure_vector<uint8_t>& msg,
}
//calculate message capacity
- const size_t capacity = output_length
- - HASH_SIZE - SALT_SIZE - tLength - 1;
+ const size_t capacity = output_length - HASH_SIZE - SALT_SIZE - tLength - 1;
//msg1 is the recoverable and msg2 the unrecoverable message part.
secure_vector<uint8_t> msg1;
secure_vector<uint8_t> msg2;
if(msg.size() > capacity)
{
- msg1 = secure_vector<uint8_t> (msg.begin(), msg.begin() + capacity);
- msg2 = secure_vector<uint8_t> (msg.begin() + capacity, msg.end());
+ msg1 = secure_vector<uint8_t>(msg.begin(), msg.begin() + capacity);
+ msg2 = secure_vector<uint8_t>(msg.begin() + capacity, msg.end());
hash->update(msg2);
}
else
@@ -55,9 +58,9 @@ secure_vector<uint8_t> iso9796_encoding(const secure_vector<uint8_t>& msg,
msg2 = hash->final();
//compute H(C||msg1 ||H(msg2)||S)
- uint64_t msgLength = msg1.size();
+ const size_t msgLength = msg1.size();
secure_vector<uint8_t> salt = rng.random_vec(SALT_SIZE);
- hash->update_be(msgLength * 8);
+ hash->update_be(static_cast<uint64_t>(msgLength) * 8);
hash->update(msg1);
hash->update(msg2);
hash->update(salt);
@@ -66,8 +69,7 @@ secure_vector<uint8_t> iso9796_encoding(const secure_vector<uint8_t>& msg,
secure_vector<uint8_t> EM(output_length);
//compute message offset.
- size_t offset = output_length - HASH_SIZE - SALT_SIZE - tLength
- - msgLength - 1;
+ const size_t offset = output_length - HASH_SIZE - SALT_SIZE - tLength - msgLength - 1;
//insert message border (0x01), msg1 and salt into the output buffer
EM[offset] = 0x01;
@@ -243,7 +245,8 @@ secure_vector<uint8_t> ISO_9796_DS2::raw_data()
* ISO-9796-2 scheme 2 encode operation
*/
secure_vector<uint8_t> ISO_9796_DS2::encoding_of(const secure_vector<uint8_t>& msg,
- size_t output_bits, RandomNumberGenerator& rng)
+ size_t output_bits,
+ RandomNumberGenerator& rng)
{
return iso9796_encoding(msg, output_bits, m_hash, m_SALT_SIZE, m_implicit, rng);
}
@@ -254,7 +257,7 @@ secure_vector<uint8_t> ISO_9796_DS2::encoding_of(const secure_vector<uint8_t>& m
bool ISO_9796_DS2::verify(const secure_vector<uint8_t>& const_coded,
const secure_vector<uint8_t>& raw, size_t key_bits)
{
- return iso9796_verification(const_coded,raw,key_bits,m_hash,m_SALT_SIZE);
+ return iso9796_verification(const_coded, raw, key_bits, m_hash, m_SALT_SIZE);
}
/*
diff --git a/src/lib/pubkey/mce/code_based_key_gen.cpp b/src/lib/pubkey/mce/code_based_key_gen.cpp
index 97414418d..dad06f0c0 100644
--- a/src/lib/pubkey/mce/code_based_key_gen.cpp
+++ b/src/lib/pubkey/mce/code_based_key_gen.cpp
@@ -253,18 +253,18 @@ McEliece_PrivateKey generate_mceliece_key( RandomNumberGenerator & rng, uint32_t
// speed up the syndrome computation)
//
//
- std::vector<uint32_t> H(bit_size_to_32bit_size(codimension) * code_length );
+ std::vector<uint32_t> H(bit_size_to_32bit_size(codimension) * code_length);
uint32_t* sk = H.data();
for(size_t i = 0; i < code_length; ++i)
{
for(size_t l = 0; l < t; ++l)
{
- const uint32_t k = (l * ext_deg) / 32;
- const uint32_t j = (l * ext_deg) % 32;
+ const size_t k = (l * ext_deg) / 32;
+ const size_t j = (l * ext_deg) % 32;
sk[k] ^= static_cast<uint32_t>(F[i].get_coef(l)) << j;
- if (j + ext_deg > 32)
+ if(j + ext_deg > 32)
{
- sk[k + 1] ^= F[i].get_coef( l) >> (32 - j);
+ sk[k + 1] ^= F[i].get_coef(l) >> (32 - j);
}
}
sk += bit_size_to_32bit_size(codimension);
@@ -274,9 +274,9 @@ McEliece_PrivateKey generate_mceliece_key( RandomNumberGenerator & rng, uint32_t
// inverse is needed
std::vector<gf2m> Linv(code_length) ;
- for (size_t i = 0; i != Linv.size(); ++i)
+ for(size_t i = 0; i != Linv.size(); ++i)
{
- Linv[L[i]] = i;
+ Linv[L[i]] = static_cast<gf2m>(i);
}
std::vector<uint8_t> pubmat (R->m_elem.size() * 4);
for(size_t i = 0; i < R->m_elem.size(); i++)
diff --git a/src/lib/pubkey/mce/code_based_util.h b/src/lib/pubkey/mce/code_based_util.h
index 3812f4a40..291954a45 100644
--- a/src/lib/pubkey/mce/code_based_util.h
+++ b/src/lib/pubkey/mce/code_based_util.h
@@ -42,12 +42,12 @@ inline gf2m lex_to_gray(gf2m lex)
return (lex >> 1) ^ lex;
}
-inline uint32_t bit_size_to_byte_size(uint32_t bit_size)
+inline size_t bit_size_to_byte_size(uint32_t bit_size)
{
return (bit_size - 1) / 8 + 1;
}
-inline uint32_t bit_size_to_32bit_size(uint32_t bit_size)
+inline size_t bit_size_to_32bit_size(uint32_t bit_size)
{
return (bit_size - 1) / 32 + 1;
}
diff --git a/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp b/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp
index 1d35447fa..2c0f32194 100644
--- a/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp
+++ b/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp
@@ -19,15 +19,13 @@ uint32_t patch_root_array(gf2m* res_root_arr,
uint32_t res_root_arr_len,
uint32_t root_pos)
{
- volatile uint32_t i;
volatile gf2m patch_elem = 0x01;
volatile gf2m cond_mask = (root_pos == res_root_arr_len);
cond_mask = expand_mask_16bit(cond_mask);
cond_mask = ~cond_mask; /* now cond = 1 if not enough roots */
patch_elem &= cond_mask;
- for(i = 0; i < res_root_arr_len; i++)
+ for(size_t i = 0; i < res_root_arr_len; i++)
{
-
gf2m masked_patch_elem = (patch_elem++) & cond_mask;
res_root_arr[i] ^= masked_patch_elem++;
}
diff --git a/src/lib/pubkey/mce/gf2m_small_m.cpp b/src/lib/pubkey/mce/gf2m_small_m.cpp
index ffa593b66..47b4c34ae 100644
--- a/src/lib/pubkey/mce/gf2m_small_m.cpp
+++ b/src/lib/pubkey/mce/gf2m_small_m.cpp
@@ -18,7 +18,7 @@ namespace Botan {
namespace {
-unsigned int prim_poly[MAX_EXT_DEG + 1] = {
+gf2m prim_poly[MAX_EXT_DEG + 1] = {
01, /* extension degree 0 (!) never used */
03, /* extension degree 1 (!) never used */
07, /* extension degree 2 */
@@ -35,7 +35,6 @@ unsigned int prim_poly[MAX_EXT_DEG + 1] = {
020033, /* extension degree 13 */
042103, /* extension degree 14 */
0100003, /* extension degree 15 */
- 0210013 /* extension degree 16 */
};
std::vector<gf2m> gf_exp_table(size_t deg, gf2m prime_poly)
@@ -72,9 +71,9 @@ std::vector<gf2m> gf_log_table(size_t deg, const std::vector<gf2m>& exp)
std::vector<gf2m> tab(1 << deg);
tab[0] = (1 << deg) - 1; // log of 0 is the order by convention
- for (size_t i = 0; i < tab.size(); ++i)
+ for(size_t i = 0; i < tab.size(); ++i)
{
- tab[exp[i]] = i;
+ tab[exp[i]] = static_cast<gf2m>(i);
}
return tab;
}
diff --git a/src/lib/pubkey/mce/goppa_code.cpp b/src/lib/pubkey/mce/goppa_code.cpp
index 8183dd1d4..a1c493a13 100644
--- a/src/lib/pubkey/mce/goppa_code.cpp
+++ b/src/lib/pubkey/mce/goppa_code.cpp
@@ -117,7 +117,7 @@ secure_vector<gf2m> goppa_decode(const polyn_gf2m & syndrom_polyn,
/// XXX double assignment, possible bug?
if(tmp >= code_length) /* invalid root */
{
- result[i] = i;
+ result[i] = static_cast<gf2m>(i);
}
result[i] = Linv[tmp];
}
@@ -197,7 +197,7 @@ secure_vector<uint8_t> mceliece_decrypt(
uint32_t syndrome_byte_vec_size = syndrome_byte_vec.size();
for(uint32_t i = 0; i < syndrome_byte_vec_size; i++)
{
- syndrome_byte_vec[i] = syndrome_vec[i/4] >> (8* (i % 4));
+ syndrome_byte_vec[i] = static_cast<uint8_t>(syndrome_vec[i/4] >> (8* (i % 4)));
}
syndrome_polyn = polyn_gf2m(t-1, syndrome_byte_vec.data(), bit_size_to_byte_size(codimension), key.get_goppa_polyn().get_sp_field());
diff --git a/src/lib/pubkey/mce/mceliece_key.cpp b/src/lib/pubkey/mce/mceliece_key.cpp
index 09c4c3f31..433e65171 100644
--- a/src/lib/pubkey/mce/mceliece_key.cpp
+++ b/src/lib/pubkey/mce/mceliece_key.cpp
@@ -15,6 +15,7 @@
#include <botan/internal/bit_ops.h>
#include <botan/internal/code_based_util.h>
#include <botan/internal/pk_ops_impl.h>
+#include <botan/loadstor.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/rng.h>
@@ -121,25 +122,26 @@ secure_vector<uint8_t> McEliece_PrivateKey::private_key_bits() const
.encode(m_public_matrix, OCTET_STRING)
.encode(m_g.encode(), OCTET_STRING); // g as octet string
enc.start_cons(SEQUENCE);
- for(uint32_t i = 0; i < m_sqrtmod.size(); i++)
+ for(size_t i = 0; i < m_sqrtmod.size(); i++)
{
enc.encode(m_sqrtmod[i].encode(), OCTET_STRING);
}
enc.end_cons();
secure_vector<uint8_t> enc_support;
- for(uint32_t i = 0; i < m_Linv.size(); i++)
+
+ for(uint16_t Linv : m_Linv)
{
- enc_support.push_back(m_Linv[i] >> 8);
- enc_support.push_back(m_Linv[i]);
+ enc_support.push_back(get_byte(0, Linv));
+ enc_support.push_back(get_byte(1, Linv));
}
enc.encode(enc_support, OCTET_STRING);
secure_vector<uint8_t> enc_H;
- for(uint32_t i = 0; i < m_coeffs.size(); i++)
+ for(uint32_t coef : m_coeffs)
{
- enc_H.push_back(m_coeffs[i] >> 24);
- enc_H.push_back(m_coeffs[i] >> 16);
- enc_H.push_back(m_coeffs[i] >> 8);
- enc_H.push_back(m_coeffs[i]);
+ enc_H.push_back(get_byte(0, coef));
+ enc_H.push_back(get_byte(1, coef));
+ enc_H.push_back(get_byte(2, coef));
+ enc_H.push_back(get_byte(3, coef));
}
enc.encode(enc_H, OCTET_STRING);
enc.end_cons();
diff --git a/src/lib/pubkey/xmss/xmss_signature.h b/src/lib/pubkey/xmss/xmss_signature.h
index 25e168fd8..838aae2e8 100644
--- a/src/lib/pubkey/xmss/xmss_signature.h
+++ b/src/lib/pubkey/xmss/xmss_signature.h
@@ -117,7 +117,7 @@ class XMSS_Signature final
secure_vector<uint8_t> bytes() const;
private:
- uint64_t m_leaf_idx;
+ size_t m_leaf_idx;
secure_vector<uint8_t> m_randomness;
XMSS_WOTS_PublicKey::TreeSignature m_tree_sig;
};
diff --git a/src/lib/utils/mem_pool/mem_pool.cpp b/src/lib/utils/mem_pool/mem_pool.cpp
index 9542ecbfa..25a3fb408 100644
--- a/src/lib/utils/mem_pool/mem_pool.cpp
+++ b/src/lib/utils/mem_pool/mem_pool.cpp
@@ -149,7 +149,7 @@ class BitMap final
BitMap(size_t bits) : m_len(bits)
{
m_bits.resize((bits + BITMASK_BITS - 1) / BITMASK_BITS);
- m_main_mask = ~static_cast<bitmask_type>(0);
+ m_main_mask = static_cast<bitmask_type>(0) - 1; // all bits set
m_last_mask = m_main_mask;
if(bits % BITMASK_BITS != 0)
@@ -163,7 +163,7 @@ class BitMap final
BOTAN_ASSERT_NOMSG(bit <= m_len);
const size_t w = bit / BITMASK_BITS;
BOTAN_ASSERT_NOMSG(w < m_bits.size());
- const size_t mask = static_cast<bitmask_type>(1) << (bit % BITMASK_BITS);
+ const bitmask_type mask = static_cast<bitmask_type>(1) << (bit % BITMASK_BITS);
m_bits[w] = m_bits[w] & (~mask);
}
@@ -203,7 +203,7 @@ bool BitMap::find_free(size_t* bit)
if((m_bits[i] & mask) != mask)
{
size_t free_bit = find_set_bit(~m_bits[i]);
- const size_t bmask = static_cast<bitmask_type>(1) << (free_bit % BITMASK_BITS);
+ const bitmask_type bmask = static_cast<bitmask_type>(1) << (free_bit % BITMASK_BITS);
BOTAN_ASSERT_NOMSG((m_bits[i] & bmask) == 0);
m_bits[i] |= bmask;
*bit = BITMASK_BITS*i + free_bit;
diff --git a/src/lib/utils/socket/socket.cpp b/src/lib/utils/socket/socket.cpp
index e7c2ccd81..41177809e 100644
--- a/src/lib/utils/socket/socket.cpp
+++ b/src/lib/utils/socket/socket.cpp
@@ -144,6 +144,7 @@ class BSD_Socket final : public OS::Socket
#if defined(BOTAN_TARGET_OS_HAS_WINSOCK2)
typedef SOCKET socket_type;
typedef int socket_op_ret_type;
+ typedef int socklen_type;
static socket_type invalid_socket() { return INVALID_SOCKET; }
static void close_socket(socket_type s) { ::closesocket(s); }
static std::string get_last_socket_error() { return std::to_string(::WSAGetLastError()); }
@@ -183,6 +184,7 @@ class BSD_Socket final : public OS::Socket
#else
typedef int socket_type;
typedef ssize_t socket_op_ret_type;
+ typedef socklen_t socklen_type;
static socket_type invalid_socket() { return -1; }
static void close_socket(socket_type s) { ::close(s); }
static std::string get_last_socket_error() { return ::strerror(errno); }
@@ -234,7 +236,7 @@ class BSD_Socket final : public OS::Socket
set_nonblocking(m_socket);
- int err = ::connect(m_socket, rp->ai_addr, rp->ai_addrlen);
+ int err = ::connect(m_socket, rp->ai_addr, static_cast<socklen_type>(rp->ai_addrlen));
if(err == -1)
{
@@ -244,7 +246,8 @@ class BSD_Socket final : public OS::Socket
struct timeval timeout_tv = make_timeout_tv();
fd_set write_set;
FD_ZERO(&write_set);
- FD_SET(m_socket, &write_set);
+ // Weirdly, Winsock uses a SOCKET type but wants FD_SET to get an int instead
+ FD_SET(static_cast<int>(m_socket), &write_set);
active = ::select(m_socket + 1, nullptr, &write_set, nullptr, &timeout_tv);
@@ -336,8 +339,8 @@ class BSD_Socket final : public OS::Socket
struct timeval make_timeout_tv() const
{
struct timeval tv;
- tv.tv_sec = m_timeout.count() / 1000000;
- tv.tv_usec = m_timeout.count() % 1000000;
+ tv.tv_sec = static_cast<time_t>(m_timeout.count() / 1000000);
+ tv.tv_usec = static_cast<long>(m_timeout.count() % 1000000);;
return tv;
}