Skip to content

drivers: crypto: Add initial support for rpi_pico sha256 accelerator #85036

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

soburi
Copy link
Member

@soburi soburi commented Feb 3, 2025

Add basic support for RaspberryPi Pico's SHA256 hardware accelerator.

@soburi soburi marked this pull request as draft February 3, 2025 01:49
@soburi soburi added the DNM This PR should not be merged (Do Not Merge) label Feb 3, 2025
@soburi soburi marked this pull request as ready for review February 3, 2025 04:02
@valeriosetti valeriosetti self-requested a review February 10, 2025 08:31
@soburi soburi removed the DNM This PR should not be merged (Do Not Merge) label Feb 11, 2025
@soburi
Copy link
Member Author

soburi commented Feb 14, 2025

@ceolin @valeriosetti @ThreeEights

Could you take a look if you have a bit of a while?

Copy link
Collaborator

@valeriosetti valeriosetti left a comment

Choose a reason for hiding this comment

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

The PR looks OK to me. I cannot test it locally because I don't have a board at hand, but at least the test that was extended builds correctly. I only left one minor non-blocking question/comment.

zephyr_library_sources_ifdef(CONFIG_CRYPTO_SMARTBOND crypto_smartbond.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_STM32 crypto_stm32.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_TINYCRYPT_SHIM crypto_tc_shim.c)
# zephyr-keep-sorted-stop
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorting - good idea!

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I'd prefer it if the sorting is one commit, and the addition is a separate commit. The end result is the same, but it's easier to to see the two orthogonal things going on.

Copy link
Collaborator

@valeriosetti valeriosetti 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 addressing previous comment. However reviewing the PR again I found a couple of new ones that I missed before. Sorry

@soburi soburi force-pushed the rpi_pico_sha256 branch 2 times, most recently from a6aeaeb to f2ca146 Compare March 10, 2025 22:42
@soburi soburi requested a review from valeriosetti March 11, 2025 05:36
valeriosetti
valeriosetti previously approved these changes Mar 14, 2025
@soburi
Copy link
Member Author

soburi commented Mar 17, 2025

@ceolin @ThreeEights @ajf58

Could you take a look at it?

Copy link
Collaborator

@ajf58 ajf58 left a comment

Choose a reason for hiding this comment

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

The change looks functionally good, but I am concerned about the outright copy and paste of BSD code, then relabeling it as Apache 2.

I feel like someone else needs to comment on this.

zephyr_library_sources_ifdef(CONFIG_CRYPTO_SMARTBOND crypto_smartbond.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_STM32 crypto_stm32.c)
zephyr_library_sources_ifdef(CONFIG_CRYPTO_TINYCRYPT_SHIM crypto_tc_shim.c)
# zephyr-keep-sorted-stop
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I'd prefer it if the sorting is one commit, and the addition is a separate commit. The end result is the same, but it's easier to to see the two orthogonal things going on.

LOG_MODULE_REGISTER(sha_rpi_pico_sha256, CONFIG_CRYPTO_LOG_LEVEL);

