From c65a71019431371ec2a0c5d2a0698984dec01264 Mon Sep 17 00:00:00 2001 From: TMRh20 Date: Sat, 9 Nov 2024 08:19:52 -0600 Subject: [PATCH] Fix for decryption Decryption was failing when DPL & AutoAck disabled. Fixed. - Also fixed potential buffer overruns --- src/nrf_to_nrf.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nrf_to_nrf.cpp b/src/nrf_to_nrf.cpp index 6db817a..1a1abbd 100644 --- a/src/nrf_to_nrf.cpp +++ b/src/nrf_to_nrf.cpp @@ -222,8 +222,8 @@ bool nrf_to_nrf::available(uint8_t* pipe_num) if (!DPL && acksEnabled(*pipe_num) == false) { #if defined CCM_ENCRYPTION_ENABLED if (enableEncryption) { - memcpy(&rxBuffer[1], &radioData[CCM_IV_SIZE + CCM_COUNTER_SIZE], staticPayloadSize); - memcpy(ccmData.iv, &radioData[0], CCM_IV_SIZE); + memcpy(&rxBuffer[1], &radioData[CCM_IV_SIZE + CCM_COUNTER_SIZE], staticPayloadSize - CCM_MIC_SIZE - CCM_IV_SIZE - CCM_COUNTER_SIZE); + memcpy(tmpIV, &radioData[0], CCM_IV_SIZE); memcpy(&counter, &radioData[CCM_IV_SIZE], CCM_COUNTER_SIZE); } else { @@ -237,10 +237,10 @@ bool nrf_to_nrf::available(uint8_t* pipe_num) #if defined CCM_ENCRYPTION_ENABLED if (enableEncryption) { if (DPL) { - memcpy(&rxBuffer[1], &radioData[2 + CCM_IV_SIZE + CCM_COUNTER_SIZE], max(0, radioData[0] - CCM_IV_SIZE - CCM_COUNTER_SIZE)); + memcpy(&rxBuffer[1], &radioData[2 + CCM_IV_SIZE + CCM_COUNTER_SIZE], max(0, radioData[0] - CCM_IV_SIZE - CCM_COUNTER_SIZE - CCM_MIC_SIZE)); } else { - memcpy(&rxBuffer[1], &radioData[2 + CCM_IV_SIZE + CCM_COUNTER_SIZE], max(0, staticPayloadSize - CCM_IV_SIZE - CCM_COUNTER_SIZE)); + memcpy(&rxBuffer[1], &radioData[2 + CCM_IV_SIZE + CCM_COUNTER_SIZE], max(0, staticPayloadSize - CCM_IV_SIZE - CCM_COUNTER_SIZE - CCM_MIC_SIZE)); } memcpy(tmpIV, &radioData[2], CCM_IV_SIZE); memcpy(&counter, &radioData[2 + CCM_IV_SIZE], CCM_COUNTER_SIZE);