@@ -83,7 +83,7 @@ def encrypt_payload(self, data):
83
83
# k = data ptr
84
84
k = 0
85
85
i = 1
86
- while i <= 1 :
86
+ while i <= num_blocks :
87
87
block_a [0 ] = 0x01
88
88
block_a [1 ] = 0x00
89
89
block_a [2 ] = 0x00
@@ -272,11 +272,11 @@ def calculate_mic(self, lora_packet, lora_packet_length, mic):
272
272
old_data [i ] = block_b [i ]
273
273
block_counter = 1
274
274
# calculate until n-1 packet blocks
275
+ k = 0 # ptr
275
276
while block_counter < num_blocks :
276
277
# copy data into array
277
- k = 0 # ptr
278
278
for i in range (16 ):
279
- new_data [k ] = lora_packet [i ]
279
+ new_data [i ] = lora_packet [k ]
280
280
k += 1
281
281
# XOR new_data with old_data
282
282
self ._xor_data (new_data , old_data )
@@ -290,7 +290,8 @@ def calculate_mic(self, lora_packet, lora_packet_length, mic):
290
290
# perform calculation on last block
291
291
if incomplete_block_size == 0 :
292
292
for i in range (16 ):
293
- new_data [i ] = lora_packet [i ]
293
+ new_data [i ] = lora_packet [k ]
294
+ k += 1
294
295
# xor with key 1
295
296
self ._xor_data (new_data , key_k1 )
296
297
# xor with old data
@@ -299,10 +300,9 @@ def calculate_mic(self, lora_packet, lora_packet_length, mic):
299
300
self ._aes_encrypt (new_data , self ._network_key )
300
301
else :
301
302
# copy the remaining data
302
- k = 0 # ptr
303
303
for i in range (16 ):
304
304
if i < incomplete_block_size :
305
- new_data [k ] = lora_packet [i ]
305
+ new_data [i ] = lora_packet [k ]
306
306
k += 1
307
307
if i == incomplete_block_size :
308
308
new_data [i ] = 0x80
0 commit comments