Skip to content

Commit b7ab5c0

Browse files
committed
Generate DeviceKey Root of Trust
Since ARMmbed/mbed-os#12385: 0e7a53c DeviceKey Root of Trust generation refactored. the Root of Trust is not automatically generated anymore. We need to generate or inject one explicitly. This commit also improves the readability of the existing code for the injection of Root of Trust.
1 parent 0fb9be3 commit b7ab5c0

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

main.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,27 @@ int main()
5656
//If TRNG is not available it is a must to inject the ROT before the first call to derive key method.
5757
printf("\n--- No TRNG support for this device. injecting ROT. ---\n");
5858
ret = inject_rot_key();
59-
if (DEVICEKEY_SUCCESS != ret && DEVICEKEY_ALREADY_EXIST != ret) {
60-
printf("\n--- Error, injection of ROT key has failed with status %d ---\n", ret);
59+
if (DEVICEKEY_ALREADY_EXIST == ret) {
60+
printf("\n--- ROT Key already exists in the persistent memory. ---\n", ret);
61+
else if (DEVICEKEY_SUCCESS == ret) {
62+
printf("\n--- ROT Key injected and stored in persistent memory. ---\n", ret);
63+
} else {
64+
printf("--- Error, injection of RoT key failed with error code %d ---\n", ret);
6165
return -1;
6266
}
6367

64-
if ( DEVICEKEY_ALREADY_EXIST == ret ) {
68+
#else
69+
70+
// The ROT must be present before the first call to derive key method.
71+
printf("\n--- Generating ROT. ---\n");
72+
ret = devkey.generate_root_of_trust();
73+
if (DEVICEKEY_ALREADY_EXIST == ret) {
6574
printf("\n--- ROT Key already exists in the persistent memory. ---\n", ret);
75+
else if (DEVICEKEY_SUCCESS == ret) {
76+
printf("\n--- ROT Key generated and stored in persistent memory. ---\n", ret);
6677
} else {
67-
printf("\n--- ROT Key injected and stored in persistent memory. ---\n", ret);
78+
printf("--- Error, generation of RoT key failed with error code %d ---\n", ret);
79+
return -1;
6880
}
6981

7082
#endif

0 commit comments

Comments
 (0)