/*
* This is based on the pico_sha256 implementation in the Pico-SDK.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Original code is a https://github.com/raspberrypi/pico-sdk/blob/2.1.0/src/rp2_common/pico_sha256/sha256.c , it's 3-Clause BSD (BSD-3-Clause).

I feel like this file has lifted-and-shifted too much for someone to ignore (many lines of code are the same, just formatted to meet the Zephyr Project's coding style).

I'd be happy if this file had a BSD-3-Clause on it. Zephyr must be compatible with this, we link against BSD-3-Clause all over the place. It's not easy t osee examples of that, however.

Alternatively, we could modify the version of the source code in the hal_rpi_pico. This is something I prefer to avoid, but that feels better at ensuring the software licence is upheld.

Copy link
Member Author

Choose a reason for hiding this comment

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

The codes derived from pico-sdk were separated into crypto_rpi_pico_sha256.h, and the license changed to BSD-3.

Copy link
Member Author

Choose a reason for hiding this comment

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

nit: I'd prefer it if the sorting is one commit, and the addition is a separate commit. The end result is the same, but it's easier to to see the two orthogonal things going on.

Addressed.

soburi added 5 commits March 18, 2025 07:56
Add `zephyr-keep-sorted` and reorder file entries alphabetically.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Add `hardware_sha256/include` to `zephyr_include_directories`.
Use the header only.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Add basic support for RaspberryPi Pico's SHA256 hardware accelerator.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Added sha256 accelerator to rpi_pico.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Add rpi_pico2 to the crypto_hash test target.

Signed-off-by: TOKITA Hiroshi <[email protected]>
@soburi
Copy link
Member Author

soburi commented Mar 19, 2025

This PR contains BSD-3 derived code. (drivers/crypto/crypto_rpi_pico_sha256.h)
I added the label because I wanted to get TSC approval.

@soburi soburi added the TSC Topics that need TSC discussion label Mar 19, 2025
@ajf58
Copy link
Collaborator

ajf58 commented Mar 19, 2025

This PR contains BSD-3 derived code. (drivers/crypto/crypto_rpi_pico_sha256.h) I added the label because I wanted to get TSC approval.

I think, based on the conversation at #81183 (comment) that this won't be a viable solution.

My suggestion is

  1. Change (extend) https://github.com/zephyrproject-rtos/hal_rpi_pico/blob/zephyr/src/rp2_common/pico_sha256/sha256.c in a PR. This already is BSD-3-Clause, nothing would change there.
  2. Update the west manifest for Zephyr to bring in the new HAL.
  3. Make use of the new code from here.

I know that this may feel contradictory to an earlier stance I have of "don't change the Pico SDK unless you have to." I feel like this is one of those times.

That said, I also hope we can do this in a way that makes wiring up the DMA engine to the SHA256 accelerator easy: it's a prime example of where one wants to offload this whilst the CPUs do something more useful.

@soburi
Copy link
Member Author

soburi commented Mar 20, 2025

@ajf58

That said, I also hope we can do this in a way that makes wiring up the DMA engine to the SHA256 accelerator easy: it's a prime example of where one wants to offload this whilst the CPUs do something more useful.

DMA processing must be based on Zephyr's API, and I have determined that this part cannot be used. This is the main reason why I forked this file.

@ajf58
Copy link
Collaborator

ajf58 commented Mar 22, 2025

@ajf58

That said, I also hope we can do this in a way that makes wiring up the DMA engine to the SHA256 accelerator easy: it's a prime example of where one wants to offload this whilst the CPUs do something more useful.

DMA processing must be based on Zephyr's API, and I have determined that this part cannot be used. This is the main reason why I forked this file.

Yes, I understand what problem you found. The approach you took was to breach the terms of the licence, which is not cool. "fork"ing a file is not a thing.

My suggestion is written out above as 3 steps. If you don't understand the steps as written, please ask specific clarifying questions.

@soburi
Copy link
Member Author

soburi commented Mar 22, 2025

@ajf58

Yes, I understand what problem you found. The approach you took was to breach the terms of the licence, which is not cool. "fork"ing a file is not a thing.

I've never heard of the BSD 3 clause license code can't forking.

@ajf58
Copy link
Collaborator

ajf58 commented Mar 22, 2025

@ajf58

Yes, I understand what problem you found. The approach you took was to breach the terms of the licence, which is not cool. "fork"ing a file is not a thing.

I've never heard of the BSD 3 clause license code can't forking.

Your original approach was to:

  1. Remove the original copyright notice. Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
  2. Add your own name as the Copyright holder
  3. Reissue the code under the Apache 2.0 license

This, to me, is a concerning behaviour. It should not require other people to check/monitor/flag that you are breaching other licence terms, you should do this yourself.

After I flagged this you have subsequently corrected this by putting back the original copyright notice, and license. From a technical perspective I don't like how this has been achieved, but that is not the concern I am raising here.

@soburi
Copy link
Member Author

soburi commented Mar 22, 2025

@ajf58

Your original approach was to:

1. Remove the original copyright notice. [Copyright (c) 2024 Raspberry Pi (Trading) Ltd.](https://github.com/raspberrypi/pico-sdk/blob/2.1.0/src/rp2_common/pico_sha256/sha256.c#L2)

2. Add your own name as the Copyright holder

3. Reissue the code under the Apache 2.0 license

This, to me, is a concerning behaviour. It should not require other people to check/monitor/flag that you are breaching other licence terms, you should do this yourself.

After I flagged this you have subsequently corrected this by putting back the original copyright notice, and license. From a technical perspective I don't like how this has been achieved, but that is not the concern I am raising here.

This is exactly as you pointed out.
I had mentioned that I was using it, but I had not properly addressed the license.
Thank you for pointing that out.

@soburi soburi marked this pull request as draft March 22, 2025 15:27
@soburi soburi removed the TSC Topics that need TSC discussion label Mar 22, 2025
@nashif nashif added the Licensing The PR has licensing issues => licensing expert to review label Apr 16, 2025
@nashif nashif moved this from Todo to In Progress in TSC Attention Needed Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Crypto / RNG Licensing The PR has licensing issues => licensing expert to review platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico)
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

7 participants