summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Sukhomlinov <sukhomlinov@google.com>2019-08-22 13:19:37 -0700
committerCommit Bot <commit-bot@chromium.org>2019-12-06 23:48:32 +0000
commit47fb09677c6b52618349773730db122f1089f97f (patch)
tree7eb8074d08f04acd697374554ab543d1c9764dea
parentd2ffa5f72aae0fcbc5aea7c985d09680f201a08f (diff)
downloadchrome-ec-47fb09677c6b52618349773730db122f1089f97f.tar.gz
g: Add support for 192 and 256 bit AES-GCM in DCRYPTO_gcm_init
DCRYPTO_gcm_init hardcoded key length to 128 bit causing preventing testing of 192 and 256 bit functionality for AES-GCM. BUG=b:135623371 BRANCH=cr50 TEST=compile, specific test for issue as described in bug Change-Id: I4fc41f6155661709115c57aa944c8976e17bffac Signed-off-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1766098 Reviewed-by: Andrey Pronin <apronin@chromium.org> (cherry picked from commit 24f7511e41c1f8140b19d69d9440a3ea6f91bd89) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1954339 Tested-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
-rw-r--r--board/cr50/tpm2/aes.c6
-rw-r--r--chip/g/dcrypto/dcrypto.h4
-rw-r--r--chip/g/dcrypto/gcm.c6
3 files changed, 9 insertions, 7 deletions
diff --git a/board/cr50/tpm2/aes.c b/board/cr50/tpm2/aes.c
index cc4d83d7e7..5fe431222a 100644
--- a/board/cr50/tpm2/aes.c
+++ b/board/cr50/tpm2/aes.c
@@ -403,7 +403,8 @@ static void aes_command_handler(void *cmd_body,
size_t count;
struct GCM_CTX ctx;
- DCRYPTO_gcm_init(&ctx, key_local.b, iv_local.b, iv_len);
+ DCRYPTO_gcm_init(&ctx, key_len, key_local.b,
+ iv_local.b, iv_len);
DCRYPTO_gcm_aad(&ctx, aad, aad_len);
count = DCRYPTO_gcm_decrypt(
&ctx, out_local.b, sizeof(out_local.b),
@@ -437,7 +438,8 @@ static void aes_command_handler(void *cmd_body,
size_t count;
struct GCM_CTX ctx;
- DCRYPTO_gcm_init(&ctx, key_local.b, iv_local.b, iv_len);
+ DCRYPTO_gcm_init(&ctx, key_len, key_local.b,
+ iv_local.b, iv_len);
DCRYPTO_gcm_aad(&ctx, aad, aad_len);
count = DCRYPTO_gcm_encrypt(
&ctx, out_local.b, sizeof(out_local.b),
diff --git a/chip/g/dcrypto/dcrypto.h b/chip/g/dcrypto/dcrypto.h
index 7bab4b864b..1de0d63b03 100644
--- a/chip/g/dcrypto/dcrypto.h
+++ b/chip/g/dcrypto/dcrypto.h
@@ -80,8 +80,8 @@ struct GCM_CTX {
};
/* Initialize the GCM context structure. */
-void DCRYPTO_gcm_init(struct GCM_CTX *ctx, const uint8_t *key,
- const uint8_t *iv, size_t iv_len);
+void DCRYPTO_gcm_init(struct GCM_CTX *ctx, uint32_t key_bits,
+ const uint8_t *key, const uint8_t *iv, size_t iv_len);
/* Additional authentication data to include in the tag calculation. */
void DCRYPTO_gcm_aad(struct GCM_CTX *ctx, const uint8_t *aad_data, size_t len);
/* Encrypt & decrypt return the number of bytes written to out
diff --git a/chip/g/dcrypto/gcm.c b/chip/g/dcrypto/gcm.c
index 2caddf4741..cd035bbd54 100644
--- a/chip/g/dcrypto/gcm.c
+++ b/chip/g/dcrypto/gcm.c
@@ -82,8 +82,8 @@ static void gcm_init_iv(
}
}
-void DCRYPTO_gcm_init(struct GCM_CTX *ctx, const uint8_t *key,
- const uint8_t *iv, size_t iv_len)
+void DCRYPTO_gcm_init(struct GCM_CTX *ctx, uint32_t key_bits,
+ const uint8_t *key, const uint8_t *iv, size_t iv_len)
{
int i;
const uint32_t zero[4] = {0, 0, 0, 0};
@@ -93,7 +93,7 @@ void DCRYPTO_gcm_init(struct GCM_CTX *ctx, const uint8_t *key,
memset(ctx, 0, sizeof(struct GCM_CTX));
/* Initialize AES engine in CTR mode, and set the counter to 0. */
- DCRYPTO_aes_init(key, 128, (const uint8_t *) zero,
+ DCRYPTO_aes_init(key, key_bits, (const uint8_t *) zero,
CIPHER_MODE_CTR, ENCRYPT_MODE);
/* Set H to AES(ZERO). */
DCRYPTO_aes_block((const uint8_t *) zero, (uint8_t *) H);