aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-01-02 10:42:11 -0500
committerJack Lloyd <[email protected]>2018-01-02 10:42:11 -0500
commit8326a481c1c7ae6ce18db8b4af9f413bd8435c3e (patch)
tree8210b7428915f3d485c260e6c679bd15a2082988 /src
parent0b957292b1c854a12356503d5b5c13e540101843 (diff)
Cleanup ECIES test
And avoid warnings from Sonar about adding booleans
Diffstat (limited to 'src')
-rw-r--r--src/lib/pubkey/ecies/ecies.cpp2
-rw-r--r--src/tests/test_ecies.cpp27
2 files changed, 11 insertions, 18 deletions
diff --git a/src/lib/pubkey/ecies/ecies.cpp b/src/lib/pubkey/ecies/ecies.cpp
index 39eb08afe..e2d574dcf 100644
--- a/src/lib/pubkey/ecies/ecies.cpp
+++ b/src/lib/pubkey/ecies/ecies.cpp
@@ -194,7 +194,7 @@ ECIES_System_Params::ECIES_System_Params(const EC_Group& domain, const std::stri
m_mac_keylen(mac_key_len)
{
// ISO 18033: "At most one of CofactorMode, OldCofactorMode, and CheckMode may be 1."
- if(cofactor_mode() + old_cofactor_mode() + check_mode() > 1)
+ if(size_t(cofactor_mode()) + size_t(old_cofactor_mode()) + size_t(check_mode()) > 1)
{
throw Invalid_Argument("ECIES: only one of cofactor_mode, old_cofactor_mode and check_mode can be set");
}
diff --git a/src/tests/test_ecies.cpp b/src/tests/test_ecies.cpp
index 6a4bcfeb0..5c5af0a41 100644
--- a/src/tests/test_ecies.cpp
+++ b/src/tests/test_ecies.cpp
@@ -150,40 +150,33 @@ class ECIES_ISO_Tests final : public Text_Based_Test
result.test_eq("derived secret key", secret_key.bits_of(), k);
// test encryption / decryption
- for(int i_cofactor_mode = 0; i_cofactor_mode < 2; ++i_cofactor_mode)
+
+ for(auto comp_type : { Botan::PointGFp::UNCOMPRESSED, Botan::PointGFp::COMPRESSED, Botan::PointGFp::HYBRID })
{
- for(int i_single_hash_mode = 0; i_single_hash_mode < 2; ++i_single_hash_mode)
+ for(bool cofactor_mode : { true, false })
{
- for(int i_old_cofactor_mode = 0; i_old_cofactor_mode < 2; ++i_old_cofactor_mode)
+ for(bool single_hash_mode : { true, false })
{
- for(int i_check_mode = 0; i_check_mode < 2; ++i_check_mode)
+ for(bool old_cofactor_mode : { true, false })
{
- for(int i_compression_type = 0; i_compression_type < 3; ++i_compression_type)
+ for(bool check_mode : { true, false })
{
- const bool cofactor_mode = i_cofactor_mode != 0;
- const bool single_hash_mode = i_single_hash_mode != 0;
- const bool old_cofactor_mode = i_old_cofactor_mode != 0;
- const bool check_mode = i_check_mode != 0;
- const Botan::PointGFp::Compression_Type gen_compression_type =
- static_cast<Botan::PointGFp::Compression_Type>(i_compression_type);
-
Flags flags = ecies_flags(cofactor_mode, old_cofactor_mode, check_mode, single_hash_mode);
- if(cofactor_mode + check_mode + old_cofactor_mode > 1)
+ if(size_t(cofactor_mode) + size_t(check_mode) + size_t(old_cofactor_mode) > 1)
{
auto onThrow = [&]()
{
- Botan::ECIES_System_Params(
- eph_private_key.domain(),
+ Botan::ECIES_System_Params(eph_private_key.domain(),
"KDF2(SHA-1)", "AES-256/CBC", 32, "HMAC(SHA-1)", 20,
- gen_compression_type, flags);
+ comp_type, flags);
};
result.test_throws("throw on invalid ECIES_Flags", onThrow);
continue;
}
Botan::ECIES_System_Params ecies_params(eph_private_key.domain(), "KDF2(SHA-1)", "AES-256/CBC",
- 32, "HMAC(SHA-1)", 20, gen_compression_type, flags);
+ 32, "HMAC(SHA-1)", 20, comp_type, flags);
check_encrypt_decrypt(result, eph_private_key, other_private_key, ecies_params, 16);
}
}