From 6be5b88705e3e48dc9e3de7bca93313528f1274e Mon Sep 17 00:00:00 2001 From: Miguel Osorio Date: Thu, 18 Aug 2022 12:59:35 -0700 Subject: [PATCH] [cryptolib] csrng driver This commit introduces the a driver for the software instance of the csrng. The driver interface supports regular DRBG functions, i.e. instantiate, reseed, update and generate functions. The focus of this commit is functionality, so there are a few things that will be addressed in future commits: - Handling of blocking operations. This is currently an area where we need to come up with a strategy for the crypto library as indefinite blocking operations may need an unconditional timeout when called in higher application layers. - alert and state checks. Signed-off-by: Miguel Osorio --- sw/device/lib/crypto/drivers/BUILD | 30 +++++++++++++------------- sw/device/lib/crypto/drivers/entropy.c | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sw/device/lib/crypto/drivers/BUILD b/sw/device/lib/crypto/drivers/BUILD index 71cf71292c2d1..9b18d7af92f57 100644 --- a/sw/device/lib/crypto/drivers/BUILD +++ b/sw/device/lib/crypto/drivers/BUILD @@ -20,6 +20,21 @@ cc_library( ], ) +opentitan_functest( + name = "aes_test", + srcs = ["aes_test.c"], + verilator = verilator_params( + timeout = "long", + ), + deps = [ + ":aes", + "//sw/device/lib/base:macros", + "//sw/device/lib/base:memory", + "//sw/device/lib/testing/test_framework:check", + "//sw/device/lib/testing/test_framework:ottf_main", + ], +) + cc_library( name = "kmac", srcs = ["kmac.c"], @@ -58,21 +73,6 @@ opentitan_functest( ], ) -opentitan_functest( - name = "aes_test", - srcs = ["aes_test.c"], - verilator = verilator_params( - timeout = "long", - ), - deps = [ - ":aes", - "//sw/device/lib/base:macros", - "//sw/device/lib/base:memory", - "//sw/device/lib/testing/test_framework:check", - "//sw/device/lib/testing/test_framework:ottf_main", - ], -) - cc_library( name = "entropy", srcs = ["entropy.c"], diff --git a/sw/device/lib/crypto/drivers/entropy.c b/sw/device/lib/crypto/drivers/entropy.c index ed3b30bf9f51b..f48a3fb7546ee 100644 --- a/sw/device/lib/crypto/drivers/entropy.c +++ b/sw/device/lib/crypto/drivers/entropy.c @@ -158,7 +158,7 @@ status_t entropy_csrng_generate_data_get(uint32_t *buf, size_t len) { // Block until there is more data available in the genbits buffer. CSRNG // generates data in 128bit chunks (i.e. 4 words). static_assert(kEntropyCsrngBitsBufferNumWords == 4, - "kEntropyCsrngBitsBufferNumWords must be a power of 2."); + "kEntropyCsrngBitsBufferNumWords must be a power of 2."); if (i & (kEntropyCsrngBitsBufferNumWords - 1)) { uint32_t reg; do {