Skip to content

cc3xx_rsa_impl #195

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 689 commits into
base: main
Choose a base branch
from
Draft

cc3xx_rsa_impl #195

wants to merge 689 commits into from

Conversation

patryk1999
Copy link

No description provided.

adeaarm and others added 30 commits September 25, 2024 15:34
When MBEDTLS_PSA_CRYPTO_CLIENT is set, the client config
file can be reduced to the bare minimum required for TF-M
profiles and configurations. A client side application
might want to add their config to the bare minimum described
in the example client config here.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: Ifa6e7a3d3bb7af104a53f2eea6879ecefcd33e52
crypto_accelerator_config.h does not need to be located on
the api_ns exported tree as client configurations do not
need to include any accelerator specific config, as those
configurations are required only on the service side config.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I024cb83ac1cbfe471d21d78c7f0adc1c3db458c6
After the connection is successfully allocated, if the parameters
association fails, then the connection needs to be released.
This is only required for STATELESS connections for the reason that
for stateful connections those are taken care of as part of the
psa_close sequence.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: Ic0674098b7780a4e83b21fe93c5ed83ff5a2e8d1
After the connection is successfully allocated, if the parameters
association fails, then the connection needs to be released.
This is only required for STATELESS connections for the reason that
for stateful connections those are taken care of as part of the
psa_close sequence.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: Ic0674098b7780a4e83b21fe93c5ed83ff5a2e8d1
(cherry picked from commit 417063d)
TF-M allocates an array ns_mailbox_client_id_info[] for Mailbox NS Agent
SP to collect non-secure Client ID ranges. Non-secure client ID ranges
are filled in this const array when Mailbox NS Agent SP manifest file is
parsed. The array size is statically decided as well.
It was expected that platform mailbox implementation could make use of
this array for non-secure client ID translation.

However, this array is not used actually. Instead, TF-M mailbox
allocates another array client_id_regions[] for platform mailbox to
dynamically register client ID ranges.
This new array size is fixed to 2 and therefore it is unable to support
more Mailbox IRQs.

Make use of the existing Client ID range array as its size is aligned
with the number of Mailbox IRQ registered, to support more Mailbox IRQ
Client ID ranges.
Other changes:
 - Remove the duplicated fixed-size array client_id_regions[].
 - Define an array ns_mailbox_client_id_range_owner() to store
   non-secure clients.
 - Rework tfm_multi_core_register_client_id_range() to link non-secure
   client info to a specific non-secure Client ID range.
 - Update platform mailbox implementations.

Change-Id: Iea3823c3755346a67dbd6f6cc5e890cfb83f37c3
Signed-off-by: David Hu <[email protected]>
The data type of irq_source in the struct tfm_ns_mailbox_client_id_info
has been updated to uint32_t.
The input parameter irq_source of get_locality_from_irq_source() is from
tfm_ns_mailbox_client_id_info.irq_source. Update the input parameter
data type to uint32_t as well.

Change-Id: I5f2a57fbd507201c202920bbe05e9a3f353914ab
Signed-off-by: David Hu <[email protected]>
Adds the GIT_SHALLOW option to fetch_remote_library calls where possible
(when checking out a tag rather than a hash), which reduces the build
time in projects that do not use local checkouts.

Signed-off-by: Jamie Fox <[email protected]>
Change-Id: I4bee0ca65b34bb56c53038827ebcb3c2e49ee947
Commit 6293f55
("SPM: Delete connection critical section") removed the critical
sections around calls to spm_allocate_connection() but neglected to
remove the critical section in spm_free_connection().

Change-Id: Icfc38a0074bf248590f89d5dfc25abb5214ab01e
Signed-off-by: Chris Brand <[email protected]>
Unused variable in boot_save_shared_data()

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I9541cc6de494fdc26f8bd52d5a294d84eef1fac2
Platform ports have to override Mailbox signal handling utilities
MAILBOX_ENABLED_INTERRUPTS()/MAILBOX_SIGNAL_IS_ACTIVE()/
MAILBOX_SIGNAL_GET_ACTIVE(), if multiple mailbox signals are enabled or
their names are different from the default ones.

