diff --git a/src/protocol/CryptionHandler.cpp b/src/protocol/CryptionHandler.cpp index 18c6e1c..1cd73f6 100644 --- a/src/protocol/CryptionHandler.cpp +++ b/src/protocol/CryptionHandler.cpp @@ -108,7 +108,7 @@ void _fe_neg(fe h, const fe f) { h[9] = h9; } -inline std::string keyMul(const uint8_t* publicKey /* compressed */, const uint8_t* privateKey /* uncompressed */, bool negate){ +inline void keyMul(uint8_t* target_buffer, const uint8_t* publicKey /* compressed */, const uint8_t* privateKey /* uncompressed */, bool negate){ ge_p3 keyA{}; ge_p2 result{}; @@ -119,9 +119,7 @@ inline std::string keyMul(const uint8_t* publicKey /* compressed */, const uint8 } ge_scalarmult_vartime(&result, privateKey, &keyA); - char buffer[32]; - ge_tobytes((uint8_t*) buffer, &result); - return string(buffer, 32); + ge_tobytes(target_buffer, &result); } bool CryptionHandler::setupSharedSecretNew(const std::string &alpha, const std::string &beta, const char* privateKey /* uncompressed */, const char* publicKey /* compressed */) { @@ -132,7 +130,7 @@ bool CryptionHandler::setupSharedSecretNew(const std::string &alpha, const std:: string sharedIv; shared.resize(32, '\0'); sharedIv.resize(64, '\0'); - shared = keyMul(reinterpret_cast(publicKey), reinterpret_cast(privateKey), true); //Remote key get negated + keyMul((uint8_t*) shared.data(), reinterpret_cast(publicKey), reinterpret_cast(privateKey), true); //Remote key get negated sharedIv = digest::sha512(shared); auto xor_key = alpha + beta;