summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile12
-rw-r--r--board/hatch_fp/build.mk1
-rw-r--r--board/nocturne_fp/build.mk1
-rw-r--r--board/nucleo-dartmonkey/build.mk1
-rw-r--r--board/nucleo-f412zg/build.mk1
-rw-r--r--board/nucleo-h743zi/build.mk1
-rw-r--r--test/boringssl_crypto.cc35
-rw-r--r--test/boringssl_crypto.tasklist9
-rw-r--r--test/build.mk2
-rwxr-xr-xtest/run_device_tests.py1
-rw-r--r--test/test_config.h4
-rw-r--r--third_party/boringssl/common/build.mk8
-rw-r--r--third_party/boringssl/common/sysrand.c20
13 files changed, 96 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index a8b282c613..f72eb9b65a 100644
--- a/Makefile
+++ b/Makefile
@@ -290,6 +290,11 @@ include test/build.mk
include util/build.mk
include util/lock/build.mk
+
+ifeq ($(CONFIG_BORINGSSL_CRYPTO), y)
+include third_party/boringssl/common/build.mk
+endif
+
includes+=$(includes-y)
# Wrapper for fetching all the sources relevant to this build
@@ -326,6 +331,10 @@ all-obj-$(1)+=$(call objs_from_dir_p,fuzz,$(PROJECT),$(1))
else
all-obj-$(1)+=$(call objs_from_dir_p,test,$(PROJECT),$(1))
endif
+ifeq ($(CONFIG_BORINGSSL_CRYPTO), y)
+all-obj-$(1)+= \
+ $(call objs_from_dir_p,third_party/boringssl/common,boringssl,$(1))
+endif
endef
# Get all sources to build
@@ -372,6 +381,9 @@ dirs+=builtin
else
dirs+=libc
endif
+ifeq ($(CONFIG_BORINGSSL_CRYPTO), y)
+dirs+=third_party/boringssl/common
+endif
common_dirs=util
ifeq ($(custom-ro_objs-y),)
diff --git a/board/hatch_fp/build.mk b/board/hatch_fp/build.mk
index 5e7af56ae2..ed9809843b 100644
--- a/board/hatch_fp/build.mk
+++ b/board/hatch_fp/build.mk
@@ -30,6 +30,7 @@ test-list-y=\
aes \
always_memset \
benchmark \
+ boringssl_crypto \
cec \
compile_time_macros \
cortexm_fpu \
diff --git a/board/nocturne_fp/build.mk b/board/nocturne_fp/build.mk
index e36309c4f0..6bf33696d5 100644
--- a/board/nocturne_fp/build.mk
+++ b/board/nocturne_fp/build.mk
@@ -30,6 +30,7 @@ test-list-y=\
aes \
always_memset \
benchmark \
+ boringssl_crypto \
cec \
compile_time_macros \
cortexm_fpu \
diff --git a/board/nucleo-dartmonkey/build.mk b/board/nucleo-dartmonkey/build.mk
index fbf78d16b7..de08959fa9 100644
--- a/board/nucleo-dartmonkey/build.mk
+++ b/board/nucleo-dartmonkey/build.mk
@@ -13,6 +13,7 @@ board-y+=fpsensor_detect.o
test-list-y=\
abort \
aes \
+ boringssl_crypto \
cec \
compile_time_macros \
crc \
diff --git a/board/nucleo-f412zg/build.mk b/board/nucleo-f412zg/build.mk
index 8299781a6f..c31e640099 100644
--- a/board/nucleo-f412zg/build.mk
+++ b/board/nucleo-f412zg/build.mk
@@ -12,6 +12,7 @@ board-y=board.o
test-list-y=\
abort \
aes \
+ boringssl_crypto \
cec \
compile_time_macros \
crc \
diff --git a/board/nucleo-h743zi/build.mk b/board/nucleo-h743zi/build.mk
index 575a6d5da3..932793898a 100644
--- a/board/nucleo-h743zi/build.mk
+++ b/board/nucleo-h743zi/build.mk
@@ -12,6 +12,7 @@ board-y=board.o
test-list-y=\
abort \
aes \
+ boringssl \
cec \
compile_time_macros \
crc \
diff --git a/test/boringssl_crypto.cc b/test/boringssl_crypto.cc
new file mode 100644
index 0000000000..bc7bd5dffe
--- /dev/null
+++ b/test/boringssl_crypto.cc
@@ -0,0 +1,35 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "common.h"
+#include "openssl/bn.h"
+#include "openssl/ec.h"
+#include "openssl/mem.h"
+#include "openssl/obj_mac.h"
+#include "openssl/rand.h"
+#include "test_util.h"
+#include "util.h"
+
+test_static enum ec_error_list test_rand(void)
+{
+ constexpr uint8_t zero[256] = { 0 };
+ uint8_t buf1[256];
+ uint8_t buf2[256];
+
+ RAND_bytes(buf1, sizeof(buf1));
+ RAND_bytes(buf2, sizeof(buf2));
+
+ TEST_ASSERT_ARRAY_NE(buf1, zero, sizeof(zero));
+ TEST_ASSERT_ARRAY_NE(buf2, zero, sizeof(zero));
+ TEST_ASSERT_ARRAY_NE(buf1, buf2, sizeof(buf1));
+
+ return EC_SUCCESS;
+}
+
+extern "C" void run_test(int argc, const char **argv)
+{
+ RUN_TEST(test_rand);
+ test_print_result();
+}
diff --git a/test/boringssl_crypto.tasklist b/test/boringssl_crypto.tasklist
new file mode 100644
index 0000000000..d1920322a9
--- /dev/null
+++ b/test/boringssl_crypto.tasklist
@@ -0,0 +1,9 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST
diff --git a/test/build.mk b/test/build.mk
index d948fd5f6e..d90e8daf26 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -28,6 +28,7 @@ test-list-host += benchmark
test-list-host += bklight_lid
test-list-host += bklight_passthru
test-list-host += body_detection
+test-list-host += boringssl_crypto
test-list-host += button
test-list-host += cbi
test-list-host += cbi_wp
@@ -181,6 +182,7 @@ benchmark-y=benchmark.o
bklight_lid-y=bklight_lid.o
bklight_passthru-y=bklight_passthru.o
body_detection-y=body_detection.o body_detection_data_literals.o motion_common.o
+boringssl_crypto-y=boringssl_crypto.o
button-y=button.o
cbi-y=cbi.o
cbi_wp-y=cbi_wp.o
diff --git a/test/run_device_tests.py b/test/run_device_tests.py
index dc454527e7..e874d08bb7 100755
--- a/test/run_device_tests.py
+++ b/test/run_device_tests.py
@@ -230,6 +230,7 @@ class AllTests:
TestConfig(test_name="aes"),
TestConfig(test_name="always_memset"),
TestConfig(test_name="benchmark"),
+ TestConfig(test_name="boringssl_crypto"),
TestConfig(test_name="cec"),
TestConfig(test_name="cortexm_fpu"),
TestConfig(test_name="crc"),
diff --git a/test/test_config.h b/test/test_config.h
index 51c15f4c8c..033ee966b7 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -114,6 +114,10 @@
#define CONFIG_SHA256
#endif
+#if defined(TEST_BORINGSSL_CRYPTO)
+#define CONFIG_BORINGSSL_CRYPTO
+#endif
+
#ifdef TEST_ROLLBACK_SECRET
#define CONFIG_ROLLBACK
#define CONFIG_ROLLBACK_SECRET_SIZE 32
diff --git a/third_party/boringssl/common/build.mk b/third_party/boringssl/common/build.mk
new file mode 100644
index 0000000000..b7848d121b
--- /dev/null
+++ b/third_party/boringssl/common/build.mk
@@ -0,0 +1,8 @@
+# Copyright 2023 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# EC OS Support Files for BoringSSL
+#
+
+boringssl-y+=sysrand.o
diff --git a/third_party/boringssl/common/sysrand.c b/third_party/boringssl/common/sysrand.c
new file mode 100644
index 0000000000..74e058f892
--- /dev/null
+++ b/third_party/boringssl/common/sysrand.c
@@ -0,0 +1,20 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Implement the boringssl sysrand from EC TRNG. */
+
+#include "trng.h"
+
+void CRYPTO_sysrand(uint8_t *out, size_t requested)
+{
+ trng_init();
+ trng_rand_bytes(out, requested);
+ trng_exit();
+}
+
+void CRYPTO_sysrand_for_seed(uint8_t *out, size_t requested)
+{
+ return CRYPTO_sysrand(out, requested);
+}