summaryrefslogtreecommitdiff
path: root/chip/host/trng.c
diff options
context:
space:
mode:
authorCraig Hesling <hesling@chromium.org>2019-07-01 12:21:49 -0700
committerCommit Bot <commit-bot@chromium.org>2019-07-18 00:15:57 +0000
commitdca00fcd76546d28f64dfc805c548d9fb34a7ba4 (patch)
tree22c7fd5a2c1d31dcd1e6fb0541b74180aba4213f /chip/host/trng.c
parent048e8abbb05ec7758045cb43dbc71fa1ecc93fbe (diff)
downloadchrome-ec-dca00fcd76546d28f64dfc805c548d9fb34a7ba4.tar.gz
chip/host: Add spi+trng support, and add gpio func
This adds fake SPI Master and TRNG support to the host target. This change also adds the missing emulated gpio interface function. Although general purpose, these changes are setup for allowing fuzzing of the FPMCU specific host commands. Thus, they do not impact any outstanding code. BRANCH=none BUG=b:116065496 TEST=make buildall -j Change-Id: Icfc40e7bf8ee421a4c3ad15377fd56ae68c763d7 Signed-off-by: Craig Hesling <hesling@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1684223 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/host/trng.c')
-rw-r--r--chip/host/trng.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/chip/host/trng.c b/chip/host/trng.c
new file mode 100644
index 0000000000..e27dc9d607
--- /dev/null
+++ b/chip/host/trng.c
@@ -0,0 +1,36 @@
+
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Dummy TRNG driver for unit test.
+ *
+ * Although a TRNG is designed to be anything but predictable,
+ * this implementation strives to be as predictable and defined
+ * as possible to allow reproducing unit tests and fuzzer crashes.
+ */
+
+#include <stdint.h>
+#include <stdlib.h> /* Only valid for host */
+
+#include "common.h"
+
+static unsigned int seed;
+
+test_mockable void init_trng(void)
+{
+ seed = 0;
+ srand(seed);
+}
+
+test_mockable void exit_trng(void)
+{
+}
+
+test_mockable void rand_bytes(void *buffer, size_t len)
+{
+ uint8_t *b, *end;
+
+ for (b = buffer, end = b+len; b != end; b++)
+ *b = (uint8_t)rand_r(&seed);
+}