1586 Commits

Author SHA1 Message Date
Manuel Pégourié-Gonnard
4aad0ff510
Merge pull request #8632 from valeriosetti/issue8598
[G5] Make block_cipher work with PSA
2024-01-08 08:07:53 +00:00
Ryan Everett
1b70a07eca Replace psa_unlock_key_slot calls in operations which act on FULL slots
Replaces calls to psa_unlock_key_slot with calls to psa_unregister_read.

All instances follow a pattern of a call to psa_get_and_lock_key_slot_X,
followed by some code which reads from a slot, followed by a call to psa_unregister_read.

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-01-04 16:57:48 +00:00
Ryan Everett
c70ce576bd Update psa_destroy_key, psa_purge_key and psa_close_key
This does not yet implement destruction while a key is in use for psa_destroy_key;
that will be implemented in a separate pr.
(I am not sure if I am allowed to change the documentation in the include files.)

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-01-04 16:57:48 +00:00
Ryan Everett
098c6659ad Update psa_get_and_lock_key_slot_X functions
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-01-04 16:57:48 +00:00
Ryan Everett
b69118ebd0 Update key creation functions to use the new key slot states
Update psa_start_key_creation,
psa_finish_key_creation and psa_fail_key_creation.

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-01-04 16:57:48 +00:00
Ryan Everett
aa33c512cc Update psa_wipe_key_slot
Change psa_wipe_key_slot to use the new state system.

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-01-04 16:57:48 +00:00
Valerio Setti
384fbde49a library/tests: replace md_psa.h with psa_util.h as include file for MD conversion
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-01-02 13:27:32 +01:00
Valerio Setti
1fff4f2012 psa: add key_type as input parameter of psa_can_do_cipher()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-12-28 18:33:17 +01:00
Manuel Pégourié-Gonnard
cddab78612
Merge pull request #8630 from joerchan/mbedtls-tfm-compat
Mbedtls tfm compat
2023-12-15 09:31:27 +00:00
David Horstmann
62a56d966d Tweak the behaviour of copy handling macros
Specifically:
* Move the creation of the pointer to the copied buffer into the
  DECLARE() macro, to solve warnings about potentially skipping
  initialization.
* Reorder the arguments of the FREE() macro - having a different order
  made it confusing, so keep the order the same throughout.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-14 18:16:02 +00:00
Valerio Setti
c6f004f0e2 psa_crypto: add internal helper to signal that cipher driver is ready
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-12-14 18:08:14 +01:00
David Horstmann
36df4b24d4 Redesign local copy handling macros
* Separate initialization from allocation.
* Rewrite description of macros to fit the new interface.
* Use a longer name to store the local copy objects, to reduce the risk
  of shadowing.
* Use different names for the original and the copy. Append the suffix
  '_external' to the original argument and use the previous name
  for the copy.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-14 16:09:00 +00:00
Joakim Andersson
b349108b99 library: Move mbedtls_ecc helper functions to psa_util
Move the mbedtls_ecc helper functions from psa_core to psa_util.
These files are not implemented as part of the PSA API and should not
be part of the PSA crypto implementation.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2023-12-14 13:55:11 +01:00
Manuel Pégourié-Gonnard
1f67363d6a
Merge pull request #8616 from lpy4105/issue/8553/test-driver-only-rsa
Add test for driver-only RSA (crypto only)
2023-12-14 11:05:55 +00:00
David Horstmann
5a945f584e Put local output status in scope
This means that a unique name is no longer needed.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-13 14:09:08 +00:00
David Horstmann
d57c0731c9 Remove spaces around token-pasting macro operator
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-13 14:03:40 +00:00
David Horstmann
bf4ec79085 Make return statuses unique in FREE_LOCAL_OUTPUT()
Previously the return from psa_crypto_local_output_free() had a fixed
name, which meant that multiple outputs would cause redefinitions of the
same variable.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
3e72db4f51 Improve FREE_LOCAL_INPUT() and FREE_LOCAL_OUTPUT()
* Set swapped pointers to NULL when the buffers are freed.
* Change example name <buffer> to <input> and <output> to reduce
  confusion.
* Document assumptions of FREE_LOCAL_ macros.
* Add comment on error case in FREE_LOCAL_OUTPUT(), explaining why it's
  okay to mask the existing status code.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
