From 63e342be8452510abb67bfe24df90a0972a4edfd Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 15 Jul 2018 12:59:58 +0100 Subject: [PATCH 1/2] crypto: move null_pkey/null_skey to the cpp file --- src/crypto/crypto.cpp | 3 +++ src/crypto/crypto.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp index f4ef751d3..36b510a5b 100644 --- a/src/crypto/crypto.cpp +++ b/src/crypto/crypto.cpp @@ -70,6 +70,9 @@ namespace crypto { #include "random.h" } + const crypto::public_key null_pkey = boost::value_initialized(); + const crypto::secret_key null_skey = boost::value_initialized(); + static inline unsigned char *operator &(ec_point &point) { return &reinterpret_cast(point); } diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index 9ea0f2ec0..492bf966e 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -277,8 +277,8 @@ namespace crypto { epee::to_hex::formatted(o, epee::as_byte_span(v)); return o; } - const static crypto::public_key null_pkey = boost::value_initialized(); - const static crypto::secret_key null_skey = boost::value_initialized(); + const extern crypto::public_key null_pkey; + const extern crypto::secret_key null_skey; } CRYPTO_MAKE_HASHABLE(public_key) From 0496c7c91abbf8ec20cc70f383868957c6f9adc9 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 20 Jul 2018 22:59:18 +0100 Subject: [PATCH 2/2] crypto: do not use boost::value_initialized to init null skey/pkey --- src/crypto/crypto.cpp | 4 ++-- src/crypto/crypto.h | 1 - tests/unit_tests/crypto.cpp | 8 ++++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp index 36b510a5b..a2db14e08 100644 --- a/src/crypto/crypto.cpp +++ b/src/crypto/crypto.cpp @@ -70,8 +70,8 @@ namespace crypto { #include "random.h" } - const crypto::public_key null_pkey = boost::value_initialized(); - const crypto::secret_key null_skey = boost::value_initialized(); + const crypto::public_key null_pkey = crypto::public_key{}; + const crypto::secret_key null_skey = crypto::secret_key{}; static inline unsigned char *operator &(ec_point &point) { return &reinterpret_cast(point); diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index 492bf966e..073707876 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp index 4bed06173..9e1680568 100644 --- a/tests/unit_tests/crypto.cpp +++ b/tests/unit_tests/crypto.cpp @@ -73,3 +73,11 @@ TEST(Crypto, Ostream) EXPECT_TRUE(is_formatted()); EXPECT_TRUE(is_formatted()); } + +TEST(Crypto, null_keys) +{ + char zero[32]; + memset(zero, 0, 32); + ASSERT_EQ(memcmp(crypto::null_skey.data, zero, 32), 0); + ASSERT_EQ(memcmp(crypto::null_pkey.data, zero, 32), 0); +}