It becomes more inconvenient to implement platform-specific utilities if
more mailbox signals are enabled.

Use TF-M manifest tool to automatically generate a header file to
implement those platform-specific utilities, according to platform
mailbox signals. Platform ports don't have to manually implement those
utilities.

 - Add a ns_agent_mailbox_signal_utils.h.template for generating those
   utilities into ns_agent_mailbox_signal_utils.h
 - Let Mailbox NS Agent SP include ns_agent_mailbox_signal_utils.h
 - Remove all the other signal handing utilities.

Change-Id: I3aa257aaf65b589e88c4bfb3138f647afda9d60a
Signed-off-by: David Hu <[email protected]>
Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: Ic7d8f6045258df4697bdcef3869fd1c81d5a8bad
The integrity check value can be copied to a local buffer in the driver
before being checked, or read out from a local buffer after being
generated. At -O3, the compiler deduces that the local buffer is written
but not read (by the CPU), or read without being modified, and
eliminates the write or read. This patch adds a volatile qualifier to
the buffer to ensure the reads & writes actually occur.

Signed-off-by: Jamie Fox <[email protected]>
Change-Id: Icffb40ee1701079171cd0668c220b5b91e7fcd18
tfm_kconfig.py only imports GUI libraries when GUI is enabled.
Allows easier integration of Kconfig tests with CI.

Change-Id: If1f7c5e64fe3592b7374f558d4029fc844fe1bfe
Signed-off-by: Igor Silin <[email protected]>
If the requested_size from the scratch allocator is
greater than 0xfffffffc, the align macro overflows
without failing allocation thus allowing out-of-bounds
writes in the Crypto partition memory.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: Ic218fea8238ecd3e8d146586d2c413386870d580
Several places in the Crypto service directly write
without checking at least pointer validity (i.e. not
NULL) or out-of-bound access in the scratch buffer
writes. These mostly would lead to crashes, i.e. a
Denial-of-Service attack for which TF-M does not
protect against, but reduce the potential for more
serious attacks by protecting those writes anyway.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I4d60cca04162f15abd96a8c3fbe3683042b7b55d
Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: Ia41faa6c551e704f3ce6038ec311825deb8b1998
The bl2_mbedcrypto_config is linked to the psa_adac_cc312 target
so the MCUBOOT_PSA_CRYPTO_CONFIG_FILEPATH and
MCUBOOT_MBEDCRYPTO_CONFIG_FILEPATH configs are used for the ADAC
driver too. If MCUBOOT_USE_PSA_CRYPTO is OFF, that
means the MCUBOOT_PSA_CRYPTO_CONFIG_FILEPATH is not included
during the build so the PSA_WANT_ALG_SHA_256 is not defined for
the ADAC driver. Because of this, the PSA_HASH_MAX_SIZE is not
set correctly for the sources of the psa_adac_cc312 target. This
caused runtime issues. Note that this is relevant only when
MCUBOOT_USE_PSA_CRYPTO is not defined, as in that case the config
file is correctly included and propagated to the target.

Signed-off-by: Bence Balogh <[email protected]>
Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I50d69dc96f0ce7e66d55492b0c71105e650d664d
The Musca-B1's cmake is used as a reference. Updated the Corstone-1000
port to link the ADAC cmake targets to the correct crypto
configurations.

Signed-off-by: Bence Balogh <[email protected]>
Change-Id: Ib690f9729e06b0d566b3149bb539bcc503d121e3
The Mailbox partition is used as an NS Agent so its stack size is used
to determine the Process Stack bottom and PSLIM (Process Stack Pointer
Limit) during the SFN (Secure Function) backend initialization.

