summaryrefslogtreecommitdiff
path: root/include/trng.h
Commit message (Collapse)AuthorAgeFilesLines
* zephyr: Add support for RNG devicesPatryk Duda2023-04-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | This patch provides implementation of trng_rand_bytes() using Zephyr's entropy API. Zephyr driver is responsible for hardware initialization, enabling and disabling, so trng_init() and trng_exit() are no-op. Add hostcmd and console command which can be used to test random number generator. Both commands have unit tests implemented. BUG=b:277029648 BRANCH=none TEST=zmake build bloonchipper TEST=Enable CONFIG_PLATFORM_EC_CONSOLE_CMD_RAND and compile firmware. Use 'rand' command to check if random values are generated. TEST=./twister -v -i -T zephyr/test/drivers/ --test drivers.random Change-Id: I3fa2c6a1aaf84dc23a8fbb06e557d9e07f5d1d32 Signed-off-by: Patryk Duda <pdk@semihalf.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4381919 Tested-by: Patryk Duda <patrykd@google.com> Commit-Queue: Patryk Duda <patrykd@google.com> Reviewed-by: Keith Short <keithshort@chromium.org>
* trng: Drop trng_rand() functionPatryk Duda2023-04-131-7/+0
| | | | | | | | | | | | | | | | | | | The function is not used anywhere except test/rng_benchmark.cc, so we will have a problem with code coverage when implementing the function using Zephyr API. The RNG benchmark was modified to use trng_rand_bytes() function. BUG=b:277029648 BRANCH=none TEST=./test/run_device_tests.py --board bloonchipper -t rng_benchmark Change-Id: Ic6cf7e511b2e8fe88a08e9e1c4354f7afa9ae425 Signed-off-by: Patryk Duda <pdk@semihalf.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4423151 Tested-by: Patryk Duda <patrykd@google.com> Commit-Queue: Patryk Duda <patrykd@google.com> Reviewed-by: Keith Short <keithshort@chromium.org>
* include: Sort header filesJeremy Bettis2022-11-291-1/+2
| | | | | | | | | | | | | | | | | | | | Sort all includes in include with the clang-format rules used by the zephyr project. BRANCH=None BUG=b:247100970 TEST=zmake build -a TEST=./twister --clobber -v -i TEST=make -j72 buildall_only runtests TEST=zmake compare-builds -a Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: Ic23f440ebd93519e4341423cf6cb7a298620cbfe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4049883 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Tristan Honscheid <honscheid@google.com>
* Update license boilerplate text in source code filesMike Frysinger2022-09-121-1/+1
| | | | | | | | | | | | | | | Normally we don't do this, but enough changes have accumulated that we're doing a tree-wide one-off update of the name & style. BRANCH=none BUG=chromium:1098010 TEST=`repo upload` works Change-Id: Icd3a1723c20595356af83d190b2c6a9078b3013b Signed-off-by: Mike Frysinger <vapier@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3891203 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* trng: Rename rand to trng_randTom Hughes2022-07-061-7/+5
| | | | | | | | | | | | | | | | | | | | | | | 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>
* Revert "trng: Rename rand to trng_rand"Pin-yen Lin2022-06-281-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit a6b0b3554f59cc9b0c4aae9bff7dff075f2089a9. Reason for revert: This CL breaks ec-utils-test package and affects CQ Original change's description: > 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. > > BRANCH=none > BUG=b:234181908 > TEST=./util/compare_build.sh -b all -j 120 > => MATCH > > Signed-off-by: Tom Hughes <tomhughes@chromium.org> > Change-Id: Ic3305a91263c45786c051eaa5b3689e7464aa0ab > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3712032 > Reviewed-by: Bobby Casey <bobbycasey@google.com> > Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Bug: b:234181908,b:237344361 Change-Id: Iceae55ad9ff0e6aa98aebd474f92a98e12c287e2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3726597 Tested-by: Manoj Gupta <manojgupta@chromium.org> Reviewed-by: Pin-yen Lin <treapking@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Owners-Override: Pin-yen Lin <treapking@chromium.org> Commit-Queue: Pin-yen Lin <treapking@chromium.org> Tested-by: Pin-yen Lin <treapking@chromium.org> Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
* trng: Rename rand to trng_randTom Hughes2022-06-281-7/+5
| | | | | | | | | | | | | | | | | | | | 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. BRANCH=none BUG=b:234181908 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ic3305a91263c45786c051eaa5b3689e7464aa0ab Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3712032 Reviewed-by: Bobby Casey <bobbycasey@google.com> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* util: Move __stdlib_compat to function definitionsCraig Hesling2019-07-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Putting a visibility-hidden attribute in the header file is ambiguous. The compiler cannot determine which definition should be hidden (our implementation or stdlib). This serves as a slight correction to the work in crrev.com/c/1180401 . In particular, this fixes test/fuzz builds with code coverage enabled: make runtests TEST_COVERAGE=1 -j Before this fix, enabling coverage would trigger build errors, like the following: In file included from common/test_util.c:19: include/util.h:82:1: error: attribute declaration must precede definition [-Werror,-Wignored-attributes] __stdlib_compat int atoi(const char *nptr); ^ include/common.h:267:40: note: expanded from macro '__stdlib_compat' #define __stdlib_compat __attribute__((visibility("hidden"))) ^ /usr/include/stdlib.h:361:8: note: previous definition is here __NTH (atoi (const char *__nptr)) Note that enabling sanitizer on some unit tests is still broken (as it was before this CL). For example, these unit tests fail when compiling with sanitizers: make host-charge_manager_drp_charging TEST_ASAN=1 make host-charge_manager_drp_charging TEST_MSAN=1 BRANCH=none BUG=none TEST=make runtests TEST_COVERAGE=1 -j TEST=make buildall -j Change-Id: I74462c964c0ff9d3ee131450e6826cbbd6c89319 Signed-off-by: Craig Hesling <hesling@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1724936 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* fuzz: Hide conflicts with cstdlib and use clang++ for linking.Allen Webb2018-09-071-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | This creates a build target called libec.a by setting the visibility of functions that conflict with cstdlib to hidden. It then links those symbols locally into one large object file that makes up libec.a Fuzzing targets are linked against libec.a so that they can invoke ec functionality while depending on outside libraries that need cstdlib. When linking a particular object against cstdlib, to avoid conflicting function declarations put the following before any includes from the ec codebase: #define __stdlib_compat(...) The fuzzing targets are now linked using clang++, so that c++ libraries and objects can be used as part of the fuzzers. BRANCH=none BUG=chromium:876582 TEST=make -j buildfuzztests && ./build/host/host_command_fuzz/host_command_fuzz.exe Change-Id: Ifdfdc6a51c6ef23b4e192b013ca993bf48a4411b Signed-off-by: Allen Webb <allenwebb@google.com> Reviewed-on: https://chromium-review.googlesource.com/1180401 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* stm32: add TRNG supportVincent Palatin2017-02-231-0/+10
| | | | | | | | | | | | | | | | | Add a driver for the STM32 True Random Number Generator. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=chrome-os-partner:62991 TEST=adhoc on STM32L, craft console command and generate/dump buffers of random numbers. Change-Id: Ie7ce890cfc36a3b9a277715b17051e3e42fdfc96 Reviewed-on: https://chromium-review.googlesource.com/445777 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* Cr50: Ensure that trng.h is self-contained.Carl Hamilton2016-12-081-0/+1
| | | | | | | | | | | | | | | | | * Include trng.h from trng.c before any other header to verify that the header is self-contained. * Add inclusion of stdint.h to trng.h to provide definition for uint32_t. BUG=none BRANCH=none TEST=make -j buildall Change-Id: I78fb6d915c357236ca0fed2a57f093f0eec07fe9 Reviewed-on: https://chromium-review.googlesource.com/417424 Commit-Ready: Carl Hamilton <carlh@chromium.org> Tested-by: Carl Hamilton <carlh@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* Enforce compilation without system headersStefan Reinauer2016-02-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces HOST_CPPFLAGS to be used for all objects being compiled with HOSTCC rather then the target compiler. Since glibc is not linked into the EC, no glibc include files should be included in the EC code base. Hence, create local definitions for clock_t and wchar_t that match what the glibc include would have done, and remove some unneeded includes. Due to very eager optimization, we have to give gcc a little notch to not kick out memset. Signed-off-by: Stefan Reinauer <reinauer@chromium.org> BUG=chrome-os-partner:43025 BUG=chrome-os-partner:49517 BRANCH=none TEST=compile tested Change-Id: Idf3a2881fa8352756b0927b09c6a97473358f239 Reviewed-on: https://chromium-review.googlesource.com/322435 Commit-Ready: Patrick Georgi <pgeorgi@chromium.org> Tested-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
* Move rand_bytes implementation from tpm2 to chip/g.nagendra modadugu2015-12-221-0/+9
| | | | | | | | | | | | | BRANCH=none TEST=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 Signed-off-by: nagendra modadugu <ngm@google.com> Change-Id: Ic7a850fdf2594ac1981237edda8dceb16cc7cbe6 Reviewed-on: https://chromium-review.googlesource.com/319155 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* common: expose true random number generator APIVadim Bendebury2015-10-171-0/+22
When supported, the true random number generator provide to API calls, to initialize it and to retrieve a random number. BRANCH=none BUG=chrome-os-partner:43025 TEST=with other patches in place TPM2 gets proper random numbers stream. Change-Id: I11effdf6f81ca76581a354218203620708195b2b Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/306688 Reviewed-by: Bill Richardson <wfrichar@chromium.org>