From 7936f8bcf9ecd7fb3defaf8eecd3badf5ff63ad9 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Sun, 19 Nov 2023 18:49:30 -0800 Subject: [PATCH] [core] add missing platform function for `OT_PLATFORM_KEY_REF` (#9620) This commit contains the following changes: - Adds `CMake` option `OT_PLATFORM_KEY_REF`, corresponding to the existing `OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE` config. - Add empty implementations of `otPlatCryptoEcdsa{}` under the simulation platform. - Modifies `test_platform.cpp` to ensure that the key-ref related APIs are defined only when the key reference feature is enabled. - Updates `toranj/build.sh` script to provide the option to enable the key reference feature. - Updates GitHub workflow to validate build with key reference feature under simulation platform, ensuring that future PRs are validated with this feature enabled. --- .github/workflows/toranj.yml | 2 ++ etc/cmake/options.cmake | 1 + examples/platforms/simulation/crypto.c | 37 ++++++++++++++++++++++++++ tests/toranj/build.sh | 23 ++++++++++++++-- tests/unit/test_platform.cpp | 4 +-- 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/.github/workflows/toranj.yml b/.github/workflows/toranj.yml index 960d52ac4..cb7ffc4d0 100644 --- a/.github/workflows/toranj.yml +++ b/.github/workflows/toranj.yml @@ -149,6 +149,8 @@ jobs: ./tests/toranj/build.sh posix-15.4+trel git clean -dfx ./tests/toranj/build.sh posix-trel + git clean -dfx + ./tests/toranj/build.sh --enable-plat-key-ref all upload-coverage: needs: diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index 6d3bd5c75..5f5d96863 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -227,6 +227,7 @@ ot_option(OT_OPERATIONAL_DATASET_AUTO_INIT OPENTHREAD_CONFIG_OPERATIONAL_DATASET ot_option(OT_OTNS OPENTHREAD_CONFIG_OTNS_ENABLE "OTNS") ot_option(OT_PING_SENDER OPENTHREAD_CONFIG_PING_SENDER_ENABLE "ping sender" ${OT_APP_CLI}) ot_option(OT_PLATFORM_BOOTLOADER_MODE OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE "platform bootloader mode") +ot_option(OT_PLATFORM_KEY_REF OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE "platform key reference secure storage") ot_option(OT_PLATFORM_NETIF OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE "platform netif") ot_option(OT_PLATFORM_UDP OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE "platform UDP") ot_option(OT_REFERENCE_DEVICE OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE "test harness reference device") diff --git a/examples/platforms/simulation/crypto.c b/examples/platforms/simulation/crypto.c index b220f7cb5..20c151b46 100644 --- a/examples/platforms/simulation/crypto.c +++ b/examples/platforms/simulation/crypto.c @@ -81,4 +81,41 @@ bool otPlatCryptoHasKey(otCryptoKeyRef aKeyRef) return false; } +otError otPlatCryptoEcdsaGenerateAndImportKey(otCryptoKeyRef aKeyRef) +{ + OT_UNUSED_VARIABLE(aKeyRef); + + return OT_ERROR_NONE; +} + +otError otPlatCryptoEcdsaExportPublicKey(otCryptoKeyRef aKeyRef, otPlatCryptoEcdsaPublicKey *aPublicKey) +{ + OT_UNUSED_VARIABLE(aKeyRef); + OT_UNUSED_VARIABLE(aPublicKey); + + return OT_ERROR_NONE; +} + +otError otPlatCryptoEcdsaSignUsingKeyRef(otCryptoKeyRef aKeyRef, + const otPlatCryptoSha256Hash *aHash, + otPlatCryptoEcdsaSignature *aSignature) +{ + OT_UNUSED_VARIABLE(aKeyRef); + OT_UNUSED_VARIABLE(aHash); + OT_UNUSED_VARIABLE(aSignature); + + return OT_ERROR_NONE; +} + +otError otPlatCryptoEcdsaVerifyUsingKeyRef(otCryptoKeyRef aKeyRef, + const otPlatCryptoSha256Hash *aHash, + const otPlatCryptoEcdsaSignature *aSignature) +{ + OT_UNUSED_VARIABLE(aKeyRef); + OT_UNUSED_VARIABLE(aHash); + OT_UNUSED_VARIABLE(aSignature); + + return OT_ERROR_NONE; +} + #endif // OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE diff --git a/tests/toranj/build.sh b/tests/toranj/build.sh index cdf6c3614..0c9a6983c 100755 --- a/tests/toranj/build.sh +++ b/tests/toranj/build.sh @@ -50,7 +50,8 @@ display_usage() echo " posix-15.4+trel : Build OpenThread POSIX - multi radio (15.4+TREL)" echo "" echo "Options:" - echo " -c/--enable-coverage Enable code coverage" + echo " -c/--enable-coverage Enable code coverage" + echo " -k/--enable-plat-key-ref Enable OT_PLATFORM_KEY_REF" echo "" } @@ -64,6 +65,7 @@ cd "$(dirname "$0")" || die "cd failed" cd ../.. || die "cd failed" ot_coverage=OFF +ot_plat_key_ref=OFF while [ $# -ge 2 ]; do case $1 in @@ -74,6 +76,10 @@ while [ $# -ge 2 ]; do -t | --enable-tests) shift ;; + -k | --enable-plat-key-ref) + ot_plat_key_ref=ON + shift + ;; "") shift ;; @@ -108,7 +114,7 @@ case ${build_config} in cd "${top_builddir}" || die "cd failed" cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ - -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \ + -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -122,6 +128,7 @@ case ${build_config} in cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ -DOT_15_4=ON -DOT_TREL=OFF -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -136,6 +143,7 @@ case ${build_config} in cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ -DOT_15_4=OFF -DOT_TREL=ON -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -150,6 +158,7 @@ case ${build_config} in cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ -DOT_15_4=ON -DOT_TREL=ON -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -163,6 +172,7 @@ case ${build_config} in cd "${top_builddir}" || die "cd failed" cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=ON -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -176,6 +186,7 @@ case ${build_config} in cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=ON -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \ -DOT_15_4=ON -DOT_TREL=OFF \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -190,6 +201,7 @@ case ${build_config} in cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=ON -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \ -DOT_15_4=OFF -DOT_TREL=ON \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -204,6 +216,7 @@ case ${build_config} in cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=ON -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \ -DOT_15_4=ON -DOT_TREL=ON \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -217,6 +230,7 @@ case ${build_config} in cd "${top_builddir}" || die "cd failed" cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=OFF -DOT_APP_NCP=OFF -DOT_APP_RCP=ON \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -229,6 +243,7 @@ case ${build_config} in cd "${top_builddir}" || die "cd failed" cmake -GNinja -DOT_PLATFORM=posix -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-posix.h \ "${top_srcdir}" || die ninja || die @@ -242,6 +257,7 @@ case ${build_config} in cmake -GNinja -DOT_PLATFORM=posix -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ -DOT_15_4=ON -DOT_TREL=OFF \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-posix.h \ "${top_srcdir}" || die ninja || die @@ -255,6 +271,7 @@ case ${build_config} in cmake -GNinja -DOT_PLATFORM=posix -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ -DOT_15_4=OFF -DOT_TREL=ON \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-posix.h \ "${top_srcdir}" || die ninja || die @@ -268,6 +285,7 @@ case ${build_config} in cmake -GNinja -DOT_PLATFORM=posix -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ -DOT_15_4=ON -DOT_TREL=ON \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-posix.h \ "${top_srcdir}" || die ninja || die @@ -280,6 +298,7 @@ case ${build_config} in cd "${top_builddir}" || die "cd failed" cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=ON \ + -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \ -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index 6980666cb..21718f1d3 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -478,8 +478,6 @@ bool otPlatCryptoHasKey(otCryptoKeyRef aKeyRef) return false; } -#endif // OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE - otError otPlatCryptoEcdsaGenerateAndImportKey(otCryptoKeyRef aKeyRef) { OT_UNUSED_VARIABLE(aKeyRef); @@ -517,6 +515,8 @@ otError otPlatCryptoEcdsaVerifyUsingKeyRef(otCryptoKeyRef aKe return OT_ERROR_NONE; } +#endif // OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE + otError otPlatRadioSetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t aThreshold) { OT_UNUSED_VARIABLE(aInstance);