From 47fb09677c6b52618349773730db122f1089f97f Mon Sep 17 00:00:00 2001 From: Vadim Sukhomlinov Date: Thu, 22 Aug 2019 13:19:37 -0700 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1766098 Reviewed-by: Andrey Pronin (cherry picked from commit 24f7511e41c1f8140b19d69d9440a3ea6f91bd89) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1954339 Tested-by: Vadim Bendebury Reviewed-by: Vadim Bendebury Commit-Queue: Vadim Bendebury --- board/cr50/tpm2/aes.c | 6 ++++-- chip/g/dcrypto/dcrypto.h | 4 ++-- chip/g/dcrypto/gcm.c | 6 +++--- 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); -- cgit v1.2.1