From 6259ebd5319da687b22cdd5661fbd4e808280303 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 7 Jul 2019 14:32:17 +0200 Subject: [PATCH] Reversed stuff --- src/protocol/CryptionHandler.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/protocol/CryptionHandler.cpp b/src/protocol/CryptionHandler.cpp index 815faba..93cc135 100644 --- a/src/protocol/CryptionHandler.cpp +++ b/src/protocol/CryptionHandler.cpp @@ -305,9 +305,18 @@ bool CryptionHandler::encryptPacket(protocol::BasicPacket *packet, std::string & return false; } + size_t length = packet->data().length(); + size_t tag_length = 8; char tag_buffer[8]; + size_t target_length = 2048; + uint8_t target_buffer[2048]; + if(target_length < length) { + error = "buffer too large"; + return false; + } + int err; if((err = eax_encrypt_authenticate_memory(find_cipher("rijndael"), (uint8_t *) key, /* the key */ @@ -318,7 +327,8 @@ 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 *) packet->data().data_ptr(), /* The result buffer */ + (uint8_t *) target_buffer, /* The result buffer */ (uint8_t *) tag_buffer, (unsigned long *) &tag_length )) != CRYPT_OK){ @@ -326,7 +336,9 @@ bool CryptionHandler::encryptPacket(protocol::BasicPacket *packet, std::string & return false; } assert(tag_length == 8); - packet->mac().write(tag_buffer, tag_length); + + packet->data(pipes::buffer_view{target_buffer, length}); + packet->mac().write(tag_buffer, tag_length); packet->setEncrypted(true); return true; }