diff options
author | Jack Lloyd <[email protected]> | 2018-12-04 09:35:41 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-12-04 09:35:41 -0500 |
commit | 4e16f683d7fd3a2ab0553c9423fc725798cd899f (patch) | |
tree | 208f30df5b1922442e2804c5c9299659bc99c77a /src/lib | |
parent | 50de06c585609d969da5b9ab5812e62328bacaee (diff) |
Silence MSVC warnings
static_casts for the compiler god
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/pubkey/ed25519/ed25519_fe.cpp | 64 | ||||
-rw-r--r-- | src/lib/pubkey/ed25519/sc_muladd.cpp | 64 | ||||
-rw-r--r-- | src/lib/pubkey/ed25519/sc_reduce.cpp | 64 | ||||
-rw-r--r-- | src/lib/pubkey/mce/code_based_key_gen.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/newhope/newhope.cpp | 16 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_common_ops.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_signature_operation.cpp | 4 | ||||
-rw-r--r-- | src/lib/stream/ctr/ctr.cpp | 4 | ||||
-rw-r--r-- | src/lib/tls/tls_extensions.cpp | 6 | ||||
-rw-r--r-- | src/lib/x509/x509cert.cpp | 4 |
10 files changed, 116 insertions, 114 deletions
diff --git a/src/lib/pubkey/ed25519/ed25519_fe.cpp b/src/lib/pubkey/ed25519/ed25519_fe.cpp index d442d89a7..135813d39 100644 --- a/src/lib/pubkey/ed25519/ed25519_fe.cpp +++ b/src/lib/pubkey/ed25519/ed25519_fe.cpp @@ -717,38 +717,38 @@ void FE_25519::to_bytes(uint8_t s[32]) const Goal: Output h0+...+2^230 h9. */ - s[0] = h0 >> 0; - s[1] = h0 >> 8; - s[2] = h0 >> 16; - s[3] = (h0 >> 24) | (h1 << 2); - s[4] = h1 >> 6; - s[5] = h1 >> 14; - s[6] = (h1 >> 22) | (h2 << 3); - s[7] = h2 >> 5; - s[8] = h2 >> 13; - s[9] = (h2 >> 21) | (h3 << 5); - s[10] = h3 >> 3; - s[11] = h3 >> 11; - s[12] = (h3 >> 19) | (h4 << 6); - s[13] = h4 >> 2; - s[14] = h4 >> 10; - s[15] = h4 >> 18; - s[16] = h5 >> 0; - s[17] = h5 >> 8; - s[18] = h5 >> 16; - s[19] = (h5 >> 24) | (h6 << 1); - s[20] = h6 >> 7; - s[21] = h6 >> 15; - s[22] = (h6 >> 23) | (h7 << 3); - s[23] = h7 >> 5; - s[24] = h7 >> 13; - s[25] = (h7 >> 21) | (h8 << 4); - s[26] = h8 >> 4; - s[27] = h8 >> 12; - s[28] = (h8 >> 20) | (h9 << 6); - s[29] = h9 >> 2; - s[30] = h9 >> 10; - s[31] = h9 >> 18; + s[0] = static_cast<uint8_t>(h0 >> 0); + s[1] = static_cast<uint8_t>(h0 >> 8); + s[2] = static_cast<uint8_t>(h0 >> 16); + s[3] = static_cast<uint8_t>((h0 >> 24) | (h1 << 2)); + s[4] = static_cast<uint8_t>(h1 >> 6); + s[5] = static_cast<uint8_t>(h1 >> 14); + s[6] = static_cast<uint8_t>((h1 >> 22) | (h2 << 3)); + s[7] = static_cast<uint8_t>(h2 >> 5); + s[8] = static_cast<uint8_t>(h2 >> 13); + s[9] = static_cast<uint8_t>((h2 >> 21) | (h3 << 5)); + s[10] = static_cast<uint8_t>(h3 >> 3); + s[11] = static_cast<uint8_t>(h3 >> 11); + s[12] = static_cast<uint8_t>((h3 >> 19) | (h4 << 6)); + s[13] = static_cast<uint8_t>(h4 >> 2); + s[14] = static_cast<uint8_t>(h4 >> 10); + s[15] = static_cast<uint8_t>(h4 >> 18); + s[16] = static_cast<uint8_t>(h5 >> 0); + s[17] = static_cast<uint8_t>(h5 >> 8); + s[18] = static_cast<uint8_t>(h5 >> 16); + s[19] = static_cast<uint8_t>((h5 >> 24) | (h6 << 1)); + s[20] = static_cast<uint8_t>(h6 >> 7); + s[21] = static_cast<uint8_t>(h6 >> 15); + s[22] = static_cast<uint8_t>((h6 >> 23) | (h7 << 3)); + s[23] = static_cast<uint8_t>(h7 >> 5); + s[24] = static_cast<uint8_t>(h7 >> 13); + s[25] = static_cast<uint8_t>((h7 >> 21) | (h8 << 4)); + s[26] = static_cast<uint8_t>(h8 >> 4); + s[27] = static_cast<uint8_t>(h8 >> 12); + s[28] = static_cast<uint8_t>((h8 >> 20) | (h9 << 6)); + s[29] = static_cast<uint8_t>(h9 >> 2); + s[30] = static_cast<uint8_t>(h9 >> 10); + s[31] = static_cast<uint8_t>(h9 >> 18); } } diff --git a/src/lib/pubkey/ed25519/sc_muladd.cpp b/src/lib/pubkey/ed25519/sc_muladd.cpp index 711118ceb..4a88be22d 100644 --- a/src/lib/pubkey/ed25519/sc_muladd.cpp +++ b/src/lib/pubkey/ed25519/sc_muladd.cpp @@ -184,38 +184,38 @@ void sc_muladd(uint8_t* s, const uint8_t* a, const uint8_t* b, const uint8_t* c) carry0<21>(s9, s10); carry0<21>(s10, s11); - s[0] = s0 >> 0; - s[1] = s0 >> 8; - s[2] = (s0 >> 16) | (s1 << 5); - s[3] = s1 >> 3; - s[4] = s1 >> 11; - s[5] = (s1 >> 19) | (s2 << 2); - s[6] = s2 >> 6; - s[7] = (s2 >> 14) | (s3 << 7); - s[8] = s3 >> 1; - s[9] = s3 >> 9; - s[10] = (s3 >> 17) | (s4 << 4); - s[11] = s4 >> 4; - s[12] = s4 >> 12; - s[13] = (s4 >> 20) | (s5 << 1); - s[14] = s5 >> 7; - s[15] = (s5 >> 15) | (s6 << 6); - s[16] = s6 >> 2; - s[17] = s6 >> 10; - s[18] = (s6 >> 18) | (s7 << 3); - s[19] = s7 >> 5; - s[20] = s7 >> 13; - s[21] = s8 >> 0; - s[22] = s8 >> 8; - s[23] = (s8 >> 16) | (s9 << 5); - s[24] = s9 >> 3; - s[25] = s9 >> 11; - s[26] = (s9 >> 19) | (s10 << 2); - s[27] = s10 >> 6; - s[28] = (s10 >> 14) | (s11 << 7); - s[29] = s11 >> 1; - s[30] = s11 >> 9; - s[31] = s11 >> 17; + s[0] = static_cast<uint8_t>(s0 >> 0); + s[1] = static_cast<uint8_t>(s0 >> 8); + s[2] = static_cast<uint8_t>((s0 >> 16) | (s1 << 5)); + s[3] = static_cast<uint8_t>(s1 >> 3); + s[4] = static_cast<uint8_t>(s1 >> 11); + s[5] = static_cast<uint8_t>((s1 >> 19) | (s2 << 2)); + s[6] = static_cast<uint8_t>(s2 >> 6); + s[7] = static_cast<uint8_t>((s2 >> 14) | (s3 << 7)); + s[8] = static_cast<uint8_t>(s3 >> 1); + s[9] = static_cast<uint8_t>(s3 >> 9); + s[10] = static_cast<uint8_t>((s3 >> 17) | (s4 << 4)); + s[11] = static_cast<uint8_t>(s4 >> 4); + s[12] = static_cast<uint8_t>(s4 >> 12); + s[13] = static_cast<uint8_t>((s4 >> 20) | (s5 << 1)); + s[14] = static_cast<uint8_t>(s5 >> 7); + s[15] = static_cast<uint8_t>((s5 >> 15) | (s6 << 6)); + s[16] = static_cast<uint8_t>(s6 >> 2); + s[17] = static_cast<uint8_t>(s6 >> 10); + s[18] = static_cast<uint8_t>((s6 >> 18) | (s7 << 3)); + s[19] = static_cast<uint8_t>(s7 >> 5); + s[20] = static_cast<uint8_t>(s7 >> 13); + s[21] = static_cast<uint8_t>(s8 >> 0); + s[22] = static_cast<uint8_t>(s8 >> 8); + s[23] = static_cast<uint8_t>((s8 >> 16) | (s9 << 5)); + s[24] = static_cast<uint8_t>(s9 >> 3); + s[25] = static_cast<uint8_t>(s9 >> 11); + s[26] = static_cast<uint8_t>((s9 >> 19) | (s10 << 2)); + s[27] = static_cast<uint8_t>(s10 >> 6); + s[28] = static_cast<uint8_t>((s10 >> 14) | (s11 << 7)); + s[29] = static_cast<uint8_t>(s11 >> 1); + s[30] = static_cast<uint8_t>(s11 >> 9); + s[31] = static_cast<uint8_t>(s11 >> 17); } } diff --git a/src/lib/pubkey/ed25519/sc_reduce.cpp b/src/lib/pubkey/ed25519/sc_reduce.cpp index 250e603e4..c69dd5ecc 100644 --- a/src/lib/pubkey/ed25519/sc_reduce.cpp +++ b/src/lib/pubkey/ed25519/sc_reduce.cpp @@ -122,38 +122,38 @@ void sc_reduce(uint8_t* s) carry0<21>(s10, s11); carry0<21>(s11, s12); - s[0] = s0 >> 0; - s[1] = s0 >> 8; - s[2] = (s0 >> 16) | (s1 << 5); - s[3] = s1 >> 3; - s[4] = s1 >> 11; - s[5] = (s1 >> 19) | (s2 << 2); - s[6] = s2 >> 6; - s[7] = (s2 >> 14) | (s3 << 7); - s[8] = s3 >> 1; - s[9] = s3 >> 9; - s[10] = (s3 >> 17) | (s4 << 4); - s[11] = s4 >> 4; - s[12] = s4 >> 12; - s[13] = (s4 >> 20) | (s5 << 1); - s[14] = s5 >> 7; - s[15] = (s5 >> 15) | (s6 << 6); - s[16] = s6 >> 2; - s[17] = s6 >> 10; - s[18] = (s6 >> 18) | (s7 << 3); - s[19] = s7 >> 5; - s[20] = s7 >> 13; - s[21] = s8 >> 0; - s[22] = s8 >> 8; - s[23] = (s8 >> 16) | (s9 << 5); - s[24] = s9 >> 3; - s[25] = s9 >> 11; - s[26] = (s9 >> 19) | (s10 << 2); - s[27] = s10 >> 6; - s[28] = (s10 >> 14) | (s11 << 7); - s[29] = s11 >> 1; - s[30] = s11 >> 9; - s[31] = s11 >> 17; + s[0] = static_cast<uint8_t>(s0 >> 0); + s[1] = static_cast<uint8_t>(s0 >> 8); + s[2] = static_cast<uint8_t>((s0 >> 16) | (s1 << 5)); + s[3] = static_cast<uint8_t>(s1 >> 3); + s[4] = static_cast<uint8_t>(s1 >> 11); + s[5] = static_cast<uint8_t>((s1 >> 19) | (s2 << 2)); + s[6] = static_cast<uint8_t>(s2 >> 6); + s[7] = static_cast<uint8_t>((s2 >> 14) | (s3 << 7)); + s[8] = static_cast<uint8_t>(s3 >> 1); + s[9] = static_cast<uint8_t>(s3 >> 9); + s[10] = static_cast<uint8_t>((s3 >> 17) | (s4 << 4)); + s[11] = static_cast<uint8_t>(s4 >> 4); + s[12] = static_cast<uint8_t>(s4 >> 12); + s[13] = static_cast<uint8_t>((s4 >> 20) | (s5 << 1)); + s[14] = static_cast<uint8_t>(s5 >> 7); + s[15] = static_cast<uint8_t>((s5 >> 15) | (s6 << 6)); + s[16] = static_cast<uint8_t>(s6 >> 2); + s[17] = static_cast<uint8_t>(s6 >> 10); + s[18] = static_cast<uint8_t>((s6 >> 18) | (s7 << 3)); + s[19] = static_cast<uint8_t>(s7 >> 5); + s[20] = static_cast<uint8_t>(s7 >> 13); + s[21] = static_cast<uint8_t>(s8 >> 0); + s[22] = static_cast<uint8_t>(s8 >> 8); + s[23] = static_cast<uint8_t>((s8 >> 16) | (s9 << 5)); + s[24] = static_cast<uint8_t>(s9 >> 3); + s[25] = static_cast<uint8_t>(s9 >> 11); + s[26] = static_cast<uint8_t>((s9 >> 19) | (s10 << 2)); + s[27] = static_cast<uint8_t>(s10 >> 6); + s[28] = static_cast<uint8_t>((s10 >> 14) | (s11 << 7)); + s[29] = static_cast<uint8_t>(s11 >> 1); + s[30] = static_cast<uint8_t>(s11 >> 9); + s[31] = static_cast<uint8_t>(s11 >> 17); } } diff --git a/src/lib/pubkey/mce/code_based_key_gen.cpp b/src/lib/pubkey/mce/code_based_key_gen.cpp index b655b543b..7ddc45655 100644 --- a/src/lib/pubkey/mce/code_based_key_gen.cpp +++ b/src/lib/pubkey/mce/code_based_key_gen.cpp @@ -199,7 +199,7 @@ std::unique_ptr<binary_matrix> generate_R(std::vector<gf2m> &L, polyn_gf2m* g, s } for (i = 0; i < code_length; ++i) { - L[i] = Laux[i]; + L[i] = static_cast<gf2m>(Laux[i]); } return result; } diff --git a/src/lib/pubkey/newhope/newhope.cpp b/src/lib/pubkey/newhope/newhope.cpp index b5d841144..1c6a841d5 100644 --- a/src/lib/pubkey/newhope/newhope.cpp +++ b/src/lib/pubkey/newhope/newhope.cpp @@ -63,7 +63,7 @@ inline void ntt(uint16_t* a, const uint16_t* omega) for(size_t i = 0; i < 10; i+=2) { // Even level - size_t distance = (1<<i); + size_t distance = (1ULL << i); for(size_t start = 0; start < distance; start++) { size_t jTwiddle = 0; @@ -138,12 +138,12 @@ inline void poly_tobytes(uint8_t* r, const poly* p) t3 = m ^ ((t3^m)&c); // <Make sure that coefficients are in [0,q] r[7*i+0] = t0 & 0xff; - r[7*i+1] = (t0 >> 8) | (t1 << 6); - r[7*i+2] = (t1 >> 2); - r[7*i+3] = (t1 >> 10) | (t2 << 4); - r[7*i+4] = (t2 >> 4); - r[7*i+5] = (t2 >> 12) | (t3 << 2); - r[7*i+6] = (t3 >> 6); + r[7*i+1] = static_cast<uint8_t>((t0 >> 8) | (t1 << 6)); + r[7*i+2] = static_cast<uint8_t>((t1 >> 2)); + r[7*i+3] = static_cast<uint8_t>((t1 >> 10) | (t2 << 4)); + r[7*i+4] = static_cast<uint8_t>((t2 >> 4)); + r[7*i+5] = static_cast<uint8_t>((t2 >> 12) | (t3 << 2)); + r[7*i+6] = static_cast<uint8_t>((t3 >> 6)); } } @@ -163,7 +163,7 @@ inline void poly_getnoise(Botan::RandomNumberGenerator& rng, poly* r) } const uint32_t a = ((d >> 8) & 0xff) + (d & 0xff); const uint32_t b = (d >> 24) + ((d >> 16) & 0xff); - r->coeffs[i] = a + PARAM_Q - b; + r->coeffs[i] = static_cast<uint16_t>(a + PARAM_Q - b); } } diff --git a/src/lib/pubkey/xmss/xmss_common_ops.cpp b/src/lib/pubkey/xmss/xmss_common_ops.cpp index 7b1ed057b..305f6dfe0 100644 --- a/src/lib/pubkey/xmss/xmss_common_ops.cpp +++ b/src/lib/pubkey/xmss/xmss_common_ops.cpp @@ -56,7 +56,7 @@ XMSS_Common_Ops::create_l_tree(secure_vector<uint8_t>& result, { for(size_t i = 0; i < l >> 1; i++) { - adrs.set_tree_index(i); + adrs.set_tree_index(static_cast<uint32_t>(i)); randomize_tree_hash(pk[i], pk[2 * i], pk[2 * i + 1], adrs, seed, hash); } if(l & 0x01) diff --git a/src/lib/pubkey/xmss/xmss_signature_operation.cpp b/src/lib/pubkey/xmss/xmss_signature_operation.cpp index 8c53cd924..f7a9079a4 100644 --- a/src/lib/pubkey/xmss/xmss_signature_operation.cpp +++ b/src/lib/pubkey/xmss/xmss_signature_operation.cpp @@ -69,8 +69,8 @@ XMSS_Signature_Operation::build_auth_path(XMSS_PrivateKey& priv_key, for(size_t j = 0; j < m_xmss_params.tree_height(); j++) { - size_t k = (m_leaf_idx / (1 << j)) ^ 0x01; - auth_path[j] = priv_key.tree_hash(k * (1 << j), j, adrs); + size_t k = (m_leaf_idx / (1ULL << j)) ^ 0x01; + auth_path[j] = priv_key.tree_hash(k * (1ULL << j), j, adrs); } return auth_path; diff --git a/src/lib/stream/ctr/ctr.cpp b/src/lib/stream/ctr/ctr.cpp index 22cfade9b..219d8042c 100644 --- a/src/lib/stream/ctr/ctr.cpp +++ b/src/lib/stream/ctr/ctr.cpp @@ -142,7 +142,7 @@ void CTR_BE::add_counter(const uint64_t counter) if(ctr_size == 4) { size_t off = (BS - 4); - uint32_t low32 = counter + load_be<uint32_t>(&m_counter[off], 0); + uint32_t low32 = static_cast<uint32_t>(counter + load_be<uint32_t>(&m_counter[off], 0)); for(size_t i = 0; i != ctr_blocks; ++i) { @@ -217,7 +217,7 @@ void CTR_BE::seek(uint64_t offset) for(size_t i = 1; i != m_ctr_blocks; ++i) { copy_mem(&m_counter[i*BS], &m_counter[0], BS); - uint32_t c = low32 + i; + const uint32_t c = static_cast<uint32_t>(low32 + i); store_be(c, &m_counter[(BS-4)+i*BS]); } } diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp index e77de9c5e..c5e6f2831 100644 --- a/src/lib/tls/tls_extensions.cpp +++ b/src/lib/tls/tls_extensions.cpp @@ -97,7 +97,7 @@ std::vector<uint8_t> Extensions::serialize() const if(extn.second->empty()) continue; - const uint16_t extn_code = extn.second->type(); + const uint16_t extn_code = static_cast<uint16_t>(extn.second->type()); std::vector<uint8_t> extn_val = extn.second->serialize(); @@ -404,9 +404,11 @@ Supported_Point_Formats::Supported_Point_Formats(TLS_Data_Reader& reader, std::vector<uint8_t> Signature_Algorithms::serialize() const { + BOTAN_ASSERT(m_schemes.size() < 256, "Too many signature schemes"); + std::vector<uint8_t> buf; - const uint16_t len = m_schemes.size() * 2; + const uint16_t len = static_cast<uint16_t>(m_schemes.size() * 2); buf.push_back(get_byte(0, len)); buf.push_back(get_byte(1, len)); diff --git a/src/lib/x509/x509cert.cpp b/src/lib/x509/x509cert.cpp index 9ed521f16..5bc04a9a2 100644 --- a/src/lib/x509/x509cert.cpp +++ b/src/lib/x509/x509cert.cpp @@ -343,7 +343,7 @@ const X509_Certificate_Data& X509_Certificate::data() const uint32_t X509_Certificate::x509_version() const { - return data().m_version; + return static_cast<uint32_t>(data().m_version); } bool X509_Certificate::is_self_signed() const @@ -447,7 +447,7 @@ bool X509_Certificate::is_CA_cert() const uint32_t X509_Certificate::path_limit() const { - return data().m_path_len_constraint; + return static_cast<uint32_t>(data().m_path_len_constraint); } Key_Constraints X509_Certificate::constraints() const |