Skip to content

Commit 92b1665

Browse files
committed
mgmt: updatehub: simplify code
Following the removal of legacy crypto support the code could be further simplified so this commit accomplish to this part. Signed-off-by: Valerio Setti <[email protected]>
1 parent 4c0de72 commit 92b1665

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

subsys/mgmt/updatehub/updatehub_integrity.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,19 @@ LOG_MODULE_DECLARE(updatehub, CONFIG_UPDATEHUB_LOG_LEVEL);
99

1010
#include "updatehub_integrity.h"
1111

12-
#define SUCCESS_VALUE PSA_SUCCESS
13-
1412
int updatehub_integrity_init(updatehub_crypto_context_t *ctx)
1513
{
16-
int ret;
14+
psa_status_t status;
1715

1816
if (ctx == NULL) {
1917
LOG_DBG("Invalid integrity context");
2018
return -EINVAL;
2119
}
2220

2321
*ctx = psa_hash_operation_init();
24-
ret = psa_hash_setup(ctx, PSA_ALG_SHA_256);
25-
if (ret != SUCCESS_VALUE) {
26-
LOG_DBG("Failed to %s SHA-256 operation. (%d)", "set up", ret);
22+
status = psa_hash_setup(ctx, PSA_ALG_SHA_256);
23+
if (status != PSA_SUCCESS) {
24+
LOG_DBG("Failed to %s SHA-256 operation. (%d)", "set up", status);
2725
return -EFAULT;
2826
}
2927

@@ -33,7 +31,7 @@ int updatehub_integrity_init(updatehub_crypto_context_t *ctx)
3331
int updatehub_integrity_update(updatehub_crypto_context_t *ctx,
3432
const uint8_t *buffer, const uint32_t len)
3533
{
36-
int ret;
34+
psa_status_t status;
3735

3836
if (ctx == NULL || buffer == NULL) {
3937
return -EINVAL;
@@ -44,10 +42,10 @@ int updatehub_integrity_update(updatehub_crypto_context_t *ctx,
4442
return 0;
4543
}
4644

47-
ret = psa_hash_update(ctx, buffer, len);
48-
if (ret != SUCCESS_VALUE) {
45+
status = psa_hash_update(ctx, buffer, len);
46+
if (status != PSA_SUCCESS) {
4947
psa_hash_abort(ctx);
50-
LOG_DBG("Failed to %s SHA-256 operation. (%d)", "update", ret);
48+
LOG_DBG("Failed to %s SHA-256 operation. (%d)", "update", status);
5149
return -EFAULT;
5250
}
5351

@@ -57,7 +55,7 @@ int updatehub_integrity_update(updatehub_crypto_context_t *ctx,
5755
int updatehub_integrity_finish(updatehub_crypto_context_t *ctx,
5856
uint8_t *hash, const uint32_t size)
5957
{
60-
int ret;
58+
psa_status_t status;
6159
size_t hash_len;
6260

6361
if (ctx == NULL || hash == NULL) {
@@ -69,10 +67,10 @@ int updatehub_integrity_finish(updatehub_crypto_context_t *ctx,
6967
return -EINVAL;
7068
}
7169

72-
ret = psa_hash_finish(ctx, hash, size, &hash_len);
73-
if (ret != SUCCESS_VALUE) {
70+
status = psa_hash_finish(ctx, hash, size, &hash_len);
71+
if (status != PSA_SUCCESS) {
7472
psa_hash_abort(ctx);
75-
LOG_DBG("Failed to %s SHA-256 operation. (%d)", "finish", ret);
73+
LOG_DBG("Failed to %s SHA-256 operation. (%d)", "finish", status);
7674
return -EFAULT;
7775
}
7876

subsys/mgmt/updatehub/updatehub_integrity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
extern "C" {
1414
#endif
1515

16-
#define SHA256_BIN_DIGEST_SIZE (32)
16+
#define SHA256_BIN_DIGEST_SIZE PSA_HASH_LENGTH(PSA_ALG_SHA_256)
1717
#define SHA256_HEX_DIGEST_SIZE ((SHA256_BIN_DIGEST_SIZE * 2) + 1)
1818

1919
typedef psa_hash_operation_t updatehub_crypto_context_t;

0 commit comments

Comments
 (0)