summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorGurleen Grewal <gurleengrewal@chromium.org>2019-11-05 17:18:42 -0800
committerCommit Bot <commit-bot@chromium.org>2020-02-19 22:19:19 +0000
commit261b58eb72b9d48168104e636021de9de54ec238 (patch)
tree98b6df28949d7812d81baa45942314bdc22ae9d9 /chip
parenta0ce3a44ee73185c03031a2364376dece6e778b6 (diff)
downloadchrome-ec-261b58eb72b9d48168104e636021de9de54ec238.tar.gz
Cr50: Adjust HMAC and hash structs to work with cryptoc
The latest update to cryptoc adds support for MD5, SHA224 & HMAC-SHA384/512. This alters some internal hash structs that also affect HMAC computation. This CL updates the structs and HMAC computation to be compatible with the latest changes to cryptoc. Space before: *** 9836 bytes in flash and 6028 bytes in RAM still available on cr50 RW **** Space after: *** 9804 bytes in flash and 6028 bytes in RAM still available on cr50 RW **** BUG=None BRANCH=cr50 TEST=test/tpm_test/tpmtest.py && tast run $device-ip firmware.ACVP.aes_ecb_short firmware.ACVP.aes_cbc_short firmware.ACVP.sha2_256_short Cq-Depend: chromium:1850535 Signed-off-by: nagendra modadugu <ngm@google.com> Change-Id: Ib1c85f89a8f9315eb835d9e35655e6059fe68b72 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1899898 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Commit-Queue: Gurleen Grewal <gurleengrewal@google.com>
Diffstat (limited to 'chip')
-rw-r--r--chip/g/dcrypto/dcrypto_sha512.c4
-rw-r--r--chip/g/dcrypto/hmac.c16
-rw-r--r--chip/g/dcrypto/sha1.c5
-rw-r--r--chip/g/dcrypto/sha256.c5
4 files changed, 19 insertions, 11 deletions
diff --git a/chip/g/dcrypto/dcrypto_sha512.c b/chip/g/dcrypto/dcrypto_sha512.c
index bb404b28d7..4938a05421 100644
--- a/chip/g/dcrypto/dcrypto_sha512.c
+++ b/chip/g/dcrypto/dcrypto_sha512.c
@@ -646,8 +646,8 @@ const uint8_t *DCRYPTO_SHA512_hash(const void *data, size_t len,
}
static const HASH_VTAB dcrypto_SHA512_VTAB = {
- DCRYPTO_SHA512_init, dcrypto_SHA512_update, dcrypto_SHA512_final,
- DCRYPTO_SHA512_hash, SHA512_DIGEST_SIZE};
+ DCRYPTO_SHA512_init, dcrypto_SHA512_update, dcrypto_SHA512_final,
+ DCRYPTO_SHA512_hash, SHA512_DIGEST_SIZE, SHA512_BLOCK_SIZE};
void DCRYPTO_SHA512_init(LITE_SHA512_CTX *ctx)
{
diff --git a/chip/g/dcrypto/hmac.c b/chip/g/dcrypto/hmac.c
index d6f2d4e775..ad0f01b126 100644
--- a/chip/g/dcrypto/hmac.c
+++ b/chip/g/dcrypto/hmac.c
@@ -17,9 +17,10 @@ static void HMAC_init(LITE_HMAC_CTX *ctx, const void *key, unsigned int len)
unsigned int i;
memset(&ctx->opad[0], 0, sizeof(ctx->opad));
+ /* Initialize the hash context */
+ DCRYPTO_SHA256_init(&ctx->hash, 0);
- if (len > sizeof(ctx->opad)) {
- DCRYPTO_SHA256_init(&ctx->hash, 0);
+ if (len > HASH_block_size(&ctx->hash)) {
HASH_update(&ctx->hash, key, len);
memcpy(&ctx->opad[0], HASH_final(&ctx->hash),
HASH_size(&ctx->hash));
@@ -27,14 +28,14 @@ static void HMAC_init(LITE_HMAC_CTX *ctx, const void *key, unsigned int len)
memcpy(&ctx->opad[0], key, len);
}
- for (i = 0; i < sizeof(ctx->opad); ++i)
+ for (i = 0; i < HASH_block_size(&ctx->hash); ++i)
ctx->opad[i] ^= 0x36;
DCRYPTO_SHA256_init(&ctx->hash, 0);
/* hash ipad */
- HASH_update(&ctx->hash, ctx->opad, sizeof(ctx->opad));
+ HASH_update(&ctx->hash, ctx->opad, HASH_block_size(&ctx->hash));
- for (i = 0; i < sizeof(ctx->opad); ++i)
+ for (i = 0; i < HASH_block_size(&ctx->hash); ++i)
ctx->opad[i] ^= (0x36 ^ 0x5c);
}
@@ -52,8 +53,9 @@ const uint8_t *DCRYPTO_HMAC_final(LITE_HMAC_CTX *ctx)
(HASH_size(&ctx->hash) <= sizeof(digest) ?
HASH_size(&ctx->hash) : sizeof(digest)));
DCRYPTO_SHA256_init(&ctx->hash, 0);
- HASH_update(&ctx->hash, ctx->opad, sizeof(ctx->opad));
+ HASH_update(&ctx->hash, ctx->opad, HASH_block_size(&ctx->hash));
HASH_update(&ctx->hash, digest, HASH_size(&ctx->hash));
- always_memset(&ctx->opad[0], 0, sizeof(ctx->opad)); /* wipe key */
+ /* wipe key */
+ always_memset(&ctx->opad[0], 0, HASH_block_size(&ctx->hash));
return HASH_final(&ctx->hash);
}
diff --git a/chip/g/dcrypto/sha1.c b/chip/g/dcrypto/sha1.c
index 07ef3a34ef..912c4500f5 100644
--- a/chip/g/dcrypto/sha1.c
+++ b/chip/g/dcrypto/sha1.c
@@ -20,7 +20,10 @@ static const HASH_VTAB HW_SHA1_VTAB = {
dcrypto_sha_update,
dcrypto_sha1_final,
DCRYPTO_SHA1_hash,
- SHA_DIGEST_SIZE
+ SHA_DIGEST_SIZE,
+#ifdef SHA512_SUPPORT
+ SHA_BLOCK_SIZE,
+#endif
};
/* Requires dcrypto_grab_sha_hw() to be called first. */
diff --git a/chip/g/dcrypto/sha256.c b/chip/g/dcrypto/sha256.c
index f127ab445a..788ca2cb97 100644
--- a/chip/g/dcrypto/sha256.c
+++ b/chip/g/dcrypto/sha256.c
@@ -79,7 +79,10 @@ static const HASH_VTAB HW_SHA256_VTAB = {
dcrypto_sha_update,
dcrypto_sha256_final,
DCRYPTO_SHA256_hash,
- SHA256_DIGEST_SIZE
+ SHA256_DIGEST_SIZE,
+#ifdef SHA512_SUPPORT
+ SHA256_BLOCK_SIZE,
+#endif
};
void dcrypto_sha_hash(enum sha_mode mode, const uint8_t *data, uint32_t n,