diff options
author | Randall Spangler <rspangler@chromium.org> | 2011-06-27 10:49:11 -0700 |
---|---|---|
committer | Randall Spangler <rspangler@chromium.org> | 2011-06-27 13:30:41 -0700 |
commit | 32a6526d25d4bf9a1c137fc3d275d1c68935d184 (patch) | |
tree | 8659c56a4129ff40f631670b7fd3b94bda73fe20 | |
parent | 7adcc60e6f5f6db081b9ad6e02288335502a0d77 (diff) | |
download | vboot-32a6526d25d4bf9a1c137fc3d275d1c68935d184.tar.gz |
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>
35 files changed, 479 insertions, 313 deletions
diff --git a/firmware/Makefile b/firmware/Makefile index d9a305b4..bdc4ca02 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -82,7 +82,9 @@ STUB_SRCS = \ ./stub/boot_device_stub.c \ ./stub/load_firmware_stub.c \ ./stub/tpm_lite_stub.c \ - ./stub/utility_stub.c + ./stub/utility_stub.c \ + ./stub/vboot_api_stub.c \ + ./stub/vboot_api_stub_disk.c STUB_OBJS = $(STUB_SRCS:%.c=${BUILD_ROOT}/%.o) diff --git a/firmware/include/utility.h b/firmware/include/utility.h index 4f88ab9c..3de8bb8a 100644 --- a/firmware/include/utility.h +++ b/firmware/include/utility.h @@ -42,11 +42,11 @@ void error(const char* format, ...); void debug(const char* format, ...); #ifdef VBOOT_DEBUG -#define assert(expr) do { if (!(expr)) { \ +#define VbAssert(expr) do { if (!(expr)) { \ error("assert fail: %s at %s:%d\n", \ #expr, __FILE__, __LINE__); }} while(0) #else -#define assert(expr) +#define VbAssert(expr) #endif /* Combine [msw] and [lsw] uint16s to a uint32_t with its [msw] and diff --git a/firmware/lib/tpm_lite/tlcl.c b/firmware/lib/tpm_lite/tlcl.c index f36f4633..3fbcd1e7 100644 --- a/firmware/lib/tpm_lite/tlcl.c +++ b/firmware/lib/tpm_lite/tlcl.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2011 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. */ @@ -175,7 +175,7 @@ uint32_t TlclWrite(uint32_t index, const void* data, uint32_t length) { VBDEBUG(("TPM: TlclWrite(0x%x, %d)\n", index, length)); Memcpy(&cmd, &tpm_nv_write_cmd, sizeof(cmd)); - assert(total_length <= TPM_LARGE_ENOUGH_COMMAND_SIZE); + VbAssert(total_length <= TPM_LARGE_ENOUGH_COMMAND_SIZE); SetTpmCommandSize(cmd.buffer, total_length); ToTpmUint32(cmd.buffer + tpm_nv_write_cmd.index, index); @@ -286,7 +286,7 @@ uint32_t TlclGetPermanentFlags(TPM_PERMANENT_FLAGS* pflags) { if (result != TPM_SUCCESS) return result; FromTpmUint32(response + kTpmResponseHeaderLength, &size); - assert(size == sizeof(TPM_PERMANENT_FLAGS)); + VbAssert(size == sizeof(TPM_PERMANENT_FLAGS)); Memcpy(pflags, response + kTpmResponseHeaderLength + sizeof(size), sizeof(TPM_PERMANENT_FLAGS)); @@ -302,7 +302,7 @@ uint32_t TlclGetSTClearFlags(TPM_STCLEAR_FLAGS* vflags) { return result; FromTpmUint32(response + kTpmResponseHeaderLength, &size); /* Ugly assertion, but the struct is padded up by one byte. */ - assert(size == 7 && sizeof(TPM_STCLEAR_FLAGS) - 1 == 7); + VbAssert(size == 7 && sizeof(TPM_STCLEAR_FLAGS) - 1 == 7); Memcpy(vflags, response + kTpmResponseHeaderLength + sizeof(size), sizeof(TPM_STCLEAR_FLAGS)); diff --git a/firmware/stub/vboot_api_stub.c b/firmware/stub/vboot_api_stub.c new file mode 100644 index 00000000..5cd0ad3c --- /dev/null +++ b/firmware/stub/vboot_api_stub.c @@ -0,0 +1,120 @@ +/* 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. + * + * Stub implementations of firmware-provided API functions. + */ + +#define _STUB_IMPLEMENTATION_ + +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/time.h> + +#include "vboot_api.h" + +/* disable MSVC warnings on unused arguments */ +__pragma(warning (disable: 4100)) + + +void VbExError(const char* format, ...) { + va_list ap; + va_start(ap, format); + fprintf(stderr, "ERROR: "); + vfprintf(stderr, format, ap); + va_end(ap); + exit(1); +} + + +void VbExDebug(const char* format, ...) { + va_list ap; + va_start(ap, format); + fprintf(stderr, "DEBUG: "); + vfprintf(stderr, format, ap); + va_end(ap); +} + + +void* VbExMalloc(size_t size) { + void* p = malloc(size); + if (!p) { + /* Fatal Error. We must abort. */ + abort(); + } + return p; +} + + +void VbExFree(void* ptr) { + free(ptr); +} + + +uint64_t VbExGetTimer(void) { + struct timeval tv; + gettimeofday(&tv, NULL); + return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec; +} + + +void VbExSleepMs(uint32_t msec) { +} + + +void VbExBeep(uint32_t msec, uint32_t frequency) { +} + + +VbError_t VbExNvStorageRead(uint8_t* buf) { + return VBERROR_SUCCESS; +} + + +VbError_t VbExNvStorageWrite(const uint8_t* buf) { + return VBERROR_SUCCESS; +} + + +VbError_t VbExHashFirmwareBody(VbCommonParams* cparams, + uint32_t firmware_index) { + return VBERROR_SUCCESS; +} + + +VbError_t VbExDisplayInit(uint32_t* width, uint32_t* height) { + return VBERROR_SUCCESS; +} + + +VbError_t VbExDisplayBacklight(uint8_t enable) { + return VBERROR_SUCCESS; +} + + +VbError_t VbExDisplayScreen(uint32_t screen_type) { + return VBERROR_SUCCESS; +} + + +VbError_t VbExDisplayImage(uint32_t x, uint32_t y, const ImageInfo* info, + const void* buffer) { + return VBERROR_SUCCESS; +} + + +VbError_t VbExDisplayDebugInfo(const char* info_str) { + return VBERROR_SUCCESS; +} + + +uint32_t VbExKeyboardRead(void) { + return 0; +} + + +uint32_t VbExIsShutdownRequested(void) { + return 0; +} diff --git a/firmware/stub/vboot_api_stub_disk.c b/firmware/stub/vboot_api_stub_disk.c new file mode 100644 index 00000000..463b2f98 --- /dev/null +++ b/firmware/stub/vboot_api_stub_disk.c @@ -0,0 +1,45 @@ +/* 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. + * + * Stub implementations of disk APIs. + */ + +#define _STUB_IMPLEMENTATION_ + +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/time.h> + +#include "vboot_api.h" + +/* disable MSVC warnings on unused arguments */ +__pragma(warning (disable: 4100)) + + +VbError_t VbExDiskGetInfo(VbDiskInfo** infos_ptr, uint32_t* count, + uint32_t disk_flags) { + *infos_ptr = NULL; + *count = 0; + return VBERROR_SUCCESS; +} + + +VbError_t VbExDiskFreeInfo(VbDiskInfo* infos_ptr, + VbExDiskHandle_t preserve_handle) { + return VBERROR_SUCCESS; +} + + +VbError_t VbExDiskRead(VbExDiskHandle_t handle, uint64_t lba_start, + uint64_t lba_count, void* buffer) { + return VBERROR_SUCCESS; +} + + +VbError_t VbExDiskWrite(VbExDiskHandle_t handle, uint64_t lba_start, + uint64_t lba_count, const void* buffer) { + return VBERROR_SUCCESS; +} diff --git a/host/Makefile b/host/Makefile index 7c2866b3..c32076a1 100644 --- a/host/Makefile +++ b/host/Makefile @@ -30,7 +30,8 @@ STUB_SRCS = \ ../firmware/stub/boot_device_stub.c \ ../firmware/stub/load_firmware_stub.c \ ../firmware/stub/tpm_lite_stub.c \ - ../firmware/stub/utility_stub.c + ../firmware/stub/utility_stub.c \ + ../firmware/stub/vboot_api_stub.c ALL_SRCS = ${LIB_SRCS} ${STUB_SRCS} diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c index 25867e12..670ce364 100644 --- a/host/arch/x86/lib/crossystem_arch.c +++ b/host/arch/x86/lib/crossystem_arch.c @@ -180,7 +180,7 @@ static uint8_t* VbGetBuffer(const char* filename, int* buffer_size) { if (!f) break; - file_buffer = Malloc(fs.st_size + 1); + file_buffer = malloc(fs.st_size + 1); if (!file_buffer) break; @@ -192,7 +192,7 @@ static uint8_t* VbGetBuffer(const char* filename, int* buffer_size) { /* Each byte in the output will replace two characters and a space * in the input, so the output size does not exceed input side/3 * (a little less if account for newline characters). */ - output_buffer = Malloc(real_size/3); + output_buffer = malloc(real_size/3); if (!output_buffer) break; output_ptr = output_buffer; @@ -229,10 +229,10 @@ static uint8_t* VbGetBuffer(const char* filename, int* buffer_size) { fclose(f); if (file_buffer) - Free(file_buffer); + free(file_buffer); if (output_buffer) - Free(output_buffer); + free(output_buffer); return return_value; } @@ -257,7 +257,7 @@ VbSharedDataHeader* VbSharedDataRead(void) { } if (got_size < expect_size) { - Free(sh); + free(sh); return NULL; } if (sh->data_size > got_size) @@ -388,7 +388,7 @@ static int VbGetRecoveryReason(void) { if (sh) { if (sh->struct_version >= 2) value = sh->recovery_reason; - Free(sh); + free(sh); if (-1 != value) return value; } diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c index 54d08561..72f2c666 100644 --- a/host/lib/crossystem.c +++ b/host/lib/crossystem.c @@ -298,7 +298,7 @@ char* GetVdatString(char* dest, int size, VdatStringField field) break; } - Free(sh); + free(sh); return value; } @@ -333,7 +333,7 @@ int GetVdatInt(VdatIntField field) { break; } - Free(sh); + free(sh); return value; } diff --git a/host/lib/file_keys.c b/host/lib/file_keys.c index 0c57dff8..c311e6ac 100644 --- a/host/lib/file_keys.c +++ b/host/lib/file_keys.c @@ -1,12 +1,10 @@ -/* 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. * * Utility functions for file and key handling. */ -#include "file_keys.h" - #include <fcntl.h> #include <stdio.h> #include <stdlib.h> @@ -16,8 +14,9 @@ #include <unistd.h> #include "cryptolib.h" +#include "file_keys.h" +#include "host_common.h" #include "signature_digest.h" -#include "utility.h" uint8_t* BufferFromFile(const char* input_file, uint64_t* len) { int fd; @@ -35,9 +34,9 @@ uint8_t* BufferFromFile(const char* input_file, uint64_t* len) { } *len = stat_fd.st_size; - buf = (uint8_t*) Malloc(*len); + buf = (uint8_t*)malloc(*len); if (!buf) { - error("Couldn't allocate %ld bytes for file %s\n", *len, input_file); + VbExError("Couldn't allocate %ld bytes for file %s\n", *len, input_file); return NULL; } @@ -56,7 +55,7 @@ RSAPublicKey* RSAPublicKeyFromFile(const char* input_file) { uint8_t* buf = BufferFromFile(input_file, &len); if (buf) key = RSAPublicKeyFromBuf(buf, len); - Free(buf); + free(buf); return key; } @@ -98,21 +97,21 @@ uint8_t* SignatureFile(const char* input_file, const char* key_file, strlen(key_file) + 1 + /* +1 for space. */ strlen(input_file) + 1); /* For the trailing '\0'. */ - cmd = (char*) Malloc(cmd_len); + cmd = (char*) malloc(cmd_len); snprintf(cmd, cmd_len, "%s %u %s %s", sign_utility, algorithm, key_file, input_file); cmd_out = popen(cmd, "r"); - Free(cmd); + free(cmd); if (!cmd_out) { VBDEBUG(("Couldn't execute: %s\n", cmd)); return NULL; } - signature = (uint8_t*) Malloc(signature_size); + signature = (uint8_t*) malloc(signature_size); if (fread(signature, signature_size, 1, cmd_out) != 1) { VBDEBUG(("Couldn't read signature.\n")); pclose(cmd_out); - Free(signature); + free(signature); return NULL; } diff --git a/host/lib/host_common.c b/host/lib/host_common.c index 952a6290..9e0a5d9f 100644 --- a/host/lib/host_common.c +++ b/host/lib/host_common.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. * @@ -31,7 +31,7 @@ VbFirmwarePreambleHeader* CreateFirmwarePreamble( VbSignature *sigtmp; /* Allocate key block */ - h = (VbFirmwarePreambleHeader*)Malloc(block_size); + h = (VbFirmwarePreambleHeader*)malloc(block_size); if (!h) return NULL; kernel_subkey_dest = (uint8_t*)(h + 1); @@ -60,7 +60,7 @@ VbFirmwarePreambleHeader* CreateFirmwarePreamble( /* Calculate signature */ sigtmp = CalculateSignature((uint8_t*)h, signed_size, signing_key); SignatureCopy(&h->preamble_signature, sigtmp); - Free(sigtmp); + free(sigtmp); /* Return the header */ return h; @@ -68,7 +68,7 @@ VbFirmwarePreambleHeader* CreateFirmwarePreamble( /* Creates a kernel preamble, signed with [signing_key]. - * Caller owns the returned pointer, and must free it with Free(). + * Caller owns the returned pointer, and must free it with free(). * * Returns NULL if error. */ VbKernelPreambleHeader* CreateKernelPreamble( @@ -93,7 +93,7 @@ VbKernelPreambleHeader* CreateKernelPreamble( block_size = desired_size; /* Allocate key block */ - h = (VbKernelPreambleHeader*)Malloc(block_size); + h = (VbKernelPreambleHeader*)malloc(block_size); Memset(h, 0, block_size); if (!h) @@ -121,7 +121,7 @@ VbKernelPreambleHeader* CreateKernelPreamble( /* Calculate signature */ sigtmp = CalculateSignature((uint8_t*)h, signed_size, signing_key); SignatureCopy(&h->preamble_signature, sigtmp); - Free(sigtmp); + free(sigtmp); /* Return the header */ return h; diff --git a/host/lib/host_key.c b/host/lib/host_key.c index 33d911f2..e2736f95 100644 --- a/host/lib/host_key.c +++ b/host/lib/host_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. * @@ -17,11 +17,10 @@ #include <stdlib.h> #include <unistd.h> -#include "host_key.h" - #include "cryptolib.h" +#include "host_common.h" +#include "host_key.h" #include "host_misc.h" -#include "utility.h" #include "vboot_common.h" @@ -51,7 +50,7 @@ VbPrivateKey* PrivateKeyReadPem(const char* filename, uint64_t algorithm) { } /* Store key and algorithm in our struct */ - key = (VbPrivateKey*)Malloc(sizeof(VbPrivateKey)); + key = (VbPrivateKey*)malloc(sizeof(VbPrivateKey)); if (!key) { RSA_free(rsa_key); return NULL; @@ -69,7 +68,7 @@ void PrivateKeyFree(VbPrivateKey* key) { return; if (key->rsa_private_key) RSA_free(key->rsa_private_key); - Free(key); + free(key); } @@ -81,33 +80,33 @@ int PrivateKeyWrite(const char* filename, const VbPrivateKey* key) { buflen = i2d_RSAPrivateKey(key->rsa_private_key, &outbuf); if (buflen <= 0) { - error("Unable to write private key buffer\n"); + VbExError("Unable to write private key buffer\n"); return 1; } f = fopen(filename, "wb"); if (!f) { - error("Unable to open file %s\n", filename); - Free(outbuf); + VbExError("Unable to open file %s\n", filename); + free(outbuf); return 1; } if (1 != fwrite(&key->algorithm, sizeof(key->algorithm), 1, f)) { - error("Unable to write to file %s\n", filename); + VbExError("Unable to write to file %s\n", filename); fclose(f); - Free(outbuf); + free(outbuf); unlink(filename); /* Delete any partial file */ } if (1 != fwrite(outbuf, buflen, 1, f)) { - error("Unable to write to file %s\n", filename); + VbExError("Unable to write to file %s\n", filename); fclose(f); unlink(filename); /* Delete any partial file */ - Free(outbuf); + free(outbuf); } fclose(f); - Free(outbuf); + free(outbuf); return 0; } @@ -119,14 +118,14 @@ VbPrivateKey* PrivateKeyRead(const char* filename) { buffer = ReadFile(filename, &filelen); if (!buffer) { - error("unable to read from file %s\n", filename); + VbExError("unable to read from file %s\n", filename); return 0; } - key = (VbPrivateKey*)Malloc(sizeof(VbPrivateKey)); + key = (VbPrivateKey*)malloc(sizeof(VbPrivateKey)); if (!key) { - error("Unable to allocate VbPrivateKey\n"); - Free(buffer); + VbExError("Unable to allocate VbPrivateKey\n"); + free(buffer); return 0; } @@ -137,13 +136,13 @@ VbPrivateKey* PrivateKeyRead(const char* filename) { filelen - sizeof(key->algorithm)); if (!key->rsa_private_key) { - error("Unable to parse RSA private key\n"); - Free(buffer); - Free(key); + VbExError("Unable to parse RSA private key\n"); + free(buffer); + free(key); return 0; } - Free(buffer); + free(buffer); return key; } @@ -151,7 +150,7 @@ VbPrivateKey* PrivateKeyRead(const char* filename) { /* Allocate a new public key with space for a [key_size] byte key. */ VbPublicKey* PublicKeyAlloc(uint64_t key_size, uint64_t algorithm, uint64_t version) { - VbPublicKey* key = (VbPublicKey*)Malloc(sizeof(VbPublicKey) + key_size); + VbPublicKey* key = (VbPublicKey*)malloc(sizeof(VbPublicKey) + key_size); if (!key) return NULL; @@ -186,18 +185,18 @@ VbPublicKey* PublicKeyReadKeyb(const char* filename, uint64_t algorithm, if (!RSAProcessedKeySize(algorithm, &expected_key_size) || expected_key_size != key_size) { VBDEBUG(("PublicKeyReadKeyb() wrong key size for algorithm\n")); - Free(key_data); + free(key_data); return NULL; } key = PublicKeyAlloc(key_size, algorithm, version); if (!key) { - Free(key_data); + free(key_data); return NULL; } Memcpy(GetPublicKeyData(key), key_data, key_size); - Free(key_data); + free(key_data); return key; } @@ -237,7 +236,7 @@ VbPublicKey* PublicKeyRead(const char* filename) { } while(0); /* Error */ - Free(key); + free(key); return NULL; } @@ -250,12 +249,12 @@ int PublicKeyWrite(const char* filename, const VbPublicKey* key) { if (!kcopy) return 1; if (0 != PublicKeyCopy(kcopy, key)) { - Free(kcopy); + free(kcopy); return 1; } /* Write the copy, then free it */ rv = WriteFile(filename, kcopy, kcopy->key_offset + kcopy->key_size); - Free(kcopy); + free(kcopy); return rv; } diff --git a/host/lib/host_keyblock.c b/host/lib/host_keyblock.c index 97a5d121..b12f024f 100644 --- a/host/lib/host_keyblock.c +++ b/host/lib/host_keyblock.c @@ -1,15 +1,14 @@ -/* 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. * * Host functions for verified boot. */ -#include "host_keyblock.h" #include "cryptolib.h" #include "host_common.h" -#include "utility.h" +#include "host_keyblock.h" #include "vboot_common.h" @@ -28,7 +27,7 @@ VbKeyBlockHeader* KeyBlockCreate(const VbPublicKey* data_key, VbSignature *sigtmp; /* Allocate key block */ - h = (VbKeyBlockHeader*)Malloc(block_size); + h = (VbKeyBlockHeader*)malloc(block_size); if (!h) return NULL; data_key_dest = (uint8_t*)(h + 1); @@ -57,13 +56,13 @@ VbKeyBlockHeader* KeyBlockCreate(const VbPublicKey* data_key, /* Calculate checksum */ sigtmp = CalculateChecksum((uint8_t*)h, signed_size); SignatureCopy(&h->key_block_checksum, sigtmp); - Free(sigtmp); + free(sigtmp); /* Calculate signature */ if (signing_key) { sigtmp = CalculateSignature((uint8_t*)h, signed_size, signing_key); SignatureCopy(&h->key_block_signature, sigtmp); - Free(sigtmp); + free(sigtmp); } /* Return the header */ @@ -88,7 +87,7 @@ VbKeyBlockHeader* KeyBlockCreate_external(const VbPublicKey* data_key, VbSignature *sigtmp; /* Allocate key block */ - h = (VbKeyBlockHeader*)Malloc(block_size); + h = (VbKeyBlockHeader*)malloc(block_size); if (!h) return NULL; if (!signing_key_pem_file || !data_key || !external_signer) @@ -117,21 +116,21 @@ VbKeyBlockHeader* KeyBlockCreate_external(const VbPublicKey* data_key, /* Calculate checksum */ sigtmp = CalculateChecksum((uint8_t*)h, signed_size); SignatureCopy(&h->key_block_checksum, sigtmp); - Free(sigtmp); + free(sigtmp); /* Calculate signature */ sigtmp = CalculateSignature_external((uint8_t*)h, signed_size, signing_key_pem_file, algorithm, external_signer); SignatureCopy(&h->key_block_signature, sigtmp); - Free(sigtmp); + free(sigtmp); /* Return the header */ return h; } /* Read a key block from a .keyblock file. Caller owns the returned - * pointer, and must free it with Free(). + * pointer, and must free it with free(). * * Returns NULL if error. */ VbKeyBlockHeader* KeyBlockRead(const char* filename) { @@ -149,7 +148,7 @@ VbKeyBlockHeader* KeyBlockRead(const char* filename) { * the public signing key. */ if (0 != KeyBlockVerify(block, file_size, NULL, 1)) { VBDEBUG(("Invalid key block file: filename\n", filename)); - Free(block); + free(block); return NULL; } diff --git a/host/lib/host_misc.c b/host/lib/host_misc.c index f8dd9b8f..ad3b4ebd 100644 --- a/host/lib/host_misc.c +++ b/host/lib/host_misc.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,8 @@ #include <string.h> #include <unistd.h> -#include "host_common.h" - #include "cryptolib.h" -#include "utility.h" +#include "host_common.h" #include "vboot_common.h" @@ -40,7 +38,7 @@ uint8_t* ReadFile(const char* filename, uint64_t* size) { *size = ftell(f); rewind(f); - buf = Malloc(*size); + buf = malloc(*size); if (!buf) { fclose(f); return NULL; @@ -49,7 +47,7 @@ uint8_t* ReadFile(const char* filename, uint64_t* size) { if(1 != fread(buf, *size, 1, f)) { VBDEBUG(("Unable to read from file %s\n", filename)); fclose(f); - Free(buf); + free(buf); return NULL; } @@ -121,5 +119,5 @@ void PrintPubKeySha1Sum(VbPublicKey* key) { int i; for (i=0; i<SHA1_DIGEST_SIZE; i++) printf("%02x", digest[i]); - Free(digest); + free(digest); } diff --git a/host/lib/host_signature.c b/host/lib/host_signature.c index 6440dd21..4dbac49a 100644 --- a/host/lib/host_signature.c +++ b/host/lib/host_signature.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. * @@ -20,13 +20,12 @@ #include "cryptolib.h" #include "file_keys.h" -#include "utility.h" -#include "vboot_common.h" #include "host_common.h" +#include "vboot_common.h" VbSignature* SignatureAlloc(uint64_t sig_size, uint64_t data_size) { - VbSignature* sig = (VbSignature*)Malloc(sizeof(VbSignature) + sig_size); + VbSignature* sig = (VbSignature*)malloc(sizeof(VbSignature) + sig_size); if (!sig) return NULL; @@ -66,7 +65,7 @@ VbSignature* CalculateChecksum(const uint8_t* data, uint64_t size) { sig = SignatureAlloc(SHA512_DIGEST_SIZE, 0); if (!sig) { - Free(header_checksum); + free(header_checksum); return NULL; } sig->sig_offset = sizeof(VbSignature); @@ -75,7 +74,7 @@ VbSignature* CalculateChecksum(const uint8_t* data, uint64_t size) { /* Signature data immediately follows the header */ Memcpy(GetSignatureData(sig), header_checksum, SHA512_DIGEST_SIZE); - Free(header_checksum); + free(header_checksum); return sig; } @@ -101,19 +100,19 @@ VbSignature* CalculateSignature(const uint8_t* data, uint64_t size, return NULL; /* Prepend the digest info to the digest */ - signature_digest = Malloc(signature_digest_len); + signature_digest = malloc(signature_digest_len); if (!signature_digest) { - Free(digest); + free(digest); return NULL; } Memcpy(signature_digest, digestinfo, digestinfo_size); Memcpy(signature_digest + digestinfo_size, digest, digest_size); - Free(digest); + free(digest); /* Allocate output signature */ sig = SignatureAlloc(siglen_map[key->algorithm], size); if (!sig) { - Free(signature_digest); + free(signature_digest); return NULL; } @@ -123,11 +122,11 @@ VbSignature* CalculateSignature(const uint8_t* data, uint64_t size, GetSignatureData(sig), /* Output sig */ key->rsa_private_key, /* Key to use */ RSA_PKCS1_PADDING); /* Padding to use */ - Free(signature_digest); + free(signature_digest); if (-1 == rv) { VBDEBUG(("SignatureBuf(): RSA_private_encrypt() failed.\n")); - Free(sig); + free(sig); return NULL; } @@ -246,19 +245,19 @@ VbSignature* CalculateSignature_external(const uint8_t* data, uint64_t size, return NULL; /* Prepend the digest info to the digest */ - signature_digest = Malloc(signature_digest_len); + signature_digest = malloc(signature_digest_len); if (!signature_digest) { - Free(digest); + free(digest); return NULL; } Memcpy(signature_digest, digestinfo, digestinfo_size); Memcpy(signature_digest + digestinfo_size, digest, digest_size); - Free(digest); + free(digest); /* Allocate output signature */ sig = SignatureAlloc(siglen_map[key_algorithm], size); if (!sig) { - Free(signature_digest); + free(signature_digest); return NULL; } @@ -269,11 +268,11 @@ VbSignature* CalculateSignature_external(const uint8_t* data, uint64_t size, siglen_map[key_algorithm], /* Max Output sig size */ key_file, /* Key file to use */ external_signer); /* External cmd to invoke */ - Free(signature_digest); + free(signature_digest); if (-1 == rv) { VBDEBUG(("SignatureBuf(): RSA_private_encrypt() failed.\n")); - Free(sig); + free(sig); return NULL; } diff --git a/host/lib/signature_digest.c b/host/lib/signature_digest.c index 6bf5c82e..81c666ea 100644 --- a/host/lib/signature_digest.c +++ b/host/lib/signature_digest.c @@ -14,13 +14,14 @@ #include <unistd.h> #include "cryptolib.h" -#include "utility.h" +#include "host_common.h" + uint8_t* PrependDigestInfo(unsigned int algorithm, uint8_t* digest) { const int digest_size = hash_size_map[algorithm]; const int digestinfo_size = digestinfo_size_map[algorithm]; const uint8_t* digestinfo = hash_digestinfo_map[algorithm]; - uint8_t* p = Malloc(digestinfo_size + digest_size); + uint8_t* p = malloc(digestinfo_size + digest_size); Memcpy(p, digestinfo, digestinfo_size); Memcpy(p + digestinfo_size, digest, digest_size); return p; @@ -36,7 +37,7 @@ uint8_t* SignatureDigest(const uint8_t* buf, uint64_t len, } else if ((digest = DigestBuf(buf, len, algorithm))) { info_digest = PrependDigestInfo(algorithm, digest); } - Free(digest); + free(digest); return info_digest; } @@ -51,11 +52,11 @@ uint8_t* SignatureBuf(const uint8_t* buf, uint64_t len, const char* key_file, key_fp = fopen(key_file, "r"); if (!key_fp) { VBDEBUG(("SignatureBuf(): Couldn't open key file: %s\n", key_file)); - Free(signature_digest); + free(signature_digest); return NULL; } if ((key = PEM_read_RSAPrivateKey(key_fp, NULL, NULL, NULL))) - signature = (uint8_t*) Malloc(siglen_map[algorithm]); + signature = (uint8_t*) malloc(siglen_map[algorithm]); else VBDEBUG(("SignatureBuf(): Couldn't read private key from file: %s\n", key_file)); @@ -70,6 +71,6 @@ uint8_t* SignatureBuf(const uint8_t* buf, uint64_t len, const char* key_file, fclose(key_fp); if (key) RSA_free(key); - Free(signature_digest); + free(signature_digest); return signature; } diff --git a/tests/rsa_verify_benchmark.c b/tests/rsa_verify_benchmark.c index 8e93e0b4..b359b62b 100644 --- a/tests/rsa_verify_benchmark.c +++ b/tests/rsa_verify_benchmark.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. */ @@ -8,8 +8,8 @@ #include "cryptolib.h" #include "file_keys.h" +#include "host_common.h" #include "timer_utils.h" -#include "utility.h" #define FILE_NAME_SIZE 128 #define NUM_OPERATIONS 100 /* Number of signature operations to time. */ @@ -77,8 +77,8 @@ int SpeedTestAlgorithm(int algorithm) { msecs); failure: - Free(signature); - Free(digest); + free(signature); + free(digest); RSAPublicKeyFree(key); return error_code; } diff --git a/tests/sha_benchmark.c b/tests/sha_benchmark.c index 8532ffa8..9f4da367 100644 --- a/tests/sha_benchmark.c +++ b/tests/sha_benchmark.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. */ @@ -7,8 +7,8 @@ #include <stdlib.h> #include "cryptolib.h" +#include "host_common.h" #include "timer_utils.h" -#include "utility.h" #define NUM_HASH_ALGORITHMS 3 #define TEST_BUFFER_SIZE 4000000 @@ -30,8 +30,8 @@ int main(int argc, char* argv[]) { int i; double speed; uint32_t msecs; - uint8_t* buffer = (uint8_t*) Malloc(TEST_BUFFER_SIZE); - uint8_t* digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE); /* Maximum size of + uint8_t* buffer = (uint8_t*) malloc(TEST_BUFFER_SIZE); + uint8_t* digest = (uint8_t*) malloc(SHA512_DIGEST_SIZE); /* Maximum size of * the digest. */ ClockTimerState ct; @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) { hash_functions[i].description, speed); } - Free(digest); - Free(buffer); + free(digest); + free(buffer); return 0; } diff --git a/tests/tpm_lite/enable.c b/tests/tpm_lite/enable.c index 5ab85bae..9163ca17 100644 --- a/tests/tpm_lite/enable.c +++ b/tests/tpm_lite/enable.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. */ @@ -8,9 +8,10 @@ #include <stdio.h> +#include "host_common.h" #include "tlcl.h" #include "tlcl_tests.h" -#include "utility.h" + int main(int argc, char** argv) { uint8_t disable, deactivated; @@ -26,7 +27,7 @@ int main(int argc, char** argv) { TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL)); printf("disable is %d, deactivated is %d\n", disable, deactivated); if (disable == 1 || deactivated == 1) { - error("failed to enable or activate"); + VbExError("failed to enable or activate"); } printf("TEST SUCCEEDED\n"); return 0; diff --git a/tests/tpm_lite/fastenable.c b/tests/tpm_lite/fastenable.c index db3c4b53..821658ca 100644 --- a/tests/tpm_lite/fastenable.c +++ b/tests/tpm_lite/fastenable.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,9 +14,9 @@ #include <stdio.h> +#include "host_common.h" #include "tlcl.h" #include "tlcl_tests.h" -#include "utility.h" int main(int argc, char** argv) { uint8_t disable, deactivated; @@ -33,12 +33,12 @@ int main(int argc, char** argv) { TPM_CHECK(TlclForceClear()); TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL)); printf("disable is %d, deactivated is %d\n", disable, deactivated); - assert(disable == 1 && deactivated == 1); + VbAssert(disable == 1 && deactivated == 1); TPM_CHECK(TlclSetEnable()); TPM_CHECK(TlclSetDeactivated(0)); TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL)); printf("disable is %d, deactivated is %d\n", disable, deactivated); - assert(disable == 0 && deactivated == 0); + VbAssert(disable == 0 && deactivated == 0); } printf("TEST SUCCEEDED\n"); diff --git a/tests/tpm_lite/globallock.c b/tests/tpm_lite/globallock.c index 24b6861f..96fad9df 100644 --- a/tests/tpm_lite/globallock.c +++ b/tests/tpm_lite/globallock.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. */ @@ -10,9 +10,9 @@ #include <stdint.h> #include <stdlib.h> +#include "host_common.h" #include "tlcl.h" #include "tlcl_tests.h" -#include "utility.h" int main(int argc, char** argv) { uint32_t zero = 0; @@ -32,13 +32,13 @@ int main(int argc, char** argv) { x = 1; TPM_EXPECT(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), TPM_E_AREA_LOCKED); TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); - assert(x == 0); + VbAssert(x == 0); // Verifies that write to index1 is still possible. x = 2; TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x))); TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); - assert(x == 2); + VbAssert(x == 2); // Turns off PP. TlclLockPhysicalPresence(); @@ -47,7 +47,7 @@ int main(int argc, char** argv) { x = 3; TPM_EXPECT(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)), TPM_E_BAD_PRESENCE); TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); - assert(x == 2); + VbAssert(x == 2); printf("TEST SUCCEEDED\n"); exit(0); } diff --git a/tests/tpm_lite/redefine_unowned.c b/tests/tpm_lite/redefine_unowned.c index f7d70d16..c54e1178 100644 --- a/tests/tpm_lite/redefine_unowned.c +++ b/tests/tpm_lite/redefine_unowned.c @@ -10,9 +10,9 @@ #include <stdint.h> #include <stdlib.h> +#include "host_common.h" #include "tlcl.h" #include "tlcl_tests.h" -#include "utility.h" int main(int argc, char** argv) { uint32_t perm; @@ -23,7 +23,7 @@ int main(int argc, char** argv) { TPM_CHECK(TlclSelfTestFull()); TPM_CHECK(TlclAssertPhysicalPresence()); - assert(!TlclIsOwned()); + VbAssert(!TlclIsOwned()); /* Ensures spaces exist. */ TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); diff --git a/tests/tpm_lite/spaceperm.c b/tests/tpm_lite/spaceperm.c index 13c31862..71a65218 100644 --- a/tests/tpm_lite/spaceperm.c +++ b/tests/tpm_lite/spaceperm.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. */ @@ -10,9 +10,9 @@ #include <stdio.h> #include <stdlib.h> +#include "host_common.h" #include "tlcl.h" #include "tlcl_tests.h" -#include "utility.h" #define PERMPPGL (TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK) #define PERMPP TPM_NV_PER_PPWRITE @@ -26,10 +26,10 @@ int main(int argc, char** argv) { TPM_CHECK(TlclAssertPhysicalPresence()); TPM_CHECK(TlclGetPermissions(INDEX0, &perm)); - assert((perm & PERMPPGL) == PERMPPGL); + VbAssert((perm & PERMPPGL) == PERMPPGL); TPM_CHECK(TlclGetPermissions(INDEX1, &perm)); - assert((perm & PERMPP) == PERMPP); + VbAssert((perm & PERMPP) == PERMPP); printf("TEST SUCCEEDED\n"); exit(0); diff --git a/tests/tpm_lite/writelimit.c b/tests/tpm_lite/writelimit.c index 07f54483..952033cb 100644 --- a/tests/tpm_lite/writelimit.c +++ b/tests/tpm_lite/writelimit.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. */ @@ -10,9 +10,9 @@ #include <stdint.h> #include <stdlib.h> +#include "host_common.h" #include "tlcl.h" #include "tlcl_tests.h" -#include "utility.h" #define TPM_MAX_NV_WRITES_NOOWNER 64 @@ -35,10 +35,10 @@ int main(int argc, char** argv) { if ((result = TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i))) != TPM_SUCCESS) { switch (result) { case TPM_E_MAXNVWRITES: - assert(i >= TPM_MAX_NV_WRITES_NOOWNER); + VbAssert(i >= TPM_MAX_NV_WRITES_NOOWNER); break; default: - error("unexpected error code %d (0x%x)\n", result, result); + VbExError("unexpected error code %d (0x%x)\n", result, result); } } } diff --git a/tests/vboot_common2_tests.c b/tests/vboot_common2_tests.c index d03b60e3..54a3f316 100644 --- a/tests/vboot_common2_tests.c +++ b/tests/vboot_common2_tests.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,7 +12,6 @@ #include "file_keys.h" #include "host_common.h" #include "test_common.h" -#include "utility.h" #include "vboot_common.h" @@ -70,7 +69,7 @@ static void VerifyDataTest(const VbPublicKey* public_key, "VerifyData() wrong sig"); RSAPublicKeyFree(rsa); - Free(sig); + free(sig); } @@ -95,8 +94,8 @@ static void VerifyDigestTest(const VbPublicKey* public_key, TEST_EQ(VerifyDigest(digest, sig, rsa), 1, "VerifyDigest() wrong sig"); RSAPublicKeyFree(rsa); - Free(sig); - Free(digest); + free(sig); + free(digest); } @@ -106,7 +105,7 @@ static void ReSignKernelPreamble(VbKernelPreambleHeader *h, h->preamble_signature.data_size, key); SignatureCopy(&h->preamble_signature, sig); - Free(sig); + free(sig); } @@ -128,7 +127,7 @@ static void VerifyKernelPreambleTest(const VbPublicKey* public_key, if (!hdr) return; hsize = (unsigned) hdr->preamble_size; - h = (VbKernelPreambleHeader*)Malloc(hsize + 16384); + h = (VbKernelPreambleHeader*)malloc(hsize + 16384); TEST_EQ(VerifyKernelPreamble(hdr, hsize, rsa), 0, "VerifyKernelPreamble() ok using key"); @@ -197,9 +196,9 @@ static void VerifyKernelPreambleTest(const VbPublicKey* public_key, /* TODO: verify parser can support a bigger header. */ - Free(h); + free(h); RSAPublicKeyFree(rsa); - Free(hdr); + free(hdr); } @@ -237,9 +236,9 @@ int main(int argc, char* argv[]) { VerifyKernelPreambleTest(public_key, private_key); if (public_key) - Free(public_key); + free(public_key); if (private_key) - Free(private_key); + free(private_key); return error_code; } diff --git a/tests/vboot_common3_tests.c b/tests/vboot_common3_tests.c index 714d255e..313078c9 100644 --- a/tests/vboot_common3_tests.c +++ b/tests/vboot_common3_tests.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,7 +12,6 @@ #include "file_keys.h" #include "host_common.h" #include "test_common.h" -#include "utility.h" #include "vboot_common.h" @@ -21,7 +20,7 @@ static void ReChecksumKeyBlock(VbKeyBlockHeader *h) { h->key_block_checksum.data_size, SHA512_DIGEST_ALGORITHM); Memcpy(GetSignatureData(&h->key_block_checksum), newchk, SHA512_DIGEST_SIZE); - Free(newchk); + free(newchk); } @@ -38,7 +37,7 @@ static void KeyBlockVerifyTest(const VbPublicKey* public_key, if (!hdr) return; hsize = (unsigned) hdr->key_block_size; - h = (VbKeyBlockHeader*)Malloc(hsize + 1024); + h = (VbKeyBlockHeader*)malloc(hsize + 1024); TEST_EQ(KeyBlockVerify(hdr, hsize, NULL, 1), 0, "KeyBlockVerify() ok using checksum"); @@ -131,8 +130,8 @@ static void KeyBlockVerifyTest(const VbPublicKey* public_key, /* TODO: verify parser can support a bigger header (i.e., one where * data_key.key_offset is bigger than expected). */ - Free(h); - Free(hdr); + free(h); + free(hdr); } @@ -142,7 +141,7 @@ static void ReSignFirmwarePreamble(VbFirmwarePreambleHeader *h, h->preamble_signature.data_size, key); SignatureCopy(&h->preamble_signature, sig); - Free(sig); + free(sig); } @@ -164,7 +163,7 @@ static void VerifyFirmwarePreambleTest(const VbPublicKey* public_key, if (!hdr) return; hsize = (unsigned) hdr->preamble_size; - h = (VbFirmwarePreambleHeader*)Malloc(hsize + 16384); + h = (VbFirmwarePreambleHeader*)malloc(hsize + 16384); TEST_EQ(VerifyFirmwarePreamble(hdr, hsize, rsa), 0, "VerifyFirmwarePreamble() ok using key"); @@ -241,9 +240,9 @@ static void VerifyFirmwarePreambleTest(const VbPublicKey* public_key, /* TODO: verify parser can support a bigger header. */ - Free(h); + free(h); RSAPublicKeyFree(rsa); - Free(hdr); + free(hdr); } @@ -291,11 +290,11 @@ int main(int argc, char* argv[]) { data_public_key); if (signing_public_key) - Free(signing_public_key); + free(signing_public_key); if (signing_private_key) - Free(signing_private_key); + free(signing_private_key); if (data_public_key) - Free(data_public_key); + free(data_public_key); return error_code; } diff --git a/utility/dev_sign_file.c b/utility/dev_sign_file.c index ac3f4002..b20423ff 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 @@ static int Sign(const char* filename, const char* keyblock_file, /* 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 @@ static int Sign(const char* filename, const char* keyblock_file, (uint64_t)0, signing_key); if (!preamble) { - error("Error creating preamble.\n"); + VbExError("Error creating preamble.\n"); return 1; } @@ -144,14 +144,14 @@ static int Sign(const char* filename, const char* keyblock_file, 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 @@ static int Sign(const char* filename, const char* keyblock_file, 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 @@ static int Verify(const char* filename, const char* vblock_file, /* 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 @@ static int Verify(const char* filename, const char* vblock_file, 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 @@ static int Verify(const char* filename, const char* vblock_file, 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 @@ static int Verify(const char* filename, const char* vblock_file, /* 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 @@ static int Verify(const char* filename, const char* vblock_file, /* 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 @@ static int Verify(const char* filename, const char* vblock_file, /* 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 b44a12e0..720cc85d 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 @@ static uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size, 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 @@ static uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size, 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 @@ static uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size, 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 @@ static uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size, /* 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 @@ static void* MapFile(const char *filename, size_t *size) { /* 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 @@ int main(int argc, char* argv[]) { 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 a8f75522..872bb4ca 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 @@ int DriveLoadFirmware(const void* base_of_rom, const void* fmap, 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 @@ int DriveLoadFirmware(const void* base_of_rom, const void* fmap, 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 @@ int main(int argc, char* argv[]) { 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 73a3626a..6b0f9a88 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 @@ int BootDeviceReadLBA(uint64_t lba_start, uint64_t lba_count, void *buffer) { 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 @@ int main(int argc, char* argv[]) { /* 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 @@ int main(int argc, char* argv[]) { } /* 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 @@ int main(int argc, char* argv[]) { } /* 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 @@ int main(int argc, char* argv[]) { 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 @@ int main(int argc, char* argv[]) { } 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 50f81461..cee89640 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 @@ int main(int argc, char* argv[]) { 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 bf23ebd5..85ba0c9b 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 @@ int main(int argc, char* argv[]) { 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 9cff2729..fb8e102c 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 @@ static int Vblock(const char* outfile, const char* keyblock_file, 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 @@ static int Vblock(const char* outfile, const char* keyblock_file, 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 @@ static int Vblock(const char* outfile, const char* keyblock_file, 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 @@ static int Verify(const char* infile, const char* signpubkey, 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 @@ static int Verify(const char* infile, const char* signpubkey, 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 @@ static int Verify(const char* infile, const char* signpubkey, /* 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 c2b4a0fa..821f7519 100644 --- a/utility/vbutil_kernel.c +++ b/utility/vbutil_kernel.c @@ -148,6 +148,7 @@ static void Debug(const char *format, ...) { 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 char* BpCmdLineLocation(blob_t *bp, uint64_t kernel_body_load_address) 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 @@ static uint8_t* ReadConfigFile(const char* config_file, uint64_t* config_size) 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 @@ static blob_t *NewBlob(uint64_t version, 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 @@ static blob_t *NewBlob(uint64_t version, 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 @@ static blob_t *NewBlob(uint64_t version, 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 @@ static blob_t *NewBlob(uint64_t version, 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 @@ static blob_t *NewBlob(uint64_t version, 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 @@ static blob_t *OldBlob(const char* filename, uint64_t pad) { 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 @@ static blob_t *OldBlob(const char* filename, uint64_t pad) { 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 @@ static blob_t *OldBlob(const char* filename, uint64_t pad) { 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 @@ static blob_t *OldBlob(const char* filename, uint64_t pad) { 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 @@ unwind_oldblob: FreeBlob(bp); bp = NULL; } else if (buf) { - Free(buf); + free(buf); } } return bp; @@ -555,15 +558,15 @@ static int Pack(const char* outfile, const char* keyblock_file, 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 @@ static int Pack(const char* outfile, const char* keyblock_file, 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 @@ static int Pack(const char* outfile, const char* keyblock_file, } 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 @@ static int Pack(const char* outfile, const char* keyblock_file, pad - key_block_size, signing_key); if (!preamble) { - error("Error creating preamble.\n"); + VbExError("Error creating preamble.\n"); return 1; } @@ -614,7 +617,7 @@ static int Pack(const char* outfile, const char* keyblock_file, 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 @@ static int Pack(const char* outfile, const char* keyblock_file, 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 @@ static int Pack(const char* outfile, const char* keyblock_file, 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 @@ static int ReplaceConfig(blob_t* bp, const char* config_file, 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 @@ static int Verify(const char* infile, const char* signpubkey, int verbose, int rv = 1; if (!infile) { - error("Must specify filename\n"); + VbExError("Must specify filename\n"); return 1; } @@ -694,7 +697,7 @@ static int Verify(const char* infile, const char* signpubkey, int verbose, 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 @@ static int Verify(const char* infile, const char* signpubkey, int verbose, /* 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 @@ static int Verify(const char* infile, const char* signpubkey, int verbose, 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 @@ static int Verify(const char* infile, const char* signpubkey, int verbose, 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 @@ static int Verify(const char* infile, const char* signpubkey, int verbose, 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 @@ static int Verify(const char* infile, const char* signpubkey, int verbose, 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 @@ static int Verify(const char* infile, const char* signpubkey, int verbose, 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 38d90003..18e37a22 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 @@ static int Pack(const char *infile, const char *outfile, uint64_t algorithm, fprintf(stderr, "vbutil_key: Error writing key.\n"); return 1; } - Free(pubkey); + free(pubkey); return 0; } @@ -99,11 +99,11 @@ static int Pack(const char *infile, const char *outfile, uint64_t algorithm, 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 @@ static int Unpack(const char *infile, const char *outfile) { 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 @@ static int Unpack(const char *infile, const char *outfile) { 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 @@ int main(int argc, char* argv[]) { switch (i) { case '?': /* Unhandled option */ - error("Unknown option\n"); + VbExError("Unknown option\n"); parse_error = 1; break; @@ -191,7 +191,7 @@ int main(int argc, char* argv[]) { 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 @@ int main(int argc, char* argv[]) { 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 c9192213..96436085 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 @@ static int Pack(const char* outfile, const char* datapubkey, 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 @@ static int Unpack(const char* infile, const char* datapubkey, 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 @@ static int Unpack(const char* infile, const char* datapubkey, } } - Free(block); + free(block); return 0; } |