mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-17 11:43:37 +00:00
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>
This commit is contained in:
parent
f1734054fa
commit
89875a4f20
@ -8540,50 +8540,50 @@ void psa_crypto_local_input_free(psa_crypto_local_input_t *local_input)
|
||||
local_input->length = 0;
|
||||
}
|
||||
|
||||
psa_status_t psa_crypto_output_copy_alloc(uint8_t *output, size_t output_len,
|
||||
psa_crypto_output_copy_t *output_copy)
|
||||
psa_status_t psa_crypto_local_output_alloc(uint8_t *output, size_t output_len,
|
||||
psa_crypto_local_output_t *local_output)
|
||||
{
|
||||
output_copy->original = NULL;
|
||||
output_copy->buffer = NULL;
|
||||
output_copy->length = 0;
|
||||
local_output->original = NULL;
|
||||
local_output->buffer = NULL;
|
||||
local_output->length = 0;
|
||||
|
||||
if (output_len == 0) {
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
output_copy->buffer = mbedtls_calloc(output_len, 1);
|
||||
if (output_copy->buffer == NULL) {
|
||||
local_output->buffer = mbedtls_calloc(output_len, 1);
|
||||
if (local_output->buffer == NULL) {
|
||||
/* Since we dealt with the zero-length case above, we know that
|
||||
* a NULL return value means a failure of allocation. */
|
||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
output_copy->length = output_len;
|
||||
output_copy->original = output;
|
||||
local_output->length = output_len;
|
||||
local_output->original = output;
|
||||
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
psa_status_t psa_crypto_output_copy_free(psa_crypto_output_copy_t *output_copy)
|
||||
psa_status_t psa_crypto_local_output_free(psa_crypto_local_output_t *local_output)
|
||||
{
|
||||
psa_status_t status;
|
||||
|
||||
if (output_copy->buffer == NULL) {
|
||||
output_copy->length = 0;
|
||||
if (local_output->buffer == NULL) {
|
||||
local_output->length = 0;
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
if (output_copy->original == NULL) {
|
||||
if (local_output->original == NULL) {
|
||||
/* We have an internal copy but nothing to copy back to. */
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
|
||||
status = psa_crypto_copy_output(output_copy->buffer, output_copy->length,
|
||||
output_copy->original, output_copy->length);
|
||||
status = psa_crypto_copy_output(local_output->buffer, local_output->length,
|
||||
local_output->original, local_output->length);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
mbedtls_free(output_copy->buffer);
|
||||
output_copy->buffer = NULL;
|
||||
output_copy->length = 0;
|
||||
mbedtls_free(local_output->buffer);
|
||||
local_output->buffer = NULL;
|
||||
local_output->length = 0;
|
||||
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
@ -883,13 +883,13 @@ psa_status_t psa_crypto_local_input_alloc(const uint8_t *input, size_t input_len
|
||||
*/
|
||||
void psa_crypto_local_input_free(psa_crypto_local_input_t *local_input);
|
||||
|
||||
typedef struct psa_crypto_output_copy_s {
|
||||
typedef struct psa_crypto_local_output_s {
|
||||
uint8_t *original;
|
||||
uint8_t *buffer;
|
||||
size_t length;
|
||||
} psa_crypto_output_copy_t;
|
||||
} psa_crypto_local_output_t;
|
||||
|
||||
#define PSA_CRYPTO_OUTPUT_COPY_INIT { NULL, NULL, 0 }
|
||||
#define PSA_CRYPTO_LOCAL_OUTPUT_INIT { NULL, NULL, 0 }
|
||||
|
||||
/** Allocate a local copy of an output buffer.
|
||||
*
|
||||
@ -897,31 +897,31 @@ typedef struct psa_crypto_output_copy_s {
|
||||
* output buffer but only allocates a buffer
|
||||
* whose contents will be copied back to the
|
||||
* original in a future call to
|
||||
* psa_crypto_output_copy_free().
|
||||
* psa_crypto_local_output_free().
|
||||
*
|
||||
* \param[in] output Pointer to output buffer.
|
||||
* \param[in] output_len Length of the output buffer.
|
||||
* \param[out] output_copy Pointer to a psa_crypto_output_copy_t struct to
|
||||
* populate with the output copy.
|
||||
* \param[out] local_output Pointer to a psa_crypto_local_output_t struct to
|
||||
* populate with the local output copy.
|
||||
* \return #PSA_SUCCESS, if the buffer was successfully
|
||||
* copied.
|
||||
* \return #PSA_ERROR_INSUFFICIENT_MEMORY, if a copy of
|
||||
* the buffer cannot be allocated.
|
||||
*/
|
||||
psa_status_t psa_crypto_output_copy_alloc(uint8_t *output, size_t output_len,
|
||||
psa_crypto_output_copy_t *output_copy);
|
||||
psa_status_t psa_crypto_local_output_alloc(uint8_t *output, size_t output_len,
|
||||
psa_crypto_local_output_t *local_output);
|
||||
|
||||
/** Copy from a local copy of an output buffer back to the original, then
|
||||
* free the local copy.
|
||||
*
|
||||
* \param[in] output_copy Pointer to a psa_crypto_output_copy_t struct
|
||||
* \param[in] local_output Pointer to a psa_crypto_local_output_t struct
|
||||
* populated by a previous call to
|
||||
* psa_crypto_output_copy_alloc().
|
||||
* \return #PSA_SUCCESS, if the output copy was
|
||||
* psa_crypto_local_output_alloc().
|
||||
* \return #PSA_SUCCESS, if the local output was
|
||||
* successfully copied back to the original.
|
||||
* \return #PSA_ERROR_CORRUPTION_DETECTED, if the output
|
||||
* could not be copied back to the original.
|
||||
*/
|
||||
psa_status_t psa_crypto_output_copy_free(psa_crypto_output_copy_t *output_copy);
|
||||
psa_status_t psa_crypto_local_output_free(psa_crypto_local_output_t *local_output);
|
||||
|
||||
#endif /* PSA_CRYPTO_CORE_H */
|
||||
|
@ -43,20 +43,20 @@ local_input_free:0
|
||||
PSA crypto local input round-trip
|
||||
local_input_round_trip
|
||||
|
||||
PSA crypto output copy alloc
|
||||
output_copy_alloc:200:PSA_SUCCESS
|
||||
PSA crypto local output alloc
|
||||
local_output_alloc:200:PSA_SUCCESS
|
||||
|
||||
PSA crypto output copy alloc, NULL buffer
|
||||
output_copy_alloc:0:PSA_SUCCESS
|
||||
PSA crypto local output alloc, NULL buffer
|
||||
local_output_alloc:0:PSA_SUCCESS
|
||||
|
||||
PSA crypto output copy free
|
||||
output_copy_free:200:0:PSA_SUCCESS
|
||||
PSA crypto local output free
|
||||
local_output_free:200:0:PSA_SUCCESS
|
||||
|
||||
PSA crypto output copy free, NULL buffer
|
||||
output_copy_free:0:0:PSA_SUCCESS
|
||||
PSA crypto local output free, NULL buffer
|
||||
local_output_free:0:0:PSA_SUCCESS
|
||||
|
||||
PSA crypto output copy free, NULL original buffer
|
||||
output_copy_free:200:1:PSA_ERROR_CORRUPTION_DETECTED
|
||||
PSA crypto local output free, NULL original buffer
|
||||
local_output_free:200:1:PSA_ERROR_CORRUPTION_DETECTED
|
||||
|
||||
PSA crypto output copy round-trip
|
||||
output_copy_round_trip
|
||||
PSA crypto local output round-trip
|
||||
local_output_round_trip
|
||||
|
@ -150,62 +150,62 @@ void local_input_round_trip()
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void output_copy_alloc(int output_len, psa_status_t exp_status)
|
||||
void local_output_alloc(int output_len, psa_status_t exp_status)
|
||||
{
|
||||
uint8_t *output = NULL;
|
||||
psa_crypto_output_copy_t output_copy;
|
||||
psa_crypto_local_output_t local_output;
|
||||
psa_status_t status;
|
||||
|
||||
output_copy.buffer = NULL;
|
||||
local_output.buffer = NULL;
|
||||
|
||||
TEST_CALLOC(output, output_len);
|
||||
|
||||
status = psa_crypto_output_copy_alloc(output, output_len, &output_copy);
|
||||
status = psa_crypto_local_output_alloc(output, output_len, &local_output);
|
||||
TEST_EQUAL(status, exp_status);
|
||||
|
||||
if (exp_status == PSA_SUCCESS) {
|
||||
TEST_ASSERT(output_copy.original == output);
|
||||
TEST_EQUAL(output_copy.length, output_len);
|
||||
TEST_ASSERT(local_output.original == output);
|
||||
TEST_EQUAL(local_output.length, output_len);
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_free(output_copy.buffer);
|
||||
output_copy.original = NULL;
|
||||
output_copy.buffer = NULL;
|
||||
output_copy.length = 0;
|
||||
mbedtls_free(local_output.buffer);
|
||||
local_output.original = NULL;
|
||||
local_output.buffer = NULL;
|
||||
local_output.length = 0;
|
||||
mbedtls_free(output);
|
||||
output = NULL;
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void output_copy_free(int output_len, int original_is_null,
|
||||
void local_output_free(int output_len, int original_is_null,
|
||||
psa_status_t exp_status)
|
||||
{
|
||||
uint8_t *output = NULL;
|
||||
uint8_t *buffer_copy_for_comparison = NULL;
|
||||
psa_crypto_output_copy_t output_copy = PSA_CRYPTO_OUTPUT_COPY_INIT;
|
||||
psa_crypto_local_output_t local_output = PSA_CRYPTO_LOCAL_OUTPUT_INIT;
|
||||
psa_status_t status;
|
||||
|
||||
if (!original_is_null) {
|
||||
TEST_CALLOC(output, output_len);
|
||||
}
|
||||
TEST_CALLOC(buffer_copy_for_comparison, output_len);
|
||||
TEST_CALLOC(output_copy.buffer, output_len);
|
||||
output_copy.length = output_len;
|
||||
output_copy.original = output;
|
||||
TEST_CALLOC(local_output.buffer, output_len);
|
||||
local_output.length = output_len;
|
||||
local_output.original = output;
|
||||
|
||||
if (output_copy.length != 0) {
|
||||
fill_buffer_pattern(output_copy.buffer, output_copy.length);
|
||||
memcpy(buffer_copy_for_comparison, output_copy.buffer, output_copy.length);
|
||||
if (local_output.length != 0) {
|
||||
fill_buffer_pattern(local_output.buffer, local_output.length);
|
||||
memcpy(buffer_copy_for_comparison, local_output.buffer, local_output.length);
|
||||
}
|
||||
|
||||
status = psa_crypto_output_copy_free(&output_copy);
|
||||
status = psa_crypto_local_output_free(&local_output);
|
||||
TEST_EQUAL(status, exp_status);
|
||||
|
||||
if (exp_status == PSA_SUCCESS) {
|
||||
TEST_ASSERT(output_copy.buffer == NULL);
|
||||
TEST_EQUAL(output_copy.length, 0);
|
||||
TEST_ASSERT(local_output.buffer == NULL);
|
||||
TEST_EQUAL(local_output.length, 0);
|
||||
TEST_MEMORY_COMPARE(buffer_copy_for_comparison, output_len,
|
||||
output, output_len);
|
||||
}
|
||||
@ -213,32 +213,32 @@ void output_copy_free(int output_len, int original_is_null,
|
||||
exit:
|
||||
mbedtls_free(output);
|
||||
mbedtls_free(buffer_copy_for_comparison);
|
||||
mbedtls_free(output_copy.buffer);
|
||||
output_copy.length = 0;
|
||||
mbedtls_free(local_output.buffer);
|
||||
local_output.length = 0;
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void output_copy_round_trip()
|
||||
void local_output_round_trip()
|
||||
{
|
||||
psa_crypto_output_copy_t output_copy;
|
||||
psa_crypto_local_output_t local_output;
|
||||
uint8_t output[200];
|
||||
uint8_t *buffer_copy_for_comparison = NULL;
|
||||
psa_status_t status;
|
||||
|
||||
status = psa_crypto_output_copy_alloc(output, sizeof(output), &output_copy);
|
||||
status = psa_crypto_local_output_alloc(output, sizeof(output), &local_output);
|
||||
TEST_EQUAL(status, PSA_SUCCESS);
|
||||
TEST_ASSERT(output_copy.buffer != output);
|
||||
TEST_ASSERT(local_output.buffer != output);
|
||||
|
||||
/* Simulate the function generating output */
|
||||
fill_buffer_pattern(output_copy.buffer, output_copy.length);
|
||||
fill_buffer_pattern(local_output.buffer, local_output.length);
|
||||
|
||||
TEST_CALLOC(buffer_copy_for_comparison, output_copy.length);
|
||||
memcpy(buffer_copy_for_comparison, output_copy.buffer, output_copy.length);
|
||||
TEST_CALLOC(buffer_copy_for_comparison, local_output.length);
|
||||
memcpy(buffer_copy_for_comparison, local_output.buffer, local_output.length);
|
||||
|
||||
psa_crypto_output_copy_free(&output_copy);
|
||||
TEST_ASSERT(output_copy.buffer == NULL);
|
||||
TEST_EQUAL(output_copy.length, 0);
|
||||
psa_crypto_local_output_free(&local_output);
|
||||
TEST_ASSERT(local_output.buffer == NULL);
|
||||
TEST_EQUAL(local_output.length, 0);
|
||||
|
||||
/* Check that the buffer was correctly copied back */
|
||||
TEST_MEMORY_COMPARE(output, sizeof(output),
|
||||
|
Loading…
x
Reference in New Issue
Block a user