ADAC: Check return value of psa_adac_generate_challenge
If psa_adac_generate_challenge fails, it should return an error
response to the client.
Signed-off-by: Maulik Patel <maulik.patel@arm.com>
Change-Id: I58476906fff9cd2e21a526fdf39ce047f3546ada
diff --git a/psa-adac/sda/src/psa_adac_sda.c b/psa-adac/sda/src/psa_adac_sda.c
index 0866f9a..d6b884a 100644
--- a/psa-adac/sda/src/psa_adac_sda.c
+++ b/psa-adac/sda/src/psa_adac_sda.c
@@ -80,6 +80,8 @@
}
response_packet_t *authentication_start(authentication_context_t *auth_ctx, request_packet_t *request) {
+ psa_status_t status;
+ response_packet_t *response;
(void) authenticator_request_packet_release(auth_ctx, request);
PSA_ADAC_LOG_DEBUG("auth", "Starting authentication\r\n");
auth_ctx->state = AUTH_CHALLENGE;
@@ -88,8 +90,13 @@
auth_ctx->challenge.format_version.major = 0x01;
auth_ctx->challenge.format_version.minor = 0x00;
auth_ctx->challenge._reserved = 0x00;
- psa_adac_generate_challenge(auth_ctx->challenge.challenge_vector, sizeof(auth_ctx->challenge.challenge_vector));
- response_packet_t *response = authenticator_response_packet_build(auth_ctx, 0x0, (uint8_t *) &auth_ctx->challenge,
+ status = psa_adac_generate_challenge(auth_ctx->challenge.challenge_vector, sizeof(auth_ctx->challenge.challenge_vector));
+ if (status != PSA_SUCCESS) {
+ PSA_ADAC_LOG_ERR("auth", "Failed to generate challenge!\r\n");
+ response = authenticator_response_packet_build(auth_ctx, ADAC_FAILURE, NULL, 0);
+ return response;
+ }
+ response = authenticator_response_packet_build(auth_ctx, 0x0, (uint8_t *) &auth_ctx->challenge,
sizeof(auth_ctx->challenge));
return response;
}