summaryrefslogtreecommitdiff
path: root/board/cr50/tpm2/endorsement.c
diff options
context:
space:
mode:
authorVadim Sukhomlinov <sukhomlinov@google.com>2021-07-30 08:40:32 -0700
committerCommit Bot <commit-bot@chromium.org>2021-08-12 14:18:48 +0000
commit7ddbd2a9eab0dc54897d6b5bb8ee1d4b3be1fe27 (patch)
tree43356bb71d38ea7f5ea1639855ac3b322d460176 /board/cr50/tpm2/endorsement.c
parent43f6e7be087720507e57cf27e9460aae64c3b69a (diff)
downloadchrome-ec-stabilize-14150.64.B-cr50_stab.tar.gz
To implement FIPS module we need to bring many crypto functions in the module boundary. Unfortunately, cryptoc is a third-party library used by dcrypto code in cr50. Cryptoc is also not well-maintained and shared with other projects. While just making local copy of cryptoc would solve an issue, it's suboptimal as prevents from many optimizations and improvements. Provided SHA & HMAC implementations from Ti50 project. This provides better performance (500us vs. 670us earlier for HMAC DRBG) and reduce code size. This implementation also enables stack use savings when only specific digest is needed. Earlier SHA512 context was allocated when only SHA256 is needed greatly increasing stack consumption for code using HMAC_DRBG and others. However, it introduce subtle API changes which require handling. As for tests, since core implementation is hardware-independent, make it available for BOARD=host too. Before change (with cryptoc): *** 12368 bytes in flash and 5784 bytes in RAM After: *** 13136 bytes in flash and 5796 bytes in RAM BUG=b:138578318 TEST=make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpmtest.py Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I2ff5362aee9078ce83dc1f8081943a5101d5f666 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3064201 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Diffstat (limited to 'board/cr50/tpm2/endorsement.c')
-rw-r--r--board/cr50/tpm2/endorsement.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/board/cr50/tpm2/endorsement.c b/board/cr50/tpm2/endorsement.c
index 844d07e2a6..49f542f782 100644
--- a/board/cr50/tpm2/endorsement.c
+++ b/board/cr50/tpm2/endorsement.c
@@ -30,8 +30,6 @@
#include "dcrypto.h"
-#include <cryptoc/sha256.h>
-
#include <endian.h>
#include <string.h>
@@ -548,7 +546,7 @@ enum manufacturing_status tpm_endorse(void)
enum manufacturing_status result;
uint8_t eps[PRIMARY_SEED_SIZE];
- LITE_HMAC_CTX hmac;
+ struct hmac_sha256_ctx hmac;
flash_cert_region_enable();
@@ -592,12 +590,12 @@ enum manufacturing_status tpm_endorse(void)
*
* This will fail if we are not running w/ expected keyladder.
*/
- DCRYPTO_HMAC_SHA256_init(&hmac, eps, sizeof(eps));
- HASH_update(&hmac.hash, "RSA", 4);
- DCRYPTO_HMAC_SHA256_init(&hmac, DCRYPTO_HMAC_final(&hmac), 32);
- HASH_update(&hmac.hash, p, RO_CERTS_REGION_SIZE - 32);
+ HMAC_SHA256_hw_init(&hmac, eps, sizeof(eps));
+ HMAC_SHA256_update(&hmac, "RSA", 4);
+ HMAC_SHA256_hw_init(&hmac, HMAC_SHA256_hw_final(&hmac), 32);
+ HMAC_SHA256_update(&hmac, p, RO_CERTS_REGION_SIZE - 32);
if (!DCRYPTO_equals(p + RO_CERTS_REGION_SIZE - 32,
- DCRYPTO_HMAC_final(&hmac), 32)) {
+ HMAC_SHA256_hw_final(&hmac), 32)) {
CPRINTF("%s: bad cert region hmac;", __func__);
#ifdef CR50_INCLUDE_FALLBACK_CERT