From 037850d38100434563d1da9c82c7b87c71d9e0b0 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 7 Jul 2019 18:24:20 +0200 Subject: [PATCH] Updated changelog --- src/protocol/CryptionHandler.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/protocol/CryptionHandler.cpp b/src/protocol/CryptionHandler.cpp index 7250f9d..0773a3d 100644 --- a/src/protocol/CryptionHandler.cpp +++ b/src/protocol/CryptionHandler.cpp @@ -111,8 +111,23 @@ void _fe_neg(fe h, const fe f) { h[8] = h8; h[9] = h9; } +/* +inline void keyMul(uint8_t(& target_buffer)[32], const uint8_t* publicKey /* compressed */, const uint8_t* privateKey /* uncompressed */, bool negate){ + ge_p3 keyA{}; + ge_p2 result{}; -inline void keyMul(uint8_t* target_buffer, const uint8_t* publicKey /* compressed */, const uint8_t* privateKey /* uncompressed */, bool negate){ + ge_frombytes_negate_vartime(&keyA, publicKey); + if(negate) { + _fe_neg(*(fe*) &keyA.X, *(const fe*) &keyA.X); /* undo negate / + _fe_neg(*(fe*) &keyA.T, *(const fe*) &keyA.T); /* undo negate / + } + ge_scalarmult_vartime(&result, privateKey, &keyA); + + ge_tobytes(target_buffer, &result); +} +*/ + +inline std::string keyMul(const uint8_t* publicKey /* compressed */, const uint8_t* privateKey /* uncompressed */, bool negate){ ge_p3 keyA{}; ge_p2 result{}; @@ -123,9 +138,12 @@ inline void keyMul(uint8_t* target_buffer, const uint8_t* publicKey /* compresse } ge_scalarmult_vartime(&result, privateKey, &keyA); - ge_tobytes(target_buffer, &result); + char buffer[32]; + ge_tobytes((uint8_t*) buffer, &result); + return string(buffer, 32); } + bool CryptionHandler::setupSharedSecretNew(const std::string &alpha, const std::string &beta, const char* privateKey /* uncompressed */, const char* publicKey /* compressed */) { if(alpha.length() != 10 || beta.length() != 54) return false; @@ -143,7 +161,7 @@ bool CryptionHandler::setupSharedSecretNew(const std::string &alpha, const std:: shared.resize(32, '\0'); sharedIv.resize(64, '\0'); ed25519_key_exchange((uint8_t*) shared.data(), (uint8_t*) publicKey, (uint8_t*) privateKey); - keyMul(shared.data(), reinterpret_cast(publicKey), reinterpret_cast(privateKey), true); //Remote key get negated + shared = keyMul(reinterpret_cast(publicKey), reinterpret_cast(privateKey), true); //Remote key get negated sharedIv = digest::sha512(shared);