From dcfed9bb123eaf617f25bde7768d5e6bfddc306d Mon Sep 17 00:00:00 2001 From: Dario Date: Wed, 24 Jun 2020 10:18:30 +0200 Subject: [PATCH] add compare function with private key as parameter for comparing private keys in controller::user::login to skip calculating public key from private key --- src/cpp/Crypto/KeyPairEd25519.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cpp/Crypto/KeyPairEd25519.h b/src/cpp/Crypto/KeyPairEd25519.h index 839b1cfc0..15bd8a89d 100644 --- a/src/cpp/Crypto/KeyPairEd25519.h +++ b/src/cpp/Crypto/KeyPairEd25519.h @@ -11,6 +11,7 @@ * \brief: Key Pairs class for ed25519 keys, used for default gradido transactions */ + #include "sodium.h" #include "AuthenticatedEncryption.h" @@ -41,6 +42,14 @@ public: inline bool isTheSame(const unsigned char* pubkey) const { return 0 == sodium_memcmp(mSodiumPublic, pubkey, crypto_sign_PUBLICKEYBYTES); } + //! \return 0 if the same + //! \return -1 if not the same + //! \return 1 if hasn't private key + inline int isTheSame(const MemoryBin* privkey) const { + if (!mSodiumSecret) return 1; + if (privkey->size() != mSodiumSecret->size()) return -1; + return sodium_memcmp(*mSodiumSecret, *privkey, privkey->size()); + } inline bool operator == (const KeyPairEd25519& b) const { return isTheSame(b); } inline bool operator != (const KeyPairEd25519& b) const { return !isTheSame(b); }