| 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 * 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" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 | 79 |
| 80 int VerifySignatureInside(const void* parent, uint64_t parent_size, | 80 int VerifySignatureInside(const void* parent, uint64_t parent_size, |
| 81 const VbSignature* sig) { | 81 const VbSignature* sig) { |
| 82 return VerifyMemberInside(parent, parent_size, | 82 return VerifyMemberInside(parent, parent_size, |
| 83 sig, sizeof(VbSignature), | 83 sig, sizeof(VbSignature), |
| 84 sig->sig_offset, sig->sig_size); | 84 sig->sig_offset, sig->sig_size); |
| 85 } | 85 } |
| 86 | 86 |
| 87 | 87 |
| 88 void PublicKeyInit(VbPublicKey* key, uint8_t* key_data, uint64_t key_size) { |
| 89 key->key_offset = OffsetOf(key, key_data); |
| 90 key->key_size = key_size; |
| 91 key->algorithm = kNumAlgorithms; /* Key not present yet */ |
| 92 key->key_version = 0; |
| 93 } |
| 94 |
| 95 |
| 96 int PublicKeyCopy(VbPublicKey* dest, const VbPublicKey* src) { |
| 97 if (dest->key_size < src->key_size) |
| 98 return 1; |
| 99 |
| 100 dest->key_size = src->key_size; |
| 101 dest->algorithm = src->algorithm; |
| 102 dest->key_version = src->key_version; |
| 103 Memcpy(GetPublicKeyData(dest), GetPublicKeyDataC(src), src->key_size); |
| 104 return 0; |
| 105 } |
| 106 |
| 107 |
| 88 RSAPublicKey* PublicKeyToRSA(const VbPublicKey* key) { | 108 RSAPublicKey* PublicKeyToRSA(const VbPublicKey* key) { |
| 89 RSAPublicKey *rsa; | 109 RSAPublicKey *rsa; |
| 90 | 110 |
| 91 if (kNumAlgorithms <= key->algorithm) { | 111 if (kNumAlgorithms <= key->algorithm) { |
| 92 debug("Invalid algorithm.\n"); | 112 debug("Invalid algorithm.\n"); |
| 93 return NULL; | 113 return NULL; |
| 94 } | 114 } |
| 95 if (RSAProcessedKeySize(key->algorithm) != key->key_size) { | 115 if (RSAProcessedKeySize(key->algorithm) != key->key_size) { |
| 96 debug("Wrong key size for algorithm\n"); | 116 debug("Wrong key size for algorithm\n"); |
| 97 return NULL; | 117 return NULL; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 /* Verify body signature is inside the block */ | 332 /* Verify body signature is inside the block */ |
| 313 if (VerifySignatureInside(preamble, preamble->preamble_size, | 333 if (VerifySignatureInside(preamble, preamble->preamble_size, |
| 314 &preamble->body_signature)) { | 334 &preamble->body_signature)) { |
| 315 debug("Kernel body signature off end of preamble\n"); | 335 debug("Kernel body signature off end of preamble\n"); |
| 316 return VBOOT_PREAMBLE_INVALID; | 336 return VBOOT_PREAMBLE_INVALID; |
| 317 } | 337 } |
| 318 | 338 |
| 319 /* Success */ | 339 /* Success */ |
| 320 return VBOOT_SUCCESS; | 340 return VBOOT_SUCCESS; |
| 321 } | 341 } |
| OLD | NEW |