Skip to content

Commit a90730b

Browse files
committed
Adding defualt behaviour for platforms without TRNG.
If setting the MBEDTLS_PLATFORM_NV_SEED_ALT and MBEDTLS_ENTROPY_NV_SEED flags and not setting MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_NV_SEED_READ_MACRO flags mbed-os will add an entropy source to the relevent partition - SPE in case of daul core or in case of single core V7 to the main partition. The defualt behaviour will be to read or write the data from the ITS.
1 parent 32bc912 commit a90730b

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
3+
#ifndef DEFAULT_RANDOM_SEED_H
4+
#define DEFAULT_RANDOM_SEED_H
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
11+
12+
/** Read seed from the secure storage.
13+
*
14+
* This function will be the default function for reading the Random seed.
15+
*
16+
* @param buf[out] buffer to hold the seed value from the secure storage
17+
* @param buf_len[in] input buffer length
18+
*
19+
* @returns
20+
* secure storage API return value.
21+
*
22+
*/
23+
int mbed_default_seed_read(unsigned char *buf, size_t buf_len);
24+
25+
/** Writes seed to the secure storage.
26+
*
27+
* This function will be the default function for writing the Random seed.
28+
*
29+
* @param buf[in] buffer to the seed value
30+
* @param buf_len[in] input buffer length
31+
*
32+
* @returns
33+
* secure storage API return value.
34+
*/
35+
int mbed_default_seed_write(unsigned char *buf, size_t buf_len);
36+
37+
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
#endif /* DEFAULT_RANDOM_SEED_H */
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "mbed.h"
2+
#include "crypto.h"
3+
#include "default_random_seed.h"
4+
#include "psa_prot_internal_storage.h"
5+
6+
int mbed_default_seed_read(unsigned char *buf, size_t buf_len)
7+
{
8+
struct psa_its_info_t info = {0, 0};
9+
size_t actual_size = buf_len;
10+
psa_its_get_info(MBED_RANDOM_SEED_ITS_UID, &info);
11+
if (info.size < buf_len)
12+
{
13+
actual_size = info.size;
14+
}
15+
psa_its_status_t rc = psa_its_get(MBED_RANDOM_SEED_ITS_UID, 0, actual_size, buf);
16+
/* Make sure that in case of an error the value will be negative
17+
* Mbed TLS errors are negative values */
18+
rc = rc < 0 ? rc : (-1 * rc);
19+
return (rc);
20+
}
21+
22+
int mbed_default_seed_write(unsigned char *buf, size_t buf_len)
23+
{
24+
psa_its_status_t rc = psa_its_set(MBED_RANDOM_SEED_ITS_UID, buf_len, buf, 0);
25+
/* Make sure that in case of an error the value will be negative
26+
* Mbed TLS errors are negative values */
27+
rc = rc < 0 ? rc : (-1 * rc);
28+
return (rc);
29+
}
30+

0 commit comments

Comments
 (0)