Skip to content
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

[TAKEOVER]: pkg/semtech-loramac: switch to RIOT AES #16313

Merged
merged 1 commit into from
Apr 12, 2021

Conversation

fjmolinas
Copy link
Contributor

Contribution description

This PR is a take over from #10124:

Patch to adapt LoRaMAC 4.4.1 to RIOT AES implementation.

  1. Code size: RIOT AES significantly bigger without sys/crypto: optimize AES footprint #10037, ~1KB bigger with sys/crypto: optimize AES footprint #10037, about the same size as LoRaMAC AES with sys/crypto: optimize AES footprint #10037 and aes_decrypt disabled (LoRaWAN doesn't need it)

  2. Performance: generally, RIOT AES is significantly (over 2 times) faster, especially on Cortex-M3 and above. On Cortex-M0, decryption is about the same speed, encryption is almost 2 times faster with RIOT AES.

Such difference is to be expected, as RIOT uses faster T-tables implementation while LoRaMAC uses S-boxes.

  1. Compatibility: LoRaMAC AES and RIOT AES can't be used simultaneously because of the same function names aes_encrypt() and aes_decrypt(). So, porting LoRaMAC to RIOT AES is a must if one needs AES for any other function, not just LoRaWAN.

Testing procedure

Run: make -C tests/pkg_semtech-loramac/ clean flash test-with-config

test result
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac erase

>
> loramac erase
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac set deveui 00D23F63A8D87783
loramac set deveui 00D23F63A8D87783
> loramac set appeui 70B3D57ED00204EC
loramac set appeui 70B3D57ED00204EC
> loramac set appkey 0A3E1510AEB8DB583B10DCA691522409
loramac set appkey 0A3E1510AEB8DB583B10DCA691522409
> loramac set dr 0
loramac set dr 0
> loramac join otaa
loramac join otaa
Join procedure succeeded!
> loramac tx "This is RIOT" cnf 123
loramac tx "This is RIOT" cnf 123
Received ACK from network
Message sent with success
> loramac tx "This is RIOT" uncnf 42
loramac tx "This is RIOT" uncnf 42
Message sent with success
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
>loramac set deveui 00D23F63A8D87783
 loramac set deveui 00D23F63A8D87783
> loramac set appeui 70B3D57ED00204EC
loramac set appeui 70B3D57ED00204EC
> loramac set appkey 0A3E1510AEB8DB583B10DCA691522409
loramac set appkey 0A3E1510AEB8DB583B10DCA691522409
> loramac set dr 3
loramac set dr 3
> loramac join otaa
loramac join otaa
Join procedure succeeded!
> loramac tx "This is RIOT" cnf 123
loramac tx "This is RIOT" cnf 123
Received ACK from network
Message sent with success
> loramac tx "This is RIOT" uncnf 42
loramac tx "This is RIOT" uncnf 42
Message sent with success
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac set deveui 00D23F63A8D87783
loramac set deveui 00D23F63A8D87783
> loramac set appeui 70B3D57ED00204EC
loramac set appeui 70B3D57ED00204EC
> loramac set appkey 0A3E1510AEB8DB583B10DCA691522409
loramac set appkey 0A3E1510AEB8DB583B10DCA691522409
> loramac set dr 5
loramac set dr 5
> loramac join otaa
loramac join otaa
Join procedure succeeded!
> loramac tx "This is RIOT" cnf 123
loramac tx "This is RIOT" cnf 123
Received ACK from network
Message sent with success
>loramac tx "This is RIOT" uncnf 42
 loramac tx "This is RIOT" uncnf 42
Message sent with success
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac erase
loramac erase
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac set deveui 00D23F63A8D87782
loramac set deveui 00D23F63A8D87782
> loramac set appeui 70B3D57ED00204EC
loramac set appeui 70B3D57ED00204EC
> loramac set devaddr 2601107E
loramac set devaddr 2601107E
> loramac set nwkskey 6CCC73B2681EC60142C5D4933BFE8D34
loramac set nwkskey 6CCC73B2681EC60142C5D4933BFE8D34
> loramac set appskey 07683C44D66D201B557B0DF7EFEF8391
loramac set appskey 07683C44D66D201B557B0DF7EFEF8391
> loramac set rx2_dr 3
loramac set rx2_dr 3
> loramac set dr 0
loramac set dr 0
> loramac join abp
loramac join abp
Join procedure succeeded!
> loramac tx "This is RIOT" cnf 123
loramac tx "This is RIOT" cnf 123
Received ACK from network
Message sent with success
> loramac tx "This is RIOT" uncnf 42
loramac tx "This is RIOT" uncnf 42
Message sent with success
> loramac get ul_cnt
loramac get ul_cnt
Uplink Counter: 2
>reboot
 reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac set ul_cnt 2
loramac set ul_cnt 2
> loramac set deveui 00D23F63A8D87782
loramac set deveui 00D23F63A8D87782
> loramac set appeui 70B3D57ED00204EC
loramac set appeui 70B3D57ED00204EC
> loramac set devaddr 2601107E
loramac set devaddr 2601107E
> loramac set nwkskey 6CCC73B2681EC60142C5D4933BFE8D34
loramac set nwkskey 6CCC73B2681EC60142C5D4933BFE8D34
> loramac set appskey 07683C44D66D201B557B0DF7EFEF8391
loramac set appskey 07683C44D66D201B557B0DF7EFEF8391
> loramac set rx2_dr 3
loramac set rx2_dr 3
>loramac set dr 3
 loramac set dr 3
