Skip to content

Commit 4a2354a

Browse files
committed
Remove need for additional tag data
1 parent cfa513b commit 4a2354a

File tree

5 files changed

+8
-18
lines changed

5 files changed

+8
-18
lines changed

include/hal/radio_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class RadioTask {
5757

5858
static constexpr int CfgRadioTaskStack = 4096; // task stack size
5959
static constexpr size_t CfgIvSize = 12; // IV/nonce, initialization vector size
60-
static constexpr size_t CfgAuthDataSize = 16; // auth data size
60+
static constexpr size_t CfgAuthTagSize = 16; // auth tag size
6161

6262
private:
6363
void setupRig(long freq, long bw, int sf, int cr, int pwr, int sync, int crcBytes);

include/settings/config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class Config {
9191
// privacy
9292
bool AudioEnPriv; // enable/disable privacy
9393
byte AudioPrivacyKey_[32]; // privacy key
94-
byte AudioPrivacyData_[16]; // privacy tag
9594

9695
// battery monitor
9796
byte BatteryMonPin_; // Battery monitor adc pin

include/settings/default_config.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,4 @@
123123
#define CFG_AUDIO_PRIVACY_KEY \
124124
byte AudioPrivacyKey[32] = {0xe7,0x5c,0xf0,0x43,0x80,0xec,0x45,0x93,0xe8,0x3b,0xfb,0x72,0x22,0x40,0x19,0x57,\
125125
0x6c,0xde,0x05,0x00,0xff,0x88,0x12,0x42,0x20,0xf2,0x89,0x9d,0x7f,0x57,0xee,0xd6}
126-
#define CFG_AUDIO_PRIVACY_DATA \
127-
byte AudioPrivacyData[16] = {0x00,0x9f,0x25,0x4d,0x3d,0xd1,0x70,0x0f,0xfa,0xea,0xbd,0xc2,0xe9,0x6c,0x1c,0x40}
128-
129126
#endif // DEFAULT_CONFIG_H

src/hal/radio_task.cpp

Lines changed: 6 additions & 10 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 + CfgIvSize + sizeof(config_->AudioPrivacyData_)];
179+
byte *tmpBuf = new byte[CfgRadioPacketBufLen + CfgIvSize + CfgAuthTagSize];
180180

181181
while (isRunning_) {
182182
uint32_t cmdBits = 0;
@@ -232,7 +232,7 @@ void RadioTask::rigTaskStartTransmit()
232232
void RadioTask::rigTaskReceive(byte *packetBuf, byte *tmpBuf)
233233
{
234234
int packetSize = radioModule_->getPacketLength();
235-
if (packetSize > CfgIvSize + CfgAuthDataSize && packetSize <= CfgRadioPacketBufLen) {
235+
if (packetSize > CfgIvSize + CfgAuthTagSize && packetSize <= CfgRadioPacketBufLen) {
236236
// receive packet
237237
int state = radioModule_->readData(packetBuf, packetSize);
238238
bool isValidPacket = true;
@@ -307,31 +307,27 @@ void RadioTask::rigTaskTransmit(byte *packetBuf, byte *tmpBuf)
307307
void RadioTask::encryptPacket(byte *inBuf, byte *outBuf, int inBufSize, int& outBufSize)
308308
{
309309
int curOutBufSize = inBufSize;
310-
// add local auth data into the cipher
311-
cipher_->addAuthData(config_->AudioPrivacyData_, CfgAuthDataSize);
312310
// generate iv and include it into payload head
313311
esp_fill_random(outBuf, CfgIvSize);
314312
cipher_->setIV(outBuf, CfgIvSize);
315313
// encrypt
316314
cipher_->encrypt(outBuf + CfgIvSize, inBuf, inBufSize);
317315
curOutBufSize += CfgIvSize;
318316
// generate auth tag and include it into payload tail
319-
cipher_->computeTag(outBuf + curOutBufSize, CfgAuthDataSize);
320-
curOutBufSize += CfgAuthDataSize;
317+
cipher_->computeTag(outBuf + curOutBufSize, CfgAuthTagSize);
318+
curOutBufSize += CfgAuthTagSize;
321319
outBufSize = curOutBufSize;
322320
}
323321

324322
bool RadioTask::decryptPacket(byte *inBuf, byte *outBuf, int inBufSize, int& outBufSize)
325323
{
326-
int curOutBufSize = inBufSize - (CfgIvSize + CfgAuthDataSize);
327-
// add local auth data into the cipher
328-
cipher_->addAuthData(config_->AudioPrivacyData_, CfgAuthDataSize);
324+
int curOutBufSize = inBufSize - (CfgIvSize + CfgAuthTagSize);
329325
// set iv from the packet and decrypt
330326
cipher_->setIV(inBuf, CfgIvSize);
331327
cipher_->decrypt(outBuf, inBuf + CfgIvSize, curOutBufSize);
332328
outBufSize = curOutBufSize;
333329
// check tag validity from the received packet
334-
return cipher_->checkTag(inBuf + CfgIvSize + curOutBufSize, CfgAuthDataSize);
330+
return cipher_->checkTag(inBuf + CfgIvSize + curOutBufSize, CfgAuthTagSize);
335331
}
336332

337333
} // LoraDv

src/settings/config.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace LoraDv {
55
#define N(v) #v
66

77
CFG_AUDIO_PRIVACY_KEY;
8-
CFG_AUDIO_PRIVACY_DATA;
98

109
Config::Config()
1110
{
@@ -96,9 +95,8 @@ void Config::InitializeDefault()
9695
PmLightSleepDurationMs_ = CFG_PM_LSLEEP_DURATION_MS;
9796
PmLightSleepAwakeMs_ = CFG_PM_LSLEEP_AWAKE_MS;
9897

99-
// encryption key and auth tag data
98+
// encryption key
10099
memcpy(AudioPrivacyKey_, AudioPrivacyKey, sizeof(AudioPrivacyKey));
101-
memcpy(AudioPrivacyData_, AudioPrivacyData, sizeof(AudioPrivacyData));
102100
}
103101

104102
void Config::Reset()

0 commit comments

Comments
 (0)