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 */ | 8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ |
9 | 9 |
10 #include "host_common.h" | 10 #include "host_common.h" |
11 | 11 |
12 #include "cryptolib.h" | 12 #include "cryptolib.h" |
13 #include "utility.h" | 13 #include "utility.h" |
14 #include "vboot_common.h" | 14 #include "vboot_common.h" |
15 | 15 |
16 | 16 |
17 VbKeyBlockHeader* CreateKeyBlock(const VbPublicKey* data_key, | |
18 const VbPrivateKey* signing_key, | |
19 uint64_t flags) { | |
20 | |
21 VbKeyBlockHeader* h; | |
22 uint64_t signed_size = sizeof(VbKeyBlockHeader) + data_key->key_size; | |
23 uint64_t block_size = (signed_size + SHA512_DIGEST_SIZE + | |
24 siglen_map[signing_key->algorithm]); | |
25 uint8_t* data_key_dest; | |
26 uint8_t* block_sig_dest; | |
27 uint8_t* block_chk_dest; | |
28 VbSignature *sigtmp; | |
29 | |
30 /* Allocate key block */ | |
31 h = (VbKeyBlockHeader*)Malloc(block_size); | |
32 if (!h) | |
33 return NULL; | |
34 data_key_dest = (uint8_t*)(h + 1); | |
35 block_chk_dest = data_key_dest + data_key->key_size; | |
36 block_sig_dest = block_chk_dest + SHA512_DIGEST_SIZE; | |
37 | |
38 Memcpy(h->magic, KEY_BLOCK_MAGIC, KEY_BLOCK_MAGIC_SIZE); | |
39 h->header_version_major = KEY_BLOCK_HEADER_VERSION_MAJOR; | |
40 h->header_version_minor = KEY_BLOCK_HEADER_VERSION_MINOR; | |
41 h->key_block_size = block_size; | |
42 h->key_block_flags = flags; | |
43 | |
44 /* Copy data key */ | |
45 PublicKeyInit(&h->data_key, data_key_dest, data_key->key_size); | |
46 PublicKeyCopy(&h->data_key, data_key); | |
47 | |
48 /* Set up signature structs so we can calculate the signatures */ | |
49 SignatureInit(&h->key_block_checksum, block_chk_dest, | |
50 SHA512_DIGEST_SIZE, signed_size); | |
51 SignatureInit(&h->key_block_signature, block_sig_dest, | |
52 siglen_map[signing_key->algorithm], signed_size); | |
53 | |
54 /* Calculate checksum */ | |
55 sigtmp = CalculateChecksum((uint8_t*)h, signed_size); | |
56 SignatureCopy(&h->key_block_checksum, sigtmp); | |
57 Free(sigtmp); | |
58 | |
59 /* Calculate signature */ | |
60 sigtmp = CalculateSignature((uint8_t*)h, signed_size, signing_key); | |
61 SignatureCopy(&h->key_block_signature, sigtmp); | |
62 Free(sigtmp); | |
63 | |
64 /* Return the header */ | |
65 return h; | |
66 } | |
67 | |
68 | |
69 VbFirmwarePreambleHeader* CreateFirmwarePreamble( | 17 VbFirmwarePreambleHeader* CreateFirmwarePreamble( |
70 uint64_t firmware_version, | 18 uint64_t firmware_version, |
71 const VbPublicKey* kernel_subkey, | 19 const VbPublicKey* kernel_subkey, |
72 const VbSignature* body_signature, | 20 const VbSignature* body_signature, |
73 const VbPrivateKey* signing_key) { | 21 const VbPrivateKey* signing_key) { |
74 | 22 |
75 VbFirmwarePreambleHeader* h; | 23 VbFirmwarePreambleHeader* h; |
76 uint64_t signed_size = (sizeof(VbFirmwarePreambleHeader) + | 24 uint64_t signed_size = (sizeof(VbFirmwarePreambleHeader) + |
77 kernel_subkey->key_size + | 25 kernel_subkey->key_size + |
78 body_signature->sig_size); | 26 body_signature->sig_size); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 siglen_map[signing_key->algorithm], signed_size); | 117 siglen_map[signing_key->algorithm], signed_size); |
170 | 118 |
171 /* Calculate signature */ | 119 /* Calculate signature */ |
172 sigtmp = CalculateSignature((uint8_t*)h, signed_size, signing_key); | 120 sigtmp = CalculateSignature((uint8_t*)h, signed_size, signing_key); |
173 SignatureCopy(&h->preamble_signature, sigtmp); | 121 SignatureCopy(&h->preamble_signature, sigtmp); |
174 Free(sigtmp); | 122 Free(sigtmp); |
175 | 123 |
176 /* Return the header */ | 124 /* Return the header */ |
177 return h; | 125 return h; |
178 } | 126 } |
OLD | NEW |