Skip to content

Commit d2e1c9a

Browse files
author
Amanda Butler
authored
Merge pull request #1244 from tymoteuszblochmobica/rot
Update DeviceKey document after root of trust refactoring
2 parents 696abf7 + 47da069 commit d2e1c9a

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

docs/api/security/Devicekey.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,62 @@ The characteristics required by this root of trust are:
1919

2020
The DeviceKey feature keeps the root of trust key in internal storage, using the KVStore component. Internal storage provides protection from external physical attacks to the device.
2121

22-
The root of trust is generated at the first use of DeviceKey if the true random number generator is available in the device. If no true random number generator is available, you must pass the injected root of trust key to the DeviceKey before you call the key derivation API.
22+
The root of trust must be created before its first use. Otherwise, the key derivation API fails.
2323

2424
## Key derivation API
2525

2626
`generate_derived_key`: This API generates a new key based on an array of data ([salt](https://en.wikipedia.org/wiki/Salt_(cryptography)) the caller provides. A single salt value always generates the same key, so if you need a new key, you must use a new salt value. The salt can have any value - array, string and so on.
2727

28-
The generated keys can be 128 or 256 bits in length.
28+
The generated keys can be 128b or 256b in length.
2929

30-
### Root of Trust Injection API
30+
### Root of Trust generation API
3131

32-
`device_inject_root_of_trust`: You must call this API once in the lifecycle of the device, before any call to key derivation, if the device does not support true random number generator (`DEVICE_TRNG` is not defined).
32+
DeviceKey class needs root of trust ready to use before the derivation API's first call. There are two options to achieve this:
33+
34+
- Create a device key using a built-in random number generator.
35+
- Manually fill the device key data array.
36+
37+
Both cases requires injecting this key data to the KVStore reserved area.
38+
39+
When `DEVICE_TRNG` is defined, the device supports a random number generator, and you may generate the key by calling `generate_root_of_trust()`. The call succeeds only if the key does not already exist. You can't change the existing key.
40+
41+
```c++ NOCI
42+
int status = DeviceKey::get_instance().generate_root_of_trust();
43+
if(status == DEVICEKEY_SUCCESS) {
44+
//success
45+
} else {
46+
//error
47+
}
48+
```
49+
50+
If `DEVICE_TRNG` is not defined, the key buffer must be filled manually by calling `device_inject_root_of_trust()`. The example below shows an injection of a dummy key:
51+
52+
```c++ NOCI
53+
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
54+
memcpy(key, "12345678123456781234567812345678", DEVICE_KEY_32BYTE);
55+
int size = DEVICE_KEY_32BYTE;
56+
57+
int status = DeviceKey::get_instance().device_inject_root_of_trust(key, size);
58+
if(status == DEVICEKEY_SUCCESS) {
59+
//success
60+
} else {
61+
//error
62+
}
63+
```
3364
3465
### Using DeviceKey
3566
36-
DeviceKey is a singleton class, meaning that the system can have only a single instance of it.
67+
DeviceKey is a singleton class, meaning the system can have only a single instance of it.
3768
38-
To instantiate DeviceKey, you need to call its `get_instance` member function as following:
69+
To instantiate DeviceKey, call its `get_instance` member function:
3970
4071
```c++ TODO
4172
DeviceKey &deviceKey = DeviceKey::get_instance();
4273
```
4374

4475
### Testing DeviceKey
4576

46-
Run the DeviceKey functionality test with the `mbed` command as following:
77+
Run the DeviceKey functionality test with the `mbed`:
4778

4879
```
4980
mbed test -n features-device_key-tests-device_key-functionality

0 commit comments

Comments
 (0)