> loramac join abp
loramac join abp
Join procedure succeeded!
> loramac tx "This is RIOT" cnf 123
loramac tx "This is RIOT" cnf 123
Received ACK from network
Message sent with success
> loramac tx "This is RIOT" uncnf 42
loramac tx "This is RIOT" uncnf 42
Message sent with success
> loramac get ul_cnt
loramac get ul_cnt
Uplink Counter: 4
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac set ul_cnt 4
loramac set ul_cnt 4
> loramac set deveui 00D23F63A8D87782
loramac set deveui 00D23F63A8D87782
> loramac set appeui 70B3D57ED00204EC
loramac set appeui 70B3D57ED00204EC
>loramac set devaddr 2601107E
 loramac set devaddr 2601107E
>loramac set nwkskey 6CCC73B2681EC60142C5D4933BFE8D34
 loramac set nwkskey 6CCC73B2681EC60142C5D4933BFE8D34
> loramac set appskey 07683C44D66D201B557B0DF7EFEF8391
loramac set appskey 07683C44D66D201B557B0DF7EFEF8391
>loramac set rx2_dr 3
 loramac set rx2_dr 3
> loramac set dr 5
loramac set dr 5
> loramac join abp
loramac join abp
Join procedure succeeded!
> loramac tx "This is RIOT" cnf 123
loramac tx "This is RIOT" cnf 123
Received ACK from network
Message sent with success
> loramac tx "This is RIOT" uncnf 42
loramac tx "This is RIOT" uncnf 42
Message sent with success
> loramac get ul_cnt
loramac get ul_cnt
Uplink Counter: 6
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac set ul_cnt 6
loramac set ul_cnt 6
> loramac help
loramac help
Usage: loramac <get|set|join|tx|link_check|save|erase>
loramac erase
> loramac erase
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac get deveui
loramac get deveui
DEVEUI: 0000000000000000
> loramac get appeui
loramac get appeui
APPEUI: 0000000000000000
> loramac get appkey
loramac get appkey
APPKEY: 00000000000000000000000000000000
> loramac get devaddr
loramac get devaddr
DEVADDR: 00000000
> loramac get nwkskey
loramac get nwkskey
NWKSKEY: 00000000000000000000000000000000
> loramac get appskey
loramac get appskey
APPSKEY: 00000000000000000000000000000000
> loramac set deveui 00D23F63A8D87783
loramac set deveui 00D23F63A8D87783
> loramac set appeui 70B3D57ED00204EC
loramac set appeui 70B3D57ED00204EC
> loramac set appkey 0A3E1510AEB8DB583B10DCA691522409
loramac set appkey 0A3E1510AEB8DB583B10DCA691522409
> loramac save
loramac save
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac get deveui
loramac get deveui
DEVEUI: 00D23F63A8D87783
> loramac get appeui
loramac get appeui
APPEUI: 70B3D57ED00204EC
> loramac get appkey
loramac get appkey
APPKEY: 0A3E1510AEB8DB583B10DCA691522409
> loramac erase
loramac erase
> reboot
reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac set deveui 00D23F63A8D87782
loramac set deveui 00D23F63A8D87782
> loramac set appeui 70B3D57ED00204EC
loramac set appeui 70B3D57ED00204EC
>loramac set devaddr 2601107E
 loramac set devaddr 2601107E
>loramac set nwkskey 6CCC73B2681EC60142C5D4933BFE8D34
 loramac set nwkskey 6CCC73B2681EC60142C5D4933BFE8D34
> loramac set appskey 07683C44D66D201B557B0DF7EFEF8391
loramac set appskey 07683C44D66D201B557B0DF7EFEF8391
> loramac set rx2_dr 3
loramac set rx2_dr 3
> loramac save
loramac save
>reboot
 reboot
main(): This is RIOT! (Version: 2021.04-devel-1304-ga3cbe-riot-loramac-system-aes)
All up, running the shell now
> loramac get devaddr
loramac get devaddr
DEVADDR: 2601107E
> loramac get nwkskey
loramac get nwkskey
NWKSKEY: 6CCC73B2681EC60142C5D4933BFE8D34
> loramac get appskey
loramac get appskey
APPSKEY: 07683C44D66D201B557B0DF7EFEF8391
> TEST PASSED
Fixes #16293

@fjmolinas fjmolinas added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 12, 2021
Copy link
Member

@jia200x jia200x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK!

LoRaWAN Class A low-power application
=====================================
Starting join procedure
Join procedure succeeded
Sending: This is RIOT!

@jia200x jia200x merged commit a4c479c into RIOT-OS:master Apr 12, 2021
@fjmolinas fjmolinas deleted the riot-loramac-system-aes branch April 12, 2021 11:15
@fjmolinas
Copy link
Contributor Author

Thanks for the original fix @olegart sorry this drifted out of sight...

@kaspar030 kaspar030 added this to the Release 2021.04 milestone Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conflict between semtech-loramac and hashes modules
4 participants