-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
base: main
Are you sure you want to change the base?
Conversation
0d6e6b8
to
a2b3bb7
Compare
a2b3bb7
to
19c04b7
Compare
@ceolin @valeriosetti @ThreeEights Could you take a look if you have a bit of a while? |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorting - good idea!
There was a problem hiding this comment.
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.
There was a problem hiding this 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
a6aeaeb
to
f2ca146
Compare
Could you take a look at it? |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
6b6de83
to
e568f8c
Compare
drivers/crypto/CMakeLists.txt
Outdated
zephyr_library_sources_ifdef(CONFIG_CRYPTO_ATAES132A crypto_ataes132a.c) | ||
zephyr_library_sources_ifdef(CONFIG_CRYPTO_CC23X0 crypto_cc23x0.c) | ||
zephyr_library_sources_ifdef(CONFIG_CRYPTO_INTEL_SHA crypto_intel_sha.c) | ||
zephyr_library_sources_ifdef(CONFIG_CRYPTO_IT51XXX_SHA crypto_it51xxx_sha.c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite all other entries being transitioned to uniform space indentation, this remains tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
drivers/crypto/CMakeLists.txt
Outdated
zephyr_library_sources_ifdef(CONFIG_CRYPTO_SI32 crypto_si32.c) | ||
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_STM32_HASH crypto_stm32_hash.c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this also be converted to spaces for alignment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
drivers/crypto/Kconfig.rpi_pico
Outdated
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config CRYPTO_RPI_PICO_SHA256 | ||
bool "RasberryPi Pico SHA256 Accelerator driver" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool "RasberryPi Pico SHA256 Accelerator driver" | |
bool "Raspberry Pi Pico SHA256 Accelerator driver" |
or maybe even like this, as Pico is a board and the driver is for SoC. It's opinionated though, feel free to reject:
bool "RasberryPi Pico SHA256 Accelerator driver" | |
bool "Raspberry Pi microcontrollers SHA256 Accelerator driver" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
drivers/crypto/Kconfig.rpi_pico
Outdated
depends on DT_HAS_RASPBERRYPI_PICO_SHA256_ENABLED | ||
select PICOSDK_USE_SHA256 | ||
help | ||
RaspberryPi Pico SHA256 accelarator driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RaspberryPi Pico SHA256 accelarator driver. | |
Raspberry Pi Pico SHA256 accelarator driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
static int crypto_rpi_pico_sha256_query_hw_caps(const struct device *dev) | ||
{ | ||
return (CAP_SEPARATE_IO_BUFS | CAP_SYNC_OPS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personal opinion: readability would be better without parentheses:
return (CAP_SEPARATE_IO_BUFS | CAP_SYNC_OPS); | |
return CAP_SEPARATE_IO_BUFS | CAP_SYNC_OPS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
e568f8c
to
08dfdb5
Compare
08dfdb5
to
a64fdfa
Compare
19ad0c7
to
a577c96
Compare
By the recent SDK update, compilation will fail if `pico_platform_common` is not added to the include path, so that we fix this. Signed-off-by: TOKITA Hiroshi <[email protected]>
Update hal_rpi_pico to commit 09e9575 to introduce hardware sha256. Signed-off-by: TOKITA Hiroshi <[email protected]>
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]>
a577c96
to
11c24e7
Compare
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]>
11c24e7
to
2c17f5e
Compare
|
Could you revisit? I would like to include this in v4.3.0 if we can meet the deadline. |
sha256_set_bswap(true); | ||
sha256_start(); | ||
|
||
pico_sha256_update(&data->state, pkt->in_buf, pkt->in_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there limits on the input size by the HAL? If so, please test for them to return EINVAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also work on Hazard3 as it's merged now? Cannot test right now, sorry, but interested whether or not bootrom call works fine, as those are somewhat interesting on RISC-V mode due to emulation being involved and may require application/RTOS to allocate a stack for BootROM emulator in some cases
Add basic support for RaspberryPi Pico's SHA256 hardware accelerator.