summaryrefslogtreecommitdiff
path: root/firmware/lib/cryptolib/sha_utility.c
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2012-05-09 16:22:04 -0700
committerGerrit <chrome-bot@google.com>2012-05-09 20:52:01 -0700
commit317e25c663162bf24453c2916c07ce2c7d2a2da3 (patch)
treec3e03d0203527c152dec2b259d7dd4ad7b3e5def /firmware/lib/cryptolib/sha_utility.c
parentfe356f9d57ba83f2658c4e00ae8431bed23a389c (diff)
downloadvboot-317e25c663162bf24453c2916c07ce2c7d2a2da3.tar.gz
Use CHROMEOS_EC macro to cut down compiled size.release-R20-2268.Bfactory-2268.16.B
This macro is only defined by the EC firmware build process, and is used to cut down the amount of compiled code. A future CL will refactor the library to make this unnecessary. BUG=chrome-os-partner:7459 TEST=manual make make runtests Change-Id: I41d0b4b282ec7147e8d6f508531af32e74f2d19e Reviewed-on: https://gerrit.chromium.org/gerrit/22313 Commit-Ready: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'firmware/lib/cryptolib/sha_utility.c')
-rw-r--r--firmware/lib/cryptolib/sha_utility.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/firmware/lib/cryptolib/sha_utility.c b/firmware/lib/cryptolib/sha_utility.c
index bec7209c..c676040b 100644
--- a/firmware/lib/cryptolib/sha_utility.c
+++ b/firmware/lib/cryptolib/sha_utility.c
@@ -12,53 +12,65 @@
void DigestInit(DigestContext* ctx, int sig_algorithm) {
ctx->algorithm = hash_type_map[sig_algorithm];
switch(ctx->algorithm) {
+#ifndef CHROMEOS_EC
case SHA1_DIGEST_ALGORITHM:
ctx->sha1_ctx = (SHA1_CTX*) VbExMalloc(sizeof(SHA1_CTX));
SHA1_init(ctx->sha1_ctx);
break;
+#endif
case SHA256_DIGEST_ALGORITHM:
ctx->sha256_ctx = (SHA256_CTX*) VbExMalloc(sizeof(SHA256_CTX));
SHA256_init(ctx->sha256_ctx);
break;
+#ifndef CHROMEOS_EC
case SHA512_DIGEST_ALGORITHM:
ctx->sha512_ctx = (SHA512_CTX*) VbExMalloc(sizeof(SHA512_CTX));
SHA512_init(ctx->sha512_ctx);
break;
+#endif
};
}
void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint32_t len) {
switch(ctx->algorithm) {
+#ifndef CHROMEOS_EC
case SHA1_DIGEST_ALGORITHM:
SHA1_update(ctx->sha1_ctx, data, len);
break;
+#endif
case SHA256_DIGEST_ALGORITHM:
SHA256_update(ctx->sha256_ctx, data, len);
break;
+#ifndef CHROMEOS_EC
case SHA512_DIGEST_ALGORITHM:
SHA512_update(ctx->sha512_ctx, data, len);
break;
+#endif
};
}
uint8_t* DigestFinal(DigestContext* ctx) {
uint8_t* digest = NULL;
switch(ctx->algorithm) {
+#ifndef CHROMEOS_EC
case SHA1_DIGEST_ALGORITHM:
digest = (uint8_t*) VbExMalloc(SHA1_DIGEST_SIZE);
Memcpy(digest, SHA1_final(ctx->sha1_ctx), SHA1_DIGEST_SIZE);
VbExFree(ctx->sha1_ctx);
break;
+#endif
case SHA256_DIGEST_ALGORITHM:
digest = (uint8_t*) VbExMalloc(SHA256_DIGEST_SIZE);
Memcpy(digest, SHA256_final(ctx->sha256_ctx), SHA256_DIGEST_SIZE);
VbExFree(ctx->sha256_ctx);
break;
+#ifndef CHROMEOS_EC
case SHA512_DIGEST_ALGORITHM:
digest = (uint8_t*) VbExMalloc(SHA512_DIGEST_SIZE);
Memcpy(digest, SHA512_final(ctx->sha512_ctx), SHA512_DIGEST_SIZE);
VbExFree(ctx->sha512_ctx);
break;
+#endif
};
return digest;
}
@@ -71,6 +83,20 @@ uint8_t* DigestBuf(const uint8_t* buf, uint64_t len, int sig_algorithm) {
*/
typedef uint8_t* (*Hash_ptr) (const uint8_t*, uint64_t, uint8_t*);
Hash_ptr hash[] = {
+#ifdef CHROMEOS_EC
+ 0, /* RSA 1024 */
+ 0,
+ 0,
+ 0, /* RSA 2048 */
+ 0,
+ 0,
+ 0, /* RSA 4096 */
+ SHA256,
+ 0,
+ 0, /* RSA 8192 */
+ 0,
+ 0,
+#else
SHA1, /* RSA 1024 */
SHA256,
SHA512,
@@ -83,6 +109,7 @@ uint8_t* DigestBuf(const uint8_t* buf, uint64_t len, int sig_algorithm) {
SHA1, /* RSA 8192 */
SHA256,
SHA512,
+#endif
};
/* Call the appropriate hash function. */
return hash[sig_algorithm](buf, len, digest);