Skip to content

Commit 3d45ee7

Browse files
valeriosettimmahadevan108
authored andcommitted
random: remove TinyCrypt usage
Following the deprecation of TinyCrypt (#79566) we remove TinyCrypt usage in random generators. This basically only affects the CTR-DRBG random generator which from now only will only make use of Mbed TLS. Signed-off-by: Valerio Setti <[email protected]>
1 parent f4b7d15 commit 3d45ee7

File tree

3 files changed

+10
-78
lines changed

3 files changed

+10
-78
lines changed

doc/releases/migration-guide-4.0.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,14 @@ MCUmgr
559559
Modem
560560
=====
561561

562+
Random
563+
======
564+
565+
* Following the deprecation of the TinyCrypt library (:github:`79566`), usage
566+
of TinyCrypt in the CTR-DRBG random number generator was removed. From now on
567+
Mbed TLS is required to enable :kconfig:option:`CONFIG_CTR_DRBG_CSPRNG_GENERATOR`.
568+
(:github:`79653`)
569+
562570
Shell
563571
=====
564572

subsys/random/Kconfig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ config HARDWARE_DEVICE_CS_GENERATOR
106106

107107
config CTR_DRBG_CSPRNG_GENERATOR
108108
bool "Use CTR-DRBG CSPRNG"
109-
depends on MBEDTLS || TINYCRYPT
109+
depends on MBEDTLS
110110
depends on ENTROPY_HAS_DRIVER
111-
select MBEDTLS_CIPHER_AES_ENABLED if MBEDTLS
112-
select TINYCRYPT_CTR_PRNG if TINYCRYPT
113-
select TINYCRYPT_AES if TINYCRYPT
111+
select MBEDTLS_CIPHER_AES_ENABLED
114112
help
115113
Enables the CTR-DRBG pseudo-random number generator. This CSPRNG
116114
shall use the entropy API for an initialization seed. The CTR-DRBG

subsys/random/random_ctr_drbg.c

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,13 @@
1010
#include <zephyr/kernel.h>
1111
#include <string.h>
1212

13-
#if defined(CONFIG_MBEDTLS)
1413
#if !defined(CONFIG_MBEDTLS_CFG_FILE)
1514
#include "mbedtls/config.h"
1615
#else
1716
#include CONFIG_MBEDTLS_CFG_FILE
1817
#endif /* CONFIG_MBEDTLS_CFG_FILE */
1918
#include <mbedtls/ctr_drbg.h>
2019

21-
#elif defined(CONFIG_TINYCRYPT)
22-
23-
#include <tinycrypt/ctr_prng.h>
24-
#include <tinycrypt/aes.h>
25-
#include <tinycrypt/constants.h>
26-
27-
#endif /* CONFIG_MBEDTLS */
28-
2920
/*
3021
* entropy_dev is initialized at runtime to allow first time initialization
3122
* of the ctr_drbg engine.
@@ -35,22 +26,13 @@ static const unsigned char drbg_seed[] = CONFIG_CS_CTR_DRBG_PERSONALIZATION;
3526
static bool ctr_initialised;
3627
static struct k_mutex ctr_lock;
3728

38-
#if defined(CONFIG_MBEDTLS)
39-
4029
static mbedtls_ctr_drbg_context ctr_ctx;
4130

4231
static int ctr_drbg_entropy_func(void *ctx, unsigned char *buf, size_t len)
4332
{
4433
return entropy_get_entropy(entropy_dev, (void *)buf, len);
4534
}
4635

47-
#elif defined(CONFIG_TINYCRYPT)
48-
49-
static TCCtrPrng_t ctr_ctx;
50-
51-
#endif /* CONFIG_MBEDTLS */
52-
53-
5436
static int ctr_drbg_initialize(void)
5537
{
5638
int ret;
@@ -62,8 +44,6 @@ static int ctr_drbg_initialize(void)
6244
return -ENODEV;
6345
}
6446

65-
#if defined(CONFIG_MBEDTLS)
66-
6747
mbedtls_ctr_drbg_init(&ctr_ctx);
6848

6949
ret = mbedtls_ctr_drbg_seed(&ctr_ctx,
@@ -77,27 +57,6 @@ static int ctr_drbg_initialize(void)
7757
return -EIO;
7858
}
7959

80-
#elif defined(CONFIG_TINYCRYPT)
81-
82-
uint8_t entropy[TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE];
83-
84-
ret = entropy_get_entropy(entropy_dev, (void *)&entropy,
85-
sizeof(entropy));
86-
if (ret != 0) {
87-
return -EIO;
88-
}
89-
90-
ret = tc_ctr_prng_init(&ctr_ctx,
91-
(uint8_t *)&entropy,
92-
sizeof(entropy),
93-
(uint8_t *)drbg_seed,
94-
sizeof(drbg_seed));
95-
96-
if (ret == TC_CRYPTO_FAIL) {
97-
return -EIO;
98-
}
99-
100-
#endif
10160
ctr_initialised = true;
10261
return 0;
10362
}
@@ -117,41 +76,8 @@ int z_impl_sys_csrand_get(void *dst, uint32_t outlen)
11776
}
11877
}
11978

120-
#if defined(CONFIG_MBEDTLS)
121-
12279
ret = mbedtls_ctr_drbg_random(&ctr_ctx, (unsigned char *)dst, outlen);
12380

124-
#elif defined(CONFIG_TINYCRYPT)
125-
126-
uint8_t entropy[TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE];
127-
128-
ret = tc_ctr_prng_generate(&ctr_ctx, 0, 0, (uint8_t *)dst, outlen);
129-
130-
if (ret == TC_CRYPTO_SUCCESS) {
131-
ret = 0;
132-
} else if (ret == TC_CTR_PRNG_RESEED_REQ) {
133-
134-
ret = entropy_get_entropy(entropy_dev,
135-
(void *)&entropy, sizeof(entropy));
136-
if (ret != 0) {
137-
ret = -EIO;
138-
goto end;
139-
}
140-
141-
ret = tc_ctr_prng_reseed(&ctr_ctx,
142-
entropy,
143-
sizeof(entropy),
144-
drbg_seed,
145-
sizeof(drbg_seed));
146-
147-
ret = tc_ctr_prng_generate(&ctr_ctx, 0, 0,
148-
(uint8_t *)dst, outlen);
149-
150-
ret = (ret == TC_CRYPTO_SUCCESS) ? 0 : -EIO;
151-
} else {
152-
ret = -EIO;
153-
}
154-
#endif
15581
end:
15682
k_mutex_unlock(&ctr_lock);
15783

0 commit comments

Comments
 (0)