summaryrefslogtreecommitdiff
path: root/board/cr50/dcrypto/fips_rand.c
diff options
context:
space:
mode:
authorVadim Sukhomlinov <sukhomlinov@google.com>2021-09-21 16:12:01 -0700
committerCommit Bot <commit-bot@chromium.org>2021-09-22 18:38:53 +0000
commit3e79af7d30c9c71029873ebad4dead13d09e298c (patch)
treec9d4c7701c6873898fdb951c370f95f288715894 /board/cr50/dcrypto/fips_rand.c
parent12a022685da02b5b409a65347bdee1ba86b5b53d (diff)
downloadchrome-ec-3e79af7d30c9c71029873ebad4dead13d09e298c.tar.gz
cr50: move several few static inline functions into dcrypto/internal.hstabilize-14238.B-cr50_stab
Several functions like lo32(), hi32(), clz() were defined into bn.c, but clz and ctz are used in fips_rand.c. Move these functions into internal.h to allow reuse. Both __builtin_ctz() and __builtin_clz() have undefined behavior for argument which is zero. Explicitly set result to 32 in such case. It was the case for __builtin_clz() in bn.c, but not for variants used in TRNG health tests. BUG=None TEST=make BOARD=cr50 CRYPTO_TEST=1; TCG tests Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Ifc6fa7f820080bdad0f14fc079163f4976369724 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3174592 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Diffstat (limited to 'board/cr50/dcrypto/fips_rand.c')
-rw-r--r--board/cr50/dcrypto/fips_rand.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/board/cr50/dcrypto/fips_rand.c b/board/cr50/dcrypto/fips_rand.c
index 4529a1cfbf..e3dcf4d298 100644
--- a/board/cr50/dcrypto/fips_rand.c
+++ b/board/cr50/dcrypto/fips_rand.c
@@ -63,11 +63,12 @@ static struct {
static bool repetition_count_test(uint32_t rnd)
{
uint32_t clz, ctz, clo, cto;
+
/* count repeating 0 and 1 bits from each side */
- clz = __builtin_clz(rnd); /* # of leading 0s */
- ctz = __builtin_ctz(rnd); /* # of trailing 0s */
- clo = __builtin_clz(~rnd); /* # of leading 1s */
- cto = __builtin_ctz(~rnd); /* # of trailing 1s */
+ clz = count_leading_zeros(rnd); /* # of leading 0s */
+ ctz = count_trailing_zeros(rnd); /* # of trailing 0s */
+ clo = count_leading_zeros(~rnd); /* # of leading 1s */
+ cto = count_trailing_zeros(~rnd); /* # of trailing 1s */
/**
* check that number of trailing 0/1 in current sample added to