From d786c0c6817ed562d18fb7a183b88fa8020cdf77 Mon Sep 17 00:00:00 2001 From: Vadim Sukhomlinov Date: Thu, 26 Jan 2023 20:59:05 -0800 Subject: cr50: return various error codes for certain TPM2 operations Adjust error codes to distinguish different places in key generation. BUG=b:262324344 TEST=TCG tests Change-Id: I33ef8b772821ad43cf8af1b33b6b49143eb24aef Signed-off-by: Vadim Sukhomlinov Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4199163 Reviewed-by: Vadim Bendebury Reviewed-by: Andrey Pronin Auto-Submit: Vadim Sukhomlinov Code-Coverage: Vadim Sukhomlinov Commit-Queue: Andrey Pronin Tested-by: Vadim Sukhomlinov Reviewed-by: Vadim Sukhomlinov --- board/cr50/tpm2/ecc.c | 8 +++++--- board/cr50/tpm2/rsa.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'board') diff --git a/board/cr50/tpm2/ecc.c b/board/cr50/tpm2/ecc.c index f9cc5a966a..84c5407337 100644 --- a/board/cr50/tpm2/ecc.c +++ b/board/cr50/tpm2/ecc.c @@ -143,7 +143,7 @@ CRYPT_RESULT _cpri__GenerateKeyEcc( * the derivation tree is distinct from RSA key derivation. */ if (DCRYPTO_hw_hmac_sha256_init(&hmac, seed->buffer, seed->size) != DCRYPTO_OK) - return CRYPT_FAIL; + return CRYPT_NO_RESULT; HMAC_SHA256_update(&hmac, "ECC", 4); memcpy(local_seed.t.buffer, HMAC_SHA256_final(&hmac), @@ -194,10 +194,12 @@ CRYPT_RESULT _cpri__GenerateKeyEcc( always_memset(local_seed.t.buffer, 0, local_seed.t.size); always_memset(key_bytes, 0, sizeof(key_bytes)); - if (count == 0) - FAIL(FATAL_ERROR_INTERNAL); if (counter != NULL) *counter = count; + if (count == 0) { + FAIL(FATAL_ERROR_CRYPTO); + return CRYPT_HW_FAILURE; /* Produce TPM_RC_FAILURE */ + } return CRYPT_SUCCESS; } diff --git a/board/cr50/tpm2/rsa.c b/board/cr50/tpm2/rsa.c index caed71e57a..367272d93c 100644 --- a/board/cr50/tpm2/rsa.c +++ b/board/cr50/tpm2/rsa.c @@ -399,7 +399,7 @@ CRYPT_RESULT _cpri__GenerateKeyRSA( if (DCRYPTO_hw_hmac_sha256_init(&hmac, seed->buffer, seed->size) != DCRYPTO_OK) - return CRYPT_FAIL; + return CRYPT_NO_RESULT; HMAC_SHA256_update(&hmac, "RSA", 4); memcpy(local_seed.t.buffer, HMAC_SHA256_final(&hmac), local_seed.t.size); -- cgit v1.2.1