blob: 0a211c57d4c8751a71317e37037e09f30dad3cda [file] [log] [blame]
Christian Walter0bd84ed2019-07-23 10:26:30 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14
15#include <security/tpm/tspi.h>
16#include <vb2_api.h>
17#include <security/vboot/tpm_common.h>
18
19#define TPM_PCR_BOOT_MODE "VBOOT: boot mode"
20#define TPM_PCR_GBB_HWID_NAME "VBOOT: GBB HWID"
21
22uint32_t vboot_setup_tpm(struct vb2_context *ctx)
23{
24 uint32_t result;
25
26 result = tpm_setup(ctx->flags & VB2_CONTEXT_S3_RESUME);
27 if (result == TPM_E_MUST_REBOOT)
28 ctx->flags |= VB2_CONTEXT_SECDATA_WANTS_REBOOT;
29
30 return result;
31}
32
Joel Kitching220ac042019-07-31 14:19:00 +080033vb2_error_t vboot_extend_pcr(struct vb2_context *ctx, int pcr,
34 enum vb2_pcr_digest which_digest)
Christian Walter0bd84ed2019-07-23 10:26:30 +020035{
36 uint8_t buffer[VB2_PCR_DIGEST_RECOMMENDED_SIZE];
37 uint32_t size = sizeof(buffer);
Joel Kitching220ac042019-07-31 14:19:00 +080038 vb2_error_t rv;
Christian Walter0bd84ed2019-07-23 10:26:30 +020039
40 rv = vb2api_get_pcr_digest(ctx, which_digest, buffer, &size);
41 if (rv != VB2_SUCCESS)
42 return rv;
43 if (size < TPM_PCR_MINIMUM_DIGEST_SIZE)
44 return VB2_ERROR_UNKNOWN;
45
46 switch (which_digest) {
47 /* SHA1 of (devmode|recmode|keyblock) bits */
48 case BOOT_MODE_PCR:
Andrey Pronin31839f32019-09-19 09:27:23 -070049 return tpm_extend_pcr(pcr, VB2_HASH_SHA256, buffer, size,
Christian Walter0bd84ed2019-07-23 10:26:30 +020050 TPM_PCR_BOOT_MODE);
51 /* SHA256 of HWID */
52 case HWID_DIGEST_PCR:
53 return tpm_extend_pcr(pcr, VB2_HASH_SHA256, buffer,
54 size, TPM_PCR_GBB_HWID_NAME);
55 default:
56 return VB2_ERROR_UNKNOWN;
57 }
58}