OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2010 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 * Data structure and API definitions for a verified boot firmware image. |
| 6 * (Firmware Portion) |
| 7 */ |
| 8 |
| 9 #ifndef VBOOT_REFERENCE_FIRMWARE_IMAGE_FW_H_ |
| 10 #define VBOOT_REFERENCE_FIRMWARE_IMAGE_FW_H_ |
| 11 |
| 12 #include <stdint.h> |
| 13 #include "rsa.h" |
| 14 #include "sha.h" |
| 15 |
| 16 #define FIRMWARE_MAGIC "CHROMEOS" |
| 17 #define FIRMWARE_MAGIC_SIZE 8 |
| 18 #define FIRMWARE_PREAMBLE_SIZE 8 |
| 19 |
| 20 /* RSA 8192 and SHA-512. */ |
| 21 #define ROOT_SIGNATURE_ALGORITHM 11 |
| 22 #define ROOT_SIGNATURE_ALGORITHM_STRING "11" |
| 23 |
| 24 typedef struct FirmwareImage { |
| 25 uint8_t magic[FIRMWARE_MAGIC_SIZE]; |
| 26 /* Key Header */ |
| 27 uint16_t header_len; /* Length of the header. */ |
| 28 uint16_t firmware_sign_algorithm; /* Signature algorithm used by the signing |
| 29 * key. */ |
| 30 uint16_t firmware_key_version; /* Key Version# for preventing rollbacks. */ |
| 31 uint8_t* firmware_sign_key; /* Pre-processed public half of signing key. */ |
| 32 uint8_t header_checksum[SHA512_DIGEST_SIZE]; /* SHA-512 hash of the header.*/ |
| 33 |
| 34 uint8_t firmware_key_signature[RSA8192NUMBYTES]; /* Signature of the header |
| 35 * above. */ |
| 36 |
| 37 /* Firmware Preamble. */ |
| 38 uint16_t firmware_version; /* Firmware Version# for preventing rollbacks.*/ |
| 39 uint64_t firmware_len; /* Length of the rest of the R/W firmware data. */ |
| 40 uint8_t preamble[FIRMWARE_PREAMBLE_SIZE]; /* Remaining preamble data.*/ |
| 41 |
| 42 uint8_t* preamble_signature; /* Signature over the preamble. */ |
| 43 |
| 44 /* The firmware signature comes first as it may allow us to parallelize |
| 45 * the firmware data fetch and RSA public operation. |
| 46 */ |
| 47 uint8_t* firmware_signature; /* Signature on the Preamble + |
| 48 [firmware_data]. */ |
| 49 uint8_t* firmware_data; /* Rest of firmware data */ |
| 50 |
| 51 } FirmwareImage; |
| 52 |
| 53 |
| 54 /* Error Codes for VerifyFirmware* family of functions. */ |
| 55 #define VERIFY_FIRMWARE_SUCCESS 0 |
| 56 #define VERIFY_FIRMWARE_INVALID_IMAGE 1 |
| 57 #define VERIFY_FIRMWARE_ROOT_SIGNATURE_FAILED 2 |
| 58 #define VERIFY_FIRMWARE_INVALID_ALGORITHM 3 |
| 59 #define VERIFY_FIRMWARE_PREAMBLE_SIGNATURE_FAILED 4 |
| 60 #define VERIFY_FIRMWARE_SIGNATURE_FAILED 5 |
| 61 #define VERIFY_FIRMWARE_WRONG_MAGIC 6 |
| 62 #define VERIFY_FIRMWARE_WRONG_HEADER_CHECKSUM 7 |
| 63 #define VERIFY_FIRMWARE_KEY_ROLLBACK 8 |
| 64 #define VERIFY_FIRMWARE_VERSION_ROLLBACK 9 |
| 65 #define VERIFY_FIRMWARE_MAX 10 /* Total number of error codes. */ |
| 66 |
| 67 extern char* kVerifyFirmwareErrors[VERIFY_FIRMWARE_MAX]; |
| 68 |
| 69 /* Checks for the sanity of the firmware header pointed by [header_blob]. |
| 70 * |
| 71 * On success, put signature algorithm in [algorithm], header length |
| 72 * in [header_len], and return 0. |
| 73 * Else, return error code on failure. |
| 74 */ |
| 75 int VerifyFirmwareHeader(const uint8_t* root_key_blob, |
| 76 const uint8_t* header_blob, |
| 77 int* algorithm, |
| 78 int* header_len); |
| 79 |
| 80 /* Checks the preamble signature on firmware preamble pointed by |
| 81 * [preamble_blob] using the signing key [sign_key]. |
| 82 * |
| 83 * On success, put firmware length into [firmware_len], and return 0. |
| 84 * Else, return error code on failure. |
| 85 */ |
| 86 int VerifyFirmwarePreamble(RSAPublicKey* sign_key, |
| 87 const uint8_t* preamble_blob, |
| 88 int algorithm, |
| 89 uint64_t* firmware_len); |
| 90 |
| 91 /* Checks the signature on the preamble + firmware data at |
| 92 * [preamble_start] and [firmware_data_start]. |
| 93 * The length of the actual firmware data is firmware_len and it is assumed to |
| 94 * be prepended with the signature whose size depends on the signature_algorithm |
| 95 * [algorithm]. This signature also covers the preamble data (but not the |
| 96 * preamble signature itself). |
| 97 * |
| 98 * Return 0 on success, error code on failure. |
| 99 */ |
| 100 int VerifyFirmwareData(RSAPublicKey* sign_key, |
| 101 const uint8_t* preamble_start, |
| 102 const uint8_t* firmware_data_start, |
| 103 uint64_t firmware_len, |
| 104 int algorithm); |
| 105 |
| 106 /* Performs a chained verify of the firmware blob [firmware_blob]. |
| 107 * |
| 108 * Returns 0 on success, error code on failure. |
| 109 * |
| 110 * NOTE: The length of the firmware blob is derived from reading the fields |
| 111 * in the first few bytes of the buffer. This might look risky but in firmware |
| 112 * land, the start address of the firmware_blob will always be fixed depending |
| 113 * on the memory map on the particular platform. In addition, the signature on |
| 114 * length itself is checked early in the verification process for extra safety. |
| 115 */ |
| 116 int VerifyFirmware(const uint8_t* root_key_blob, |
| 117 const uint8_t* firmware_blob); |
| 118 |
| 119 /* Returns the logical version of a firmware blob which is calculated as |
| 120 * (firmware_key_version << 16 | firmware_version). */ |
| 121 uint32_t GetLogicalFirmwareVersion(uint8_t* firmware_blob); |
| 122 |
| 123 #define BOOT_FIRMWARE_A_CONTINUE 1 |
| 124 #define BOOT_FIRMWARE_B_CONTINUE 2 |
| 125 #define BOOT_FIRMWARE_RECOVERY_CONTINUE 3 |
| 126 |
| 127 /* This function is the driver used by the RO firmware to |
| 128 * determine which copy of the firmware to boot from. It performs |
| 129 * the requisite rollback index checking, including updating them, |
| 130 * if required. |
| 131 * |
| 132 * Returns the code path to follow. It is one of: |
| 133 * BOOT_FIRMWARE_A_CONTINUE Boot from Firmware A |
| 134 * BOOT_FIRMWARE_B_CONTINUE Boot from Firmware B |
| 135 * BOOT_FIRMWARE_RECOVERY_CONTINUE Jump to recovery mode |
| 136 */ |
| 137 int VerifyFirmwareDriver_f(uint8_t* root_key_blob, |
| 138 uint8_t* firmwareA, |
| 139 uint8_t* firmwareB); |
| 140 |
| 141 |
| 142 #endif /* VBOOT_REFERENCE_FIRMWARE_IMAGE_FW_H_ */ |
OLD | NEW |