Skip to content

Commit 4e9eebc

Browse files
authored
Merge pull request #20 from jerryneedell/jerryn_big_packet
fix error for packets with payloads > 7 bytes
2 parents 980955c + e4a23b2 commit 4e9eebc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

adafruit_tinylora/adafruit_tinylora_encryption.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def encrypt_payload(self, data):
8383
# k = data ptr
8484
k = 0
8585
i = 1
86-
while i <= 1:
86+
while i <= num_blocks:
8787
block_a[0] = 0x01
8888
block_a[1] = 0x00
8989
block_a[2] = 0x00
@@ -272,11 +272,11 @@ def calculate_mic(self, lora_packet, lora_packet_length, mic):
272272
old_data[i] = block_b[i]
273273
block_counter = 1
274274
# calculate until n-1 packet blocks
275+
k = 0 # ptr
275276
while block_counter < num_blocks:
276277
# copy data into array
277-
k = 0 # ptr
278278
for i in range(16):
279-
new_data[k] = lora_packet[i]
279+
new_data[i] = lora_packet[k]
280280
k += 1
281281
# XOR new_data with old_data
282282
self._xor_data(new_data, old_data)
@@ -290,7 +290,8 @@ def calculate_mic(self, lora_packet, lora_packet_length, mic):
290290
# perform calculation on last block
291291
if incomplete_block_size == 0:
292292
for i in range(16):
293-
new_data[i] = lora_packet[i]
293+
new_data[i] = lora_packet[k]
294+
k += 1
294295
# xor with key 1
295296
self._xor_data(new_data, key_k1)
296297
# xor with old data
@@ -299,10 +300,9 @@ def calculate_mic(self, lora_packet, lora_packet_length, mic):
299300
self._aes_encrypt(new_data, self._network_key)
300301
else:
301302
# copy the remaining data
302-
k = 0 # ptr
303303
for i in range(16):
304304
if i < incomplete_block_size:
305-
new_data[k] = lora_packet[i]
305+
new_data[i] = lora_packet[k]
306306
k += 1
307307
if i == incomplete_block_size:
308308
new_data[i] = 0x80

0 commit comments

Comments
 (0)