From 8447b1d7eb70f108214b05806860ec315e979e4d Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 7 Jul 2019 14:04:06 +0200 Subject: [PATCH] Fixed ED255 library --- src/License.cpp | 18 ++++++++++++------ src/misc/digest.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/License.cpp b/src/License.cpp index 1d99c41..cbcdc8c 100644 --- a/src/License.cpp +++ b/src/License.cpp @@ -275,10 +275,18 @@ std::string LicenseChain::exportChain() { return stream.str(); } +inline void _ed25519_create_keypair(uint8_t(&public_key)[32], uint8_t(&private_key)[32]) { + uint8_t seed[32]; + ed25519_create_seed(seed); + + uint8_t buffer_private[64]; /* Because we word with SHA512 we required 64 bytes! */ + ed25519_create_keypair(public_key, buffer_private, seed); + memcpy(private_key, buffer_private, 32); +} + void LicenseChain::addIntermediateEntry() { auto entry = make_shared(); - uint8_t seed[32 * 2]; //FIXME more secure - ed25519_create_keypair(entry->key.publicKeyData, entry->key.privateKeyData, seed); + _ed25519_create_keypair(entry->key.publicKeyData, entry->key.privateKeyData); entry->key.privateKey = true; entry->_begin = system_clock::now() - hours(16); entry->_end = system_clock::now() + hours(16); @@ -289,8 +297,7 @@ void LicenseChain::addIntermediateEntry() { std::shared_ptr LicenseChain::addServerEntry(ServerLicenseType type, const std::string &issuer, uint32_t slots) { auto entry = make_shared(); - uint8_t seed[32 * 2]; //FIXME more secure - ed25519_create_keypair(entry->key.publicKeyData, entry->key.privateKeyData, seed); + _ed25519_create_keypair(entry->key.publicKeyData, entry->key.privateKeyData); entry->key.privateKey = true; entry->issuer = issuer; entry->licenseType = type; @@ -303,8 +310,7 @@ std::shared_ptr LicenseChain::addServerEntry(ServerLicenseType typ void LicenseChain::addEphemeralEntry() { auto entry = make_shared(); - uint8_t seed[32 * 2]; //FIXME more secure - ed25519_create_keypair(entry->key.publicKeyData, entry->key.privateKeyData, seed); + _ed25519_create_keypair(entry->key.publicKeyData, entry->key.privateKeyData); entry->key.privateKey = true; entry->_begin = system_clock::now() - hours(6); entry->_end = system_clock::now() + hours(6); diff --git a/src/misc/digest.h b/src/misc/digest.h index 7959b4a..cf1c57a 100644 --- a/src/misc/digest.h +++ b/src/misc/digest.h @@ -20,6 +20,7 @@ } \ \ inline std::string name(const char* input, int64_t length = -1) { \ + if(length == -1) length = strlen(input); \ uint8_t result[digestLength]; \ tomcrypt::name(input, length, result); \ return std::string((const char*) result, digestLength); \