| OLD | NEW |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 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 * Host functions for verified boot. | 5 * Host functions for verified boot. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ | |
| 9 | |
| 10 #include "host_keyblock.h" | 8 #include "host_keyblock.h" |
| 11 | 9 |
| 12 #include "cryptolib.h" | 10 #include "cryptolib.h" |
| 13 #include "host_common.h" | 11 #include "host_common.h" |
| 14 #include "utility.h" | 12 #include "utility.h" |
| 15 #include "vboot_common.h" | 13 #include "vboot_common.h" |
| 16 | 14 |
| 17 | 15 |
| 18 VbKeyBlockHeader* KeyBlockCreate(const VbPublicKey* data_key, | 16 VbKeyBlockHeader* KeyBlockCreate(const VbPublicKey* data_key, |
| 19 const VbPrivateKey* signing_key, | 17 const VbPrivateKey* signing_key, |
| 20 uint64_t flags) { | 18 uint64_t flags) { |
| 21 | 19 |
| 22 VbKeyBlockHeader* h; | 20 VbKeyBlockHeader* h; |
| 23 uint64_t signed_size = sizeof(VbKeyBlockHeader) + data_key->key_size; | 21 uint64_t signed_size = sizeof(VbKeyBlockHeader) + data_key->key_size; |
| 24 uint64_t block_size = (signed_size + SHA512_DIGEST_SIZE + | 22 uint64_t block_size = (signed_size + SHA512_DIGEST_SIZE + |
| 25 (signing_key ? siglen_map[signing_key->algorithm] : 0))
; | 23 (signing_key ? |
| 24 siglen_map[signing_key->algorithm] : 0)); |
| 26 uint8_t* data_key_dest; | 25 uint8_t* data_key_dest; |
| 27 uint8_t* block_sig_dest; | 26 uint8_t* block_sig_dest; |
| 28 uint8_t* block_chk_dest; | 27 uint8_t* block_chk_dest; |
| 29 VbSignature *sigtmp; | 28 VbSignature *sigtmp; |
| 30 | 29 |
| 31 /* Allocate key block */ | 30 /* Allocate key block */ |
| 32 h = (VbKeyBlockHeader*)Malloc(block_size); | 31 h = (VbKeyBlockHeader*)Malloc(block_size); |
| 33 if (!h) | 32 if (!h) |
| 34 return NULL; | 33 return NULL; |
| 35 data_key_dest = (uint8_t*)(h + 1); | 34 data_key_dest = (uint8_t*)(h + 1); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 uint64_t file_size; | 81 uint64_t file_size; |
| 83 | 82 |
| 84 block = (VbKeyBlockHeader*)ReadFile(filename, &file_size); | 83 block = (VbKeyBlockHeader*)ReadFile(filename, &file_size); |
| 85 if (!block) { | 84 if (!block) { |
| 86 VBDEBUG(("Error reading key block file: %s\n", filename)); | 85 VBDEBUG(("Error reading key block file: %s\n", filename)); |
| 87 return NULL; | 86 return NULL; |
| 88 } | 87 } |
| 89 | 88 |
| 90 /* Verify the hash of the key block, since we can do that without | 89 /* Verify the hash of the key block, since we can do that without |
| 91 * the public signing key. */ | 90 * the public signing key. */ |
| 92 if (0 != KeyBlockVerify(block, file_size, NULL)) { | 91 if (0 != KeyBlockVerify(block, file_size, NULL, 1)) { |
| 93 VBDEBUG(("Invalid key block file: filename\n", filename)); | 92 VBDEBUG(("Invalid key block file: filename\n", filename)); |
| 94 Free(block); | 93 Free(block); |
| 95 return NULL; | 94 return NULL; |
| 96 } | 95 } |
| 97 | 96 |
| 98 return block; | 97 return block; |
| 99 } | 98 } |
| 100 | 99 |
| 101 | 100 |
| 102 /* Write a key block to a file in .keyblock format. */ | 101 /* Write a key block to a file in .keyblock format. */ |
| 103 int KeyBlockWrite(const char* filename, const VbKeyBlockHeader* key_block) { | 102 int KeyBlockWrite(const char* filename, const VbKeyBlockHeader* key_block) { |
| 104 | 103 |
| 105 if (0 != WriteFile(filename, key_block, key_block->key_block_size)) { | 104 if (0 != WriteFile(filename, key_block, key_block->key_block_size)) { |
| 106 VBDEBUG(("KeyBlockWrite() error writing key block\n")); | 105 VBDEBUG(("KeyBlockWrite() error writing key block\n")); |
| 107 return 1; | 106 return 1; |
| 108 } | 107 } |
| 109 | 108 |
| 110 return 0; | 109 return 0; |
| 111 } | 110 } |
| OLD | NEW |