summaryrefslogtreecommitdiff
path: root/utility/tpmc.c
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2012-02-29 16:09:14 -0800
committerGerrit <chrome-bot@google.com>2012-03-01 15:25:31 -0800
commitf0605cbdc36f58829a908a3333e438c565c8c7af (patch)
tree3cbf146c627d95d2d01461ac0224d90234e802fe /utility/tpmc.c
parent5ee257d94cb8aab2f3717c5cd4ceb37fbba3ec41 (diff)
downloadvboot-f0605cbdc36f58829a908a3333e438c565c8c7af.tar.gz
tpm_lite: implement TPM_GetRandom
Provide TPM_GetRandom function to library callers. BUG=chromium-os:22172 TEST=lumpy build & manual testing Change-Id: Id604fd92490ba697033158a580b0b4df1d975932 Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/17120 Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Diffstat (limited to 'utility/tpmc.c')
-rw-r--r--utility/tpmc.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/utility/tpmc.c b/utility/tpmc.c
index d8fb07a5..68ce6d3f 100644
--- a/utility/tpmc.c
+++ b/utility/tpmc.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -228,6 +228,35 @@ static uint32_t HandlerGetPermissions(void) {
return result;
}
+static uint32_t HandlerGetRandom(void) {
+ uint32_t length, size;
+ uint8_t* bytes;
+ uint32_t result;
+ int i;
+ if (nargs != 3) {
+ fprintf(stderr, "usage: tpmc getrandom <size>\n");
+ exit(OTHER_ERROR);
+ }
+ if (HexStringToUint32(args[2], &length) != 0) {
+ fprintf(stderr, "<size> must be 32-bit hex (0x[0-9a-f]+)\n");
+ exit(OTHER_ERROR);
+ }
+ bytes = calloc(1, length);
+ if (bytes == NULL) {
+ perror("calloc");
+ exit(OTHER_ERROR);
+ }
+ result = TlclGetRandom(bytes, length, &size);
+ if (result == 0 && size > 0) {
+ for (i = 0; i < size; i++) {
+ printf("%02x", bytes[i]);
+ }
+ printf("\n");
+ }
+ free(bytes);
+ return result;
+}
+
static uint32_t HandlerGetPermanentFlags(void) {
TPM_PERMANENT_FLAGS pflags;
uint32_t result = TlclGetPermanentFlags(&pflags);
@@ -312,6 +341,8 @@ command_record command_table[] = {
HandlerGetPermissions },
{ "getpermanentflags", "getpf", "print all permanent flags",
HandlerGetPermanentFlags },
+ { "getrandom", "rand", "read bytes from RNG (rand <size>)",
+ HandlerGetRandom },
{ "getstclearflags", "getvf", "print all volatile (ST_CLEAR) flags",
HandlerGetSTClearFlags },
{ "resume", "res", "execute TPM_Startup(ST_STATE)", TlclResume },