Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 * | 4 * |
| 5 * Common functions between firmware and kernel verified boot. | 5 * Common functions between firmware and kernel verified boot. |
| 6 * (Firmware portion) | 6 * (Firmware portion) |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "vboot_common.h" | 10 #include "vboot_common.h" |
| 11 #include "utility.h" | 11 #include "utility.h" |
| 12 | 12 |
| 13 | 13 |
| 14 char* kVbootErrors[VBOOT_ERROR_MAX] = { | 14 char* kVbootErrors[VBOOT_ERROR_MAX] = { |
| 15 "Success.", | 15 "Success.", |
| 16 "Key block invalid.", | 16 "Key block invalid.", |
| 17 "Key block signature failed.", | 17 "Key block signature failed.", |
| 18 "Key block hash failed.", | 18 "Key block hash failed.", |
| 19 "Public key invalid.", | 19 "Public key invalid.", |
| 20 "Preamble invalid.", | 20 "Preamble invalid.", |
| 21 "Preamble signature check failed.", | 21 "Preamble signature check failed.", |
| 22 "Shared data invalid." | |
| 22 }; | 23 }; |
| 23 | 24 |
| 24 | 25 |
| 25 uint64_t OffsetOf(const void *base, const void *ptr) { | 26 uint64_t OffsetOf(const void *base, const void *ptr) { |
| 26 return (uint64_t)(size_t)ptr - (uint64_t)(size_t)base; | 27 return (uint64_t)(size_t)ptr - (uint64_t)(size_t)base; |
| 27 } | 28 } |
| 28 | 29 |
| 29 | 30 |
| 30 /* Helper functions to get data pointed to by a public key or signature. */ | 31 /* Helper functions to get data pointed to by a public key or signature. */ |
| 31 uint8_t* GetPublicKeyData(VbPublicKey* key) { | 32 uint8_t* GetPublicKeyData(VbPublicKey* key) { |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 /* Verify body signature is inside the block */ | 371 /* Verify body signature is inside the block */ |
| 371 if (VerifySignatureInside(preamble, preamble->preamble_size, | 372 if (VerifySignatureInside(preamble, preamble->preamble_size, |
| 372 &preamble->body_signature)) { | 373 &preamble->body_signature)) { |
| 373 VBDEBUG(("Kernel body signature off end of preamble\n")); | 374 VBDEBUG(("Kernel body signature off end of preamble\n")); |
| 374 return VBOOT_PREAMBLE_INVALID; | 375 return VBOOT_PREAMBLE_INVALID; |
| 375 } | 376 } |
| 376 | 377 |
| 377 /* Success */ | 378 /* Success */ |
| 378 return VBOOT_SUCCESS; | 379 return VBOOT_SUCCESS; |
| 379 } | 380 } |
| 381 | |
| 382 | |
| 383 int VbSharedDataInit(VbSharedDataHeader* header, uint64_t size) { | |
| 384 if (size < sizeof(VbSharedDataHeader)) { | |
| 385 VBDEBUG(("Not enough data for header.\n")); | |
| 386 return VBOOT_SHARED_DATA_INVALID; | |
| 387 } | |
| 388 | |
| 389 if (!header) | |
| 390 return VBOOT_SHARED_DATA_INVALID; | |
| 391 | |
| 392 /* Zero the header */ | |
| 393 Memset(header, 0, sizeof(VbSharedDataHeader)); | |
| 394 | |
| 395 /* Initialize fields */ | |
| 396 header->struct_version = VB_SHARED_DATA_VERSION; | |
| 397 header->struct_size = sizeof(VbSharedDataHeader); | |
| 398 header->data_size = size; | |
| 399 header->data_used = sizeof(VbSharedDataHeader); | |
|
Bill Richardson
2011/03/09 20:52:20
What is the relationship between data_size and dat
Randall Spangler
2011/03/09 21:11:35
There is. See the first if() in this func.
size i
| |
| 400 | |
| 401 /* Success */ | |
| 402 return VBOOT_SUCCESS; | |
| 403 } | |
| 404 | |
| 405 | |
| 406 uint64_t VbSharedDataReserve(VbSharedDataHeader* header, uint64_t size) { | |
| 407 uint64_t offs = header->data_used; | |
| 408 | |
| 409 if (!header || size > header->data_size - header->data_used) | |
| 410 return 0; /* Not initialize, or not enough space left. */ | |
| 411 header->data_used += size; | |
| 412 return offs; | |
| 413 } | |
| 414 | |
| 415 | |
| 416 int VbSharedDataSetKernelKey(VbSharedDataHeader* header, | |
| 417 const VbPublicKey* src) { | |
| 418 | |
| 419 VbPublicKey *kdest = &header->kernel_subkey; | |
| 420 | |
| 421 if (!header) | |
| 422 return VBOOT_SHARED_DATA_INVALID; | |
| 423 | |
| 424 /* Attempt to allocate space for the key, if it hasn't been allocated yet */ | |
| 425 if (!header->kernel_subkey_data_offset) { | |
| 426 header->kernel_subkey_data_offset = VbSharedDataReserve(header, | |
| 427 src->key_size); | |
| 428 if (!header->kernel_subkey_data_offset) | |
| 429 return VBOOT_SHARED_DATA_INVALID; | |
| 430 header->kernel_subkey_data_size = src->key_size; | |
| 431 } | |
| 432 | |
| 433 /* Copy the kernel sign key blob into the destination buffer */ | |
| 434 PublicKeyInit(kdest, (uint8_t*)header + header->kernel_subkey_data_offset, | |
| 435 header->kernel_subkey_data_size); | |
| 436 | |
| 437 return PublicKeyCopy(kdest, src); | |
| 438 } | |
| OLD | NEW |