00d7a04b82 Add more information to comment on test hooks
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
513101b00f Add MBEDTLS_PSA_COPY_CALLER_BUFFERS config option
This allows us to entirely remove copying code, where the convenience
macros are used for copying.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
e9a88ab0d5 Use macros to manage buffer copies
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
e138dce329 Change to use test-hook-based approach
Since we are applying hooks transparently to all tests, we cannot setup
and teardown test hooks in the tests. Instead we must do this in the
test wrappers which are used to pre-poison and unpoison memory.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
c6977b4899 Copy input and output in psa_cipher_encrypt()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
David Horstmann
372b8bb6c5 Add memory poisoning hooks
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-11 17:58:56 +00:00
Pengyu Lv
f75893bb36 Update comments
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-12-08 17:40:00 +08:00
Pengyu Lv
e9efbc2aa5 Error out when get domain_parameters is not supported
From time being, domain_parameters could not be extracted
from driver. We need to return error to indicate this
situation. This is temporary and would be fixed after #6494.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-12-08 17:30:26 +08:00
Valerio Setti
83e0de8481 crypto_extra: revert changes to mbedtls_psa_random_free()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-12-04 11:04:42 +01:00
Valerio Setti
402cfba4dc psa: free RNG implementation before checking for remaining open key slots
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-12-04 11:04:41 +01:00
Gilles Peskine
0457559323 Merge remote-tracking branch 'development' into development-restricted 2023-11-29 19:21:19 +01:00
Dave Rodgman
c94f8f1163
Merge pull request #8551 from daverodgman/sign-conversion-part1
Sign conversion part 1
2023-11-24 15:12:00 +00:00
Dave Rodgman
c7cc83cc44
Merge pull request #1119 from davidhorstmann-arm/psa-buffer-copy-fn
Implement buffer copying functions for PSA crypto
2023-11-24 10:46:38 +00:00
David Horstmann
9db14486da Use initializers in alloc functions
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-23 15:50:37 +00:00
Dave Rodgman
e4a6f5a7ec Use size_t cast for pointer subtractions
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-21 17:09:46 +00:00
David Horstmann
89875a4f20 Rename "output_copy" -> "local_output"
This helps to prevent confusion as it avoids overloading the word
"copy" as both an action and an object.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-20 17:55:13 +00:00
David Horstmann
f1734054fa Rename "input_copy" -> "local_input"
This helps to prevent confusion as it avoids overloading the word
"copy" as both an action and an object.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-20 17:54:57 +00:00
David Horstmann
2f307b4216 De-abbreviate "len" -> "length"
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-20 13:04:06 +00:00
David Horstmann
671f5f539e Change psa_crypto_copy_output error code
When we are copying output, it makes sense to return
PSA_ERROR_BUFFER_TOO_SMALL since the buffer we are copying to is a user
output buffer.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-20 13:03:43 +00:00
Ryan Everett
975d411d92 Only set slot to OCCUPIED on successful key loading
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2023-11-16 13:37:51 +00:00
David Horstmann
c5cc1c3a92 Remove redundant NULL check
A NULL buffer with a non-zero length is an internal error, so just
check the length.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-15 18:11:26 +00:00
David Horstmann
777e74130f Skip call to memcpy if buffer length is zero
This allows the copy functions to work when passed a (NULL, 0) buffer.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-15 17:38:46 +00:00
David Horstmann
1b7279a849 Make copy functions static-testable
This allows greater compiler optimisation.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-15 17:26:18 +00:00
Ryan Everett
ac5b32b894 Fix error handling for secure element keys in psa_start_key_creation
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2023-11-15 16:26:01 +00:00
David Horstmann
c335a4e186 Fix unintentional direct use of memcpy()
Change psa_crypto_output_copy_free() to use psa_crypto_copy_output()
rather than calling memcpy directly as was erroneously done previously.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-15 16:00:28 +00:00
David Horstmann
9467ea343b Add psa_crypto_output_copy_free() implementation
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-08 18:13:23 +00:00
David Horstmann
ba3c7d649c Add implementation of psa_crypto_output_alloc()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-08 18:13:23 +00:00
David Horstmann
e6042ffc49 Add implementation of psa_crypto_input_copy_free()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-08 18:13:23 +00:00
David Horstmann
4ac788573b Add psa_crypto_input_copy_alloc() implementation
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-08 15:22:27 +00:00
Ryan Everett
5567e3a34b Make empty key slots explicit
Add new status field to key slots, and use it.

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2023-11-08 13:28:20 +00:00
David Horstmann
b3de69493c Remove psa_crypto_alloc_and_copy() API
This tied input and output buffers together in
awkward pairs, which made the API more difficult
to use.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-06 17:45:09 +00:00
David Horstmann
49a7276c49 Switch error code to more appropriate value
Since we are internal rather than user-facing,
PSA_ERROR_CORRUPTION_DETECTED makes more sense than
PSA_ERROR_BUFFER_TOO_SMALL. Whilst it really is a buffer that is too
small, this error code is intended to indicate that a user-supplied
buffer is too small, not an internal one.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-03 19:51:40 +00:00