Reformat files to kernel style

No code changes, just reformatting.

BUG=none
BRANCH=none
TEST=make runtests

Change-Id: I30c7f74217c10ac7cc618aee30a22febe1e41f5c
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/42053
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
Randall Spangler
2013-01-25 15:05:08 -08:00
committed by ChromeBot
parent 3b806ea951
commit 68f54d4475
12 changed files with 929 additions and 820 deletions

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -52,14 +52,16 @@ typedef struct FontArrayHeader {
typedef struct FontArrayEntryHeader { typedef struct FontArrayEntryHeader {
uint32_t ascii; /* What to show. Could even be UTF? */ uint32_t ascii; /* What to show. Could even be UTF? */
ImageInfo info; /* Describes the bitmap. */ ImageInfo info; /* Describes the bitmap. */
/* The image to use follows immediately, NOT compressed. It's uncompressed
* because each glyph is only a few hundred bytes, but they have much in /*
* common (colormaps, for example). When we add the whole font blob to the * The image to use follows immediately, NOT compressed. It's
* bmpblk, it will be compressed as a single item there. * uncompressed because each glyph is only a few hundred bytes, but
* they have much in common (colormaps, for example). When we add the
* whole font blob to the bmpblk, it will be compressed as a single
* item there.
*/ */
} __attribute__((packed)) FontArrayEntryHeader; } __attribute__((packed)) FontArrayEntryHeader;
__pragma(pack(pop)) /* Support packing for MSVC. */ __pragma(pack(pop)) /* Support packing for MSVC. */
#endif /* VBOOT_REFERENCE_BMPBLK_FONT_H_ */ #endif /* VBOOT_REFERENCE_BMPBLK_FONT_H_ */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -8,6 +8,6 @@
#define VBOOT_REFERENCE_CRC8_H_ #define VBOOT_REFERENCE_CRC8_H_
#include "sysincludes.h" #include "sysincludes.h"
uint8_t Crc8(const void* data, int len); uint8_t Crc8(const void *data, int len);
#endif /* VBOOT_REFERENCE_CRC8_H_ */ #endif /* VBOOT_REFERENCE_CRC8_H_ */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -23,106 +23,155 @@ __pragma(pack(push, 1)) /* Support packing for MSVC. */
/* Kernel space - KERNEL_NV_INDEX, locked with physical presence. */ /* Kernel space - KERNEL_NV_INDEX, locked with physical presence. */
#define ROLLBACK_SPACE_KERNEL_VERSION 2 #define ROLLBACK_SPACE_KERNEL_VERSION 2
#define ROLLBACK_SPACE_KERNEL_UID 0x4752574C /* 'GRWL' */ #define ROLLBACK_SPACE_KERNEL_UID 0x4752574C /* 'GRWL' */
typedef struct RollbackSpaceKernel { typedef struct RollbackSpaceKernel {
uint8_t struct_version; /* Struct version, for backwards /* Struct version, for backwards compatibility */
* compatibility */ uint8_t struct_version;
uint32_t uid; /* Unique ID to detect space redefinition */ /* Unique ID to detect space redefinition */
uint32_t kernel_versions; /* Kernel versions */ uint32_t uid;
uint8_t reserved[3]; /* Reserved for future expansion */ /* Kernel versions */
uint8_t crc8; /* Checksum (v2 and later only) */ uint32_t kernel_versions;
/* Reserved for future expansion */
uint8_t reserved[3];
/* Checksum (v2 and later only) */
uint8_t crc8;
} __attribute__((packed)) RollbackSpaceKernel; } __attribute__((packed)) RollbackSpaceKernel;
/* Flags for firmware space */ /* Flags for firmware space */
/* Last boot was developer mode. TPM ownership is cleared when /*
* transitioning to/from developer mode. */ * Last boot was developer mode. TPM ownership is cleared when transitioning
* to/from developer mode.
*/
#define FLAG_LAST_BOOT_DEVELOPER 0x01 #define FLAG_LAST_BOOT_DEVELOPER 0x01
/* Some systems may not have a dedicated dev-mode switch, but enter and leave /*
* dev-mode through some recovery-mode magic keypresses. For those systems, * Some systems may not have a dedicated dev-mode switch, but enter and leave
* the dev-mode "switch" state is in this bit (0=normal, 1=dev). To make it * dev-mode through some recovery-mode magic keypresses. For those systems, the
* work, a new flag is passed to VbInit(), indicating that the system lacks a * dev-mode "switch" state is in this bit (0=normal, 1=dev). To make it work, a
* physical dev-mode switch. If a physical switch is present, this bit is * new flag is passed to VbInit(), indicating that the system lacks a physical
* ignored. */ * dev-mode switch. If a physical switch is present, this bit is ignored.
*/
#define FLAG_VIRTUAL_DEV_MODE_ON 0x02 #define FLAG_VIRTUAL_DEV_MODE_ON 0x02
#define ROLLBACK_SPACE_FIRMWARE_VERSION 2
/* Firmware space - FIRMWARE_NV_INDEX, locked with global lock. */ /* Firmware space - FIRMWARE_NV_INDEX, locked with global lock. */
#define ROLLBACK_SPACE_FIRMWARE_VERSION 2
typedef struct RollbackSpaceFirmware { typedef struct RollbackSpaceFirmware {
uint8_t struct_version; /* Struct version, for backwards compatibility */ /* Struct version, for backwards compatibility */
uint8_t flags; /* Flags (see FLAG_* above) */ uint8_t struct_version;
uint32_t fw_versions; /* Firmware versions */ /* Flags (see FLAG_* above) */
uint8_t reserved[3]; /* Reserved for future expansion */ uint8_t flags;
uint8_t crc8; /* Checksum (v2 and later only) */ /* Firmware versions */
uint32_t fw_versions;
/* Reserved for future expansion */
uint8_t reserved[3];
/* Checksum (v2 and later only) */
uint8_t crc8;
} __attribute__((packed)) RollbackSpaceFirmware; } __attribute__((packed)) RollbackSpaceFirmware;
__pragma(pack(pop)) /* Support packing for MSVC. */ __pragma(pack(pop)) /* Support packing for MSVC. */
/* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */ /* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */
/* These functions are called from VbInit(). They cannot use global /*
* variables. */ * These functions are called from VbInit(). They cannot use global
* variables.
*/
uint32_t RollbackS3Resume(void); uint32_t RollbackS3Resume(void);
/* These functions are callable from VbSelectFirmware(). They cannot use /*
* global variables. */ * These functions are callable from VbSelectFirmware(). They cannot use
* global variables.
*/
/* This must be called. */ /**
* This must be called.
*/
uint32_t RollbackFirmwareSetup(int recovery_mode, int is_hw_dev, uint32_t RollbackFirmwareSetup(int recovery_mode, int is_hw_dev,
int disable_dev_request, int disable_dev_request,
int clear_tpm_owner_request, int clear_tpm_owner_request,
/* two outputs on success */ /* two outputs on success */
int *is_virt_dev, uint32_t *tpm_version); int *is_virt_dev, uint32_t *tpm_version);
/* Write may be called if the versions change */ /**
* Write may be called if the versions change.
*/
uint32_t RollbackFirmwareWrite(uint32_t version); uint32_t RollbackFirmwareWrite(uint32_t version);
/* Lock must be called */ /**
* Lock must be called.
*/
uint32_t RollbackFirmwareLock(void); uint32_t RollbackFirmwareLock(void);
/* These functions are callable from VbSelectAndLoadKernel(). They /*
* may use global variables. */ * These functions are callable from VbSelectAndLoadKernel(). They may use
* global variables.
*/
/* Read and write may be called to read and write the kernel version. */ /**
uint32_t RollbackKernelRead(uint32_t* version); * Read stored kernel version.
*/
uint32_t RollbackKernelRead(uint32_t *version);
/**
* Write stored kernel version.
*/
uint32_t RollbackKernelWrite(uint32_t version); uint32_t RollbackKernelWrite(uint32_t version);
/* Lock must be called. Internally, it's ignored in recovery mode. */ /**
* Lock must be called. Internally, it's ignored in recovery mode.
*/
uint32_t RollbackKernelLock(void); uint32_t RollbackKernelLock(void);
/****************************************************************************/ /****************************************************************************/
/* The following functions are internal apis, listed here for use by
* unit tests only. */
/* Issue a TPM_Clear and reenable/reactivate the TPM. */ /*
* The following functions are internal apis, listed here for use by unit tests
* only.
*/
/**
* Issue a TPM_Clear and reenable/reactivate the TPM.
*/
uint32_t TPMClearAndReenable(void); uint32_t TPMClearAndReenable(void);
/* Like TlclWrite(), but checks for write errors due to hitting the 64-write /**
* Like TlclWrite(), but checks for write errors due to hitting the 64-write
* limit and clears the TPM when that happens. This can only happen when the * limit and clears the TPM when that happens. This can only happen when the
* TPM is unowned, so it is OK to clear it (and we really have no choice). * TPM is unowned, so it is OK to clear it (and we really have no choice).
* This is not expected to happen frequently, but it could happen. */ * This is not expected to happen frequently, but it could happen.
uint32_t SafeWrite(uint32_t index, const void* data, uint32_t length); */
uint32_t SafeWrite(uint32_t index, const void *data, uint32_t length);
/* Similarly to SafeWrite(), this ensures we don't fail a DefineSpace because /**
* Similarly to SafeWrite(), this ensures we don't fail a DefineSpace because
* we hit the TPM write limit. This is even less likely to happen than with * we hit the TPM write limit. This is even less likely to happen than with
* writes because we only define spaces once at initialization, but we'd rather * writes because we only define spaces once at initialization, but we'd rather
* be paranoid about this. */ * be paranoid about this.
*/
uint32_t SafeDefineSpace(uint32_t index, uint32_t perm, uint32_t size); uint32_t SafeDefineSpace(uint32_t index, uint32_t perm, uint32_t size);
/* Performs one-time initializations. Creates the NVRAM spaces, and sets their /**
* initial values as needed. Sets the nvLocked bit and ensures the physical * Perform one-time initializations.
* presence command is enabled and locked. *
* Create the NVRAM spaces, and set their initial values as needed. Sets the
* nvLocked bit and ensures the physical presence command is enabled and
* locked.
*/ */
uint32_t OneTimeInitializeTPM(RollbackSpaceFirmware* rsf, uint32_t OneTimeInitializeTPM(RollbackSpaceFirmware *rsf,
RollbackSpaceKernel* rsk); RollbackSpaceKernel *rsk);
/* SetupTPM starts the TPM and establishes the root of trust for the /**
* anti-rollback mechanism. */ * Start the TPM and establish the root of trust for the anti-rollback
* mechanism.
*/
uint32_t SetupTPM(int recovery_mode, int developer_mode, uint32_t SetupTPM(int recovery_mode, int developer_mode,
int disable_dev_request, int clear_tpm_owner_request, int disable_dev_request, int clear_tpm_owner_request,
RollbackSpaceFirmware* rsf); RollbackSpaceFirmware *rsf);
/* Utility function to turn the virtual dev-mode flag on or off. 0=off, 1=on */ /**
* Utility function to turn the virtual dev-mode flag on or off. 0=off, 1=on.
*/
uint32_t SetVirtualDevMode(int val); uint32_t SetVirtualDevMode(int val);
#endif /* VBOOT_REFERENCE_ROLLBACK_INDEX_H_ */ #endif /* VBOOT_REFERENCE_ROLLBACK_INDEX_H_ */

View File

@@ -1,66 +1,76 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
*/ */
/* Helper functions/wrappers for memory allocations, manipulation and /*
* Helper functions/wrappers for memory allocations, manipulation and
* comparison. * comparison.
*/ */
#ifndef VBOOT_FIRMWARE_LIB_UTILITY_H_ #ifndef VBOOT_FIRMWARE_LIB_STATEFUL_UTIL_H_
#define VBOOT_FIRMWARE_LIB_UTILITY_H_ #define VBOOT_FIRMWARE_LIB_STATEFUL_UTIL_H_
#include "sysincludes.h" #include "sysincludes.h"
/* Track remaining data to be read in a buffer. */ /* Track remaining data to be read in a buffer. */
typedef struct MemcpyState { typedef struct MemcpyState {
uint8_t* remaining_buf; uint8_t *remaining_buf;
uint64_t remaining_len; /* Remaining length of the buffer. */ uint64_t remaining_len; /* Remaining length of the buffer. */
uint8_t overrun; /* Flag set to 1 when an overrun occurs. */ uint8_t overrun; /* Flag set to 1 when an overrun occurs. */
} MemcpyState; } MemcpyState;
/* Initialize a stateful buffer struct to point to the buffer, with /**
* the specified remaining length in bytes. */ * Initialize a stateful buffer struct to point to the buffer, with the
void StatefulInit(MemcpyState* state, void* buf, uint64_t len); * specified remaining length in bytes.
*/
void StatefulInit(MemcpyState *state, void *buf, uint64_t len);
/* Skip [len] bytes only if there's enough data to skip according /**
* to [state]. * Skip [len] bytes only if there's enough data to skip according to [state].
*
* On success, return a meaningless but non-NULL pointer and updates [state]. * On success, return a meaningless but non-NULL pointer and updates [state].
* On failure, return NULL, set state->overrun to 1. * On failure, return NULL, set state->overrun to 1.
* *
* Useful for iterating through a binary blob to populate a struct. After the * Useful for iterating through a binary blob to populate a struct. After the
* first failure (buffer overrun), successive calls will always fail. * first failure (buffer overrun), successive calls will always fail.
*/ */
void* StatefulSkip(MemcpyState* state, uint64_t len); void *StatefulSkip(MemcpyState *state, uint64_t len);
/* Copy [len] bytes into [dst] only if there's enough data to read according /**
* Copy [len] bytes into [dst] only if there's enough data to read according
* to [state]. * to [state].
*
* On success, return [dst] and update [state]. * On success, return [dst] and update [state].
* On failure, return NULL, set state->overrun to 1. * On failure, return NULL, set state->overrun to 1.
* *
* Useful for iterating through a binary blob to populate a struct. After the * Useful for iterating through a binary blob to populate a struct. After the
* first failure (buffer overrun), successive calls will always fail. * first failure (buffer overrun), successive calls will always fail.
*/ */
void* StatefulMemcpy(MemcpyState* state, void* dst, uint64_t len); void *StatefulMemcpy(MemcpyState *state, void *dst, uint64_t len);
/* Like StatefulMemcpy() but copies in the opposite direction, populating /**
* Like StatefulMemcpy() but copies in the opposite direction, populating
* data from [src] into the buffer encapsulated in state [state]. * data from [src] into the buffer encapsulated in state [state].
*
* On success, return [src] and update [state]. * On success, return [src] and update [state].
* On failure, return NULL, set state->overrun to 1. * On failure, return NULL, set state->overrun to 1.
* *
* Useful for iterating through a structure to populate a binary blob. After the * Useful for iterating through a structure to populate a binary blob. After the
* first failure (buffer overrun), successive calls will always fail. * first failure (buffer overrun), successive calls will always fail.
*/ */
const void* StatefulMemcpy_r(MemcpyState* state, const void* src, uint64_t len); const void *StatefulMemcpy_r(MemcpyState *state, const void *src, uint64_t len);
/* Like StatefulMemcpy_r() but fills a portion of the encapsulated buffer with /**
* Like StatefulMemcpy_r() but fills a portion of the encapsulated buffer with
* a constant value. * a constant value.
*
* On success, return a meaningless but non-NULL pointer and updates [state]. * On success, return a meaningless but non-NULL pointer and updates [state].
* On failure, return NULL, set state->overrun to 1. * On failure, return NULL, set state->overrun to 1.
* *
* After the first failure (buffer overrun), successive calls will always fail. * After the first failure (buffer overrun), successive calls will always fail.
*/ */
const void* StatefulMemset_r(MemcpyState* state, const uint8_t val, const void *StatefulMemset_r(MemcpyState *state, const uint8_t val,
uint64_t len); uint64_t len);
#endif /* VBOOT_FIRMWARE_LIB_UTILITY_H_ */ #endif

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -10,15 +10,16 @@
#include "sysincludes.h" #include "sysincludes.h"
/* Update TPM PCR State with the boot path status. /**
* Update TPM PCR State with the boot path status.
*
* [developer_mode]: State of the developer switch. * [developer_mode]: State of the developer switch.
* [recovery_mode}: State of the recovery mode. * [recovery_mode}: State of the recovery mode.
* [fw_keyblock_flags]: Keyblock flags on the to-be-booted * [fw_keyblock_flags]: Keyblock flags of the to-be-booted
* RW firmware keyblock. * RW firmware keyblock.
* *
* Returns: TPM_SUCCESS if the TPM extend operation succeeds. * Returns: TPM_SUCCESS if the TPM extend operation succeeds.
*/ */
uint32_t SetTPMBootModeState(int developer_mode, int recovery_mode, uint32_t SetTPMBootModeState(int developer_mode, int recovery_mode,
uint64_t fw_keyblock_flags); uint64_t fw_keyblock_flags);

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -12,14 +12,20 @@
typedef struct VbAudioContext VbAudioContext; typedef struct VbAudioContext VbAudioContext;
/* Initialization function. Returns context for processing dev-mode delay */ /**
VbAudioContext* VbAudioOpen(VbCommonParams* cparams); * Initialization function. Returns context for processing dev-mode delay.
*/
VbAudioContext *VbAudioOpen(VbCommonParams *cparams);
/* Caller should loop without extra delay until this returns false */ /**
int VbAudioLooping(VbAudioContext* audio); * Caller should loop without extra delay until this returns false.
*/
int VbAudioLooping(VbAudioContext *audio);
/* Caller should call this prior to booting */ /**
void VbAudioClose(VbAudioContext* audio); * Caller should call this prior to booting.
*/
void VbAudioClose(VbAudioContext *audio);
#endif /* VBOOT_REFERENCE_VBOOT_AUDIO_H_ */ #endif /* VBOOT_REFERENCE_VBOOT_AUDIO_H_ */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -26,7 +26,7 @@ typedef struct VbDevMusic {
struct VbAudioContext { struct VbAudioContext {
/* note tracking */ /* note tracking */
VbDevMusicNote* music_notes; VbDevMusicNote *music_notes;
uint32_t note_count; uint32_t note_count;
uint32_t next_note; uint32_t next_note;
@@ -55,4 +55,3 @@ uint32_t VbExMaxMusicSize(void);
#endif #endif
#endif /* VBOOT_REFERENCE_VBOOT_AUDIO_PRIVATE_H_ */ #endif /* VBOOT_REFERENCE_VBOOT_AUDIO_PRIVATE_H_ */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -18,121 +18,146 @@
/* Error Codes for all common functions. */ /* Error Codes for all common functions. */
enum { enum {
VBOOT_SUCCESS = 0, VBOOT_SUCCESS = 0,
VBOOT_KEY_BLOCK_INVALID, /* Key block internal structure is /* Key block internal structure is invalid, or not a key block */
* invalid, or not a key block */ VBOOT_KEY_BLOCK_INVALID,
VBOOT_KEY_BLOCK_SIGNATURE, /* Key block signature check failed */ /* Key block signature check failed */
VBOOT_KEY_BLOCK_HASH, /* Key block hash check failed */ VBOOT_KEY_BLOCK_SIGNATURE,
VBOOT_PUBLIC_KEY_INVALID, /* Invalid public key passed to a /* Key block hash check failed */
* signature verficiation function. */ VBOOT_KEY_BLOCK_HASH,
VBOOT_PREAMBLE_INVALID, /* Preamble internal structure is /* Invalid public key passed to a signature verficiation function. */
* invalid */ VBOOT_PUBLIC_KEY_INVALID,
VBOOT_PREAMBLE_SIGNATURE, /* Preamble signature check failed */ /* Preamble internal structure is invalid */
VBOOT_SHARED_DATA_INVALID, /* Shared data is invalid. */ VBOOT_PREAMBLE_INVALID,
/* Preamble signature check failed */
VBOOT_PREAMBLE_SIGNATURE,
/* Shared data is invalid. */
VBOOT_SHARED_DATA_INVALID,
VBOOT_ERROR_MAX, VBOOT_ERROR_MAX,
}; };
extern char* kVbootErrors[VBOOT_ERROR_MAX]; extern const char *kVbootErrors[VBOOT_ERROR_MAX];
/**
* Return offset of ptr from base.
*/
uint64_t OffsetOf(const void *base, const void *ptr);
/* Return offset of ptr from base. */ /*
uint64_t OffsetOf(const void* base, const void* ptr); * Helper functions to get data pointed to by a public key or signature.
*/
uint8_t *GetPublicKeyData(VbPublicKey *key);
const uint8_t *GetPublicKeyDataC(const VbPublicKey *key);
uint8_t *GetSignatureData(VbSignature *sig);
const uint8_t *GetSignatureDataC(const VbSignature *sig);
/* Helper functions to get data pointed to by a public key or signature. */ /*
uint8_t* GetPublicKeyData(VbPublicKey* key); * Helper functions to verify the data pointed to by a subfield is inside the
const uint8_t* GetPublicKeyDataC(const VbPublicKey* key); * parent data. Returns 0 if inside, 1 if error.
uint8_t* GetSignatureData(VbSignature* sig); */
const uint8_t* GetSignatureDataC(const VbSignature* sig);
int VerifyMemberInside(const void *parent, uint64_t parent_size,
/* Helper functions to verify the data pointed to by a subfield is inside const void *member, uint64_t member_size,
* the parent data. Returns 0 if inside, 1 if error. */
int VerifyMemberInside(const void* parent, uint64_t parent_size,
const void* member, uint64_t member_size,
uint64_t member_data_offset, uint64_t member_data_offset,
uint64_t member_data_size); uint64_t member_data_size);
int VerifyPublicKeyInside(const void* parent, uint64_t parent_size, int VerifyPublicKeyInside(const void *parent, uint64_t parent_size,
const VbPublicKey* key); const VbPublicKey *key);
int VerifySignatureInside(const void* parent, uint64_t parent_size, int VerifySignatureInside(const void *parent, uint64_t parent_size,
const VbSignature* sig); const VbSignature *sig);
/**
* Initialize a public key to refer to [key_data].
*/
void PublicKeyInit(VbPublicKey *key, uint8_t *key_data, uint64_t key_size);
/* Initialize a public key to refer to [key_data]. */ /**
void PublicKeyInit(VbPublicKey* key, uint8_t* key_data, uint64_t key_size); * Copy a public key from [src] to [dest].
/* Copy a public key from [src] to [dest].
* *
* Returns 0 if success, non-zero if error. */ * Returns 0 if success, non-zero if error.
int PublicKeyCopy(VbPublicKey* dest, const VbPublicKey* src); */
int PublicKeyCopy(VbPublicKey *dest, const VbPublicKey *src);
/**
/* Converts a public key to RsaPublicKey format. The returned key must * Convert a public key to RsaPublicKey format. The returned key must be freed
* be freed using RSAPublicKeyFree(). * using RSAPublicKeyFree().
* *
* Returns NULL if error. */ * Returns NULL if error.
RSAPublicKey* PublicKeyToRSA(const VbPublicKey* key); */
RSAPublicKey *PublicKeyToRSA(const VbPublicKey *key);
/**
* Verify [data] matches signature [sig] using [key]. [size] is the size of
* the data buffer; the amount of data to be validated is contained in
* sig->data_size.
*/
int VerifyData(const uint8_t *data, uint64_t size, const VbSignature *sig,
const RSAPublicKey *key);
/* Verifies [data] matches signature [sig] using [key]. [size] is the size /**
* of the data buffer; the amount of data to be validated is contained in * Verify a secure hash digest from DigestBuf() or DigestFinal(), using
* sig->data_size. */ * [key]. Returns 0 on success.
int VerifyData(const uint8_t* data, uint64_t size, const VbSignature* sig, */
const RSAPublicKey* key); int VerifyDigest(const uint8_t *digest, const VbSignature *sig,
const RSAPublicKey *key);
/**
/* Verifies a secure hash digest from DigestBuf() or DigestFinal(), * Check the sanity of a key block of size [size] bytes, using public key
* using [key]. Returns 0 on success. */ * [key]. If hash_only is non-zero, uses only the block checksum to verify the
int VerifyDigest(const uint8_t* digest, const VbSignature *sig, * key block. Header fields are also checked for sanity. Does not verify key
const RSAPublicKey* key); * index or key block flags.
*/
/* Checks the sanity of a key block of size [size] bytes, using public int KeyBlockVerify(const VbKeyBlockHeader *block, uint64_t size,
* key [key]. If hash_only is non-zero, uses only the block checksum
* to verify the key block. Header fields are also checked for
* sanity. Does not verify key index or key block flags. */
int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t size,
const VbPublicKey *key, int hash_only); const VbPublicKey *key, int hash_only);
/* Checks the sanity of a firmware preamble of size [size] bytes, /**
* using public key [key]. * Check the sanity of a firmware preamble of size [size] bytes, using public
* key [key].
* *
* Returns VBOOT_SUCCESS if successful. */ * Returns VBOOT_SUCCESS if successful.
int VerifyFirmwarePreamble(const VbFirmwarePreambleHeader* preamble, */
uint64_t size, const RSAPublicKey* key); int VerifyFirmwarePreamble(const VbFirmwarePreambleHeader *preamble,
uint64_t size, const RSAPublicKey *key);
/* Returns the flags from a firmware preamble, or a default value for /**
* older preamble versions which didn't contain flags. Use this * Return the flags from a firmware preamble, or a default value for older
* function to ensure compatibility with older preamble versions * preamble versions which didn't contain flags. Use this function to ensure
* (2.0). Assumes the preamble has already been verified via * compatibility with older preamble versions (2.0). Assumes the preamble has
* VerifyFirmwarePreamble(). */ * already been verified via VerifyFirmwarePreamble().
uint32_t VbGetFirmwarePreambleFlags(const VbFirmwarePreambleHeader* preamble); */
uint32_t VbGetFirmwarePreambleFlags(const VbFirmwarePreambleHeader *preamble);
/**
/* Checks the sanity of a kernel preamble of size [size] bytes, * Check the sanity of a kernel preamble of size [size] bytes, using public key
* using public key [key]. * [key].
* *
* Returns VBOOT_SUCCESS if successful. */ * Returns VBOOT_SUCCESS if successful.
int VerifyKernelPreamble(const VbKernelPreambleHeader* preamble, */
uint64_t size, const RSAPublicKey* key); int VerifyKernelPreamble(const VbKernelPreambleHeader *preamble,
uint64_t size, const RSAPublicKey *key);
/* Initialize a verified boot shared data structure. /**
* Initialize a verified boot shared data structure.
* *
* Returns 0 if success, non-zero if error. */ * Returns 0 if success, non-zero if error.
int VbSharedDataInit(VbSharedDataHeader* header, uint64_t size); */
int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size);
/* Reserve [size] bytes of the shared data area. Returns the offset of the /**
* reserved data from the start of the shared data buffer, or 0 if error. */ * Reserve [size] bytes of the shared data area. Returns the offset of the
uint64_t VbSharedDataReserve(VbSharedDataHeader* header, uint64_t size); * reserved data from the start of the shared data buffer, or 0 if error.
*/
uint64_t VbSharedDataReserve(VbSharedDataHeader *header, uint64_t size);
/* Copy the kernel subkey into the shared data. /**
* Copy the kernel subkey into the shared data.
* *
* Returns 0 if success, non-zero if error. */ * Returns 0 if success, non-zero if error.
int VbSharedDataSetKernelKey(VbSharedDataHeader* header, */
const VbPublicKey* src); int VbSharedDataSetKernelKey(VbSharedDataHeader *header,
const VbPublicKey *src);
#endif /* VBOOT_REFERENCE_VBOOT_COMMON_H_ */ #endif /* VBOOT_REFERENCE_VBOOT_COMMON_H_ */

