From 79bb9b94cf9d5e8760272662b9ddfe56c3107c46 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 7 Jul 2019 19:02:28 +0200 Subject: [PATCH] Finally fixed crypto library! --- src/misc/digest.h | 8 ++++++-- src/protocol/CryptionHandler.cpp | 9 ++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/misc/digest.h b/src/misc/digest.h index fee3436..150e282 100644 --- a/src/misc/digest.h +++ b/src/misc/digest.h @@ -16,14 +16,18 @@ inline std::string name(const std::string& input) { \ uint8_t result[digestLength]; \ tomcrypt::name(input.data(), input.length(), result); \ - return std::string((const char*) result, (size_t) digestLength); \ + auto _result = std::string((const char*) result, (size_t) digestLength); \ + assert(_result.length() == digestLength) \ + return _result; \ } \ \ 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, (size_t) digestLength); \ + auto _result = std::string((const char*) result, (size_t) digestLength); \ + assert(_result.length() == digestLength) \ + return _result; \ } \ \ \ diff --git a/src/protocol/CryptionHandler.cpp b/src/protocol/CryptionHandler.cpp index 300d86e..aec5063 100644 --- a/src/protocol/CryptionHandler.cpp +++ b/src/protocol/CryptionHandler.cpp @@ -208,10 +208,6 @@ bool CryptionHandler::generate_key_nonce( memcpy(&buffer[6], this->iv_struct, this->iv_struct_length); digest::sha256(buffer, buffer_length, key_cache.key_nonce); - /* - memcpy(key_cache.key, key_nonce.data(), 16); - memcpy(key_cache.nonce, key_nonce.data() + 16, 16); - */ key_cache.generation = generation; } @@ -294,7 +290,7 @@ bool CryptionHandler::decryptPacket(protocol::BasicPacket *packet, std::string & (unsigned long) header.length(), /* header length */ (const unsigned char *) data.data_ptr(), (unsigned long) data.length(), - (unsigned char *) data.data_ptr(), + (unsigned char *) target_buffer, (unsigned char *) packet->mac().data_ptr(), (unsigned long) packet->mac().length(), &success @@ -309,7 +305,7 @@ bool CryptionHandler::decryptPacket(protocol::BasicPacket *packet, std::string & return false; } - //packet->data(pipes::buffer_view{target_buffer, length}); + packet->data(pipes::buffer_view{target_buffer, length}); packet->setEncrypted(false); return true; } @@ -343,7 +339,6 @@ bool CryptionHandler::encryptPacket(protocol::BasicPacket *packet, std::string & (unsigned long) packet->header().length(), /* header length */ (uint8_t *) packet->data().data_ptr(), /* The plain text */ (unsigned long) packet->data().length(), /* Plain text length */ - // (uint8_t *) packet->data().data_ptr(), /* The result buffer */ (uint8_t *) target_buffer, /* The result buffer */ (uint8_t *) tag_buffer, (unsigned long *) &tag_length