mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add possibility to use ed25519 with only a pubkey
This commit is contained in:
parent
ae74352fc6
commit
0325a90dab
@ -6,12 +6,20 @@
|
|||||||
|
|
||||||
#include "../lib/BinHexConverter.h"
|
#include "../lib/BinHexConverter.h"
|
||||||
|
|
||||||
|
#include "Passphrase.h"
|
||||||
|
|
||||||
KeyPairEd25519::KeyPairEd25519(MemoryBin* privateKey, const unsigned char* publicKey)
|
KeyPairEd25519::KeyPairEd25519(MemoryBin* privateKey, const unsigned char* publicKey)
|
||||||
: mSodiumSecret(privateKey)
|
: mSodiumSecret(privateKey)
|
||||||
{
|
{
|
||||||
memcpy(mSodiumPublic, publicKey, crypto_sign_PUBLICKEYBYTES);
|
memcpy(mSodiumPublic, publicKey, crypto_sign_PUBLICKEYBYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeyPairEd25519::KeyPairEd25519(const unsigned char* publicKey)
|
||||||
|
: mSodiumSecret(nullptr)
|
||||||
|
{
|
||||||
|
memcpy(mSodiumPublic, publicKey, crypto_sign_PUBLICKEYBYTES);
|
||||||
|
}
|
||||||
|
|
||||||
KeyPairEd25519::KeyPairEd25519()
|
KeyPairEd25519::KeyPairEd25519()
|
||||||
: mSodiumSecret(nullptr)
|
: mSodiumSecret(nullptr)
|
||||||
{
|
{
|
||||||
@ -96,6 +104,7 @@ MemoryBin* KeyPairEd25519::sign(const MemoryBin* message)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (!message || !message->size()) return nullptr;
|
if (!message || !message->size()) return nullptr;
|
||||||
|
if (!mSodiumSecret) return nullptr;
|
||||||
auto messageSize = message->size();
|
auto messageSize = message->size();
|
||||||
auto mm = MemoryManager::getInstance();
|
auto mm = MemoryManager::getInstance();
|
||||||
auto em = ErrorManager::getInstance();
|
auto em = ErrorManager::getInstance();
|
||||||
|
|||||||
@ -11,9 +11,9 @@
|
|||||||
* \brief: Key Pairs class for ed25519 keys, used for default gradido transactions
|
* \brief: Key Pairs class for ed25519 keys, used for default gradido transactions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../SingletonManager/MemoryManager.h"
|
|
||||||
#include "sodium.h"
|
#include "sodium.h"
|
||||||
#include "Passphrase.h"
|
|
||||||
|
class Passphrase;
|
||||||
|
|
||||||
class KeyPairEd25519 : public IKeyPair
|
class KeyPairEd25519 : public IKeyPair
|
||||||
{
|
{
|
||||||
@ -21,6 +21,7 @@ public:
|
|||||||
//! \param privateKey: take ownership, release after object destruction
|
//! \param privateKey: take ownership, release after object destruction
|
||||||
//! \param publicKey: copy
|
//! \param publicKey: copy
|
||||||
KeyPairEd25519(MemoryBin* privateKey, const unsigned char* publicKey);
|
KeyPairEd25519(MemoryBin* privateKey, const unsigned char* publicKey);
|
||||||
|
KeyPairEd25519(const unsigned char* publicKey);
|
||||||
|
|
||||||
~KeyPairEd25519();
|
~KeyPairEd25519();
|
||||||
|
|
||||||
@ -33,8 +34,19 @@ public:
|
|||||||
|
|
||||||
inline const unsigned char* getPublicKey() const { return mSodiumPublic; }
|
inline const unsigned char* getPublicKey() const { return mSodiumPublic; }
|
||||||
|
|
||||||
|
inline bool isTheSame(const KeyPairEd25519& b) const {
|
||||||
|
return 0 == sodium_memcmp(mSodiumPublic, b.mSodiumPublic, crypto_sign_PUBLICKEYBYTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator == (const KeyPairEd25519& b) const { return isTheSame(b); }
|
||||||
|
inline bool operator != (const KeyPairEd25519& b) const { return !isTheSame(b); }
|
||||||
|
|
||||||
|
inline bool hasPrivateKey() const { return mSodiumSecret != nullptr; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
KeyPairEd25519();
|
KeyPairEd25519();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 64 Byte
|
// 64 Byte
|
||||||
//! \brief ed25519 libsodium private key
|
//! \brief ed25519 libsodium private key
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user