Skip to content

Commit f4f139b

Browse files
YadongQilijinxia
authored andcommitted
DM: generate random virtual RPMB key
The virtual rpmb key transfer path is ready now, so replace previous temporary fixed key solution with random key solution. Tracked-On: #1636 Signed-off-by: Qi Yadong <yadong.qi@intel.com> Acked-by: Zhu Bing <bing.zhu@intel.com>
1 parent dff441a commit f4f139b

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

devicemodel/core/vrpmb.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,28 @@
2929
#include <stdio.h>
3030
#include <string.h>
3131
#include <assert.h>
32+
#include <openssl/rand.h>
3233

3334
#include "types.h"
3435
#include "vrpmb.h"
3536

37+
#define DRNG_MAX_RETRIES 5U
38+
3639
struct key_material {
3740
uint8_t key[RPMB_KEY_LEN];
3841
bool initialized;
3942
};
4043

41-
static struct key_material vrkey = { .initialized = false };
44+
static struct key_material vrkey = {
45+
.key = {0},
46+
.initialized = false
47+
};
4248

4349
int get_vrpmb_key(uint8_t *out, size_t size)
4450
{
51+
int ret;
52+
int i;
53+
4554
if (!out) {
4655
fprintf(stderr, "%s: Invalid output pointer\n", __func__);
4756
return 0;
@@ -50,10 +59,18 @@ int get_vrpmb_key(uint8_t *out, size_t size)
5059
assert(size == RPMB_KEY_LEN);
5160

5261
if ( vrkey.initialized == false ) {
53-
/* FIXME: Currently the transport path is not ready, so
54-
* use fixed key(all 0) for temporary solution.
55-
*/
56-
memset(vrkey.key, 0, RPMB_KEY_LEN);
62+
for (i = 0; i < DRNG_MAX_RETRIES; i++) {
63+
ret = RAND_bytes(vrkey.key, RPMB_KEY_LEN);
64+
if (ret == 1) {
65+
vrkey.initialized = true;
66+
break;
67+
}
68+
}
69+
70+
if (vrkey.initialized != true) {
71+
fprintf(stderr, "%s: unable to generate random key!\n", __func__);
72+
return 0;
73+
}
5774
}
5875

5976
memcpy(out, vrkey.key, size);

0 commit comments

Comments
 (0)