@@ -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