Skip to content

Commit 45aec0c

Browse files
author
Antti Kauppila
committed
Pre-cert fixes
1 parent 0c7f568 commit 45aec0c

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

features/lorawan/lorastack/mac/LoRaMacChannelPlan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ lorawan_status_t LoRaMacChannelPlan::remove_plan()
128128
continue;
129129
}
130130

131-
if (_lora_phy->remove_channel(channel_id) == false) {
131+
if (_lora_phy->remove_channel(i) == false) {
132132
return LORAWAN_STATUS_PARAMETER_INVALID;
133133
}
134134
}

features/lorawan/lorastack/mac/LoRaMacCrypto.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ int LoRaMacCrypto::compute_mic(const uint8_t *buffer, uint16_t size,
128128
}
129129

130130
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, APPKEY_KEY_LENGTH);
131-
if (0 != ret)
131+
if (0 != ret) {
132132
goto exit;
133133
}
134134

@@ -169,6 +169,7 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
169169
uint16_t i;
170170
uint8_t bufferIndex = 0;
171171
int ret = 0;
172+
uint16_t ctr = 1;
172173
uint8_t a_block[16] = {0};
173174
uint8_t s_block[16] = {0};
174175
const uint8_t *key;
@@ -183,7 +184,7 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
183184
mbedtls_aes_init(&aes_ctx);
184185

185186
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, APPKEY_KEY_LENGTH);
186-
if (0 != ret)
187+
if (0 != ret) {
187188
goto exit;
188189
}
189190

@@ -212,7 +213,8 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
212213
a_block[15] = 0x01;
213214

214215
while (size >= 16) {
215-
a_block[15]++;
216+
a_block[15] = ((ctr) & 0xFF);
217+
ctr++;
216218

217219
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
218220
s_block);
@@ -228,6 +230,7 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
228230
}
229231

230232
if (size > 0) {
233+
a_block[15] = ((ctr) & 0xFF);
231234
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
232235
s_block);
233236
if (0 != ret) {
@@ -281,7 +284,7 @@ int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *buffer, uint16_t size,
281284
}
282285

283286
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, APPKEY_KEY_LENGTH);
284-
if (0 != ret)
287+
if (0 != ret) {
285288
goto exit;
286289
}
287290

@@ -322,7 +325,7 @@ int LoRaMacCrypto::decrypt_join_frame(const uint8_t *buffer, uint16_t size,
322325
}
323326

324327
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, APPKEY_KEY_LENGTH);
325-
if (0 != ret)
328+
if (0 != ret) {
326329
goto exit;
327330
}
328331

@@ -365,22 +368,23 @@ int LoRaMacCrypto::compute_skeys_for_join_frame(const uint8_t *args, uint8_t arg
365368
nonce[0] = 0x02;
366369
memcpy(nonce + 1, args, args_size);
367370
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, _keys.app_skey);
368-
if (0 != ret)
371+
if (0 != ret) {
369372
goto exit;
373+
}
370374

371375
mbedtls_aes_free(&aes_ctx);
372376
mbedtls_aes_init(&aes_ctx);
373377

374378
ret = mbedtls_aes_setkey_enc(&aes_ctx, _keys.nwk_key, APPKEY_KEY_LENGTH);
375-
if (0 != ret)
379+
if (0 != ret) {
376380
goto exit;
377381
}
378382

379383
memset(nonce, 0, sizeof(nonce));
380384
nonce[0] = 0x01;
381385
memcpy(nonce + 1, args, args_size);
382386
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, _keys.nwk_skey);
383-
if (0 != ret)
387+
if (0 != ret) {
384388
goto exit;
385389
}
386390

@@ -392,15 +396,17 @@ int LoRaMacCrypto::compute_skeys_for_join_frame(const uint8_t *args, uint8_t arg
392396
nonce[0] = 0x03;
393397
memcpy(nonce + 1, args, args_size);
394398
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, _keys.snwk_sintkey);
395-
if (0 != ret)
399+
if (0 != ret) {
396400
goto exit;
401+
}
397402

398403
memset(nonce, 0, sizeof(nonce));
399404
nonce[0] = 0x04;
400405
memcpy(nonce + 1, args, args_size);
401406
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, _keys.nwk_senckey);
402-
if (0 != ret)
407+
if (0 != ret) {
403408
goto exit;
409+
}
404410
}
405411

406412
exit: mbedtls_aes_free(&aes_ctx);
@@ -428,15 +434,17 @@ int LoRaMacCrypto::compute_join_server_keys(const uint8_t *eui)
428434
nonce[0] = 0x05;
429435
memcpy(nonce + 1, eui, 8);
430436
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, _keys.js_enckey);
431-
if (0 != ret)
437+
if (0 != ret) {
432438
goto exit;
439+
}
433440

434441
memset(nonce, 0, sizeof(nonce));
435442
nonce[0] = 0x06;
436443
memcpy(nonce + 1, eui, 8);
437444
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, _keys.js_intkey);
438-
if (0 != ret)
445+
if (0 != ret) {
439446
goto exit;
447+
}
440448

441449
exit:
442450
mbedtls_aes_free(&aes_ctx);

0 commit comments

Comments
 (0)