Skip to content

Commit 2d53876

Browse files
author
Amanda Butler
authored
Fix headings in entropy.md
Update headings for TOC.
1 parent 3578ed8 commit 2d53876

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

docs/reference/contributing/target/entropy.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
### Mbed TLS entropy
1+
## Mbed TLS entropy
22

33
This document explains how to port [Arm Mbed TLS](https://github.com/ARMmbed/mbedtls) to a new Arm Mbed development board.
44

55
<span class="notes">**Note:** This part is critical for the security of your product, and you should consult a cryptography expert while considering the choices and implementing them.</span>
66

7-
#### Why Mbed TLS needs entropy
7+
### Why Mbed TLS needs entropy
88

99
Almost every cryptographic protocol requires random values that no one should be able to predict. A striking example is their use as session keys: It is easy to see that if an adversary can predict the session key, then he can decrypt the whole session. Even if the adversary can't predict it exactly, just with a relatively high probability, he can still recover the contents of the session. For example, if the adversary has a 0.00001% chance of predicting the 256 bit AES session key, then he can break it as easily as if we had used a 23 bit key (that is - very easily).
1010

1111
Creating session keys is only one use for random values; they have far more complicated applications. In these more complex use cases, the connection between the predictability of the values and the security of the protocol is not as obvious, but it is still crucial.
1212

13-
#### Which entropy source to choose
13+
### Which entropy source to choose
1414

1515
- If you have a target with a True Random Number Generator (TRNG), then follow Section 3 to allow Mbed TLS to use it.
1616

1717
- If you have a target without a TRNG, but with a non-volatile (NV) storage, then read Section 4 for instructions on making Mbed TLS use a random seed as entropy. This seed should be separately initialized with a true random number for each device at manufacturing time.
1818

1919
- If you just want to test Mbed TLS on your target without implementing either of the above, and having no security at all is acceptable, then go to Section 5.
2020

21-
#### How to provide Mbed TLS entropy from a hardware entropy source
21+
### How to provide Mbed TLS entropy from a hardware entropy source
2222

23-
##### What kind of a source you can add
23+
#### What kind of a source you can add
2424

2525
It is important that you only add a TRNG as described in this section. For the purposes of this document a device is considered a TRNG only if:
2626

@@ -32,7 +32,7 @@ It is important that you only add a TRNG as described in this section. For the p
3232

3333
For example, an integrated circuit extracting statistically random data from two oscillators of unknown frequencies and independent phases is considered a TRNG, but anything derived from a real time clock is NOT.
3434

35-
##### How to add an entropy source
35+
#### How to add an entropy source
3636

3737
Mbed TLS distinguishes between strong and weak entropy sources. Of the sources registered by default, two are strong: /dev/urandom and Windows CryptoAPI. However, these resources are not available on many embedded platforms, and the default behaviour of Mbed TLS is to refuse to work if there are no strong sources present. To get around this, Mbed TLS assumes that the hardware entropy source you register (as explained in this section) is a TRNG and thus treats it as strong.
3838

@@ -43,15 +43,15 @@ The preferred way to provide a custom entropy source:
4343

4444
The next two sections explain how to do this.
4545

46-
#### How to implement the TRNG API
46+
### How to implement the TRNG API
4747

4848
The implementation of this interface has to be located in the Arm Mbed OS directory specific to your target. The name of this directory is of the form `targets/.../TARGET_<target name>`. For example, in the case of K64F targets, it is `targets/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_MCU_K64F/`.
4949

50-
##### Data structure
50+
#### Data structure
5151

5252
You have to define a structure `trng_s` that holds all the information needed to operate the peripheral and describe its state.
5353

54-
##### Initialization and release
54+
#### Initialization and release
5555

5656
To enable initializing and releasing the peripheral, you must implement the following functions:
5757

@@ -60,7 +60,7 @@ void trng_init(trng_t *obj);
6060
void trng_free(trng_t *obj);
6161
```
6262
63-
##### The entropy collector function
63+
#### The entropy collector function
6464
6565
The function `trng_get_bytes()` serves as the primary interface to the entropy source. It is expected to load the collected entropy to the buffer and is declared as follows:
6666
@@ -78,24 +78,23 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
7878

7979
- ``size_t *output_length``: the length of the data written into the output buffer. It tells the caller how much entropy has been collected and how many bytes of the output buffer it can use. It should always reflect the exact amount of entropy collected; setting it higher than the actual number of bytes collected is a serious security risk.
8080

81-
82-
##### Indicating the presence of a TRNG
81+
#### Indicating the presence of a TRNG
8382

8483
To indicate that the target has an entropy source, you have to add `TRNG` to the capabilities of the target in `targets/targets.json`:
8584

8685
```
8786
"device_has": ["TRNG", etc.]
8887
```
8988

90-
#### How to implement the non-volatile seed entropy source
89+
### How to implement the non-volatile seed entropy source
9190

9291
If a hardware platform does not have a hardware entropy source to leverage into the entropy pool, alternatives have to be considered. As stated above, a strong entropy source is crucial for security of cryptographic and TLS operations. For platforms that support non-volatile memory, an option is to use the NV seed entropy source that Mbed TLS provides.
9392

9493
This makes Mbed TLS use a fixed amount of entropy as a seed and update this seed each time entropy is gathered with an Mbed TLS entropy collector for the first time. In a simple case it means that the seed is updated after reset at the start of the first TLS connection.
9594

9695
<span class="notes">**Note:** To make this option a relatively strong compromize, the seed should be initialized separately for each device with true random data at manufacturing time. It has to be true random data, something dependant on, for example the serial number is **not** secure. </span>
9796

98-
##### Enabling NV seed entropy source support
97+
#### Enabling NV seed entropy source support
9998

10099
To enable the NV seed entropy source, you have to add `MBEDTLS_ENTROPY_NV_SEED` to your macros in `targets.json`:
101100

@@ -107,7 +106,7 @@ This ensures the entropy pool knows it can use the NV seed entropy source.
107106

108107
By default the platform adaptation functions write/read a seed file called *seedfile*. If you have a system that does not support regular POSIX file operations (Arm Mbed OS does not support them by default), the default platform-adaptation functions will not be useful to you, and you will need to provide platform-adaptation functions (see next section).
109108

110-
##### Providing platform-adaptation functions
109+
#### Providing platform-adaptation functions
111110

112111
The NV seed entropy source needs to know how to retrieve and store the seed in non-volatile memory. So in order to make the NV seed entropy source work, two platform-layer functions need to be provided.
113112

@@ -126,11 +125,11 @@ There are three methods for setting those functions pointers (similar to all pla
126125
* `MBEDTLS_PLATFORM_STD_NV_SEED_READ` and `MBEDTLS_PLATFORM_STD_NV_SEED_WRITE` (requires `MBEDTLS_PLATFORM_NV_SEED_ALT`). By setting these two macros to the relevant function names, the default read/write functions are replaced at compile-time, and you still have the option to replace them at runtime as well.
127126
* `MBEDTLS_PLATFORM_NV_SEED_READ_MACRO` and `MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO`. By setting these two macros to the relevant functions names, the read/write functions are replaced at compile-time.
128127

129-
#### How to test without entropy sources
128+
### How to test without entropy sources
130129

131130
Both of the above options are secure if done properly, and depending on the platform may need more or less development work. In some cases it may be necessary to test Mbed TLS on boards without entropy. For these kinds of scenarios, Mbed TLS provides a compile time switch to enable testing without entropy sources.
132131

133-
##### Setting the macros
132+
#### Setting the macros
134133

135134
This option is very dangerous because compiling with it results in a build that is not secure! You have to let Mbed TLS know that you are using it deliberately and you are aware of the consequences. That is why you have to turn off any entropy sources explicitly first.
136135

0 commit comments

Comments
 (0)