1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-05 19:01:12 +03:00
Commit Graph

7465 Commits

Author SHA1 Message Date
b80e35a54a 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-20 14:49:41 +00:00
926193a93d 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-20 14:49:41 +00:00
2b70a66118 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-20 14:49:41 +00:00
f96ae67a76 Remove spaces around token-pasting macro operator
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
e800aa8d34 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-20 14:49:41 +00:00
1f53213830 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-20 14:49:41 +00:00
114d82407c Add more information to comment on test hooks
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
2b10b3713d Remove unnecessary include directory from CMake
Since psa_crypto.c does not include tests/include/test/memory.h, we do
not need the tests/include include path.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
c0a2c30252 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-20 14:49:41 +00:00
34980bd832 Use macros to manage buffer copies
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
63f82f7c0c 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-20 14:49:41 +00:00
d2ad886258 Copy input and output in psa_cipher_encrypt()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
0760b15d45 Add memory poisoning hooks
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
806c27c5f4 Merge pull request #1126 from davidhorstmann-arm/psa-buffer-copy-fn-2.28
[Backport 2.28] Implement buffer copying functions for PSA crypto
2023-11-24 10:46:31 +00:00
8e1f0d0d31 Improve description of psa_crypto_input_copy_alloc
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-23 16:04:11 +00:00
0d52c71ccd Use initializers in alloc functions
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-23 16:04:11 +00:00
45221ffdc4 Add casts to local input / output initializers
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-23 16:04:11 +00:00
1a76ab1c34 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-22 15:09:04 +00:00
81a0d57e36 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-22 15:09:02 +00:00
48ffb93d7f De-abbreviate "len" -> "length"
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
232ab25bcd 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-22 15:07:31 +00:00
34c434a3ca Add initializers for input / output copies
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
c3be8cb24a Fix code style in psa_crypto_core.h
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
726bf058fe 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-22 15:07:31 +00:00
660027f310 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-22 15:07:31 +00:00
df49355faa Make copy functions static-testable
This allows greater compiler optimisation.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:29 +00:00
761761ff64 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-22 14:59:17 +00:00
aeeb2740a9 Add psa_crypto_output_copy_free() implementation
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
953cd5b372 Add implementation of psa_crypto_output_alloc()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
b80367e3b4 Add function prototypes for psa_crypto_output fns
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
fa2d75d30a Add implementation of psa_crypto_input_copy_free()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
8d9d4fe20d Add psa_crypto_input_copy_alloc() implementation
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
f0ec6e87b1 Add prototypes for psa_crypto_input_copy API
This includes:
* The psa_crypto_input_copy_t struct
* psa_crypto_input_copy_alloc()
* psa_crypto_input_copy_free()

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
cbdec9e470 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-22 14:59:17 +00:00
8684ad548f 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-22 14:50:09 +00:00
7131b8eecc Reject zero-lengths in psa_crypto_copy_and_free()
Zero-length buffers should be represented in the
psa_crypto_buffer_copy_t struct as NULL if it was created in
psa_crypto_alloc_and_copy(), so reject non-NULL zero-length buffers.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:44:18 +00:00
0368d20d51 Reject NULL original_output with non-NULL output
If we have a copy buffer but no original to copy back to, there is not
much sensible we can do. The psa_crypto_buffer_copy_t state is invalid.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:44:18 +00:00
5847b70829 Add implementation of psa_crypto_copy_and_free()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:44:18 +00:00
0e38180e1d Simplify zero-length buffers to always be NULL
Since it is implementation-dependent whether
malloc(0) returns NULL or a pointer, explicitly
represent zero-length buffers as NULL in the
buffer-copy struct, so as to have a uniform
behaviour.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:44:18 +00:00
cc4dfa6892 Add implementation of psa_crypto_alloc_and_copy()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:44:18 +00:00
a707a6f56d Add buffers struct and prototypes for alloc API
Add function prototypes for psa_crypto_alloc_and_copy() and
psa_crypto_alloc_and_free(), along with the necessary state struct.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:44:18 +00:00
2bd296e890 Add implementation of psa_crypto_copy_output()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:44:18 +00:00
957f980379 Add implementation of psa_crypto_copy_input()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:44:16 +00:00
1cc21c31a9 Add function prototypes for copying functions
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:37:17 +00:00
a645708949 Restore bump version
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-08 11:50:57 +00:00
287ab6edb2 Update header
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-03 12:58:29 +00:00
7ff7965561 Update headers
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-03 12:04:52 +00:00
3ccb844117 Merge pull request #8373 from sergio-nsk/sergio-nsk/8372/1
Backport 2.28: Fix compiling AESNI in Mbed-TLS with clang on Windows
2023-10-26 15:59:05 +00:00
37b8478ab8 Merge pull request #8403 from daverodgman/iar-fixes-2.28
Backport 2.28: Stop IAR warning about goto skipping variable definition
2023-10-23 14:59:33 +01:00
2af05c857a Stop IAR warning about goto skipping variable definition
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-10-23 11:04:36 +01:00