Skip to content

Commit 4c0de72

Browse files
committed
mgmt: updatehub: remove legacy Mbed TLS crypto support
The long-term Zephyr's goal is rely only on PSA Crypto API for crypto support in Zephyr and at the same time Mbed TLS will remove this support from the next release. Therefore this commit removes usage of legacy crypto hash support from updatehub. Signed-off-by: Valerio Setti <[email protected]>
1 parent d99cddd commit 4c0de72

File tree

3 files changed

+5
-39
lines changed

3 files changed

+5
-39
lines changed

subsys/mgmt/updatehub/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ menuconfig UPDATEHUB
1818
select IMG_ENABLE_IMAGE_CHECK
1919
select MPU_ALLOW_FLASH_WRITE
2020
select MBEDTLS if !BUILD_WITH_TFM
21-
select MBEDTLS_SHA256 if !PSA_CRYPTO_CLIENT
21+
select MBEDTLS_PSA_CRYPTO_C if !BUILD_WITH_TFM
22+
select PSA_WANT_ALG_SHA_256
2223
help
2324
UpdateHub is an enterprise-grade solution which makes simple to
2425
remotely update all your embedded devices in the field. It

subsys/mgmt/updatehub/updatehub_integrity.c

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ LOG_MODULE_DECLARE(updatehub, CONFIG_UPDATEHUB_LOG_LEVEL);
99

1010
#include "updatehub_integrity.h"
1111

12-
#if defined(CONFIG_PSA_CRYPTO_CLIENT)
1312
#define SUCCESS_VALUE PSA_SUCCESS
14-
#else
15-
#define SUCCESS_VALUE 0
16-
#endif
1713

1814
int updatehub_integrity_init(updatehub_crypto_context_t *ctx)
1915
{
@@ -24,13 +20,8 @@ int updatehub_integrity_init(updatehub_crypto_context_t *ctx)
2420
return -EINVAL;
2521
}
2622

27-
#if defined(CONFIG_PSA_CRYPTO_CLIENT)
2823
*ctx = psa_hash_operation_init();
2924
ret = psa_hash_setup(ctx, PSA_ALG_SHA_256);
30-
#else
31-
mbedtls_sha256_init(ctx);
32-
ret = mbedtls_sha256_starts(ctx, false);
33-
#endif
3425
if (ret != SUCCESS_VALUE) {
3526
LOG_DBG("Failed to %s SHA-256 operation. (%d)", "set up", ret);
3627
return -EFAULT;
@@ -53,19 +44,9 @@ int updatehub_integrity_update(updatehub_crypto_context_t *ctx,
5344
return 0;
5445
}
5546

56-
#if defined(CONFIG_PSA_CRYPTO_CLIENT)
5747
ret = psa_hash_update(ctx, buffer, len);
58-
if (ret != PSA_SUCCESS) {
59-
psa_hash_abort(ctx);
60-
}
61-
#else
62-
ret = mbedtls_sha256_update(ctx, buffer, len);
63-
if (ret != 0) {
64-
mbedtls_sha256_free(ctx);
65-
}
66-
#endif
67-
6848
if (ret != SUCCESS_VALUE) {
49+
psa_hash_abort(ctx);
6950
LOG_DBG("Failed to %s SHA-256 operation. (%d)", "update", ret);
7051
return -EFAULT;
7152
}
@@ -77,6 +58,7 @@ int updatehub_integrity_finish(updatehub_crypto_context_t *ctx,
7758
uint8_t *hash, const uint32_t size)
7859
{
7960
int ret;
61+
size_t hash_len;
8062

8163
if (ctx == NULL || hash == NULL) {
8264
return -EINVAL;
@@ -87,18 +69,9 @@ int updatehub_integrity_finish(updatehub_crypto_context_t *ctx,
8769
return -EINVAL;
8870
}
8971

90-
#if defined(CONFIG_PSA_CRYPTO_CLIENT)
91-
size_t hash_len;
92-
9372
ret = psa_hash_finish(ctx, hash, size, &hash_len);
94-
if (ret != PSA_SUCCESS) {
95-
psa_hash_abort(ctx);
96-
}
97-
#else
98-
ret = mbedtls_sha256_finish(ctx, hash);
99-
mbedtls_sha256_free(ctx);
100-
#endif
10173
if (ret != SUCCESS_VALUE) {
74+
psa_hash_abort(ctx);
10275
LOG_DBG("Failed to %s SHA-256 operation. (%d)", "finish", ret);
10376
return -EFAULT;
10477
}

subsys/mgmt/updatehub/updatehub_integrity.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
#ifndef __UPDATEHUB_INTEGRITY_H__
88
#define __UPDATEHUB_INTEGRITY_H__
99

10-
#if defined(CONFIG_PSA_CRYPTO_CLIENT)
1110
#include <psa/crypto.h>
12-
#else
13-
#include <mbedtls/sha256.h>
14-
#endif
1511

1612
#ifdef __cplusplus
1713
extern "C" {
@@ -20,11 +16,7 @@ extern "C" {
2016
#define SHA256_BIN_DIGEST_SIZE (32)
2117
#define SHA256_HEX_DIGEST_SIZE ((SHA256_BIN_DIGEST_SIZE * 2) + 1)
2218

23-
#if defined(CONFIG_PSA_CRYPTO_CLIENT)
2419
typedef psa_hash_operation_t updatehub_crypto_context_t;
25-
#else
26-
typedef mbedtls_sha256_context updatehub_crypto_context_t;
27-
#endif
2820

2921
int updatehub_integrity_init(updatehub_crypto_context_t *ctx);
3022
int updatehub_integrity_update(updatehub_crypto_context_t *ctx,

0 commit comments

Comments
 (0)