Merge remote-tracking branch 'origin/upstream/master' into HEAD Bug: 86669 Change-Id: I987ae6564601ab7ae399d7a1c5f85ce436f3254c
diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 0000000..91aee7f --- /dev/null +++ b/BUILD.gn
@@ -0,0 +1,99 @@ +# Copyright 2020 The Fuchsia Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//build/components.gni") + +# micro-ecc library +source_set("micro-ecc") { + sources = [ "uECC.c" ] + public = [ + "asm_arm.inc", + "asm_arm_mult_square.inc", + "asm_arm_mult_square_umaal.inc", + "asm_avr.inc", + "asm_avr_mult_square.inc", + "curve-specific.inc", + "platform-specific.inc", + "types.h", + "uECC.h", + "uECC_vli.h", + ] + public_configs = [ ":micro-ecc_config" ] + deps = [ + ":micro-ecc-headers", + "//zircon/system/ulib/zx", + ] + + # TODO(fxb/58162): delete the below and fix compiler warnings + configs += [ "//build/config:Wno-conversion" ] +} + +copy("micro-ecc-headers") { + sources = [ + "types.h", + "uECC.h", + "uECC_vli.h", + ] + outputs = [ "$target_gen_dir/include/micro-ecc/{{source_file_part}}" ] +} + +config("micro-ecc_config") { + include_dirs = [ + "$target_gen_dir/include", + "$target_gen_dir/include/micro-ecc", + ] + + # TODO(fxb/53953): Dependent libraries assume this word size, which should + # work for arm, arm64, x86, and x86_64 variants. After unwinding those + # assumptions, uECC_WORD_SIZE should be removed from this config. + defines = [ + "uECC_ENABLE_VLI_API", + "uECC_WORD_SIZE=4", + ] +} + +# micro-ecc test binaries +template("micro_ecc_test") { + assert(defined(invoker.sources), "must specify sources") + executable("${target_name}_bin") { + testonly = true + visibility = [ ":*" ] + sources = invoker.sources + configs += [ ":micro-ecc-test_config" ] + deps = [ ":micro-ecc" ] + } + fuchsia_unittest_component(target_name) { + deps = [ ":${target_name}_bin" ] + } +} + +micro_ecc_test("compress_test") { + sources = [ "test/test_compress.c" ] +} + +micro_ecc_test("compute_test") { + sources = [ "test/test_compute.c" ] +} + +micro_ecc_test("ecdh_test") { + sources = [ "test/test_ecdh.c" ] +} + +micro_ecc_test("ecdsa_test") { + sources = [ "test/test_ecdsa.c" ] +} + +config("micro-ecc-test_config") { + configs = [ ":micro-ecc_config" ] +} + +# micro-ecc test package +fuchsia_test_package("micro-ecc-tests") { + test_components = [ + ":compress_test", + ":compute_test", + ":ecdh_test", + ":ecdsa_test", + ] +}
diff --git a/OWNERS b/OWNERS new file mode 100644 index 0000000..b616bfa --- /dev/null +++ b/OWNERS
@@ -0,0 +1 @@ +prashanthsw@google.com
diff --git a/README.fuchsia b/README.fuchsia new file mode 100644 index 0000000..c446f58 --- /dev/null +++ b/README.fuchsia
@@ -0,0 +1,13 @@ +Name: uECC +License: BSD 2-Clause "Simplified" License +License File: LICENSE.txt +Upstream git: https://github.com/kmackay/micro-ecc +Description: + +A small and fast ECDH and ECDSA implementation for 8-bit, 32-bit, and 64-bit processors. + +Local Modifications: + +Added README.fuchsia. +Added GN build rules. +Added implementation of default_RNG for Fuchsia in platform-specific.inc.
diff --git a/platform-specific.inc b/platform-specific.inc index 7e0373f..c1b551d 100644 --- a/platform-specific.inc +++ b/platform-specific.inc
@@ -66,6 +66,18 @@ } #define default_RNG_defined 1 +#elif defined(__Fuchsia__) + +#include <sys/types.h> +#include <unistd.h> +#include <zircon/syscalls.h> + +static int default_RNG(uint8_t *dest, unsigned size) { + zx_cprng_draw(dest, size); + return 1; +} +#define default_RNG_defined 1 + #elif defined(RIOT_VERSION) #include <random.h>