diff options
author | Tom Hughes <tomhughes@chromium.org> | 2022-06-17 17:15:14 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-07-06 22:04:35 +0000 |
commit | 738de2b575de93f71f3a95f9294b9006f4f7b008 (patch) | |
tree | 4d95d8dcdb00843cd137bf883ef98c4723040ab7 /chip | |
parent | c1415ecc5fc7ace6e91115e73b97e7034b329d2b (diff) | |
download | chrome-ec-738de2b575de93f71f3a95f9294b9006f4f7b008.tar.gz |
trng: Rename rand to trng_rand
The declaration for rand conflicts with the standard library declaration
so rename it from "rand" to "trng_rand". This has the benefit of making
it obvious when we're using the true random number generator.
For consistency, this also renames init_trng/exit_trng to
trng_init/trng_exit.
This is a reland of commit a6b0b3554f59cc9b0c4aae9bff7dff075f2089a9.
BRANCH=none
BUG=b:234181908, b:237344361
TEST=./util/compare_build.sh -b all -j 120
=> MATCH
TEST=emerge-hatch ec-utils-test
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: Ic26890572cb9865275c866b65b0532c5ab029865
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3738978
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Bobby Casey <bobbycasey@google.com>
Diffstat (limited to 'chip')
-rw-r--r-- | chip/host/trng.c | 6 | ||||
-rw-r--r-- | chip/stm32/trng.c | 22 |
2 files changed, 14 insertions, 14 deletions
diff --git a/chip/host/trng.c b/chip/host/trng.c index d54983f3a1..e2c13d7d14 100644 --- a/chip/host/trng.c +++ b/chip/host/trng.c @@ -21,17 +21,17 @@ static unsigned int seed; -test_mockable void init_trng(void) +test_mockable void trng_init(void) { seed = 0; srand(seed); } -test_mockable void exit_trng(void) +test_mockable void trng_exit(void) { } -test_mockable void rand_bytes(void *buffer, size_t len) +test_mockable void trng_rand_bytes(void *buffer, size_t len) { uint8_t *b, *end; diff --git a/chip/stm32/trng.c b/chip/stm32/trng.c index 6927786c48..6538263add 100644 --- a/chip/stm32/trng.c +++ b/chip/stm32/trng.c @@ -15,7 +15,7 @@ #include "trng.h" #include "util.h" -uint32_t rand(void) +uint32_t trng_rand(void) { int tries = 300; /* Wait for a valid random number */ @@ -28,10 +28,10 @@ uint32_t rand(void) return STM32_RNG_DR; } -test_mockable void rand_bytes(void *buffer, size_t len) +test_mockable void trng_rand_bytes(void *buffer, size_t len) { while (len) { - uint32_t number = rand(); + uint32_t number = trng_rand(); size_t cnt = 4; /* deal with the lack of alignment guarantee in the API */ uintptr_t align = (uintptr_t)buffer & 3; @@ -47,7 +47,7 @@ test_mockable void rand_bytes(void *buffer, size_t len) } } -test_mockable void init_trng(void) +test_mockable void trng_init(void) { #ifdef CHIP_FAMILY_STM32L4 /* Enable the 48Mhz internal RC oscillator */ @@ -84,7 +84,7 @@ test_mockable void init_trng(void) STM32_RNG_CR |= STM32_RNG_CR_RNGEN; } -test_mockable void exit_trng(void) +test_mockable void trng_exit(void) { STM32_RNG_CR &= ~STM32_RNG_CR_RNGEN; STM32_RCC_AHB2ENR &= ~STM32_RCC_AHB2ENR_RNGEN; @@ -107,9 +107,9 @@ static int command_rand(int argc, char **argv) { uint8_t data[32]; - init_trng(); - rand_bytes(data, sizeof(data)); - exit_trng(); + trng_init(); + trng_rand_bytes(data, sizeof(data)); + trng_exit(); ccprintf("rand %ph\n", HEX_BUF(data, sizeof(data))); @@ -130,9 +130,9 @@ static enum ec_status host_command_rand(struct host_cmd_handler_args *args) if (num_rand_bytes > args->response_max) return EC_RES_OVERFLOW; - init_trng(); - rand_bytes(r->rand, num_rand_bytes); - exit_trng(); + trng_init(); + trng_rand_bytes(r->rand, num_rand_bytes); + trng_exit(); args->response_size = num_rand_bytes; |