From 3230545d5f9af6a45a80e206d51220f151608a51 Mon Sep 17 00:00:00 2001 From: Thomas Cuyckens Date: Tue, 23 Jan 2024 20:00:37 +0100 Subject: [PATCH] feat(mbedtls): upgrade to mbedtls v3.3.0 * upgrade to mbedtls v3.3.0 * minor fixes to all platforms * some cmake refactoring --- CMakeLists.txt | 35 +- etc/options.cmake | 6 + script/build | 4 +- src/gp712/CMakeLists.txt | 44 +- src/gp712/openthread-core-gp712-config.h | 10 - src/gp712/radio.c | 33 +- src/gp712/uart-posix.c | 4 +- src/qpg6105/CMakeLists.txt | 68 +- src/qpg6105/crypto/aes_alt.h | 230 ------ src/qpg6105/crypto/ccm_alt.h | 163 ----- src/qpg6105/crypto/common-mbedtls-config.h | 119 ++++ src/qpg6105/crypto/ecjpake_alt.h | 233 ------- src/qpg6105/crypto/ecp_alt.h | 657 ------------------ src/qpg6105/crypto/qpg6105-mbedtls-config.h | 28 +- src/qpg6105/crypto/sha256_alt.h | 194 ------ src/qpg6105/openthread-core-qpg6105-config.h | 16 +- src/qpg6105/platform.c | 6 +- src/qpg6105/radio.c | 38 +- src/qpg6105/{settings.cpp => settings.c} | 2 +- src/qpg7015m/CMakeLists.txt | 44 +- .../openthread-core-qpg7015m-config.h | 10 - src/qpg7015m/radio.c | 43 +- src/qpg7015m/uart-posix.c | 4 +- third_party/Qorvo/CMakeLists.txt | 57 +- third_party/Qorvo/repo | 2 +- 25 files changed, 348 insertions(+), 1702 deletions(-) delete mode 100644 src/qpg6105/crypto/aes_alt.h delete mode 100644 src/qpg6105/crypto/ccm_alt.h create mode 100644 src/qpg6105/crypto/common-mbedtls-config.h delete mode 100644 src/qpg6105/crypto/ecjpake_alt.h delete mode 100644 src/qpg6105/crypto/ecp_alt.h mode change 100755 => 100644 src/qpg6105/crypto/qpg6105-mbedtls-config.h delete mode 100644 src/qpg6105/crypto/sha256_alt.h rename src/qpg6105/{settings.cpp => settings.c} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a369b432..0588ab7e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,16 +34,23 @@ set(QORVO_PLATFORM_VALUES "qpg6105" "qpg7015m" ) +set(QORVO_MBEDTLS_USED + "qpg6105" +) + set_property(CACHE QORVO_PLATFORM PROPERTY STRINGS ${QORVO_PLATFORM_VALUES}) if(NOT QORVO_PLATFORM IN_LIST QORVO_PLATFORM_VALUES) message(FATAL_ERROR "Please select a supported platform: ${QORVO_PLATFORM_VALUES}") endif() -set(OT_PLATFORM_LIB_FTD "openthread-${QORVO_PLATFORM}-ftd") -set(OT_PLATFORM_LIB_MTD "openthread-${QORVO_PLATFORM}-mtd") -set(OT_PLATFORM_LIB_RCP "openthread-${QORVO_PLATFORM}-ftd") -set(OT_PLATFORM_LIB "openthread-${QORVO_PLATFORM}-ftd") - +if (QORVO_PLATFORM IN_LIST QORVO_MBEDTLS_USED) + set(OT_BUILTIN_MBEDTLS_MANAGEMENT OFF CACHE BOOL "disable builtin mbedtls management" FORCE) + set(OT_EXTERNAL_MBEDTLS "qorvo-mbedtls" CACHE STRING "use qorvo mbedtls" FORCE) + set(OT_MBEDTLS ${OT_EXTERNAL_MBEDTLS}) + set(QORVO_MBEDTLS 1) +else() + set(QORVO_MBEDTLS 0) +endif() set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) @@ -53,15 +60,31 @@ if (DEFINED ENV{QORVO_OT_SDK}) SET(SDK_DIR "$ENV{QORVO_OT_SDK}") else() SET(SDK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/Qorvo/repo") + if(NOT EXISTS ${SDK_DIR}/${QORVO_PLATFORM}) + message(FATAL_ERROR "Please select a correct SDK directory: ${SDK_DIR}/${QORVO_PLATFORM} does not exist") + endif() endif() +set(PLATFORM_TARGET_FTD "openthread-${QORVO_PLATFORM}-ftd") +set(PLATFORM_DRIVER_FTD "${QORVO_PLATFORM}-driver-ftd") +set(OT_PLATFORM_LIB_FTD "${PLATFORM_TARGET_FTD}") + +set(PLATFORM_TARGET_MTD "openthread-${QORVO_PLATFORM}-mtd") +set(PLATFORM_DRIVER_MTD "${QORVO_PLATFORM}-driver-mtd") +set(OT_PLATFORM_LIB_MTD "${PLATFORM_TARGET_MTD}") + +set(PLATFORM_TARGET_RCP "openthread-${QORVO_PLATFORM}-ftd") +set(PLATFORM_DRIVER_RCP "${QORVO_PLATFORM}-driver-ftd") +set(OT_PLATFORM_LIB_RCP "${PLATFORM_TARGET_RCP}") + include("${PROJECT_SOURCE_DIR}/etc/options.cmake") set(OPENTHREAD_DIR ${PROJECT_SOURCE_DIR}/openthread) add_subdirectory(${OPENTHREAD_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) target_compile_definitions(ot-config INTERFACE - OPENTHREAD_PLATFORM_CORE_CONFIG_FILE="openthread-core-${QORVO_PLATFORM}-config.h" + OPENTHREAD_CONFIG_FILE="openthread-core-${QORVO_PLATFORM}-config.h" + OPENTHREAD_PROJECT_CORE_CONFIG_FILE="openthread-core-${QORVO_PLATFORM}-config.h" OPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE="openthread-core-${QORVO_PLATFORM}-config-check.h" ) diff --git a/etc/options.cmake b/etc/options.cmake index f88a0d436..f3cd2aff5 100644 --- a/etc/options.cmake +++ b/etc/options.cmake @@ -34,3 +34,9 @@ endif() # Uart transport option option(OT_QORVO_SOCKET "enable socket interface for uart transport on RPi based platforms" OFF) + +# Number of supported children +option(OT_QORVO_SUPPORTED_CHILDREN "The amount of children supported on the platform" OFF) +if (OT_QORVO_SUPPORTED_CHILDREN) + add_definitions(-DOPENTHREAD_CONFIG_MLE_MAX_CHILDREN=${OT_QORVO_SUPPORTED_CHILDREN}) +endif() diff --git a/script/build b/script/build index 2576d8168..6ee8ed3db 100755 --- a/script/build +++ b/script/build @@ -97,11 +97,11 @@ main() case "${platform}" in qpg6105) - find "${builddir}/bin" -type f -executable -not -name '*.*' -not -name "${platform}-*" \ + find "${builddir}/bin" -type f -executable -not -name '*.*' -not -name "${platform}-*" -not -name "*-test-*" \ -execdir sh -c 'x="$1"; arm-none-eabi-objcopy -O ihex "$1" "$2-$(basename ${x}).hex"' _ {} "${platform}" \; ;; esac - find "${builddir}/bin" -type f -executable -not -name '*.*' -not -name "${platform}-*" \ + find "${builddir}/bin" -type f -executable -not -name '*.*' -not -name "${platform}-*" -not -name "*-test-*" \ -execdir sh -c 'x="$1"; mv "$x" "$2-$(basename ${x}).elf"' _ {} "${platform}" \; } diff --git a/src/gp712/CMakeLists.txt b/src/gp712/CMakeLists.txt index c97084aee..d2503c439 100644 --- a/src/gp712/CMakeLists.txt +++ b/src/gp712/CMakeLists.txt @@ -32,7 +32,7 @@ list(APPEND OT_PLATFORM_DEFINES ) target_compile_definitions(ot-config INTERFACE - "MBEDTLS_USER_CONFIG_FILE=\"gp712-mbedtls-config.h\"" + "MBEDTLS_USER_CONFIG_FILE=\"${QORVO_PLATFORM}-mbedtls-config.h\"" ) list(APPEND OT_PUBLIC_INCLUDES @@ -43,14 +43,6 @@ set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) set(OT_PUBLIC_INCLUDES ${OT_PUBLIC_INCLUDES} PARENT_SCOPE) -if(OT_CFLAGS MATCHES "-pedantic-errors") - string(REPLACE "-pedantic-errors" "" OT_CFLAGS "${OT_CFLAGS}") -endif() - -if(OT_CFLAGS MATCHES "-Wno-c\\+\\+14-compat") - string(REPLACE "-Wno-c++14-compat" "" OT_CFLAGS "${OT_CFLAGS}") -endif() - set(PLATFORM_SOURCES alarm.c diag.c @@ -72,22 +64,21 @@ else() ) endif() -add_library(openthread-gp712-ftd +add_library(${PLATFORM_TARGET_FTD} STATIC ${PLATFORM_SOURCES} ) -set_target_properties( - openthread-gp712-ftd +set_target_properties(${PLATFORM_TARGET_FTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 11 + CXX_STANDARD 14 ) -target_link_libraries(openthread-gp712-ftd +target_link_libraries(${PLATFORM_TARGET_FTD} PRIVATE -Wl,--start-group - gp712-driver-ftd + ${PLATFORM_DRIVER_FTD} ${OT_MBEDTLS} ot-config -Wl,--end-group @@ -98,38 +89,37 @@ target_link_libraries(openthread-gp712-ftd -Wl,-Map=$.map ) -target_compile_definitions(openthread-gp712-ftd +target_compile_definitions(${PLATFORM_TARGET_FTD} PUBLIC ${OT_PLATFORM_DEFINES} ) -target_compile_options(openthread-gp712-ftd +target_compile_options(${PLATFORM_TARGET_FTD} PRIVATE ${OT_CFLAGS} ) -target_include_directories(openthread-gp712-ftd +target_include_directories(${PLATFORM_TARGET_FTD} PRIVATE ${OT_PUBLIC_INCLUDES} ${OPENTHREAD_DIR}/examples/platforms ) -add_library(openthread-gp712-mtd +add_library(${PLATFORM_TARGET_MTD} STATIC ${PLATFORM_SOURCES} ) -set_target_properties( - openthread-gp712-mtd +set_target_properties(${PLATFORM_TARGET_MTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 11 + CXX_STANDARD 14 ) -target_link_libraries(openthread-gp712-mtd +target_link_libraries(${PLATFORM_TARGET_MTD} PRIVATE -Wl,--start-group - gp712-driver-mtd + ${PLATFORM_DRIVER_MTD} ${OT_MBEDTLS} ot-config -Wl,--end-group @@ -140,17 +130,17 @@ target_link_libraries(openthread-gp712-mtd -Wl,-Map=$.map ) -target_compile_definitions(openthread-gp712-mtd +target_compile_definitions(${PLATFORM_TARGET_MTD} PUBLIC ${OT_PLATFORM_DEFINES} ) -target_compile_options(openthread-gp712-mtd +target_compile_options(${PLATFORM_TARGET_MTD} PRIVATE ${OT_CFLAGS} ) -target_include_directories(openthread-gp712-mtd +target_include_directories(${PLATFORM_TARGET_MTD} PRIVATE ${OT_PUBLIC_INCLUDES} ${OPENTHREAD_DIR}/examples/platforms diff --git a/src/gp712/openthread-core-gp712-config.h b/src/gp712/openthread-core-gp712-config.h index 3e4c6f7e7..e05e6a70c 100644 --- a/src/gp712/openthread-core-gp712-config.h +++ b/src/gp712/openthread-core-gp712-config.h @@ -116,14 +116,4 @@ #define OPENTHREAD_CONFIG_HEAP_INTERNAL_SIZE (2048 * sizeof(void *)) #endif -/** - * @def OPENTHREAD_CONFIG_TLS_ENABLE - * - * Define as 1 to enable support for TLS over TCP. - * - */ -#ifndef OPENTHREAD_CONFIG_TLS_ENABLE -#define OPENTHREAD_CONFIG_TLS_ENABLE 0 -#endif - #endif // OPENTHREAD_CORE_GP712_CONFIG_H_ diff --git a/src/gp712/radio.c b/src/gp712/radio.c index 45991f4e3..6ab761dd5 100644 --- a/src/gp712/radio.c +++ b/src/gp712/radio.c @@ -36,25 +36,24 @@ #include #include +#include #include "utils/code_utils.h" #include "radio_qorvo.h" -#define QPG_RECEIVE_SENSITIVITY -100 // dBm - -#define IEEE802154_MIN_LENGTH 5 -#define IEEE802154_MAX_LENGTH 127 -#define IEEE802154_ACK_LENGTH 5 -#define IEEE802154_FRAME_TYPE_MASK 0x7 -#define IEEE802154_FRAME_TYPE_ACK 0x2 -#define IEEE802154_FRAME_PENDING 1 << 4 -#define IEEE802154_ACK_REQUEST 1 << 5 -#define IEEE802154_DSN_OFFSET 2 +enum +{ + QPG_RECEIVE_SENSITIVITY = -100, // [dBm] +}; -#define QORVO_RSSI_OFFSET 73 -#define QORVO_CRC_BIT_MASK 0x80 -#define QORVO_LQI_BIT_MASK 0x7f +enum +{ + IEEE802154_ACK_LENGTH = 5, + IEEE802154_FRAME_TYPE_ACK = 0x2, + IEEE802154_FRAME_PENDING = 1 << 4, + IEEE802154_DSN_OFFSET = 2, +}; extern otRadioFrame sTransmitFrame; @@ -225,6 +224,12 @@ void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable) qorvoRadioSetPromiscuous(aEnable); } +uint64_t otPlatTimeGet(void) +{ + // required for RCP/spinel + return qorvoRadioGetNow(); +} + uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); @@ -360,7 +365,7 @@ void cbQorvoRadioTransmitDone(otRadioFrame *aFrame, bool aFramePending, otError ackFrame.mPsdu[1] = 0; ackFrame.mPsdu[2] = aFrame->mPsdu[IEEE802154_DSN_OFFSET]; - otPlatRadioTxDone(pQorvoInstance, aFrame, &ackFrame, aError); + otPlatRadioTxDone(pQorvoInstance, aFrame, (aError == OT_ERROR_NONE) ? &ackFrame : NULL, aError); } int8_t otPlatRadioGetRssi(otInstance *aInstance) diff --git a/src/gp712/uart-posix.c b/src/gp712/uart-posix.c index 1d1875550..b22c19ba1 100644 --- a/src/gp712/uart-posix.c +++ b/src/gp712/uart-posix.c @@ -79,7 +79,7 @@ static void cbKeyPressed(uint8_t Param) { OT_UNUSED_VARIABLE(Param); - qorvoAlarmScheduleEventArg(0, platformDummy, (void *)&s_in_fd); + qorvoAlarmMilliStart(0, platformDummy, (void *)&s_in_fd); } void platformUartRestore(void) @@ -216,7 +216,7 @@ otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength) s_write_buffer = aBuf; s_write_length = aBufLength; - qorvoAlarmScheduleEventArg(0, platformDummy, (void *)&s_in_fd); + qorvoAlarmMilliStart(0, platformDummy, (void *)&s_in_fd); exit: return error; diff --git a/src/qpg6105/CMakeLists.txt b/src/qpg6105/CMakeLists.txt index c7ae10865..7bc0471aa 100755 --- a/src/qpg6105/CMakeLists.txt +++ b/src/qpg6105/CMakeLists.txt @@ -27,23 +27,18 @@ # target_compile_definitions(ot-config INTERFACE - "MBEDTLS_USER_CONFIG_FILE=\"qpg6105-mbedtls-config.h\"" + "MBEDTLS_CONFIG_FILE=\"${QORVO_PLATFORM}-mbedtls-config.h\"" ) list(APPEND OT_PUBLIC_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/crypto" ) -set(OT_PUBLIC_INCLUDES ${OT_PUBLIC_INCLUDES} PARENT_SCOPE) -if(OT_CFLAGS MATCHES "-pedantic-errors") - string(REPLACE "-pedantic-errors" "" OT_CFLAGS "${OT_CFLAGS}") -endif() +set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) -if(OT_CFLAGS MATCHES "-Wno-c\\+\\+14-compat") - string(REPLACE "-Wno-c++14-compat" "" OT_CFLAGS "${OT_CFLAGS}") -endif() +set(OT_PUBLIC_INCLUDES ${OT_PUBLIC_INCLUDES} PARENT_SCOPE) -add_library(openthread-qpg6105-ftd +set(PLATFORM_SOURCES alarm.c diag.c entropy.c @@ -51,92 +46,87 @@ add_library(openthread-qpg6105-ftd misc.c platform.c radio.c - settings.cpp + settings.c uart.c ) -set_target_properties( - openthread-qpg6105-ftd +add_library(${PLATFORM_TARGET_FTD} + STATIC + ${PLATFORM_SOURCES} +) + +set_target_properties(${PLATFORM_TARGET_FTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 11 + CXX_STANDARD 14 ) -target_link_libraries(openthread-qpg6105-ftd +target_link_libraries(${PLATFORM_TARGET_FTD} PRIVATE -Wl,--start-group - qpg6105-driver-ftd + ${PLATFORM_DRIVER_FTD} ${OT_MBEDTLS} ot-config -Wl,--end-group PUBLIC - -T${SDK_DIR}/qpg6105/ld/qpg6105.ld + -T${SDK_DIR}/${QORVO_PLATFORM}/ld/${QORVO_PLATFORM}.ld -nostdlib -Wl,--gc-sections -Wl,-Map=$.map,--cref ) -target_compile_definitions(openthread-qpg6105-ftd +target_compile_definitions(${PLATFORM_TARGET_FTD} PUBLIC ${OT_PLATFORM_DEFINES} ) -target_compile_options(openthread-qpg6105-ftd +target_compile_options(${PLATFORM_TARGET_FTD} PRIVATE ${OT_CFLAGS} ) -target_include_directories(openthread-qpg6105-ftd +target_include_directories(${PLATFORM_TARGET_FTD} PRIVATE ${OT_PUBLIC_INCLUDES} ${OPENTHREAD_DIR}/examples/platforms ) - -add_library(openthread-qpg6105-mtd - alarm.c - diag.c - entropy.c - logging.c - misc.c - platform.c - radio.c - settings.cpp - uart.c +add_library(${PLATFORM_TARGET_MTD} + STATIC + ${PLATFORM_SOURCES} ) -set_target_properties( - openthread-qpg6105-mtd +set_target_properties(${PLATFORM_TARGET_MTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 11 + CXX_STANDARD 14 ) -target_link_libraries(openthread-qpg6105-mtd +target_link_libraries(${PLATFORM_TARGET_MTD} PRIVATE -Wl,--start-group - qpg6105-driver-mtd + ${PLATFORM_DRIVER_MTD} ${OT_MBEDTLS} ot-config -Wl,--end-group PUBLIC - -T${SDK_DIR}/qpg6105/ld/qpg6105.ld + -T${SDK_DIR}/${QORVO_PLATFORM}/ld/${QORVO_PLATFORM}.ld -nostdlib -Wl,--gc-sections -Wl,-Map=$.map,--cref ) -target_compile_definitions(openthread-qpg6105-mtd +target_compile_definitions(${PLATFORM_TARGET_MTD} PUBLIC ${OT_PLATFORM_DEFINES} ) -target_compile_options(openthread-qpg6105-mtd +target_compile_options(${PLATFORM_TARGET_MTD} PRIVATE ${OT_CFLAGS} ) -target_include_directories(openthread-qpg6105-mtd +target_include_directories(${PLATFORM_TARGET_MTD} PRIVATE ${OT_PUBLIC_INCLUDES} ${OPENTHREAD_DIR}/examples/platforms diff --git a/src/qpg6105/crypto/aes_alt.h b/src/qpg6105/crypto/aes_alt.h deleted file mode 100644 index 07951eb60..000000000 --- a/src/qpg6105/crypto/aes_alt.h +++ /dev/null @@ -1,230 +0,0 @@ -/** - * \file aes_alt.h - * - * \brief AES block cipher - * - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This file is part of mbed TLS (https://tls.mbed.org) - */ -#ifndef MBEDTLS_AES_ALT_H -#define MBEDTLS_AES_ALT_H - -#if defined(MBEDTLS_AES_ALT) - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \brief AES context structure - * - * \note buf is able to hold 32 extra bytes, which can be used: - * - for alignment purposes if VIA padlock is used, and/or - * - to simplify key expansion in the 256-bit case by - * generating an extra round key - */ -typedef struct -{ - uint32_t buf[68]; /*!< unaligned data */ - unsigned char key[32]; /*!< internal copy of the key */ - unsigned int keysize; /*!< size in bytes of the key */ -} mbedtls_aes_context; - -/** - * \brief Initialize AES context - * - * \param ctx AES context to be initialized - */ -void mbedtls_aes_init(mbedtls_aes_context *ctx); - -/** - * \brief Clear AES context - * - * \param ctx AES context to be cleared - */ -void mbedtls_aes_free(mbedtls_aes_context *ctx); - -/** - * \brief AES key schedule (encryption) - * - * \param ctx AES context to be initialized - * \param key encryption key - * \param keybits must be 128, 192 or 256 - * - * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH - */ -int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits); - -/** - * \brief AES key schedule (decryption) - * - * \param ctx AES context to be initialized - * \param key decryption key - * \param keybits must be 128, 192 or 256 - * - * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH - */ -int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits); - -/** - * \brief AES-ECB block encryption/decryption - * - * \param ctx AES context - * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT - * \param input 16-byte input block - * \param output 16-byte output block - * - * \return 0 if successful - */ -int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16]); - -#if defined(MBEDTLS_CIPHER_MODE_CBC) -/** - * \brief AES-CBC buffer encryption/decryption - * Length should be a multiple of the block - * size (16 bytes) - * - * \note Upon exit, the content of the IV is updated so that you can - * call the function same function again on the following - * block(s) of data and get the same result as if it was - * encrypted in one call. This allows a "streaming" usage. - * If on the other hand you need to retain the contents of the - * IV, you should either save it manually or use the cipher - * module instead. - * - * \param ctx AES context - * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT - * \param length length of the input data - * \param iv initialization vector (updated after use) - * \param input buffer holding the input data - * \param output buffer holding the output data - * - * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH - */ -int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output); -#endif /* MBEDTLS_CIPHER_MODE_CBC */ - -#if defined(MBEDTLS_CIPHER_MODE_CFB) -/** - * \brief AES-CFB128 buffer encryption/decryption. - * - * Note: Due to the nature of CFB you should use the same key schedule for - * both encryption and decryption. So a context initialized with - * mbedtls_aes_setkey_enc() for both MBEDTLS_AES_ENCRYPT and MBEDTLS_AES_DECRYPT. - * - * \note Upon exit, the content of the IV is updated so that you can - * call the function same function again on the following - * block(s) of data and get the same result as if it was - * encrypted in one call. This allows a "streaming" usage. - * If on the other hand you need to retain the contents of the - * IV, you should either save it manually or use the cipher - * module instead. - * - * \param ctx AES context - * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT - * \param length length of the input data - * \param iv_off offset in IV (updated after use) - * \param iv initialization vector (updated after use) - * \param input buffer holding the input data - * \param output buffer holding the output data - * - * \return 0 if successful - */ -int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx, - int mode, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output); - -/** - * \brief AES-CFB8 buffer encryption/decryption. - * - * Note: Due to the nature of CFB you should use the same key schedule for - * both encryption and decryption. So a context initialized with - * mbedtls_aes_setkey_enc() for both MBEDTLS_AES_ENCRYPT and MBEDTLS_AES_DECRYPT. - * - * \note Upon exit, the content of the IV is updated so that you can - * call the function same function again on the following - * block(s) of data and get the same result as if it was - * encrypted in one call. This allows a "streaming" usage. - * If on the other hand you need to retain the contents of the - * IV, you should either save it manually or use the cipher - * module instead. - * - * \param ctx AES context - * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT - * \param length length of the input data - * \param iv initialization vector (updated after use) - * \param input buffer holding the input data - * \param output buffer holding the output data - * - * \return 0 if successful - */ -int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output); -#endif /*MBEDTLS_CIPHER_MODE_CFB */ - -#if defined(MBEDTLS_CIPHER_MODE_CTR) -/** - * \brief AES-CTR buffer encryption/decryption - * - * Warning: You have to keep the maximum use of your counter in mind! - * - * Note: Due to the nature of CTR you should use the same key schedule for - * both encryption and decryption. So a context initialized with - * mbedtls_aes_setkey_enc() for both MBEDTLS_AES_ENCRYPT and MBEDTLS_AES_DECRYPT. - * - * \param ctx AES context - * \param length The length of the data - * \param nc_off The offset in the current stream_block (for resuming - * within current cipher stream). The offset pointer to - * should be 0 at the start of a stream. - * \param nonce_counter The 128-bit nonce and counter. - * \param stream_block The saved stream-block for resuming. Is overwritten - * by the function. - * \param input The input data stream - * \param output The output data stream - * - * \return 0 if successful - */ -int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx, - size_t length, - size_t *nc_off, - unsigned char nonce_counter[16], - unsigned char stream_block[16], - const unsigned char *input, - unsigned char *output); -#endif /* MBEDTLS_CIPHER_MODE_CTR */ - -#ifdef __cplusplus -} -#endif - -#endif /* MBEDTLS_AES_ALT */ - -#endif /* aes_alt.h */ diff --git a/src/qpg6105/crypto/ccm_alt.h b/src/qpg6105/crypto/ccm_alt.h deleted file mode 100644 index 9ced9ab64..000000000 --- a/src/qpg6105/crypto/ccm_alt.h +++ /dev/null @@ -1,163 +0,0 @@ -/** - * \file ccm_alt.h - * - * \brief CCM combines Counter mode encryption with CBC-MAC authentication - * for 128-bit block ciphers. - * - * Input to CCM includes the following elements: - *
  • Payload - data that is both authenticated and encrypted.
  • - *
  • Associated data (Adata) - data that is authenticated but not - * encrypted, For example, a header.
  • - *
  • Nonce - A unique value that is assigned to the payload and the - * associated data.
- * - */ -/* - * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This file is part of Mbed TLS (https://tls.mbed.org) - */ - -#ifndef MBEDTLS_CCM_ALT_H -#define MBEDTLS_CCM_ALT_H - -#if defined(MBEDTLS_CCM_ALT) - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifndef MBEDTLS_AES_MAX_KEY_SIZE -#define MBEDTLS_AES_MAX_KEY_SIZE 32 -#endif - -/** - * \brief The CCM context-type definition. The CCM context is passed - * to the APIs called. - */ -typedef struct -{ - uint8_t key[MBEDTLS_AES_MAX_KEY_SIZE]; - int keysize; -} mbedtls_ccm_context; - -/** - * \brief This function initializes the specified CCM context, - * to make references valid, and prepare the context - * for mbedtls_ccm_setkey() or mbedtls_ccm_free(). - * - * \param ctx The CCM context to initialize. - */ -void mbedtls_ccm_init(mbedtls_ccm_context *ctx); - -/** - * \brief This function initializes the CCM context set in the - * \p ctx parameter and sets the encryption key. - * - * \param ctx The CCM context to initialize. - * \param cipher The 128-bit block cipher to use. - * \param key The encryption key. - * \param keybits The key size in bits. This must be acceptable by the cipher. - * - * \return \c 0 on success, or a cipher-specific error code. - */ -int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx, - mbedtls_cipher_id_t cipher, - const unsigned char *key, - unsigned int keybits); - -/** - * \brief This function releases and clears the specified CCM context - * and underlying cipher sub-context. - * - * \param ctx The CCM context to clear. - */ -void mbedtls_ccm_free(mbedtls_ccm_context *ctx); - -/** - * \brief This function encrypts a buffer using CCM. - * - * \param ctx The CCM context to use for encryption. - * \param length The length of the input data in Bytes. - * \param iv Initialization vector (nonce). - * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13. - * \param add The additional data field. - * \param add_len The length of additional data in Bytes. - * Must be less than 2^16 - 2^8. - * \param input The buffer holding the input data. - * \param output The buffer holding the output data. - * Must be at least \p length Bytes wide. - * \param tag The buffer holding the tag. - * \param tag_len The length of the tag to generate in Bytes: - * 4, 6, 8, 10, 14 or 16. - * - * \note The tag is written to a separate buffer. To concatenate - * the \p tag with the \p output, as done in RFC-3610: - * Counter with CBC-MAC (CCM), use - * \p tag = \p output + \p length, and make sure that the - * output buffer is at least \p length + \p tag_len wide. - * - * \return \c 0 on success. - */ -int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, - size_t length, - const unsigned char *iv, - size_t iv_len, - const unsigned char *add, - size_t add_len, - const unsigned char *input, - unsigned char *output, - unsigned char *tag, - size_t tag_len); - -/** - * \brief This function performs a CCM authenticated decryption of a - * buffer. - * - * \param ctx The CCM context to use for decryption. - * \param length The length of the input data in Bytes. - * \param iv Initialization vector. - * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13. - * \param add The additional data field. - * \param add_len The length of additional data in Bytes. - * \param input The buffer holding the input data. - * \param output The buffer holding the output data. - * \param tag The buffer holding the tag. - * \param tag_len The length of the tag in Bytes. - * - * \return 0 if successful and authenticated, or - * #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. - */ -int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, - size_t length, - const unsigned char *iv, - size_t iv_len, - const unsigned char *add, - size_t add_len, - const unsigned char *input, - unsigned char *output, - const unsigned char *tag, - size_t tag_len); - -#ifdef __cplusplus -} -#endif - -#endif /* MBEDTLS_CCM_ALT */ - -#endif /* MBEDTLS_CCM_ALT_H */ diff --git a/src/qpg6105/crypto/common-mbedtls-config.h b/src/qpg6105/crypto/common-mbedtls-config.h new file mode 100644 index 000000000..d871d9618 --- /dev/null +++ b/src/qpg6105/crypto/common-mbedtls-config.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef COMMON_MBEDTLS_CONFIG_H +#define COMMON_MBEDTLS_CONFIG_H + +#define MBEDTLS_AES_C +#define MBEDTLS_ECP_C +#define MBEDTLS_ECDH_C +#define MBEDTLS_ENTROPY_C +//#define MBEDTLS_SHA1_C +#define MBEDTLS_SHA224_C +#define MBEDTLS_SHA256_C +#define MBEDTLS_CIPHER_MODE_CTR + +#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf + +#define MBEDTLS_AES_ROM_TABLES +#define MBEDTLS_ASN1_PARSE_C +#define MBEDTLS_ASN1_WRITE_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_CCM_C +#define MBEDTLS_CIPHER_C +#define MBEDTLS_CMAC_C +#define MBEDTLS_CTR_DRBG_C +#define MBEDTLS_ECJPAKE_C +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED +#define MBEDTLS_ECP_NIST_OPTIM +#define MBEDTLS_HAVE_ASM +#define MBEDTLS_HMAC_DRBG_C +#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED +#define MBEDTLS_MD_C +#define MBEDTLS_NO_PLATFORM_ENTROPY +#define MBEDTLS_OID_C // what is this ? +#define MBEDTLS_PK_C +#define MBEDTLS_PK_PARSE_C +#define MBEDTLS_PK_WRITE_C +#define MBEDTLS_PLATFORM_C +#define MBEDTLS_PLATFORM_MEMORY +#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS +#define MBEDTLS_SHA256_SMALLER +#define MBEDTLS_SSL_CLI_C +#define MBEDTLS_SSL_DTLS_ANTI_REPLAY +#define MBEDTLS_SSL_DTLS_HELLO_VERIFY +#define MBEDTLS_SSL_EXPORT_KEYS +#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH +#define MBEDTLS_SSL_PROTO_TLS1_2 +#define MBEDTLS_SSL_PROTO_DTLS +#define MBEDTLS_SSL_TLS_C +#define MBEDTLS_ERROR_STRERROR_DUMMY +#define MBEDTLS_HKDF_C +#define MBEDTLS_X509_CREATE_C +#define MBEDTLS_X509_CSR_WRITE_C +#define MBEDTLS_X509_CRT_PARSE_C +#define MBEDTLS_X509_USE_C +#define MBEDTLS_X509_REMOVE_INFO +#define MBEDTLS_BASE64_C +#define MBEDTLS_PEM_WRITE_C + +#define MBEDTLS_ECDH_LEGACY_CONTEXT +#define MBEDTLS_ECDSA_C +#define MBEDTLS_ECDSA_DETERMINISTIC + +#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED +#define MBEDTLS_BASE64_C +#define MBEDTLS_ECDSA_C +#define MBEDTLS_OID_C +#define MBEDTLS_PEM_PARSE_C +#define MBEDTLS_X509_USE_C +#define MBEDTLS_X509_CRT_PARSE_C +#endif + +#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS +#define MBEDTLS_SSL_DTLS_CONNECTION_ID 0 +#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0 + +#define MBEDTLS_DEPRECATED_REMOVED + +#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */ +#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */ +#define MBEDTLS_ECP_MAX_BITS 256 /**< Maximum bit size of groups */ +#define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */ + +#include +#define MBEDTLS_PLATFORM_STD_CALLOC calloc +#define MBEDTLS_PLATFORM_STD_FREE free + +#define MBEDTLS_SSL_MAX_CONTENT_LEN 768 /**< Maxium fragment length in bytes */ + +#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 + +#define MBEDTLS_PKCS5_C + +#endif // COMMON_MBEDTLS_CONFIG_H diff --git a/src/qpg6105/crypto/ecjpake_alt.h b/src/qpg6105/crypto/ecjpake_alt.h deleted file mode 100644 index 95d35eed4..000000000 --- a/src/qpg6105/crypto/ecjpake_alt.h +++ /dev/null @@ -1,233 +0,0 @@ -/** - * \file ecjpake_alt.h - * - * \brief Elliptic curve J-PAKE - */ -/* - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This file is part of mbed TLS (https://tls.mbed.org) - */ -#ifndef MBEDTLS_ECJPAKE_ALT_H -#define MBEDTLS_ECJPAKE_ALT_H - -#if defined(MBEDTLS_ECJPAKE_ALT) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MBEDTLS_ECJPAKE_ALT // QORVO -/** - * Roles in the EC J-PAKE exchange - */ -typedef enum -{ - MBEDTLS_ECJPAKE_CLIENT = 0, /**< Client */ - MBEDTLS_ECJPAKE_SERVER, /**< Server */ -} mbedtls_ecjpake_role; -#endif // MBEDTLS_ECJPAKE_ALT // QORVO - -#ifndef MBEDTLS_ECJPAKE_MAX_BYTES - -/** The maximum size in bytes for a ECJPAKE number or coordinate. - * - * Default size works for P256 as MbedTLS and the Thread standard officially - * only support P256. To support larger curves, chose MBEDTLS_ECP_MAX_BYTES. - */ -#define MBEDTLS_ECJPAKE_MAX_BYTES (256 / 8) -#endif - -/** - * EC J-PAKE context structure. - * - * J-PAKE is a symmetric protocol, except for the identifiers used in - * Zero-Knowledge Proofs, and the serialization of the second message - * (KeyExchange) as defined by the Thread spec. - * - * In order to benefit from this symmetry, we choose a different naming - * convetion from the Thread v1.0 spec. Correspondance is indicated in the - * description as a pair C: client name, S: server name - */ -typedef struct -{ - mbedtls_ecp_group grp; /**< Elliptic curve */ - mbedtls_ecjpake_role role; /**< Are we client or server? */ - int point_format; /**< Format for point export */ - - mbedtls_ecp_point Xm1; /**< My public key 1 C: X1, S: X3 */ - mbedtls_ecp_point Xm2; /**< My public key 2 C: X2, S: X4 */ - mbedtls_ecp_point Xp1; /**< Peer public key 1 C: X3, S: X1 */ - mbedtls_ecp_point Xp2; /**< Peer public key 2 C: X4, S: X2 */ - mbedtls_ecp_point Xp; /**< Peer public key C: Xs, S: Xc */ - - mbedtls_mpi xm1; /**< My private key 1 C: x1, S: x3 */ - mbedtls_mpi xm2; /**< My private key 2 C: x2, S: x4 */ - - mbedtls_mpi s; /**< Pre-shared secret (passphrase) */ - - const struct sx_ecc_curve_t *curve; /**< Elliptic curve for HW offload */ - int hashalg; /**< Hash algorithm for HW offload */ -} mbedtls_ecjpake_context; - -#ifndef MBEDTLS_ECJPAKE_ALT // QORVO -/** - * \brief Initialize a context - * (just makes it ready for setup() or free()). - * - * \param ctx context to initialize - */ -void mbedtls_ecjpake_init(mbedtls_ecjpake_context *ctx); - -/** - * \brief Set up a context for use - * - * \note Currently the only values for hash/curve allowed by the - * standard are MBEDTLS_MD_SHA256/MBEDTLS_ECP_DP_SECP256R1. - * - * \param ctx context to set up - * \param role Our role: client or server - * \param hash hash function to use (MBEDTLS_MD_XXX) - * \param curve elliptic curve identifier (MBEDTLS_ECP_DP_XXX) - * \param secret pre-shared secret (passphrase) - * \param len length of the shared secret - * - * \return 0 if successfull, - * a negative error code otherwise - */ -int mbedtls_ecjpake_setup(mbedtls_ecjpake_context *ctx, - mbedtls_ecjpake_role role, - mbedtls_md_type_t hash, - mbedtls_ecp_group_id curve, - const unsigned char *secret, - size_t len); - -/** - * \brief Check if a context is ready for use - * - * \param ctx Context to check - * - * \return 0 if the context is ready for use, - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise - */ -int mbedtls_ecjpake_check(const mbedtls_ecjpake_context *ctx); - -/** - * \brief Generate and write the first round message - * (TLS: contents of the Client/ServerHello extension, - * excluding extension type and length bytes) - * - * \param ctx Context to use - * \param buf Buffer to write the contents to - * \param len Buffer size - * \param olen Will be updated with the number of bytes written - * \param f_rng RNG function - * \param p_rng RNG parameter - * - * \return 0 if successfull, - * a negative error code otherwise - */ -int mbedtls_ecjpake_write_round_one(mbedtls_ecjpake_context *ctx, - unsigned char *buf, - size_t len, - size_t *olen, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief Read and process the first round message - * (TLS: contents of the Client/ServerHello extension, - * excluding extension type and length bytes) - * - * \param ctx Context to use - * \param buf Pointer to extension contents - * \param len Extension length - * - * \return 0 if successfull, - * a negative error code otherwise - */ -int mbedtls_ecjpake_read_round_one(mbedtls_ecjpake_context *ctx, const unsigned char *buf, size_t len); - -/** - * \brief Generate and write the second round message - * (TLS: contents of the Client/ServerKeyExchange) - * - * \param ctx Context to use - * \param buf Buffer to write the contents to - * \param len Buffer size - * \param olen Will be updated with the number of bytes written - * \param f_rng RNG function - * \param p_rng RNG parameter - * - * \return 0 if successfull, - * a negative error code otherwise - */ -int mbedtls_ecjpake_write_round_two(mbedtls_ecjpake_context *ctx, - unsigned char *buf, - size_t len, - size_t *olen, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief Read and process the second round message - * (TLS: contents of the Client/ServerKeyExchange) - * - * \param ctx Context to use - * \param buf Pointer to the message - * \param len Message length - * - * \return 0 if successfull, - * a negative error code otherwise - */ -int mbedtls_ecjpake_read_round_two(mbedtls_ecjpake_context *ctx, const unsigned char *buf, size_t len); - -/** - * \brief Derive the shared secret - * (TLS: Pre-Master Secret) - * - * \param ctx Context to use - * \param buf Buffer to write the contents to - * \param len Buffer size - * \param olen Will be updated with the number of bytes written - * \param f_rng RNG function - * \param p_rng RNG parameter - * - * \return 0 if successfull, - * a negative error code otherwise - */ -int mbedtls_ecjpake_derive_secret(mbedtls_ecjpake_context *ctx, - unsigned char *buf, - size_t len, - size_t *olen, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief Free a context's content - * - * \param ctx context to free - */ -void mbedtls_ecjpake_free(mbedtls_ecjpake_context *ctx); -#endif // MBEDTLS_ECJPAKE_ALT // QORVO - -#ifdef __cplusplus -} -#endif - -#endif /* MBEDTLS_ECJPAKE_ALT */ - -#endif /* ecjpake.h */ diff --git a/src/qpg6105/crypto/ecp_alt.h b/src/qpg6105/crypto/ecp_alt.h deleted file mode 100644 index 2b3798c07..000000000 --- a/src/qpg6105/crypto/ecp_alt.h +++ /dev/null @@ -1,657 +0,0 @@ -/** - * \file ecp_alt.h - * - * \brief Elliptic curves over GF(p) - * - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This file is part of mbed TLS (https://tls.mbed.org) - */ -/* Adapted for hardware acceleration by CryptoSoc - * Copyright (c) 2018 Barco Silex - * Copyright (c) 2018 François Beerten - */ - -#ifndef MBEDTLS_ECP_ALT_H -#define MBEDTLS_ECP_ALT_H - -/* - * default mbed TLS elliptic curve arithmetic implementation - * - * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an - * alternative implementation for the whole module and it will replace this - * one.) - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MBEDTLS_ECP_ALT // QORVO -/** - * Domain parameters (curve, subgroup and generator) identifiers. - * - * Only curves over prime fields are supported. - * - * \warning This library does not support validation of arbitrary domain - * parameters. Therefore, only well-known domain parameters from trusted - * sources should be used. See mbedtls_ecp_group_load(). - */ -typedef enum -{ - MBEDTLS_ECP_DP_NONE = 0, - MBEDTLS_ECP_DP_SECP192R1, /*!< 192-bits NIST curve */ - MBEDTLS_ECP_DP_SECP224R1, /*!< 224-bits NIST curve */ - MBEDTLS_ECP_DP_SECP256R1, /*!< 256-bits NIST curve */ - MBEDTLS_ECP_DP_SECP384R1, /*!< 384-bits NIST curve */ - MBEDTLS_ECP_DP_SECP521R1, /*!< 521-bits NIST curve */ - MBEDTLS_ECP_DP_BP256R1, /*!< 256-bits Brainpool curve */ - MBEDTLS_ECP_DP_BP384R1, /*!< 384-bits Brainpool curve */ - MBEDTLS_ECP_DP_BP512R1, /*!< 512-bits Brainpool curve */ - MBEDTLS_ECP_DP_CURVE25519, /*!< Curve25519 */ - MBEDTLS_ECP_DP_SECP192K1, /*!< 192-bits "Koblitz" curve */ - MBEDTLS_ECP_DP_SECP224K1, /*!< 224-bits "Koblitz" curve */ - MBEDTLS_ECP_DP_SECP256K1, /*!< 256-bits "Koblitz" curve */ -} mbedtls_ecp_group_id; - -/** - * Number of supported curves (plus one for NONE). - * - * (Montgomery curves excluded for now.) - */ -#define MBEDTLS_ECP_DP_MAX 12 - -/** - * Curve information for use by other modules - */ -typedef struct -{ - mbedtls_ecp_group_id grp_id; /*!< Internal identifier */ - uint16_t tls_id; /*!< TLS NamedCurve identifier */ - uint16_t bit_size; /*!< Curve size in bits */ - const char *name; /*!< Human-friendly name */ -} mbedtls_ecp_curve_info; - -/** - * \brief ECP point structure (jacobian coordinates) - * - * \note All functions expect and return points satisfying - * the following condition: Z == 0 or Z == 1. (Other - * values of Z are used by internal functions only.) - * The point is zero, or "at infinity", if Z == 0. - * Otherwise, X and Y are its standard (affine) coordinates. - */ -typedef struct -{ - mbedtls_mpi X; /*!< the point's X coordinate */ - mbedtls_mpi Y; /*!< the point's Y coordinate */ - mbedtls_mpi Z; /*!< the point's Z coordinate */ -} mbedtls_ecp_point; -#endif // MBEDTLS_ECP_ALT // QORVO - -/** - * \brief ECP group structure - * - * We consider two types of curves equations: - * 1. Short Weierstrass y^2 = x^3 + A x + B mod P (SEC1 + RFC 4492) - * 2. Montgomery, y^2 = x^3 + A x^2 + x mod P (Curve25519 + draft) - * In both cases, a generator G for a prime-order subgroup is fixed. In the - * short weierstrass, this subgroup is actually the whole curve, and its - * cardinal is denoted by N. - * - * In the case of Short Weierstrass curves, our code requires that N is an odd - * prime. (Use odd in mbedtls_ecp_mul() and prime in mbedtls_ecdsa_sign() for blinding.) - * - * In the case of Montgomery curves, we don't store A but (A + 2) / 4 which is - * the quantity actually used in the formulas. Also, nbits is not the size of N - * but the required size for private keys. - * - * If modp is NULL, reduction modulo P is done using a generic algorithm. - * Otherwise, it must point to a function that takes an mbedtls_mpi in the range - * 0..2^(2*pbits)-1 and transforms it in-place in an integer of little more - * than pbits, so that the integer may be efficiently brought in the 0..P-1 - * range by a few additions or substractions. It must return 0 on success and - * non-zero on failure. - */ -typedef struct -{ - mbedtls_ecp_group_id id; /*!< internal group identifier */ - mbedtls_mpi P; /*!< prime modulus of the base field */ - mbedtls_mpi A; /*!< 1. A in the equation, or 2. (A + 2) / 4. for pkparse only. */ - mbedtls_mpi B; /*!< 1. B in the equation, or 2. unused. for pkparse only. */ - mbedtls_ecp_point G; /*!< generator of the (sub)group used */ - mbedtls_mpi N; /*!< 1. the order of G, or 2. unused */ - size_t pbits; /*!< number of bits in P */ - size_t nbits; /*!< number of bits in 1. P, or 2. private keys */ - unsigned int h; /*!< internal: 1 if the constants are static */ - int (*modp)(mbedtls_mpi *); /*!< Internally unused. NULL to build some tests. */ - mbedtls_ecp_point *T; /*!< Internally unused. Needed to build benchmark. */ - size_t T_size; /*!< Internally unused. Needed to build benchmark. */ -} mbedtls_ecp_group; - -#ifndef MBEDTLS_ECP_ALT // QORVO -/** - * \brief ECP key pair structure - * - * A generic key pair that could be used for ECDSA, fixed ECDH, etc. - * - * \note Members purposefully in the same order as struc mbedtls_ecdsa_context. - */ -typedef struct -{ - mbedtls_ecp_group grp; /*!< Elliptic curve and base point */ - mbedtls_mpi d; /*!< our secret value */ - mbedtls_ecp_point Q; /*!< our public value */ -} mbedtls_ecp_keypair; -#endif // MBEDTLS_ECP_ALT // QORVO - -/** - * \name SECTION: Module settings - * - * The configuration options you can set for this module are in this section. - * Either change them in config.h or define them on the compiler command line. - * \{ - */ - -#if !defined(MBEDTLS_ECP_MAX_BITS) -/** - * Maximum size of the groups (that is, of N and P) - */ -#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */ -#endif - -#define MBEDTLS_ECP_MAX_BYTES ((MBEDTLS_ECP_MAX_BITS + 7) / 8) -#define MBEDTLS_ECP_MAX_PT_LEN (2 * MBEDTLS_ECP_MAX_BYTES + 1) - -#if defined(MBEDTLS_ECP_WINDOW_SIZE) -#error "MBEDTLS_ECP_WINDOW_SIZE not applicable for HW accel" -#endif /* MBEDTLS_ECP_WINDOW_SIZE */ - -#if defined(MBEDTLS_ECP_FIXED_POINT_OPTIM) -#error "MBEDTLS_ECP_FIXED_POINT_OPTIM not applicable for HW accel" -#endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */ - -/* \} name SECTION: Module settings */ - -/* - * Point formats, from RFC 4492's enum ECPointFormat - */ -#define MBEDTLS_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format */ -#define MBEDTLS_ECP_PF_COMPRESSED 1 /**< Compressed point format */ - -/* - * Some other constants from RFC 4492 - */ -#define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< ECCurveType's named_curve */ - -#ifndef MBEDTLS_ECP_ALT // QORVO -/** - * \brief Get the list of supported curves in order of preferrence - * (full information) - * - * \return A statically allocated array, the last entry is 0. - */ -const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list(void); - -/** - * \brief Get the list of supported curves in order of preferrence - * (grp_id only) - * - * \return A statically allocated array, - * terminated with MBEDTLS_ECP_DP_NONE. - */ -const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list(void); - -/** - * \brief Get curve information from an internal group identifier - * - * \param grp_id A MBEDTLS_ECP_DP_XXX value - * - * \return The associated curve information or NULL - */ -const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id(mbedtls_ecp_group_id grp_id); - -/** - * \brief Get curve information from a TLS NamedCurve value - * - * \param tls_id A MBEDTLS_ECP_DP_XXX value - * - * \return The associated curve information or NULL - */ -const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id); - -/** - * \brief Get curve information from a human-readable name - * - * \param name The name - * - * \return The associated curve information or NULL - */ -const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name(const char *name); - -/** - * \brief Initialize a point (as zero) - */ -void mbedtls_ecp_point_init(mbedtls_ecp_point *pt); - -/** - * \brief Initialize a group (to something meaningless) - */ -void mbedtls_ecp_group_init(mbedtls_ecp_group *grp); - -/** - * \brief Initialize a key pair (as an invalid one) - */ -void mbedtls_ecp_keypair_init(mbedtls_ecp_keypair *key); - -/** - * \brief Free the components of a point - */ -void mbedtls_ecp_point_free(mbedtls_ecp_point *pt); - -/** - * \brief Free the components of an ECP group - */ -void mbedtls_ecp_group_free(mbedtls_ecp_group *grp); - -/** - * \brief Free the components of a key pair - */ -void mbedtls_ecp_keypair_free(mbedtls_ecp_keypair *key); - -/** - * \brief Copy the contents of point Q into P - * - * \param P Destination point - * \param Q Source point - * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed - */ -int mbedtls_ecp_copy(mbedtls_ecp_point *P, const mbedtls_ecp_point *Q); - -/** - * \brief Copy the contents of a group object - * - * \param dst Destination group - * \param src Source group - * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed - */ -int mbedtls_ecp_group_copy(mbedtls_ecp_group *dst, const mbedtls_ecp_group *src); - -/** - * \brief Set a point to zero - * - * \param pt Destination point - * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed - */ -int mbedtls_ecp_set_zero(mbedtls_ecp_point *pt); - -/** - * \brief Tell if a point is zero - * - * \param pt Point to test - * - * \return 1 if point is zero, 0 otherwise - */ -int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt); - -/** - * \brief Compare two points - * - * \note This assumes the points are normalized. Otherwise, - * they may compare as "not equal" even if they are. - * - * \param P First point to compare - * \param Q Second point to compare - * - * \return 0 if the points are equal, - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise - */ -int mbedtls_ecp_point_cmp(const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q); - -/** - * \brief Import a non-zero point from two ASCII strings - * - * \param P Destination point - * \param radix Input numeric base - * \param x First affine coordinate as a null-terminated string - * \param y Second affine coordinate as a null-terminated string - * - * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code - */ -int mbedtls_ecp_point_read_string(mbedtls_ecp_point *P, int radix, const char *x, const char *y); - -/** - * \brief Export a point into unsigned binary data - * - * \param grp Group to which the point should belong - * \param P Point to export - * \param format Point format, should be a MBEDTLS_ECP_PF_XXX macro - * \param olen Length of the actual output - * \param buf Output buffer - * \param buflen Length of the output buffer - * - * \return 0 if successful, - * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA - * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL - */ -int mbedtls_ecp_point_write_binary(const mbedtls_ecp_group *grp, - const mbedtls_ecp_point *P, - int format, - size_t *olen, - unsigned char *buf, - size_t buflen); - -/** - * \brief Import a point from unsigned binary data - * - * \param grp Group to which the point should belong - * \param P Point to import - * \param buf Input buffer - * \param ilen Actual length of input - * - * \return 0 if successful, - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format - * is not implemented. - * - * \note This function does NOT check that the point actually - * belongs to the given group, see mbedtls_ecp_check_pubkey() for - * that. - */ -int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group *grp, - mbedtls_ecp_point *P, - const unsigned char *buf, - size_t ilen); - -/** - * \brief Import a point from a TLS ECPoint record - * - * \param grp ECP group used - * \param pt Destination point - * \param buf $(Start of input buffer) - * \param len Buffer length - * - * \note buf is updated to point right after the ECPoint on exit - * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_XXX if initialization failed - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid - */ -int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group *grp, - mbedtls_ecp_point *pt, - const unsigned char **buf, - size_t len); - -/** - * \brief Export a point as a TLS ECPoint record - * - * \param grp ECP group used - * \param pt Point to export - * \param format Export format - * \param olen length of data written - * \param buf Buffer to write to - * \param blen Buffer length - * - * \return 0 if successful, - * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA - * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL - */ -int mbedtls_ecp_tls_write_point(const mbedtls_ecp_group *grp, - const mbedtls_ecp_point *pt, - int format, - size_t *olen, - unsigned char *buf, - size_t blen); - -/** - * \brief Set a group using well-known domain parameters - * - * \param grp Destination group - * \param id Index in the list of well-known domain parameters - * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_XXX if initialization failed - * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE for unkownn groups - * - * \note Index should be a value of RFC 4492's enum NamedCurve, - * usually in the form of a MBEDTLS_ECP_DP_XXX macro. - */ -int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id id); - -/** - * \brief Set a group from a TLS ECParameters record - * - * \param grp Destination group - * \param buf &(Start of input buffer) - * \param len Buffer length - * - * \note buf is updated to point right after ECParameters on exit - * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_XXX if initialization failed - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid - */ -int mbedtls_ecp_tls_read_group(mbedtls_ecp_group *grp, const unsigned char **buf, size_t len); - -/** - * \brief Write the TLS ECParameters record for a group - * - * \param grp ECP group used - * \param olen Number of bytes actually written - * \param buf Buffer to write to - * \param blen Buffer length - * - * \return 0 if successful, - * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL - */ -int mbedtls_ecp_tls_write_group(const mbedtls_ecp_group *grp, size_t *olen, unsigned char *buf, size_t blen); - -/** - * \brief Multiplication by an integer: R = m * P - * (Not thread-safe to use same group in multiple threads) - * - * \note In order to prevent timing attacks, this function - * executes the exact same sequence of (base field) - * operations for any valid m. It avoids any if-branch or - * array index depending on the value of m. - * - * \note If f_rng is not NULL, it is used to randomize intermediate - * results in order to prevent potential timing attacks - * targeting these results. It is recommended to always - * provide a non-NULL f_rng (the overhead is negligible). - * - * \param grp ECP group - * \param R Destination point - * \param m Integer by which to multiply - * \param P Point to multiply - * \param f_rng RNG function (see notes) - * \param p_rng RNG parameter - * - * \return 0 if successful, - * MBEDTLS_ERR_ECP_INVALID_KEY if m is not a valid privkey - * or P is not a valid pubkey, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed - */ -int mbedtls_ecp_mul(mbedtls_ecp_group *grp, - mbedtls_ecp_point *R, - const mbedtls_mpi *m, - const mbedtls_ecp_point *P, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief Multiplication and addition of two points by integers: - * R = m * P + n * Q - * (Not thread-safe to use same group in multiple threads) - * - * \note In contrast to mbedtls_ecp_mul(), this function does not guarantee - * a constant execution flow and timing. - * - * \param grp ECP group - * \param R Destination point - * \param m Integer by which to multiply P - * \param P Point to multiply by m - * \param n Integer by which to multiply Q - * \param Q Point to be multiplied by n - * - * \return 0 if successful, - * MBEDTLS_ERR_ECP_INVALID_KEY if m or n is not a valid privkey - * or P or Q is not a valid pubkey, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed - */ -int mbedtls_ecp_muladd(mbedtls_ecp_group *grp, - mbedtls_ecp_point *R, - const mbedtls_mpi *m, - const mbedtls_ecp_point *P, - const mbedtls_mpi *n, - const mbedtls_ecp_point *Q); - -/** - * \brief Check that a point is a valid public key on this curve - * - * \param grp Curve/group the point should belong to - * \param pt Point to check - * - * \return 0 if point is a valid public key, - * MBEDTLS_ERR_ECP_INVALID_KEY otherwise. - * - * \note This function only checks the point is non-zero, has valid - * coordinates and lies on the curve, but not that it is - * indeed a multiple of G. This is additional check is more - * expensive, isn't required by standards, and shouldn't be - * necessary if the group used has a small cofactor. In - * particular, it is useless for the NIST groups which all - * have a cofactor of 1. - * - * \note Uses bare components rather than an mbedtls_ecp_keypair structure - * in order to ease use with other structures such as - * mbedtls_ecdh_context of mbedtls_ecdsa_context. - */ -int mbedtls_ecp_check_pubkey(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt); - -/** - * \brief Check that an mbedtls_mpi is a valid private key for this curve - * - * \param grp Group used - * \param d Integer to check - * - * \return 0 if point is a valid private key, - * MBEDTLS_ERR_ECP_INVALID_KEY otherwise. - * - * \note Uses bare components rather than an mbedtls_ecp_keypair structure - * in order to ease use with other structures such as - * mbedtls_ecdh_context of mbedtls_ecdsa_context. - */ -int mbedtls_ecp_check_privkey(const mbedtls_ecp_group *grp, const mbedtls_mpi *d); - -/** - * \brief Generate a keypair with configurable base point - * - * \param grp ECP group - * \param G Chosen base point - * \param d Destination MPI (secret part) - * \param Q Destination point (public part) - * \param f_rng RNG function - * \param p_rng RNG parameter - * - * \return 0 if successful, - * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code - * - * \note Uses bare components rather than an mbedtls_ecp_keypair structure - * in order to ease use with other structures such as - * mbedtls_ecdh_context of mbedtls_ecdsa_context. - */ -int mbedtls_ecp_gen_keypair_base(mbedtls_ecp_group *grp, - const mbedtls_ecp_point *G, - mbedtls_mpi *d, - mbedtls_ecp_point *Q, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief Generate a keypair - * - * \param grp ECP group - * \param d Destination MPI (secret part) - * \param Q Destination point (public part) - * \param f_rng RNG function - * \param p_rng RNG parameter - * - * \return 0 if successful, - * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code - * - * \note Uses bare components rather than an mbedtls_ecp_keypair structure - * in order to ease use with other structures such as - * mbedtls_ecdh_context of mbedtls_ecdsa_context. - */ -int mbedtls_ecp_gen_keypair(mbedtls_ecp_group *grp, - mbedtls_mpi *d, - mbedtls_ecp_point *Q, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief Generate a keypair - * - * \param grp_id ECP group identifier - * \param key Destination keypair - * \param f_rng RNG function - * \param p_rng RNG parameter - * - * \return 0 if successful, - * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code - */ -int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, - mbedtls_ecp_keypair *key, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief Check a public-private key pair - * - * \param pub Keypair structure holding a public key - * \param prv Keypair structure holding a private (plus public) key - * - * \return 0 if successful (keys are valid and match), or - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA, or - * a MBEDTLS_ERR_ECP_XXX or MBEDTLS_ERR_MPI_XXX code. - */ -int mbedtls_ecp_check_pub_priv(const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv); -#endif // MBEDTLS_ECP_ALT // QORVO - -#if defined(MBEDTLS_SELF_TEST) - -/** - * \brief Checkup routine - * - * \return 0 if successful, or 1 if a test failed - */ -int mbedtls_ecp_self_test(int verbose); - -#endif /* MBEDTLS_SELF_TEST */ - -#ifdef __cplusplus -} -#endif - -#endif /* ecp_alt.h */ diff --git a/src/qpg6105/crypto/qpg6105-mbedtls-config.h b/src/qpg6105/crypto/qpg6105-mbedtls-config.h old mode 100755 new mode 100644 index 41cd478db..7c6b76491 --- a/src/qpg6105/crypto/qpg6105-mbedtls-config.h +++ b/src/qpg6105/crypto/qpg6105-mbedtls-config.h @@ -26,21 +26,27 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef QGP6105_MBEDTLS_CONFIG_H -#define QGP6105_MBEDTLS_CONFIG_H +#ifndef QPG6105_MBEDTLS_CONFIG_H +#define QPG6105_MBEDTLS_CONFIG_H -// Use Qorvo HW crypto support -#undef MBEDTLS_ECP_WINDOW_SIZE -#undef MBEDTLS_ECP_FIXED_POINT_OPTIM +#include "common-mbedtls-config.h" -#define MBEDTLS_AES_ALT -#define MBEDTLS_CCM_ALT +#ifndef MBEDTLS_SW_ONLY +#define MBEDTLS_SHA1_ALT 1 #define MBEDTLS_ECP_ALT -#define MBEDTLS_ECJPAKE_ALT -#define MBEDTLS_SHA256_ALT #define MBEDTLS_ECDSA_VERIFY_ALT #define MBEDTLS_ECDSA_SIGN_ALT +#define MBEDTLS_SHA256_ALT +#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT +#endif -#include "mbedtls/check_config.h" +#define MBEDTLS_ENTROPY_HARDWARE_ALT + +// Using Qorvo HW crypto engine +#undef MBEDTLS_ECP_WINDOW_SIZE +#undef MBEDTLS_ECP_FIXED_POINT_OPTIM + +#define MBEDTLS_AES_ALT +#define MBEDTLS_ECJPAKE_ALT -#endif // QGP6105_MBEDTLS_CONFIG_H +#endif // QPG6105_MBEDTLS_CONFIG_H diff --git a/src/qpg6105/crypto/sha256_alt.h b/src/qpg6105/crypto/sha256_alt.h deleted file mode 100644 index 48efadd96..000000000 --- a/src/qpg6105/crypto/sha256_alt.h +++ /dev/null @@ -1,194 +0,0 @@ -/** - * \file mbedtls_sha256.h - * - * \brief SHA-224 and SHA-256 cryptographic hash function - * - * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved - * - * This file is part of mbed TLS (https://tls.mbed.org) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef MBEDTLS_SHA256_ALT_H -#define MBEDTLS_SHA256_ALT_H - -#if !defined(MBEDTLS_CONFIG_FILE) -#include "config.h" -#else -#include MBEDTLS_CONFIG_FILE -#endif - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \brief SHA-256 context structure - */ -typedef struct -{ - uint32_t total[2]; /*!< number of bytes processed */ - uint32_t state[8]; /*!< intermediate digest state */ - unsigned char buffer[64]; /*!< data block being processed */ - int is224; /*!< 0 => SHA-256, else SHA-224 */ -} mbedtls_sha256_context; - -/** - * \brief This function initializes a SHA-256 context. - * - * \param ctx The SHA-256 context to initialize. - */ -void mbedtls_sha256_init(mbedtls_sha256_context *ctx); - -/** - * \brief This function clears a SHA-256 context. - * - * \param ctx The SHA-256 context to clear. - */ -void mbedtls_sha256_free(mbedtls_sha256_context *ctx); - -/** - * \brief This function clones the state of a SHA-256 context. - * - * \param dst The destination context. - * \param src The context to clone. - */ -void mbedtls_sha256_clone(mbedtls_sha256_context *dst, const mbedtls_sha256_context *src); - -/** - * \brief This function starts a SHA-224 or SHA-256 checksum - * calculation. - * - * \param ctx The context to initialize. - * \param is224 Determines which function to use. - *
  • 0: Use SHA-256.
  • - *
  • 1: Use SHA-224.
- * - * \return \c 0 on success. - */ -int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224); - -/** - * \brief This function feeds an input buffer into an ongoing - * SHA-256 checksum calculation. - * - * \param ctx SHA-256 context - * \param input buffer holding the data - * \param ilen length of the input data - * - * \return \c 0 on success. - */ -int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen); - -/** - * \brief This function finishes the SHA-256 operation, and writes - * the result to the output buffer. - * - * \param ctx The SHA-256 context. - * \param output The SHA-224 or SHA-256 checksum result. - * - * \return \c 0 on success. - */ -int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx, unsigned char output[32]); - -/** - * \brief This function processes a single data block within - * the ongoing SHA-256 computation. This function is for - * internal use only. - * - * \param ctx The SHA-256 context. - * \param data The buffer holding one block of data. - * - * \return \c 0 on success. - */ -int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64]); - -#if !defined(MBEDTLS_DEPRECATED_REMOVED) -#if defined(MBEDTLS_DEPRECATED_WARNING) -#define MBEDTLS_DEPRECATED __attribute__((deprecated)) -#else -#define MBEDTLS_DEPRECATED -#endif -/** - * \brief This function starts a SHA-256 checksum calculation. - * - * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0. - * - * \param ctx The SHA-256 context to initialize. - * \param is224 Determines which function to use. - *
  • 0: Use SHA-256.
  • - *
  • 1: Use SHA-224.
- */ -MBEDTLS_DEPRECATED static inline void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224) -{ - mbedtls_sha256_starts_ret(ctx, is224); -} - -/** - * \brief This function feeds an input buffer into an ongoing - * SHA-256 checksum calculation. - * - * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0. - * - * \param ctx The SHA-256 context to initialize. - * \param input The buffer holding the data. - * \param ilen The length of the input data. - */ -MBEDTLS_DEPRECATED static inline void mbedtls_sha256_update(mbedtls_sha256_context *ctx, - const unsigned char *input, - size_t ilen) -{ - mbedtls_sha256_update_ret(ctx, input, ilen); -} - -/** - * \brief This function finishes the SHA-256 operation, and writes - * the result to the output buffer. - * - * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0. - * - * \param ctx The SHA-256 context. - * \param output The SHA-224or SHA-256 checksum result. - */ -MBEDTLS_DEPRECATED static inline void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32]) -{ - mbedtls_sha256_finish_ret(ctx, output); -} - -/** - * \brief This function processes a single data block within - * the ongoing SHA-256 computation. This function is for - * internal use only. - * - * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0. - * - * \param ctx The SHA-256 context. - * \param data The buffer holding one block of data. - */ -MBEDTLS_DEPRECATED static inline void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64]) -{ - mbedtls_internal_sha256_process(ctx, data); -} - -#undef MBEDTLS_DEPRECATED -#endif /* !MBEDTLS_DEPRECATED_REMOVED */ -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/qpg6105/openthread-core-qpg6105-config.h b/src/qpg6105/openthread-core-qpg6105-config.h index e5f966409..e703e2a4b 100644 --- a/src/qpg6105/openthread-core-qpg6105-config.h +++ b/src/qpg6105/openthread-core-qpg6105-config.h @@ -62,6 +62,12 @@ #define OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) #endif +/** + * @def OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD + * + * Reception scheduling and ramp up time needed for the CSL receiver to be ready, in units of microseconds. + * + */ #if defined(OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE) #define OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD 1150 #endif @@ -178,14 +184,4 @@ #define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3) #endif -/** - * @def OPENTHREAD_CONFIG_TLS_ENABLE - * - * Define as 1 to enable support for TLS over TCP. - * - */ -#ifndef OPENTHREAD_CONFIG_TLS_ENABLE -#define OPENTHREAD_CONFIG_TLS_ENABLE 0 -#endif - #endif // OPENTHREAD_CORE_QPG6105_CONFIG_H_ diff --git a/src/qpg6105/platform.c b/src/qpg6105/platform.c index dcc1d7e68..815df4c41 100755 --- a/src/qpg6105/platform.c +++ b/src/qpg6105/platform.c @@ -38,6 +38,7 @@ #include "random_qorvo.h" #include "uart_qorvo.h" #include +#include #include "utils/uart.h" @@ -82,5 +83,8 @@ void otSysProcessDrivers(otInstance *aInstance) localInstance = aInstance; } - qorvoPlatMainLoop(!otTaskletsArePending(aInstance)); + // Do not sleep until attached to network to handle UART CLI + qorvoPlatMainLoop(!otTaskletsArePending(aInstance) && + (otThreadGetDeviceRole(aInstance) != OT_DEVICE_ROLE_DETACHED) && + (otThreadGetDeviceRole(aInstance) != OT_DEVICE_ROLE_DISABLED)); } diff --git a/src/qpg6105/radio.c b/src/qpg6105/radio.c index 6a491e218..7fb2ee4e5 100644 --- a/src/qpg6105/radio.c +++ b/src/qpg6105/radio.c @@ -41,22 +41,20 @@ #include "radio_qorvo.h" -#define QPG_RECEIVE_SENSITIVITY -100 // dBm -#define QPG_CSL_ACCURACY 50 // ppm -#define QPG_CSL_CLOCK_UNCERTAINTY 255 // 10us - -#define IEEE802154_MIN_LENGTH 5 -#define IEEE802154_MAX_LENGTH 127 -#define IEEE802154_ACK_LENGTH 5 -#define IEEE802154_FRAME_TYPE_MASK 0x7 -#define IEEE802154_FRAME_TYPE_ACK 0x2 -#define IEEE802154_FRAME_PENDING 1 << 4 -#define IEEE802154_ACK_REQUEST 1 << 5 -#define IEEE802154_DSN_OFFSET 2 - -#define QORVO_RSSI_OFFSET 73 -#define QORVO_CRC_BIT_MASK 0x80 -#define QORVO_LQI_BIT_MASK 0x7f +enum +{ + QPG_RECEIVE_SENSITIVITY = -100, // [dBm] + QPG_CSL_ACCURACY = 50, // [ppm] + QPG_CSL_CLOCK_UNCERTAINTY = 1, // [10us] +}; + +enum +{ + IEEE802154_ACK_LENGTH = 5, + IEEE802154_FRAME_TYPE_ACK = 0x2, + IEEE802154_FRAME_PENDING = 1 << 4, + IEEE802154_DSN_OFFSET = 2, +}; extern otRadioFrame sTransmitFrame; @@ -243,6 +241,8 @@ void otPlatRadioSetMacKey(otInstance *aInstance, void otPlatRadioSetMacFrameCounter(otInstance *aInstance, uint32_t aMacFrameCounter) { + OT_UNUSED_VARIABLE(aInstance); + qorvoRadioSetMacFrameCounter(aMacFrameCounter); } @@ -389,7 +389,7 @@ void cbQorvoRadioTxStarted(otRadioFrame *aFrame) void cbQorvoRadioTransmitDone_AckFrame(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError) { - otPlatRadioTxDone(pQorvoInstance, aFrame, aAckFrame, aError); + otPlatRadioTxDone(pQorvoInstance, aFrame, (aError == OT_ERROR_NONE) ? aAckFrame : NULL, aError); } void cbQorvoRadioTransmitDone(otRadioFrame *aFrame, bool aFramePending, otError aError) @@ -410,7 +410,7 @@ void cbQorvoRadioTransmitDone(otRadioFrame *aFrame, bool aFramePending, otError ackFrame.mPsdu[1] = 0; ackFrame.mPsdu[2] = aFrame->mPsdu[IEEE802154_DSN_OFFSET]; - otPlatRadioTxDone(pQorvoInstance, aFrame, &ackFrame, aError); + otPlatRadioTxDone(pQorvoInstance, aFrame, (aError == OT_ERROR_NONE) ? &ackFrame : NULL, aError); } void cbQorvoDiagRadioTransmitDone(otRadioFrame *aFrame, otError aError) @@ -550,7 +550,7 @@ uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance) return QPG_CSL_ACCURACY; } -uint8_t otPlatRadioGetCslClockUncertainty(otInstance *aInstance) +uint8_t otPlatRadioGetCslUncertainty(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); diff --git a/src/qpg6105/settings.cpp b/src/qpg6105/settings.c similarity index 99% rename from src/qpg6105/settings.cpp rename to src/qpg6105/settings.c index 8250cf676..0d63eceee 100644 --- a/src/qpg6105/settings.cpp +++ b/src/qpg6105/settings.c @@ -75,7 +75,7 @@ otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint if (error == OT_ERROR_NOT_FOUND) { - if (aValue != nullptr) + if (aValue != NULL) { *aValueLength = 0; } diff --git a/src/qpg7015m/CMakeLists.txt b/src/qpg7015m/CMakeLists.txt index 75a7c3953..d2503c439 100644 --- a/src/qpg7015m/CMakeLists.txt +++ b/src/qpg7015m/CMakeLists.txt @@ -32,7 +32,7 @@ list(APPEND OT_PLATFORM_DEFINES ) target_compile_definitions(ot-config INTERFACE - "MBEDTLS_USER_CONFIG_FILE=\"qpg7015m-mbedtls-config.h\"" + "MBEDTLS_USER_CONFIG_FILE=\"${QORVO_PLATFORM}-mbedtls-config.h\"" ) list(APPEND OT_PUBLIC_INCLUDES @@ -43,14 +43,6 @@ set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) set(OT_PUBLIC_INCLUDES ${OT_PUBLIC_INCLUDES} PARENT_SCOPE) -if(OT_CFLAGS MATCHES "-pedantic-errors") - string(REPLACE "-pedantic-errors" "" OT_CFLAGS "${OT_CFLAGS}") -endif() - -if(OT_CFLAGS MATCHES "-Wno-c\\+\\+14-compat") - string(REPLACE "-Wno-c++14-compat" "" OT_CFLAGS "${OT_CFLAGS}") -endif() - set(PLATFORM_SOURCES alarm.c diag.c @@ -72,22 +64,21 @@ else() ) endif() -add_library(openthread-qpg7015m-ftd +add_library(${PLATFORM_TARGET_FTD} STATIC ${PLATFORM_SOURCES} ) -set_target_properties( - openthread-qpg7015m-ftd +set_target_properties(${PLATFORM_TARGET_FTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 11 + CXX_STANDARD 14 ) -target_link_libraries(openthread-qpg7015m-ftd +target_link_libraries(${PLATFORM_TARGET_FTD} PRIVATE -Wl,--start-group - qpg7015m-driver-ftd + ${PLATFORM_DRIVER_FTD} ${OT_MBEDTLS} ot-config -Wl,--end-group @@ -98,38 +89,37 @@ target_link_libraries(openthread-qpg7015m-ftd -Wl,-Map=$.map ) -target_compile_definitions(openthread-qpg7015m-ftd +target_compile_definitions(${PLATFORM_TARGET_FTD} PUBLIC ${OT_PLATFORM_DEFINES} ) -target_compile_options(openthread-qpg7015m-ftd +target_compile_options(${PLATFORM_TARGET_FTD} PRIVATE ${OT_CFLAGS} ) -target_include_directories(openthread-qpg7015m-ftd +target_include_directories(${PLATFORM_TARGET_FTD} PRIVATE ${OT_PUBLIC_INCLUDES} ${OPENTHREAD_DIR}/examples/platforms ) -add_library(openthread-qpg7015m-mtd +add_library(${PLATFORM_TARGET_MTD} STATIC ${PLATFORM_SOURCES} ) -set_target_properties( - openthread-qpg7015m-mtd +set_target_properties(${PLATFORM_TARGET_MTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 11 + CXX_STANDARD 14 ) -target_link_libraries(openthread-qpg7015m-mtd +target_link_libraries(${PLATFORM_TARGET_MTD} PRIVATE -Wl,--start-group - qpg7015m-driver-mtd + ${PLATFORM_DRIVER_MTD} ${OT_MBEDTLS} ot-config -Wl,--end-group @@ -140,17 +130,17 @@ target_link_libraries(openthread-qpg7015m-mtd -Wl,-Map=$.map ) -target_compile_definitions(openthread-qpg7015m-mtd +target_compile_definitions(${PLATFORM_TARGET_MTD} PUBLIC ${OT_PLATFORM_DEFINES} ) -target_compile_options(openthread-qpg7015m-mtd +target_compile_options(${PLATFORM_TARGET_MTD} PRIVATE ${OT_CFLAGS} ) -target_include_directories(openthread-qpg7015m-mtd +target_include_directories(${PLATFORM_TARGET_MTD} PRIVATE ${OT_PUBLIC_INCLUDES} ${OPENTHREAD_DIR}/examples/platforms diff --git a/src/qpg7015m/openthread-core-qpg7015m-config.h b/src/qpg7015m/openthread-core-qpg7015m-config.h index cdae4564f..02751db2d 100755 --- a/src/qpg7015m/openthread-core-qpg7015m-config.h +++ b/src/qpg7015m/openthread-core-qpg7015m-config.h @@ -217,14 +217,4 @@ #define OPENTHREAD_CONFIG_HEAP_INTERNAL_SIZE (2048 * sizeof(void *)) #endif -/** - * @def OPENTHREAD_CONFIG_TLS_ENABLE - * - * Define as 1 to enable support for TLS over TCP. - * - */ -#ifndef OPENTHREAD_CONFIG_TLS_ENABLE -#define OPENTHREAD_CONFIG_TLS_ENABLE 0 -#endif - #endif // OPENTHREAD_CORE_QPG7015M_CONFIG_H_ diff --git a/src/qpg7015m/radio.c b/src/qpg7015m/radio.c index 6a491e218..d502132dc 100644 --- a/src/qpg7015m/radio.c +++ b/src/qpg7015m/radio.c @@ -36,27 +36,26 @@ #include #include +#include #include "utils/code_utils.h" #include "radio_qorvo.h" -#define QPG_RECEIVE_SENSITIVITY -100 // dBm -#define QPG_CSL_ACCURACY 50 // ppm -#define QPG_CSL_CLOCK_UNCERTAINTY 255 // 10us - -#define IEEE802154_MIN_LENGTH 5 -#define IEEE802154_MAX_LENGTH 127 -#define IEEE802154_ACK_LENGTH 5 -#define IEEE802154_FRAME_TYPE_MASK 0x7 -#define IEEE802154_FRAME_TYPE_ACK 0x2 -#define IEEE802154_FRAME_PENDING 1 << 4 -#define IEEE802154_ACK_REQUEST 1 << 5 -#define IEEE802154_DSN_OFFSET 2 +enum +{ + QPG_RECEIVE_SENSITIVITY = -100, // [dBm] + QPG_CSL_ACCURACY = 50, // [ppm] + QPG_CSL_CLOCK_UNCERTAINTY = 255, // [10us] +}; -#define QORVO_RSSI_OFFSET 73 -#define QORVO_CRC_BIT_MASK 0x80 -#define QORVO_LQI_BIT_MASK 0x7f +enum +{ + IEEE802154_ACK_LENGTH = 5, + IEEE802154_FRAME_TYPE_ACK = 0x2, + IEEE802154_FRAME_PENDING = 1 << 4, + IEEE802154_DSN_OFFSET = 2, +}; extern otRadioFrame sTransmitFrame; @@ -243,9 +242,17 @@ void otPlatRadioSetMacKey(otInstance *aInstance, void otPlatRadioSetMacFrameCounter(otInstance *aInstance, uint32_t aMacFrameCounter) { + OT_UNUSED_VARIABLE(aInstance); + qorvoRadioSetMacFrameCounter(aMacFrameCounter); } +uint64_t otPlatTimeGet(void) +{ + // required for RCP/spinel + return qorvoRadioGetNow(); +} + uint64_t otPlatRadioGetNow(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); @@ -389,7 +396,7 @@ void cbQorvoRadioTxStarted(otRadioFrame *aFrame) void cbQorvoRadioTransmitDone_AckFrame(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError) { - otPlatRadioTxDone(pQorvoInstance, aFrame, aAckFrame, aError); + otPlatRadioTxDone(pQorvoInstance, aFrame, (aError == OT_ERROR_NONE) ? aAckFrame : NULL, aError); } void cbQorvoRadioTransmitDone(otRadioFrame *aFrame, bool aFramePending, otError aError) @@ -410,7 +417,7 @@ void cbQorvoRadioTransmitDone(otRadioFrame *aFrame, bool aFramePending, otError ackFrame.mPsdu[1] = 0; ackFrame.mPsdu[2] = aFrame->mPsdu[IEEE802154_DSN_OFFSET]; - otPlatRadioTxDone(pQorvoInstance, aFrame, &ackFrame, aError); + otPlatRadioTxDone(pQorvoInstance, aFrame, (aError == OT_ERROR_NONE) ? &ackFrame : NULL, aError); } void cbQorvoDiagRadioTransmitDone(otRadioFrame *aFrame, otError aError) @@ -550,7 +557,7 @@ uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance) return QPG_CSL_ACCURACY; } -uint8_t otPlatRadioGetCslClockUncertainty(otInstance *aInstance) +uint8_t otPlatRadioGetCslUncertainty(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); diff --git a/src/qpg7015m/uart-posix.c b/src/qpg7015m/uart-posix.c index 1d1875550..b22c19ba1 100644 --- a/src/qpg7015m/uart-posix.c +++ b/src/qpg7015m/uart-posix.c @@ -79,7 +79,7 @@ static void cbKeyPressed(uint8_t Param) { OT_UNUSED_VARIABLE(Param); - qorvoAlarmScheduleEventArg(0, platformDummy, (void *)&s_in_fd); + qorvoAlarmMilliStart(0, platformDummy, (void *)&s_in_fd); } void platformUartRestore(void) @@ -216,7 +216,7 @@ otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength) s_write_buffer = aBuf; s_write_length = aBufLength; - qorvoAlarmScheduleEventArg(0, platformDummy, (void *)&s_in_fd); + qorvoAlarmMilliStart(0, platformDummy, (void *)&s_in_fd); exit: return error; diff --git a/third_party/Qorvo/CMakeLists.txt b/third_party/Qorvo/CMakeLists.txt index 67bfa65d1..f64e90b4d 100644 --- a/third_party/Qorvo/CMakeLists.txt +++ b/third_party/Qorvo/CMakeLists.txt @@ -27,40 +27,47 @@ # message(STATUS "Qorvo ${QORVO_PLATFORM} libs in ${SDK_DIR}/${QORVO_PLATFORM}") + string(TOUPPER ${QORVO_PLATFORM} QORVO_PLATFORM_UPPER) # setting defaults for the variables set(MBEDTLSALT "") set(MBEDCRYPTO "") -if(OT_FTD) - set(QORVO_PLATFORM_LIB_FTD "${SDK_DIR}/${QORVO_PLATFORM}/lib/libQorvo${QORVO_PLATFORM_UPPER}_ftd.a") -endif() -if (OT_MTD) - set(QORVO_PLATFORM_LIB_MTD "${SDK_DIR}/${QORVO_PLATFORM}/lib/libQorvo${QORVO_PLATFORM_UPPER}_mtd.a") -endif() - -# QPG6100 and QPG6105 use mbedtls_alt -if (QORVO_PLATFORM MATCHES "qpg6100" OR QORVO_PLATFORM MATCHES "qpg6105") +# mbedtls +if (${QORVO_MBEDTLS}) + if (DEFINED ENV{QORVO_OT_MBEDTLS_SDK}) + SET(QORVO_MBEDTLS_DIR "$ENV{QORVO_OT_MBEDTLS_SDK}") + else() + SET(QORVO_MBEDTLS_DIR "${SDK_DIR}") + endif() set(MBEDTLSALT "${SDK_DIR}/${QORVO_PLATFORM}/lib/libmbedtls_alt.a") + set(QORVO_MBEDTLS_SDK_DIR "${QORVO_MBEDTLS_DIR}/qorvo-mbedtls/") + if(NOT EXISTS ${QORVO_MBEDTLS_SDK_DIR}/mbedtls/v3.3.0/include/mbedtls) + message(FATAL_ERROR "'${QORVO_MBEDTLS_SDK_DIR}/mbedtls/v3.3.0/include/mbedtls' does not exist. Try setting 'QORVO_OT_SDK' or 'QORVO_OT_MBEDTLS_SDK'") + endif() + message(STATUS "Including Qorvo MBEDTLS - ${QORVO_MBEDTLS_SDK_DIR}") + + include(${QORVO_MBEDTLS_SDK_DIR}/mbedtls.cmake) + + list(APPEND OT_PUBLIC_INCLUDES "${QORVO_MBEDTLS_SDK_DIR}/mbedtls/v3.3.0/include/mbedtls") + list(APPEND OT_PUBLIC_INCLUDES "${QORVO_MBEDTLS_SDK_DIR}/inc") + + set(OT_PUBLIC_INCLUDES ${OT_PUBLIC_INCLUDES} PARENT_SCOPE) +else() set(MBEDCRYPTO "mbedcrypto") endif() -message( STATUS "Building platform ${QORVO_PLATFORM}" ) - -add_library(${QORVO_PLATFORM}-driver-ftd INTERFACE) -target_link_libraries(${QORVO_PLATFORM}-driver-ftd - INTERFACE - ${QORVO_PLATFORM_LIB_FTD} - ${MBEDTLSALT} - ${MBEDCRYPTO} -) +foreach(TYPE "FTD" "MTD") + string(TOLOWER ${TYPE} ftd) + set(QORVO_PLATFORM_LIB_${TYPE} "${SDK_DIR}/${QORVO_PLATFORM}/lib/libQorvo${QORVO_PLATFORM_UPPER}_${ftd}.a") -add_library(${QORVO_PLATFORM}-driver-mtd INTERFACE) -target_link_libraries(${QORVO_PLATFORM}-driver-mtd - INTERFACE - ${QORVO_PLATFORM_LIB_MTD} - ${MBEDTLSALT} - ${MBEDCRYPTO} -) + add_library(${PLATFORM_DRIVER_${TYPE}} INTERFACE) + target_link_libraries(${PLATFORM_DRIVER_${TYPE}} + INTERFACE + ${QORVO_PLATFORM_LIB_${TYPE}} + ${MBEDTLSALT} + ${MBEDCRYPTO} + ) +endforeach() diff --git a/third_party/Qorvo/repo b/third_party/Qorvo/repo index 2b9ca47a1..7a67c5b61 160000 --- a/third_party/Qorvo/repo +++ b/third_party/Qorvo/repo @@ -1 +1 @@ -Subproject commit 2b9ca47a15d05caa2524b5888c77cb3689d6eb1a +Subproject commit 7a67c5b613971d3e66a1ffd6d98391550c9f96e9