2tpm_bootmode.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include "2sysincludes.h"
  8. #include "2common.h"
  9. #include "2sha.h"
  10. #include "2tpm_bootmode.h"
  11. /*
  12. * Input digests for PCR extend.
  13. * These are calculated as:
  14. * SHA1("|Developer_Mode||Recovery_Mode||Keyblock_Mode|").
  15. * Developer_Mode can be 0 or 1.
  16. * Recovery_Mode can be 0 or 1.
  17. * Keyblock flags are defined in 2struct.h and assumed always 0 in recovery mode
  18. * or 7 in non-recovery mode.
  19. *
  20. * We map them to Keyblock_Mode as follows:
  21. * -----------------------------------------
  22. * Keyblock Flags | Keyblock Mode
  23. * -----------------------------------------
  24. * 0 recovery mode | 0
  25. * 7 Normal-signed firmware | 1
  26. */
  27. const uint8_t kBootStateSHA1Digests[][VB2_SHA1_DIGEST_SIZE] = {
  28. /* SHA1(0x00|0x00|0x01) */
  29. {0x25, 0x47, 0xcc, 0x73, 0x6e, 0x95, 0x1f, 0xa4, 0x91, 0x98, 0x53, 0xc4,
  30. 0x3a, 0xe8, 0x90, 0x86, 0x1a, 0x3b, 0x32, 0x64},
  31. /* SHA1(0x01|0x00|0x01) */
  32. {0xc4, 0x2a, 0xc1, 0xc4, 0x6f, 0x1d, 0x4e, 0x21, 0x1c, 0x73, 0x5c, 0xc7,
  33. 0xdf, 0xad, 0x4f, 0xf8, 0x39, 0x11, 0x10, 0xe9},
  34. /* SHA1(0x00|0x01|0x00) */
  35. {0x62, 0x57, 0x18, 0x91, 0x21, 0x5b, 0x4e, 0xfc, 0x1c, 0xea, 0xb7, 0x44,
  36. 0xce, 0x59, 0xdd, 0x0b, 0x66, 0xea, 0x6f, 0x73},
  37. /* SHA1(0x01|0x01|0x00) */
  38. {0x47, 0xec, 0x8d, 0x98, 0x36, 0x64, 0x33, 0xdc, 0x00, 0x2e, 0x77, 0x21,
  39. 0xc9, 0xe3, 0x7d, 0x50, 0x67, 0x54, 0x79, 0x37},
  40. };
  41. const uint8_t *vb2_get_boot_state_digest(struct vb2_context *ctx)
  42. {
  43. int index = (ctx->flags & VB2_CONTEXT_RECOVERY_MODE ? 2 : 0) +
  44. (ctx->flags & VB2_CONTEXT_DEVELOPER_MODE ? 1 : 0);
  45. return kBootStateSHA1Digests[index];
  46. }