| 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 * Functions for generating and manipulating a verified boot kernel image. | 5 * Functions for generating and manipulating a verified boot kernel image. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "kernel_image.h" | 8 #include "kernel_image.h" |
| 9 | 9 |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 FIELD_LEN(options.kernel_load_addr)); | 243 FIELD_LEN(options.kernel_load_addr)); |
| 244 StatefulMemcpy_r(&st, &image->options.kernel_entry_addr, | 244 StatefulMemcpy_r(&st, &image->options.kernel_entry_addr, |
| 245 FIELD_LEN(options.kernel_entry_addr)); | 245 FIELD_LEN(options.kernel_entry_addr)); |
| 246 if (st.remaining_len != 0) { /* Overrun or Underrun. */ | 246 if (st.remaining_len != 0) { /* Overrun or Underrun. */ |
| 247 Free(config_blob); | 247 Free(config_blob); |
| 248 return NULL; | 248 return NULL; |
| 249 } | 249 } |
| 250 return config_blob; | 250 return config_blob; |
| 251 } | 251 } |
| 252 | 252 |
| 253 uint8_t* GetKernelBlob(const KernelImage* image, int* blob_len) { | 253 uint8_t* GetKernelBlob(const KernelImage* image, uint64_t* blob_len) { |
| 254 int kernel_key_signature_len; | 254 int kernel_key_signature_len; |
| 255 int kernel_signature_len; | 255 int kernel_signature_len; |
| 256 uint8_t* kernel_blob = NULL; | 256 uint8_t* kernel_blob = NULL; |
| 257 uint8_t* header_blob = NULL; | 257 uint8_t* header_blob = NULL; |
| 258 uint8_t* config_blob = NULL; | 258 uint8_t* config_blob = NULL; |
| 259 MemcpyState st; | 259 MemcpyState st; |
| 260 | 260 |
| 261 if (!image) | 261 if (!image) |
| 262 return NULL; | 262 return NULL; |
| 263 kernel_key_signature_len = siglen_map[image->firmware_sign_algorithm]; | 263 kernel_key_signature_len = siglen_map[image->firmware_sign_algorithm]; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 290 Free(kernel_blob); | 290 Free(kernel_blob); |
| 291 return NULL; | 291 return NULL; |
| 292 } | 292 } |
| 293 return kernel_blob; | 293 return kernel_blob; |
| 294 } | 294 } |
| 295 | 295 |
| 296 int WriteKernelImage(const char* input_file, | 296 int WriteKernelImage(const char* input_file, |
| 297 const KernelImage* image) { | 297 const KernelImage* image) { |
| 298 int fd; | 298 int fd; |
| 299 uint8_t* kernel_blob; | 299 uint8_t* kernel_blob; |
| 300 int blob_len; | 300 uint64_t blob_len; |
| 301 | 301 |
| 302 if (!image) | 302 if (!image) |
| 303 return 0; | 303 return 0; |
| 304 if (-1 == (fd = creat(input_file, S_IRWXU))) { | 304 if (-1 == (fd = creat(input_file, S_IRWXU))) { |
| 305 fprintf(stderr, "Couldn't open file for writing kernel image: %s\n", | 305 fprintf(stderr, "Couldn't open file for writing kernel image: %s\n", |
| 306 input_file); | 306 input_file); |
| 307 return 0; | 307 return 0; |
| 308 } | 308 } |
| 309 kernel_blob = GetKernelBlob(image, &blob_len); | 309 kernel_blob = GetKernelBlob(image, &blob_len); |
| 310 if (!kernel_blob) { | 310 if (!kernel_blob) { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 kernel_signing_key_file, | 703 kernel_signing_key_file, |
| 704 image->kernel_sign_algorithm))) { | 704 image->kernel_sign_algorithm))) { |
| 705 fprintf(stderr, "Could not compute signature on the kernel.\n"); | 705 fprintf(stderr, "Could not compute signature on the kernel.\n"); |
| 706 return 0; | 706 return 0; |
| 707 } | 707 } |
| 708 image->kernel_signature = (uint8_t*) Malloc(signature_len); | 708 image->kernel_signature = (uint8_t*) Malloc(signature_len); |
| 709 Memcpy(image->kernel_signature, kernel_signature, signature_len); | 709 Memcpy(image->kernel_signature, kernel_signature, signature_len); |
| 710 Free(kernel_signature); | 710 Free(kernel_signature); |
| 711 return 1; | 711 return 1; |
| 712 } | 712 } |
| OLD | NEW |