Skip to content

sys: PSA Crypto API implementation#18547

Merged
bors[bot] merged 8 commits intoRIOT-OS:masterfrom
Einhornhool:pr/psa-crypto-implementation
Sep 4, 2023
Merged

sys: PSA Crypto API implementation#18547
bors[bot] merged 8 commits intoRIOT-OS:masterfrom
Einhornhool:pr/psa-crypto-implementation

Conversation

@Einhornhool
Copy link
Copy Markdown
Contributor

@Einhornhool Einhornhool commented Sep 2, 2022

Contribution description

This adds an implementation of the ARM PSA Crypto API specification to RIOT.

It is a cryptographic API that supports software and hardware backends as well as the use of multiple secure elements, which can be configured with Kconfig.
It integrates indirect, identifier based key management to support persistent storage of key material in local memory and devices with protected key storage.

A description of the implementation design and an evaluation of the processing time and memory overhead in RIOT has been published here: Usable Security for an IoT OS: Integrating the Zoo of Embedded Crypto Components Below a Common API

Implementation status

So far this implementation supports the following operations:

  • Volatile key storage
  • AES in CBC mode
  • Hashes (MD5, SHA1, SHA224, SHA256)
  • HMAC SHA256
  • ECDSA with NIST P192 and P256 curves

The following backends are supported so far:

  • RIOT Cipher Module
  • RIOT Hash Module
  • Micro ECC library package
  • Cryptocell 310 hardware accelerator on the Nordic NRF52840dk
  • Microchip ATECC608A secure element

Other operations and backends as well as persistent key storage can and will be implemented by me and anyone who wants to contribute in the future.

Testing procedure

So far there is a show case application in examples/psa_crypto to demonstrate the usage and configuration of different backends of the API (refer to the application README for more information).

@github-actions github-actions bot added Area: boards Area: Board ports Area: build system Area: Build system Area: doc Area: Documentation Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports Area: sys Area: System labels Sep 2, 2022
@benpicco benpicco requested review from kfessel and maribu September 2, 2022 13:07
@benpicco
Copy link
Copy Markdown
Contributor

benpicco commented Sep 2, 2022

Nice work!

But a single 20kSLOC commit is a bit hard to handle - can you please split this up into more manageable chunks? Ideally even multiple PRs since there seem to be several things in there that could be merged independently.

@Einhornhool
Copy link
Copy Markdown
Contributor Author

Thank you!
I know it's big and I can definitely split it up for reviewing.
If it's okay, I would like to keep it this way until after the summit next week (there probably is going to be a discussion about PSA Crypto in RIOT), so people who are interested can take a look at how everything is supposed to work together.

@benpicco
Copy link
Copy Markdown
Contributor

benpicco commented Sep 2, 2022

You can of course do this in whatever time scale suits you best, but splitting this into multiple commits would be a good first step independent of whether the PR should be split or not.

@Einhornhool
Copy link
Copy Markdown
Contributor Author

Alright, I will do that

@Einhornhool Einhornhool force-pushed the pr/psa-crypto-implementation branch from 24395e3 to 03407f8 Compare September 2, 2022 14:58
Copy link
Copy Markdown
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

Lots of style nitpicks. I didn't look at all and event failed to grasp the high level picture yet, as it is really hard to read code on a mobile phone :( I will provide better feadback one I am back at a keyboard.

Copy link
Copy Markdown
Contributor

@MrKevinWeiss MrKevinWeiss left a comment

Choose a reason for hiding this comment

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

Maybe it would be nice to add a simple automatic test to the CI can test it as well?

Details
diff --git a/examples/psa_crypto/tests/01-run.py b/examples/psa_crypto/tests/01-run.py
new file mode 100755
index 0000000000..25257b8ca8
--- /dev/null
+++ b/examples/psa_crypto/tests/01-run.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python3
+
+import sys
+from testrunner import run
+
+
+def testfunc(child):
+    child.expect_exact('All Done')
+    print("[TEST PASSED]")
+
+
+if __name__ == "__main__":
+    sys.exit(run(testfunc))

@@ -0,0 +1,14 @@
PKG_NAME=driver_cryptocell
PKG_URL=https://github.com/Einhornhool/RIOT-cryptocell-driver.git
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This package points to an archive (.a) only, with headers repository. That's quite limited: only nrf52840 cpu is supported. Is there a possibility and a plan to provide an open-source implementation ?

Also note that the package is too much limited IMHO: it can only be built for nrf52840dk board but I think any nrf52840 CPU based board should work with it.

Copy link
Copy Markdown
Contributor Author

@Einhornhool Einhornhool Sep 6, 2022

Choose a reason for hiding this comment

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

Unfortunately this driver is closed source and there don't seem to be any plans to make it open source.
I got this from the Nordic SDK, where they only provide the archives and header files. There is a Git Repositiory (nrfxlib), which also provides archive files, but only headers with SHA 256 and ECC P256 support.

The limitation is my mistake, I did not realize that the nrf52840 also had an accelerator, I will fix that.

@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Sep 7, 2022
Copy link
Copy Markdown
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

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

wow this is a great PR
since you already said you want to split it, I just had a first glance and found some small nit picks.

#define CFG_I2C_DEFAULT_H

#include "periph_cpu.h"
#include "kernel_defines.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

are the "kernel_defines.h" needed in this header? (cant see anything being added that requires them)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

resolved in 18582

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No resolved here... Please remove

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

bors try

@bors
Copy link
Copy Markdown
Contributor

bors bot commented Aug 29, 2023

try

Build failed:

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

I don't why codespell isn't picking it up the ignore. I did notice that in the docker static tests, our requirements are specifying codespell as a minimum, not an exact. This means, if codespell updates, new, unrelated errors may occur.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Aug 30, 2023

All other words in that ignore list are spelled lower case (even if the target word is upper case). Maybe that is the problem?

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

tested locally... That was it. lowercase please :)

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

Now that things are good do you have any final remarks @Teufelchen1 ?

@Teufelchen1
Copy link
Copy Markdown
Contributor

Teufelchen1 commented Aug 31, 2023

There are still around 5ish recent (> 01.01.23) conversations unresolved. They seem to be minor, I would like to see them fixed before merging.

Also, take a look at murdock? Missing stdio.h something something

@Einhornhool
Copy link
Copy Markdown
Contributor Author

I think I'm done.

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

bors try

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

just to see everything :)

@bors
Copy link
Copy Markdown
Contributor

bors bot commented Aug 31, 2023

try

Build failed:

@miri64
Copy link
Copy Markdown
Member

miri64 commented Aug 31, 2023

Just one ATmega being too small for this :-)

Copy link
Copy Markdown
Contributor

@MrKevinWeiss MrKevinWeiss left a comment

Choose a reason for hiding this comment

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

If everything works I would give it my ACK. It is just a matter of @Teufelchen1 to finish checking the changes!

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

If everyone is happy then.

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

bors merge

@bors
Copy link
Copy Markdown
Contributor

bors bot commented Sep 4, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@bors
Copy link
Copy Markdown
Contributor

bors bot commented Sep 4, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@Ollrogge
Copy link
Copy Markdown
Member

Ollrogge commented Sep 4, 2023

Congrats @Einhornhool !!

@miri64
Copy link
Copy Markdown
Member

miri64 commented Sep 4, 2023

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: boards Area: Board ports Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports Area: sys Area: System Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.