1*8617a60dSAndroid Build Coastguard Worker /* Copyright 2015 The ChromiumOS Authors
2*8617a60dSAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license that can be
3*8617a60dSAndroid Build Coastguard Worker * found in the LICENSE file.
4*8617a60dSAndroid Build Coastguard Worker *
5*8617a60dSAndroid Build Coastguard Worker * Functions for updating the TPM state with the status of boot path.
6*8617a60dSAndroid Build Coastguard Worker */
7*8617a60dSAndroid Build Coastguard Worker
8*8617a60dSAndroid Build Coastguard Worker #include "2common.h"
9*8617a60dSAndroid Build Coastguard Worker #include "2sha.h"
10*8617a60dSAndroid Build Coastguard Worker #include "2sysincludes.h"
11*8617a60dSAndroid Build Coastguard Worker #include "2tpm_bootmode.h"
12*8617a60dSAndroid Build Coastguard Worker
13*8617a60dSAndroid Build Coastguard Worker /*
14*8617a60dSAndroid Build Coastguard Worker * Input digests for PCR extend.
15*8617a60dSAndroid Build Coastguard Worker * These are calculated as:
16*8617a60dSAndroid Build Coastguard Worker * SHA1("|Developer_Mode||Recovery_Mode||Keyblock_Mode|").
17*8617a60dSAndroid Build Coastguard Worker * Developer_Mode can be 0 or 1.
18*8617a60dSAndroid Build Coastguard Worker * Recovery_Mode can be 0 or 1.
19*8617a60dSAndroid Build Coastguard Worker * Keyblock flags are defined in 2struct.h and assumed always 0 in recovery mode
20*8617a60dSAndroid Build Coastguard Worker * or 7 in non-recovery mode.
21*8617a60dSAndroid Build Coastguard Worker *
22*8617a60dSAndroid Build Coastguard Worker * We map them to Keyblock_Mode as follows:
23*8617a60dSAndroid Build Coastguard Worker * -----------------------------------------
24*8617a60dSAndroid Build Coastguard Worker * Keyblock Flags | Keyblock Mode
25*8617a60dSAndroid Build Coastguard Worker * -----------------------------------------
26*8617a60dSAndroid Build Coastguard Worker * 0 recovery mode | 0
27*8617a60dSAndroid Build Coastguard Worker * 7 Normal-signed firmware | 1
28*8617a60dSAndroid Build Coastguard Worker */
29*8617a60dSAndroid Build Coastguard Worker
30*8617a60dSAndroid Build Coastguard Worker const uint8_t kBootStateSHA1Digests[][VB2_SHA1_DIGEST_SIZE] = {
31*8617a60dSAndroid Build Coastguard Worker /* SHA1(0x00|0x00|0x01) */
32*8617a60dSAndroid Build Coastguard Worker {0x25, 0x47, 0xcc, 0x73, 0x6e, 0x95, 0x1f, 0xa4, 0x91, 0x98, 0x53, 0xc4,
33*8617a60dSAndroid Build Coastguard Worker 0x3a, 0xe8, 0x90, 0x86, 0x1a, 0x3b, 0x32, 0x64},
34*8617a60dSAndroid Build Coastguard Worker
35*8617a60dSAndroid Build Coastguard Worker /* SHA1(0x01|0x00|0x01) */
36*8617a60dSAndroid Build Coastguard Worker {0xc4, 0x2a, 0xc1, 0xc4, 0x6f, 0x1d, 0x4e, 0x21, 0x1c, 0x73, 0x5c, 0xc7,
37*8617a60dSAndroid Build Coastguard Worker 0xdf, 0xad, 0x4f, 0xf8, 0x39, 0x11, 0x10, 0xe9},
38*8617a60dSAndroid Build Coastguard Worker
39*8617a60dSAndroid Build Coastguard Worker /* SHA1(0x00|0x01|0x00) */
40*8617a60dSAndroid Build Coastguard Worker {0x62, 0x57, 0x18, 0x91, 0x21, 0x5b, 0x4e, 0xfc, 0x1c, 0xea, 0xb7, 0x44,
41*8617a60dSAndroid Build Coastguard Worker 0xce, 0x59, 0xdd, 0x0b, 0x66, 0xea, 0x6f, 0x73},
42*8617a60dSAndroid Build Coastguard Worker
43*8617a60dSAndroid Build Coastguard Worker /* SHA1(0x01|0x01|0x00) */
44*8617a60dSAndroid Build Coastguard Worker {0x47, 0xec, 0x8d, 0x98, 0x36, 0x64, 0x33, 0xdc, 0x00, 0x2e, 0x77, 0x21,
45*8617a60dSAndroid Build Coastguard Worker 0xc9, 0xe3, 0x7d, 0x50, 0x67, 0x54, 0x79, 0x37},
46*8617a60dSAndroid Build Coastguard Worker };
47*8617a60dSAndroid Build Coastguard Worker
vb2_get_boot_state_digest(struct vb2_context * ctx)48*8617a60dSAndroid Build Coastguard Worker const uint8_t *vb2_get_boot_state_digest(struct vb2_context *ctx)
49*8617a60dSAndroid Build Coastguard Worker {
50*8617a60dSAndroid Build Coastguard Worker int index = (ctx->flags & VB2_CONTEXT_RECOVERY_MODE ? 2 : 0) +
51*8617a60dSAndroid Build Coastguard Worker (ctx->flags & VB2_CONTEXT_DEVELOPER_MODE ? 1 : 0);
52*8617a60dSAndroid Build Coastguard Worker
53*8617a60dSAndroid Build Coastguard Worker return kBootStateSHA1Digests[index];
54*8617a60dSAndroid Build Coastguard Worker }
55