|
6 | 6 |
|
7 | 7 | /*
|
8 | 8 | * Copyright (c) 2017 Intel Corporation
|
| 9 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
9 | 10 | *
|
10 | 11 | * SPDX-License-Identifier: Apache-2.0
|
11 | 12 | */
|
12 | 13 |
|
13 | 14 | #include <zephyr/init.h>
|
14 | 15 | #include <zephyr/app_memory/app_memdomain.h>
|
15 |
| -#include <zephyr/drivers/entropy.h> |
16 |
| -#include <zephyr/random/random.h> |
17 |
| -#include <mbedtls/entropy.h> |
18 | 16 | #include <mbedtls/platform_time.h>
|
19 | 17 |
|
20 |
| - |
21 | 18 | #include <mbedtls/debug.h>
|
22 | 19 |
|
23 | 20 | #if defined(CONFIG_MBEDTLS)
|
|
29 | 26 | #endif
|
30 | 27 |
|
31 | 28 | #if defined(CONFIG_MBEDTLS_ENABLE_HEAP) && \
|
32 |
| - defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
| 29 | + defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
33 | 30 | #include <mbedtls/memory_buffer_alloc.h>
|
34 | 31 |
|
35 | 32 | #if !defined(CONFIG_MBEDTLS_HEAP_SIZE)
|
@@ -83,68 +80,3 @@ mbedtls_ms_time_t mbedtls_ms_time(void)
|
83 | 80 | {
|
84 | 81 | return (mbedtls_ms_time_t)k_uptime_get();
|
85 | 82 | }
|
86 |
| - |
87 |
| -#if defined(CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR) || defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
88 |
| -static int get_random_data(uint8_t *output, size_t output_size, bool allow_non_cs) |
89 |
| -{ |
90 |
| - int ret = MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED; |
91 |
| - |
92 |
| -#if defined(CONFIG_CSPRNG_ENABLED) |
93 |
| - ret = sys_csrand_get(output, output_size); |
94 |
| - if (ret == 0) { |
95 |
| - return 0; |
96 |
| - } |
97 |
| -#endif /* CONFIG_CSPRNG_ENABLED */ |
98 |
| - |
99 |
| - if (allow_non_cs) { |
100 |
| - sys_rand_get(output, output_size); |
101 |
| - ret = 0; |
102 |
| - } |
103 |
| - |
104 |
| - return ret; |
105 |
| -} |
106 |
| -#endif /* CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR || CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ |
107 |
| - |
108 |
| -#if defined(CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR) |
109 |
| -int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, |
110 |
| - size_t *olen) |
111 |
| -{ |
112 |
| - int ret; |
113 |
| - uint16_t request_len = len > UINT16_MAX ? UINT16_MAX : len; |
114 |
| - |
115 |
| - ARG_UNUSED(data); |
116 |
| - |
117 |
| - if (output == NULL || olen == NULL || len == 0) { |
118 |
| - return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; |
119 |
| - } |
120 |
| - |
121 |
| - ret = get_random_data(output, len, true); |
122 |
| - if (ret < 0) { |
123 |
| - return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; |
124 |
| - } |
125 |
| - |
126 |
| - *olen = request_len; |
127 |
| - |
128 |
| - return 0; |
129 |
| -} |
130 |
| -#endif /* CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR */ |
131 |
| - |
132 |
| -#if defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
133 |
| -psa_status_t mbedtls_psa_external_get_random( |
134 |
| - mbedtls_psa_external_random_context_t *context, |
135 |
| - uint8_t *output, size_t output_size, size_t *output_length) |
136 |
| -{ |
137 |
| - (void) context; |
138 |
| - int ret; |
139 |
| - |
140 |
| - ret = get_random_data(output, output_size, |
141 |
| - IS_ENABLED(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG)); |
142 |
| - if (ret != 0) { |
143 |
| - return PSA_ERROR_GENERIC_ERROR; |
144 |
| - } |
145 |
| - |
146 |
| - *output_length = output_size; |
147 |
| - |
148 |
| - return PSA_SUCCESS; |
149 |
| -} |
150 |
| -#endif /* CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ |
0 commit comments