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