It has to be increased because a stackoverflow could happen with the
default 0x800 value which is coming from the TF-M default config files.
The new 0x1000 was chosen by trial, the regression tests pass with
this stack size.

Change-Id: Ib3fd523c4a1c3cf30d520eb0cb00c130c684eed5
Signed-off-by: Bence Balogh <[email protected]>
The declarations of some functions/objects are different from
corresponding implementation/definitions of them.
Fix those mismatches.

A lot of Crypto function's declarations and implementations are
different as well, due to the integration with Mbed TLS specific
underlying implementation. Keep the current implementation of Crypto.

Signed-off-by: David Hu <[email protected]>
Change-Id: I8a6f19d0cd1c5dd59e971a561db2a40e34c6d0ff
Signed-off-by: Anton Komlev <[email protected]>
Add a low-level driver API for setting the host_dcu_en bits
in the AO block. Such API is required to be called from ADAC
related call flows.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I180115047ab4097b91b88e009ff829e4a7169525
Signed-off-by: Anton Komlev <[email protected]>
Change-Id: I028c2baf34b5b779a0222c1628be74ff965c0f95
Signed-off-by: Gergely Korcsák <[email protected]>
Change-Id: I17148769106946a867042ec2b10f924db2a3336c
Remove executable permissions from an index.rst file in docs
as well.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: Ic2b0ed08d5a7707aff17f955ac3644074817bb2a
A few checks are missing from the mailbox message parameters:
 - NULL checks on vector pointers
 - maximum number of input vectors

Add such checks and move the related copy to local vectors
in a separate function.

Note that proper validation of the psa vectors on whether the
given addresses are valid is performed in the subsequent
'spm_associate_call_params' when processing
the call.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: Ife09a48ca9d8547ada3ac099cc1eb2b0c9cf3f17
If the validation of the vector parameters fails, the outvec are written
back regardless.
This may cause an out-of-bound write from the address that was previously
stored in original_out_vec and the length that could go passed the local
out_vec.

Note that this fix requires:
`tfm_spe_mailbox: Validate vectors from NSPE`

Prior to this change and the one above, it is possible to craft a couple
of mailbox messages to first write in vectors[1].in_vec a target value,
then a second message with:
 - a out_vec.len to go past out_vec[0], 6 for example
 - a target address for a PSA-ROT private storage, `ps_crypto_iv_buf`
   for example.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: Iadff8d6ba8160c1b757e6a1a9622473781b2027c
Security Advisory TFMV-8 is documented:
"Unchecked user-supplied pointer via mailbox messages may cause write
of arbitrary address".

Please check the advisory document for further details.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: Ieb72bbe046e4d909aab4728902fa5da61ab9bf0c
Assert on the validity of the input buffer only if the
input_length is different than 0. Calls with non-NULL
input and input_length == 0 are fairly normal, especially
when used only for authentication purposes.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I733341179dcbd04c3862050b1105474dd7322e77
Assert on the validity of the input buffer only if the
input_length is different than 0. Calls with non-NULL
input and input_length == 0 are fairly normal, especially
when used only for authentication purposes.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I733341179dcbd04c3862050b1105474dd7322e77
Minor tidy-up to use local in_vec and out_vec in local_copy_vects.

Signed-off-by: Nicola Mazzucato <[email protected]>
Suggested-by: Chris Brand <[email protected]>
Change-Id: I7179d668e42b27a1d18ccf727008cc47e549a7ef
maulik-arm and others added 29 commits December 2, 2024 14:13
Signed-off-by: Maulik Patel <[email protected]>
Change-Id: Ic452534cb8cb151ec87680162c8562725799eed6
Adds the platform porting layer required to support the SCMI Comms
partition.

Signed-off-by: Jamie Fox <[email protected]>
Change-Id: I7414afdfb2e14defe93747c33ed6ed4d2788e256
Adds the platform porting required to support the SCMI comms tests.

