-
Notifications
You must be signed in to change notification settings - Fork 3k
Cryptocell 310 support #6794
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
Cryptocell 310 support #6794
Conversation
ARM Internal Ref: IOTSSL-2262 |
Do you have ready documentation for this feature (will you create one to Handbook?) ? To understand this new feature. I assume there will be as well porting guide (how to port this to other targets). |
@0xc0170 what sort of documentation do you have in mind? |
@RonEld Please clean the commit history and commit messages. Looks like a development branch not ready for release. |
@0xc0170 How do you suggest I do that? Should I squash all commits into a single one? |
@0xc0170 I have re-written history, and combined the commits according to topics. |
Unfortunately, during this rewrite, @k-stachowiak name was removed on some of the contributions |
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 git history looks 👍
platform/mbed_sdk_boot.c
Outdated
@@ -18,7 +18,9 @@ | |||
#include <stdlib.h> | |||
#include <stdint.h> | |||
#include "cmsis.h" | |||
|
|||
#if DEVICE_CRYPTOCELL |
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.
This is SDK boot . The mbed OS 5 boot is in rtos folder (unified), see mbed_boot.c
file
When and how this library should be initialized (why it was added to this boot sequence) ? Why trng_init does not initalizes this (is there better place to do init than adding this here) ?
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.
you are correct. This part was already removed as part of 98a9e91db34c8ebad5ad3276097c56ea7d416017
I probably returned it with my history changes. I'll remove it again
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.
LGTM, just one question about cryptocell versioning via labels.
targets/targets.json
Outdated
@@ -3658,6 +3658,9 @@ | |||
"NRF52840_DK": { | |||
"supported_form_factors": ["ARDUINO"], | |||
"inherits": ["MCU_NRF52840"], | |||
"macros_add": ["MBEDTLS_CONFIG_HW_SUPPORT"], | |||
"device_has_add": ["CRYPTOCELL"], |
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.
This is HAL implementation for cryptocell, that we provide. And then what is the extra label for ? To specify the version?
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.
I added the DEVICE_CRYPTOCELL
label for the sake of using the cryptocell trng.
For example, in the platform's trng_api.c
, it is mutual to all of NRF5x boards, but on the NRF52840_DK, there is also cryptocell TRNG.
I am thinking that perhaps in the future, to use this label also for the MPS2 porting, done in #6169 but this is only if the API will be common for both targets, which is currently not.
The label for DEVICE_CRYPTOCELL
is more intended to the partner's code, for them to specify Cryptocell specific function( in case it is common for several boards)
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.
If your question is about the TARGET_CRYPTOCELL310
, this is specifically the CC310 product. Future Cryptocell products will have a different target
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.
DEVICE_
is used for HAL, device capabilities, like trng
. Shouldn't this just be part of it? If cryptocell is enabled, it is used instead ? Does this new cryptocell provide own API or it's just what trng should use? Or does it need better name CRYPTOCELL_TRNG
?
I am confused what cryptocell is , why is it being defined as DEVICE_CRYPTOCELL
and needs extra label of its own to specify a version
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.
Cryptocell is Arm's HW accelerator.
perhaps DEVICE_CRYPTOCELL
is not the right MACRO, but I used device_has
, same way the MICROVISOR was used.
The extra label, is the actual target version, that partner should add\enable.
The DEVICE_CRYPTOCELL
is in compilation time, to determine in the partner's common code, for some functionality that should be compiled in \ out of the partner's specific code contains Cryptocell HW. I wouldn't limit it only for TRNG, but this is probably the most common case.
The Cryptocell trng implements same API for trng as any other trng driver, so I needed some special compilation flag to determine the specific board has cryptocell, to avoid multiple definition of same function.
Perhaps the Readme I just added could explain better.
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.
@sg- Please review (device_has and label addition)
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.
Is cryptocell part of the SoC or is it something separate? That you connect to the board/design?
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.
Cryptocell is an ARM security module that is part of the SoC.
The device brief mentions it several times: https://infocenter.nordicsemi.com/pdf/nRF52840_PB_v2.0.pdf
@0xc0170 I think the problem with CRYPTOCELL_TRNG
is that CRYPTOCELL appears to be more generic than simply applying to the TRNG.
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.
Cryptocell is Arm's HW crypto accelerator. It is more than just TRNG, this is why I defined it as DEVICE_CRYPTOCELL
, to add flexibility for the partner to decide whether to use Cryptocell or their code, if there are duplicates
@0xc0170 I eventually uploaded the porting guidelines to this PR. I am not sure if the location is OK. @AnotherButler Please review the Readme file |
* `MBEDTLS_CONFIG_HW_SUPPORT` to `macros_add` key. | ||
* `CRYPTOCELL` to `device_has_add` key. | ||
* `CRYPTOCELL310` to `extra_labels_add` key. | ||
1. In `objects.h`, include `objects_cryptocell.h`. (You can condition it with `#if DEVICE_CRYPTOCELL` in case you have another `trng` engine for a differnt board, and `objects.h` is common file for your boards, in this case your common `trng_api.c` file should be compiled only if `#if !defined(DEVICE_CRYPTOCELL)`). |
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.
This line confuses me. Could you please rewrite the second and third sentences for clarity?
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.
Please address the comment on line 17.
@AnotherButler I have added usage of the labels in |
* `MBEDTLS_CONFIG_HW_SUPPORT` to `macros_add` key. This is used to suggest there is HW accelerated cryptography engine that will replace the default Mbed TLS implementation. | ||
* `CRYPTOCELL` to `device_has_add` key. This should be used in your common code, that you need to remove from compilation in case CC exists in your board. Use `#if !defined(DEVICE_CRYPTOCELL)` or `#if DEVICE_CRYPTOCELL`. | ||
* `CRYPTOCELL310` to `extra_labels_add` key. This is used for the build system to look for the CC 310 code and binaries. | ||
1. In `objects.h`, include `objects_cryptocell.h`. You can use the `DEBICE_CRYPTOCELL` pre-compilation check as defined above. | ||
1. In `features/mbedtls/targets/TARGET_CRYPTOCELL310/TARGET_<target name>`, add your platform-specific libraries for all toolchains in `TOOLCHAIN_ARM`, `TOOLCHAIN_GCC_ARM` and `TOOLCHAIN_IAR` respectively. | ||
1. Add your CC setup code: | ||
* Implement `cc_platform_setup()` and `cc_platform_terminate()` to enable CC on your platform, in case you have such limitations. You can implement these functions as empty functions. |
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.
"in case you have such limitations"
Could you be more explicit in this document about which limitations you have in mind? It's not obvious which limitations are being referred to.
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.
perhaps limitations is not the proper wording. It was meant for board specific setup, prior to CC setup. I'll rephrase
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.
OK, this is explained well enough now. Thanks.
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.
@RonEld I've completed a final copy edit of this. Please review my changes to make sure I didn't accidentally change the meaning of anything.
}mbedtls_rand_func_container; | ||
|
||
|
||
uint32_t mbedtls_to_cc_rand_func( void *mbedtls_rnd_ctx, uint16_t outSizeBytes, uint8_t *out_ptr ) |
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.
This is defined in a header, yet not declared static
. Is that deliberate?
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.
As far as I see, this file is nowhere used. It seems to be a duplicate of code from cc_internal.h
and cc_internal.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.
@hanno-arm yes, it should have been removed, and probably returned on my rebase. I'll remove it
Thank you! The DK is the only one at the moment, but any future boards should be inheriting from MCU_NRF52840 so now we are future ready. |
Assure that `size_t` isn't larger than 32 bit, with preprocessor check. Using `#if SIZE_MAX > UINT_MAX`.
I addressed comment from @andresag01 regarding assuring the Current status: |
/morph build |
Build : SUCCESSBuild number : 2122 Triggering tests/morph test |
Shuffling around some jobs. /morph export-build |
/morph test |
Test : FAILUREBuild number : 1922 |
Exporter Build : SUCCESSBuild number : 1753 |
Log saved for further debugging. Restarting test since failure seems timing/CI load related. /morph test |
Test : SUCCESSBuild number : 1928 |
Description
Add support for Cryptocell 310.
Ported on Nrf52840_DK target.
Adds HW acceleration for the following cryptographic modules:
SHA1, SHA256, AES128_CCM,ECDH, ECDSA
Performance before modification(with ARMCC toolchain):
after acceleration:
Tested also with Mbed TLS self tests
Note: CCM self test passes only with Mbed-TLS/mbedtls#1598
This is a PR from the private repository - https://github.com/ARMmbed/mbed-os-cc-porting
Pull request type