Get rid of some crufty macros.

These were macros that were never used, or that were only set to one thing and
could be substituted up front.

I left in code guarded by the HAVE_ENDIAN_H and HAVE_LITTLE_ENDIAN macros even
though those are never defined because they guard a reportedly significantly
faster implementation of some functionality, at least according to a comment
in the source. It would be a good idea to enable that code path and see if it
really does make a big difference before removing it entirely.

BUG=None
TEST=Built for Link, Daisy, and the host with FEATURES=test. Built depthcharge
for Link and booted in normal mode.
BRANCH=None

Change-Id: I934a4dd0da169ac018ba07350d56924ab88b1acc
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: https://gerrit.chromium.org/gerrit/45687
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
This commit is contained in:
Gabe Black
2013-03-16 04:03:40 -07:00
committed by ChromeBot
parent 77f55ca1cd
commit ac8805e7e9
43 changed files with 57 additions and 199 deletions

View File

@@ -12,8 +12,6 @@
#include "sysincludes.h"
__pragma(pack(push,1)) /* Support packing for MSVC. */
#define GPT_HEADER_SIGNATURE "EFI PART"
#define GPT_HEADER_SIGNATURE2 "CHROMEOS"
#define GPT_HEADER_SIGNATURE_SIZE sizeof(GPT_HEADER_SIGNATURE)
@@ -114,6 +112,4 @@ typedef struct {
#define GPTENTRY_EXPECTED_SIZE 128
__pragma(pack(pop)) /* Support packing for MSVC. */
#endif /* VBOOT_REFERENCE_CGPTLIB_GPT_H_ */

View File

@@ -39,14 +39,14 @@ static void montMulAdd(const RSAPublicKey *key,
uint32_t* c,
const uint32_t a,
const uint32_t* b) {
uint64_t A = UINT64_MULT32(a, b[0]) + c[0];
uint64_t A = (uint64_t)a * b[0] + c[0];
uint32_t d0 = (uint32_t)A * key->n0inv;
uint64_t B = UINT64_MULT32(d0, key->n[0]) + (uint32_t)A;
uint64_t B = (uint64_t)d0 * key->n[0] + (uint32_t)A;
uint32_t i;
for (i = 1; i < key->len; ++i) {
A = (A >> 32) + UINT64_MULT32(a, b[i]) + c[i];
B = (B >> 32) + UINT64_MULT32(d0, key->n[i]) + (uint32_t)A;
A = (A >> 32) + (uint64_t)a * b[i] + c[i];
B = (B >> 32) + (uint64_t)d0 * key->n[i] + (uint32_t)A;
c[i - 1] = (uint32_t)B;
}

View File

@@ -247,7 +247,7 @@ uint8_t* SHA1_final(SHA1_CTX *ctx) {
SHA1_update(ctx, (uint8_t*)"\0", 1);
}
for (i = 0; i < 8; ++i) {
uint8_t tmp = (uint8_t)UINT64_RSHIFT(cnt, (7 - i) * 8);
uint8_t tmp = (uint8_t)((uint64_t)cnt >> ((7 - i) * 8));
SHA1_update(ctx, &tmp, 1);
}

View File

@@ -57,16 +57,16 @@
*((str) + 0) = (uint8_t) ((x) >> 24); \
}
#define UNPACK64(x, str) \
{ \
*((str) + 7) = (uint8_t) x; \
*((str) + 6) = (uint8_t) UINT64_RSHIFT(x, 8); \
*((str) + 5) = (uint8_t) UINT64_RSHIFT(x, 16); \
*((str) + 4) = (uint8_t) UINT64_RSHIFT(x, 24); \
*((str) + 3) = (uint8_t) UINT64_RSHIFT(x, 32); \
*((str) + 2) = (uint8_t) UINT64_RSHIFT(x, 40); \
*((str) + 1) = (uint8_t) UINT64_RSHIFT(x, 48); \
*((str) + 0) = (uint8_t) UINT64_RSHIFT(x, 56); \
#define UNPACK64(x, str) \
{ \
*((str) + 7) = (uint8_t) x; \
*((str) + 6) = (uint8_t) ((uint64_t)x >> 8); \
*((str) + 5) = (uint8_t) ((uint64_t)x >> 16); \
*((str) + 4) = (uint8_t) ((uint64_t)x >> 24); \
*((str) + 3) = (uint8_t) ((uint64_t)x >> 32); \
*((str) + 2) = (uint8_t) ((uint64_t)x >> 40); \
*((str) + 1) = (uint8_t) ((uint64_t)x >> 48); \
*((str) + 0) = (uint8_t) ((uint64_t)x >> 56); \
}
#define PACK64(str, x) \

View File

@@ -39,8 +39,6 @@
#include "bmpblk_header.h"
__pragma(pack(push, 1)) /* Support packing for MSVC. */
#define FONT_SIGNATURE "FONT"
#define FONT_SIGNATURE_SIZE 4
@@ -62,6 +60,4 @@ typedef struct FontArrayEntryHeader {
*/
} __attribute__((packed)) FontArrayEntryHeader;
__pragma(pack(pop)) /* Support packing for MSVC. */
#endif /* VBOOT_REFERENCE_BMPBLK_FONT_H_ */

View File

@@ -18,8 +18,6 @@
/* Structure definitions for TPM spaces */
__pragma(pack(push, 1)) /* Support packing for MSVC. */
/* Kernel space - KERNEL_NV_INDEX, locked with physical presence. */
#define ROLLBACK_SPACE_KERNEL_VERSION 2
#define ROLLBACK_SPACE_KERNEL_UID 0x4752574C /* 'GRWL' */
@@ -68,8 +66,6 @@ typedef struct RollbackSpaceFirmware {
uint8_t crc8;
} __attribute__((packed)) RollbackSpaceFirmware;
__pragma(pack(pop)) /* Support packing for MSVC. */
/* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */
/*

View File

@@ -38,9 +38,6 @@ uint32_t WriteSpaceKernel(RollbackSpaceKernel *rsk);
static int g_rollback_recovery_mode = 0;
/* disable MSVC warning on const logical expression (as in } while(0);) */
__pragma(warning (disable: 4127))
#define RETURN_ON_FAILURE(tpm_command) do { \
uint32_t result_; \
if ((result_ = (tpm_command)) != TPM_SUCCESS) { \
@@ -484,9 +481,6 @@ uint32_t SetupTPM(int recovery_mode, int developer_mode,
return TPM_SUCCESS;
}
/* Disable MSVC warnings on unused arguments */
__pragma(warning (disable: 4100))
#ifdef DISABLE_ROLLBACK_TPM
/* Dummy implementations which don't support TPM rollback protection */

View File

@@ -22,8 +22,8 @@
* command buffer. FromTpmTYPE gets a value of type TYPE from a TPM command
* buffer into a variable.
*/
POSSIBLY_UNUSED
static INLINE void ToTpmUint32(uint8_t *buffer, uint32_t x) {
__attribute__((unused))
static inline void ToTpmUint32(uint8_t *buffer, uint32_t x) {
buffer[0] = (uint8_t)(x >> 24);
buffer[1] = (uint8_t)((x >> 16) & 0xff);
buffer[2] = (uint8_t)((x >> 8) & 0xff);
@@ -33,8 +33,8 @@ static INLINE void ToTpmUint32(uint8_t *buffer, uint32_t x) {
/*
* See comment for above function.
*/
POSSIBLY_UNUSED
static INLINE void FromTpmUint32(const uint8_t *buffer, uint32_t *x) {
__attribute__((unused))
static inline void FromTpmUint32(const uint8_t *buffer, uint32_t *x) {
*x = ((buffer[0] << 24) |
(buffer[1] << 16) |
(buffer[2] << 8) |
@@ -44,8 +44,8 @@ static INLINE void FromTpmUint32(const uint8_t *buffer, uint32_t *x) {
/*
* See comment for above function.
*/
POSSIBLY_UNUSED
static INLINE void ToTpmUint16(uint8_t *buffer, uint16_t x) {
__attribute__((unused))
static inline void ToTpmUint16(uint8_t *buffer, uint16_t x) {
buffer[0] = (uint8_t)(x >> 8);
buffer[1] = (uint8_t)(x & 0xff);
}
@@ -53,8 +53,8 @@ static INLINE void ToTpmUint16(uint8_t *buffer, uint16_t x) {
/*
* See comment for above function.
*/
POSSIBLY_UNUSED
static INLINE void FromTpmUint16(const uint8_t *buffer, uint16_t *x) {
__attribute__((unused))
static inline void FromTpmUint16(const uint8_t *buffer, uint16_t *x) {
*x = (buffer[0] << 8) | buffer[1];
}

View File

@@ -27,12 +27,13 @@
#endif
/* Sets the size field of a TPM command. */
static INLINE void SetTpmCommandSize(uint8_t* buffer, uint32_t size) {
static inline void SetTpmCommandSize(uint8_t* buffer, uint32_t size) {
ToTpmUint32(buffer + sizeof(uint16_t), size);
}
/* Gets the size field of a TPM command. */
POSSIBLY_UNUSED static INLINE int TpmCommandSize(const uint8_t* buffer) {
__attribute__((unused))
static inline int TpmCommandSize(const uint8_t* buffer) {
uint32_t size;
FromTpmUint32(buffer + sizeof(uint16_t), &size);
return (int) size;
@@ -44,14 +45,14 @@ int TlclPacketSize(const uint8_t* packet) {
}
/* Gets the code field of a TPM command. */
static INLINE int TpmCommandCode(const uint8_t* buffer) {
static inline int TpmCommandCode(const uint8_t* buffer) {
uint32_t code;
FromTpmUint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &code);
return code;
}
/* Gets the return code field of a TPM result. */
static INLINE int TpmReturnCode(const uint8_t* buffer) {
static inline int TpmReturnCode(const uint8_t* buffer) {
return TpmCommandCode(buffer);
}

View File

@@ -62,10 +62,8 @@ VbError_t VbSelectFirmware(VbCommonParams *cparams,
/* Update TPM if necessary */
if (shared->fw_version_tpm_start < shared->fw_version_tpm) {
VBPERFSTART("VB_TPMU");
tpm_status =
RollbackFirmwareWrite(shared->fw_version_tpm);
VBPERFEND("VB_TPMU");
if (0 != tpm_status) {
VBDEBUG(("Can't write FW version to TPM.\n"));
VbNvSet(&vnc, VBNV_RECOVERY_REQUEST,
@@ -76,9 +74,7 @@ VbError_t VbSelectFirmware(VbCommonParams *cparams,
}
/* Lock firmware versions in TPM */
VBPERFSTART("VB_TPML");
tpm_status = RollbackFirmwareLock();
VBPERFEND("VB_TPML");
if (0 != tpm_status) {
VBDEBUG(("Unable to lock firmware version in TPM.\n"));
VbNvSet(&vnc, VBNV_RECOVERY_REQUEST,

View File

@@ -167,7 +167,6 @@ VbError_t VbInit(VbCommonParams *cparams, VbInitParams *iparams)
VbNvGet(&vnc, VBNV_CLEAR_TPM_OWNER_REQUEST,
&clear_tpm_owner_request);
VBPERFSTART("VB_TPMI");
/*
* Initialize the TPM. If the developer mode state has changed
* since the last boot, we need to clear TPM ownership. If the
@@ -179,7 +178,6 @@ VbError_t VbInit(VbCommonParams *cparams, VbInitParams *iparams)
clear_tpm_owner_request,
/* two outputs on success */
&is_virt_dev, &tpm_version);
VBPERFEND("VB_TPMI");
if (0 != tpm_status) {
VBDEBUG(("Unable to setup TPM and read "

View File

@@ -130,15 +130,12 @@ int LoadFirmware(VbCommonParams *cparams, VbSelectFirmwareParams *fparams,
}
/* Verify the key block */
VBPERFSTART("VB_VKB");
if ((0 != KeyBlockVerify(key_block, vblock_size,
root_key, 0))) {
VBDEBUG(("Key block verification failed.\n"));
*check_result = VBSD_LF_CHECK_VERIFY_KEYBLOCK;
VBPERFEND("VB_VKB");
continue;
}
VBPERFEND("VB_VKB");
/* Check for rollback of key version. */
key_version = key_block->data_key.key_version;
@@ -169,7 +166,6 @@ int LoadFirmware(VbCommonParams *cparams, VbSelectFirmwareParams *fparams,
}
/* Verify the preamble, which follows the key block. */
VBPERFSTART("VB_VPB");
preamble = (VbFirmwarePreambleHeader *)
((uint8_t *)key_block + key_block->key_block_size);
if ((0 != VerifyFirmwarePreamble(
@@ -179,10 +175,8 @@ int LoadFirmware(VbCommonParams *cparams, VbSelectFirmwareParams *fparams,
VBDEBUG(("Preamble verfication failed.\n"));
*check_result = VBSD_LF_CHECK_VERIFY_PREAMBLE;
RSAPublicKeyFree(data_key);
VBPERFEND("VB_VPB");
continue;
}
VBPERFEND("VB_VPB");
/* Check for rollback of firmware version. */
combined_version = (uint32_t)((key_version << 16) |
@@ -230,7 +224,6 @@ int LoadFirmware(VbCommonParams *cparams, VbSelectFirmwareParams *fparams,
VbError_t rv;
/* Read the firmware data */
VBPERFSTART("VB_RFD");
DigestInit(&lfi->body_digest_context,
data_key->algorithm);
lfi->body_size_accum = 0;
@@ -243,7 +236,6 @@ int LoadFirmware(VbCommonParams *cparams, VbSelectFirmwareParams *fparams,
"index %d\n", index));
*check_result = VBSD_LF_CHECK_GET_FW_BODY;
RSAPublicKeyFree(data_key);
VBPERFEND("VB_RFD");
continue;
}
if (lfi->body_size_accum !=
@@ -253,13 +245,10 @@ int LoadFirmware(VbCommonParams *cparams, VbSelectFirmwareParams *fparams,
(int)preamble->body_signature.data_size));
*check_result = VBSD_LF_CHECK_HASH_WRONG_SIZE;
RSAPublicKeyFree(data_key);
VBPERFEND("VB_RFD");
continue;
}
VBPERFEND("VB_RFD");
/* Verify firmware data */
VBPERFSTART("VB_VFD");
body_digest = DigestFinal(&lfi->body_digest_context);
if (0 != VerifyDigest(body_digest,
&preamble->body_signature,
@@ -268,11 +257,9 @@ int LoadFirmware(VbCommonParams *cparams, VbSelectFirmwareParams *fparams,
*check_result = VBSD_LF_CHECK_VERIFY_BODY;
RSAPublicKeyFree(data_key);
VbExFree(body_digest);
VBPERFEND("VB_VFD");
continue;
}
VbExFree(body_digest);
VBPERFEND("VB_VFD");
}
/* Done with the data key, so can free it now */

View File

@@ -140,9 +140,6 @@ int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
return 0;
}
/* disable MSVC warning on const logical expression (as in } while(0);) */
__pragma(warning(disable: 4127))
VbError_t LoadKernel(LoadKernelParams *params)
{
VbSharedDataHeader *shared =
@@ -486,16 +483,13 @@ VbError_t LoadKernel(LoadKernelParams *params)
}
/* Read the kernel data */
VBPERFSTART("VB_RKD");
if (0 != VbExDiskRead(params->disk_handle,
part_start + body_offset_sectors,
body_sectors, params->kernel_buffer)) {
VBDEBUG(("Unable to read kernel data.\n"));
VBPERFEND("VB_RKD");
shpart->check_result = VBSD_LKP_CHECK_READ_DATA;
goto bad_kernel;
}
VBPERFEND("VB_RKD");
/* Verify kernel data */
if (0 != VerifyData((const uint8_t *)params->kernel_buffer,