Skip to content

Commit

Permalink
Merge pull request #20 from jerryneedell/jerryn_big_packet
Browse files Browse the repository at this point in the history
 fix error for packets with payloads > 7 bytes
  • Loading branch information
brentru committed Feb 11, 2019
2 parents 980955c + e4a23b2 commit 4e9eebc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions adafruit_tinylora/adafruit_tinylora_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def encrypt_payload(self, data):
# k = data ptr
k = 0
i = 1
while i <= 1:
while i <= num_blocks:
block_a[0] = 0x01
block_a[1] = 0x00
block_a[2] = 0x00
Expand Down Expand Up @@ -272,11 +272,11 @@ def calculate_mic(self, lora_packet, lora_packet_length, mic):
old_data[i] = block_b[i]
block_counter = 1
# calculate until n-1 packet blocks
k = 0 # ptr
while block_counter < num_blocks:
# copy data into array
k = 0 # ptr
for i in range(16):
new_data[k] = lora_packet[i]
new_data[i] = lora_packet[k]
k += 1
# XOR new_data with old_data
self._xor_data(new_data, old_data)
Expand All @@ -290,7 +290,8 @@ def calculate_mic(self, lora_packet, lora_packet_length, mic):
# perform calculation on last block
if incomplete_block_size == 0:
for i in range(16):
new_data[i] = lora_packet[i]
new_data[i] = lora_packet[k]
k += 1
# xor with key 1
self._xor_data(new_data, key_k1)
# xor with old data
Expand All @@ -299,10 +300,9 @@ def calculate_mic(self, lora_packet, lora_packet_length, mic):
self._aes_encrypt(new_data, self._network_key)
else:
# copy the remaining data
k = 0 # ptr
for i in range(16):
if i < incomplete_block_size:
new_data[k] = lora_packet[i]
new_data[i] = lora_packet[k]
k += 1
if i == incomplete_block_size:
new_data[i] = 0x80
Expand Down

0 comments on commit 4e9eebc

Please sign in to comment.