summaryrefslogtreecommitdiff
path: root/firmware/lib/cryptolib
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2011-07-01 15:35:43 -0700
committerRandall Spangler <rspangler@chromium.org>2011-07-01 15:36:42 -0700
commitcfd841d3c2c8bb91e7024c62d0acc8668c5041b3 (patch)
tree23707ff082b864894634860d19b85af9cf5fd51f /firmware/lib/cryptolib
parentf8c65491595a8e849cf61b600b2371357ec75ff4 (diff)
downloadvboot-cfd841d3c2c8bb91e7024c62d0acc8668c5041b3.tar.gz
Revert "Verified boot wrapper - replace utility functions"
This reverts commit 0184886c8cb35e8e01d610622df448a7cb063e06 (This works with uboot-next, but not uboot, which doesn't implement its half of the new wrapper API. So rolling back to leave uboot working. Change-Id: I1f9e3c63e5bbdb20b9195cd68787bef89f24afee Reviewed-on: http://gerrit.chromium.org/gerrit/3588 Reviewed-by: Randall Spangler <rspangler@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'firmware/lib/cryptolib')
-rw-r--r--firmware/lib/cryptolib/include/sha.h4
-rw-r--r--firmware/lib/cryptolib/rsa.c19
-rw-r--r--firmware/lib/cryptolib/rsa_utility.c21
-rw-r--r--firmware/lib/cryptolib/sha_utility.c26
4 files changed, 33 insertions, 37 deletions
diff --git a/firmware/lib/cryptolib/include/sha.h b/firmware/lib/cryptolib/include/sha.h
index a8164710..8beb296b 100644
--- a/firmware/lib/cryptolib/include/sha.h
+++ b/firmware/lib/cryptolib/include/sha.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -107,7 +107,7 @@ typedef struct DigestContext {
/* Initialize a digest context for use with signature algorithm [algorithm]. */
void DigestInit(DigestContext* ctx, int sig_algorithm);
-void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint32_t len);
+void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint64_t len);
/* Caller owns the returned digest and must free it. */
uint8_t* DigestFinal(DigestContext* ctx);
diff --git a/firmware/lib/cryptolib/rsa.c b/firmware/lib/cryptolib/rsa.c
index d552e13e..1dbf92c3 100644
--- a/firmware/lib/cryptolib/rsa.c
+++ b/firmware/lib/cryptolib/rsa.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -9,7 +9,6 @@
*/
#include "cryptolib.h"
-#include "vboot_api.h"
#include "utility.h"
/* a[] -= mod */
@@ -78,9 +77,9 @@ static void montMul(const RSAPublicKey *key,
*/
static void modpowF4(const RSAPublicKey *key,
uint8_t* inout) {
- uint32_t* a = (uint32_t*) VbExMalloc(key->len * sizeof(uint32_t));
- uint32_t* aR = (uint32_t*) VbExMalloc(key->len * sizeof(uint32_t));
- uint32_t* aaR = (uint32_t*) VbExMalloc(key->len * sizeof(uint32_t));
+ uint32_t* a = (uint32_t*) Malloc(key->len * sizeof(uint32_t));
+ uint32_t* aR = (uint32_t*) Malloc(key->len * sizeof(uint32_t));
+ uint32_t* aaR = (uint32_t*) Malloc(key->len * sizeof(uint32_t));
uint32_t* aaa = aaR; /* Re-use location. */
int i;
@@ -117,9 +116,9 @@ static void modpowF4(const RSAPublicKey *key,
*inout++ = (uint8_t)(tmp >> 0);
}
- VbExFree(a);
- VbExFree(aR);
- VbExFree(aaR);
+ Free(a);
+ Free(aR);
+ Free(aaR);
}
/* Verify a RSA PKCS1.5 signature against an expected hash.
@@ -153,7 +152,7 @@ int RSAVerify(const RSAPublicKey *key,
return 0;
}
- buf = (uint8_t*) VbExMalloc(sig_len);
+ buf = (uint8_t*) Malloc(sig_len);
if (!buf)
return 0;
Memcpy(buf, sig, sig_len);
@@ -178,7 +177,7 @@ int RSAVerify(const RSAPublicKey *key,
VBDEBUG(("In RSAVerify(): Hash check failed!\n"));
success = 0;
}
- VbExFree(buf);
+ Free(buf);
return success;
}
diff --git a/firmware/lib/cryptolib/rsa_utility.c b/firmware/lib/cryptolib/rsa_utility.c
index b227b060..cc653c68 100644
--- a/firmware/lib/cryptolib/rsa_utility.c
+++ b/firmware/lib/cryptolib/rsa_utility.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -8,12 +8,11 @@
#include "cryptolib.h"
#include "stateful_util.h"
#include "utility.h"
-#include "vboot_api.h"
uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size) {
- int key_len; /* Key length in bytes. (int type matches siglen_map) */
+ uint64_t key_len; /* Key length in bytes. */
if (algorithm < kNumAlgorithms) {
- key_len = siglen_map[algorithm];
+ key_len = siglen_map[algorithm];
/* Total size needed by a RSAPublicKey structure is =
* 2 * key_len bytes for the n and rr arrays
* + sizeof len + sizeof n0inv.
@@ -25,7 +24,7 @@ uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size) {
}
RSAPublicKey* RSAPublicKeyNew(void) {
- RSAPublicKey* key = (RSAPublicKey*) VbExMalloc(sizeof(RSAPublicKey));
+ RSAPublicKey* key = (RSAPublicKey*) Malloc(sizeof(RSAPublicKey));
key->n = NULL;
key->rr = NULL;
return key;
@@ -33,9 +32,9 @@ RSAPublicKey* RSAPublicKeyNew(void) {
void RSAPublicKeyFree(RSAPublicKey* key) {
if (key) {
- VbExFree(key->n);
- VbExFree(key->rr);
- VbExFree(key);
+ Free(key->n);
+ Free(key->rr);
+ Free(key);
}
}
@@ -60,8 +59,8 @@ RSAPublicKey* RSAPublicKeyFromBuf(const uint8_t* buf, uint64_t len) {
return NULL;
}
- key->n = (uint32_t*) VbExMalloc(key_len);
- key->rr = (uint32_t*) VbExMalloc(key_len);
+ key->n = (uint32_t*) Malloc(key_len);
+ key->rr = (uint32_t*) Malloc(key_len);
StatefulMemcpy(&st, &key->n0inv, sizeof(key->n0inv));
StatefulMemcpy(&st, key->n, key_len);
@@ -107,7 +106,7 @@ int RSAVerifyBinary_f(const uint8_t* key_blob,
success = RSAVerify(verification_key, sig, (uint32_t)sig_size,
(uint8_t)algorithm, digest);
- VbExFree(digest);
+ Free(digest);
if (!key)
RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */
return success;
diff --git a/firmware/lib/cryptolib/sha_utility.c b/firmware/lib/cryptolib/sha_utility.c
index bec7209c..4e266f7c 100644
--- a/firmware/lib/cryptolib/sha_utility.c
+++ b/firmware/lib/cryptolib/sha_utility.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -7,27 +7,26 @@
#include "cryptolib.h"
#include "utility.h"
-#include "vboot_api.h"
void DigestInit(DigestContext* ctx, int sig_algorithm) {
ctx->algorithm = hash_type_map[sig_algorithm];
switch(ctx->algorithm) {
case SHA1_DIGEST_ALGORITHM:
- ctx->sha1_ctx = (SHA1_CTX*) VbExMalloc(sizeof(SHA1_CTX));
+ ctx->sha1_ctx = (SHA1_CTX*) Malloc(sizeof(SHA1_CTX));
SHA1_init(ctx->sha1_ctx);
break;
case SHA256_DIGEST_ALGORITHM:
- ctx->sha256_ctx = (SHA256_CTX*) VbExMalloc(sizeof(SHA256_CTX));
+ ctx->sha256_ctx = (SHA256_CTX*) Malloc(sizeof(SHA256_CTX));
SHA256_init(ctx->sha256_ctx);
break;
case SHA512_DIGEST_ALGORITHM:
- ctx->sha512_ctx = (SHA512_CTX*) VbExMalloc(sizeof(SHA512_CTX));
+ ctx->sha512_ctx = (SHA512_CTX*) Malloc(sizeof(SHA512_CTX));
SHA512_init(ctx->sha512_ctx);
break;
};
}
-void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint32_t len) {
+void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint64_t len) {
switch(ctx->algorithm) {
case SHA1_DIGEST_ALGORITHM:
SHA1_update(ctx->sha1_ctx, data, len);
@@ -45,27 +44,26 @@ uint8_t* DigestFinal(DigestContext* ctx) {
uint8_t* digest = NULL;
switch(ctx->algorithm) {
case SHA1_DIGEST_ALGORITHM:
- digest = (uint8_t*) VbExMalloc(SHA1_DIGEST_SIZE);
+ digest = (uint8_t*) Malloc(SHA1_DIGEST_SIZE);
Memcpy(digest, SHA1_final(ctx->sha1_ctx), SHA1_DIGEST_SIZE);
- VbExFree(ctx->sha1_ctx);
+ Free(ctx->sha1_ctx);
break;
case SHA256_DIGEST_ALGORITHM:
- digest = (uint8_t*) VbExMalloc(SHA256_DIGEST_SIZE);
+ digest = (uint8_t*) Malloc(SHA256_DIGEST_SIZE);
Memcpy(digest, SHA256_final(ctx->sha256_ctx), SHA256_DIGEST_SIZE);
- VbExFree(ctx->sha256_ctx);
+ Free(ctx->sha256_ctx);
break;
case SHA512_DIGEST_ALGORITHM:
- digest = (uint8_t*) VbExMalloc(SHA512_DIGEST_SIZE);
+ digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE);
Memcpy(digest, SHA512_final(ctx->sha512_ctx), SHA512_DIGEST_SIZE);
- VbExFree(ctx->sha512_ctx);
+ Free(ctx->sha512_ctx);
break;
};
return digest;
}
uint8_t* DigestBuf(const uint8_t* buf, uint64_t len, int sig_algorithm) {
- /* Allocate enough space for the largest digest */
- uint8_t* digest = (uint8_t*) VbExMalloc(SHA512_DIGEST_SIZE);
+ uint8_t* digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE); /* Use the max. */
/* Define an array mapping [sig_algorithm] to function pointers to the
* SHA{1|256|512} functions.
*/