diff options
author | Kees Cook <keescook@chromium.org> | 2012-02-29 16:09:14 -0800 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-03-01 15:25:31 -0800 |
commit | f0605cbdc36f58829a908a3333e438c565c8c7af (patch) | |
tree | 3cbf146c627d95d2d01461ac0224d90234e802fe /firmware/lib/tpm_lite/tlcl.c | |
parent | 5ee257d94cb8aab2f3717c5cd4ceb37fbba3ec41 (diff) | |
download | vboot-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 'firmware/lib/tpm_lite/tlcl.c')
-rw-r--r-- | firmware/lib/tpm_lite/tlcl.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/firmware/lib/tpm_lite/tlcl.c b/firmware/lib/tpm_lite/tlcl.c index 338e2f67..9e9ece84 100644 --- a/firmware/lib/tpm_lite/tlcl.c +++ b/firmware/lib/tpm_lite/tlcl.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 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. */ @@ -396,3 +396,34 @@ uint32_t TlclGetPermissions(uint32_t index, uint32_t* permissions) { FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions); return result; } + +uint32_t TlclGetRandom(uint8_t* data, uint32_t length, uint32_t *size) { + struct s_tpm_get_random_cmd cmd; + uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; + uint32_t result; + + VBDEBUG(("TPM: TlclGetRandom(%d)\n", length)); + Memcpy(&cmd, &tpm_get_random_cmd, sizeof(cmd)); + ToTpmUint32(cmd.buffer + tpm_get_random_cmd.bytesRequested, length); + /* There must be room in the response buffer for the bytes. */ + if (length > TPM_LARGE_ENOUGH_COMMAND_SIZE - kTpmResponseHeaderLength + - sizeof(uint32_t)) { + return TPM_E_IOERROR; + } + + result = TlclSendReceive(cmd.buffer, response, sizeof(response)); + if (result == TPM_SUCCESS) { + uint8_t* get_random_cursor; + FromTpmUint32(response + kTpmResponseHeaderLength, size); + + /* There must be room in the target buffer for the bytes. */ + if (*size > length) { + return TPM_E_RESPONSE_TOO_LARGE; + } + get_random_cursor = response + kTpmResponseHeaderLength + + sizeof(uint32_t); + Memcpy(data, get_random_cursor, *size); + } + + return result; +} |