Skip to content

Commit 6eeadee

Browse files
committed
Refactor
1 parent 77f380f commit 6eeadee

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

include/hal/radio_task.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class RadioTask {
8080
std::shared_ptr<MODULE_NAME> radioModule_;
8181
std::shared_ptr<AudioTask> audioTask_;
8282

83-
uint8_t iv_[CfgIvSize];
8483
std::shared_ptr<ChaChaPoly> cipher_;
8584

8685
static TaskHandle_t loraTaskHandle_;

src/hal/radio_task.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void RadioTask::rigTask()
176176
rigTaskStartReceive();
177177

178178
byte *packetBuf = new byte[CfgRadioPacketBufLen];
179-
byte *tmpBuf = new byte[CfgRadioPacketBufLen + sizeof(iv_) + sizeof(config_->AudioPrivacyData_)];
179+
byte *tmpBuf = new byte[CfgRadioPacketBufLen + CfgIvSize + sizeof(config_->AudioPrivacyData_)];
180180

181181
while (isRunning_) {
182182
uint32_t cmdBits = 0;
@@ -310,17 +310,15 @@ void RadioTask::encryptPacket(byte *inBuf, byte *outBuf, int inBufSize, int& out
310310
// add local auth data into the cipher
311311
cipher_->addAuthData(config_->AudioPrivacyData_, CfgAuthDataSize);
312312
// generate iv and include it into payload head
313-
generateIv(outBuf);
314-
cipher_->setIV(iv_, CfgIvSize);
313+
for (int i = 0; i < CfgIvSize; i++) {
314+
outBuf[i] = random(255);
315+
}
316+
cipher_->setIV(outBuf, CfgIvSize);
315317
// encrypt
316318
cipher_->encrypt(outBuf + CfgIvSize, inBuf, inBufSize);
317319
curOutBufSize += CfgIvSize;
318320
// generate auth tag and include it into payload tail
319-
byte authTag[CfgAuthDataSize];
320-
cipher_->computeTag(authTag, CfgAuthDataSize);
321-
for (int i = 0; i < CfgAuthDataSize; i++) {
322-
outBuf[curOutBufSize + i] = authTag[i];
323-
}
321+
cipher_->computeTag(outBuf + curOutBufSize, CfgAuthDataSize);
324322
curOutBufSize += CfgAuthDataSize;
325323
outBufSize = curOutBufSize;
326324
}
@@ -339,12 +337,4 @@ bool RadioTask::decryptPacket(byte *inBuf, byte *outBuf, int inBufSize, int& out
339337
return cipher_->checkTag(inBuf + CfgIvSize + curOutBufSize, CfgAuthDataSize);
340338
}
341339

342-
void RadioTask::generateIv(byte *tmpBuf)
343-
{
344-
for (int i = 0; i < sizeof(iv_); i++) {
345-
iv_[i] = random(255);
346-
tmpBuf[i] = iv_[i];
347-
}
348-
}
349-
350340
} // LoraDv

0 commit comments

Comments
 (0)