Skip to content

Commit b3c33ca

Browse files
committed
[nrf noup] Revert "modules: mbedtls: fix entropy polling"
This reverts commit 21ee827. Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
1 parent b87553e commit b3c33ca

4 files changed

Lines changed: 28 additions & 21 deletions

File tree

modules/mbedtls/Kconfig.tf-psa-crypto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ comment "Random number generators"
278278
config MBEDTLS_CTR_DRBG_C
279279
bool "CTR_DRBG AES-256-based random generator"
280280
depends on MBEDTLS_CIPHER_AES_ENABLED
281+
default y
281282

282283
config MBEDTLS_HMAC_DRBG_C
283284
bool "HMAC_DRBG random generator"
@@ -357,14 +358,13 @@ config MBEDTLS_HAVE_ASM
357358

358359
config MBEDTLS_ENTROPY_C
359360
bool "Mbed TLS entropy accumulator"
360-
select PSA_WANT_ALG_SHA_256 if !PSA_WANT_ALG_SHA_512
361+
depends on MBEDTLS_SHA256 || MBEDTLS_SHA384 || MBEDTLS_SHA512
361362
help
362363
This module gathers entropy data from enabled entropy sources. It's
363364
mostly used in conjunction with CTR_DRBG or HMAC_DRBG to create
364365
a deterministic random number generator.
365-
It requires either PSA_WANT_ALG_SHA_256 or PSA_WANT_ALG_SHA_512.
366366

367-
config MBEDTLS_PSA_DRIVER_GET_ENTROPY
367+
config MBEDTLS_ENTROPY_POLL_ZEPHYR
368368
bool "Provide entropy data to Mbed TLS through entropy driver or random generator"
369369
default y
370370
depends on MBEDTLS_ENTROPY_C

modules/mbedtls/configs/config-tf-psa-crypto.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
2626
#define MBEDTLS_MEMORY_ALIGN_MULTIPLE (sizeof(void *))
2727
#define MBEDTLS_PLATFORM_EXIT_ALT
28+
#define MBEDTLS_NO_PLATFORM_ENTROPY
2829

2930
#if defined(CONFIG_MBEDTLS_ZEROIZE_ALT)
3031
#define MBEDTLS_PLATFORM_ZEROIZE_ALT
@@ -38,8 +39,10 @@
3839
#define MBEDTLS_PLATFORM_SNPRINTF_ALT
3940
#endif /* defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) */
4041

41-
#if defined(CONFIG_MBEDTLS_PSA_DRIVER_GET_ENTROPY)
42-
#define MBEDTLS_PSA_DRIVER_GET_ENTROPY
42+
#if defined(CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR)
43+
#define MBEDTLS_ENTROPY_HARDWARE_ALT
44+
#else
45+
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
4346
#endif
4447

4548
#if defined(CONFIG_MBEDTLS_HAVE_ASM)

modules/mbedtls/zephyr_entropy.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
*/
66

77
#include <zephyr/random/random.h>
8+
#include <mbedtls/entropy.h>
89
#include <psa/crypto.h>
9-
#include <mbedtls/platform.h>
1010

1111

12-
#if defined(CONFIG_MBEDTLS_PSA_DRIVER_GET_ENTROPY) || \
13-
defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
12+
#if defined(CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR) || defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
1413
static int get_random_data(uint8_t *output, size_t output_size, bool allow_non_cs)
1514
{
16-
int ret = -EINVAL;
15+
int ret = MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED;
1716

1817
#if defined(CONFIG_CSPRNG_ENABLED)
1918
ret = sys_csrand_get(output, output_size);
@@ -29,24 +28,31 @@ static int get_random_data(uint8_t *output, size_t output_size, bool allow_non_c
2928

3029
return ret;
3130
}
32-
#endif /* CONFIG_MBEDTLS_PSA_DRIVER_GET_ENTROPY || CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
31+
#endif /* CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR || CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
3332

34-
#if defined(CONFIG_MBEDTLS_PSA_DRIVER_GET_ENTROPY)
35-
int mbedtls_platform_get_entropy(psa_driver_get_entropy_flags_t flags,
36-
size_t *estimate_bits,
37-
unsigned char *output, size_t output_size)
33+
#if defined(CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR)
34+
int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len,
35+
size_t *olen)
3836
{
39-
ARG_UNUSED(flags);
37+
int ret;
38+
uint16_t request_len = len > UINT16_MAX ? UINT16_MAX : len;
39+
40+
ARG_UNUSED(data);
41+
42+
if (output == NULL || olen == NULL || len == 0) {
43+
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
44+
}
4045

41-
if (get_random_data(output, output_size, true) < 0) {
42-
return -EIO;
46+
ret = get_random_data(output, len, true);
47+
if (ret < 0) {
48+
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
4349
}
4450

45-
*estimate_bits = 8 * output_size;
51+
*olen = request_len;
4652

4753
return 0;
4854
}
49-
#endif /* CONFIG_MBEDTLS_PSA_DRIVER_GET_ENTROPY */
55+
#endif /* CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR */
5056

5157
#if defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
5258
psa_status_t mbedtls_psa_external_get_random(

modules/mbedtls/zephyr_init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
*/
1313

1414
#include <zephyr/init.h>
15-
#include <zephyr/kernel.h>
1615
#include <zephyr/app_memory/app_memdomain.h>
1716
#include <mbedtls/platform_time.h>
18-
#include <errno.h>
1917

2018
#include <mbedtls/debug.h>
2119

0 commit comments

Comments
 (0)