7453 Commits

Author SHA1 Message Date
David Horstmann
0760b15d45 Add memory poisoning hooks
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-12-20 14:49:41 +00:00
Dave Rodgman
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
David Horstmann
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
David Horstmann
0d52c71ccd Use initializers in alloc functions
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-23 16:04:11 +00:00
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
48ffb93d7f De-abbreviate "len" -> "length"
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
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
David Horstmann
34c434a3ca Add initializers for input / output copies
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
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
David Horstmann
1cc21c31a9 Add function prototypes for copying functions
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:37:17 +00:00
Dave Rodgman
a645708949 Restore bump version
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-08 11:50:57 +00:00
Dave Rodgman
287ab6edb2 Update header
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-03 12:58:29 +00:00
Dave Rodgman
7ff7965561 Update headers
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-03 12:04:52 +00:00
Bence Szépkúti
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
Dave Rodgman
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
Dave Rodgman
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
Pengyu Lv
f3c6e2ee34 aesni: select __cpuid impl based on compiler type
MinGW provides both kinds of implementations of `__cpuid`,
but since `cpuid.h` is provided by GNUC, so we should choose
the implementation by the compiler type instead of OS type.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-10-19 16:45:37 +08:00
Pengyu Lv
79d7faf030 aesni: declare cpuinfo as int
Change the type of array that stores the cpuinfo
data to int[4] to match the signature of `__cpuinfo`
in `intrin.h` header file.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-10-19 16:45:37 +08:00
Pengyu Lv
2856e076e6 aesni: support cpuid on WIN32
`__cpuid` has two kinds of signatures in different
headers depending on the target OS. We make it
consistent between the usages ang the included header.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-10-19 16:45:36 +08:00
Sergey Markelov
9902a6b752 Fix #8372 - Error compiling AESNI in Mbed-TLS with clang on Windows
It can successfully compile w/ or w/o the clang options -maes -mpclmul.

Signed-off-by: Sergey Markelov <sergey@solidstatenetworks.com>
2023-10-18 20:26:01 -07:00
Bence Szépkúti
01902779a3
Merge pull request #8162 from yanrayw/2.28-save_stack_usage_pkwrite
Backport 2.28: pkwrite: use heap to save stack usage for writing keys in PEM string
2023-10-13 14:27:18 +00:00
Jerzy Kasenberg
1222ae67d5 Rename local variable in aes.c
This changes local variable name RCON to round_constants.

RCON being definition in xc32 compiler headers for some PIC32 register.
Without this change mynewt project for PIC32 platform fails to build due to
macro redefinition.

This does not changes behavior of library in any way.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
2023-10-12 09:16:34 +02:00
Minos Galanakis
c7a8ea998d Bump version to 2.28.5
```
./scripts/bump_version.sh --version 2.28.5
```

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2023-10-03 22:24:04 +01:00
Minos Galanakis
6d169947e9 Merge branch 'mbedtls-2.28-restricted' into mbedtls-2.28.5rc0-pr
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2023-10-03 22:22:36 +01:00
Dave Rodgman
da635ab657
Merge pull request #8280 from gilles-peskine-arm/ssl_cache-negative_errors-2.28
Backport 2.28: ssl_cache: misc improvements
2023-09-29 17:58:10 +00:00
Gilles Peskine
fe4d93ad4d ssl_cache: return error codes on error
mbedtls_ssl_cache_get() and mbedtls_ssl_cache_set() returned 1 on many error
conditions. Change this to returning a negative MBEDTLS_ERR_xxx error code.

Completeness: after this commit, there are no longer any occurrences of
`return 1` or `ret = 1`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-29 13:40:33 +02:00
Gilles Peskine
917dd8bd81 Add new error code for SSL cache entry not found
There was no good error to return in this case.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-29 13:39:49 +02:00
JonathanWitthoeft
930679a1d7 Make mbedtls_ecdsa_can_do definition unconditional
Signed-off-by: JonathanWitthoeft <jonw@gridconnect.com>
2023-09-29 13:31:48 +02:00