Skip to content

Commit

Permalink
Correct bug in aes due to bug in array implementation on avr
Browse files Browse the repository at this point in the history
  • Loading branch information
ngraziano committed Oct 30, 2021
1 parent 606e607 commit d6f73aa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LMICPP-Arduino",
"version": "2.3.0",
"version": "2.3.1",
"keywords": "Lora",
"description": "Modified Arduino port of the LMIC (LoraWAN-in-C, formerly LoraMAC-in-C) framework provided by IBM. Changed to C++ format.",
"frameworks": ["arduino"],
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=LMICPP-Arduino
version=2.3.0
version=2.3.1
author=IBM
maintainer=Nicolas Graziano <[email protected]>
sentence=Modified Arduino port of the LMIC (LoraWAN-in-C, formerly LoraMAC-in-C) framework provided by IBM. Changed to C++ format.
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ upload_speed = 9600
#upload_speed = 57600
upload_port = COM3
# test_port= COM3
# test_speed=57600
test_speed=9600

monitor_port = COM3
monitor_speed = 9600
Expand Down
11 changes: 7 additions & 4 deletions src/aes/limc_aes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void Aes::appendMic(const uint32_t devaddr, const uint32_t seqno,
* len : total length (MIC included)
*/
void Aes::appendMic0(uint8_t *const pdu, const uint8_t len) const {
AesBlock buf = {0};
AesBlock buf;
buf.fill(0);
const uint8_t lenWithoutMic = len - lengths::MIC;
aes_cmac(pdu, lenWithoutMic, false, AESDevKey, buf);
// Copy MIC0 at the end
Expand All @@ -91,7 +92,8 @@ void Aes::appendMic0(uint8_t *const pdu, const uint8_t len) const {
* len : total length (MIC included)
*/
bool Aes::verifyMic0(const uint8_t *const pdu, const uint8_t len) const {
AesBlock buf = {0};
AesBlock buf;
buf.fill(0);
const uint8_t lenWithoutMic = len - lengths::MIC;
aes_cmac(pdu, lenWithoutMic, false, AESDevKey, buf);
return std::equal(buf.begin(), buf.begin() + lengths::MIC,
Expand Down Expand Up @@ -202,8 +204,9 @@ void Aes::aes_cmac(const uint8_t *buf, uint8_t len, const bool prepend_aux,
// Final block, xor with K1 or K2. K1 and K2 are calculated
// by encrypting the all-zeroes block and then applying some
// shifts and xor on that.
AesBlock final_key = {0};
// std::fill(final_key, final_key + AES_BLCK_SIZE, 0);
AesBlock final_key;
std::fill_n(final_key.begin(), final_key.size(), 0);

block_encrypt(final_key, key);

// Calculate K1
Expand Down

0 comments on commit d6f73aa

Please sign in to comment.