View File

@@ -11,12 +11,12 @@
#include "vboot_api.h" #include "vboot_api.h"
#include "vboot_nvstorage.h" #include "vboot_nvstorage.h"
VbError_t VbDisplayScreenFromGBB(VbCommonParams* cparams, uint32_t screen, VbError_t VbDisplayScreenFromGBB(VbCommonParams *cparams, uint32_t screen,
VbNvContext *vncptr); VbNvContext *vncptr);
VbError_t VbDisplayScreen(VbCommonParams* cparams, uint32_t screen, int force, VbError_t VbDisplayScreen(VbCommonParams *cparams, uint32_t screen, int force,
VbNvContext *vncptr); VbNvContext *vncptr);
VbError_t VbDisplayDebugInfo(VbCommonParams* cparams, VbNvContext *vncptr); VbError_t VbDisplayDebugInfo(VbCommonParams *cparams, VbNvContext *vncptr);
VbError_t VbCheckDisplayKey(VbCommonParams* cparams, uint32_t key, VbError_t VbCheckDisplayKey(VbCommonParams *cparams, uint32_t key,
VbNvContext *vncptr); VbNvContext *vncptr);
/* Internal functions, for unit testing */ /* Internal functions, for unit testing */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -12,15 +12,18 @@
#include "cgptlib.h" #include "cgptlib.h"
#include "vboot_api.h" #include "vboot_api.h"
/* Allocates and reads GPT data from the drive. The sector_bytes and /**
* drive_sectors fields should be filled on input. The primary and * Allocate and read GPT data from the drive. The sector_bytes and
* secondary header and entries are filled on output. * drive_sectors fields should be filled on input. The primary and secondary
* header and entries are filled on output.
* *
* Returns 0 if successful, 1 if error. */ * Returns 0 if successful, 1 if error.
int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData* gptdata); */
int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata);
/* Writes any changes for the GPT data back to the drive, then frees the /**
* buffers. */ * Write any changes for the GPT data back to the drive, then free the buffers.
int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData* gptdata); */
int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData *gptdata);
#endif /* VBOOT_REFERENCE_VBOOT_KERNEL_H_ */ #endif /* VBOOT_REFERENCE_VBOOT_KERNEL_H_ */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -6,13 +6,11 @@
* (Firmware portion) * (Firmware portion)
*/ */
#include "vboot_api.h" #include "vboot_api.h"
#include "vboot_common.h" #include "vboot_common.h"
#include "utility.h" #include "utility.h"
const char *kVbootErrors[VBOOT_ERROR_MAX] = {
char* kVbootErrors[VBOOT_ERROR_MAX] = {
"Success.", "Success.",
"Key block invalid.", "Key block invalid.",
"Key block signature failed.", "Key block signature failed.",
@@ -23,36 +21,43 @@ char* kVbootErrors[VBOOT_ERROR_MAX] = {
"Shared data invalid." "Shared data invalid."
}; };
uint64_t OffsetOf(const void *base, const void *ptr)
uint64_t OffsetOf(const void *base, const void *ptr) { {
return (uint64_t)(size_t)ptr - (uint64_t)(size_t)base; return (uint64_t)(size_t)ptr - (uint64_t)(size_t)base;
} }
/* Helper functions to get data pointed to by a public key or signature. */ /* Helper functions to get data pointed to by a public key or signature. */
uint8_t* GetPublicKeyData(VbPublicKey* key) {
return (uint8_t*)key + key->key_offset; uint8_t *GetPublicKeyData(VbPublicKey *key)
{
return (uint8_t *)key + key->key_offset;
} }
const uint8_t* GetPublicKeyDataC(const VbPublicKey* key) { const uint8_t *GetPublicKeyDataC(const VbPublicKey *key)
return (const uint8_t*)key + key->key_offset; {
return (const uint8_t *)key + key->key_offset;
} }
uint8_t* GetSignatureData(VbSignature* sig) { uint8_t *GetSignatureData(VbSignature *sig)
return (uint8_t*)sig + sig->sig_offset; {
return (uint8_t *)sig + sig->sig_offset;
} }
const uint8_t* GetSignatureDataC(const VbSignature* sig) { const uint8_t *GetSignatureDataC(const VbSignature *sig)
return (const uint8_t*)sig + sig->sig_offset; {
return (const uint8_t *)sig + sig->sig_offset;
} }
/*
* Helper functions to verify the data pointed to by a subfield is inside
* the parent data. Returns 0 if inside, 1 if error.
*/
/* Helper functions to verify the data pointed to by a subfield is inside int VerifyMemberInside(const void *parent, uint64_t parent_size,
* the parent data. Returns 0 if inside, 1 if error. */ const void *member, uint64_t member_size,
int VerifyMemberInside(const void* parent, uint64_t parent_size,
const void* member, uint64_t member_size,
uint64_t member_data_offset, uint64_t member_data_offset,
uint64_t member_data_size) { uint64_t member_data_size)
{
uint64_t end = OffsetOf(parent, member); uint64_t end = OffsetOf(parent, member);
if (end > parent_size) if (end > parent_size)
@@ -77,32 +82,32 @@ int VerifyMemberInside(const void* parent, uint64_t parent_size,
return 0; return 0;
} }
int VerifyPublicKeyInside(const void *parent, uint64_t parent_size,
int VerifyPublicKeyInside(const void* parent, uint64_t parent_size, const VbPublicKey *key)
const VbPublicKey* key) { {
return VerifyMemberInside(parent, parent_size, return VerifyMemberInside(parent, parent_size,
key, sizeof(VbPublicKey), key, sizeof(VbPublicKey),
key->key_offset, key->key_size); key->key_offset, key->key_size);
} }
int VerifySignatureInside(const void *parent, uint64_t parent_size,
int VerifySignatureInside(const void* parent, uint64_t parent_size, const VbSignature *sig)
const VbSignature* sig) { {
return VerifyMemberInside(parent, parent_size, return VerifyMemberInside(parent, parent_size,
sig, sizeof(VbSignature), sig, sizeof(VbSignature),
sig->sig_offset, sig->sig_size); sig->sig_offset, sig->sig_size);
} }
void PublicKeyInit(VbPublicKey *key, uint8_t *key_data, uint64_t key_size)
void PublicKeyInit(VbPublicKey* key, uint8_t* key_data, uint64_t key_size) { {
key->key_offset = OffsetOf(key, key_data); key->key_offset = OffsetOf(key, key_data);
key->key_size = key_size; key->key_size = key_size;
key->algorithm = kNumAlgorithms; /* Key not present yet */ key->algorithm = kNumAlgorithms; /* Key not present yet */
key->key_version = 0; key->key_version = 0;
} }
int PublicKeyCopy(VbPublicKey *dest, const VbPublicKey *src)
int PublicKeyCopy(VbPublicKey* dest, const VbPublicKey* src) { {
if (dest->key_size < src->key_size) if (dest->key_size < src->key_size)
return 1; return 1;
@@ -113,8 +118,8 @@ int PublicKeyCopy(VbPublicKey* dest, const VbPublicKey* src) {
return 0; return 0;
} }
RSAPublicKey *PublicKeyToRSA(const VbPublicKey *key)
RSAPublicKey* PublicKeyToRSA(const VbPublicKey* key) { {
RSAPublicKey *rsa; RSAPublicKey *rsa;
uint64_t key_size; uint64_t key_size;
@@ -136,10 +141,9 @@ RSAPublicKey* PublicKeyToRSA(const VbPublicKey* key) {
return rsa; return rsa;
} }
int VerifyData(const uint8_t *data, uint64_t size, const VbSignature *sig,
int VerifyData(const uint8_t* data, uint64_t size, const VbSignature *sig, const RSAPublicKey *key)
const RSAPublicKey* key) { {
if (sig->sig_size != siglen_map[key->algorithm]) { if (sig->sig_size != siglen_map[key->algorithm]) {
VBDEBUG(("Wrong signature size for algorithm.\n")); VBDEBUG(("Wrong signature size for algorithm.\n"));
return 1; return 1;
@@ -156,27 +160,26 @@ int VerifyData(const uint8_t* data, uint64_t size, const VbSignature *sig,
return 0; return 0;
} }
int VerifyDigest(const uint8_t *digest, const VbSignature *sig,
int VerifyDigest(const uint8_t* digest, const VbSignature *sig, const RSAPublicKey *key)
const RSAPublicKey* key) { {
if (sig->sig_size != siglen_map[key->algorithm]) { if (sig->sig_size != siglen_map[key->algorithm]) {
VBDEBUG(("Wrong signature size for algorithm.\n")); VBDEBUG(("Wrong signature size for algorithm.\n"));
return 1; return 1;
} }
if (!RSAVerifyBinaryWithDigest_f(NULL, key, digest, if (!RSAVerifyBinaryWithDigest_f(NULL, key, digest,
GetSignatureDataC(sig), key->algorithm)) GetSignatureDataC(sig),
key->algorithm))
return 1; return 1;
return 0; return 0;
} }
int KeyBlockVerify(const VbKeyBlockHeader *block, uint64_t size,
int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t size, const VbPublicKey *key, int hash_only)
const VbPublicKey *key, int hash_only) { {
const VbSignature *sig;
const VbSignature* sig;
/* Sanity checks before attempting signature of data */ /* Sanity checks before attempting signature of data */
if(size < sizeof(VbKeyBlockHeader)) { if(size < sizeof(VbKeyBlockHeader)) {
@@ -200,14 +203,15 @@ int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t size,
return VBOOT_PUBLIC_KEY_INVALID; return VBOOT_PUBLIC_KEY_INVALID;
} }
/* Check signature or hash, depending on the hash_only parameter. Note that /*
* we don't require a key even if the keyblock has a signature, because the * Check signature or hash, depending on the hash_only parameter. Note
* caller may not care if the keyblock itself is signed (for example, booting * that we don't require a key even if the keyblock has a signature,
* a Google-signed kernel in developer mode). * because the caller may not care if the keyblock itself is signed
* (for example, booting a Google-signed kernel in developer mode).
*/ */
if (hash_only) { if (hash_only) {
/* Check hash */ /* Check hash */
uint8_t* header_checksum = NULL; uint8_t *header_checksum = NULL;
int rv; int rv;
sig = &block->key_block_checksum; sig = &block->key_block_checksum;
@@ -223,12 +227,13 @@ int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t size,
/* Make sure advertised signature data sizes are sane. */ /* Make sure advertised signature data sizes are sane. */
if (block->key_block_size < sig->data_size) { if (block->key_block_size < sig->data_size) {
VBDEBUG(("Signature calculated past end of the block\n")); VBDEBUG(("Signature calculated past end of block\n"));
return VBOOT_KEY_BLOCK_INVALID; return VBOOT_KEY_BLOCK_INVALID;
} }
VBDEBUG(("Checking key block hash only...\n")); VBDEBUG(("Checking key block hash only...\n"));
header_checksum = DigestBuf((const uint8_t*)block, sig->data_size, header_checksum = DigestBuf((const uint8_t *)block,
sig->data_size,
SHA512_DIGEST_ALGORITHM); SHA512_DIGEST_ALGORITHM);
rv = SafeMemcmp(header_checksum, GetSignatureDataC(sig), rv = SafeMemcmp(header_checksum, GetSignatureDataC(sig),
SHA512_DIGEST_SIZE); SHA512_DIGEST_SIZE);
@@ -239,7 +244,7 @@ int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t size,
} }
} else { } else {
/* Check signature */ /* Check signature */
RSAPublicKey* rsa; RSAPublicKey *rsa;
int rv; int rv;
sig = &block->key_block_signature; sig = &block->key_block_signature;
@@ -257,13 +262,13 @@ int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t size,
/* Make sure advertised signature data sizes are sane. */ /* Make sure advertised signature data sizes are sane. */
if (block->key_block_size < sig->data_size) { if (block->key_block_size < sig->data_size) {
VBDEBUG(("Signature calculated past end of the block\n")); VBDEBUG(("Signature calculated past end of block\n"));
RSAPublicKeyFree(rsa); RSAPublicKeyFree(rsa);
return VBOOT_KEY_BLOCK_INVALID; return VBOOT_KEY_BLOCK_INVALID;
} }
VBDEBUG(("Checking key block signature...\n")); VBDEBUG(("Checking key block signature...\n"));
rv = VerifyData((const uint8_t*)block, size, sig, rsa); rv = VerifyData((const uint8_t *)block, size, sig, rsa);
RSAPublicKeyFree(rsa); RSAPublicKeyFree(rsa);
if (rv) { if (rv) {
VBDEBUG(("Invalid key block signature.\n")); VBDEBUG(("Invalid key block signature.\n"));
@@ -278,7 +283,8 @@ int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t size,
} }
/* Verify data key is inside the block and inside signed data */ /* Verify data key is inside the block and inside signed data */
if (VerifyPublicKeyInside(block, block->key_block_size, &block->data_key)) { if (VerifyPublicKeyInside(block, block->key_block_size,
&block->data_key)) {
VBDEBUG(("Data key off end of key block\n")); VBDEBUG(("Data key off end of key block\n"));
return VBOOT_KEY_BLOCK_INVALID; return VBOOT_KEY_BLOCK_INVALID;
} }
@@ -291,10 +297,10 @@ int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t size,
return VBOOT_SUCCESS; return VBOOT_SUCCESS;
} }
int VerifyFirmwarePreamble(const VbFirmwarePreambleHeader* preamble, int VerifyFirmwarePreamble(const VbFirmwarePreambleHeader *preamble,
uint64_t size, const RSAPublicKey* key) { uint64_t size, const RSAPublicKey *key)
{
const VbSignature* sig = &preamble->preamble_signature; const VbSignature *sig = &preamble->preamble_signature;
/* Sanity checks before attempting signature of data */ /* Sanity checks before attempting signature of data */
if(size < EXPECTED_VBFIRMWAREPREAMBLEHEADER2_0_SIZE) { if(size < EXPECTED_VBFIRMWAREPREAMBLEHEADER2_0_SIZE) {
@@ -323,7 +329,7 @@ int VerifyFirmwarePreamble(const VbFirmwarePreambleHeader* preamble,
return VBOOT_PREAMBLE_INVALID; return VBOOT_PREAMBLE_INVALID;
} }
if (VerifyData((const uint8_t*)preamble, size, sig, key)) { if (VerifyData((const uint8_t *)preamble, size, sig, key)) {
VBDEBUG(("Preamble signature validation failed\n")); VBDEBUG(("Preamble signature validation failed\n"));
return VBOOT_PREAMBLE_SIGNATURE; return VBOOT_PREAMBLE_SIGNATURE;
} }
@@ -348,8 +354,10 @@ int VerifyFirmwarePreamble(const VbFirmwarePreambleHeader* preamble,
return VBOOT_PREAMBLE_INVALID; return VBOOT_PREAMBLE_INVALID;
} }
/* If the preamble header version is at least 2.1, verify we have /*
* space for the added fields from 2.1. */ * If the preamble header version is at least 2.1, verify we have space
* for the added fields from 2.1.
*/
if (preamble->header_version_minor >= 1) { if (preamble->header_version_minor >= 1) {
if(size < EXPECTED_VBFIRMWAREPREAMBLEHEADER2_1_SIZE) { if(size < EXPECTED_VBFIRMWAREPREAMBLEHEADER2_1_SIZE) {
VBDEBUG(("Not enough data for preamble header 2.1.\n")); VBDEBUG(("Not enough data for preamble header 2.1.\n"));
@@ -361,30 +369,32 @@ int VerifyFirmwarePreamble(const VbFirmwarePreambleHeader* preamble,
return VBOOT_SUCCESS; return VBOOT_SUCCESS;
} }
uint32_t VbGetFirmwarePreambleFlags(const VbFirmwarePreambleHeader *preamble)
uint32_t VbGetFirmwarePreambleFlags(const VbFirmwarePreambleHeader* preamble) { {
if (preamble->header_version_minor < 1) { if (preamble->header_version_minor < 1) {
/* Old structure; return default flags. (Note that we don't need /*
* to check header_version_major; if that's not 2 then * Old structure; return default flags. (Note that we don't
* VerifyFirmwarePreamble() would have already failed. */ * need to check header_version_major; if that's not 2 then
* VerifyFirmwarePreamble() would have already failed.
*/
return 0; return 0;
} }
return preamble->flags; return preamble->flags;
} }
int VerifyKernelPreamble(const VbKernelPreambleHeader *preamble,
int VerifyKernelPreamble(const VbKernelPreambleHeader* preamble, uint64_t size, const RSAPublicKey *key)
uint64_t size, const RSAPublicKey* key) { {
const VbSignature *sig = &preamble->preamble_signature;
const VbSignature* sig = &preamble->preamble_signature;
/* Sanity checks before attempting signature of data */ /* Sanity checks before attempting signature of data */
if(size < sizeof(VbKernelPreambleHeader)) { if(size < sizeof(VbKernelPreambleHeader)) {
VBDEBUG(("Not enough data for preamble header.\n")); VBDEBUG(("Not enough data for preamble header.\n"));
return VBOOT_PREAMBLE_INVALID; return VBOOT_PREAMBLE_INVALID;
} }
if (preamble->header_version_major != KERNEL_PREAMBLE_HEADER_VERSION_MAJOR) { if (preamble->header_version_major !=
KERNEL_PREAMBLE_HEADER_VERSION_MAJOR) {
VBDEBUG(("Incompatible kernel preamble header version.\n")); VBDEBUG(("Incompatible kernel preamble header version.\n"));
return VBOOT_PREAMBLE_INVALID; return VBOOT_PREAMBLE_INVALID;
} }
@@ -398,7 +408,7 @@ int VerifyKernelPreamble(const VbKernelPreambleHeader* preamble,
VBDEBUG(("Preamble signature off end of preamble\n")); VBDEBUG(("Preamble signature off end of preamble\n"));
return VBOOT_PREAMBLE_INVALID; return VBOOT_PREAMBLE_INVALID;
} }
if (VerifyData((const uint8_t*)preamble, size, sig, key)) { if (VerifyData((const uint8_t *)preamble, size, sig, key)) {
VBDEBUG(("Preamble signature validation failed\n")); VBDEBUG(("Preamble signature validation failed\n"));
return VBOOT_PREAMBLE_SIGNATURE; return VBOOT_PREAMBLE_SIGNATURE;
} }
@@ -420,9 +430,8 @@ int VerifyKernelPreamble(const VbKernelPreambleHeader* preamble,
return VBOOT_SUCCESS; return VBOOT_SUCCESS;
} }
int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size)
int VbSharedDataInit(VbSharedDataHeader* header, uint64_t size) { {
VBDEBUG(("VbSharedDataInit, %d bytes, header %d bytes\n", (int)size, VBDEBUG(("VbSharedDataInit, %d bytes, header %d bytes\n", (int)size,
sizeof(VbSharedDataHeader))); sizeof(VbSharedDataHeader)));
@@ -453,8 +462,8 @@ int VbSharedDataInit(VbSharedDataHeader* header, uint64_t size) {
return VBOOT_SUCCESS; return VBOOT_SUCCESS;
} }
uint64_t VbSharedDataReserve(VbSharedDataHeader *header, uint64_t size)
uint64_t VbSharedDataReserve(VbSharedDataHeader* header, uint64_t size) { {
uint64_t offs = header->data_used; uint64_t offs = header->data_used;
VBDEBUG(("VbSharedDataReserve %d bytes at %d\n", (int)size, (int)offs)); VBDEBUG(("VbSharedDataReserve %d bytes at %d\n", (int)size, (int)offs));
@@ -467,26 +476,25 @@ uint64_t VbSharedDataReserve(VbSharedDataHeader* header, uint64_t size) {
return offs; return offs;
} }
int VbSharedDataSetKernelKey(VbSharedDataHeader *header, const VbPublicKey *src)
int VbSharedDataSetKernelKey(VbSharedDataHeader* header, {
const VbPublicKey* src) {
VbPublicKey *kdest = &header->kernel_subkey; VbPublicKey *kdest = &header->kernel_subkey;
if (!header) if (!header)
return VBOOT_SHARED_DATA_INVALID; return VBOOT_SHARED_DATA_INVALID;
/* Attempt to allocate space for the key, if it hasn't been allocated yet */ /* Attempt to allocate space for key, if it hasn't been allocated yet */
if (!header->kernel_subkey_data_offset) { if (!header->kernel_subkey_data_offset) {
header->kernel_subkey_data_offset = VbSharedDataReserve(header, header->kernel_subkey_data_offset =
src->key_size); VbSharedDataReserve(header, src->key_size);
if (!header->kernel_subkey_data_offset) if (!header->kernel_subkey_data_offset)
return VBOOT_SHARED_DATA_INVALID; return VBOOT_SHARED_DATA_INVALID;
header->kernel_subkey_data_size = src->key_size; header->kernel_subkey_data_size = src->key_size;
} }
/* Copy the kernel sign key blob into the destination buffer */ /* Copy the kernel sign key blob into the destination buffer */
PublicKeyInit(kdest, (uint8_t*)header + header->kernel_subkey_data_offset, PublicKeyInit(kdest,
(uint8_t *)header + header->kernel_subkey_data_offset,
header->kernel_subkey_data_size); header->kernel_subkey_data_size);
return PublicKeyCopy(kdest, src); return PublicKeyCopy(kdest, src);

View File

@@ -16,19 +16,20 @@
#include "vboot_common.h" #include "vboot_common.h"
static void ReChecksumKeyBlock(VbKeyBlockHeader *h) { static void ReChecksumKeyBlock(VbKeyBlockHeader *h)
uint8_t* newchk = DigestBuf((const uint8_t*)h, {
uint8_t *newchk = DigestBuf((const uint8_t *)h,
h->key_block_checksum.data_size, h->key_block_checksum.data_size,
SHA512_DIGEST_ALGORITHM); SHA512_DIGEST_ALGORITHM);
Memcpy(GetSignatureData(&h->key_block_checksum), newchk, SHA512_DIGEST_SIZE); Memcpy(GetSignatureData(&h->key_block_checksum), newchk,
SHA512_DIGEST_SIZE);
free(newchk); free(newchk);
} }
static void KeyBlockVerifyTest(const VbPublicKey *public_key,
static void KeyBlockVerifyTest(const VbPublicKey* public_key, const VbPrivateKey *private_key,
const VbPrivateKey* private_key, const VbPublicKey *data_key)
const VbPublicKey* data_key) { {
VbKeyBlockHeader *hdr; VbKeyBlockHeader *hdr;
VbKeyBlockHeader *h; VbKeyBlockHeader *h;
unsigned hsize; unsigned hsize;
@@ -38,7 +39,7 @@ static void KeyBlockVerifyTest(const VbPublicKey* public_key,
if (!hdr) if (!hdr)
return; return;
hsize = (unsigned) hdr->key_block_size; hsize = (unsigned) hdr->key_block_size;
h = (VbKeyBlockHeader*)malloc(hsize + 1024); h = (VbKeyBlockHeader *)malloc(hsize + 1024);
TEST_EQ(KeyBlockVerify(hdr, hsize, NULL, 1), 0, TEST_EQ(KeyBlockVerify(hdr, hsize, NULL, 1), 0,
"KeyBlockVerify() ok using checksum"); "KeyBlockVerify() ok using checksum");
@@ -54,28 +55,33 @@ static void KeyBlockVerifyTest(const VbPublicKey* public_key,
Memcpy(h, hdr, hsize); Memcpy(h, hdr, hsize);
h->magic[0] &= 0x12; h->magic[0] &= 0x12;
TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() magic"); TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
"KeyBlockVerify() magic");
/* Care about major version but not minor */ /* Care about major version but not minor */
Memcpy(h, hdr, hsize); Memcpy(h, hdr, hsize);
h->header_version_major++; h->header_version_major++;
ReChecksumKeyBlock(h); ReChecksumKeyBlock(h);
TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() major++"); TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
"KeyBlockVerify() major++");
Memcpy(h, hdr, hsize); Memcpy(h, hdr, hsize);
h->header_version_major--; h->header_version_major--;
ReChecksumKeyBlock(h); ReChecksumKeyBlock(h);
TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() major--"); TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
"KeyBlockVerify() major--");
Memcpy(h, hdr, hsize); Memcpy(h, hdr, hsize);
h->header_version_minor++; h->header_version_minor++;
ReChecksumKeyBlock(h); ReChecksumKeyBlock(h);
TEST_EQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() minor++"); TEST_EQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
"KeyBlockVerify() minor++");
Memcpy(h, hdr, hsize); Memcpy(h, hdr, hsize);
h->header_version_minor--; h->header_version_minor--;
ReChecksumKeyBlock(h); ReChecksumKeyBlock(h);
TEST_EQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() minor--"); TEST_EQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
"KeyBlockVerify() minor--");
/* Check hash */ /* Check hash */
Memcpy(h, hdr, hsize); Memcpy(h, hdr, hsize);
@@ -114,7 +120,6 @@ static void KeyBlockVerifyTest(const VbPublicKey* public_key,
"KeyBlockVerify() sig mismatch"); "KeyBlockVerify() sig mismatch");
Memcpy(h, hdr, hsize); Memcpy(h, hdr, hsize);
//ReChecksumKeyBlock(h);
h->key_block_checksum.data_size = h->key_block_size + 1; h->key_block_checksum.data_size = h->key_block_size + 1;
TEST_NEQ(KeyBlockVerify(h, hsize, public_key, 1), 0, TEST_NEQ(KeyBlockVerify(h, hsize, public_key, 1), 0,
"KeyBlockVerify() checksum data past end of block"); "KeyBlockVerify() checksum data past end of block");
@@ -138,44 +143,45 @@ static void KeyBlockVerifyTest(const VbPublicKey* public_key,
TEST_NEQ(KeyBlockVerify(NULL, 4, NULL, 1), 0, TEST_NEQ(KeyBlockVerify(NULL, 4, NULL, 1), 0,
"KeyBlockVerify size too small"); "KeyBlockVerify size too small");
/* TODO: verify parser can support a bigger header (i.e., one where /*
* data_key.key_offset is bigger than expected). */ * TODO: verify parser can support a bigger header (i.e., one where
* data_key.key_offset is bigger than expected).
*/
free(h); free(h);
free(hdr); free(hdr);
} }
static void ReSignFirmwarePreamble(VbFirmwarePreambleHeader *h,
static void ReSignFirmwarePreamble(VbFirmwarePreambleHeader* h, const VbPrivateKey *key)
const VbPrivateKey* key) { {
VbSignature *sig = CalculateSignature((const uint8_t*)h, VbSignature *sig = CalculateSignature(
h->preamble_signature.data_size, key); (const uint8_t *)h, h->preamble_signature.data_size, key);
SignatureCopy(&h->preamble_signature, sig); SignatureCopy(&h->preamble_signature, sig);
free(sig); free(sig);
} }
static void VerifyFirmwarePreambleTest(const VbPublicKey *public_key,
static void VerifyFirmwarePreambleTest(const VbPublicKey* public_key, const VbPrivateKey *private_key,
const VbPrivateKey* private_key, const VbPublicKey *kernel_subkey)
const VbPublicKey* kernel_subkey) { {
VbFirmwarePreambleHeader *hdr;
VbFirmwarePreambleHeader* hdr; VbFirmwarePreambleHeader *h;
VbFirmwarePreambleHeader* h; RSAPublicKey *rsa;
RSAPublicKey* rsa;
unsigned hsize; unsigned hsize;
/* Create a dummy signature */ /* Create a dummy signature */
VbSignature* body_sig = SignatureAlloc(56, 78); VbSignature* body_sig = SignatureAlloc(56, 78);
rsa = PublicKeyToRSA(public_key); rsa = PublicKeyToRSA(public_key);
hdr = CreateFirmwarePreamble(0x1234, kernel_subkey, body_sig, private_key, hdr = CreateFirmwarePreamble(0x1234, kernel_subkey, body_sig,
0x5678); private_key, 0x5678);
TEST_NEQ(hdr && rsa, 0, "VerifyFirmwarePreamble() prerequisites"); TEST_NEQ(hdr && rsa, 0, "VerifyFirmwarePreamble() prerequisites");
if (!hdr) if (!hdr)
return; return;
hsize = (unsigned) hdr->preamble_size; hsize = (unsigned) hdr->preamble_size;
h = (VbFirmwarePreambleHeader*)malloc(hsize + 16384); h = (VbFirmwarePreambleHeader *)malloc(hsize + 16384);
TEST_EQ(VerifyFirmwarePreamble(hdr, hsize, rsa), 0, TEST_EQ(VerifyFirmwarePreamble(hdr, hsize, rsa), 0,
"VerifyFirmwarePreamble() ok using key"); "VerifyFirmwarePreamble() ok using key");
@@ -271,12 +277,12 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm,
const char *keys_dir) const char *keys_dir)
{ {
char filename[1024]; char filename[1024];
int signing_rsa_len = siglen_map[signing_key_algorithm] * 8;; int signing_rsa_len = siglen_map[signing_key_algorithm] * 8;
int data_rsa_len = siglen_map[data_key_algorithm] * 8;; int data_rsa_len = siglen_map[data_key_algorithm] * 8;
VbPrivateKey* signing_private_key = NULL; VbPrivateKey *signing_private_key = NULL;
VbPublicKey* signing_public_key = NULL; VbPublicKey *signing_public_key = NULL;
VbPublicKey* data_public_key = NULL; VbPublicKey *data_public_key = NULL;
printf("***Testing signing algorithm: %s\n", printf("***Testing signing algorithm: %s\n",
algo_strings[signing_key_algorithm]); algo_strings[signing_key_algorithm]);
@@ -339,7 +345,7 @@ struct test_perm
*/ */
const struct test_perm test_perms[] = {{7, 4}, {11, 4}, {11, 7}}; const struct test_perm test_perms[] = {{7, 4}, {11, 4}, {11, 7}};
int main(int argc, char* argv[]) int main(int argc, char *argv[])
{ {
if (argc == 2) { if (argc == 2) {
/* Test only the algorithms we use */ /* Test only the algorithms we use */