aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-12-06 11:03:20 -0500
committerJack Lloyd <[email protected]>2019-12-06 11:11:55 -0500
commit3f46301b68d9160931de620a03e956065fef8927 (patch)
tree37b6efe17752b923dfd8feade3a4c9c4132eb0f3
parentecb092d18aa6c87814bb63748d104910f4c27d6c (diff)
Fix MSVC warnings in XMSS
-rw-r--r--src/lib/pubkey/xmss/xmss_privatekey.cpp16
-rw-r--r--src/lib/pubkey/xmss/xmss_signature_operation.cpp2
-rw-r--r--src/lib/pubkey/xmss/xmss_signature_operation.h2
-rw-r--r--src/lib/pubkey/xmss/xmss_verification_operation.cpp11
-rw-r--r--src/lib/pubkey/xmss/xmss_wots_privatekey.cpp4
-rw-r--r--src/lib/pubkey/xmss/xmss_wots_publickey.cpp4
6 files changed, 20 insertions, 19 deletions
diff --git a/src/lib/pubkey/xmss/xmss_privatekey.cpp b/src/lib/pubkey/xmss/xmss_privatekey.cpp
index 72bb0c06f..e9363bba6 100644
--- a/src/lib/pubkey/xmss/xmss_privatekey.cpp
+++ b/src/lib/pubkey/xmss/xmss_privatekey.cpp
@@ -117,7 +117,7 @@ XMSS_PrivateKey::tree_hash(size_t start_idx,
XMSS_Address& adrs)
{
BOTAN_ASSERT_NOMSG(target_node_height <= 30);
- BOTAN_ASSERT((start_idx % (1 << target_node_height)) == 0,
+ BOTAN_ASSERT((start_idx % (static_cast<size_t>(1) << target_node_height)) == 0,
"Start index must be divisible by 2^{target node height}.");
#if defined(BOTAN_HAS_THREAD_UTILS)
@@ -184,13 +184,13 @@ XMSS_PrivateKey::tree_hash(size_t start_idx,
while(level-- > 1)
{
std::vector<secure_vector<uint8_t>> ro_nodes(
- nodes.begin(), nodes.begin() + (1 << (level+1)));
+ nodes.begin(), nodes.begin() + (static_cast<size_t>(1) << (level+1)));
- for(size_t i = 0; i < (1U << level); i++)
+ for(size_t i = 0; i < (static_cast<size_t>(1) << level); i++)
{
BOTAN_ASSERT_NOMSG(xmss_hash.size() > i);
- node_addresses[i].set_tree_height(target_node_height - (level + 1));
+ node_addresses[i].set_tree_height(static_cast<uint32_t>(target_node_height - (level + 1)));
node_addresses[i].set_tree_index(
(node_addresses[2 * i + 1].get_tree_index() - 1) >> 1);
using rnd_tree_hash_fn_t =
@@ -222,7 +222,7 @@ XMSS_PrivateKey::tree_hash(size_t start_idx,
}
// Avoid creation an extra thread to calculate root node.
- node_addresses[0].set_tree_height(target_node_height - 1);
+ node_addresses[0].set_tree_height(static_cast<uint32_t>(target_node_height - 1));
node_addresses[0].set_tree_index(
(node_addresses[1].get_tree_index() - 1) >> 1);
randomize_tree_hash(nodes[0],
@@ -264,7 +264,7 @@ XMSS_PrivateKey::tree_hash_subtree(secure_vector<uint8_t>& result,
for(size_t i = start_idx; i < last_idx; i++)
{
adrs.set_type(XMSS_Address::Type::OTS_Hash_Address);
- adrs.set_ots_address(i);
+ adrs.set_ots_address(static_cast<uint32_t>(i));
this->wots_private_key().generate_public_key(
pk,
// getWOTS_SK(SK, s + i), reference implementation uses adrs
@@ -273,13 +273,13 @@ XMSS_PrivateKey::tree_hash_subtree(secure_vector<uint8_t>& result,
adrs,
hash);
adrs.set_type(XMSS_Address::Type::LTree_Address);
- adrs.set_ltree_address(i);
+ adrs.set_ltree_address(static_cast<uint32_t>(i));
create_l_tree(nodes[level], pk, adrs, seed, hash);
node_levels[level] = 0;
adrs.set_type(XMSS_Address::Type::Hash_Tree_Address);
adrs.set_tree_height(0);
- adrs.set_tree_index(i);
+ adrs.set_tree_index(static_cast<uint32_t>(i));
while(level > 0 && node_levels[level] ==
node_levels[level - 1])
diff --git a/src/lib/pubkey/xmss/xmss_signature_operation.cpp b/src/lib/pubkey/xmss/xmss_signature_operation.cpp
index 6402ffac4..38659a88b 100644
--- a/src/lib/pubkey/xmss/xmss_signature_operation.cpp
+++ b/src/lib/pubkey/xmss/xmss_signature_operation.cpp
@@ -100,7 +100,7 @@ void XMSS_Signature_Operation::initialize()
secure_vector<uint8_t> index_bytes;
// reserve leaf index so it can not be reused in by another signature
// operation using the same private key.
- m_leaf_idx = m_priv_key.reserve_unused_leaf_index();
+ m_leaf_idx = static_cast<uint32_t>(m_priv_key.reserve_unused_leaf_index());
// write prefix for message hashing into buffer.
XMSS_Tools::concat(index_bytes, m_leaf_idx, 32);
diff --git a/src/lib/pubkey/xmss/xmss_signature_operation.h b/src/lib/pubkey/xmss/xmss_signature_operation.h
index c279faffd..bba860602 100644
--- a/src/lib/pubkey/xmss/xmss_signature_operation.h
+++ b/src/lib/pubkey/xmss/xmss_signature_operation.h
@@ -84,7 +84,7 @@ class XMSS_Signature_Operation final : public virtual PK_Ops::Signature,
XMSS_PrivateKey m_priv_key;
secure_vector<uint8_t> m_randomness;
- size_t m_leaf_idx;
+ uint32_t m_leaf_idx;
bool m_is_initialized;
};
diff --git a/src/lib/pubkey/xmss/xmss_verification_operation.cpp b/src/lib/pubkey/xmss/xmss_verification_operation.cpp
index 2eacc19fd..a38f7f63c 100644
--- a/src/lib/pubkey/xmss/xmss_verification_operation.cpp
+++ b/src/lib/pubkey/xmss/xmss_verification_operation.cpp
@@ -26,8 +26,9 @@ XMSS_Verification_Operation::root_from_signature(const XMSS_Signature& sig,
XMSS_Address& adrs,
const secure_vector<uint8_t>& seed)
{
+ const uint32_t next_index = static_cast<uint32_t>(sig.unused_leaf_index());
adrs.set_type(XMSS_Address::Type::OTS_Hash_Address);
- adrs.set_ots_address(sig.unused_leaf_index());
+ adrs.set_ots_address(next_index);
XMSS_WOTS_PublicKey pub_key_ots(m_pub_key.wots_parameters().oid(),
msg,
@@ -36,18 +37,18 @@ XMSS_Verification_Operation::root_from_signature(const XMSS_Signature& sig,
seed);
adrs.set_type(XMSS_Address::Type::LTree_Address);
- adrs.set_ltree_address(sig.unused_leaf_index());
+ adrs.set_ltree_address(next_index);
std::array<secure_vector<uint8_t>, 2> node;
create_l_tree(node[0], pub_key_ots, adrs, seed);
adrs.set_type(XMSS_Address::Type::Hash_Tree_Address);
- adrs.set_tree_index(sig.unused_leaf_index());
+ adrs.set_tree_index(next_index);
for(size_t k = 0; k < m_xmss_params.tree_height(); k++)
{
- adrs.set_tree_height(k);
- if(((sig.unused_leaf_index() / (1 << k)) & 0x01) == 0)
+ adrs.set_tree_height(static_cast<uint32_t>(k));
+ if(((next_index / (static_cast<size_t>(1) << k)) & 0x01) == 0)
{
adrs.set_tree_index(adrs.get_tree_index() >> 1);
randomize_tree_hash(node[1],
diff --git a/src/lib/pubkey/xmss/xmss_wots_privatekey.cpp b/src/lib/pubkey/xmss/xmss_wots_privatekey.cpp
index 5b48d2d4d..d3c00f765 100644
--- a/src/lib/pubkey/xmss/xmss_wots_privatekey.cpp
+++ b/src/lib/pubkey/xmss/xmss_wots_privatekey.cpp
@@ -50,7 +50,7 @@ XMSS_WOTS_PrivateKey::generate_public_key(XMSS_WOTS_PublicKey& pub_key,
pub_key.set_key_data(std::move(in_key_data));
for(size_t i = 0; i < m_wots_params.len(); i++)
{
- adrs.set_chain_address(i);
+ adrs.set_chain_address(static_cast<uint32_t>(i));
chain(pub_key[i], 0, m_wots_params.wots_parameter() - 1, adrs,
public_seed(), hash);
}
@@ -72,7 +72,7 @@ XMSS_WOTS_PrivateKey::sign(const secure_vector<uint8_t>& msg,
for(size_t i = 0; i < m_wots_params.len(); i++)
{
- adrs.set_chain_address(i);
+ adrs.set_chain_address(static_cast<uint32_t>(i));
chain(sig[i], 0 , msg_digest[i], adrs, m_public_seed, hash);
}
diff --git a/src/lib/pubkey/xmss/xmss_wots_publickey.cpp b/src/lib/pubkey/xmss/xmss_wots_publickey.cpp
index a7a445963..667c8574a 100644
--- a/src/lib/pubkey/xmss/xmss_wots_publickey.cpp
+++ b/src/lib/pubkey/xmss/xmss_wots_publickey.cpp
@@ -26,7 +26,7 @@ XMSS_WOTS_PublicKey::chain(secure_vector<uint8_t>& result,
i < (start_idx + steps) && i < m_wots_params.wots_parameter();
i++)
{
- adrs.set_hash_address(i);
+ adrs.set_hash_address(static_cast<uint32_t>(i));
//Calculate tmp XOR bitmask
adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Mask_Mode);
@@ -58,7 +58,7 @@ XMSS_WOTS_PublicKey::pub_key_from_signature(const secure_vector<uint8_t>& msg,
for(size_t i = 0; i < m_wots_params.len(); i++)
{
- adrs.set_chain_address(i);
+ adrs.set_chain_address(static_cast<uint32_t>(i));
chain(result[i],
msg_digest[i],
m_wots_params.wots_parameter() - 1 - msg_digest[i],