Patrick Williams | 975a06f | 2022-10-21 14:42:47 -0500 | [diff] [blame] | 1 | From a1da63a8c4d55d52321608a72129af49e0a498b2 Mon Sep 17 00:00:00 2001 |
| 2 | From: Satish Kumar <satish.kumar01@arm.com> |
| 3 | Date: Mon, 14 Feb 2022 08:22:25 +0000 |
| 4 | Subject: [PATCH 18/19] Fixes in AEAD for psa-arch test 54 and 58. |
| 5 | |
| 6 | Upstream-Status: Pending |
| 7 | Signed-off-by: Satish Kumar <satish.kumar01@arm.com> |
| 8 | Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> |
| 9 | --- |
| 10 | .../crypto/client/caller/packed-c/crypto_caller_aead.h | 1 + |
| 11 | components/service/crypto/include/psa/crypto_sizes.h | 2 +- |
| 12 | .../crypto/provider/extension/aead/aead_provider.c | 8 ++++++-- |
| 13 | .../extension/aead/serializer/aead_provider_serializer.h | 1 + |
| 14 | .../packed-c/packedc_aead_provider_serializer.c | 2 ++ |
| 15 | protocols/service/crypto/packed-c/aead.h | 1 + |
| 16 | 6 files changed, 12 insertions(+), 3 deletions(-) |
| 17 | |
| 18 | diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_aead.h b/components/service/crypto/client/caller/packed-c/crypto_caller_aead.h |
| 19 | index c4ffb20cf7f8..a91f66c14008 100644 |
| 20 | --- a/components/service/crypto/client/caller/packed-c/crypto_caller_aead.h |
| 21 | +++ b/components/service/crypto/client/caller/packed-c/crypto_caller_aead.h |
| 22 | @@ -309,6 +309,7 @@ static inline psa_status_t crypto_caller_aead_update(struct service_client *cont |
| 23 | size_t req_len = req_fixed_len; |
| 24 | |
| 25 | *output_length = 0; |
| 26 | + req_msg.output_size = output_size; |
| 27 | req_msg.op_handle = op_handle; |
| 28 | |
| 29 | /* Mandatory input data parameter */ |
| 30 | diff --git a/components/service/crypto/include/psa/crypto_sizes.h b/components/service/crypto/include/psa/crypto_sizes.h |
| 31 | index 4d7bf6e959b0..e3c4df2927b3 100644 |
| 32 | --- a/components/service/crypto/include/psa/crypto_sizes.h |
| 33 | +++ b/components/service/crypto/include/psa/crypto_sizes.h |
| 34 | @@ -351,7 +351,7 @@ |
| 35 | * just the largest size that may be generated by |
| 36 | * #psa_aead_generate_nonce(). |
| 37 | */ |
| 38 | -#define PSA_AEAD_NONCE_MAX_SIZE 12 |
| 39 | +#define PSA_AEAD_NONCE_MAX_SIZE 16 |
| 40 | |
| 41 | /** A sufficient output buffer size for psa_aead_update(). |
| 42 | * |
| 43 | diff --git a/components/service/crypto/provider/extension/aead/aead_provider.c b/components/service/crypto/provider/extension/aead/aead_provider.c |
| 44 | index 14a25436b3f6..6b144db821de 100644 |
| 45 | --- a/components/service/crypto/provider/extension/aead/aead_provider.c |
| 46 | +++ b/components/service/crypto/provider/extension/aead/aead_provider.c |
| 47 | @@ -283,10 +283,11 @@ static rpc_status_t aead_update_handler(void *context, struct call_req *req) |
| 48 | uint32_t op_handle; |
| 49 | const uint8_t *input; |
| 50 | size_t input_len; |
| 51 | + uint32_t recv_output_size; |
| 52 | |
| 53 | if (serializer) |
| 54 | rpc_status = serializer->deserialize_aead_update_req(req_buf, &op_handle, |
| 55 | - &input, &input_len); |
| 56 | + &recv_output_size, &input, &input_len); |
| 57 | |
| 58 | if (rpc_status == TS_RPC_CALL_ACCEPTED) { |
| 59 | |
| 60 | @@ -300,9 +301,12 @@ static rpc_status_t aead_update_handler(void *context, struct call_req *req) |
| 61 | if (crypto_context) { |
| 62 | |
| 63 | size_t output_len = 0; |
| 64 | - size_t output_size = PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(input_len); |
| 65 | + size_t output_size = PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(24); |
| 66 | uint8_t *output = malloc(output_size); |
| 67 | |
| 68 | + if (recv_output_size < output_size) { |
| 69 | + output_size = recv_output_size; |
| 70 | + } |
| 71 | if (output) { |
| 72 | |
| 73 | psa_status = psa_aead_update(&crypto_context->op.aead, |
| 74 | diff --git a/components/service/crypto/provider/extension/aead/serializer/aead_provider_serializer.h b/components/service/crypto/provider/extension/aead/serializer/aead_provider_serializer.h |
| 75 | index bb1a2a97e4b7..0156aaba3fe3 100644 |
| 76 | --- a/components/service/crypto/provider/extension/aead/serializer/aead_provider_serializer.h |
| 77 | +++ b/components/service/crypto/provider/extension/aead/serializer/aead_provider_serializer.h |
| 78 | @@ -51,6 +51,7 @@ struct aead_provider_serializer { |
| 79 | /* Operation: aead_update */ |
| 80 | rpc_status_t (*deserialize_aead_update_req)(const struct call_param_buf *req_buf, |
| 81 | uint32_t *op_handle, |
| 82 | + uint32_t *output_size, |
| 83 | const uint8_t **input, size_t *input_len); |
| 84 | |
| 85 | rpc_status_t (*serialize_aead_update_resp)(struct call_param_buf *resp_buf, |
| 86 | diff --git a/components/service/crypto/provider/extension/aead/serializer/packed-c/packedc_aead_provider_serializer.c b/components/service/crypto/provider/extension/aead/serializer/packed-c/packedc_aead_provider_serializer.c |
| 87 | index 6f00b3e3f6f1..45c739abcbb4 100644 |
| 88 | --- a/components/service/crypto/provider/extension/aead/serializer/packed-c/packedc_aead_provider_serializer.c |
| 89 | +++ b/components/service/crypto/provider/extension/aead/serializer/packed-c/packedc_aead_provider_serializer.c |
| 90 | @@ -192,6 +192,7 @@ static rpc_status_t deserialize_aead_update_ad_req(const struct call_param_buf * |
| 91 | /* Operation: aead_update */ |
| 92 | static rpc_status_t deserialize_aead_update_req(const struct call_param_buf *req_buf, |
| 93 | uint32_t *op_handle, |
| 94 | + uint32_t *output_size, |
| 95 | const uint8_t **input, size_t *input_len) |
| 96 | { |
| 97 | rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY; |
| 98 | @@ -208,6 +209,7 @@ static rpc_status_t deserialize_aead_update_req(const struct call_param_buf *req |
| 99 | memcpy(&recv_msg, req_buf->data, expected_fixed_len); |
| 100 | |
| 101 | *op_handle = recv_msg.op_handle; |
| 102 | + *output_size = recv_msg.output_size; |
| 103 | |
| 104 | tlv_const_iterator_begin(&req_iter, |
| 105 | (uint8_t*)req_buf->data + expected_fixed_len, |
| 106 | diff --git a/protocols/service/crypto/packed-c/aead.h b/protocols/service/crypto/packed-c/aead.h |
| 107 | index 0be266b52403..435fd3b523ce 100644 |
| 108 | --- a/protocols/service/crypto/packed-c/aead.h |
| 109 | +++ b/protocols/service/crypto/packed-c/aead.h |
| 110 | @@ -98,6 +98,7 @@ enum |
| 111 | struct __attribute__ ((__packed__)) ts_crypto_aead_update_in |
| 112 | { |
| 113 | uint32_t op_handle; |
| 114 | + uint32_t output_size; |
| 115 | }; |
| 116 | |
| 117 | /* Variable length input parameter tags */ |
| 118 | -- |
| 119 | 2.38.0 |
| 120 | |