Skip to content

fix error for packets with payloads > 7 bytes #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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