Paul Elliott
20e76134ea
Merge pull request #8557 from gilles-peskine-arm/metatest-gcc-12-2.28
...
Backport 2.28: Fix metatest.c with gcc-12 -Wuse-after-free
2023-11-23 11:09:24 +00:00
Gilles Peskine
c3a9bdb2b5
Detect enabled GCC/Clang sanitizers
...
Occasionally we want tests to take advantage of sanitizers, or work around
them.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-22 18:00:31 +01:00
Gilles Peskine
e9616fdbc9
Fix the build with gcc-12 -Wuse-after-free
...
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-22 17:37:57 +01: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
37e3fc6c76
Remove unnecessary checks for NULL-ness of copies
...
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
d79d5e7ed0
Check for len == 0 rather than buffer == NULL
...
This makes the intention clearer
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
2d730c015e
Compare buffers even for zero-length cases
...
This enables us to test that lengths are correctly zero when the buffer
pointer is NULL.
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
0ee4d18bc6
Use TEST_CALLOC_NONNULL
...
Check that input/output copying works for zero-length NULL input
buffers.
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 15:07:31 +00:00
David Horstmann
e8a92227dc
Change data pattern to simpler one
...
Just use the index modulo 256, as this has a greater stride and is
simpler to use.
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
ba65bd79e8
Add output round-trip testcase
...
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:59:17 +00:00
David Horstmann
aca210d4c7
Add input round-trip testcase
...
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
3bc1316ceb
Add testcase for psa_crypto_output_copy_free()
...
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
1acf7afa83
Add testcase for psa_crypto_output_copy_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
6790a6d36f
Add testcase for 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
89299c476c
Add testcase for psa_crypto_input_copy_alloc()
...
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
93e08c6db6
Move buffer copy tests into new testsuite
...
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:56:46 +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
89b4caab53
Switch to TEST_CALLOC_NONNULL()
...
This removes some gubbins related to making sure the buffer is not NULL
that was previously cluttering the test case.
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:09 +00:00
David Horstmann
113f2d46b0
Switch from ret to status as naming convention
...
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:09 +00:00
David Horstmann
7a31ac02ab
Switch from int to psa_status_t for test args
...
Remove unnecessary casts as well.
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:09 +00:00
David Horstmann
818b39dbc3
Remove psa_crypto_ prefix from test functions
...
This ensures they have a different name to the functions they test.
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:09 +00:00
David Horstmann
34342a2410
Remove superfluous comment
...
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:09 +00:00
David Horstmann
f38eb76b34
Replace compound-initializers with memset
...
This should eliminate some pedantic compiler warnings.
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:08 +00:00
David Horstmann
121994f33e
Refactor: move buffer pattern fills into helper
...
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:50:06 +00:00
David Horstmann
5e0b4f8b42
Add full round-trip tests for buffer copying
...
Test that a buffer pair can be created with psa_crypto_alloc_and_copy()
and destroyed with psa_crypto_copy_and_free() correctly.
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:48:00 +00:00
David Horstmann
406d28ba87
Add test case for overlapping buffers
...
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:47:58 +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
9ecd53d1bb
Add testcases for 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
ea08ab775d
Zero-length test for psa_crypto_alloc_and_copy()
...
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-11-22 14:44:18 +00:00
David Horstmann
41966d7433
Add extra testcases for buffer copying
...
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