From 6256b6ef339196bc4a60e6c601c29f6e0fc7688e Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sat, 10 Feb 2024 11:32:16 +0100 Subject: [PATCH] Improve crypto primitives --- include/relay/CryptoPrimitives.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/include/relay/CryptoPrimitives.h b/include/relay/CryptoPrimitives.h index 0af5bbb..278645a 100644 --- a/include/relay/CryptoPrimitives.h +++ b/include/relay/CryptoPrimitives.h @@ -10,10 +10,18 @@ struct PrivateKey { /// @brief The size of a private key - static const int size = 32; + static constexpr int size = 32; uint8_t bytes[size]; + bool isUnset() { + for (uint8_t i = 0; i < size; i += 1) { + if (bytes[i] != 0) { + return false; + } + } + return true; + } }; /** @@ -22,10 +30,18 @@ struct PrivateKey { struct PublicKey { /// @brief The size of a public key - static const int size = 32; + static constexpr int size = 32; uint8_t bytes[size]; + bool isUnset() { + for (uint8_t i = 0; i < size; i += 1) { + if (bytes[i] != 0) { + return false; + } + } + return true; + } }; /** @@ -34,7 +50,7 @@ struct PublicKey { struct Signature { /// @brief The size of a message signature - static const int size = 64; + static constexpr int size = 64; uint8_t bytes[size];