Skip to content

Commit 33d8ac3

Browse files
authored
Merge pull request #25 from devran01/fix_psa_inject_entropy
Remove MBEDTLS_ENTROPY_NV_SEED, MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES and MBEDTLS_PSA_INJECT_ENTROPY
2 parents 29fa42d + d8cf7d7 commit 33d8ac3

File tree

4 files changed

+4
-83
lines changed

4 files changed

+4
-83
lines changed

README.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,6 @@ This repository contains an example demonstrating the compilation and use of PSA
33

44
Example contained within this repository is inject attestation key-pair, get attetstaion token size and attetstaion token.
55

6-
## Factory injection of entropy
7-
8-
This example also contains a fake entropy injection example. Use of this
9-
function (`mbedtls_psa_inject_entropy()`) is demonstrated in this example, but
10-
it is not a function users would ever need to call as part of their
11-
applications. The function is useful for factory tool developers only.
12-
13-
In a production system, and in the absence of other sources of entropy, a
14-
factory tool can inject entropy into the device. After the factory tool
15-
completes manufacturing of a device, that device must contain enough entropy
16-
for the lifetime of the device or be able to produce it with an on-board TRNG.
17-
18-
A factory application wishing to inject entropy should configure Mbed Crypto
19-
using the Mbed TLS configuration system (for the PSA Secure Processing Element,
20-
SPE), such as in the factory application's SPE binary's `mbed_app.json` as
21-
follows:
22-
23-
```javascript
24-
{
25-
"macros": [
26-
"MBEDTLS_ENTROPY_NV_SEED=1",
27-
"MBEDTLS_PLATFORM_NV_SEED_READ_MACRO=mbed_default_seed_read",
28-
"MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO=mbed_default_seed_write"
29-
]
30-
}
31-
```
32-
336
## Prerequisites
347
* Install <a href='https://github.com/ARMmbed/mbed-cli#installing-mbed-cli'>Mbed CLI</a>
358

main.cpp

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,6 @@ int main(void)
5757

5858
#define PSA_ATTESTATION_PRIVATE_KEY_ID 17
5959

60-
static const uint8_t private_key_data[] = {
61-
0x49, 0xc9, 0xa8, 0xc1, 0x8c, 0x4b, 0x88, 0x56,
62-
0x38, 0xc4, 0x31, 0xcf, 0x1d, 0xf1, 0xc9, 0x94,
63-
0x13, 0x16, 0x09, 0xb5, 0x80, 0xd4, 0xfd, 0x43,
64-
0xa0, 0xca, 0xb1, 0x7d, 0xb2, 0xf1, 0x3e, 0xee
65-
};
66-
67-
static const uint8_t public_key_data[] = {
68-
0x04, 0x77, 0x72, 0x65, 0x6f, 0x81, 0x4b, 0x39,
69-
0x92, 0x79, 0xd5, 0xe1, 0xf1, 0x78, 0x1f, 0xac,
70-
0x6f, 0x09, 0x9a, 0x3c, 0x5c, 0xa1, 0xb0, 0xe3,
71-
0x53, 0x51, 0x83, 0x4b, 0x08, 0xb6, 0x5e, 0x0b,
72-
0x57, 0x25, 0x90, 0xcd, 0xaf, 0x8f, 0x76, 0x93,
73-
0x61, 0xbc, 0xf3, 0x4a, 0xcf, 0xc1, 0x1e, 0x5e,
74-
0x07, 0x4e, 0x84, 0x26, 0xbd, 0xde, 0x04, 0xbe,
75-
0x6e, 0x65, 0x39, 0x45, 0x44, 0x96, 0x17, 0xde,
76-
0x45
77-
};
78-
7960
#define TEST_TOKEN_SIZE (0x200)
8061
#define TEST_CHALLENGE_OBJ_SIZE (32u)
8162

@@ -92,14 +73,14 @@ static psa_status_t check_initial_attestation_get_token()
9273
{
9374
psa_status_t status = PSA_SUCCESS;
9475
size_t exported_length;
95-
uint8_t exported[sizeof(public_key_data)];
76+
uint8_t exported[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(256)];
9677
enum psa_attest_err_t attest_err = PSA_ATTEST_ERR_SUCCESS;
9778
uint32_t token_size;
9879

9980
status = psa_crypto_init();
10081
ASSERT_STATUS(status, PSA_SUCCESS);
101-
status = psa_attestation_inject_key(private_key_data,
102-
sizeof(private_key_data),
82+
status = psa_attestation_inject_key(NULL,
83+
0,
10384
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP256R1),
10485
exported,
10586
sizeof(exported),
@@ -136,40 +117,10 @@ static void attestation_example(void)
136117
}
137118
}
138119

139-
static void fake_set_initial_nvseed(void)
140-
{
141-
/* This function, fake_set_initial_nvseed(), is useless on platforms that
142-
* have already been manufactured correctly. This function demonstrates
143-
* what a factory tool may do in order to manufacture a device that does
144-
* not have its own source of entropy. */
145-
146-
/* mbedtls_psa_inject_entropy() is always present, but calls to it will
147-
* always fail unless the PSA Secure Processing Element (SPE) is configured
148-
* with both MBEDTLS_ENTROPY_NV_SEED and MBEDTLS_PSA_HAS_ITS_IO by the
149-
* SPE's Mbed TLS configuration system. */
150-
uint8_t seed[MBEDTLS_ENTROPY_MAX_SEED_SIZE];
151-
152-
/* Calculate a fake seed for injecting. A real factory application would
153-
* inject true entropy for use as the initial NV Seed. */
154-
for (size_t i = 0; i < sizeof(seed); ++i) {
155-
seed[i] = i;
156-
}
157-
158-
int status = mbedtls_psa_inject_entropy(seed, sizeof(seed));
159-
if (status) {
160-
/* The device may already have an NV Seed injected, or another error
161-
* may have happened during injection. */
162-
mbedtls_printf("warning (%d) - this attempt at entropy injection"
163-
" failed\n", status);
164-
}
165-
}
166-
167120
int main(void)
168121
{
169122
const psa_key_id_t key_id = PSA_ATTESTATION_PRIVATE_KEY_ID;
170123
psa_key_handle_t handle = 0;
171-
172-
fake_set_initial_nvseed();
173124

174125
attestation_example();
175126

mbed-os.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os/#e0c7e087de858fd9c88703edf325705583c9939a
1+
https://github.com/ARMmbed/mbed-os/

mbedtls_user_config.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
/* Enable the default implementation of the PSA entropy injection API if we are
2626
* building for an SPE. */
2727
#if defined(COMPONENT_PSA_SRV_IMPL) || defined(COMPONENT_PSA_SRV_EMUL)
28-
# define MBEDTLS_ENTROPY_NV_SEED
29-
# define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
30-
# define MBEDTLS_PSA_INJECT_ENTROPY
3128
# define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbed_default_seed_read
3229
# define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbed_default_seed_write
3330
#endif

0 commit comments

Comments
 (0)