Signed-off-by: Jamie Fox <[email protected]>
Change-Id: I63b038edf1ae4cecd6bd07379533a8c9329e34bb
Prepare the environment where partition firmware update can be
enabled and platform specific bootloader configuration can be used.

FWU implementation provides an abstraction for the bootloader.
This bootloader abstraction layer is implemented for MCUBoot.
It can be used after making changes that can handle platform
specific behaviors. But the implementation limits it.

When TFM_PARTITION_FIRMWARE_UPDATE is enabled, the configuration
becomes invalid. Therefore, the invalid configuration is limited
to the case where TFM_FWU_BOOTLOADER_LIB is used for MCUboot.
This makes the configuration valid when a platform specific
configuration is used.

TFM_FWU_BOOTLOADER_LIB can only be added from a subdirectory, which
prevents the use of platform-specific bootloader configurations.
The logic has been changed to allow the use of platform-specific
bootloader configurations.

Change-Id: I4b258ca09f3f90580f2bf2f5b052c8c65eae5478
Signed-off-by: Ali Can Ozaslan <[email protected]>
In addition to the previous changes making TC headers common,a common
host_device_cfg.h can also be added. Note that we do not completely move
this header to the common directory, as the MHU device used for
SCP<->RSE communication differs between TC3 and TC4. Therefore, we need
to keep some definitions in the platform specific directory.

Change-Id: I564b5aa84ab1fd9c59738ce6e9d14d927f8abb37
Signed-off-by: Jackson Cooper-Driver <[email protected]>
Otherwise setting PLATFORM_DEFAULT_PS_HAL=OFF does not work

Change-Id: I3f6c00e76dca3427aff71b8d881a29110ccd12c5
Signed-off-by: Bohdan Hunko <[email protected]>
Signed-off-by: Jamie Fox <[email protected]>
Change-Id: Ic3da65aa8aac5427062fee079bda88daab50dfad
Signed-off-by: Anton Komlev <[email protected]>
Change-Id: If3bf712e740022e8c79937793604e8dfa932cfeb
Explicitly allow for variables to be defined at the
beginning of a scope, not necessarily of the function

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I6331fdd8e1fa15a1f9f23ac8e6187f0ab817c840
Resort to a simple word-aligned copy to fulfill driver requirements
when interacting with key management units on some hardware
platforms, but do not randomly shuffle bytes when copying.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: Ic0531a7c28b74e6f9743bfd02afa31a5c1b19ec6
Also, makes sure that the modulus of a not supported
curve is returned as zero and not as random data

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I193d5bba86adc9fc1bc962a60ba0a1f7d2f01e0f
curve_data, the global structure containing curve parameters,
is a const, so make sure it is handled through const * in
the functions that interface with it.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I56588bad4058209fbbe262fec7e7770c06cd6fc1
ITS_ENCRYPTION cannot be used when PSA_FRAMEWORK_HAS_MM_IOVEC
is also enabled.

ITS_ENCRYPTION requires buffers which are only available when
memory mapped vectors are disabled.

This miscoconfiguration fails to compile ITS with a compilation
error which is not very helpful. This makes it more clear what is
the issue.

Signed-off-by: Georgios Vasilakis <[email protected]>
Change-Id: I5de12aea8ebf76f5ce258fc16f2d1b9d053174cd
In the newer version the device is not allocated
dynamically, so we can remove the patches too.

Signed-off-by: Dávid Házi <[email protected]>
Change-Id: I6bbefa490f85bfa1884587fbcce3c83d11ae15aa
Some platforms come with multiple NPU configuration.
Modified the ETHOSU_ARCH cmake variable to CACHED
to make the configuration possible from commandline.

Added missing check_config.cmake files.

