Skip to content

sys/psa_crypto: sha3 support#20698

Merged
mguetschow merged 1 commit intoRIOT-OS:masterfrom
netd-tud:sha3_implementation
Jul 15, 2024
Merged

sys/psa_crypto: sha3 support#20698
mguetschow merged 1 commit intoRIOT-OS:masterfrom
netd-tud:sha3_implementation

Conversation

@Wunderbaeumchen99817
Copy link
Copy Markdown
Contributor

@Wunderbaeumchen99817 Wunderbaeumchen99817 commented May 27, 2024

Contribution description
This PR adds a new pseudomodule for using the existing sha3-hashings-algorithms in a simpler way.
More specific: It adds gluecode for the PSA Crypto API to access the RIOT implementation of SHA3.

Testing procedure
The corresponding tests are located in tests/sys/psa_crypto_hashes/example_sha3_glue.c

You can run them the following way:

  1. go to tests/sys/psa_crypto_hashes/
  2. run "make compile-commands"
  3. run "make flash test"

Issues/PRs references
N/A

@github-actions github-actions bot added Area: doc Area: Documentation Area: tests Area: tests and testing framework Area: build system Area: Build system Area: sys Area: System Area: examples Area: Example Applications labels May 27, 2024
@Wunderbaeumchen99817 Wunderbaeumchen99817 marked this pull request as ready for review May 27, 2024 10:45
@mguetschow mguetschow changed the title Sha3 implementation sys/psa_crypto: sha3 support May 27, 2024
@Teufelchen1
Copy link
Copy Markdown
Contributor

Cool! Could you clean up your commits?

Copy link
Copy Markdown
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

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

Nice work! 🎉

Some rather minor suggestions for improvement below. Please add them first in separate commits and only squash/rebase after we've had a look at the new changes.

Comment on lines +344 to +352
#if IS_USED(MODULE_PSA_HASH_SHA_3) || defined(DOXYGEN)
/**
* @brief Low level wrapper function to call a driver for a SHA3-256 hash setup
* See @ref psa_hash_setup()
*
* @param ctx
* @return psa_status_t
*/
psa_status_t psa_hashes_sha3_256_setup(psa_hashes_sha3_ctx_t *ctx);
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.

Would it make sense to have different psa modules for SHA3-256/384/512 or is the increase in code size if including all three per default negligible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mguetschow The increase in code-size is indeed negligible since they are all based on the same keccak-code (which is the biggest part of the underlying code), which needs to be compiled anyway with every variant of the sha3 algorithm.

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.

Okay, then it sounds reasonable to me to keep it as is. But maybe @Einhornhool has a different opinion and would argue in favor of consistency with the SHA-2 PSA modules?

Copy link
Copy Markdown
Contributor

@Einhornhool Einhornhool Jun 4, 2024

Choose a reason for hiding this comment

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

Hmm, for consistency it would be better to separate them. BUT we separated the SHA-2 modules for the purpose of being modular, since some hardware backends we saw only supported SHA-256 and we wanted to be able to build software backends for the others.
As far as I can see there's only one implementation for SHA-3 available (RIOT Hashes) which supports all three variants. So there's no need to build two different backends.

For me it would be totally fine to keep them together for now and only separate them once we integrate a backend that does not support all of them.
It would be good to document this, though.

Update: Just checked again and there are some other libraries with SHA-3 support. HACL also supports 256/384/512 and Cifra additionally supports 224. I don't see a reason to mix different software backends, though, so I think separation is only needed once we get a hardware accelerator that only supports a subset of 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.

I think separation is only needed once we get a hardware accelerator that only supports a subset of them.

but that would be an API change then

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.

I considered this and I agree. This would be an API change, which makes it more prone to errors.
Also it would require people who add drivers in the future to not only add wrappers, but also to change the module structure.
That makes it less friendly to develop.

I'm sorry for changing my mind now, but I think it would be better to keep the structure consistent with the other modules :)

@mguetschow mguetschow added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 4, 2024
@riot-ci
Copy link
Copy Markdown

riot-ci commented Jun 4, 2024

Murdock results

✔️ PASSED

9b50202 sys/psa_crypto: added sha3 glue code

Success Failures Total Runtime
10177 0 10178 16m:40s

Artifacts

Copy link
Copy Markdown
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

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

Thanks for your fixups, I'm now happy with the changeset! You may rebase and squash everything together in one or two commits (in case you want to split implementation + test in separate commits).

@github-actions github-actions bot removed Area: pkg Area: External package ports Platform: AVR Platform: This PR/issue effects AVR-based platforms Area: drivers Area: Device drivers Area: CI Area: Continuous Integration of RIOT components Area: tools Area: Supplementary tools Area: boards Area: Board ports Platform: ESP Platform: This PR/issue effects ESP-based platforms Area: CoAP Area: Constrained Application Protocol implementations Area: cpu Area: CPU/MCU ports Area: Kconfig Area: Kconfig integration labels Jun 4, 2024
@github-actions github-actions bot removed the Area: examples Area: Example Applications label Jun 6, 2024
@mguetschow mguetschow added this to the Release 2024.07 milestone Jun 11, 2024
Copy link
Copy Markdown
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

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

@Wunderbaeumchen99817 sorry for the back and forth, but could you try to split the three parts in separate (pseudo)modules and add your changes as separate commits for easier review?

@mguetschow
Copy link
Copy Markdown
Contributor

There are still two failing static checks that you should be able to fix (a trailing whitespace and running make generate-features once from the main RIOT repo): https://github.com/RIOT-OS/RIOT/actions/runs/9570133114/job/26416056964?pr=20698

I'm not sure why the third check failed, though.

Copy link
Copy Markdown
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

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

Looks mostly good, just some more minor nitpicks :)

Copy link
Copy Markdown
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

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

Looks good to me now, please squash @Wunderbaeumchen99817 :)

@github-actions github-actions bot added Platform: native Platform: This PR/issue effects the native platform Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Jul 14, 2024
@Wunderbaeumchen99817
Copy link
Copy Markdown
Contributor Author

@mguetschow done :)

Copy link
Copy Markdown
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

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

Thanks, nice work!

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

Labels

Area: build system Area: Build system Area: doc Area: Documentation Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants