Verified boot wrapper - add stub implementations for host
This is part 2 of the wrapper API refactor. It adds stub
implementations for the host, and changes the host-side utilities to
use them. Firmware implementation is unchanged in this CL (other than
a few updates to macros).
BUG=chromium_os:16997
TEST=make && make runtests
Change-Id: I63989bd11de1f2239ddae256beaccd31bfb5acef
Reviewed-on: http://gerrit.chromium.org/gerrit/3256
Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
Tested-by: Randall Spangler <rspangler@chromium.org>
diff --git a/utility/dev_sign_file.c b/utility/dev_sign_file.c
index ac3f400..b20423f 100644
--- a/utility/dev_sign_file.c
+++ b/utility/dev_sign_file.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -104,26 +104,26 @@
/* Read the file that we're going to sign. */
file_data = ReadFile(filename, &file_size);
if (!file_data) {
- error("Error reading file to sign.\n");
+ VbExError("Error reading file to sign.\n");
return 1;
}
/* Get the key block and read the private key corresponding to it. */
key_block = (VbKeyBlockHeader*)ReadFile(keyblock_file, &key_block_size);
if (!key_block) {
- error("Error reading key block.\n");
+ VbExError("Error reading key block.\n");
return 1;
}
signing_key = PrivateKeyRead(signprivate_file);
if (!signing_key) {
- error("Error reading signing key.\n");
+ VbExError("Error reading signing key.\n");
return 1;
}
/* Sign the file data */
body_sig = CalculateSignature(file_data, file_size, signing_key);
if (!body_sig) {
- error("Error calculating body signature\n");
+ VbExError("Error calculating body signature\n");
return 1;
}
@@ -136,7 +136,7 @@
(uint64_t)0,
signing_key);
if (!preamble) {
- error("Error creating preamble.\n");
+ VbExError("Error creating preamble.\n");
return 1;
}
@@ -144,14 +144,14 @@
Debug("writing %s...\n", outfile);
output_fp = fopen(outfile, "wb");
if (!output_fp) {
- error("Can't open output file %s\n", outfile);
+ VbExError("Can't open output file %s\n", outfile);
return 1;
}
Debug("0x%" PRIx64 " bytes of key_block\n", key_block_size);
Debug("0x%" PRIx64 " bytes of preamble\n", preamble->preamble_size);
if ((1 != fwrite(key_block, key_block_size, 1, output_fp)) ||
(1 != fwrite(preamble, preamble->preamble_size, 1, output_fp))) {
- error("Can't write output file %s\n", outfile);
+ VbExError("Can't write output file %s\n", outfile);
fclose(output_fp);
unlink(outfile);
return 1;
@@ -159,11 +159,11 @@
fclose(output_fp);
/* Done */
- Free(preamble);
- Free(body_sig);
- Free(signing_key);
- Free(key_block);
- Free(file_data);
+ free(preamble);
+ free(body_sig);
+ free(signing_key);
+ free(key_block);
+ free(file_data);
/* Success */
return 0;
@@ -184,14 +184,14 @@
/* Read the file that we're going to verify. */
file_data = ReadFile(filename, &file_size);
if (!file_data) {
- error("Error reading file to sign.\n");
+ VbExError("Error reading file to sign.\n");
return 1;
}
/* Read the vblock that we're going to use on it */
buf = ReadFile(vblock_file, &buf_size);
if (!buf) {
- error("Error reading vblock_file.\n");
+ VbExError("Error reading vblock_file.\n");
return 1;
}
@@ -200,7 +200,7 @@
Debug("Keyblock is 0x%" PRIx64 " bytes\n", key_block->key_block_size);
current_buf_offset += key_block->key_block_size;
if (current_buf_offset > buf_size) {
- error("key_block_size advances past the end of the buffer\n");
+ VbExError("key_block_size advances past the end of the buffer\n");
return 1;
}
@@ -209,7 +209,7 @@
Debug("Preamble is 0x%" PRIx64 " bytes\n", preamble->preamble_size);
current_buf_offset += preamble->preamble_size;
if (current_buf_offset > buf_size ) {
- error("preamble_size advances past the end of the buffer\n");
+ VbExError("preamble_size advances past the end of the buffer\n");
return 1;
}
@@ -217,7 +217,7 @@
/* Check the key block (hash only) */
if (0 != KeyBlockVerify(key_block, key_block->key_block_size, NULL, 1)) {
- error("Error verifying key block.\n");
+ VbExError("Error verifying key block.\n");
return 1;
}
@@ -234,11 +234,11 @@
/* Verify preamble */
rsa = PublicKeyToRSA(&key_block->data_key);
if (!rsa) {
- error("Error parsing data key.\n");
+ VbExError("Error parsing data key.\n");
return 1;
}
if (0 != VerifyKernelPreamble(preamble, preamble->preamble_size, rsa)) {
- error("Error verifying preamble.\n");
+ VbExError("Error verifying preamble.\n");
return 1;
}
@@ -256,14 +256,14 @@
/* Verify body */
if (0 != VerifyData(file_data, file_size, &preamble->body_signature, rsa)) {
- error("Error verifying kernel body.\n");
+ VbExError("Error verifying kernel body.\n");
return 1;
}
printf("Body verification succeeded.\n");
if (keyblock_file) {
if (0 != WriteFile(keyblock_file, key_block, key_block->key_block_size)) {
- error("Unable to export keyblock file\n");
+ VbExError("Unable to export keyblock file\n");
return 1;
}
printf("Key block exported to %s\n", keyblock_file);
diff --git a/utility/dump_kernel_config.c b/utility/dump_kernel_config.c
index b44a12e..720cc85 100644
--- a/utility/dump_kernel_config.c
+++ b/utility/dump_kernel_config.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -12,10 +12,10 @@
#include <sys/mman.h>
#include <unistd.h>
+#include "host_common.h"
#include "kernel_blob.h"
-#include "utility.h"
#include "vboot_common.h"
-#include "vboot_struct.h"
+
enum {
OPT_KLOADADDR = 1000,
@@ -49,7 +49,7 @@
key_block = (VbKeyBlockHeader*)blob;
now += key_block->key_block_size;
if (now + blob > blob + blob_size) {
- error("key_block_size advances past the end of the blob\n");
+ VbExError("key_block_size advances past the end of the blob\n");
return NULL;
}
@@ -57,7 +57,7 @@
preamble = (VbKernelPreambleHeader*)(blob + now);
now += preamble->preamble_size;
if (now + blob > blob + blob_size) {
- error("preamble_size advances past the end of the blob\n");
+ VbExError("preamble_size advances past the end of the blob\n");
return NULL;
}
@@ -66,7 +66,7 @@
offset = preamble->bootloader_address -
(kernel_body_load_address + CROS_PARAMS_SIZE) + now;
if (offset > blob_size) {
- error("params are outside of the memory blob: %x\n", offset);
+ VbExError("params are outside of the memory blob: %x\n", offset);
return NULL;
}
params = (struct linux_kernel_params *)(blob + offset);
@@ -74,7 +74,7 @@
/* Grab the offset to the kernel command line using the supplied pointer. */
offset = params->cmd_line_ptr - kernel_body_load_address + now;
if (offset > blob_size) {
- error("cmdline is outside of the memory blob: %x\n", offset);
+ VbExError("cmdline is outside of the memory blob: %x\n", offset);
return NULL;
}
return (uint8_t *)(blob + offset);
@@ -104,7 +104,7 @@
/* Uses a host primitive as this is not meant for firmware use. */
buf = mmap(NULL, *size, PROT_READ, MAP_PRIVATE, fileno(f), 0);
if (buf == MAP_FAILED) {
- error("Failed to mmap the file %s\n", filename);
+ VbExError("Failed to mmap the file %s\n", filename);
fclose(f);
return NULL;
}
@@ -156,21 +156,21 @@
return PrintHelp();
if (!infile || !*infile) {
- error("Must specify filename\n");
+ VbExError("Must specify filename\n");
return 1;
}
/* Map the kernel image blob. */
blob = MapFile(infile, &blob_size);
if (!blob) {
- error("Error reading input file\n");
+ VbExError("Error reading input file\n");
return 1;
}
config = find_kernel_config(blob, (uint64_t)blob_size,
kernel_body_load_address);
if (!config) {
- error("Error parsing input file\n");
+ VbExError("Error parsing input file\n");
munmap(blob, blob_size);
return 1;
}
diff --git a/utility/load_firmware_test.c b/utility/load_firmware_test.c
index a8f7552..872bb4c 100644
--- a/utility/load_firmware_test.c
+++ b/utility/load_firmware_test.c
@@ -11,9 +11,9 @@
#include "fmap.h"
#include "gbb_header.h"
+#include "host_common.h"
#include "host_misc.h"
#include "load_firmware_fw.h"
-#include "vboot_struct.h"
typedef struct _CallerInternal {
@@ -187,7 +187,7 @@
ci.firmware[index].size);
}
- lfp.shared_data_blob = Malloc(VB_SHARED_DATA_MIN_SIZE);
+ lfp.shared_data_blob = malloc(VB_SHARED_DATA_MIN_SIZE);
lfp.shared_data_size = VB_SHARED_DATA_MIN_SIZE;
printf("shared data size 0x%08" PRIx64 "\n", lfp.shared_data_size);
@@ -203,7 +203,7 @@
if (status == LOAD_FIRMWARE_SUCCESS)
printf("firmwiare index is %" PRIu64 "\n", lfp.firmware_index);
- Free(lfp.shared_data_blob);
+ free(lfp.shared_data_blob);
return 0;
}
@@ -264,7 +264,7 @@
retval = DriveLoadFirmware(base_of_rom, fmap, boot_flags);
- Free((void*) base_of_rom);
+ free((void*) base_of_rom);
return retval;
}
diff --git a/utility/load_kernel_test.c b/utility/load_kernel_test.c
index 73a3626..6b0f9a8 100644
--- a/utility/load_kernel_test.c
+++ b/utility/load_kernel_test.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -14,13 +14,12 @@
#include <sys/types.h>
#include <unistd.h>
-#include "load_firmware_fw.h"
-#include "load_kernel_fw.h"
#include "boot_device.h"
#include "gbb_header.h"
#include "host_common.h"
+#include "load_firmware_fw.h"
+#include "load_kernel_fw.h"
#include "rollback_index.h"
-#include "utility.h"
#include "vboot_common.h"
#include "vboot_kernel.h"
@@ -52,7 +51,6 @@
return 0;
}
-
int BootDeviceWriteLBA(uint64_t lba_start, uint64_t lba_count,
const void *buffer) {
printf("Write(%" PRIu64 ", %" PRIu64 ")\n", lba_start, lba_count);
@@ -153,7 +151,7 @@
/* Initialize the GBB */
lkp.gbb_size = sizeof(GoogleBinaryBlockHeader) + key_size;
- lkp.gbb_data = (void*)Malloc(lkp.gbb_size);
+ lkp.gbb_data = (void*)malloc(lkp.gbb_size);
gbb = (GoogleBinaryBlockHeader*)lkp.gbb_data;
Memset(gbb, 0, lkp.gbb_size);
Memcpy(gbb->signature, GBB_SIGNATURE, GBB_SIGNATURE_SIZE);
@@ -171,7 +169,7 @@
}
/* Initialize the shared data area */
- lkp.shared_data_blob = Malloc(VB_SHARED_DATA_REC_SIZE);
+ lkp.shared_data_blob = malloc(VB_SHARED_DATA_REC_SIZE);
lkp.shared_data_size = VB_SHARED_DATA_REC_SIZE;
shared = (VbSharedDataHeader*)lkp.shared_data_blob;
if (0 != VbSharedDataInit(shared, lkp.shared_data_size)) {
@@ -187,7 +185,7 @@
}
/* Free the key blob, now that we're done with it */
- Free(key_blob);
+ free(key_blob);
/* Needs to skip the address check, since we're putting it somewhere on the
* heap instead of its actual target address in the firmware. */
@@ -217,7 +215,7 @@
printf("Ending LBA: %" PRIu64 "\n", lkp.ending_lba);
/* Allocate a buffer for the kernel */
- lkp.kernel_buffer = Malloc(KERNEL_BUFFER_SIZE);
+ lkp.kernel_buffer = malloc(KERNEL_BUFFER_SIZE);
if(!lkp.kernel_buffer) {
fprintf(stderr, "Unable to allocate kernel buffer.\n");
return 1;
@@ -254,6 +252,6 @@
}
fclose(image_file);
- Free(lkp.kernel_buffer);
+ free(lkp.kernel_buffer);
return rv != LOAD_KERNEL_SUCCESS;
}
diff --git a/utility/pad_digest_utility.c b/utility/pad_digest_utility.c
index 50f8146..cee8964 100644
--- a/utility/pad_digest_utility.c
+++ b/utility/pad_digest_utility.c
@@ -11,9 +11,10 @@
#include <stdlib.h>
#include "file_keys.h"
+#include "host_common.h"
#include "padding.h"
#include "signature_digest.h"
-#include "utility.h"
+
int main(int argc, char* argv[]) {
int algorithm = -1;
@@ -48,7 +49,7 @@
if(padded_digest &&
1 != fwrite(padded_digest, padded_digest_len, 1, stdout))
error_code = -1;
- Free(padded_digest);
- Free(digest);
+ free(padded_digest);
+ free(digest);
return error_code;
}
diff --git a/utility/signature_digest_utility.c b/utility/signature_digest_utility.c
index bf23ebd..85ba0c9 100644
--- a/utility/signature_digest_utility.c
+++ b/utility/signature_digest_utility.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -12,9 +12,10 @@
#include <stdlib.h>
#include "file_keys.h"
+#include "host_common.h"
#include "padding.h"
#include "signature_digest.h"
-#include "utility.h"
+
int main(int argc, char* argv[]) {
int algorithm = -1;
@@ -48,7 +49,7 @@
if(signature_digest &&
1 != fwrite(signature_digest, signature_digest_len, 1, stdout))
error_code = -1;
- Free(signature_digest);
- Free(buf);
+ free(signature_digest);
+ free(buf);
return error_code;
}
diff --git a/utility/vbutil_firmware.c b/utility/vbutil_firmware.c
index 9cff272..fb8e102 100644
--- a/utility/vbutil_firmware.c
+++ b/utility/vbutil_firmware.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -85,34 +85,34 @@
uint64_t i;
if (!outfile) {
- error("Must specify output filename\n");
+ VbExError("Must specify output filename\n");
return 1;
}
if (!keyblock_file || !signprivate || !kernelkey_file) {
- error("Must specify all keys\n");
+ VbExError("Must specify all keys\n");
return 1;
}
if (!fv_file) {
- error("Must specify firmware volume\n");
+ VbExError("Must specify firmware volume\n");
return 1;
}
/* Read the key block and keys */
key_block = (VbKeyBlockHeader*)ReadFile(keyblock_file, &key_block_size);
if (!key_block) {
- error("Error reading key block.\n");
+ VbExError("Error reading key block.\n");
return 1;
}
signing_key = PrivateKeyRead(signprivate);
if (!signing_key) {
- error("Error reading signing key.\n");
+ VbExError("Error reading signing key.\n");
return 1;
}
kernel_subkey = PublicKeyRead(kernelkey_file);
if (!kernel_subkey) {
- error("Error reading kernel subkey.\n");
+ VbExError("Error reading kernel subkey.\n");
return 1;
}
@@ -121,15 +121,15 @@
if (!fv_data)
return 1;
if (!fv_size) {
- error("Empty firmware volume file\n");
+ VbExError("Empty firmware volume file\n");
return 1;
}
body_sig = CalculateSignature(fv_data, fv_size, signing_key);
if (!body_sig) {
- error("Error calculating body signature\n");
+ VbExError("Error calculating body signature\n");
return 1;
}
- Free(fv_data);
+ free(fv_data);
/* Create preamble */
preamble = CreateFirmwarePreamble(version,
@@ -137,21 +137,21 @@
body_sig,
signing_key);
if (!preamble) {
- error("Error creating preamble.\n");
+ VbExError("Error creating preamble.\n");
return 1;
}
/* Write the output file */
f = fopen(outfile, "wb");
if (!f) {
- error("Can't open output file %s\n", outfile);
+ VbExError("Can't open output file %s\n", outfile);
return 1;
}
i = ((1 != fwrite(key_block, key_block_size, 1, f)) ||
(1 != fwrite(preamble, preamble->preamble_size, 1, f)));
fclose(f);
if (i) {
- error("Can't write output file %s\n", outfile);
+ VbExError("Can't write output file %s\n", outfile);
unlink(outfile);
return 1;
}
@@ -176,38 +176,38 @@
uint64_t now = 0;
if (!infile || !signpubkey || !fv_file) {
- error("Must specify filename, signpubkey, and fv\n");
+ VbExError("Must specify filename, signpubkey, and fv\n");
return 1;
}
/* Read public signing key */
sign_key = PublicKeyRead(signpubkey);
if (!sign_key) {
- error("Error reading signpubkey.\n");
+ VbExError("Error reading signpubkey.\n");
return 1;
}
/* Read blob */
blob = ReadFile(infile, &blob_size);
if (!blob) {
- error("Error reading input file\n");
+ VbExError("Error reading input file\n");
return 1;
}
/* Read firmware volume */
fv_data = ReadFile(fv_file, &fv_size);
if (!fv_data) {
- error("Error reading firmware volume\n");
+ VbExError("Error reading firmware volume\n");
return 1;
}
/* Verify key block */
key_block = (VbKeyBlockHeader*)blob;
if (0 != KeyBlockVerify(key_block, blob_size, sign_key, 0)) {
- error("Error verifying key block.\n");
+ VbExError("Error verifying key block.\n");
return 1;
}
- Free(sign_key);
+ free(sign_key);
now += key_block->key_block_size;
printf("Key block:\n");
@@ -225,14 +225,14 @@
rsa = PublicKeyToRSA(&key_block->data_key);
if (!rsa) {
- error("Error parsing data key.\n");
+ VbExError("Error parsing data key.\n");
return 1;
}
/* Verify preamble */
preamble = (VbFirmwarePreambleHeader*)(blob + now);
if (0 != VerifyFirmwarePreamble(preamble, blob_size - now, rsa)) {
- error("Error verifying preamble.\n");
+ VbExError("Error verifying preamble.\n");
return 1;
}
now += preamble->preamble_size;
@@ -259,7 +259,7 @@
/* Verify body */
if (0 != VerifyData(fv_data, fv_size, &preamble->body_signature, rsa)) {
- error("Error verifying firmware body.\n");
+ VbExError("Error verifying firmware body.\n");
return 1;
}
printf("Body verification succeeded.\n");
diff --git a/utility/vbutil_kernel.c b/utility/vbutil_kernel.c
index c2b4a0f..821f751 100644
--- a/utility/vbutil_kernel.c
+++ b/utility/vbutil_kernel.c
@@ -148,6 +148,7 @@
va_end(ap);
}
+
/* Return an explanation when fread() fails. */
static const char *error_fread(FILE *fp) {
const char *retval = "beats me why";
@@ -218,10 +219,10 @@
static void FreeBlob(blob_t *bp) {
if (bp) {
if (bp->blob)
- Free(bp->blob);
+ free(bp->blob);
if (bp->buf)
- Free(bp->buf);
- Free(bp);
+ free(bp->buf);
+ free(bp);
}
}
@@ -240,8 +241,8 @@
config_buf = ReadFile(config_file, config_size);
Debug(" config file size=0x%" PRIx64 "\n", *config_size);
if (CROS_CONFIG_SIZE <= *config_size) { /* need room for trailing '\0' */
- error("Config file %s is too large (>= %d bytes)\n",
- config_file, CROS_CONFIG_SIZE);
+ VbExError("Config file %s is too large (>= %d bytes)\n",
+ config_file, CROS_CONFIG_SIZE);
return NULL;
}
@@ -277,13 +278,13 @@
uint64_t now = 0;
if (!vmlinuz || !bootloader_file || !config_file) {
- error("Must specify all input files\n");
+ VbExError("Must specify all input files\n");
return 0;
}
- bp = (blob_t *)Malloc(sizeof(blob_t));
+ bp = (blob_t *)malloc(sizeof(blob_t));
if (!bp) {
- error("Couldn't allocate bytes for blob_t.\n");
+ VbExError("Couldn't allocate bytes for blob_t.\n");
return 0;
}
@@ -310,7 +311,7 @@
return 0;
Debug(" kernel file size=0x%" PRIx64 "\n", kernel_size);
if (!kernel_size) {
- error("Empty kernel file\n");
+ VbExError("Empty kernel file\n");
return 0;
}
@@ -320,7 +321,7 @@
lh = (struct linux_kernel_header *)kernel_buf;
kernel32_start = (lh->setup_sects + 1) << 9;
if (kernel32_start >= kernel_size) {
- error("Malformed kernel\n");
+ VbExError("Malformed kernel\n");
return 0;
}
} else
@@ -334,10 +335,10 @@
CROS_CONFIG_SIZE +
CROS_PARAMS_SIZE +
roundup(bootloader_size, CROS_ALIGN);
- blob = (uint8_t *)Malloc(bp->blob_size);
+ blob = (uint8_t *)malloc(bp->blob_size);
Debug("blob_size=0x%" PRIx64 "\n", bp->blob_size);
if (!blob) {
- error("Couldn't allocate %ld bytes.\n", bp->blob_size);
+ VbExError("Couldn't allocate %ld bytes.\n", bp->blob_size);
return 0;
}
Memset(blob, 0, bp->blob_size);
@@ -398,9 +399,9 @@
Debug("end of blob is 0x%" PRIx64 "\n", now);
/* Free input buffers */
- Free(kernel_buf);
- Free(config_buf);
- Free(bootloader_buf);
+ free(kernel_buf);
+ free(config_buf);
+ free(bootloader_buf);
/* Success */
return bp;
@@ -419,36 +420,36 @@
int ret_error = 1;
if (!filename) {
- error("Must specify prepacked blob to read\n");
+ VbExError("Must specify prepacked blob to read\n");
return 0;
}
if (0 != stat(filename, &statbuf)) {
- error("Unable to stat %s: %s\n", filename, strerror(errno));
+ VbExError("Unable to stat %s: %s\n", filename, strerror(errno));
return 0;
}
Debug("%s size is 0x%" PRIx64 "\n", filename, statbuf.st_size);
if (statbuf.st_size < pad) {
- error("%s is too small to be a valid kernel blob\n");
+ VbExError("%s is too small to be a valid kernel blob\n");
return 0;
}
Debug("Reading %s\n", filename);
fp = fopen(filename, "rb");
if (!fp) {
- error("Unable to open file %s: %s\n", filename, strerror(errno));
+ VbExError("Unable to open file %s: %s\n", filename, strerror(errno));
return 0;
}
- buf = Malloc(pad);
+ buf = malloc(pad);
if (!buf) {
- error("Unable to allocate padding\n");
+ VbExError("Unable to allocate padding\n");
goto unwind_oldblob;
}
if (1 != fread(buf, pad, 1, fp)) {
- error("Unable to read header from %s: %s\n", filename, error_fread(fp));
+ VbExError("Unable to read header from %s: %s\n", filename, error_fread(fp));
goto unwind_oldblob;
}
@@ -457,11 +458,11 @@
Debug("Keyblock is 0x%" PRIx64 " bytes\n", key_block->key_block_size);
now += key_block->key_block_size;
if (now > statbuf.st_size) {
- error("key_block_size advances past the end of the blob\n");
+ VbExError("key_block_size advances past the end of the blob\n");
goto unwind_oldblob;
}
if (now > pad) {
- error("key_block_size advances past %" PRIu64 " byte padding\n", pad);
+ VbExError("key_block_size advances past %" PRIu64 " byte padding\n", pad);
goto unwind_oldblob;
}
@@ -470,26 +471,26 @@
Debug("Preamble is 0x%" PRIx64 " bytes\n", preamble->preamble_size);
now += preamble->preamble_size;
if (now > statbuf.st_size) {
- error("preamble_size advances past the end of the blob\n");
+ VbExError("preamble_size advances past the end of the blob\n");
goto unwind_oldblob;
}
if (now > pad) {
- error("preamble_size advances past %" PRIu64 " byte padding\n", pad);
+ VbExError("preamble_size advances past %" PRIu64 " byte padding\n", pad);
goto unwind_oldblob;
}
/* Go find the kernel blob */
Debug("kernel blob is at offset 0x%" PRIx64 "\n", now);
if (0 != fseek(fp, now, SEEK_SET)) {
- error("Unable to seek to 0x%" PRIx64 " in %s: %s\n", now, filename,
+ VbExError("Unable to seek to 0x%" PRIx64 " in %s: %s\n", now, filename,
strerror(errno));
goto unwind_oldblob;
}
/* Remember what we've got */
- bp = (blob_t *)Malloc(sizeof(blob_t));
+ bp = (blob_t *)malloc(sizeof(blob_t));
if (!bp) {
- error("Couldn't allocate bytes for blob_t.\n");
+ VbExError("Couldn't allocate bytes for blob_t.\n");
goto unwind_oldblob;
}
@@ -508,19 +509,21 @@
Debug(" blob_size = 0x%" PRIx64 "\n", bp->blob_size);
if (!bp->blob_size) {
- error("No kernel blob found\n");
+ VbExError("No kernel blob found\n");
goto unwind_oldblob;
}
- bp->blob = (uint8_t *)Malloc(bp->blob_size);
+ bp->blob = (uint8_t *)malloc(bp->blob_size);
if (!bp->blob) {
- error("Couldn't allocate 0x%" PRIx64 " bytes for blob_t.\n", bp->blob_size);
+ VbExError("Couldn't allocate 0x%" PRIx64 " bytes for blob_t.\n",
+ bp->blob_size);
goto unwind_oldblob;
}
/* read it in */
if (1 != fread(bp->blob, bp->blob_size, 1, fp)) {
- error("Unable to read kernel blob from %s: %s\n", filename, error_fread(fp));
+ VbExError("Unable to read kernel blob from %s: %s\n", filename,
+ error_fread(fp));
goto unwind_oldblob;
}
@@ -534,7 +537,7 @@
FreeBlob(bp);
bp = NULL;
} else if (buf) {
- Free(buf);
+ free(buf);
}
}
return bp;
@@ -555,15 +558,15 @@
uint64_t i;
if (!outfile) {
- error("Must specify output filename\n");
+ VbExError("Must specify output filename\n");
return 1;
}
if ((!keyblock_file && !bp->key_block) || !signprivate) {
- error("Must specify all keys\n");
+ VbExError("Must specify all keys\n");
return 1;
}
if (!bp) {
- error("Refusing to pack invalid kernel blob\n");
+ VbExError("Refusing to pack invalid kernel blob\n");
return 1;
}
@@ -571,7 +574,7 @@
if (keyblock_file) {
key_block = (VbKeyBlockHeader*)ReadFile(keyblock_file, &key_block_size);
if (!key_block) {
- error("Error reading key block.\n");
+ VbExError("Error reading key block.\n");
return 1;
}
} else {
@@ -580,20 +583,20 @@
}
if (pad < key_block->key_block_size) {
- error("Pad too small\n");
+ VbExError("Pad too small\n");
return 1;
}
signing_key = PrivateKeyRead(signprivate);
if (!signing_key) {
- error("Error reading signing key.\n");
+ VbExError("Error reading signing key.\n");
return 1;
}
/* Sign the kernel data */
body_sig = CalculateSignature(bp->blob, bp->blob_size, signing_key);
if (!body_sig) {
- error("Error calculating body signature\n");
+ VbExError("Error calculating body signature\n");
return 1;
}
@@ -606,7 +609,7 @@
pad - key_block_size,
signing_key);
if (!preamble) {
- error("Error creating preamble.\n");
+ VbExError("Error creating preamble.\n");
return 1;
}
@@ -614,7 +617,7 @@
Debug("writing %s...\n", outfile);
f = fopen(outfile, "wb");
if (!f) {
- error("Can't open output file %s\n", outfile);
+ VbExError("Can't open output file %s\n", outfile);
return 1;
}
Debug("0x%" PRIx64 " bytes of key_block\n", key_block_size);
@@ -622,7 +625,7 @@
i = ((1 != fwrite(key_block, key_block_size, 1, f)) ||
(1 != fwrite(preamble, preamble->preamble_size, 1, f)));
if (i) {
- error("Can't write output file %s\n", outfile);
+ VbExError("Can't write output file %s\n", outfile);
fclose(f);
unlink(outfile);
return 1;
@@ -632,7 +635,7 @@
Debug("0x%" PRIx64 " bytes of blob\n", bp->blob_size);
i = (1 != fwrite(bp->blob, bp->blob_size, 1, f));
if (i) {
- error("Can't write output file %s\n", outfile);
+ VbExError("Can't write output file %s\n", outfile);
fclose(f);
unlink(outfile);
return 1;
@@ -667,7 +670,7 @@
Memset(BpCmdLineLocation(bp, kernel_body_load_address), 0, CROS_CONFIG_SIZE);
Memcpy(BpCmdLineLocation(bp, kernel_body_load_address),
new_conf, config_size);
- Free(new_conf);
+ free(new_conf);
return 0;
}
@@ -686,7 +689,7 @@
int rv = 1;
if (!infile) {
- error("Must specify filename\n");
+ VbExError("Must specify filename\n");
return 1;
}
@@ -694,7 +697,7 @@
if (signpubkey) {
sign_key = PublicKeyRead(signpubkey);
if (!sign_key) {
- error("Error reading signpubkey.\n");
+ VbExError("Error reading signpubkey.\n");
return 1;
}
}
@@ -702,7 +705,7 @@
/* Read blob */
bp = OldBlob(infile, pad);
if (!bp) {
- error("Error reading input file\n");
+ VbExError("Error reading input file\n");
return 1;
}
@@ -710,7 +713,7 @@
key_block = bp->key_block;
if (0 != KeyBlockVerify(key_block, bp->blob_size, sign_key,
(sign_key ? 0 : 1))) {
- error("Error verifying key block.\n");
+ VbExError("Error verifying key block.\n");
goto verify_exit;
}
now = key_block->key_block_size;
@@ -719,11 +722,11 @@
FILE* f = NULL;
f = fopen(key_block_file, "wb");
if (!f) {
- error("Can't open key block file %s\n", key_block_file);
+ VbExError("Can't open key block file %s\n", key_block_file);
return 1;
}
if (1 != fwrite(key_block, key_block->key_block_size, 1, f)) {
- error("Can't write key block file %s\n", key_block_file);
+ VbExError("Can't write key block file %s\n", key_block_file);
return 1;
}
fclose(f);
@@ -753,14 +756,15 @@
printf("\n");
if (data_key->key_version < (min_version >> 16)) {
- error("Data key version %" PRIu64 " is lower than minimum %" PRIu64".\n",
- data_key->key_version, (min_version >> 16));
+ VbExError("Data key version %" PRIu64
+ " is lower than minimum %" PRIu64".\n",
+ data_key->key_version, (min_version >> 16));
goto verify_exit;
}
rsa = PublicKeyToRSA(&key_block->data_key);
if (!rsa) {
- error("Error parsing data key.\n");
+ VbExError("Error parsing data key.\n");
goto verify_exit;
}
@@ -768,7 +772,7 @@
preamble = bp->preamble;
if (0 != VerifyKernelPreamble(
preamble, bp->blob_size - key_block->key_block_size, rsa)) {
- error("Error verifying preamble.\n");
+ VbExError("Error verifying preamble.\n");
goto verify_exit;
}
now += preamble->preamble_size;
@@ -786,15 +790,15 @@
printf(" Bootloader size: 0x%" PRIx64 "\n", preamble->bootloader_size);
if (preamble->kernel_version < (min_version & 0xFFFF)) {
- error("Kernel version %" PRIu64 " is lower than minimum %" PRIu64 ".\n",
- preamble->kernel_version, (min_version & 0xFFFF));
+ VbExError("Kernel version %" PRIu64 " is lower than minimum %" PRIu64 ".\n",
+ preamble->kernel_version, (min_version & 0xFFFF));
goto verify_exit;
}
/* Verify body */
if (0 != VerifyData(bp->blob, bp->blob_size, &preamble->body_signature,
rsa)) {
- error("Error verifying kernel body.\n");
+ VbExError("Error verifying kernel body.\n");
goto verify_exit;
}
printf("Body verification succeeded.\n");
diff --git a/utility/vbutil_key.c b/utility/vbutil_key.c
index 38d9000..18e37a2 100644
--- a/utility/vbutil_key.c
+++ b/utility/vbutil_key.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -90,7 +90,7 @@
fprintf(stderr, "vbutil_key: Error writing key.\n");
return 1;
}
- Free(pubkey);
+ free(pubkey);
return 0;
}
@@ -99,11 +99,11 @@
fprintf(stderr, "vbutil_key: Error writing key.\n");
return 1;
}
- Free(privkey);
+ free(privkey);
return 0;
}
- error("Unable to parse either .keyb or .pem from %s\n", infile);
+ VbExError("Unable to parse either .keyb or .pem from %s\n", infile);
return 1;
}
@@ -130,11 +130,11 @@
if (outfile) {
if (0 != PublicKeyWrite(outfile, pubkey)) {
fprintf(stderr, "vbutil_key: Error writing key copy.\n");
- Free(pubkey);
+ free(pubkey);
return 1;
}
}
- Free(pubkey);
+ free(pubkey);
return 0;
}
@@ -146,15 +146,15 @@
if (outfile) {
if (0 != PrivateKeyWrite(outfile, privkey)) {
fprintf(stderr, "vbutil_key: Error writing key copy.\n");
- Free(privkey);
+ free(privkey);
return 1;
}
}
- Free(privkey);
+ free(privkey);
return 0;
}
- error("Unable to parse either .vbpubk or vbprivk from %s\n", infile);
+ VbExError("Unable to parse either .vbpubk or vbprivk from %s\n", infile);
return 1;
}
@@ -180,7 +180,7 @@
switch (i) {
case '?':
/* Unhandled option */
- error("Unknown option\n");
+ VbExError("Unknown option\n");
parse_error = 1;
break;
@@ -191,7 +191,7 @@
case OPT_KEY_VERSION:
version = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- error("Invalid --version\n");
+ VbExError("Invalid --version\n");
parse_error = 1;
}
break;
@@ -199,7 +199,7 @@
case OPT_ALGORITHM:
algorithm = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- error("Invalid --algorithm\n");
+ VbExError("Invalid --algorithm\n");
parse_error = 1;
}
break;
diff --git a/utility/vbutil_keyblock.c b/utility/vbutil_keyblock.c
index c919221..9643608 100644
--- a/utility/vbutil_keyblock.c
+++ b/utility/vbutil_keyblock.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -133,15 +133,15 @@
block = KeyBlockCreate(data_key, signing_key, flags);
}
- Free(data_key);
+ free(data_key);
if (signing_key)
- Free(signing_key);
+ free(signing_key);
if (0 != KeyBlockWrite(outfile, block)) {
fprintf(stderr, "vbutil_keyblock: Error writing key block.\n");
return 1;
}
- Free(block);
+ free(block);
return 0;
}
@@ -174,7 +174,7 @@
fprintf(stderr, "vbutil_keyblock: Error verifying key block.\n");
return 1;
}
- Free(sign_key);
+ free(sign_key);
}
printf("Key block file: %s\n", infile);
@@ -207,7 +207,7 @@
}
}
- Free(block);
+ free(block);
return 0;
}