Signed-off-by: Dávid Házi <[email protected]>
Change-Id: Ia47ac4bc6ca8ea5b23c01c1addd3ecac44926ac6
update_caller_outvec_len is used in only one place (psa_api),
thus move it where it's used.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: I9071f645685a46190d5ccc5a21a20da8e48db56e
Move reporting of zero outvec data written inside
update_caller_outvec_len to have a common place where those vects
are updated.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: I3440235a045c4d3100c9602f4691835223643958
The field iovec_status is used to track the status of memory-mapped invecs
and outvecs through an encoding. Two bits used respectively for mapped and
unmapped status are set but not individually cleared.

In some places, those bits are checked but their conditions do not
reflect the right status for the vectors.

Improve the intent and use of the encoding by making _MAPPED_BIT and
_UNMAPPED_BIT mutually exclusive.

This avoids the situation where a mm-iovec is first mapped and then
correctly unmapped, while the respective status is both mapped and unmapped,
making checks confusing and not valid.

As a consequence, update the reporting of 'no data written' in outvects for
update_caller_outvec_len.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: I3137e74bc2d29b296ad698a41ee7896ab90f2110
tfm_crypto_call_srv performs the initialization and mapping of mm-iovecs
and after the required operation is completed, the outvecs are unmapped.

The invec are not unmapped though, resulting in a situation where
subsequent PSA calls would fail.

Note that currently this is not immediately visible due to the fact that
PSA crypto services are accessed via a static handle, so each call takes
a new connection with a clean mm-iovec status.
It would take a stateful Crypto service to actually fall into the issue
noticed above.

Signed-off-by: Nicola Mazzucato <[email protected]>
Reported-by: Brian Quach <[email protected]>
Change-Id: Idb4dc40ff439e177c64ddad2421f8febf6007dcb
psa_attest_get_token maps memory-mapped invec and outvec but only
unmaps the outvec.

Thus, add missing unmapping of invec.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: I7ad128a5bace89ddbc6b7241117061cd7b788601
This is a big change with two goals:
1) Add initial support for building nRF54L15 with upstream TF-M
2) Align the Nordic platform code between the upstream TF-M and
   Nordics TF-M fork

This change does NOT add support for nRF54L15 in upstream TF-M yet,
it only adds building support at the moment. More effort is needed
to allow running upstream TF-M in this platform. Most of the
configuration files for nRF54L15 are plain copies from the nRF5340
with light modifications to allow building.

This change brings an updated version of the nrfx library as well,
since it is needed to provide definitions for the nRF54L15.

Change-Id: I7543296f2ba839c5dd886fbc1231a5fedc23fd8f
Signed-off-by: Georgios Vasilakis <[email protected]>
Once the register_size is configured on the initialized PKA
engine, it can be retrieved through a getter function from
users of the PKA APIs to make sure they can check the sizes
of the values they are trying to load will fit the configured
register size.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I7c19a5676857dca0f4323a123e1a0f29e8d97dda
Make sure that the private key is consistently validated
both in the getpub() and sign() APIs of the lowlevel driver.
Add a common function which loads in the PKA and validates
against limits based on the loaded curve parameters. Also,
make sure that the length of the private_key is validated
initially only against the register_size, as that step makes
only sure that the private key can be loaded on the PKA.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: Ia75e3008352f1b1382b150f2f68ab73f049e97a3
Following eRPC test changes.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I0b5f2522450c99685678e65c9d824252ec02d1eb
Introduced by the latest commit.

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I2ecadef051f8131de9e6e93a61bf78af852060bb
Declare the shared memory region that is used for the MHU pointer
access protocol.

Signed-off-by: Michael Zhao <[email protected]>
Change-Id: Id654e6f01c5ab4ffd2b74a497c1d814247dee990
Explicitly control the addition of the cc3xx tests in
test suites through TEST_CC3XX and not CC3XX_RUNTIME_ENABLED
Mimics the same strategy as RSE builds

Signed-off-by: Antonio de Angelis <[email protected]>
Change-Id: I7e3fcc07c0edab5b1a089c03fe6ea60e439088bb
Signed-off-by: Patryk Kuklinski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.