mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 02:05:01 +00:00
Port vboot_reference to use new wrapper API utility functions
Third time's the charm. Now that we've moved to u-boot-next, this won't break the ARM build. BUG=chromium-os:17006 TEST=make && make runtests; emerge vboot_reference; emerge-tegra2_seaboard chromeos-bootimage Change-Id: Ib4fa26c7a23868dd2ffd2b321ee8dc08c66ea322 Original-Change-Id: I771085dcdf79d9592de64f35e3b758111a80dd9f Original-Reviewed-on: http://gerrit.chromium.org/gerrit/3263 Original-Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-on: http://gerrit.chromium.org/gerrit/3803 Tested-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
/* Debug and error output */
|
/* Debug and error output */
|
||||||
#ifdef VBOOT_DEBUG
|
#ifdef VBOOT_DEBUG
|
||||||
#define VBDEBUG(params) debug params
|
#define VBDEBUG(params) VbExDebug params
|
||||||
#else
|
#else
|
||||||
#define VBDEBUG(params)
|
#define VBDEBUG(params)
|
||||||
#endif
|
#endif
|
||||||
@@ -35,15 +35,9 @@
|
|||||||
#define VBPERFEND(name)
|
#define VBPERFEND(name)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Outputs an error message and quits. */
|
|
||||||
void error(const char* format, ...);
|
|
||||||
|
|
||||||
/* Outputs debug/warning messages. */
|
|
||||||
void debug(const char* format, ...);
|
|
||||||
|
|
||||||
#ifdef VBOOT_DEBUG
|
#ifdef VBOOT_DEBUG
|
||||||
#define VbAssert(expr) do { if (!(expr)) { \
|
#define VbAssert(expr) do { if (!(expr)) { \
|
||||||
error("assert fail: %s at %s:%d\n", \
|
VbExError("assert fail: %s at %s:%d\n", \
|
||||||
#expr, __FILE__, __LINE__); }} while(0)
|
#expr, __FILE__, __LINE__); }} while(0)
|
||||||
#else
|
#else
|
||||||
#define VbAssert(expr)
|
#define VbAssert(expr)
|
||||||
@@ -57,14 +51,6 @@ void debug(const char* format, ...);
|
|||||||
/* Return the minimum of (a) or (b). */
|
/* Return the minimum of (a) or (b). */
|
||||||
#define Min(a, b) (((a) < (b)) ? (a) : (b))
|
#define Min(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
|
|
||||||
/* Allocate [size] bytes and return a pointer to the allocated memory. Abort
|
|
||||||
* on error.
|
|
||||||
*/
|
|
||||||
void* Malloc(size_t size);
|
|
||||||
|
|
||||||
/* Free memory pointed by [ptr] previously allocated by Malloc(). */
|
|
||||||
void Free(void* ptr);
|
|
||||||
|
|
||||||
/* Compare [n] bytes in [src1] and [src2]
|
/* Compare [n] bytes in [src1] and [src2]
|
||||||
* Returns an integer less than, equal to, or greater than zero if the first [n]
|
* Returns an integer less than, equal to, or greater than zero if the first [n]
|
||||||
* bytes of [src1] is found, respectively, to be less than, to match, or be
|
* bytes of [src1] is found, respectively, to be less than, to match, or be
|
||||||
@@ -114,18 +100,4 @@ uint32_t Strncat(char *dest, const char *src, uint32_t destlen);
|
|||||||
#define memset _do_not_use_standard_memset
|
#define memset _do_not_use_standard_memset
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Read a high-resolution timer. */
|
|
||||||
uint64_t VbGetTimer(void);
|
|
||||||
|
|
||||||
/* Return the maximum frequency for the high-resolution timer, in Hz.
|
|
||||||
*
|
|
||||||
* Note that this call MUST be fast; the implementation must not
|
|
||||||
* attempt to actually measure the frequency. This function need only
|
|
||||||
* return an upper bound for the timer frequency, so that minimum
|
|
||||||
* delays can be established. For example, if the same BIOS can run
|
|
||||||
* on CPUs where the timer frequency varies between 1.2GHz and 1.8GHz,
|
|
||||||
* return 1800000000 (or even 2000000000). */
|
|
||||||
uint64_t VbGetTimerMaxFreq(void);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* VBOOT_REFERENCE_UTILITY_H_ */
|
#endif /* VBOOT_REFERENCE_UTILITY_H_ */
|
||||||
|
|||||||
@@ -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
|
* 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,7 @@
|
|||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
#include "gpt.h"
|
#include "gpt.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
|
|
||||||
int GptInit(GptData *gpt) {
|
int GptInit(GptData *gpt) {
|
||||||
int retval;
|
int retval;
|
||||||
|
|||||||
@@ -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
|
* 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.
|
||||||
*/
|
*/
|
||||||
@@ -107,7 +107,7 @@ typedef struct DigestContext {
|
|||||||
|
|
||||||
/* Initialize a digest context for use with signature algorithm [algorithm]. */
|
/* Initialize a digest context for use with signature algorithm [algorithm]. */
|
||||||
void DigestInit(DigestContext* ctx, int sig_algorithm);
|
void DigestInit(DigestContext* ctx, int sig_algorithm);
|
||||||
void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint64_t len);
|
void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint32_t len);
|
||||||
|
|
||||||
/* Caller owns the returned digest and must free it. */
|
/* Caller owns the returned digest and must free it. */
|
||||||
uint8_t* DigestFinal(DigestContext* ctx);
|
uint8_t* DigestFinal(DigestContext* ctx);
|
||||||
|
|||||||
@@ -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
|
* 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.
|
||||||
*/
|
*/
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cryptolib.h"
|
#include "cryptolib.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
|
||||||
/* a[] -= mod */
|
/* a[] -= mod */
|
||||||
@@ -77,9 +78,9 @@ static void montMul(const RSAPublicKey *key,
|
|||||||
*/
|
*/
|
||||||
static void modpowF4(const RSAPublicKey *key,
|
static void modpowF4(const RSAPublicKey *key,
|
||||||
uint8_t* inout) {
|
uint8_t* inout) {
|
||||||
uint32_t* a = (uint32_t*) Malloc(key->len * sizeof(uint32_t));
|
uint32_t* a = (uint32_t*) VbExMalloc(key->len * sizeof(uint32_t));
|
||||||
uint32_t* aR = (uint32_t*) Malloc(key->len * sizeof(uint32_t));
|
uint32_t* aR = (uint32_t*) VbExMalloc(key->len * sizeof(uint32_t));
|
||||||
uint32_t* aaR = (uint32_t*) Malloc(key->len * sizeof(uint32_t));
|
uint32_t* aaR = (uint32_t*) VbExMalloc(key->len * sizeof(uint32_t));
|
||||||
|
|
||||||
uint32_t* aaa = aaR; /* Re-use location. */
|
uint32_t* aaa = aaR; /* Re-use location. */
|
||||||
int i;
|
int i;
|
||||||
@@ -116,9 +117,9 @@ static void modpowF4(const RSAPublicKey *key,
|
|||||||
*inout++ = (uint8_t)(tmp >> 0);
|
*inout++ = (uint8_t)(tmp >> 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Free(a);
|
VbExFree(a);
|
||||||
Free(aR);
|
VbExFree(aR);
|
||||||
Free(aaR);
|
VbExFree(aaR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify a RSA PKCS1.5 signature against an expected hash.
|
/* Verify a RSA PKCS1.5 signature against an expected hash.
|
||||||
@@ -152,7 +153,7 @@ int RSAVerify(const RSAPublicKey *key,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = (uint8_t*) Malloc(sig_len);
|
buf = (uint8_t*) VbExMalloc(sig_len);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return 0;
|
return 0;
|
||||||
Memcpy(buf, sig, sig_len);
|
Memcpy(buf, sig, sig_len);
|
||||||
@@ -177,7 +178,7 @@ int RSAVerify(const RSAPublicKey *key,
|
|||||||
VBDEBUG(("In RSAVerify(): Hash check failed!\n"));
|
VBDEBUG(("In RSAVerify(): Hash check failed!\n"));
|
||||||
success = 0;
|
success = 0;
|
||||||
}
|
}
|
||||||
Free(buf);
|
VbExFree(buf);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
* 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,9 +8,10 @@
|
|||||||
#include "cryptolib.h"
|
#include "cryptolib.h"
|
||||||
#include "stateful_util.h"
|
#include "stateful_util.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
|
|
||||||
uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size) {
|
uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size) {
|
||||||
uint64_t key_len; /* Key length in bytes. */
|
int key_len; /* Key length in bytes. (int type matches siglen_map) */
|
||||||
if (algorithm < kNumAlgorithms) {
|
if (algorithm < kNumAlgorithms) {
|
||||||
key_len = siglen_map[algorithm];
|
key_len = siglen_map[algorithm];
|
||||||
/* Total size needed by a RSAPublicKey structure is =
|
/* Total size needed by a RSAPublicKey structure is =
|
||||||
@@ -24,7 +25,7 @@ uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RSAPublicKey* RSAPublicKeyNew(void) {
|
RSAPublicKey* RSAPublicKeyNew(void) {
|
||||||
RSAPublicKey* key = (RSAPublicKey*) Malloc(sizeof(RSAPublicKey));
|
RSAPublicKey* key = (RSAPublicKey*) VbExMalloc(sizeof(RSAPublicKey));
|
||||||
key->n = NULL;
|
key->n = NULL;
|
||||||
key->rr = NULL;
|
key->rr = NULL;
|
||||||
return key;
|
return key;
|
||||||
@@ -32,9 +33,9 @@ RSAPublicKey* RSAPublicKeyNew(void) {
|
|||||||
|
|
||||||
void RSAPublicKeyFree(RSAPublicKey* key) {
|
void RSAPublicKeyFree(RSAPublicKey* key) {
|
||||||
if (key) {
|
if (key) {
|
||||||
Free(key->n);
|
VbExFree(key->n);
|
||||||
Free(key->rr);
|
VbExFree(key->rr);
|
||||||
Free(key);
|
VbExFree(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,8 +60,8 @@ RSAPublicKey* RSAPublicKeyFromBuf(const uint8_t* buf, uint64_t len) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
key->n = (uint32_t*) Malloc(key_len);
|
key->n = (uint32_t*) VbExMalloc(key_len);
|
||||||
key->rr = (uint32_t*) Malloc(key_len);
|
key->rr = (uint32_t*) VbExMalloc(key_len);
|
||||||
|
|
||||||
StatefulMemcpy(&st, &key->n0inv, sizeof(key->n0inv));
|
StatefulMemcpy(&st, &key->n0inv, sizeof(key->n0inv));
|
||||||
StatefulMemcpy(&st, key->n, key_len);
|
StatefulMemcpy(&st, key->n, key_len);
|
||||||
@@ -106,7 +107,7 @@ int RSAVerifyBinary_f(const uint8_t* key_blob,
|
|||||||
success = RSAVerify(verification_key, sig, (uint32_t)sig_size,
|
success = RSAVerify(verification_key, sig, (uint32_t)sig_size,
|
||||||
(uint8_t)algorithm, digest);
|
(uint8_t)algorithm, digest);
|
||||||
|
|
||||||
Free(digest);
|
VbExFree(digest);
|
||||||
if (!key)
|
if (!key)
|
||||||
RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */
|
RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */
|
||||||
return success;
|
return success;
|
||||||
|
|||||||
@@ -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
|
* 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.
|
||||||
*
|
*
|
||||||
@@ -7,26 +7,27 @@
|
|||||||
|
|
||||||
#include "cryptolib.h"
|
#include "cryptolib.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
|
|
||||||
void DigestInit(DigestContext* ctx, int sig_algorithm) {
|
void DigestInit(DigestContext* ctx, int sig_algorithm) {
|
||||||
ctx->algorithm = hash_type_map[sig_algorithm];
|
ctx->algorithm = hash_type_map[sig_algorithm];
|
||||||
switch(ctx->algorithm) {
|
switch(ctx->algorithm) {
|
||||||
case SHA1_DIGEST_ALGORITHM:
|
case SHA1_DIGEST_ALGORITHM:
|
||||||
ctx->sha1_ctx = (SHA1_CTX*) Malloc(sizeof(SHA1_CTX));
|
ctx->sha1_ctx = (SHA1_CTX*) VbExMalloc(sizeof(SHA1_CTX));
|
||||||
SHA1_init(ctx->sha1_ctx);
|
SHA1_init(ctx->sha1_ctx);
|
||||||
break;
|
break;
|
||||||
case SHA256_DIGEST_ALGORITHM:
|
case SHA256_DIGEST_ALGORITHM:
|
||||||
ctx->sha256_ctx = (SHA256_CTX*) Malloc(sizeof(SHA256_CTX));
|
ctx->sha256_ctx = (SHA256_CTX*) VbExMalloc(sizeof(SHA256_CTX));
|
||||||
SHA256_init(ctx->sha256_ctx);
|
SHA256_init(ctx->sha256_ctx);
|
||||||
break;
|
break;
|
||||||
case SHA512_DIGEST_ALGORITHM:
|
case SHA512_DIGEST_ALGORITHM:
|
||||||
ctx->sha512_ctx = (SHA512_CTX*) Malloc(sizeof(SHA512_CTX));
|
ctx->sha512_ctx = (SHA512_CTX*) VbExMalloc(sizeof(SHA512_CTX));
|
||||||
SHA512_init(ctx->sha512_ctx);
|
SHA512_init(ctx->sha512_ctx);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint64_t len) {
|
void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint32_t len) {
|
||||||
switch(ctx->algorithm) {
|
switch(ctx->algorithm) {
|
||||||
case SHA1_DIGEST_ALGORITHM:
|
case SHA1_DIGEST_ALGORITHM:
|
||||||
SHA1_update(ctx->sha1_ctx, data, len);
|
SHA1_update(ctx->sha1_ctx, data, len);
|
||||||
@@ -44,26 +45,27 @@ uint8_t* DigestFinal(DigestContext* ctx) {
|
|||||||
uint8_t* digest = NULL;
|
uint8_t* digest = NULL;
|
||||||
switch(ctx->algorithm) {
|
switch(ctx->algorithm) {
|
||||||
case SHA1_DIGEST_ALGORITHM:
|
case SHA1_DIGEST_ALGORITHM:
|
||||||
digest = (uint8_t*) Malloc(SHA1_DIGEST_SIZE);
|
digest = (uint8_t*) VbExMalloc(SHA1_DIGEST_SIZE);
|
||||||
Memcpy(digest, SHA1_final(ctx->sha1_ctx), SHA1_DIGEST_SIZE);
|
Memcpy(digest, SHA1_final(ctx->sha1_ctx), SHA1_DIGEST_SIZE);
|
||||||
Free(ctx->sha1_ctx);
|
VbExFree(ctx->sha1_ctx);
|
||||||
break;
|
break;
|
||||||
case SHA256_DIGEST_ALGORITHM:
|
case SHA256_DIGEST_ALGORITHM:
|
||||||
digest = (uint8_t*) Malloc(SHA256_DIGEST_SIZE);
|
digest = (uint8_t*) VbExMalloc(SHA256_DIGEST_SIZE);
|
||||||
Memcpy(digest, SHA256_final(ctx->sha256_ctx), SHA256_DIGEST_SIZE);
|
Memcpy(digest, SHA256_final(ctx->sha256_ctx), SHA256_DIGEST_SIZE);
|
||||||
Free(ctx->sha256_ctx);
|
VbExFree(ctx->sha256_ctx);
|
||||||
break;
|
break;
|
||||||
case SHA512_DIGEST_ALGORITHM:
|
case SHA512_DIGEST_ALGORITHM:
|
||||||
digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE);
|
digest = (uint8_t*) VbExMalloc(SHA512_DIGEST_SIZE);
|
||||||
Memcpy(digest, SHA512_final(ctx->sha512_ctx), SHA512_DIGEST_SIZE);
|
Memcpy(digest, SHA512_final(ctx->sha512_ctx), SHA512_DIGEST_SIZE);
|
||||||
Free(ctx->sha512_ctx);
|
VbExFree(ctx->sha512_ctx);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
return digest;
|
return digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* DigestBuf(const uint8_t* buf, uint64_t len, int sig_algorithm) {
|
uint8_t* DigestBuf(const uint8_t* buf, uint64_t len, int sig_algorithm) {
|
||||||
uint8_t* digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE); /* Use the max. */
|
/* Allocate enough space for the largest digest */
|
||||||
|
uint8_t* digest = (uint8_t*) VbExMalloc(SHA512_DIGEST_SIZE);
|
||||||
/* Define an array mapping [sig_algorithm] to function pointers to the
|
/* Define an array mapping [sig_algorithm] to function pointers to the
|
||||||
* SHA{1|256|512} functions.
|
* SHA{1|256|512} functions.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#define VBOOT_REFERENCE_VBOOT_KERNEL_H_
|
#define VBOOT_REFERENCE_VBOOT_KERNEL_H_
|
||||||
|
|
||||||
#include "cgptlib.h"
|
#include "cgptlib.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
|
|
||||||
/* Allocates and reads GPT data from the drive. The sector_bytes and
|
/* Allocates and reads GPT data from the drive. The sector_bytes and
|
||||||
* drive_sectors fields should be filled on input. The primary and
|
* drive_sectors fields should be filled on input. The primary and
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "tpm_bootmode.h"
|
#include "tpm_bootmode.h"
|
||||||
#include "tss_constants.h"
|
#include "tss_constants.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
|
|
||||||
static int g_rollback_recovery_mode = 0;
|
static int g_rollback_recovery_mode = 0;
|
||||||
|
|
||||||
@@ -414,7 +415,7 @@ uint32_t RollbackFirmwareRead(uint32_t* version) {
|
|||||||
|
|
||||||
RETURN_ON_FAILURE(ReadSpaceFirmware(&rsf));
|
RETURN_ON_FAILURE(ReadSpaceFirmware(&rsf));
|
||||||
VBDEBUG(("TPM: RollbackFirmwareRead %x --> %x\n", (int)rsf.fw_versions,
|
VBDEBUG(("TPM: RollbackFirmwareRead %x --> %x\n", (int)rsf.fw_versions,
|
||||||
(int)version));
|
(int)*version));
|
||||||
*version = rsf.fw_versions;
|
*version = rsf.fw_versions;
|
||||||
VBDEBUG(("TPM: RollbackFirmwareRead %x\n", (int)rsf.fw_versions));
|
VBDEBUG(("TPM: RollbackFirmwareRead %x\n", (int)rsf.fw_versions));
|
||||||
return TPM_SUCCESS;
|
return TPM_SUCCESS;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
|
|
||||||
/* TPM PCR to use for storing boot mode measurements. */
|
/* TPM PCR to use for storing boot mode measurements. */
|
||||||
#define BOOT_MODE_PCR 0
|
#define BOOT_MODE_PCR 0
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "tlcl_internal.h"
|
#include "tlcl_internal.h"
|
||||||
#include "tlcl_structures.h"
|
#include "tlcl_structures.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
|
|
||||||
/* Sets the size field of a TPM command. */
|
/* 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) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "vboot_api.h"
|
||||||
#include "vboot_common.h"
|
#include "vboot_common.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
|
||||||
@@ -231,7 +232,7 @@ int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t 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);
|
||||||
Free(header_checksum);
|
VbExFree(header_checksum);
|
||||||
if (rv) {
|
if (rv) {
|
||||||
VBDEBUG(("Invalid key block hash.\n"));
|
VBDEBUG(("Invalid key block hash.\n"));
|
||||||
return VBOOT_KEY_BLOCK_HASH;
|
return VBOOT_KEY_BLOCK_HASH;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "rollback_index.h"
|
#include "rollback_index.h"
|
||||||
#include "tpm_bootmode.h"
|
#include "tpm_bootmode.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
#include "vboot_common.h"
|
#include "vboot_common.h"
|
||||||
#include "vboot_nvstorage.h"
|
#include "vboot_nvstorage.h"
|
||||||
|
|
||||||
@@ -77,7 +78,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
|
|||||||
recovery = VBNV_RECOVERY_RO_SHARED_DATA;
|
recovery = VBNV_RECOVERY_RO_SHARED_DATA;
|
||||||
goto LoadFirmwareExit;
|
goto LoadFirmwareExit;
|
||||||
}
|
}
|
||||||
shared->timer_load_firmware_enter = VbGetTimer();
|
shared->timer_load_firmware_enter = VbExGetTimer();
|
||||||
|
|
||||||
/* Handle test errors */
|
/* Handle test errors */
|
||||||
VbNvGet(vnc, VBNV_TEST_ERROR_FUNC, &test_err);
|
VbNvGet(vnc, VBNV_TEST_ERROR_FUNC, &test_err);
|
||||||
@@ -136,7 +137,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate our internal data */
|
/* Allocate our internal data */
|
||||||
lfi = (VbLoadFirmwareInternal*)Malloc(sizeof(VbLoadFirmwareInternal));
|
lfi = (VbLoadFirmwareInternal*)VbExMalloc(sizeof(VbLoadFirmwareInternal));
|
||||||
if (!lfi)
|
if (!lfi)
|
||||||
return LOAD_FIRMWARE_RECOVERY;
|
return LOAD_FIRMWARE_RECOVERY;
|
||||||
|
|
||||||
@@ -275,7 +276,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
|
|||||||
VBDEBUG(("Firmware body verification failed.\n"));
|
VBDEBUG(("Firmware body verification failed.\n"));
|
||||||
*check_result = VBSD_LF_CHECK_VERIFY_BODY;
|
*check_result = VBSD_LF_CHECK_VERIFY_BODY;
|
||||||
RSAPublicKeyFree(data_key);
|
RSAPublicKeyFree(data_key);
|
||||||
Free(body_digest);
|
VbExFree(body_digest);
|
||||||
VBPERFEND("VB_VFD");
|
VBPERFEND("VB_VFD");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -283,7 +284,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
|
|||||||
|
|
||||||
/* Done with the digest and data key, so can free them now */
|
/* Done with the digest and data key, so can free them now */
|
||||||
RSAPublicKeyFree(data_key);
|
RSAPublicKeyFree(data_key);
|
||||||
Free(body_digest);
|
VbExFree(body_digest);
|
||||||
|
|
||||||
/* If we're still here, the firmware is valid. */
|
/* If we're still here, the firmware is valid. */
|
||||||
VBDEBUG(("Firmware %d is valid.\n", index));
|
VBDEBUG(("Firmware %d is valid.\n", index));
|
||||||
@@ -327,7 +328,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Free internal data */
|
/* Free internal data */
|
||||||
Free(lfi);
|
VbExFree(lfi);
|
||||||
params->load_firmware_internal = NULL;
|
params->load_firmware_internal = NULL;
|
||||||
|
|
||||||
/* Handle finding good firmware */
|
/* Handle finding good firmware */
|
||||||
@@ -390,7 +391,7 @@ LoadFirmwareExit:
|
|||||||
recovery : VBNV_RECOVERY_NOT_REQUESTED);
|
recovery : VBNV_RECOVERY_NOT_REQUESTED);
|
||||||
VbNvTeardown(vnc);
|
VbNvTeardown(vnc);
|
||||||
|
|
||||||
shared->timer_load_firmware_exit = VbGetTimer();
|
shared->timer_load_firmware_exit = VbExGetTimer();
|
||||||
|
|
||||||
/* Note that we don't reduce params->shared_data_size to shared->data_used,
|
/* Note that we don't reduce params->shared_data_size to shared->data_used,
|
||||||
* since we want to leave space for LoadKernel() to add to the shared data
|
* since we want to leave space for LoadKernel() to add to the shared data
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
* (Firmware portion)
|
* (Firmware portion)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "vboot_kernel.h"
|
|
||||||
|
|
||||||
#include "boot_device.h"
|
#include "boot_device.h"
|
||||||
#include "cgptlib.h"
|
#include "cgptlib.h"
|
||||||
#include "cgptlib_internal.h"
|
#include "cgptlib_internal.h"
|
||||||
@@ -15,7 +13,10 @@
|
|||||||
#include "load_kernel_fw.h"
|
#include "load_kernel_fw.h"
|
||||||
#include "rollback_index.h"
|
#include "rollback_index.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
#include "vboot_common.h"
|
#include "vboot_common.h"
|
||||||
|
#include "vboot_kernel.h"
|
||||||
|
|
||||||
|
|
||||||
#define KBUF_SIZE 65536 /* Bytes to read at start of kernel partition */
|
#define KBUF_SIZE 65536 /* Bytes to read at start of kernel partition */
|
||||||
#define LOWEST_TPM_VERSION 0xffffffff
|
#define LOWEST_TPM_VERSION 0xffffffff
|
||||||
@@ -40,10 +41,10 @@ int AllocAndReadGptData(GptData* gptdata) {
|
|||||||
gptdata->modified = 0;
|
gptdata->modified = 0;
|
||||||
|
|
||||||
/* Allocate all buffers */
|
/* Allocate all buffers */
|
||||||
gptdata->primary_header = (uint8_t*)Malloc(gptdata->sector_bytes);
|
gptdata->primary_header = (uint8_t*)VbExMalloc(gptdata->sector_bytes);
|
||||||
gptdata->secondary_header = (uint8_t*)Malloc(gptdata->sector_bytes);
|
gptdata->secondary_header = (uint8_t*)VbExMalloc(gptdata->sector_bytes);
|
||||||
gptdata->primary_entries = (uint8_t*)Malloc(TOTAL_ENTRIES_SIZE);
|
gptdata->primary_entries = (uint8_t*)VbExMalloc(TOTAL_ENTRIES_SIZE);
|
||||||
gptdata->secondary_entries = (uint8_t*)Malloc(TOTAL_ENTRIES_SIZE);
|
gptdata->secondary_entries = (uint8_t*)VbExMalloc(TOTAL_ENTRIES_SIZE);
|
||||||
|
|
||||||
if (gptdata->primary_header == NULL || gptdata->secondary_header == NULL ||
|
if (gptdata->primary_header == NULL || gptdata->secondary_header == NULL ||
|
||||||
gptdata->primary_entries == NULL || gptdata->secondary_entries == NULL)
|
gptdata->primary_entries == NULL || gptdata->secondary_entries == NULL)
|
||||||
@@ -79,7 +80,7 @@ int WriteAndFreeGptData(GptData* gptdata) {
|
|||||||
if (0 != BootDeviceWriteLBA(1, 1, gptdata->primary_header))
|
if (0 != BootDeviceWriteLBA(1, 1, gptdata->primary_header))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
Free(gptdata->primary_header);
|
VbExFree(gptdata->primary_header);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gptdata->primary_entries) {
|
if (gptdata->primary_entries) {
|
||||||
@@ -89,7 +90,7 @@ int WriteAndFreeGptData(GptData* gptdata) {
|
|||||||
gptdata->primary_entries))
|
gptdata->primary_entries))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
Free(gptdata->primary_entries);
|
VbExFree(gptdata->primary_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gptdata->secondary_entries) {
|
if (gptdata->secondary_entries) {
|
||||||
@@ -99,7 +100,7 @@ int WriteAndFreeGptData(GptData* gptdata) {
|
|||||||
entries_sectors, gptdata->secondary_entries))
|
entries_sectors, gptdata->secondary_entries))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
Free(gptdata->secondary_entries);
|
VbExFree(gptdata->secondary_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gptdata->secondary_header) {
|
if (gptdata->secondary_header) {
|
||||||
@@ -109,7 +110,7 @@ int WriteAndFreeGptData(GptData* gptdata) {
|
|||||||
gptdata->secondary_header))
|
gptdata->secondary_header))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
Free(gptdata->secondary_header);
|
VbExFree(gptdata->secondary_header);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Success */
|
/* Success */
|
||||||
@@ -142,7 +143,7 @@ int LoadKernel(LoadKernelParams* params) {
|
|||||||
|
|
||||||
int retval = LOAD_KERNEL_RECOVERY;
|
int retval = LOAD_KERNEL_RECOVERY;
|
||||||
int recovery = VBNV_RECOVERY_RO_UNSPECIFIED;
|
int recovery = VBNV_RECOVERY_RO_UNSPECIFIED;
|
||||||
uint64_t timer_enter = VbGetTimer();
|
uint64_t timer_enter = VbExGetTimer();
|
||||||
|
|
||||||
/* Setup NV storage */
|
/* Setup NV storage */
|
||||||
VbNvSetup(vnc);
|
VbNvSetup(vnc);
|
||||||
@@ -300,7 +301,7 @@ int LoadKernel(LoadKernelParams* params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate kernel header buffers */
|
/* Allocate kernel header buffers */
|
||||||
kbuf = (uint8_t*)Malloc(KBUF_SIZE);
|
kbuf = (uint8_t*)VbExMalloc(KBUF_SIZE);
|
||||||
if (!kbuf)
|
if (!kbuf)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -585,7 +586,7 @@ int LoadKernel(LoadKernelParams* params) {
|
|||||||
|
|
||||||
/* Free kernel buffer */
|
/* Free kernel buffer */
|
||||||
if (kbuf)
|
if (kbuf)
|
||||||
Free(kbuf);
|
VbExFree(kbuf);
|
||||||
|
|
||||||
/* Write and free GPT data */
|
/* Write and free GPT data */
|
||||||
WriteAndFreeGptData(&gpt);
|
WriteAndFreeGptData(&gpt);
|
||||||
@@ -665,7 +666,7 @@ LoadKernelExit:
|
|||||||
|
|
||||||
/* Save timer values */
|
/* Save timer values */
|
||||||
shared->timer_load_kernel_enter = timer_enter;
|
shared->timer_load_kernel_enter = timer_enter;
|
||||||
shared->timer_load_kernel_exit = VbGetTimer();
|
shared->timer_load_kernel_exit = VbExGetTimer();
|
||||||
/* Store how much shared data we used, if any */
|
/* Store how much shared data we used, if any */
|
||||||
params->shared_data_size = shared->data_used;
|
params->shared_data_size = shared->data_used;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
* 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.
|
||||||
*
|
*
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "load_firmware_fw.h"
|
#include "load_firmware_fw.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
|
|
||||||
#define BOOT_FIRMWARE_A_CONTINUE 1
|
#define BOOT_FIRMWARE_A_CONTINUE 1
|
||||||
#define BOOT_FIRMWARE_B_CONTINUE 2
|
#define BOOT_FIRMWARE_B_CONTINUE 2
|
||||||
@@ -99,7 +100,7 @@ int VerifyFirmwareDriver_stub(uint8_t* gbb_data,
|
|||||||
p.nv_context = &vnc;
|
p.nv_context = &vnc;
|
||||||
|
|
||||||
/* Allocate a shared data buffer */
|
/* Allocate a shared data buffer */
|
||||||
p.shared_data_blob = Malloc(VB_SHARED_DATA_REC_SIZE);
|
p.shared_data_blob = VbExMalloc(VB_SHARED_DATA_REC_SIZE);
|
||||||
p.shared_data_size = VB_SHARED_DATA_REC_SIZE;
|
p.shared_data_size = VB_SHARED_DATA_REC_SIZE;
|
||||||
|
|
||||||
/* TODO: YOU NEED TO SET THE BOOT FLAGS SOMEHOW */
|
/* TODO: YOU NEED TO SET THE BOOT FLAGS SOMEHOW */
|
||||||
|
|||||||
@@ -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
|
* 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,6 +10,7 @@
|
|||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tlcl_internal.h"
|
#include "tlcl_internal.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "vboot_api.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -56,22 +57,22 @@ static void TpmExecute(const uint8_t *in, const uint32_t in_len,
|
|||||||
uint8_t *out, uint32_t *pout_len) {
|
uint8_t *out, uint32_t *pout_len) {
|
||||||
uint8_t response[TPM_MAX_COMMAND_SIZE];
|
uint8_t response[TPM_MAX_COMMAND_SIZE];
|
||||||
if (in_len <= 0) {
|
if (in_len <= 0) {
|
||||||
error("invalid command length %d for command 0x%x\n", in_len, in[9]);
|
VbExError("invalid command length %d for command 0x%x\n", in_len, in[9]);
|
||||||
} else if (tpm_fd < 0) {
|
} else if (tpm_fd < 0) {
|
||||||
error("the TPM device was not opened. Forgot to call TlclLibInit?\n");
|
VbExError("the TPM device was not opened. Forgot to call TlclLibInit?\n");
|
||||||
} else {
|
} else {
|
||||||
int n = write(tpm_fd, in, in_len);
|
int n = write(tpm_fd, in, in_len);
|
||||||
if (n != in_len) {
|
if (n != in_len) {
|
||||||
error("write failure to TPM device: %s\n", strerror(errno));
|
VbExError("write failure to TPM device: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
n = read(tpm_fd, response, sizeof(response));
|
n = read(tpm_fd, response, sizeof(response));
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
error("null read from TPM device\n");
|
VbExError("null read from TPM device\n");
|
||||||
} else if (n < 0) {
|
} else if (n < 0) {
|
||||||
error("read failure from TPM device: %s\n", strerror(errno));
|
VbExError("read failure from TPM device: %s\n", strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
if (n > *pout_len) {
|
if (n > *pout_len) {
|
||||||
error("TPM response too long for output buffer\n");
|
VbExError("TPM response too long for output buffer\n");
|
||||||
} else {
|
} else {
|
||||||
*pout_len = n;
|
*pout_len = n;
|
||||||
Memcpy(out, response, n);
|
Memcpy(out, response, n);
|
||||||
@@ -126,7 +127,8 @@ uint32_t TlclOpenDevice(void) {
|
|||||||
|
|
||||||
tpm_fd = open(device_path, O_RDWR);
|
tpm_fd = open(device_path, O_RDWR);
|
||||||
if (tpm_fd < 0) {
|
if (tpm_fd < 0) {
|
||||||
error("TPM: Cannot open TPM device %s: %s\n", device_path, strerror(errno));
|
VbExError("TPM: Cannot open TPM device %s: %s\n", device_path,
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -15,50 +15,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
void error(const char *format, ...) {
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, format);
|
|
||||||
fprintf(stderr, "ERROR: ");
|
|
||||||
vfprintf(stderr, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void debug(const char *format, ...) {
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, format);
|
|
||||||
fprintf(stderr, "DEBUG: ");
|
|
||||||
vfprintf(stderr, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* Malloc(size_t size) {
|
|
||||||
void* p = malloc(size);
|
|
||||||
if (!p) {
|
|
||||||
/* Fatal Error. We must abort. */
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Free(void* ptr) {
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Memcmp(const void* src1, const void* src2, size_t n) {
|
int Memcmp(const void* src1, const void* src2, size_t n) {
|
||||||
return memcmp(src1, src2, n);
|
return memcmp(src1, src2, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void* Memcpy(void* dest, const void* src, uint64_t n) {
|
void* Memcpy(void* dest, const void* src, uint64_t n) {
|
||||||
return memcpy(dest, src, (size_t)n);
|
return memcpy(dest, src, (size_t)n);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t VbGetTimer(void) {
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t VbGetTimerMaxFreq(void) {
|
|
||||||
return UINT64_C(1000000);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user