Skip to content

Commit 5c5017b

Browse files
committed
Addressed Reviewer's + copilot's comments.
1 parent 1ec71aa commit 5c5017b

5 files changed

Lines changed: 34 additions & 15 deletions

File tree

hal/stm32l5.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626

2727
#if defined(WOLFBOOT_HASH_SHA256)
2828
#include <wolfssl/wolfcrypt/sha256.h>
29-
#elif defined(WOLFBOOT_HASH_SHA384) || defined(WOLFBOOT_HASH_SHA3_384)
29+
#elif defined(WOLFBOOT_HASH_SHA384)
3030
#include <wolfssl/wolfcrypt/sha512.h>
31+
#elif defined(WOLFBOOT_HASH_SHA3_384)
32+
#include <wolfssl/wolfcrypt/sha3.h>
3133
#endif
3234

3335
#include "hal.h"
@@ -121,9 +123,12 @@ static int uds_from_uid(uint8_t *out, size_t out_len)
121123
#if defined(WOLFBOOT_HASH_SHA256)
122124
uint8_t digest[SHA256_DIGEST_SIZE];
123125
wc_Sha256 hash;
124-
#else
126+
#elif defined(WOLFBOOT_HASH_SHA384)
125127
uint8_t digest[SHA384_DIGEST_SIZE];
126128
wc_Sha384 hash;
129+
#elif defined(WOLFBOOT_HASH_SHA3_384)
130+
uint8_t digest[SHA3_384_DIGEST_SIZE];
131+
wc_Sha3 hash;
127132
#endif
128133
size_t copy_len;
129134

@@ -149,11 +154,16 @@ static int uds_from_uid(uint8_t *out, size_t out_len)
149154
wc_Sha256Update(&hash, uid, sizeof(uid));
150155
wc_Sha256Final(&hash, digest);
151156
copy_len = sizeof(digest);
152-
#else
157+
#elif defined(WOLFBOOT_HASH_SHA384)
153158
wc_InitSha384(&hash);
154159
wc_Sha384Update(&hash, uid, sizeof(uid));
155160
wc_Sha384Final(&hash, digest);
156161
copy_len = sizeof(digest);
162+
#elif defined(WOLFBOOT_HASH_SHA3_384)
163+
wc_InitSha3_384(&hash, NULL, INVALID_DEVID);
164+
wc_Sha3_384_Update(&hash, uid, sizeof(uid));
165+
wc_Sha3_384_Final(&hash, digest);
166+
copy_len = sizeof(digest);
157167
#endif
158168

159169
if (copy_len > out_len) {

src/arm_tee_psa_ipc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,6 @@ static psa_status_t wolfboot_crypto_dispatch(const psa_invec *in_vec,
569569
out_vec[0].len = sizeof(uint32_t);
570570
return PSA_SUCCESS;
571571
}
572-
(void)psa_hash_abort(&slot->op);
573572
wolfboot_hash_free(iov->op_handle);
574573
*(uint32_t *)out_vec[0].base = 0;
575574
out_vec[0].len = sizeof(uint32_t);
@@ -665,7 +664,6 @@ static psa_status_t wolfboot_crypto_dispatch(const psa_invec *in_vec,
665664
struct wolfboot_cipher_slot *slot;
666665
slot = wolfboot_cipher_find(iov->op_handle);
667666
if (slot != NULL) {
668-
(void)psa_cipher_abort(&slot->op);
669667
wolfboot_cipher_free(iov->op_handle);
670668
}
671669
return PSA_SUCCESS;

test-app/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ ifeq ($(TARGET),aurix_tc3xx)
679679
endif
680680

681681
# Capture final flags for locally built wolfSSL objects.
682-
WOLFSSL_CFLAGS:=$(CFLAGS)
682+
WOLFSSL_CFLAGS=$(CFLAGS)
683683

684684
ifeq ($(WOLFHSM_CLIENT),1)
685685
CFLAGS += -DSTRING_USER -I"$(WOLFBOOT_LIB_WOLFSSL)"

test-app/app_stm32h5.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,9 @@ static int run_psa_boot_attestation(void)
709709
psa_status_t status;
710710
uint8_t challenge[PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64];
711711
uint8_t token[1024];
712+
#if (APP_HASH_SIZE > 0u)
712713
uint8_t hash_buf[APP_HASH_SIZE];
714+
#endif
713715
size_t token_size = 0;
714716
int ret = 0;
715717
size_t i;
@@ -721,6 +723,7 @@ static int run_psa_boot_attestation(void)
721723

722724
printf(" step 3: compute wolfBoot measurement\r\n");
723725
#if defined(WOLFBOOT_PARTITION_BOOT_ADDRESS) && defined(ARCH_FLASH_OFFSET)
726+
#if (APP_HASH_SIZE > 0u)
724727
if (ret == 0) {
725728
uintptr_t start = (uintptr_t)ARCH_FLASH_OFFSET;
726729
uintptr_t end = (uintptr_t)WOLFBOOT_PARTITION_BOOT_ADDRESS;
@@ -736,6 +739,9 @@ static int run_psa_boot_attestation(void)
736739
print_hex(hash_buf, APP_HASH_SIZE, 0);
737740
}
738741
}
742+
#else
743+
printf(" step 3: hash algorithm not enabled\r\n");
744+
#endif
739745
#else
740746
printf(" step 3: wolfBoot region unavailable for hashing\r\n");
741747
#endif

zephyr/src/arm_tee_crypto_api.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation,
406406
const uint8_t *iv,
407407
size_t iv_length)
408408
{
409+
if (operation == NULL || (iv == NULL && iv_length > 0)) {
410+
return PSA_ERROR_INVALID_ARGUMENT;
411+
}
412+
409413
struct arm_tee_crypto_pack_iovec iov = {
410414
.function_id = ARM_TEE_CRYPTO_CIPHER_SET_IV_SID,
411415
.op_handle = (uint32_t)operation->opaque,
@@ -415,10 +419,6 @@ psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation,
415419
{.base = iv, .len = iv_length},
416420
};
417421

418-
if (operation == NULL || (iv == NULL && iv_length > 0)) {
419-
return PSA_ERROR_INVALID_ARGUMENT;
420-
}
421-
422422
return API_DISPATCH_NO_OUTVEC(in_vec);
423423
}
424424

@@ -487,6 +487,12 @@ psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
487487

488488
psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation)
489489
{
490+
psa_status_t status;
491+
492+
if (operation == NULL) {
493+
return PSA_ERROR_INVALID_ARGUMENT;
494+
}
495+
490496
struct arm_tee_crypto_pack_iovec iov = {
491497
.function_id = ARM_TEE_CRYPTO_CIPHER_ABORT_SID,
492498
.op_handle = (uint32_t)operation->opaque,
@@ -495,12 +501,11 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation)
495501
{.base = &iov, .len = sizeof(struct arm_tee_crypto_pack_iovec)},
496502
};
497503

498-
if (operation == NULL) {
499-
return PSA_ERROR_INVALID_ARGUMENT;
504+
status = API_DISPATCH_NO_OUTVEC(in_vec);
505+
if (status == PSA_SUCCESS) {
506+
operation->opaque = 0;
500507
}
501-
502-
operation->opaque = 0;
503-
return API_DISPATCH_NO_OUTVEC(in_vec);
508+
return status;
504509
}
505510

506511
psa_status_t psa_sign_hash(psa_key_id_t key,

0 commit comments

Comments
 (0)