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

Open
wants to merge 6 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 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
@d3zd3z
Copy link
Collaborator

d3zd3z commented May 20, 2025

To be clear here. Changing an existing license declaration on a file can only be done by permission of all of the contributing authors. Changing license declarations is much worse than bringing in the files with the licenses on them (and figuring out what needs to happen to use the code under the license the authors released the code under).

The license lines in the file are an indication, from the author, of the terms that they allow their code to be used under them. Removing those declarations is in bad-faith, and is something we have to be very careful never happens to code in this project.

@nashif
Copy link
Member

nashif commented May 21, 2025

This was discussed in the TSC and it was agreed that we will not accept non original, Apache licensed code for this type of driver. Please use another method of integration.

@nashif nashif moved this from In Progress to Done in TSC Attention Needed May 21, 2025
@soburi
Copy link
Member Author

soburi commented May 21, 2025

Thank you for your comment.

@d3zd3z @nashif

I am aware that this is not a good situation, and I am very sorry.
I also thank @ajf58 for pointing this out to me.

I think there is another way to deal with this, so I will carefully reconsider it.

@ajf58
Copy link
Collaborator

ajf58 commented May 22, 2025

I think there is another way to deal with this, so I will carefully reconsider it.

Agreed. There have been a few PRs recently where we need them to stay Apache 2.0. I think the best way to do this is in the HAL, which is where several of them originate from. I don't think there's much of a convention across the different vendor HALs here, but I'll take a look.

soburi added 3 commits June 16, 2025 07:47
Add `zephyr-keep-sorted` and reorder file entries alphabetically.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Update hal_rpi_pico to introduce the Zephyr adaptation
for the sha256 driver.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add include paths and source files for the sha256 driver
when enabled `CONFIG_PICOSDK_USE_SHA256` config.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the rpi_pico_sha256 branch from 90f02be to da897ce Compare June 15, 2025 23:00
Copy link

github-actions bot commented Jun 15, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_rpi_pico zephyrproject-rtos/hal_rpi_pico@7b57b24 zephyrproject-rtos/hal_rpi_pico#13 zephyrproject-rtos/hal_rpi_pico#13/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-hal_rpi_pico DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Jun 15, 2025
@soburi
Copy link
Member Author

soburi commented Jun 15, 2025

Add a public interface to the hal side and change the policy to use it.

@soburi soburi marked this pull request as ready for review June 15, 2025 23:40
@soburi soburi requested review from ajf58 and valeriosetti June 16, 2025 01:24
{
struct rpi_pico_sha256_data *data = dev->data;

assert(!data->state.locked);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't assert() a bit too strong here? I suggest adding a mutex in struct rpi_pico_sha256_data and use it here:

  • lock the mutex
  • check data->state.locked and return if already set (releasing the mutex, of course before returning)
  • set data->state.locked (not on line 79 as it is done now)
  • unlock the mutex
  • remember to unset data->state.locked in rpi_pico_sha256_hash_session_free()

In this way you can have 2 threads willing to use the hash driver at the same time and then the one that comes later will just wait for the resource to be free.

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 response has become slower.

It's true that assert is quite powerful, so I have modified it.
Your suggestion was to use a mutex, but the exclusive section completes in an extremely short time, so I implemented it using a spinlock.

@soburi soburi force-pushed the rpi_pico_sha256 branch 2 times, most recently from ed7b1d2 to 43bbff2 Compare June 27, 2025 05:21
soburi added 3 commits June 27, 2025 14:32
Add basic support for RaspberryPi Pico's SHA256 hardware accelerator.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Added sha256 accelerator to rpi_pico.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add rpi_pico2 to the crypto_hash test target.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the rpi_pico_sha256 branch from 43bbff2 to 236fd9d Compare June 27, 2025 05:32
@soburi soburi requested a review from valeriosetti June 27, 2025 05:35
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Crypto / RNG DNM (manifest) This PR should not be merged (controlled by action-manifest) Licensing The PR has licensing issues => licensing expert to review manifest manifest-hal_rpi_pico platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants