From 96fa5dafb8f1eef8206041e01f17295e879e9210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 7 Jan 2023 13:36:02 +0100 Subject: [PATCH] fixing portduino --- .../portduino/CrossPlatformCryptoEngine.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/platform/portduino/CrossPlatformCryptoEngine.cpp b/src/platform/portduino/CrossPlatformCryptoEngine.cpp index 7bd021a42..208c60a5f 100644 --- a/src/platform/portduino/CrossPlatformCryptoEngine.cpp +++ b/src/platform/portduino/CrossPlatformCryptoEngine.cpp @@ -54,16 +54,18 @@ class CrossPlatformCryptoEngine : public CryptoEngine static uint8_t scratch[MAX_BLOCKSIZE]; //size_t nc_off = 0; - // LOG_DEBUG("ESP32 encrypt!\n"); initNonce(fromNode, packetId); - assert(numBytes <= MAX_BLOCKSIZE); - memcpy(scratch, bytes, numBytes); - memset(scratch + numBytes, 0, + if (numBytes <= MAX_BLOCKSIZE) { + memcpy(scratch, bytes, numBytes); + memset(scratch + numBytes, 0, sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it) - ctr->setIV(nonce, sizeof(nonce)); - ctr->setCounterSize(4); - ctr->encrypt(bytes, scratch, numBytes); + ctr->setIV(nonce, sizeof(nonce)); + ctr->setCounterSize(4); + ctr->encrypt(bytes, scratch, numBytes); + } else { + LOG_ERROR("Packet too large for crypto engine: %d. noop encryption!\n", numBytes); + } } }