Skip to content

Commit

Permalink
Fix for decryption
Browse files Browse the repository at this point in the history
Decryption was failing when DPL & AutoAck disabled. Fixed.
- Also fixed potential buffer overruns
  • Loading branch information
TMRh20 committed Nov 9, 2024
1 parent 2cff259 commit c65a710
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/nrf_to_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit c65a710

Please sign in to comment.