Initial snapshot: Aliro applet, harness, Nucleo NFC10A1 reader port
Three components, all bench-validated to varying depths: - applet/: CSA Aliro v1.0 Java Card applet for J3R180. AUTH0 + AUTH1 expedited-standard flow end-to-end green via PC/SC bench reader (aliro-bench-test). Userland AES-256-GCM and HMAC-SHA-256 layered on top of J3R180's primitives because the card lacks both natively. P-256 curve params seeded explicitly per J3R180's quirk. - harness/: Python orchestrator (aliro-trustgen, aliro-personalize, aliro-bench-test) for trust-bundle generation, card personalization via PersonalizationApplet, and PC/SC AUTH0+AUTH1 transactions. 126 pytest cases passing. - reader/STM32CubeExpansion_ALIRO_V1_0_0/: ST X-CUBE-ALIRO V1.0.0 with our NFC10A1 port (NUCLEO-U545RE-Q + X-NUCLEO-NFC10A1, ST25R200 shared with NFC09A1). nfc10-only/ project, NFC10A1 BSP shim, ALIRO_TRUST_OVERRIDE include into vendor's provisioning.c, and an ALIRO_APDU_TRACE wrapper around demoTransceiveBlocking. Boots, detects the J3R180, completes SELECT + AUTH0; AUTH1 currently fails with RFAL ERR_PROTO (0xB) — under investigation, see docs/plans/2026-04-20-nucleo-nfc10a1-port.md and bench-notes/. Excluded: x-cube-aliro.zip vendor archive, harness/.venv, build dirs, generated aliro_trust.h (contains private reader scalar), all PEMs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(Aliro LANGUAGES C)
|
||||
|
||||
# Collect all source files in Src
|
||||
file(GLOB ALIRO_SRC "Src/*.c")
|
||||
|
||||
# Path to the precompiled library
|
||||
set(ALIRO_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/aliro.a")
|
||||
|
||||
# Create a static library from the source files
|
||||
add_library(aliro_src STATIC ${ALIRO_SRC})
|
||||
|
||||
# Create an interface target for the precompiled library
|
||||
add_library(aliro_prebuilt STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(aliro_prebuilt PROPERTIES
|
||||
IMPORTED_LOCATION "${ALIRO_LIB_PATH}"
|
||||
)
|
||||
|
||||
# Create an interface target that combines both
|
||||
add_library(aliro INTERFACE)
|
||||
target_link_libraries(aliro INTERFACE aliro_prebuilt aliro_src)
|
||||
target_include_directories(aliro INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/Inc)
|
||||
|
||||
# Usage:
|
||||
# target_link_libraries(your_target PRIVATE aliro)
|
||||
|
||||
# Example
|
||||
# # Add the Aliro library directory
|
||||
# add_subdirectory(path/to/Aliro)
|
||||
|
||||
# # Link to the Aliro interface target
|
||||
# target_link_libraries(my_app PRIVATE aliro)
|
||||
@@ -0,0 +1,307 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : ST_provisioning.h
|
||||
* @brief : This file provides the provisioning profiles for User.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup USER_PROVISIONING
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Reader ID and Sub ID for User provisioning without certificate.
|
||||
* @details
|
||||
* Reader ID and Sub ID used for User provisioning without certificate.
|
||||
*/
|
||||
/* Provisioning without Certificate*/
|
||||
// reader_id_User:8f9633dd856d2a156f2aee573deb11e5
|
||||
// reader_sub_id_User:43815ef53299c92e95b052138133ed39
|
||||
#define READER_ID_2 {0x8f, 0x96, 0x33, 0xdd, 0x85, 0x6d, 0x2a, 0x15, 0x6f, 0x2a, 0xee, 0x57, 0x3d, 0xeb, 0x11, 0xe5, 0x43, 0x81, 0x5e, 0xf5, 0x32, 0x99, 0xc9, 0x2e, 0x95, 0xb0, 0x52, 0x13, 0x81, 0x33, 0xed, 0x39}
|
||||
|
||||
/**
|
||||
* @brief Reader public key for User provisioning without certificate.
|
||||
* @details
|
||||
* Reader public key for User provisioning without certificate.
|
||||
*/
|
||||
// reader_public_key_User:045bc20b2853e11fcb086192d8a5d5b7829b13d143b0da2de68e1bc94f8b016027a8854eae0226d4205e8f710d168da2f57d3fa2150b64338d212ce015e200513f
|
||||
#define READER_PUB_KEY_2 {0x5b, 0xc2, 0x0b, 0x28, 0x53, 0xe1, 0x1f, 0xcb, 0x08, 0x61, 0x92, 0xd8, 0xa5, 0xd5, 0xb7, 0x82, 0x9b, 0x13, 0xd1, 0x43, 0xb0, 0xda, 0x2d, 0xe6, 0x8e, 0x1b, 0xc9, 0x4f, 0x8b, 0x01, 0x60, 0x27, 0xa8, 0x85, 0x4e, 0xae, 0x02, 0x26, 0xd4, 0x20, 0x5e, 0x8f, 0x71, 0x0d, 0x16, 0x8d, 0xa2, 0xf5, 0x7d, 0x3f, 0xa2, 0x15, 0x0b, 0x64, 0x33, 0x8d, 0x21, 0x2c, 0xe0, 0x15, 0xe2, 0x00, 0x51, 0x3f}
|
||||
|
||||
/**
|
||||
* @brief Reader private key for User provisioning without certificate.
|
||||
* @details
|
||||
* Reader private key for User provisioning without certificate.
|
||||
*/
|
||||
// reader_private_key_User:cb64a58a5fae052d458b3bce2599a20a665987b537b157cc3cc42e1d9c652409
|
||||
#define READER_PRIVATE_KEY_2 {0xcb, 0x64, 0xa5, 0x8a, 0x5f, 0xae, 0x05, 0x2d, 0x45, 0x8b, 0x3b, 0xce, 0x25, 0x99, 0xa2, 0x0a, 0x66, 0x59, 0x87, 0xb5, 0x37, 0xb1, 0x57, 0xcc, 0x3c, 0xc4, 0x2e, 0x1d, 0x9c, 0x65, 0x24, 0x09}
|
||||
|
||||
/**
|
||||
* @brief Reader issuer public key for User provisioning without certificate.
|
||||
* @details
|
||||
* Not used for User provisioning without certificate.
|
||||
*/
|
||||
#define READER_ISSUER_PUB_KEY_2 { 0 }
|
||||
|
||||
/**
|
||||
* @brief Reader issuer private key for User provisioning without certificate.
|
||||
* @details
|
||||
* Not used for User provisioning without certificate.
|
||||
*/
|
||||
#define READER_ISSUER_PRIVATE_KEY_2 { 0 }
|
||||
|
||||
/**
|
||||
* @brief Reader certificate for User provisioning without certificate.
|
||||
* @details
|
||||
* Not used for User provisioning without certificate.
|
||||
*/
|
||||
#define READER_CERTIFICATE_2 { 0 }
|
||||
|
||||
/**
|
||||
* @brief Group resolving key for User provisioning without certificate.
|
||||
* @details
|
||||
* Group resolving key used for User provisioning without certificate.
|
||||
*/
|
||||
#define GROUP_RESOLVING_KEY_2 GROUP_RESOLVING_KEY
|
||||
|
||||
/**
|
||||
* @brief Endpoint key slot for User provisioning without certificate.
|
||||
* @details
|
||||
* Key slot identifier for endpoint.
|
||||
*/
|
||||
#define ENDPOINT_KEYSLOT_2 ENDPOINT_KEYSLOT
|
||||
|
||||
/**
|
||||
* @brief Endpoint public key for User provisioning without certificate.
|
||||
* @details
|
||||
* Endpoint public key for endpoint.
|
||||
*/
|
||||
#define ENDPOINT_PUBLIC_KEY_2 ENDPOINT_PUBLIC_KEY
|
||||
|
||||
/**
|
||||
* @brief Endpoint private key for User provisioning without certificate.
|
||||
* @details
|
||||
* Endpoint private key for endpoint.
|
||||
*/
|
||||
#define ENDPOINT_PRIVATE_KEY_2 ENDPOINT_PRIVATE_KEY
|
||||
|
||||
/**
|
||||
* @brief Endpoint name for User provisioning without certificate.
|
||||
* @details
|
||||
* Endpoint name for endpoint.
|
||||
*/
|
||||
#define ENDPOINT_NAME_2 "User"
|
||||
|
||||
/**
|
||||
* @brief Vendor specific extension for User provisioning without certificate.
|
||||
* @details
|
||||
* Vendor specific extension for endpoint.
|
||||
*/
|
||||
#define B1_VENDOR_SPECIFIC_EXTENSION_2 B1_VENDOR_SPECIFIC_EXTENSION
|
||||
|
||||
/**
|
||||
* @brief Length of vendor specific extension for User provisioning without certificate.
|
||||
* @details
|
||||
* Length of vendor specific extension for endpoint.
|
||||
*/
|
||||
#define B1_VENDOR_SPECIFIC_EXTENSION_LEN_2 B1_VENDOR_SPECIFIC_EXTENSION_LEN
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reader ID and Sub ID for User provisioning with certificate.
|
||||
* @details
|
||||
* Reader ID and Sub ID used for User provisioning with certificate.
|
||||
*/
|
||||
/* Provisioning with Certificate*/
|
||||
// reader_id_cert_User:9f9633dd856d2a156f2aee573deb11e5
|
||||
// reader_sub_id_cert_User:43815ef53299c92e95b052138133ed39
|
||||
#define READER_ID {0x9f, 0x96, 0x33, 0xdd, 0x85, 0x6d, 0x2a, 0x15, 0x6f, 0x2a, 0xee, 0x57, 0x3d, 0xeb, 0x11, 0xe5, 0x43, 0x81, 0x5e, 0xf5, 0x32, 0x99, 0xc9, 0x2e, 0x95, 0xb0, 0x52, 0x13, 0x81, 0x33, 0xed, 0x39}
|
||||
|
||||
/**
|
||||
* @brief Reader public key for User provisioning with certificate.
|
||||
* @details
|
||||
* Reader public key for User provisioning with certificate.
|
||||
*/
|
||||
// reader_public_key_cert_User:045bc20b2853e11fcb086192d8a5d5b7829b13d143b0da2de68e1bc94f8b016027a8854eae0226d4205e8f710d168da2f57d3fa2150b64338d212ce015e200513f
|
||||
#define READER_PUB_KEY {0x5b, 0xc2, 0x0b, 0x28, 0x53, 0xe1, 0x1f, 0xcb, 0x08, 0x61, 0x92, 0xd8, 0xa5, 0xd5, 0xb7, 0x82, 0x9b, 0x13, 0xd1, 0x43, 0xb0, 0xda, 0x2d, 0xe6, 0x8e, 0x1b, 0xc9, 0x4f, 0x8b, 0x01, 0x60, 0x27, 0xa8, 0x85, 0x4e, 0xae, 0x02, 0x26, 0xd4, 0x20, 0x5e, 0x8f, 0x71, 0x0d, 0x16, 0x8d, 0xa2, 0xf5, 0x7d, 0x3f, 0xa2, 0x15, 0x0b, 0x64, 0x33, 0x8d, 0x21, 0x2c, 0xe0, 0x15, 0xe2, 0x00, 0x51, 0x3f}
|
||||
|
||||
/**
|
||||
* @brief Reader private key for User provisioning with certificate.
|
||||
* @details
|
||||
* Reader private key for User provisioning with certificate.
|
||||
*/
|
||||
// reader_private_key_cert_User:cb64a58a5fae052d458b3bce2599a20a665987b537b157cc3cc42e1d9c652409
|
||||
#define READER_PRIVATE_KEY {0xcb, 0x64, 0xa5, 0x8a, 0x5f, 0xae, 0x05, 0x2d, 0x45, 0x8b, 0x3b, 0xce, 0x25, 0x99, 0xa2, 0x0a, 0x66, 0x59, 0x87, 0xb5, 0x37, 0xb1, 0x57, 0xcc, 0x3c, 0xc4, 0x2e, 0x1d, 0x9c, 0x65, 0x24, 0x09}
|
||||
|
||||
/**
|
||||
* @brief Reader issuer public key for User provisioning with certificate.
|
||||
* @details
|
||||
* Reader issuer public key for User provisioning with certificate.
|
||||
*/
|
||||
// reader_issuer_public_key_cert_User:04fbc3fdac291606a0a986862004bbe5c6188ce64098f4a65b7a6595fc31f416259141a972b916e6321dbeee22b77eec5929d80779c99f8ebe5c2588f24b24de68
|
||||
#define READER_ISSUER_PUB_KEY {0xfb, 0xc3, 0xfd, 0xac, 0x29, 0x16, 0x06, 0xa0, 0xa9, 0x86, 0x86, 0x20, 0x04, 0xbb, 0xe5, 0xc6, 0x18, 0x8c, 0xe6, 0x40, 0x98, 0xf4, 0xa6, 0x5b, 0x7a, 0x65, 0x95, 0xfc, 0x31, 0xf4, 0x16, 0x25, 0x91, 0x41, 0xa9, 0x72, 0xb9, 0x16, 0xe6, 0x32, 0x1d, 0xbe, 0xee, 0x22, 0xb7, 0x7e, 0xec, 0x59, 0x29, 0xd8, 0x07, 0x79, 0xc9, 0x9f, 0x8e, 0xbe, 0x5c, 0x25, 0x88, 0xf2, 0x4b, 0x24, 0xde, 0x68}
|
||||
|
||||
/**
|
||||
* @brief Reader issuer private key for User provisioning with certificate.
|
||||
* @details
|
||||
* Reader issuer private key for User provisioning with certificate.
|
||||
*/
|
||||
// reader_issuer_private_key_cert_User:31222ec2125a2921671e471ae67b8796668e37c0167c72bf540e4c5393599f85
|
||||
#define READER_ISSUER_PRIVATE_KEY {0x31, 0x22, 0x2e, 0xc2, 0x12, 0x5a, 0x29, 0x21, 0x67, 0x1e, 0x47, 0x1a, 0xe6, 0x7b, 0x87, 0x96, 0x66, 0x8e, 0x37, 0xc0, 0x16, 0x7c, 0x72, 0xbf, 0x54, 0x0e, 0x4c, 0x53, 0x93, 0x59, 0x9f, 0x85}
|
||||
|
||||
/**
|
||||
* @brief Reader certificate for User provisioning with certificate.
|
||||
* @details
|
||||
* Reader certificate for User provisioning with certificate.
|
||||
*/
|
||||
// reader_certificate_cert_User:3081e8040200003081e18014269e0680731d796703576be42b668a7dfe9c1e29811253544d6963726f656c656374726f6e696373820d3235313231363135343034395a830d3330313231363135343034395a840844656d6f6c6f636b854200045bc20b2853e11fcb086192d8a5d5b7829b13d143b0da2de68e1bc94f8b016027a8854eae0226d4205e8f710d168da2f57d3fa2150b64338d212ce015e200513f8649003046022100f1e0b84ad64aa078a039cc1be850a9d1534d52a26d6a5e137e0a710f59f12b49022100d089e452ee102cb5813eaded8625cc4b54b69835ec2e4c59c12e2a4a495dddaf
|
||||
#define READER_CERTIFICATE {0x30, 0x81, 0xe8, 0x04, 0x02, 0x00, 0x00, 0x30, 0x81, 0xe1, 0x80, 0x14, 0x26, 0x9e, 0x06, 0x80, 0x73, 0x1d, 0x79, 0x67, 0x03, 0x57, 0x6b, 0xe4, 0x2b, 0x66, 0x8a, 0x7d, 0xfe, 0x9c, 0x1e, 0x29, 0x81, 0x12, 0x53, 0x54, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x73, 0x82, 0x0d, 0x32, 0x35, 0x31, 0x32, 0x31, 0x36, 0x31, 0x35, 0x34, 0x30, 0x34, 0x39, 0x5a, 0x83, 0x0d, 0x33, 0x30, 0x31, 0x32, 0x31, 0x36, 0x31, 0x35, 0x34, 0x30, 0x34, 0x39, 0x5a, 0x84, 0x08, 0x44, 0x65, 0x6d, 0x6f, 0x6c, 0x6f, 0x63, 0x6b, 0x85, 0x42, 0x00, 0x04, 0x5b, 0xc2, 0x0b, 0x28, 0x53, 0xe1, 0x1f, 0xcb, 0x08, 0x61, 0x92, 0xd8, 0xa5, 0xd5, 0xb7, 0x82, 0x9b, 0x13, 0xd1, 0x43, 0xb0, 0xda, 0x2d, 0xe6, 0x8e, 0x1b, 0xc9, 0x4f, 0x8b, 0x01, 0x60, 0x27, 0xa8, 0x85, 0x4e, 0xae, 0x02, 0x26, 0xd4, 0x20, 0x5e, 0x8f, 0x71, 0x0d, 0x16, 0x8d, 0xa2, 0xf5, 0x7d, 0x3f, 0xa2, 0x15, 0x0b, 0x64, 0x33, 0x8d, 0x21, 0x2c, 0xe0, 0x15, 0xe2, 0x00, 0x51, 0x3f, 0x86, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xf1, 0xe0, 0xb8, 0x4a, 0xd6, 0x4a, 0xa0, 0x78, 0xa0, 0x39, 0xcc, 0x1b, 0xe8, 0x50, 0xa9, 0xd1, 0x53, 0x4d, 0x52, 0xa2, 0x6d, 0x6a, 0x5e, 0x13, 0x7e, 0x0a, 0x71, 0x0f, 0x59, 0xf1, 0x2b, 0x49, 0x02, 0x21, 0x00, 0xd0, 0x89, 0xe4, 0x52, 0xee, 0x10, 0x2c, 0xb5, 0x81, 0x3e, 0xad, 0xed, 0x86, 0x25, 0xcc, 0x4b, 0x54, 0xb6, 0x98, 0x35, 0xec, 0x2e, 0x4c, 0x59, 0xc1, 0x2e, 0x2a, 0x4a, 0x49, 0x5d, 0xdd, 0xaf}
|
||||
|
||||
/**
|
||||
* @brief Reader long certificate for User provisioning with certificate.
|
||||
* @details
|
||||
* Reader long certificate for User provisioning with certificate.
|
||||
*/
|
||||
// reader_certificate_cert_long_User:3082010b0402000030820103801412c2a20661964981c92cd242e6d06d2ce8053b4f811f53544d6963726f656c656374726f6e69637353544d6963726f656c65637472820d3235313231363135343034395a830d3330313231363135343034395a841f44656d6f6c6f636b44656d6f6c6f636b44656d6f6c6f636b44656d6f6c6f63854200045bc20b2853e11fcb086192d8a5d5b7829b13d143b0da2de68e1bc94f8b016027a8854eae0226d4205e8f710d168da2f57d3fa2150b64338d212ce015e200513f864700304402206aef6a6cf112f97c16c1e844f65ef3913cbe388b4e9ee8795fbc08f240f5337702205da03ad102a63e1095da5692a463db8d18866b07e5580f6ef0f28c5153ac3400
|
||||
#define READER_LONG_CERTIFICATE {0x30, 0x82, 0x01, 0x0b, 0x04, 0x02, 0x00, 0x00, 0x30, 0x82, 0x01, 0x03, 0x80, 0x14, 0x12, 0xc2, 0xa2, 0x06, 0x61, 0x96, 0x49, 0x81, 0xc9, 0x2c, 0xd2, 0x42, 0xe6, 0xd0, 0x6d, 0x2c, 0xe8, 0x05, 0x3b, 0x4f, 0x81, 0x1f, 0x53, 0x54, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x73, 0x53, 0x54, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x72, 0x82, 0x0d, 0x32, 0x35, 0x31, 0x32, 0x31, 0x36, 0x31, 0x35, 0x34, 0x30, 0x34, 0x39, 0x5a, 0x83, 0x0d, 0x33, 0x30, 0x31, 0x32, 0x31, 0x36, 0x31, 0x35, 0x34, 0x30, 0x34, 0x39, 0x5a, 0x84, 0x1f, 0x44, 0x65, 0x6d, 0x6f, 0x6c, 0x6f, 0x63, 0x6b, 0x44, 0x65, 0x6d, 0x6f, 0x6c, 0x6f, 0x63, 0x6b, 0x44, 0x65, 0x6d, 0x6f, 0x6c, 0x6f, 0x63, 0x6b, 0x44, 0x65, 0x6d, 0x6f, 0x6c, 0x6f, 0x63, 0x85, 0x42, 0x00, 0x04, 0x5b, 0xc2, 0x0b, 0x28, 0x53, 0xe1, 0x1f, 0xcb, 0x08, 0x61, 0x92, 0xd8, 0xa5, 0xd5, 0xb7, 0x82, 0x9b, 0x13, 0xd1, 0x43, 0xb0, 0xda, 0x2d, 0xe6, 0x8e, 0x1b, 0xc9, 0x4f, 0x8b, 0x01, 0x60, 0x27, 0xa8, 0x85, 0x4e, 0xae, 0x02, 0x26, 0xd4, 0x20, 0x5e, 0x8f, 0x71, 0x0d, 0x16, 0x8d, 0xa2, 0xf5, 0x7d, 0x3f, 0xa2, 0x15, 0x0b, 0x64, 0x33, 0x8d, 0x21, 0x2c, 0xe0, 0x15, 0xe2, 0x00, 0x51, 0x3f, 0x86, 0x47, 0x00, 0x30, 0x44, 0x02, 0x20, 0x6a, 0xef, 0x6a, 0x6c, 0xf1, 0x12, 0xf9, 0x7c, 0x16, 0xc1, 0xe8, 0x44, 0xf6, 0x5e, 0xf3, 0x91, 0x3c, 0xbe, 0x38, 0x8b, 0x4e, 0x9e, 0xe8, 0x79, 0x5f, 0xbc, 0x08, 0xf2, 0x40, 0xf5, 0x33, 0x77, 0x02, 0x20, 0x5d, 0xa0, 0x3a, 0xd1, 0x02, 0xa6, 0x3e, 0x10, 0x95, 0xda, 0x56, 0x92, 0xa4, 0x63, 0xdb, 0x8d, 0x18, 0x86, 0x6b, 0x07, 0xe5, 0x58, 0x0f, 0x6e, 0xf0, 0xf2, 0x8c, 0x51, 0x53, 0xac, 0x34, 0x00}
|
||||
|
||||
/**
|
||||
* @brief Reader short certificate for User provisioning with certificate.
|
||||
* @details
|
||||
* Reader short certificate for User provisioning with certificate.
|
||||
*/
|
||||
// reader_certificate_cert_short_User:3081940402000030818d854200045bc20b2853e11fcb086192d8a5d5b7829b13d143b0da2de68e1bc94f8b016027a8854eae0226d4205e8f710d168da2f57d3fa2150b64338d212ce015e200513f8647003044022004060b7ec96115558aaa21686b8a5cd76c3cf0ef0214ef3d93189b789624c48f022031664dc32677ff6eba89126ebd212f903dc0dc8a4c837ebb306e062ba2231be2
|
||||
#define READER_SHORT_CERTIFICATE {0x30, 0x81, 0x94, 0x04, 0x02, 0x00, 0x00, 0x30, 0x81, 0x8d, 0x85, 0x42, 0x00, 0x04, 0x5b, 0xc2, 0x0b, 0x28, 0x53, 0xe1, 0x1f, 0xcb, 0x08, 0x61, 0x92, 0xd8, 0xa5, 0xd5, 0xb7, 0x82, 0x9b, 0x13, 0xd1, 0x43, 0xb0, 0xda, 0x2d, 0xe6, 0x8e, 0x1b, 0xc9, 0x4f, 0x8b, 0x01, 0x60, 0x27, 0xa8, 0x85, 0x4e, 0xae, 0x02, 0x26, 0xd4, 0x20, 0x5e, 0x8f, 0x71, 0x0d, 0x16, 0x8d, 0xa2, 0xf5, 0x7d, 0x3f, 0xa2, 0x15, 0x0b, 0x64, 0x33, 0x8d, 0x21, 0x2c, 0xe0, 0x15, 0xe2, 0x00, 0x51, 0x3f, 0x86, 0x47, 0x00, 0x30, 0x44, 0x02, 0x20, 0x04, 0x06, 0x0b, 0x7e, 0xc9, 0x61, 0x15, 0x55, 0x8a, 0xaa, 0x21, 0x68, 0x6b, 0x8a, 0x5c, 0xd7, 0x6c, 0x3c, 0xf0, 0xef, 0x02, 0x14, 0xef, 0x3d, 0x93, 0x18, 0x9b, 0x78, 0x96, 0x24, 0xc4, 0x8f, 0x02, 0x20, 0x31, 0x66, 0x4d, 0xc3, 0x26, 0x77, 0xff, 0x6e, 0xba, 0x89, 0x12, 0x6e, 0xbd, 0x21, 0x2f, 0x90, 0x3d, 0xc0, 0xdc, 0x8a, 0x4c, 0x83, 0x7e, 0xbb, 0x30, 0x6e, 0x06, 0x2b, 0xa2, 0x23, 0x1b, 0xe2}
|
||||
|
||||
/**
|
||||
* @brief Group resolving key for User provisioning with certificate.
|
||||
* @details
|
||||
* Group resolving key used for User provisioning with certificate.
|
||||
*/
|
||||
// group_resolving_key_User:0375ed63685570f6b2168eab7296ec01
|
||||
#define GROUP_RESOLVING_KEY {0x03, 0x75, 0xed, 0x63, 0x68, 0x55, 0x70, 0xf6, 0xb2, 0x16, 0x8e, 0xab, 0x72, 0x96, 0xec, 0x01}
|
||||
|
||||
/**
|
||||
* @brief Endpoint key slot for User provisioning with certificate.
|
||||
* @details
|
||||
* Key slot identifier for endpoint.
|
||||
*/
|
||||
// endpoint_key_slot_cert_Alice_User:54b54e27d515ac4c
|
||||
#define ENDPOINT_KEYSLOT {0x54, 0xb5, 0x4e, 0x27, 0xd5, 0x15, 0xac, 0x4c}
|
||||
|
||||
/**
|
||||
* @brief Endpoint public key for User provisioning with certificate.
|
||||
* @details
|
||||
* Endpoint public key for endpoint.
|
||||
*/
|
||||
// endpoint_public_key_cert_Alice_User:04773f9aa84ac9705161c490a2dba0b4a19a3d2a78705a801cff924e26357e4213191db83789a25916e4accea1fd6f09239b4cf2dd0d05b33b72d8a3a642e30866
|
||||
#define ENDPOINT_PUBLIC_KEY {0x77, 0x3f, 0x9a, 0xa8, 0x4a, 0xc9, 0x70, 0x51, 0x61, 0xc4, 0x90, 0xa2, 0xdb, 0xa0, 0xb4, 0xa1, 0x9a, 0x3d, 0x2a, 0x78, 0x70, 0x5a, 0x80, 0x1c, 0xff, 0x92, 0x4e, 0x26, 0x35, 0x7e, 0x42, 0x13, 0x19, 0x1d, 0xb8, 0x37, 0x89, 0xa2, 0x59, 0x16, 0xe4, 0xac, 0xce, 0xa1, 0xfd, 0x6f, 0x09, 0x23, 0x9b, 0x4c, 0xf2, 0xdd, 0x0d, 0x05, 0xb3, 0x3b, 0x72, 0xd8, 0xa3, 0xa6, 0x42, 0xe3, 0x08, 0x66}
|
||||
|
||||
/**
|
||||
* @brief Endpoint private key for User provisioning with certificate.
|
||||
* @details
|
||||
* Endpoint private key for endpoint.
|
||||
*/
|
||||
// endpoint_private_key_cert_Alice_User:db1d6524990aecce49c3c5c79ee41361b01b49302eac1cc5f9decd0d1058d14e
|
||||
#define ENDPOINT_PRIVATE_KEY {0xdb, 0x1d, 0x65, 0x24, 0x99, 0x0a, 0xec, 0xce, 0x49, 0xc3, 0xc5, 0xc7, 0x9e, 0xe4, 0x13, 0x61, 0xb0, 0x1b, 0x49, 0x30, 0x2e, 0xac, 0x1c, 0xc5, 0xf9, 0xde, 0xcd, 0x0d, 0x10, 0x58, 0xd1, 0x4e}
|
||||
|
||||
/**
|
||||
* @brief Endpoint name for User provisioning with certificate.
|
||||
* @details
|
||||
* Endpoint name for endpoint.
|
||||
*/
|
||||
#define ENDPOINT_NAME "User_cert"
|
||||
|
||||
/**
|
||||
* @brief Vendor specific extension for User provisioning with certificate.
|
||||
* @details
|
||||
* Vendor specific extension for endpoint.
|
||||
*/
|
||||
#define B1_VENDOR_SPECIFIC_EXTENSION "ST Rooms"
|
||||
|
||||
/**
|
||||
* @brief Vendor specific extension length for User provisioning with certificate.
|
||||
* @details
|
||||
* Vendor specific extension length for endpoint.
|
||||
*/
|
||||
#define B1_VENDOR_SPECIFIC_EXTENSION_LEN 8
|
||||
|
||||
|
||||
/**
|
||||
* @brief Credential issuer public key for User provisioning.
|
||||
* @details
|
||||
* Credential issuer public key for stepup menager.
|
||||
*/
|
||||
#define CREDENTIAL_ISSUER_PUB_KEY_2 { 0x7B, 0xA3, 0x19, 0x38, 0x49, 0x2E, 0x3F, 0x5E, 0x97, 0xBC, 0x91, 0x80, 0x6B, 0x58, 0x35, 0xB5, 0xD9, 0xE4, 0x26, 0x60, 0x91, 0x39, 0x00, 0x67, 0x11, 0xE5, 0xFB, 0x7A, 0x67, 0x0E, 0xE4, 0xE1, 0x2F, 0xC9, 0xF2, 0x53, 0x96, 0xC0, 0x13, 0xCC, 0x20, 0x16, 0x60, 0x29, 0xD7, 0x61, 0xA1, 0x05, 0xDE, 0xA5, 0xE0, 0x71, 0xE8, 0x4A, 0x9E, 0x49, 0x99, 0x20, 0x52, 0x4C, 0xE2, 0x30, 0x11, 0x37 }
|
||||
|
||||
/**
|
||||
* @brief Credential issuer private key for User provisioning.
|
||||
* @details
|
||||
* Credential issuer private key for stepup menager.
|
||||
*/
|
||||
#define CREDENTIAL_ISSUER_PRIVATE_KEY_2 { 0 }
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Test Harness configuration
|
||||
{
|
||||
"test_parameters": {
|
||||
"dut_reader_public_key": "045bc20b2853e11fcb086192d8a5d5b7829b13d143b0da2de68e1bc94f8b016027a8854eae0226d4205e8f710d168da2f57d3fa2150b64338d212ce015e200513f",
|
||||
"dut_reader_group_identifier": "8f9633dd856d2a156f2aee573deb11e5",
|
||||
"dut_reader_issuer_public_key": "04fbc3fdac291606a0a986862004bbe5c6188ce64098f4a65b7a6595fc31f416259141a972b916e6321dbeee22b77eec5929d80779c99f8ebe5c2588f24b24de68",
|
||||
"dut_reader_issuer_group_identifier": "9f9633dd856d2a156f2aee573deb11e5",
|
||||
"dut_reader_group_sub_identifier": "43815ef53299c92e95b052138133ed39",
|
||||
"dut_reader_group_resolving_key": "0375ed63685570f6b2168eab7296ec01",
|
||||
"th_access_credential_private_key": "db1d6524990aecce49c3c5c79ee41361b01b49302eac1cc5f9decd0d1058d14e",
|
||||
"th_access_credential_public_key": "04773f9aa84ac9705161c490a2dba0b4a19a3d2a78705a801cff924e26357e4213191db83789a25916e4accea1fd6f09239b4cf2dd0d05b33b72d8a3a642e30866",
|
||||
"th_reader_private_key": "8aefdff8d5b47aa9a3edbac7a345ed2221021512fd55abde3b8ee0f208952693",
|
||||
"th_reader_public_key": "043928f322019d4757893bde6a0fe5e13e3e537b9ca0f549c0bd2f40f79060252a0a4f291192157a95cb6eb202759428c00cd834998c5d0eab192ee8873c5d34ee",
|
||||
"th_reader_group_identifier": "00113344667799AA00113344667799AA",
|
||||
"th_reader_sub_group_identifier": "113344667799AA00113344667799AA00",
|
||||
"th_reader_certificate": "308201523081f9a003020102020101300a06082a8648ce3d0403023011310f300d06035504030c06697373756572301e170d3230303130313030303030305a170d3439303130313030303030305a30123110300e06035504030c077375626a6563743059301306072a8648ce3d020106082a8648ce3d030107034200043928f322019d4757893bde6a0fe5e13e3e537b9ca0f549c0bd2f40f79060252a0a4f291192157a95cb6eb202759428c00cd834998c5d0eab192ee8873c5d34eea341303f301f0603551d230418301680143fb5efecb9f0a8b253e4b6788dc15a5913f7c763300c0603551d130101ff04023000300e0603551d0f0101ff040403020780300a06082a8648ce3d04030203480030450220296b57afcb0f1f86e7c3e76b16f82ea0737e8105d5c5e03f3333e6ef9193c80d022100909083e76eaaf0430c7639159b00620d0c6a40fdb6e11ec52ed5bdd3dfb1706f",
|
||||
"th_reader_group_resolving_key": "0375ed63685570f6b2168eab7296ec01",
|
||||
"th_reader_spsm": "0080"
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* Reader provisioning
|
||||
{
|
||||
"MaxDevices": 8,
|
||||
"reader_identifier": "8f9633dd856d2a156f2aee573deb11e543815ef53299c92e95b052138133ed39",
|
||||
"reader_PrivK": "cb64a58a5fae052d458b3bce2599a20a665987b537b157cc3cc42e1d9c652409",
|
||||
"reader_PubK": "045bc20b2853e11fcb086192d8a5d5b7829b13d143b0da2de68e1bc94f8b016027a8854eae0226d4205e8f710d168da2f57d3fa2150b64338d212ce015e200513f",
|
||||
"issuer_Private": "31222ec2125a2921671e471ae67b8796668e37c0167c72bf540e4c5393599f85",
|
||||
"issuer_Public": "04fbc3fdac291606a0a986862004bbe5c6188ce64098f4a65b7a6595fc31f416259141a972b916e6321dbeee22b77eec5929d80779c99f8ebe5c2588f24b24de68",
|
||||
"certificate_data": "3081e8040200003081e18014269e0680731d796703576be42b668a7dfe9c1e29811253544d6963726f656c656374726f6e696373820d3235313231363135343034395a830d3330313231363135343034395a840844656d6f6c6f636b854200045bc20b2853e11fcb086192d8a5d5b7829b13d143b0da2de68e1bc94f8b016027a8854eae0226d4205e8f710d168da2f57d3fa2150b64338d212ce015e200513f8649003046022100f1e0b84ad64aa078a039cc1be850a9d1534d52a26d6a5e137e0a710f59f12b49022100d089e452ee102cb5813eaded8625cc4b54b69835ec2e4c59c12e2a4a495dddaf",
|
||||
"b1VendorSpecificExtension": "ST Rooms",
|
||||
"Devices": [
|
||||
{
|
||||
"Name": "Alice",
|
||||
"endpoint_Keyslot": "54b54e27d515ac4c",
|
||||
"endpoint_PubK": "04773f9aa84ac9705161c490a2dba0b4a19a3d2a78705a801cff924e26357e4213191db83789a25916e4accea1fd6f09239b4cf2dd0d05b33b72d8a3a642e30866",
|
||||
"endpoint_PrivK": "db1d6524990aecce49c3c5c79ee41361b01b49302eac1cc5f9decd0d1058d14e"
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
/* Terminal command for provisioning
|
||||
// setRDiden-8f9633dd856d2a156f2aee573deb11e543815ef53299c92e95b052138133ed39
|
||||
// setRDprvk-cb64a58a5fae052d458b3bce2599a20a665987b537b157cc3cc42e1d9c652409
|
||||
// setRDpubk-045bc20b2853e11fcb086192d8a5d5b7829b13d143b0da2de68e1bc94f8b016027a8854eae0226d4205e8f710d168da2f57d3fa2150b64338d212ce015e200513f
|
||||
// setDEVpbk-04773f9aa84ac9705161c490a2dba0b4a19a3d2a78705a801cff924e26357e4213191db83789a25916e4accea1fd6f09239b4cf2dd0d05b33b72d8a3a642e30866
|
||||
// setRDgrrk-0375ed63685570f6b2168eab7296ec01
|
||||
// setRisspk-04fbc3fdac291606a0a986862004bbe5c6188ce64098f4a65b7a6595fc31f416259141a972b916e6321dbeee22b77eec5929d80779c99f8ebe5c2588f24b24de68
|
||||
*/
|
||||
@@ -0,0 +1,708 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : app_aliro.h
|
||||
* @brief : Header for app_aliro.c file.
|
||||
* This file contains the public declarations for the Aliro demo.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _APP_ALIRO_H_
|
||||
#define _APP_ALIRO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup NFCBLE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include "st_errno.h"
|
||||
#include "ACWG_Security.h"
|
||||
#include "provisioning.h"
|
||||
#if defined(STM32U545xx) || defined(STM32U585xx)
|
||||
#include "stm32u5xx_hal.h"
|
||||
#include "stm32u5xx_nucleo.h"
|
||||
#include "log_module_u5.h"
|
||||
void Log_Module_Print(Log_Verbose_Level_t VerboseLevel, Log_Region_t Region, const char * Text, ...);
|
||||
#endif //defined(STM32U545xx) || defined(STM32U585xx)
|
||||
#if defined(STM32U385xx)
|
||||
#include "stm32u3xx_hal.h"
|
||||
#include "stm32u3xx_nucleo.h"
|
||||
#include "log_module_u3.h"
|
||||
void Log_Module_Print(Log_Verbose_Level_t VerboseLevel, Log_Region_t Region, const char * Text, ...);
|
||||
#endif //defined(STM32U385xx)
|
||||
#if defined(STM32WBA52xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx)
|
||||
#include "stm32wbaxx_hal.h"
|
||||
#include "stm32wbaxx_nucleo.h"
|
||||
#include "log_module.h"
|
||||
#endif //defined(STM32WBA52xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx)
|
||||
|
||||
/** @addtogroup Aliro_app_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @enum verblevel_t
|
||||
* @brief Verbosity levels for logging.
|
||||
*/
|
||||
typedef enum _verblevel
|
||||
{
|
||||
VERB_NULL=0, /**< No output */
|
||||
VERB_ALWAYS=1, /**< Always output */
|
||||
VERB_CRITICAL=2, /**< Critical output */
|
||||
VERB_ERROR=3, /**< Error output */
|
||||
VERB_NORMAL=4, /**< Normal output */
|
||||
VERB_VERBOSE=5, /**< Verbose output */
|
||||
VERB_INFO=6 /**< Informational output */
|
||||
}verblevel_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum timeStampsPos_t
|
||||
* @brief Timestamp positions for performance measurement.
|
||||
*/
|
||||
typedef enum _timeStampsPos
|
||||
{
|
||||
SELECT_APP_POS, /**< Application selection */
|
||||
END_SELECT_APP_POS, /**< End of application selection */
|
||||
AUTH0_POS, /**< Start authentication 0 */
|
||||
END_AUTH0_POS, /**< End authentication 0 */
|
||||
LOADCERT_POS, /**< Certificate loading */
|
||||
END_LOADCERT_POS, /**< End certificate loading */
|
||||
AUTH1_POS, /**< Start authentication 1 */
|
||||
END_AUTH1_POS, /**< End authentication 1 */
|
||||
CONTROL_FLOW_POS, /**< Control flow */
|
||||
END_CONTROL_FLOW_POS, /**< End control flow */
|
||||
EXCHANGE_POS, /**< Data exchange */
|
||||
END_EXCHANGE_POS, /**< End data exchange */
|
||||
STEPUP_POS, /**< Step-up */
|
||||
END_STEPUP_POS, /**< End step-up */
|
||||
DOOR_IS_OPENED_POS, /**< Door opened */
|
||||
DOOR_IS_CLOSED_POS, /**< Door closed */
|
||||
DOOR_IS_DISARMED_POS, /**< Door disarmed */
|
||||
DON_T_KNOW_POS, /**< Unknown state */
|
||||
|
||||
DERIVE_PERSISTENT_KEYS_POS, /**< Derivation of persistent keys */
|
||||
END_DERIVE_PERSISTENT_KEYS_POS,/**< End derivation of persistent keys */
|
||||
|
||||
ELAPSED_TIME_POS, /**< Elapsed time */
|
||||
|
||||
NUM_TIMESTAMPS /**< Total number of timestamps (do not change) */
|
||||
}timeStampsPos_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct statItem_t
|
||||
* @brief Structure for managing timestamps and statistics.
|
||||
*/
|
||||
typedef struct _statItem
|
||||
{
|
||||
timeStampsPos_t pos; /**< Timestamp position */
|
||||
char title[10]; /**< Title */
|
||||
uint8_t toPrint; /**< Print flag */
|
||||
uint32_t ts; /**< Timestamp value */
|
||||
}statItem_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct alirosvc_param_t
|
||||
* @brief Aliro service parameters.
|
||||
*/
|
||||
typedef struct _alirosvc_param
|
||||
{
|
||||
uint8_t proposedSPSM[2]; /**< Proposed SPSM */
|
||||
uint8_t protVerSupportedLen; /**< Supported protocol version length */
|
||||
uint8_t supportedProtocolVersion[4]; /**< Supported protocol versions */
|
||||
uint8_t selectedProtocolVersion[2]; /**< Selected protocol version */
|
||||
uint8_t featuresSupportedLen; /**< Supported features length */
|
||||
uint8_t featuresSupported[1]; /**< Supported features */
|
||||
}
|
||||
alirosvc_param_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Aliro_app_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported variables ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Aliro protocol versions supported.
|
||||
*/
|
||||
extern uint32_t xProtocolVersionSupported;
|
||||
|
||||
/**
|
||||
* @brief Current verbosity level.
|
||||
*/
|
||||
extern verblevel_t nVerbosityLevel;
|
||||
|
||||
/**
|
||||
* @brief NFC session context.
|
||||
*/
|
||||
extern ACWG_SessionContext_t context_nfc;
|
||||
|
||||
/**
|
||||
* @brief NFC session context.
|
||||
*/
|
||||
extern ACWG_SessionContext_t context_ble;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Aliro_app_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define VERBOSITY_SET nVerbosityLevel /**< Macro to get the current verbosity level */
|
||||
#define ALIRO_MEASURE_PERFORMANCE 0 /**< Enable performance measurement */
|
||||
#define ALIRO_CERTIFICATION_TEST 1 /**< Enable certification test */
|
||||
|
||||
//0x40 --> Bit 6: Bluetooth LE-Only Aliro flow supported.
|
||||
//0x80 --> Bit 7: Bluetooth LE + UWB Aliro flow supported.
|
||||
#define BLE_RKE_ALIRO_FLOW_SUPPORTED 0x40 /**< Bit 6: BLE-only Aliro flow supported */
|
||||
#define BLE_UWB_ALIRO_FLOW_SUPPORTED 0x80 /**< Bit 7: BLE + UWB Aliro flow supported */
|
||||
|
||||
#define BLE_ALIRO_FLOWS_SUPPORTED (BLE_UWB_ALIRO_FLOW_SUPPORTED | BLE_RKE_ALIRO_FLOW_SUPPORTED) /**< Macro for supported Aliro flows */
|
||||
|
||||
#define ALIRO_RTC_SET_STATUS_IAR 0x00F4 /**< RTC IAR status */
|
||||
#define ALIRO_RTC_SET_STATUS_GOOD 0x34F4 /**< RTC good status */
|
||||
|
||||
#define TIMEOUT_PREPARE_RANGING_DEFAULT 20000 /** Default timeout (ms) for prepare ranging operation. */
|
||||
#define TIMEOUT_EXECUTE_RANGING_DEFAULT 70000 /** Default timeout (ms) for execute ranging operation. */
|
||||
#define TIMEOUT_SUSPEND_RANGING_DEFAULT 10000 /** Default timeout (ms) for suspend ranging operation. */
|
||||
#define TIMEOUT_RESUME_RANGING_DEFAULT 20000 /** Default timeout (ms) for resume ranging operation. */
|
||||
#define TIMEOUT_DOOR_OPERATION_DEFAULT 20000 /** Default timeout (ms) for door operation. */
|
||||
|
||||
#if defined (ST25R200)
|
||||
#define X_NUCLEO_NFC_NAME "X-NUCLEO-NFC09A1/NFC10A1"
|
||||
#endif //defined (ST25R200)
|
||||
|
||||
#if defined (ST25R500)
|
||||
#define X_NUCLEO_NFC_NAME "X-NUCLEO-NFC12A1"
|
||||
#endif //defined (ST25R200)
|
||||
|
||||
#if USE_GEN2
|
||||
|
||||
#define ALIRO_BLE 1
|
||||
|
||||
#define H_ALIRO_UART huart1
|
||||
#define HH_ALIRO_UART &H_ALIRO_UART
|
||||
#define H_TIM htim2
|
||||
|
||||
extern RTC_HandleTypeDef hrtc;
|
||||
|
||||
#define ALIRO_HRTC hrtc
|
||||
#define ALIRO_RTC_BKP_TIME RTC_BKP_DR10
|
||||
|
||||
#define LD3_Pin GPIO_PIN_0
|
||||
#define LD3_GPIO_Port GPIOE
|
||||
#define LD2_Pin GPIO_PIN_1
|
||||
#define LD2_GPIO_Port GPIOE
|
||||
|
||||
//sector 125
|
||||
#define PROVISIONING_SECTOR 253
|
||||
#define PROVISIONING_START_ADDRESS (0x08000000+PROVISIONING_SECTOR*0x2000) //0x081fa000
|
||||
|
||||
//sector 124
|
||||
#define PROVISIONING_JSON_SECTOR 252
|
||||
#define PROVISIONING_JSON_START_ADDRESS (0x08000000+PROVISIONING_JSON_SECTOR*0x2000) //0x081f8000
|
||||
#else //USE_GEN2
|
||||
|
||||
#if defined(STM32WBA52xx)||defined(STM32WBA55xx)
|
||||
|
||||
#define ALIRO_BLE 1
|
||||
|
||||
#define H_ALIRO_UART huart1
|
||||
#define HH_ALIRO_UART &H_ALIRO_UART
|
||||
#define H_TIM htim2
|
||||
extern RTC_HandleTypeDef hrtc;
|
||||
|
||||
#define ALIRO_HRTC hrtc
|
||||
#define ALIRO_RTC_BKP_TIME RTC_BKP_DR10
|
||||
|
||||
#define LD3_Pin GPIO_PIN_8
|
||||
#define LD3_GPIO_Port GPIOB
|
||||
#define LD2_Pin GPIO_PIN_9
|
||||
#define LD2_GPIO_Port GPIOA
|
||||
|
||||
//sector 125
|
||||
#define PROVISIONING_SECTOR 123
|
||||
#define PROVISIONING_START_ADDRESS (0x08000000+PROVISIONING_SECTOR*0x2000) //0x080fa000
|
||||
|
||||
//sector 124
|
||||
#define PROVISIONING_JSON_SECTOR 122
|
||||
#define PROVISIONING_JSON_START_ADDRESS (0x08000000+PROVISIONING_JSON_SECTOR*0x2000) //0x080f8000
|
||||
#endif //defined(STM32WBA52xx)||defined(STM32WBA55xx)
|
||||
|
||||
|
||||
#ifdef STM32WBA65xx
|
||||
|
||||
#define ALIRO_BLE 1
|
||||
|
||||
#define H_ALIRO_UART huart1
|
||||
#define HH_ALIRO_UART &H_ALIRO_UART
|
||||
#define H_TIM htim2
|
||||
extern RTC_HandleTypeDef hrtc;
|
||||
|
||||
#define ALIRO_HRTC hrtc
|
||||
#define ALIRO_RTC_BKP_TIME RTC_BKP_DR10
|
||||
|
||||
#define LD3_Pin GPIO_PIN_0
|
||||
#define LD3_GPIO_Port GPIOE
|
||||
#define LD2_Pin GPIO_PIN_1
|
||||
#define LD2_GPIO_Port GPIOE
|
||||
|
||||
//sector 125
|
||||
#define PROVISIONING_SECTOR 253
|
||||
#define PROVISIONING_START_ADDRESS (0x08000000+PROVISIONING_SECTOR*0x2000) //0x081fa000
|
||||
|
||||
//sector 124
|
||||
#define PROVISIONING_JSON_SECTOR 252
|
||||
#define PROVISIONING_JSON_START_ADDRESS (0x08000000+PROVISIONING_JSON_SECTOR*0x2000) //0x081f8000
|
||||
#endif //STM32WBA65xx
|
||||
|
||||
|
||||
|
||||
#if defined(STM32U545xx) || defined(STM32U585xx) || defined(STM32U385xx)
|
||||
extern EXTI_HandleTypeDef H_EXTI_13;
|
||||
extern UART_HandleTypeDef huart1;
|
||||
#define HH_ALIRO_UART &huart1
|
||||
#define H_ALIRO_UART huart1
|
||||
#define H_TIM htim2
|
||||
|
||||
#define LD3_Pin GPIO_PIN_8
|
||||
#define LD3_GPIO_Port GPIOB
|
||||
#define LD2_Pin GPIO_PIN_4
|
||||
#define LD2_GPIO_Port GPIOC
|
||||
|
||||
//sector 125
|
||||
#define PROVISIONING_SECTOR 63
|
||||
#define PROVISIONING_START_ADDRESS (0x08000000+PROVISIONING_SECTOR*0x2000) //0x081fa000
|
||||
|
||||
//sector 124
|
||||
#define PROVISIONING_JSON_SECTOR 62
|
||||
#define PROVISIONING_JSON_START_ADDRESS (0x08000000+PROVISIONING_JSON_SECTOR*0x2000) //0x081f8000
|
||||
#endif //defined(STM32U545xx) || defined(STM32U585xx) || defined(STM32U385xx)
|
||||
|
||||
#endif //USE_GEN2
|
||||
|
||||
#if defined ALIRO_HRTC
|
||||
#define USE_RTC 1
|
||||
#endif //defined ALIRO_HRTC
|
||||
|
||||
#define CLEAR_SCREEN_COMMAND "\033[2J\r\n"
|
||||
#define TEXT_COLOR_1 "\033[0;32m" //green
|
||||
#define TEXT_COLOR_GREEN "\033[0;32m" //green
|
||||
#define TEXT_COLOR_2 "\033[0;33m"
|
||||
#define TEXT_COLOR_YELLOW "\033[0;33m"
|
||||
#define TEXT_COLOR_3 "\033[0;31m"
|
||||
#define TEXT_COLOR_RED "\033[0;31m"
|
||||
#define TEXT_COLOR_4 "\033[0;36m"
|
||||
#define TEXT_COLOR_CYAN "\033[0;36m"
|
||||
#define TEXT_COLOR_BLU "\033[0;34m"
|
||||
#define TEXT_COLOR_VIOLET "\033[0;35m"
|
||||
#define TEXT_COLOR_GRAY "\033[0;37m"
|
||||
#define TEXT_COLOR_NOIR "\033[0;30m"
|
||||
#define TEXT_COLOR_DEFAULT "\033[0;39m"
|
||||
|
||||
//Background
|
||||
#define TEXT_BACKGROUND_COLOR_BLACK "\033[40m"
|
||||
#define TEXT_BACKGROUND_COLOR_RED "\033[41m"
|
||||
#define TEXT_BACKGROUND_COLOR_GREEN "\033[42m"
|
||||
#define TEXT_BACKGROUND_COLOR_YELLOW "\033[43m"
|
||||
#define TEXT_BACKGROUND_COLOR_BLUE "\033[44m"
|
||||
#define TEXT_BACKGROUND_COLOR_PURPLE "\033[45m"
|
||||
#define TEXT_BACKGROUND_COLOR_CYAN "\033[46m"
|
||||
#define TEXT_BACKGROUND_COLOR_WHITE "\033[47m"
|
||||
|
||||
#define TEXT_TEST_COLOR "\033[7;34m"
|
||||
|
||||
#define TEXT_RESET "\033[0m"
|
||||
#define TEXT_BOLD "\033[1m" //used to make ligth color
|
||||
#define TEXT_UNDERSCORE "\033[4m"
|
||||
#define TEXT_BLINK "\033[5m"
|
||||
#define TEXT_REVERSE "\033[7m"
|
||||
#define TEXT_CONCEALED "\033[8m"
|
||||
|
||||
#define TEXT_COLOR_ESCAPE_CHAR '\033'
|
||||
|
||||
#define VERB_STATISTICS VERB_INFO
|
||||
#define VERB_STATISTICS_REPORT VERB_CRITICAL
|
||||
#define VERB_STATE_TITLE VERB_NORMAL
|
||||
#define VERB_FN_NAME VERB_VERBOSE
|
||||
#define VERB_TERMINAL VERB_NORMAL
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Aliro_app_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#if ALIRO_MEASURE_PERFORMANCE
|
||||
#define RESET_TIME_STAMP() do{ ResetTimeStamp();ResetAllSavedTimeStamps(); }while(0)
|
||||
#define PRINT_TIME_STAMP(pos) do{ SaveTimeStamp(pos);/*PrintTimeStamp(label);*/ }while(0)
|
||||
#define TIME_STAMP_REPORT() do{ PrintTimeStampReport(); }while(0)
|
||||
#else //ALIRO_MEASURE_PERFORMANCE
|
||||
#define RESET_TIME_STAMP()
|
||||
#define PRINT_TIME_STAMP(pos)
|
||||
#define TIME_STAMP_REPORT()
|
||||
#endif //ALIRO_MEASURE_PERFORMANCE
|
||||
|
||||
#define countof(_A_) (sizeof(_A_) / sizeof(*(_A_))) /**< Macro to count array elements */
|
||||
|
||||
#define PLATFORM_LOG(VERBOSITY, ...) do{if((uint8_t)VERBOSITY <= (uint8_t)nVerbosityLevel)LOG_INFO_APP(__VA_ARGS__);}while(0)
|
||||
#define DELAY_CONDITIONAL(D) do{if( nVerbosityLevel > VERB_VERBOSE)HAL_Delay(D);}while(0)
|
||||
|
||||
#define HIGH_BYTE(A) ((A&0xFF00)>>8)
|
||||
#define LOW_BYTE(A) (A&0x00FF)
|
||||
|
||||
#define HEX(C) (((C>='0') && (C<='9'))?(C-'0'):((C>='A') && (C<='F'))?(C-'A'+0xA):(0))
|
||||
|
||||
#define GET_IAR_YEAR_DEC(D) ((HEX(D[7])*1000 + HEX(D[8])*100 + HEX(D[9])*10 + HEX(D[10])*1) - 2000)
|
||||
#define GET_IAR_YEAR(D) (GET_IAR_YEAR_DEC(D)%10 + (GET_IAR_YEAR_DEC(D)/10)*16 - 0x30)
|
||||
#define GET_IAR_DATE(D) (HEX(D[4])*16 + HEX(D[5])*1)
|
||||
#define GET_IAR_HOURS(T) (HEX(T[0])*16 + HEX(T[1])*1)
|
||||
#define GET_IAR_MINUTES(T) (HEX(T[3])*16 + HEX(T[4])*1)
|
||||
#define GET_IAR_SECONDS(T) (HEX(T[6])*16 + HEX(T[7])*1)
|
||||
#define GET_IAR_MONTH(D) (\
|
||||
(D[0]==JAN[0] && D[1] == JAN[1] && D[2] == JAN[2])?0x1:\
|
||||
(D[0]==FEB[0] && D[1] == FEB[1] && D[2] == FEB[2])?0x2:\
|
||||
(D[0]==MAR[0] && D[1] == MAR[1] && D[2] == MAR[2])?0x3:\
|
||||
(D[0]==APR[0] && D[1] == APR[1] && D[2] == APR[2])?0x4:\
|
||||
(D[0]==MAY[0] && D[1] == MAY[1] && D[2] == MAY[2])?0x5:\
|
||||
(D[0]==JUN[0] && D[1] == JUN[1] && D[2] == JUN[2])?0x6:\
|
||||
(D[0]==JUL[0] && D[1] == JUL[1] && D[2] == JUL[2])?0x7:\
|
||||
(D[0]==AUG[0] && D[1] == AUG[1] && D[2] == AUG[2])?0x8:\
|
||||
(D[0]==SEP[0] && D[1] == SEP[1] && D[2] == SEP[2])?0x9:\
|
||||
(D[0]==OCT[0] && D[1] == OCT[1] && D[2] == OCT[2])?0x10:\
|
||||
(D[0]==NOV[0] && D[1] == NOV[1] && D[2] == NOV[2])?0x11:\
|
||||
(D[0]==DEC[0] && D[1] == DEC[1] && D[2] == DEC[2])?0x12:\
|
||||
1)
|
||||
|
||||
#define TRANSACTION_SUCCESS_OPEN() AliroPort_TRANSACTION_SUCCESS_OPEN()
|
||||
#define TRANSACTION_SUCCESS_CLOSE() AliroPort_TRANSACTION_SUCCESS_CLOSE()
|
||||
#define TRANSACTION_FAILURE() AliroPort_TRANSACTION_FAILURE()
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Aliro_app_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Returns the current timestamp.
|
||||
* @return Timestamp value.
|
||||
*/
|
||||
uint32_t GetTimeStamp(void);
|
||||
|
||||
/**
|
||||
* @brief Prints the timestamp associated with a string.
|
||||
* @param pstr Descriptive string.
|
||||
* @return Printed timestamp value.
|
||||
*/
|
||||
uint32_t PrintTimeStamp(char *pstr);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets the current date and time.
|
||||
* @param timeDate Pointer to struct tm to store the date and time.
|
||||
*/
|
||||
void GetTimeDate(struct tm *timeDate);
|
||||
|
||||
/**
|
||||
* @brief Shows current date and time.
|
||||
*/
|
||||
void ShowTimeDate(void);
|
||||
|
||||
#if defined(STM32WBA52xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx)
|
||||
/**
|
||||
* @brief Sets the RTC configuration status.
|
||||
* @param nStatus Status to set.
|
||||
*/
|
||||
void SetRtcSettingStatus(uint32_t nStatus);
|
||||
#endif //defined(STM32WBA52xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Resets all saved timestamps.
|
||||
*/
|
||||
void ResetAllSavedTimeStamps(void);
|
||||
|
||||
/**
|
||||
* @brief Searches for the position of a timestamp.
|
||||
* @param pos Position to search.
|
||||
* @return Pointer to the found statItem_t structure.
|
||||
*/
|
||||
statItem_t *SearchPos(timeStampsPos_t pos);
|
||||
|
||||
/**
|
||||
* @brief Saves the timestamp in a specific position.
|
||||
* @param pos Timestamp position.
|
||||
*/
|
||||
void SaveTimeStamp(timeStampsPos_t pos);
|
||||
|
||||
/**
|
||||
* @brief Prints the timestamp report.
|
||||
*/
|
||||
void PrintTimeStampReport(void);
|
||||
|
||||
/**
|
||||
* @brief Resets the current timestamp.
|
||||
*/
|
||||
void ResetTimeStamp(void);
|
||||
|
||||
/**
|
||||
* @brief Prints a buffer in hexadecimal format.
|
||||
* @param pstr Descriptive string.
|
||||
* @param pBuf Buffer to print.
|
||||
* @param nSize Buffer size.
|
||||
*/
|
||||
void PrintBufferHex(const char *pstr, const uint8_t *pBuf, const uint32_t nSize);
|
||||
|
||||
/**
|
||||
* @brief Always prints a buffer in hexadecimal format.
|
||||
* @param pstr Descriptive string.
|
||||
* @param pBuf Buffer to print.
|
||||
* @param nSize Buffer size.
|
||||
*/
|
||||
void PrintBufferHexAlways(const char *pstr, const uint8_t *pBuf, const uint32_t nSize);
|
||||
|
||||
/**
|
||||
* @brief Prints an error string.
|
||||
* @param errstr Error string.
|
||||
* @param retval Return code.
|
||||
*/
|
||||
void PrintErrorString(char*errstr, ACWG_Status_t retval);
|
||||
|
||||
/**
|
||||
* @brief Receives a character from USART.
|
||||
* @param buf Buffer to store the character.
|
||||
* @return Number of received characters.
|
||||
*/
|
||||
uint16_t UsartGetChar(uint8_t *buf);
|
||||
|
||||
/**
|
||||
* @brief Receives a character from USART in blocking mode.
|
||||
* @param buf Buffer to store the character.
|
||||
* @return Number of received characters.
|
||||
*/
|
||||
uint16_t UsartGetCharBlocking(uint8_t *buf);
|
||||
|
||||
/**
|
||||
* @brief Initializes the Aliro module.
|
||||
* @return true if initialization is successful, false otherwise.
|
||||
*/
|
||||
bool aliro_init();
|
||||
|
||||
/**
|
||||
* @brief Executes the main Aliro process.
|
||||
*/
|
||||
void aliro_process();
|
||||
|
||||
/**
|
||||
* @brief Hook for successful transaction - Door open
|
||||
*/
|
||||
__weak void AliroPort_TRANSACTION_SUCCESS_OPEN(void);
|
||||
|
||||
/**
|
||||
* @brief Hook for successful transaction - Door close
|
||||
*/
|
||||
__weak void AliroPort_TRANSACTION_SUCCESS_CLOSE(void);
|
||||
|
||||
/**
|
||||
* @brief Hook for transaction failure
|
||||
*/
|
||||
__weak void AliroPort_TRANSACTION_FAILURE(void);
|
||||
|
||||
/**
|
||||
* @brief Delay porting for Aliro.
|
||||
* @param Delay Delay time in ms.
|
||||
*/
|
||||
void AliroPort_Delay(uint32_t Delay);
|
||||
|
||||
/**
|
||||
* @brief Writes the state of a GPIO pin.
|
||||
* @param GPIOx Pointer to GPIO.
|
||||
* @param GPIO_Pin Pin to write.
|
||||
* @param PinState State to set.
|
||||
*/
|
||||
void AliroPort_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
|
||||
|
||||
/**
|
||||
* @brief Transmits data via UART.
|
||||
* @param huart UART handle.
|
||||
* @param pData Data to transmit.
|
||||
* @param Size Data size.
|
||||
* @param Timeout Operation timeout.
|
||||
* @return HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef AliroPort_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout);
|
||||
|
||||
/**
|
||||
* @brief Receives data via UART.
|
||||
* @param huart UART handle.
|
||||
* @param pData Data buffer.
|
||||
* @param Size Pointer to data size.
|
||||
* @param Timeout Operation timeout.
|
||||
* @return HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef AliroPort_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t *Size, uint32_t Timeout);
|
||||
|
||||
/**
|
||||
* @brief Interrupt Service Routine for button 1.
|
||||
*/
|
||||
void Button1_isr( void );
|
||||
|
||||
/**
|
||||
* @brief Board reset.
|
||||
*/
|
||||
void board_reset();
|
||||
|
||||
/**
|
||||
* @brief Checks if the selected SPSM is valid.
|
||||
* @param selected Selected SPSM.
|
||||
* @return 1 if valid, 0 otherwise.
|
||||
*/
|
||||
uint8_t isValidSPSM(uint16_t selected);
|
||||
|
||||
/**
|
||||
* @brief Gets dynamic SPSM.
|
||||
* @param old_spsm Previous SPSM.
|
||||
* @return Dynamic SPSM.
|
||||
*/
|
||||
uint16_t get_dynamic_spsm(uint8_t old_spsm);
|
||||
|
||||
/**
|
||||
* @brief Fills the advertising buffer.
|
||||
* @param advbuf Advertising buffer.
|
||||
* @param psize Pointer to size.
|
||||
*/
|
||||
void fillAdvBuffer(uint8_t *advbuf, uint8_t *psize);
|
||||
|
||||
/**
|
||||
* @brief Gets the initial length of Aliro service parameters.
|
||||
* @param pLen Pointer to length.
|
||||
* @return Length.
|
||||
*/
|
||||
uint8_t AliroSvcParamGetInitLen(uint8_t *pLen);
|
||||
|
||||
/**
|
||||
* @brief Gets the initial buffer of Aliro service parameters.
|
||||
* @param DataBuf Pointer to data buffer.
|
||||
* @return Buffer length.
|
||||
*/
|
||||
uint8_t AliroSvcParamGetInitBuf(uint8_t **DataBuf);
|
||||
|
||||
/**
|
||||
* @brief Verifies the Aliro protocol version.
|
||||
* @param selectedProtocolVersion_16 Selected version.
|
||||
* @return 1 if valid, 0 otherwise.
|
||||
*/
|
||||
uint8_t AliroSvcVerifyProtVer(uint16_t selectedProtocolVersion_16);
|
||||
|
||||
/**
|
||||
* @brief Gets the saved selected protocol version.
|
||||
* @return Selected version.
|
||||
*/
|
||||
uint16_t AliroGetSavedSelectedProtocolVersion();
|
||||
|
||||
/**
|
||||
* @brief BLE Aliro initialization complete callback.
|
||||
*/
|
||||
void AliroBLE_Init_complete_cb();
|
||||
|
||||
/**
|
||||
* @brief BLE Aliro disconnection complete callback.
|
||||
*/
|
||||
void AliroBleDisconnection_complete_cb();
|
||||
|
||||
/**
|
||||
* @brief BLE CoC Aliro disconnection complete callback.
|
||||
*/
|
||||
void AliroBleCocDisconnection_complete_cb();
|
||||
|
||||
/**
|
||||
* @brief Fills techs2find for Aliro.
|
||||
* @param techs2find Pointer to techs2find.
|
||||
*/
|
||||
void AliroFilltechs2Find(uint16_t *techs2find);
|
||||
|
||||
/**
|
||||
* @brief Set the timeout for the prepare ranging operation.
|
||||
*
|
||||
* @param timeout_ms Timeout value in milliseconds.
|
||||
*/
|
||||
void Set_timeout_prepare_ranging(uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Set the timeout for the execute ranging operation.
|
||||
*
|
||||
* @param timeout_ms Timeout value in milliseconds.
|
||||
*/
|
||||
void Set_timeout_execute_ranging(uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Set the timeout for the suspend ranging operation.
|
||||
*
|
||||
* @param timeout_ms Timeout value in milliseconds.
|
||||
*/
|
||||
void Set_timeout_suspend_ranging(uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Set the timeout for the resume ranging operation.
|
||||
*
|
||||
* @param timeout_ms Timeout value in milliseconds.
|
||||
*/
|
||||
void Set_timeout_resume_ranging(uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Set the timeout for the door operation.
|
||||
*
|
||||
* @param timeout_ms Timeout value in milliseconds.
|
||||
*/
|
||||
void Set_timeout_door_operation(uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _APP_ALIRO_H_ */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : app_build_info.h
|
||||
* @brief : Header for app_build_info.c file.
|
||||
* This file contains the firmware build information structure.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _APP_BUILD_INFO_H_
|
||||
#define _APP_BUILD_INFO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup NFCBLE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
/** @addtogroup App_build_info_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Current version of @ref app_build_info
|
||||
*/
|
||||
#define ABI_VERSION 1
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup App_build_info_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Various info about the firmware build
|
||||
*
|
||||
* The build info are put at a specific address in flash (e.g. 0x0200), so that we can easily recover it with an
|
||||
* external application which would read the flash.
|
||||
*/
|
||||
typedef struct app_build_info_s {
|
||||
uint8_t magic_cookie[4]; //!< A magic cookie that external application could easily read: 'B', 'F', 'W', 'I'
|
||||
uint8_t build_info_version; //!< Version of this structure, e.g. @ref MBI_VERSION
|
||||
uint8_t app_major; //!< Major version number of the firmware
|
||||
uint8_t app_minor; //!< Minor version number of the firmware
|
||||
uint8_t app_subminor; //!< Subminor version number of the firmware
|
||||
// char revision[32]; //!< git version at the build time, based on hash
|
||||
char date[12]; //!< Build date, e.g. "Jan 1 1970"
|
||||
char time[12]; //!< Build time, e.g. "01:00:00"
|
||||
|
||||
uint8_t aliro_spec_major; //!< Major version number of the Aliro spec.
|
||||
uint8_t aliro_spec_minor; //!< Minor version number of the Aliro spec.
|
||||
uint8_t aliro_spec_subminor; //!< Subminor version number of the Aliro spec.
|
||||
uint8_t acwg_ver_major;
|
||||
uint8_t acwg_ver_minor;
|
||||
uint8_t acwg_ver_subminor;
|
||||
#define MBI_FW_DESCRIPTION_LEN 24
|
||||
char fw_description[MBI_FW_DESCRIPTION_LEN]; //!< Name of the firmware
|
||||
}app_build_info_t;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup App_build_info_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
// The symbol 'build_info' is defined by the linker script. See file arm-gcc-link.ld
|
||||
// Alternatively, we could use:
|
||||
// #define build_info (*(struct buildinfo*)(0x08000200))
|
||||
|
||||
/* Exported variables ------------------------------------------------------------*/
|
||||
extern const app_build_info_t app_build_info;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _APP_BUILD_INFO_H_ */
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : app_nfc.h
|
||||
* @brief : Header for app_nfc.c file.
|
||||
* This file contains the public NFC API and common NFC definitions for the Aliro application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _APP_NFC_H_
|
||||
#define _APP_NFC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup NFC
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "st_errno.h"
|
||||
#include "ACWG_Security.h"
|
||||
|
||||
|
||||
/** @addtogroup Aliro_NFC_ExportedTypes
|
||||
* @brief Exported types for Aliro NFC module
|
||||
* @{
|
||||
*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup Aliro_NFC_ExportedConstants
|
||||
* @brief Exported constants for Aliro NFC module
|
||||
* @{
|
||||
*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup Aliro_NFC_ExportedMacros
|
||||
* @brief Exported macros for Aliro NFC module
|
||||
* @{
|
||||
*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup Aliro_NFC_ExportedFunctions
|
||||
* @brief Exported functions for Aliro NFC module
|
||||
* @{
|
||||
*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Initializes the NFC module for Aliro.
|
||||
* @param context Pointer to the session context.
|
||||
* @return true if initialization is successful, false otherwise.
|
||||
*/
|
||||
bool AliroNfcIni( ACWG_SessionContext_t *context );
|
||||
|
||||
/**
|
||||
* @brief Executes the main NFC cycle for Aliro.
|
||||
* @param context Pointer to the session context.
|
||||
*/
|
||||
void AliroNfcCycle( ACWG_SessionContext_t *context );
|
||||
|
||||
/**
|
||||
* @brief Stops the NFC module for Aliro.
|
||||
*/
|
||||
void AliroNfcStop( void );
|
||||
|
||||
/**
|
||||
* @brief Gets the technologies to find during NFC discovery.
|
||||
* @return Bitmask of technologies to find.
|
||||
*/
|
||||
uint16_t AliroNfcGetDiscoverTechs2Find( void );
|
||||
|
||||
/**
|
||||
* @brief Gets the total duration for NFC discovery.
|
||||
* @return Duration in milliseconds.
|
||||
*/
|
||||
uint16_t AliroNfcGetDiscoverTotalDuration( void );
|
||||
|
||||
/**
|
||||
* @brief Initializes the NFC hardware for Aliro.
|
||||
*/
|
||||
void AliroNfcHwInit( void );
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _APP_NFC_H_ */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : app_version.h
|
||||
* @brief : Header for app_version.c file.
|
||||
* This file defines application and specification version macros used by the Aliro firmware.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _APP_VERSION_H_
|
||||
#define _APP_VERSION_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup NFCBLE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "provisioning_info.h"
|
||||
|
||||
/** @addtogroup App_Version_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define APP_VERSION_MAJ 0
|
||||
#define APP_VERSION_MIN 9
|
||||
#define APP_VERSION_SUBMIN 3
|
||||
// #define APP_VERSION "0.1.0"
|
||||
// #define SW_VERSION "FW VERSION TBD"
|
||||
|
||||
#define ALIRO_SPEC_VERSION_MAJ 0
|
||||
#define ALIRO_SPEC_VERSION_MIN 9
|
||||
#define ALIRO_SPEC_VERSION_SUBMIN 5
|
||||
#define APP_ACWG_VERSION_MAJ 0
|
||||
#define APP_ACWG_VERSION_MIN 3
|
||||
#define APP_ACWG_VERSION_SUBMIN 4
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _APP_VERSION_H_ */
|
||||
@@ -0,0 +1,238 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* \file certificate.h
|
||||
* \author STMicroelectronics - CS application team
|
||||
* \brief x509 certificate Parser
|
||||
******************************************************************************
|
||||
* \attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2022 STMicroelectronics</center></h2>
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef CERTIFICATE_H
|
||||
#define CERTIFICATE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/** \defgroup certificate_core Certificate parser
|
||||
* \ingroup certificate
|
||||
* \brief Certificate parser
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \enum certificate_status_t
|
||||
* \brief response codes enumeration
|
||||
*/
|
||||
typedef enum {
|
||||
CERT_OK = 0x00, /*!< Successful processing */
|
||||
CERT_INVALID_PARAMETER = 0x01, /*!< Wrong function parameters */
|
||||
CERT_UNEXPECTED_SEQUENCE,
|
||||
CERT_UNEXPECTED_BITSTRING,
|
||||
CERT_INVALID_SIGNATURE,
|
||||
CERT_INVALID_CERTIFICATE,
|
||||
CERT_CA_NOT_MATCHING,
|
||||
CERT_UNSUPPORTED_FEATURE,
|
||||
CERT_BAD_SIZE,
|
||||
}certificate_status_t;
|
||||
|
||||
/** \brief Definitions of available signature algorithms */
|
||||
typedef enum {
|
||||
CERT_SIG_ECDSA_SHA1 = 0, /*!< ECDSA with SHA1 algorithm */
|
||||
CERT_SIG_ECDSA_SHA224, /*!< ECDSA with SHA224 algorithm */
|
||||
CERT_SIG_ECDSA_SHA256, /*!< ECDSA with SHA256 algorithm */
|
||||
CERT_SIG_ECDSA_SHA384, /*!< ECDSA with SHA384 algorithm */
|
||||
CERT_SIG_ECDSA_SHA512, /*!< ECDSA with SHA512 algorithm */
|
||||
}certificate_signature_algorithms_t;
|
||||
|
||||
/** \brief Definitions of supported Elliptic Curve Names */
|
||||
typedef enum {
|
||||
CERT_EC_P256 = 0, /*!< NIST P-256 */
|
||||
CERT_EC_P384, /*!< NIST P-384 */
|
||||
CERT_EC_P521, /*!< NIST P-521 */
|
||||
CERT_EC_bp256r1, /*!< brainpoolP256r1 */
|
||||
CERT_EC_bp256t1, /*!< brainpoolP256t1 */
|
||||
CERT_EC_bp384r1, /*!< brainpoolP384r1 */
|
||||
CERT_EC_bp384t1, /*!< brainpoolP384t1 */
|
||||
CERT_EC_bp512r1, /*!< brainpoolP512r1 */
|
||||
CERT_EC_bp512t1, /*!< brainpoolP512t1 */
|
||||
}certificate_elliptic_curves_t;
|
||||
|
||||
|
||||
/** \brief typedef for the structure keeping the validity */
|
||||
typedef struct validity_st {
|
||||
uint8_t seconds; /*!< seconds (range 0 to 59) */
|
||||
uint8_t minutes; /*!< minutes (range 0 to 59) */
|
||||
uint8_t hours; /*!< hours (range 0 to 23) */
|
||||
uint8_t days; /*!< days (range 1 to 31) */
|
||||
uint8_t month; /*!< month (range 1 to 12) */
|
||||
uint32_t year; /*!< years 0 to whatever */
|
||||
} cert_validity_t;
|
||||
|
||||
/** \brief typedef for the structure keeping the Ellipitc Curve Public Key */
|
||||
typedef struct cert_public_key_t
|
||||
{
|
||||
const uint8_t *pX; /*!< Pointer to X Coordinate */
|
||||
const uint8_t *pY; /*!< Pointer to Y Coordiante */
|
||||
uint32_t fsize; /*!< Size of the field in bytes */
|
||||
} cert_public_key_t;
|
||||
|
||||
/** \brief typedef for the structure keeping the ECDSA Signature */
|
||||
typedef struct ECDSAsign_st
|
||||
{
|
||||
const uint8_t *pR; /*!< Pointer to r */
|
||||
uint32_t rSize; /*!< size to r */
|
||||
const uint8_t *pS; /*!< Pointer to s*/
|
||||
uint32_t sSize; /*!< size to s */
|
||||
} cert_signature_t;
|
||||
|
||||
/** \brief internal structure used to keep the values parsed from the x509 */
|
||||
struct internal_certificate {
|
||||
const uint8_t *pPubKey_point_representation_id; /*!< 0x04: Uncompressed key, 0x02 or 0x03: Compressed key */
|
||||
const uint8_t *tbs; /*!< Pointer to tcs field */
|
||||
uint32_t tbsSize; /*!< Size of tcs */
|
||||
uint32_t x509Version; /*!< x509 Version */
|
||||
const uint8_t *serialNumber; /*!< Pointer to SerialNumber*/
|
||||
uint32_t serialNumberSize; /*!< Size of SerialNumber */
|
||||
uint32_t signature; /*!< Signature (algorithm) but from tcs */
|
||||
const uint8_t *issuer; /*!< Pointer to Issuer */
|
||||
uint32_t issuerSize; /*!< Size of Issuer */
|
||||
const uint8_t *validity; /*!< Pointer to Validity */
|
||||
uint32_t validitySize; /*!< Size of Validity */
|
||||
const uint8_t *subject; /*!< Pointer to subject */
|
||||
uint32_t subjectSize; /*!< Size of Subject */
|
||||
uint32_t EllipticCurve; /*!< Identifies the Elliptic Curve */
|
||||
cert_public_key_t PubKey; /*!< Contain the struct \ref cert_public_key_t */
|
||||
const uint8_t *extensions; /*!< Pointer to Extensions */
|
||||
uint32_t extensionsSize; /*!< Size of Extensions */
|
||||
uint32_t extensionsFlags; /*!< Integer encoding the fields present in the tcs: \n
|
||||
* bit 0: BasicConstraints is present \n
|
||||
* bit 1: BasicConstraints is critical \n
|
||||
* bit 2: BasicConstraints indicates this is a CA \n
|
||||
* bit 3: BasicConstraints has a pathLenConstraint \n
|
||||
* bit 4-7: PathLen \n
|
||||
* bit 8: keyUsage is present \n
|
||||
* bit 9: keyUsage is critical \n
|
||||
* bit 15: keyUsage field decipherOnly \n
|
||||
* bit 16: keyUsage field digitalSignature \n
|
||||
* bit 17: keyUsage field contentCommitment/nonRepudiation \n
|
||||
* bit 18: keyUsage field keyEncipherment \n
|
||||
* bit 19: keyUsage field dataEncipherment \n
|
||||
* bit 20: keyUsage field keyAgreement \n
|
||||
* bit 21: keyUsage field keyCertSign \n
|
||||
* bit 22: keyUsage field cRLSign \n
|
||||
* bit 23: keyUsage field encipherOnly \n
|
||||
* bit 24: ExtendedKeyUsage is present \n
|
||||
* bit 25: ExtendedKeyUsage is critical \n
|
||||
* bit 27-29: Unused
|
||||
*/
|
||||
const uint8_t *extAKIkeyIdentifier; /*!< field key identifier of extension authority key identifier */
|
||||
uint32_t extAKIkeyIdentifierSize; /*!< size of previous field */
|
||||
uint32_t SignatureAlgorithm; /*!< SignatureAlgorithm */
|
||||
cert_signature_t Sign; /*!< Contain the struct \ref cert_signature_t */
|
||||
};
|
||||
|
||||
/** \brief typedef for the certificate_t */
|
||||
typedef struct internal_certificate certificate_t;
|
||||
|
||||
|
||||
/* Exported Functions */
|
||||
|
||||
/**
|
||||
* \brief Initialize a certificate (\ref certificate_t) to an empty one
|
||||
* \param[in,out] cert pointer to the certificate_t to be initialized
|
||||
* \note This functions should be called before parsing a certificate
|
||||
* \details \include{doc} Authentication.dox
|
||||
*/
|
||||
void certificate_init(certificate_t *cert);
|
||||
|
||||
/**
|
||||
* \brief Parse an x509 certificate
|
||||
* \param[in] cert pointer to the x509 certificate to be parsed
|
||||
* \param[in] max_size maximum size of certificate to be parsed
|
||||
* \param[out] certificate pointer to the certificate_t that will be filled
|
||||
* \param[out] next pointer to cert array after the parsed certificate (it can be NULL)
|
||||
* \return \ref certificate_status_t : CERT_OK on success ; error code otherwise
|
||||
* \warning The parsed certificated could be empty, it is necessary to call a function
|
||||
* which verifies the certificate to be valid before using it.
|
||||
*/
|
||||
certificate_status_t certificate_parse(const uint8_t *cert, uint32_t max_size, certificate_t *certificate, const uint8_t **next);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Parse the top of x509 certificate to find the tbs and the signature
|
||||
* \param[in] cert pointer to the x509 certificate to be parsed
|
||||
* \param[in] max_size maximum size of certificate to be parsed
|
||||
* \param[out] certificate pointer to the certificate_t that will be filled
|
||||
* \param[out] next pointer to cert array after the parsed certificate (it can be NULL)
|
||||
* \return \ref certificate_status_t : CERT_OK on success ; error code otherwise
|
||||
* \warning The parsed certificated could be empty, it is necessary to call a function
|
||||
* which verifies the certificate to be valid before using it.
|
||||
*/
|
||||
certificate_status_t certificate_find_tbs_and_signature(const uint8_t *cert, uint32_t max_size, certificate_t *certificate, const uint8_t **next);
|
||||
|
||||
/**
|
||||
* \brief Parse the tbs part of a certificate
|
||||
* \param[in/out] *certificate pointer to the certificate_t
|
||||
*/
|
||||
void certificate_parse_tbs(certificate_t *certificate);
|
||||
|
||||
/**
|
||||
* \brief Check that an imported x509 certificate is valid
|
||||
* \param[in] certificate pointer to the parsed x509 certificate to be validated
|
||||
* \param[in] currentTime pointer to a cert_validity_t with the current DateTime. If NULL no date check is done
|
||||
* \return \ref certificate_status_t : CERT_OK on success ; error code otherwise
|
||||
* \warning If currentTime==NULL the check on the validity dates of the certificate will be bypassed.
|
||||
*/
|
||||
certificate_status_t certificate_is_valid(const certificate_t *certificate, const cert_validity_t *currentTime);
|
||||
|
||||
/**
|
||||
* \brief Check whether a certificate is marked as belonging to a CA
|
||||
* \param[in] *cert pointer to the parsed x509 certificate to be checked
|
||||
* \return \ref certificate_status_t : CERT_OK on success ; error code otherwise
|
||||
*/
|
||||
certificate_status_t certificate_is_CA(const certificate_t *cert);
|
||||
|
||||
/**
|
||||
* \brief Check whether "parent" issued "child"
|
||||
* \param[in] parent pointer to the parsed x509 certificate of the supposed issuer of child
|
||||
* \param[in] child pointer to the parsed x509 certificate of the certificated supposedly issued by parent
|
||||
* \param[in] currentTime pointer to a cert_validity_t with the current DateTime. If NULL no date check is done.
|
||||
* \return \ref certificate_status_t : CERT_OK on success ; error code otherwise
|
||||
* \note RFC 5280 mandates an extremely expensive comparison, which we don't perform.
|
||||
* As result of this simplification some legitimate parentship relation could be not acknowledged (the opposite should not occur).
|
||||
* \warning This check only a single level parent relashion (i.e. whether parent issued child)
|
||||
*/
|
||||
certificate_status_t certificate_is_parent(const certificate_t *parent, const certificate_t *child, const cert_validity_t *currentTime);
|
||||
|
||||
/**
|
||||
* \brief Copy a certificate (\ref certificate_t) into another structure
|
||||
* \param[out] copiedCert pointer to the certificate_t that will be written
|
||||
* \param[out] originalCert pointer to the certificate_t that will be copied
|
||||
* \return \ref certificate_status_t : CERT_OK on success ; error code otherwise
|
||||
*/
|
||||
void certificate_copy(certificate_t *copiedCert, const certificate_t *originalCert);
|
||||
|
||||
/**
|
||||
* \brief Iterate over the certificate chain in argument and check each child/parent pairs
|
||||
* \param[in] rootCA Pointer to the root CA certificate buffer
|
||||
* \param[in] certChain Pointer to the certificate chain buffer
|
||||
* \param[in] certChainSize Size of the certificate chain buffer
|
||||
* \param[out] leafCert Pointer to the leaf certificate structure
|
||||
* \return : ertificate_status_t 0 on success ; error code otherwise
|
||||
*/
|
||||
certificate_status_t certificate_parse_chain(
|
||||
uint8_t *rootCA,
|
||||
uint8_t *certChain,
|
||||
uint16_t certChainSize,
|
||||
certificate_t *leafCert);
|
||||
|
||||
/** @}*/
|
||||
|
||||
#endif /* CERTIFICATE_H */
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* \file certificate_crypto.h
|
||||
* \author STMicroelectronics - CS application team
|
||||
* \brief Crypto functionalities for x509 verification
|
||||
******************************************************************************
|
||||
* \attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2022 STMicroelectronics</center></h2>
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef CERTIFICATE_CRYPTO_H
|
||||
#define CERTIFICATE_CRYPTO_H
|
||||
|
||||
/** \defgroup certificate_crypto Certificate cryptography
|
||||
* \ingroup certificate
|
||||
* \brief Certificate cryptography functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Verify the signature of a certificate with a public key
|
||||
* \param[in] signing_public_key pointer to the parsed x509 certificate containing the public key to be used for the signature verification
|
||||
* \param[in] signing_public_key_size size in bytes of the digest of the message to be verified
|
||||
* \param[in] certificate pointer to the parsed x509 certificate to verify
|
||||
* \return \ref certificate_status_t : CERT_OK on success ; error code otherwise
|
||||
*/
|
||||
certificate_status_t certificate_verify_signature(const uint8_t* signing_public_key, uint32_t signing_public_key_size, const certificate_t* certificate);
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* \brief Verify the signature of a digest with a public key extracted from the certificate
|
||||
* \param[in] cert pointer to the parsed x509 certificate containing the public key to be used for the signature verification
|
||||
* \param[in] digest the digest of the message to be verified
|
||||
* \param[in] digestSize size in bytes of the digest of the message to be verified
|
||||
* \param[in] signatureR the R value of the signature to be verified
|
||||
* \param[in] signatureRsize the size in bytes of signatureR
|
||||
* \param[in] signatureS the S value of the signature to be verified
|
||||
* \param[in] signatureSsize the size in bytes of signatureS
|
||||
* \return \ref certificate_status_t : CERT_OK on success ; error code otherwise
|
||||
*/
|
||||
certificate_status_t certificate_verify_signature(
|
||||
const certificate_t *cert,
|
||||
const uint8_t *digest,
|
||||
int32_t digestSize,
|
||||
const uint8_t *signatureR,
|
||||
int32_t signatureRsize,
|
||||
const uint8_t *signatureS,
|
||||
int32_t signatureSsize);
|
||||
#endif
|
||||
/**
|
||||
* \brief Check whether "parent" signed "child"
|
||||
* \param[in] parent pointer to the parsed x509 certificate of the supposed issuer of child
|
||||
* \param[in] child pointer to the parsed x509 certificate of the certificated supposedly issued by parent
|
||||
* \return \ref certificate_status_t : CERT_OK on success ; error code otherwise
|
||||
*/
|
||||
certificate_status_t certificate_verify_child_signature(
|
||||
const certificate_t *parent,
|
||||
const certificate_t *child);
|
||||
|
||||
/** @}*/
|
||||
|
||||
#endif /* CERTIFICATE_CRYPTO_H */
|
||||
@@ -0,0 +1,289 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* \file certificate_subparsing.h
|
||||
* \author STMicroelectronics - CS application team
|
||||
* \brief Helper for the x509 certificate Parser
|
||||
******************************************************************************
|
||||
* \attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2022 STMicroelectronics</center></h2>
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef CERTIFICATE_SUBPARSING_H
|
||||
#define CERTIFICATE_SUBPARSING_H
|
||||
|
||||
/** \defgroup certificate_subparsing Certificate subparsing routines
|
||||
* \ingroup certificate
|
||||
* \brief Certificate subparsing routines
|
||||
* \{
|
||||
*/
|
||||
|
||||
/** \brief Definitions of X509 TAGs */
|
||||
typedef enum {
|
||||
TAG_BOOLEAN = 0x01, /*!< x509 tag for BOOLEAN */
|
||||
TAG_INTEGER, /*!< x509 tag for INTEGER */
|
||||
TAG_BITSTRING, /*!< x509 tag for BITSTRING */
|
||||
TAG_OCTETSTRING, /*!< x509 tag for OCTETSTRING */
|
||||
TAG_NULL, /*!< x509 tag for NULL */
|
||||
TAG_OBJECT_IDENTIFIER, /*!< x509 tag for OBJECT_IDENTIFIER */
|
||||
TAG_ObjectDescriptor, /*!< x509 tag for ObjectDescriptor */
|
||||
TAG_ENUMERATED = 0x0A, /*!< x509 tag for ENUMERATED */
|
||||
TAG_UTF8String = 0x0C, /*!< x509 tag for UTF8String */
|
||||
TAG_PrintableString = 0x13, /*!< x509 tag for PrintableString */
|
||||
TAG_IA5String = 0x16, /*!< x509 tag for IA5String */
|
||||
TAG_UTCTime, /*!< x509 tag for UTCTime */
|
||||
TAG_GeneralizedTime, /*!< x509 tag for GeneralizedTime */
|
||||
TAG_SEQUENCE = 0x30, /*!< x509 tag for SEQUENCE */
|
||||
TAG_SET, /*!< x509 tag for SET */
|
||||
TAG_OPTION_0 = 0x80, /*!< x509 tag for option 0 */
|
||||
TAG_OPTION_1 , /*!< x509 tag for option 1 */
|
||||
TAG_OPTION_2 , /*!< x509 tag for option 2 */
|
||||
TAG_OPTION_3 , /*!< x509 tag for option 3 */
|
||||
TAG_x509VERSION = 0xA0, /*!< x509 tag for x509VERSION */
|
||||
TAG_issuerUniqueID, /*!< x509 tag for issuerUniqueID */
|
||||
TAG_subjectUniqueID, /*!< x509 tag for subjectUniqueID */
|
||||
TAG_extensions, /*!< x509 tag for extensions */
|
||||
}certificate_tag_t;
|
||||
|
||||
/** \brief Definitions of supported Name Attributes */
|
||||
typedef enum {
|
||||
ATTR_CN = 3, /*!< CommonName */
|
||||
ATTR_SN = 5, /*!< SerialNumber */
|
||||
ATTR_C = 6, /*!< Country */
|
||||
ATTR_LN = 7, /*!< LocalityName */
|
||||
ATTR_SOPN = 8, /*!< stateOrProvinceName */
|
||||
ATTR_ON = 10, /*!< Organization Name */
|
||||
ATTR_OUN = 11, /*!< Organization Unit Name */
|
||||
ATTR_UID = 45, /*!< UniqueIdentifier */
|
||||
ATTR_DN = 49, /*!< DistinguishedName */
|
||||
}certificate_name_attributes_t;
|
||||
|
||||
/** \brief Definitions of supported Extensions types */
|
||||
typedef enum {
|
||||
EXTENSION_KU = 15, /*!< KeyUsage */
|
||||
EXTENSION_BC = 19, /*!< BasicContrains */
|
||||
EXTENSION_AKI = 35, /*!< authority key identifier */
|
||||
EXTENSION_EKU = 37, /*!< extKeyUsage */
|
||||
}certificate_extensions_type_t;
|
||||
|
||||
/** \brief Structure used to keep SignatureAlgorithm OIDs */
|
||||
struct SignatureAlgorithmOID_st
|
||||
{
|
||||
uint32_t len; /*!< size of the encoded OID */
|
||||
uint32_t type; /*!< type of OID */
|
||||
uint8_t oid[8]; /*!< encoded OID */
|
||||
};
|
||||
|
||||
/** \brief Structure used to keep Name Attribute OIDs */
|
||||
struct AttributeOID_st
|
||||
{
|
||||
uint32_t len; /*!< size of the encoded OID */
|
||||
uint32_t type; /*!< type of OID */
|
||||
uint8_t oid[3]; /*!< encoded OID */
|
||||
};
|
||||
|
||||
/** \brief Structure used to keep named Elliptic Curve OIDs */
|
||||
struct EllipticCurveOID_st
|
||||
{
|
||||
uint32_t len; /*!< size of the encoded OID */
|
||||
uint32_t type; /*!< type of OID */
|
||||
uint8_t oid[9]; /*!< encoded OID */
|
||||
};
|
||||
|
||||
/** \brief typedef for the attribute */
|
||||
typedef struct attribute_st
|
||||
{
|
||||
uint32_t type; /*!< type of attribute (corresponding to OID) */
|
||||
uint32_t strFormat; /*!< format of the string */
|
||||
const uint8_t *str; /*!< pointer to the string of the attribute */
|
||||
uint32_t strSize; /*!< size of the string */
|
||||
} cert_attribute_t;
|
||||
|
||||
/** \brief Structure used to keep Name Attribute OIDs */
|
||||
struct ExtensionOID_st
|
||||
{
|
||||
uint32_t len; /*!< size of the encoded OID */
|
||||
uint32_t type; /*!< type of OID */
|
||||
uint8_t oid[5]; /*!< encoded OID */
|
||||
};
|
||||
|
||||
/** \brief typedef for the extension */
|
||||
typedef struct extension_st
|
||||
{
|
||||
uint32_t type; /*!< type of extension (corresponding to OID) */
|
||||
uint32_t critical; /*!< critical */
|
||||
const uint8_t *value;/*!< pointer to the value hold by the extension (this is an octet string) */
|
||||
uint32_t valueSize; /*!< size of the string */
|
||||
} cert_extension_t;
|
||||
|
||||
|
||||
/* Exported Macros */
|
||||
|
||||
/** \brief Macro which checks if a TAG is valid (known) */
|
||||
#define IS_VALID_TAG(tag) (( \
|
||||
(TAG_BOOLEAN <= (tag) && (tag) <= TAG_ObjectDescriptor) || \
|
||||
(tag) == TAG_ENUMERATED || \
|
||||
(tag) == TAG_UTF8String || \
|
||||
(tag) == TAG_PrintableString || \
|
||||
(TAG_IA5String <= (tag) && (tag) <= TAG_GeneralizedTime) || \
|
||||
(tag) == TAG_SEQUENCE || \
|
||||
(tag) == TAG_SET || \
|
||||
(TAG_OPTION_0 <= (tag) && (tag) <= TAG_OPTION_3) || \
|
||||
(TAG_x509VERSION <= (tag) && (tag) <= TAG_extensions) ) ? 1 : 0)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Identify the ASN.1 TLV
|
||||
* \param[in] *asn1 pointer to the ASN.1 TLV
|
||||
* \param[out] *parsed will contain the number of processed bytes (rarely used)
|
||||
* \param[out] *size will contain the size (in bytes) of the value field of this ASN.1 TLV
|
||||
* \param[out] **value will contain a pointer to the value field of this ASN.1 TLV
|
||||
* \param[in/out] *max_size maximum size left for value
|
||||
* \return The internal TAG identifier of this TLV or -1 if failure
|
||||
*/
|
||||
int32_t certificate_identify_ASN1_TLV(const uint8_t *asn1, int32_t *parsed, int32_t *size, const uint8_t **value, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Identify the Name Attribute from its OID
|
||||
* \param[in] *oid The value of the OID of the Attribute (got from \ref certificate_identify_ASN1_TLV )
|
||||
* \param[in] size size (in bytes) of the value field of this OID (got from \ref certificate_identify_ASN1_TLV )
|
||||
* \note Only a very limited set of Attributes is supported
|
||||
* \return The internal type identifing the Attribute or -1 for failure
|
||||
*/
|
||||
int32_t certificate_identify_attribute(const uint8_t *oid, int32_t size);
|
||||
|
||||
/**
|
||||
* \brief Parse an ECDSA signature
|
||||
* \param[in] *signature pointer to the expected signature field of the x509 certificate
|
||||
* \param[out] *certificate pointer to the certificate_t that will be filled
|
||||
* \param[out] **next_thing will contain a pointer to the next TLV
|
||||
*/
|
||||
void certificate_parse_ECDSA_signature(const uint8_t *signature, certificate_t *certificate, const uint8_t **next_thing, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Parse the x509 Version of a certificate
|
||||
* \param[in] *x509VersionField pointer to the version field of a certificate
|
||||
* \param[out] *certificate pointer to the certificate_t that will be filled
|
||||
* \param[out] **next_thing output pointer to next TLV
|
||||
*/
|
||||
void certificate_parse_X509_version(const uint8_t *x509VersionField, certificate_t *certificate, const uint8_t **next_thing, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Parse a SignatureAlgorithm (or signature of a tbsCertificate)
|
||||
* \param[in] *SA pointer to the SignatureAlgorithm (or signature of a tbsCertificate)
|
||||
* \param[out] *singatureAlgorithm integer that will be filled with the internal encoding of signatureAlgorithm
|
||||
* \param[out] **next_thing output pointer to next TLV
|
||||
* \note Only a very limited set of SignatureAlgorithm is supported
|
||||
*/
|
||||
void certificate_parse_signature_algorithm(const uint8_t *SA, uint32_t *singatureAlgorithm, const uint8_t **next_thing, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Parse an ECC public Key from a certificate
|
||||
* \param[in] *EccPK pointer to the ECC public Key
|
||||
* \param[out] *certificate pointer to the certificate_t that will be filled
|
||||
* \param[out] **next_thing output pointer to next TLV
|
||||
*/
|
||||
void certificate_parse_ECC_public_key(const uint8_t *EccPK, certificate_t *certificate, const uint8_t **next_thing, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Parse an ASN.1 INTEGER
|
||||
* \param[in] *integer pointer to the expected INTEGER TLV
|
||||
* \param[out] *outp will point to the starting byte of the integer
|
||||
* \param[out] *outSize will contain the size of the integer in bytes
|
||||
* \param[out] **next_thing will contain a pointer to the next TLV
|
||||
* \note This doesn't copy the integer. To keep memory small this just returns a pointer to it.
|
||||
* \warning only non-negative integers are supported
|
||||
*/
|
||||
void certificate_parse_integer(const uint8_t *integer, const uint8_t **outp, uint32_t *outSize, const uint8_t **next_thing, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Parse the validity of a certificate
|
||||
* \param[in] *p pointer to the Name Attribute SET to be parsed
|
||||
* \param[out] *notBefore_st pointer to cert_validity_t structure that will be filled with the "not before" date
|
||||
* \param[out] *notAfter_st pointer to cert_validity_t structure that will be filled with the "not after" date
|
||||
* \param[out] **next_thing output pointer to next TLV
|
||||
* \note In this function next_thing can be NULL
|
||||
*/
|
||||
void certificate_parse_validity(const uint8_t *p, cert_validity_t *notBefore_st, cert_validity_t *notAfter_st, const uint8_t **next_thing, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Parse an RelativeDistinguishedName
|
||||
* \param[in] *p pointer to the RelativeDistinguishedName (expeting a SET)
|
||||
* \param[out] **nextRDN output pointer to next RDN
|
||||
* \param[out] **attribute output pointer to RDN first attribute
|
||||
*/
|
||||
void certificate_parse_relative_distinguished_name(const uint8_t *p, const uint8_t **nextRDN, const uint8_t **attribute, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Parse a Name Attribute
|
||||
* \param[in] *p pointer to the AttributeTypeAndValue SEQUENCE to be parsed
|
||||
* \param[out] *attribute_st pointer to cert_attribute_t structure that will be filled
|
||||
* \param[out] **next_thing output pointer to next TLV
|
||||
*/
|
||||
void certificate_parse_attribute(const uint8_t *p, cert_attribute_t *attribute_st, const uint8_t **next_thing, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Compare two cert_validity_t structures
|
||||
* \param[in] *D1 pointer to the first cert_validity_t
|
||||
* \param[in] *D2 pointer to the second cert_validity_t
|
||||
* \return Result of Comparison
|
||||
* \retval -1 D1 < D2
|
||||
* \retval 0 D1 = D2
|
||||
* \retval 1 D1 > D2
|
||||
*/
|
||||
int32_t certificate_date_compare(const cert_validity_t *D1, const cert_validity_t *D2);
|
||||
|
||||
/**
|
||||
* \brief Count the number of Attributes within a NAME
|
||||
* \param[in] *p pointer to the RDNSequence to be parsed
|
||||
* \returun The number of Attributes
|
||||
*/
|
||||
int32_t certificate_count_attributes(const uint8_t *p);
|
||||
|
||||
/**
|
||||
* \brief String Comparison (case insensitive and for utf8)
|
||||
* \param[in] *p1 first string to compare
|
||||
* \param[in] *p2 second string to compare
|
||||
* \param[in] size p1/p2 size
|
||||
* \return result of comparison
|
||||
* \retval -1 strings are different
|
||||
* \retval 0 strings match
|
||||
*/
|
||||
int32_t certificate_case_insensitive_compare(const uint8_t *p1, const uint8_t *p2, int32_t size);
|
||||
|
||||
/**
|
||||
* \brief Identify the Extension from its OID
|
||||
* \param[in] *oid The value of the OID of the Extension (got from \ref certificate_identify_ASN1_TLV )
|
||||
* \param[in] size size (in bytes) of the value field of this OID (got from \ref certificate_identify_ASN1_TLV )
|
||||
* \note Only a very limited set of Extension is supported
|
||||
* \return The internal type identifing the Extension or -1 for failure
|
||||
*/
|
||||
int32_t certificate_case_identify_extension(const uint8_t *oid, int32_t size);
|
||||
|
||||
/**
|
||||
* \brief Parse an x509 Extension
|
||||
* \param[in] *ext pointer to the extension
|
||||
* \param[out] certificate structure
|
||||
* \param[out] *ext_st pointer to an cert_extension_t structure
|
||||
*/
|
||||
void certificate_parse_extension(const uint8_t *ext, certificate_t *certificate, cert_extension_t *ext_st, uint32_t* max_size);
|
||||
|
||||
/**
|
||||
* \brief Reads the value of an INTEGER and returns it as a int32_t
|
||||
* \param[in] *value pointer to the value field of an INTEGER TLV (got from \ref certificate_identify_ASN1_TLV)
|
||||
* \param[in] size size of the integer (got from \ref certificate_identify_ASN1_TLV)
|
||||
* \return the integer value as an int32_t
|
||||
* \warning only non-negative integers are supported
|
||||
*/
|
||||
int32_t certificate_get_small_integer(const uint8_t *value, int32_t size);
|
||||
|
||||
/** \}*/
|
||||
|
||||
#endif /* CERTIFICATE_SUBPARSING_H */
|
||||
@@ -0,0 +1,236 @@
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : custom_uwb.h
|
||||
* @brief : Header for custom_uwb.c file.
|
||||
* This file contains the public declarations for the custom UWB functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _CUSTOM_UWB_H_
|
||||
#define _CUSTOM_UWB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ACWG_Security.h"
|
||||
|
||||
|
||||
/** @addtogroup BLE_UWB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup UWB_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Initialize UWB session.
|
||||
* Uses for UWB Context and ranging session initialization.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Initiate_uwb_ctx(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Handle UWB time synchronization frame.
|
||||
* Uses to process and apply time sync information for the current UWB session.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Handle_uwb_Time_Sync(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Fill outbound M1 message fields.
|
||||
* Uses to fill UWB M1 message fields:
|
||||
* The first three fields depends of the UWB capabilities.
|
||||
* 1. UWB Configuration Identifier
|
||||
* 2. Pulse Shape Combination
|
||||
* 3. Channel Bitmask
|
||||
* 4. UWB Session Identifier
|
||||
* 5. Vendor Specific attribute is optionally present.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Fill_uwb_M1(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Handle inbound M2 message fields.
|
||||
* Uses to handle UWB M2 message fields:
|
||||
* The first three fields is linked to the same in M1 and represents the device selection,
|
||||
* then the follow fields are session parameters/mask available by device:
|
||||
* 1. UWB Configuration Identifier
|
||||
* 2. Pulse Shape Combination
|
||||
* 3. Channel Bitmask
|
||||
* 4. SYNC Code Index Bitmask
|
||||
* 5. RAN Multiplier
|
||||
* 6. Slot Bitmask
|
||||
* 7. Hopping Configuration Bitmask
|
||||
* 8. Vendor Specific attribute is optionally present.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Handle_uwb_M2(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Fill outbound M3 message fields.
|
||||
* Uses to fill UWB M3 message fields:
|
||||
* The follow fields are session parameters set by the Reader based on M2 content:
|
||||
* 1. RAN Multiplier
|
||||
* 2. Number Chaps per Slot
|
||||
* 3. Number Responders Nodes
|
||||
* 4. Number Slots per Round
|
||||
* 5. SYNC Code Index Bitmask
|
||||
* 6. Hopping Configuration Bitmask
|
||||
* 7. MAC Mode
|
||||
* 8. Vendor Specific attribute is optionally present.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Fill_uwb_M3(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Handle inbound M4 message fields.
|
||||
* Uses to handle UWB M4 message fields.
|
||||
* The follow fields are session parameters set by the device based on M3 content:
|
||||
* 1. STS Index0
|
||||
* 2. UWB Time0
|
||||
* 3. HOP Mode Key
|
||||
* 4. SYNC Code Index
|
||||
* 5. Vendor Specific attribute is optionally present.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Handle_uwb_M4(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Prepare the ranging initialization step.
|
||||
* Called only once after M1/M2/M3/M4 exchange.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Prepare_ranging_init(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Prepare the ranging loop step.
|
||||
* Called repeatedly in the prepare ranging loop until timeout expires.
|
||||
* Uses to setup uwb ranging parameters before starting ranging.
|
||||
* @param ctx Session context.
|
||||
* @param timeout Pointer to timeout in ms. Set to 1 to exit the loop.
|
||||
*/
|
||||
void Prepare_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout);
|
||||
|
||||
/**
|
||||
* @brief Execute the ranging initialization step.
|
||||
* Called only one time after prepare ranging steps.
|
||||
* Uses to start the UWB ranging .
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Execute_ranging_init(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Execute the ranging loop step.
|
||||
* Called repeatedly in the execute ranging loop until timeout expires.
|
||||
* Uses to perform UWB ranging acquisition and evaluate ranging results.
|
||||
* Exiting this loop the Handle_lock_actuation function is called.
|
||||
* @param ctx Session context.
|
||||
* @param timeout Pointer to timeout in ms. Set to 1 to exit the loop.
|
||||
*/
|
||||
void Execute_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout);
|
||||
|
||||
/**
|
||||
* @brief Close the ranging initialization step.
|
||||
* Called only one time after Handle_lock_actuation.
|
||||
* Uses to stop and deinit UWB ranging session.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Close_ranging_init(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Close the ranging loop step.
|
||||
* Called repeatedly in the close ranging loop until timeout expires.
|
||||
* @param ctx Session context.
|
||||
* @param timeout Pointer to timeout in ms. Set to 1 to exit the loop.
|
||||
*/
|
||||
void Close_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout);
|
||||
|
||||
/**
|
||||
* @brief Suspend the ranging initialization step.
|
||||
* Called only one time after suspend response or suspend event in ranging session.
|
||||
* Uses to stop UWB ranging session.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Suspend_ranging_init(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Suspend the ranging loop step.
|
||||
* Called repeatedly in the suspend ranging loop until timeout expires.
|
||||
* @param ctx Session context.
|
||||
* @param timeout Pointer to timeout in ms. Set to 1 to exit the loop.
|
||||
*/
|
||||
void Suspend_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout);
|
||||
|
||||
/**
|
||||
* @brief Resume the ranging initialization step.
|
||||
* Called only one time after resume response in ranging session.
|
||||
* Uses to set new Time0 and SlotIndex0 in UWB ranging session.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Resume_ranging_init(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Resume the ranging loop step.
|
||||
* Called repeatedly in the resume ranging loop until timeout expires.
|
||||
* After exiting this loop the Execute_ranging_init function is called.
|
||||
* @param ctx Session context.
|
||||
* @param timeout Pointer to timeout in ms. Set to 1 to exit the loop.
|
||||
*/
|
||||
void Resume_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout);
|
||||
|
||||
/**
|
||||
* @brief Handle and evaluate distance results.
|
||||
* Called only one time during preparing Reader Status Exchange frame.
|
||||
* Uses to notify if distance allowed to open the lock.
|
||||
* @param ctx Session context.
|
||||
* @return 1 if distance allowed to open lock, 0 otherwise.
|
||||
*/
|
||||
uint8_t Handle_distance_result(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Trigger lock actuation based on session state.
|
||||
* Called only one time after Execute_ranging_loop.
|
||||
* Uses to actuate the lock based on distance result evaluation.
|
||||
* @param ctx Session context.
|
||||
*/
|
||||
void Handle_lock_actuation(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Initialize UWB hardware.
|
||||
* Uses for UWB hardware initialization, called only one time at startup.
|
||||
*/
|
||||
void UWB_HW_init( void );
|
||||
|
||||
/**
|
||||
* @brief Run periodic UWB hardware tasks.
|
||||
* Uses for periodic UWB hardware tasks, called repeatedly in main loop.
|
||||
*/
|
||||
void UWB_HW_loop( void );
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CUSTOM_UWB_H_ */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : flash_mng.h
|
||||
* @brief : Header for flash_mng.c file.
|
||||
* This file declares the Flash management API used by the Aliro application (erase/write helpers).
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _FLASH_MNG_H_
|
||||
#define _FLASH_MNG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup FLASH_MNG
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "app_nfc.h"
|
||||
//#include "utils.h"
|
||||
#include "main.h"
|
||||
|
||||
/** @addtogroup Flash_mng_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @enum flashOpStatus_e
|
||||
* @brief Status codes for flash operations.
|
||||
*/
|
||||
typedef enum _flashOpStatus
|
||||
{
|
||||
FLASH_OP_OK, /**< Operation successful */
|
||||
FLASH_OP_BUSY, /**< Flash is busy */
|
||||
FLASH_OP_ERROR /**< Operation failed */
|
||||
}
|
||||
flashOpStatus_e;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Flash_mng_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Writes data to flash memory.
|
||||
* @param data Pointer to the data to write.
|
||||
* @param nBytes Number of bytes to write.
|
||||
* @param nAddress Destination address in flash.
|
||||
* @return Status of the operation.
|
||||
*/
|
||||
flashOpStatus_e WriteToFlash(void *data, uint32_t nBytes, uint32_t nAddress);
|
||||
|
||||
/**
|
||||
* @brief Erases the flash sector and writes data to it.
|
||||
* @param data Pointer to the data to write.
|
||||
* @param nBytes Number of bytes to write.
|
||||
* @param nAddress Destination address in flash.
|
||||
* @return Status of the operation.
|
||||
*/
|
||||
flashOpStatus_e EraseWriteToFlash(void *data, uint32_t nBytes, uint32_t nAddress);
|
||||
|
||||
/**
|
||||
* @brief Erases a region of flash memory.
|
||||
* @param nAddress Start address of the region to erase.
|
||||
* @param nBytes Number of bytes to erase.
|
||||
* @return Status of the operation.
|
||||
*/
|
||||
flashOpStatus_e EraseFlash(uint32_t nAddress, uint32_t nBytes);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FLASH_MNG_H_ */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : log_module_u5.h
|
||||
* @brief : Header for log_module_u5.c file.
|
||||
* Provides logging macros and prototypes for the U5 platform.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _LOG_MODULE_U5_H_
|
||||
#define _LOG_MODULE_U5_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "st_errno.h"
|
||||
|
||||
/** @addtogroup NFCBLE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup log_module_u5_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
typedef uint8_t Log_Verbose_Level_t;
|
||||
typedef uint8_t Log_Region_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup log_module_u5_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @def LOG_INFO_APP
|
||||
* @brief Macro for logging information messages in the application.
|
||||
* @param ... Arguments to be printed using DBG_PRINTF.
|
||||
*/
|
||||
#define LOG_INFO_APP(...) do{Log_Module_Print(0,0,__VA_ARGS__);}while(0)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LOG_MODULE_U5_H_ */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : log_module_u5.h
|
||||
* @brief : Header for log_module_u5.c file.
|
||||
* Provides logging macros and prototypes for the U5 platform.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _LOG_MODULE_U5_H_
|
||||
#define _LOG_MODULE_U5_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "st_errno.h"
|
||||
|
||||
/** @addtogroup NFCBLE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup log_module_u5_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
typedef uint8_t Log_Verbose_Level_t;
|
||||
typedef uint8_t Log_Region_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup log_module_u5_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @def LOG_INFO_APP
|
||||
* @brief Macro for logging information messages in the application.
|
||||
* @param ... Arguments to be printed using DBG_PRINTF.
|
||||
*/
|
||||
#define LOG_INFO_APP(...) do{Log_Module_Print(0,0,__VA_ARGS__);}while(0)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LOG_MODULE_U5_H_ */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,284 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : provisioning.h
|
||||
* @brief : Header for provisioning module.
|
||||
* This file contains the common defines and structures for provisioning.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _PROVISIONING_H_
|
||||
#define _PROVISIONING_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup PROVISIONING_MNG
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ACWG_Security.h"
|
||||
#include "stdbool.h"
|
||||
#include "provisioning_info.h"
|
||||
|
||||
/** @addtogroup Provisioning_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @def PRIVATE_KEY_SIZE_BYTES
|
||||
* @brief Size of private key in bytes.
|
||||
*/
|
||||
#define PRIVATE_KEY_SIZE_BYTES ((uint32_t)32)
|
||||
/**
|
||||
* @def AUTH_PUBKEY_LEN_BYTES
|
||||
* @brief Length of authentication public key in bytes.
|
||||
*/
|
||||
#define AUTH_PUBKEY_LEN_BYTES ((uint32_t)64)
|
||||
/**
|
||||
* @def GROUP_RESOLVING_KEY_SIZE_BYTES
|
||||
* @brief Size of group resolving key in bytes.
|
||||
*/
|
||||
#define GROUP_RESOLVING_KEY_SIZE_BYTES ((uint32_t)16)
|
||||
/**
|
||||
* @def DEVICE_NAME_SIZE_BYTES
|
||||
* @brief Size of device name in bytes.
|
||||
*/
|
||||
#define DEVICE_NAME_SIZE_BYTES ((uint32_t)16)
|
||||
/**
|
||||
* @def B1_VENDOR_SPEC_EXT_SIZE_BYTES
|
||||
* @brief Size of vendor specific extension in bytes.
|
||||
*/
|
||||
#define B1_VENDOR_SPEC_EXT_SIZE_BYTES ((uint32_t)64)
|
||||
/**
|
||||
* @def RESERVED_PAIRING_KEYS_SIZE_BYTES
|
||||
* @brief Size of buffer in bytes reserved for future use .
|
||||
*/
|
||||
#define RESERVED_PAIRING_KEYS_SIZE_BYTES ((uint32_t)32)
|
||||
/**
|
||||
* @def CERTIFICATE_SIZE
|
||||
* @brief Size of certificate data in bytes.
|
||||
*/
|
||||
#define CERTIFICATE_SIZE ((uint32_t)400)
|
||||
|
||||
/**
|
||||
* @def NUM_PROV_DEVICES
|
||||
* @brief Maximum number of provisioned devices.
|
||||
*/
|
||||
#define NUM_PROV_DEVICES 5
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Provisioning_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/* Exported variables ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Provisioning_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @struct devices_t
|
||||
* @brief Structure representing a provisioned device.
|
||||
*/
|
||||
typedef struct devices_s
|
||||
{
|
||||
uint8_t name[DEVICE_NAME_SIZE_BYTES]; /**< Device name */
|
||||
uint8_t endpoint_Keyslot[AUTH_KEYSLOT_LEN_BYTES]; /**< Endpoint keyslot */
|
||||
uint8_t endpoint_PubK[AUTH_PUBKEY_LEN_BYTES]; /**< Endpoint public key */
|
||||
uint8_t endpoint_PrivK[PRIVATE_KEY_SIZE_BYTES]; /**< Endpoint private key */
|
||||
}devices_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct provstruct_t
|
||||
* @brief Structure representing the provisioning data.
|
||||
*/
|
||||
typedef struct provstruct_s
|
||||
{
|
||||
uint32_t isValid; /**< Validity flag */
|
||||
uint8_t readerID[AUTH_READER_GROUP_ID_LEN_BYTES + AUTH_READER_GROUP_SUB_ID_LEN_BYTES]; /**< Reader ID */
|
||||
uint8_t readerPubK[AUTH_PUBKEY_LEN_BYTES]; /**< Reader public key */
|
||||
uint8_t staticPrivateKey[PRIVATE_KEY_SIZE_BYTES]; /**< Static private key */
|
||||
uint8_t group_resolving_key[GROUP_RESOLVING_KEY_SIZE_BYTES]; /**< Group resolving key */
|
||||
uint8_t certificate_data[CERTIFICATE_SIZE]; /**< Certificate data */
|
||||
uint32_t certificate_len; /**< Certificate length */
|
||||
uint8_t readerIssuerPubK[AUTH_PUBKEY_LEN_BYTES]; /**< Reader issuer public key */
|
||||
uint8_t b1VendorSpecificExtension[B1_VENDOR_SPEC_EXT_SIZE_BYTES]; /**< Vendor specific extension */
|
||||
uint32_t b1VendorSpecificExtensionLen; /**< Vendor specific extension length */
|
||||
uint32_t numDevices; /**< Number of devices */
|
||||
devices_t devices[NUM_PROV_DEVICES]; /**< Array of provisioned devices */
|
||||
uint32_t isValidReserved; /**< RESERVED validity flag */
|
||||
uint8_t reservedPairingKeys[RESERVED_PAIRING_KEYS_SIZE_BYTES]; /**< RESERVED pairing keys */
|
||||
uint32_t struct_size; /**< Structure size */
|
||||
}provstruct_t;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Provisioning_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Shows the status of the JSON provisioning data.
|
||||
*/
|
||||
void showJsonStatus();
|
||||
|
||||
/**
|
||||
* @brief Shows the status of the provisioning data.
|
||||
*/
|
||||
void showProvisioningStatus();
|
||||
|
||||
/**
|
||||
* @brief Saves the provisioning data to flash memory.
|
||||
* @param profile_num Profile number to save.
|
||||
*/
|
||||
void saveProvisioningToFlash(uint32_t profile_num);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the provisioning data from flash memory.
|
||||
* @return Pointer to the provisioning structure.
|
||||
*/
|
||||
provstruct_t* getProvisioningFromFlash();
|
||||
|
||||
/**
|
||||
* @brief Loads provisioning data from a JSON address.
|
||||
* @param jsonAddress Address of the JSON data.
|
||||
* @param provstruct Pointer to the provisioning structure to fill.
|
||||
*/
|
||||
void loadProvisionFromJson(uint32_t jsonAddress, provstruct_t*provstruct);
|
||||
|
||||
/**
|
||||
* @brief Converts provisioning data from JSON format.
|
||||
* @param jsonAddress Address of the JSON data.
|
||||
*/
|
||||
void convertProvisioningFromJson(uint32_t jsonAddress);
|
||||
|
||||
/**
|
||||
* @brief Converts default provisioning data from JSON format.
|
||||
*/
|
||||
void convertDefaultProvisioningFromJson();
|
||||
|
||||
/**
|
||||
* @brief Prints the device JSON data.
|
||||
*/
|
||||
void printDeviceJson();
|
||||
|
||||
/**
|
||||
* @brief Prints the script JSON data.
|
||||
*/
|
||||
void printScriptJson();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Saves the reader public key to flash memory.
|
||||
* @param pkey Pointer to the public key.
|
||||
* @param ksize Size of the key.
|
||||
*/
|
||||
void saveRDPubKToFlash(const uint8_t *pkey, const uint8_t ksize);
|
||||
|
||||
/**
|
||||
* @brief Saves the reader private key to flash memory.
|
||||
* @param pkey Pointer to the private key.
|
||||
* @param ksize Size of the key.
|
||||
*/
|
||||
void saveRDPrvKToFlash(const uint8_t *pkey, const uint8_t ksize);
|
||||
|
||||
/**
|
||||
* @brief Saves the reader identity to flash memory.
|
||||
* @param pkey Pointer to the identity data.
|
||||
* @param ksize Size of the identity data.
|
||||
*/
|
||||
void saveRDidenToFlash(const uint8_t *pkey, const uint8_t ksize);
|
||||
|
||||
/**
|
||||
* @brief Saves the reader group resolving key to flash memory.
|
||||
* @param pkey Pointer to the group resolving key.
|
||||
* @param ksize Size of the key.
|
||||
*/
|
||||
void saveRDgrrkToFlash(const uint8_t *pkey, const uint8_t ksize);
|
||||
|
||||
/**
|
||||
* @brief Saves the credential issuer public key to flash memory.
|
||||
* @param pkey Pointer to the credential issuer public key.
|
||||
* @param ksize Size of the public key.
|
||||
*/
|
||||
void saveCredIsPkToFlash(const uint8_t *pkey, const uint8_t ksize);
|
||||
|
||||
/**
|
||||
* @brief Saves the access credential public key.
|
||||
* @param last_pkey Pointer to the last public key.
|
||||
* @param ksize Size of the key.
|
||||
* @param nSlot Slot number.
|
||||
*/
|
||||
void saveAccessCredentialPuBK(uint8_t *pkey, const uint8_t ksize, uint8_t nSlot, uint8_t *pkeyname);
|
||||
|
||||
/**
|
||||
* @brief Checks if a buffer contains only zeros.
|
||||
* @param pBuf Pointer to the buffer.
|
||||
* @param nSize Size of the buffer.
|
||||
* @return 1 if all zeros, 0 otherwise.
|
||||
*/
|
||||
uint8_t is_zeros(uint8_t* pBuf, uint32_t nSize);
|
||||
|
||||
/**
|
||||
* @brief Checks the endpoint public key for provisioning.
|
||||
* @param endp_PubK Pointer to the endpoint public key.
|
||||
* @return Status code.
|
||||
*/
|
||||
uint8_t ProvisioningCheckEndpointPubK(uint8_t *endp_PubK);
|
||||
|
||||
/**
|
||||
* @brief Gets the endpoint public key from a keyslot.
|
||||
* @param endp_PubK Pointer to the endpoint public key.
|
||||
* @param endp_Keyslot Pointer to the endpoint keyslot.
|
||||
* @param slotFound Pointer to the found slot.
|
||||
* @return Status code.
|
||||
*/
|
||||
uint8_t ProvisioningGetEndpointPubKFromKeyslot(uint8_t *endp_PubK, uint8_t *endp_Keyslot, uint8_t*slotFound);
|
||||
|
||||
/**
|
||||
* @brief Converts a hex string to a hex buffer.
|
||||
* @param p Pointer to the hex string.
|
||||
* @param len Length of the string.
|
||||
* @param hexp Pointer to the hex buffer.
|
||||
*/
|
||||
void hexStrToHex(char *p, uint32_t len, uint8_t *hexp);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_PROVISIONING_H_
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : provisioning_info.h
|
||||
* @brief : Provisioning information and configuration defines for the application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _PROVISIONING_INFO_H_
|
||||
#define _PROVISIONING_INFO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup PROVISIONING_MNG
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Provisioning_info_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/**
|
||||
* @def ALIRO_APP_NAME
|
||||
* @brief Application name string.
|
||||
*/
|
||||
#define ALIRO_APP_NAME "TruELock"
|
||||
/**
|
||||
* @def DEFAULT_CMD_PARAMS_VALUE
|
||||
* @brief Default command parameters value (0 = Standard, 1 = Fast).
|
||||
*/
|
||||
#define DEFAULT_CMD_PARAMS_VALUE 0
|
||||
|
||||
/**
|
||||
* @def NFC_PROP_BUF_CONTENT
|
||||
* @brief Default NFC property buffer content.
|
||||
*/
|
||||
#define NFC_PROP_BUF_CONTENT { 0 }
|
||||
/**
|
||||
* @def BLE_ADV_DISABLE
|
||||
* @brief Disable BLE advertising (0 = enabled).
|
||||
*/
|
||||
#define BLE_ADV_DISABLE 0
|
||||
/**
|
||||
* @def ALIRO_NFC_TOTAL_DURATION
|
||||
* @brief Total duration for NFC operations in milliseconds.
|
||||
*/
|
||||
#define ALIRO_NFC_TOTAL_DURATION 1000U
|
||||
/**
|
||||
* @def TEST_HARNESS_SIMULATION
|
||||
* @brief Enable test harness simulation (0 = disabled).
|
||||
*/
|
||||
#define TEST_HARNESS_SIMULATION 0
|
||||
/**
|
||||
* @def ALIRO_PROT_VER
|
||||
* @brief Defines the default Aliro protocol versions supported for authentication and transport.
|
||||
*/
|
||||
#define ALIRO_PROT_VER_DEFAULT ( AUTH_EXP_TRANS_PROT_VERSION )
|
||||
|
||||
/**
|
||||
* @def ALIRO_PROT_VER
|
||||
* @brief Defines the Aliro protocol versions supported for authentication and transport.
|
||||
*/
|
||||
#define ALIRO_PROT_VER xProtocolVersionSupported
|
||||
|
||||
/**
|
||||
* @def ALIRO_MAIN_PROT_VER
|
||||
* @brief Main protocol version (lower 16 bits).
|
||||
*/
|
||||
#define ALIRO_MAIN_PROT_VER (ALIRO_PROT_VER & 0xffff)
|
||||
/**
|
||||
* @def ALIRO_HAS_SEC_PROT_VER
|
||||
* @brief Check if secondary protocol version is present.
|
||||
*/
|
||||
#define ALIRO_HAS_SEC_PROT_VER ((ALIRO_PROT_VER&0xFFFF0000)?(1):(0))
|
||||
/**
|
||||
* @def ALIRO_SEC_PROT_VER
|
||||
* @brief Secondary protocol version (upper 16 bits).
|
||||
*/
|
||||
#define ALIRO_SEC_PROT_VER ((ALIRO_PROT_VER&0xFFFF0000)>>16)
|
||||
/**
|
||||
* @def DEVICE_PROVISIONING_STRUCT_IS_VALID
|
||||
* @brief Magic value indicating a valid device provisioning structure.
|
||||
*/
|
||||
#define DEVICE_PROVISIONING_STRUCT_IS_VALID 0xA5A55A5A
|
||||
/**
|
||||
* @def EXPIRY_TIME_STAMP_DEFAULT_VALUE
|
||||
* @brief Default expiry timestamp value.
|
||||
*/
|
||||
#define EXPIRY_TIME_STAMP_DEFAULT_VALUE 0x76100fe0
|
||||
|
||||
/** @} */ // end of Provisioning_info_Constants
|
||||
|
||||
/** @addtogroup Provisioning_info_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/**
|
||||
* @def DISPLAY_SPLASH
|
||||
* @brief Macro to display splash screen.
|
||||
*/
|
||||
#define DISPLAY_SPLASH()
|
||||
/**
|
||||
* @def LOAD_NFC_PROP
|
||||
* @brief Macro to load NFC properties.
|
||||
*/
|
||||
#define LOAD_NFC_PROP()
|
||||
/**
|
||||
* @def DET_NFC_PROP
|
||||
* @brief Macro to detect NFC properties.
|
||||
*/
|
||||
#define DET_NFC_PROP()
|
||||
/**
|
||||
* @def INIT_NFC_PROP
|
||||
* @brief Macro to initialize NFC properties.
|
||||
*/
|
||||
#define INIT_NFC_PROP()
|
||||
|
||||
/**
|
||||
* @def UWB_SESSION_ID_DEFAULT
|
||||
* @brief Default UWB session ID value.
|
||||
*/
|
||||
#define UWB_SESSION_ID_DEFAULT getUwbSessionId()
|
||||
|
||||
/** @} */ // end of Provisioning_info_Macros
|
||||
|
||||
/** @addtogroup Provisioning_info_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "User_provisioning.h"
|
||||
|
||||
/** @} */ // end of Provisioning_info_Includes
|
||||
|
||||
/** @} */ // end of PROVISIONING
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_PROVISIONING_INFO_H_
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,249 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : sm_crypto.h
|
||||
* @brief : Header for sm_crypto.c file.
|
||||
* This file provides the interface for SM cryptographic operations.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _SM_CRYPTO_H_
|
||||
#define _SM_CRYPTO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup MCU_CRYPTO
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
/** @addtogroup SM_Crypto_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @def RAW_PRIV_KEY_BYTE_SIZE
|
||||
* @brief Size of raw private key in bytes.
|
||||
*/
|
||||
#define RAW_PRIV_KEY_BYTE_SIZE ((uint32_t)32)
|
||||
/**
|
||||
* @def SHA256_BYTE_SIZE
|
||||
* @brief Size of SHA-256 hash in bytes.
|
||||
*/
|
||||
#define SHA256_BYTE_SIZE ((uint32_t)32)
|
||||
/**
|
||||
* @def ECDSA_256_SIG_BYTE_SIZE
|
||||
* @brief Size of ECDSA-256 signature in bytes.
|
||||
*/
|
||||
#define ECDSA_256_SIG_BYTE_SIZE ((uint32_t)64)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup SM_Crypto_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @enum SM_Crypto_Error_t
|
||||
* @brief Error codes for SM cryptographic operations.
|
||||
*/
|
||||
typedef enum {
|
||||
SM_Crypto_OK = 0, /**< Operation successful */
|
||||
SM_Crypto_Error, /**< General error */
|
||||
SM_Crypto_HW_Error /**< Hardware error */
|
||||
} SM_Crypto_Error_t;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup SM_Crypto_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Initializes the cryptographic module.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_init(void);
|
||||
|
||||
/**
|
||||
* @brief Generates random bytes.
|
||||
* @param bytes Pointer to output buffer.
|
||||
* @param size Number of bytes to generate.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_genRandomBytes(uint8_t *bytes, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Generates a keypair and returns the public key.
|
||||
* @param pub Pointer to output public key buffer.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_genKeypair(uint8_t *pub);
|
||||
|
||||
/**
|
||||
* @brief Key Derivation Function RFC5869.
|
||||
* @param pZ Input keying material.
|
||||
* @param ZSize Size of input keying material.
|
||||
* @param pSalt Pointer to salt.
|
||||
* @param saltSize Size of salt.
|
||||
* @param pFixedInfo Pointer to fixed info.
|
||||
* @param fixedInfoSize Size of fixed info.
|
||||
* @param L Length of output keying material.
|
||||
* @param pOutput Pointer to output buffer.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_KDFRFC5869(const uint8_t* pZ, uint32_t ZSize,
|
||||
const uint8_t* pSalt, uint32_t saltSize,
|
||||
const uint8_t* pFixedInfo, uint32_t fixedInfoSize,
|
||||
uint32_t L, uint8_t* pOutput);
|
||||
|
||||
/**
|
||||
* @brief Computes SHA-1 hash.
|
||||
* @param input Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @param hash Pointer to output hash buffer.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha1(uint8_t *input, uint32_t inputSize, uint8_t *hash);
|
||||
|
||||
/**
|
||||
* @brief Computes SHA-256 hash.
|
||||
* @param input Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @param hash Pointer to output hash buffer.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha256(uint8_t *input, uint32_t inputSize, uint8_t *hash);
|
||||
|
||||
/**
|
||||
* @brief Starts SHA-256 computation.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha256_start(void);
|
||||
|
||||
/**
|
||||
* @brief Updates SHA-256 computation with new data.
|
||||
* @param input Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha256_update(const uint8_t *input, uint32_t inputSize);
|
||||
|
||||
/**
|
||||
* @brief Finishes SHA-256 computation and returns the hash.
|
||||
* @param hash Pointer to output hash buffer.
|
||||
* @param input Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha256_finish(uint8_t *hash, const uint8_t *input, uint32_t inputSize);
|
||||
|
||||
/**
|
||||
* @brief Signs data using ECDSA.
|
||||
* @param tbs Pointer to data to be signed.
|
||||
* @param tbsSize Size of data to be signed.
|
||||
* @param signature Pointer to output signature buffer.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sign(const uint8_t *tbs, uint32_t tbsSize, uint8_t *signature);
|
||||
|
||||
/**
|
||||
* @brief Performs ECDH key agreement.
|
||||
* @param pPublicKey Pointer to public key.
|
||||
* @param pSharedSecret Pointer to output shared secret.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_Ecdh(const uint8_t *pPublicKey, uint8_t *pSharedSecret);
|
||||
|
||||
/**
|
||||
* @brief Derives KDH key.
|
||||
* @param pZ Pointer to input keying material.
|
||||
* @param info Pointer to info data.
|
||||
* @param infoSize Size of info data.
|
||||
* @param pKdh Pointer to output KDH key.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_deriveKdh(const uint8_t *pZ, const uint8_t * info, uint32_t infoSize, uint8_t *pKdh);
|
||||
|
||||
/**
|
||||
* @brief Decrypts data using AES-256 GCM.
|
||||
* @param pKey Pointer to key.
|
||||
* @param pNonce Pointer to nonce.
|
||||
* @param pAad Pointer to additional authenticated data.
|
||||
* @param aadSize Size of AAD.
|
||||
* @param pPayload Pointer to encrypted payload.
|
||||
* @param payloadSize Size of payload.
|
||||
* @param pPlaintext Pointer to output plaintext buffer.
|
||||
* @param pTag Pointer to authentication tag.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_aes256GcmDecrypt(const uint8_t* pKey, const uint8_t* pNonce, const uint8_t* pAad, const uint32_t aadSize,
|
||||
const uint8_t* pPayload, const uint32_t payloadSize, uint8_t* pPlaintext, const uint8_t* pTag);
|
||||
|
||||
/**
|
||||
* @brief Encrypts data using AES-256 GCM.
|
||||
* @param pKey Pointer to key.
|
||||
* @param pNonce Pointer to nonce.
|
||||
* @param pAad Pointer to additional authenticated data.
|
||||
* @param aadSize Size of AAD.
|
||||
* @param pInput Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @param pOutput Pointer to output buffer.
|
||||
* @param pOutputSize Pointer to output size.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_aes256GcmEncrypt(const uint8_t* pKey, const uint8_t* pNonce, const uint8_t* pAad, const uint32_t aadSize,
|
||||
const uint8_t* pInput, const uint32_t inputSize, uint8_t* pOutput, uint32_t* pOutputSize);
|
||||
|
||||
/**
|
||||
* @brief Verifies a signature using ECDSA.
|
||||
* @param pPublicKey Pointer to public key.
|
||||
* @param tbs Pointer to data to be verified.
|
||||
* @param tbsSize Size of data to be verified.
|
||||
* @param signature Pointer to signature.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_verify(const uint8_t *pPublicKey, const uint8_t *tbs, const uint32_t tbsSize, const uint8_t *signature);
|
||||
|
||||
/**
|
||||
* @brief Gets the certificate.
|
||||
* @param certificate Pointer to output certificate buffer.
|
||||
* @param certificateSize Pointer to output certificate size.
|
||||
* @return Error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_getCertificate(uint8_t *certificate, uint32_t *certificateSize);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _SM_CRYPTO_H_
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : sm_crypto_mcu.h
|
||||
* @brief : Header for sm_crypto_mcu.c file.
|
||||
* This file provides the interface for SM cryptographic operations on MCU platforms.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _SM_CRYPTO_MCU_H_
|
||||
#define _SM_CRYPTO_MCU_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup MCU_CRYPTO
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "sm_crypto.h"
|
||||
#if defined(STM32U545xx) || defined(STM32U585xx)
|
||||
#include "stm32u5xx_hal.h"
|
||||
#elif defined(STM32U385xx)
|
||||
#include "stm32u3xx_hal.h"
|
||||
#elif defined(STM32WBA52xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx)
|
||||
#include "stm32wbaxx_hal.h"
|
||||
#else
|
||||
#error "product not supported"
|
||||
#endif
|
||||
|
||||
/** @addtogroup SM_crypto_mcu_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/**
|
||||
* @def MAX_FIXED_INFO_SIZE
|
||||
* @brief Maximum size for fixed info buffer in bytes.
|
||||
*/
|
||||
#define MAX_FIXED_INFO_SIZE ((uint32_t)256)
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup SM_crypto_mcu_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Initializes cryptographic hardware modules for MCU.
|
||||
* @param rng Pointer to RNG handle.
|
||||
* @param pka Pointer to PKA handle.
|
||||
* @param hash Pointer to HASH handle.
|
||||
* @param cryp Pointer to CRYP handle.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_initCryptoMCU(RNG_HandleTypeDef *rng, PKA_HandleTypeDef *pka, HASH_HandleTypeDef *hash, CRYP_HandleTypeDef *cryp);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _SM_CRYPTO_MCU_H_
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : sm_crypto_stsafe.h
|
||||
* @brief : Header for sm_crypto_stsafe.c file.
|
||||
* This file provides the interface for SM cryptographic operations using STSAFE.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _SM_CRYPTO_STSAFE_H_
|
||||
#define _SM_CRYPTO_STSAFE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup MCU_CRYPTO
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "sm_crypto.h"
|
||||
#if defined(STM32U585xx)
|
||||
#include "stm32u5xx_hal.h"
|
||||
#elif defined(STM32WBA52xx) || defined(STM32WBA65xx)
|
||||
#include "stm32wbaxx_hal.h"
|
||||
#else
|
||||
#error "product not supported"
|
||||
#endif
|
||||
#include "stselib.h"
|
||||
|
||||
/** @addtogroup SM_crypto_stsafe_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Initializes cryptographic operations using STSAFE.
|
||||
* @param pairingdone Pointer to a flag indicating if pairing is done.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_initCryptoStSafe(uint8_t *pairingdone);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _SM_CRYPTO_STSAFE_H_
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : stepup_mgr.h
|
||||
* @brief : Header for stepup_mgr.c file.
|
||||
* This file declares the interface for the step-up manager functionality.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STEPUP_MGR_H
|
||||
#define __STEPUP_MGR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup STEPUP_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ACWG_Security.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
/** @addtogroup STEPUP_MGR_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
//typedef struct _access_mngr_data
|
||||
//{
|
||||
// uint8_t access_credential_PuBK_last[64];
|
||||
//}
|
||||
//access_mngr_data_t;
|
||||
//
|
||||
//extern access_mngr_data_t access_mngr_data;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STEPUP_MGR_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STEPUP_MGR_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STEPUP_MGR_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STEPUP_MGR_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Requests a step-up operation.
|
||||
* @param acwgctx Pointer to the session context.
|
||||
* @param buf Pointer to the buffer for request data.
|
||||
* @param len Pointer to the length of the buffer.
|
||||
* @return Status code.
|
||||
*/
|
||||
uint8_t stepup_request(ACWG_SessionContext_t *acwgctx, uint8_t *stringAccElem, uint32_t AccElemLen, uint8_t *stringRevElem, uint32_t RevElemLen, uint8_t *buf, uint32_t *len);
|
||||
|
||||
/**
|
||||
* @brief Pushes step-up data to the buffer.
|
||||
* @param buf Pointer to the data buffer.
|
||||
* @param len Length of the data.
|
||||
* @return Status code.
|
||||
*/
|
||||
uint8_t stepup_pushdata(uint8_t *buf, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief Processes the step-up operation.
|
||||
* @param acwgctx Pointer to the session context.
|
||||
* @return Status code.
|
||||
*/
|
||||
uint8_t stepup_process(ACWG_SessionContext_t *acwgctx);
|
||||
|
||||
/**
|
||||
* @brief Checks the endpoint public key for step-up.
|
||||
* @param endp_PubK Pointer to the endpoint public key.
|
||||
* @return Status code.
|
||||
*/
|
||||
uint8_t stepup_CheckEndpointPubK(uint8_t *endp_PubK);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STEPUP_MGR_H */
|
||||
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : tlv.h
|
||||
* @brief : Header for TLV (Tag-Length-Value) utilities.
|
||||
* This file contains type definitions and function
|
||||
* prototypes for TLV operations.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _TLV_H_
|
||||
#define _TLV_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup TLV_UTILITIES
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/** @addtogroup TLV_Utilities_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/**
|
||||
* @struct tlv_t
|
||||
* @brief Structure representing a TLV (Tag-Length-Value) element.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t tag; /**< Tag identifier */
|
||||
uint8_t *value; /**< Pointer to value data */
|
||||
uint32_t length; /**< Length of value data */
|
||||
} tlv_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum tlvStatus_t
|
||||
* @brief Status codes for TLV operations.
|
||||
*/
|
||||
typedef enum {
|
||||
TLV_SUCCESS, /**< Operation successful */
|
||||
TLV_ERROR_SHORT_PAYLOAD, /**< Payload too short */
|
||||
TLV_ERROR_INVALID_LENGTH, /**< Invalid length */
|
||||
TLV_ERROR_SHORT_BUFFER, /**< Buffer too short */
|
||||
TLV_ERROR_TAG_NOT_FOUND /**< Tag not found */
|
||||
} tlvStatus_t;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup TLV_Utilities_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/**
|
||||
* @brief Extracts one TLV element from a buffer.
|
||||
* @param tlvBuf Pointer to the buffer pointer.
|
||||
* @param tlvLength Pointer to the buffer length.
|
||||
* @param tlv Pointer to the TLV structure to fill.
|
||||
* @return Status code.
|
||||
*/
|
||||
tlvStatus_t getOneTlv(uint8_t **tlvBuf, uint32_t *tlvLength, tlv_t *tlv);
|
||||
|
||||
/**
|
||||
* @brief Appends a TLV element to a buffer.
|
||||
* @param inputBuffer Pointer to the buffer pointer.
|
||||
* @param inputBufferLen Pointer to the buffer length.
|
||||
* @param tlv Pointer to the TLV structure to append.
|
||||
* @return Status code.
|
||||
*/
|
||||
tlvStatus_t appendTLV(uint8_t **inputBuffer, uint32_t *inputBufferLen, const tlv_t *tlv);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TLV_H_ */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,550 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : tlwrapper.h
|
||||
* @brief : Header for tlwrapper.c file.
|
||||
* This file contains the type definitions and function
|
||||
* prototypes for the tlwrapper module.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __TLWRAPPER_H
|
||||
#define __TLWRAPPER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ACWG_Security.h"
|
||||
#include "stdbool.h"
|
||||
#include "custom_uwb.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup WRAPPER_UTILITY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_Utils_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum tlw_error_e
|
||||
* @brief Error codes for TLWrapper operations.
|
||||
*/
|
||||
typedef enum _tlw_error
|
||||
{
|
||||
TLW_ERROR_NONE = 0, /**< No error */
|
||||
TLW_NEW_OUTPUT, /**< New output available */
|
||||
TLW_NO_PREPARE_NEEDED, /**< No preparation needed */
|
||||
TLW_ERROR_FAST, /**< Fast error */
|
||||
TLW_NEED_GET_RESPONSE, /**< Need to get response */
|
||||
TLW_NEED_AUTH1, /**< Need authentication 1 */
|
||||
TLW_NEED_LOAD_CERT, /**< Need to load certificate */
|
||||
TLW_BUSY, /**< Busy state */
|
||||
TLW_FAIL_GENERATE, /**< Generation failed */
|
||||
TLW_FAIL_PROCESS, /**< Processing failed */
|
||||
TLW_FAIL_GENERIC, /**< Generic failure */
|
||||
TLW_FAIL_TIMEOUT, /**< Timeout failure */
|
||||
TLW_END /**< End of error codes */
|
||||
}
|
||||
tlw_error_e;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup NFC
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_Nfc_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum tlw_state_nfc_e
|
||||
* @brief NFC state machine states for TLWrapper.
|
||||
*/
|
||||
typedef enum _tlw_state_nfc
|
||||
{
|
||||
TLW_STATE_NFC_PREPARE_SELECT = 0,
|
||||
TLW_STATE_NFC_PROCESS_SELECT,
|
||||
TLW_STATE_NFC_PREPARE_AUTH0,
|
||||
TLW_STATE_NFC_PROCESS_AUTH0,
|
||||
TLW_STATE_NFC_PREPARE_LOAD_CERT,
|
||||
TLW_STATE_NFC_PROCESS_LOAD_CERT,
|
||||
TLW_STATE_NFC_PREPARE_AUTH1,
|
||||
TLW_STATE_NFC_PROCESS_AUTH1,
|
||||
TLW_STATE_NFC_PREPARE_AUTH1_CHAINED,
|
||||
TLW_STATE_NFC_PROCESS_AUTH1_CHAINED,
|
||||
TLW_STATE_NFC_PREPARE_SELECT_STEPUP,
|
||||
TLW_STATE_NFC_PROCESS_SELECT_STEPUP,
|
||||
TLW_STATE_NFC_PREPARE_STEPUP,
|
||||
TLW_STATE_NFC_PROCESS_STEPUP,
|
||||
TLW_STATE_NFC_PREPARE_GET_RESPONSE,
|
||||
TLW_STATE_NFC_PREPARE_EXCHANGE,
|
||||
TLW_STATE_NFC_PROCESS_EXCHANGE,
|
||||
|
||||
TLW_STATE_NFC_PREPARE_CONTROL_FLOW,
|
||||
TLW_STATE_NFC_PROCESS_CONTROL_FLOW,
|
||||
|
||||
TLW_STATE_NFC_PREPARE_READER_STATUS_EXCHANGE,
|
||||
TLW_STATE_NFC_PROCESS_READER_STATUS_EXCHANGE,
|
||||
TLW_STATE_NFC_ERROR,
|
||||
TLW_STATE_NFC_END
|
||||
}
|
||||
tlw_state_nfc_e;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup BLE_UWB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_BleUwb_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum tlw_state_ble_e
|
||||
* @brief BLE state machine states for TLWrapper.
|
||||
*/
|
||||
typedef enum _tlw_state_ble
|
||||
{
|
||||
TLW_STATE_BLE_PREPARE_SELECT = 0,
|
||||
TLW_STATE_BLE_PROCESS_SELECT,
|
||||
TLW_STATE_BLE_PREPARE_AUTH0,
|
||||
TLW_STATE_BLE_PROCESS_AUTH0,
|
||||
TLW_STATE_BLE_PREPARE_LOAD_CERT,
|
||||
TLW_STATE_BLE_PROCESS_LOAD_CERT,
|
||||
TLW_STATE_BLE_PREPARE_AUTH1,
|
||||
TLW_STATE_BLE_PROCESS_AUTH1,
|
||||
|
||||
TLW_STATE_BLE_PREPARE_STEPUP,
|
||||
TLW_STATE_BLE_PROCESS_STEPUP,
|
||||
TLW_STATE_BLE_PREPARE_GET_RESPONSE,
|
||||
|
||||
TLW_STATE_BLE_PREPARE_EXCHANGE,
|
||||
TLW_STATE_BLE_PROCESS_EXCHANGE,
|
||||
TLW_STATE_BLE_PREPARE_AP_COMPLETED,
|
||||
TLW_STATE_BLE_PROCESS_AP_COMPLETED,
|
||||
|
||||
TLW_STATE_BLE_PROCESS_TIME_SYNC,
|
||||
TLW_STATE_BLE_PROCESS_INITIATE_RANGING_SESSION,
|
||||
TLW_STATE_BLE_PREPARE_M1,
|
||||
TLW_STATE_BLE_PROCESS_M2,
|
||||
TLW_STATE_BLE_PREPARE_M3,
|
||||
TLW_STATE_BLE_PROCESS_M4,
|
||||
|
||||
// Reader initiated suspension
|
||||
TLW_STATE_BLE_PREPARE_SUSPEND_RQU,
|
||||
TLW_STATE_BLE_PROCESS_SUSPEND_RSP,
|
||||
|
||||
// Device initiated suspension
|
||||
TLW_STATE_BLE_PREPARE_SUSPEND_RSP,
|
||||
TLW_STATE_BLE_PROCESS_SUSPEND,
|
||||
|
||||
// Reader impose suspension
|
||||
TLW_STATE_BLE_PREPARE_EVENT_RANGING_SUSPENDED,
|
||||
// Device impose suspension
|
||||
TLW_STATE_BLE_PROCESS_EVENT_RANGING_SUSPENDED,
|
||||
|
||||
|
||||
// Device trigger resumption
|
||||
TLW_STATE_BLE_PROCESS_EVENT_RANGING_RESUME,
|
||||
TLW_STATE_BLE_PROCESS_RESUME_RSP,
|
||||
|
||||
|
||||
TLW_STATE_BLE_PREPARE_RANGING,
|
||||
TLW_STATE_BLE_EXECUTE_RANGING,
|
||||
TLW_STATE_BLE_HANDLE_SUSPEND,
|
||||
TLW_STATE_BLE_HANDLE_RESUME,
|
||||
// Reader initiated resumption
|
||||
TLW_STATE_BLE_PREPARE_RESUME_RQU,
|
||||
TLW_STATE_BLE_HANDLE_DOOR_LOCK_OPERATION,
|
||||
|
||||
TLW_STATE_BLE_PREPARE_READER_STATUS_EXCHANGE,
|
||||
TLW_STATE_BLE_PROCESS_READER_STATUS_EXCHANGE,
|
||||
|
||||
TLW_STATE_BLE_PREPARE_NOTIFICATION_EVENT_ERR,
|
||||
|
||||
TLW_STATE_BLE_ERROR,
|
||||
TLW_STATE_BLE_END
|
||||
}
|
||||
tlw_state_ble_e;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup NFC
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_Nfc_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @struct tlw_SM_nfc_t
|
||||
* @brief Structure for NFC state machine context in TLWrapper.
|
||||
*/
|
||||
typedef struct _tlwrapper_SM_nfc
|
||||
{
|
||||
uint8_t flags_nfc;
|
||||
tlw_state_nfc_e state;
|
||||
ACWG_SessionContext_t *ctx;
|
||||
uint8_t *input;
|
||||
uint16_t *input_len;
|
||||
uint8_t output[512];
|
||||
uint16_t output_len;
|
||||
ACWG_Status_t (*callback)(ACWG_SessionContext_t *ctx);
|
||||
}
|
||||
tlw_SM_nfc_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup WRAPPER_UTILITY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_Utils_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum General_Error_Attribute_ID_e
|
||||
* @brief General error attribute IDs for BLE operations.
|
||||
*/
|
||||
typedef enum _General_Error_Attribute_ID
|
||||
{
|
||||
GENERAL_UNKNOWN_ERROR = 0U,
|
||||
GENERAL_RESOURCE_UNAVAILABLE = 1U,
|
||||
GENERAL_WRONG_PARAMETERS = 2U,
|
||||
GENERAL_URSK_UNAVAILABLE = 3U
|
||||
}
|
||||
General_Error_Attribute_ID_e;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup BLE_UWB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_BleUwb_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @struct tlw_SM_ble_t
|
||||
* @brief Structure for BLE state machine context in TLWrapper.
|
||||
*/
|
||||
typedef struct _tlwrapper_SM_ble
|
||||
{
|
||||
bool isBleOnly;
|
||||
General_Error_Attribute_ID_e general_error_ble;
|
||||
uint8_t flags_ble;
|
||||
tlw_state_ble_e state;
|
||||
ACWG_SessionContext_t *ctx;
|
||||
uint8_t *input;
|
||||
uint16_t *input_len;
|
||||
uint8_t output[300];
|
||||
uint16_t output_len;
|
||||
ACWG_Status_t (*callback)(ACWG_SessionContext_t *ctx);
|
||||
uint8_t (*sendData)(uint8_t *buff, uint16_t len);
|
||||
uint8_t (*disconnect)(void);
|
||||
}
|
||||
tlw_SM_ble_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup WRAPPER_UTILITY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_Utils_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @struct access_mngr_data_t
|
||||
* @brief Structure for access manager data.
|
||||
*/
|
||||
typedef struct _access_mngr_data
|
||||
{
|
||||
uint8_t access_credential_PuBK_last[64];
|
||||
}
|
||||
access_mngr_data_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup NFC
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_Nfc_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Global NFC state machine context.
|
||||
*/
|
||||
extern tlw_SM_nfc_t nfc_SM;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup BLE_UWB
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup TLWrapper_BleUwb_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Global BLE state machine context.
|
||||
*/
|
||||
extern tlw_SM_ble_t ble_SM;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup WRAPPER_UTILITY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_Utils_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Global access manager data.
|
||||
*/
|
||||
extern access_mngr_data_t access_mngr_data;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
|
||||
/** @addtogroup NFC
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_Nfc_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the NFC state machine.
|
||||
* @param ctx Pointer to session context.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_init_nfc(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Reloads the NFC state machine.
|
||||
* @param ctx Pointer to session context.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_reload_nfc(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Prepares the NFC state machine for operation.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_prepare_nfc(void);
|
||||
|
||||
/**
|
||||
* @brief Processes the NFC state machine.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_process_nfc(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup BLE_UWB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_BleUwb_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the BLE state machine.
|
||||
* @param ctx Pointer to session context.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_init_ble(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Reloads the BLE state machine.
|
||||
* @param ctx Pointer to session context.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_reload_ble(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Prepares the BLE state machine for operation.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_prepare_ble(void);
|
||||
|
||||
/**
|
||||
* @brief Processes the BLE state machine.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_process_ble(void);
|
||||
|
||||
/**
|
||||
* @brief Handles received BLE data and sends response.
|
||||
* @param data Pointer to received data buffer.
|
||||
* @param len Pointer to length of received data.
|
||||
* @param sendData_fn Function pointer to send data.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_ble_receivedData(uint8_t *data, uint8_t *len, uint8_t (*sendData_fn)(uint8_t *, uint16_t));
|
||||
|
||||
/**
|
||||
* @brief Steps the BLE state machine.
|
||||
* @return Error code.
|
||||
*/
|
||||
tlw_error_e tlw_ble_SM_step(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the current UWB session ID.
|
||||
* @return UWB session ID value.
|
||||
*/
|
||||
uint32_t getUwbSessionId( void );
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup WRAPPER_UTILITY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TLWrapper_Utils_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Checks the endpoint public key.
|
||||
* @param endpointPub Pointer to context that contains endpoint public key.
|
||||
* @return Status code.
|
||||
*/
|
||||
uint8_t tlw_CheckEndpointKey(ACWG_SessionContext_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Gets the last endpoint public key.
|
||||
* @return Pointer to the last endpoint public key.
|
||||
*/
|
||||
uint8_t* tlw_GetLastEndpointKey(void);
|
||||
|
||||
/**
|
||||
* @brief Sets the access element string.
|
||||
* @param AccElmStr Pointer to the access element string.
|
||||
*/
|
||||
void tlw_SetAccessElementString(uint8_t *AccElmStr);
|
||||
|
||||
/**
|
||||
* @brief Gets the access element string.
|
||||
* @return Pointer to the access element string.
|
||||
*/
|
||||
uint8_t *tlw_GetAccessElementString(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TLWRAPPER_H */
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,244 @@
|
||||
#include "custom_uwb.h"
|
||||
#include "main.h"
|
||||
#include "app_aliro.h"
|
||||
|
||||
#define NUM_ITEMS 2
|
||||
#define DISTANCE_OPEN 40
|
||||
#define DEFAULT_FAR_DISTANCE 1000
|
||||
|
||||
#define TIME_CHECK_RANGING 5000
|
||||
|
||||
uint32_t nMeasures[NUM_ITEMS] = {0};
|
||||
uint32_t mean_dist_cm = 0;
|
||||
|
||||
|
||||
void responderReset(void)
|
||||
{
|
||||
for(uint32_t i=0;i<NUM_ITEMS;i++)nMeasures[i]=1000;
|
||||
mean_dist_cm = DEFAULT_FAR_DISTANCE;
|
||||
}
|
||||
|
||||
void Initiate_uwb_ctx(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
// responderReset();
|
||||
// HAL_Delay(10);
|
||||
// send_frame(...);
|
||||
|
||||
}
|
||||
|
||||
void Fill_uwb_M1(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
// UNUSED( ctx );
|
||||
|
||||
// force UWB Configuration Identifier to 0x0001
|
||||
uint8_t AliroUWB_Configuration_Identifier[] = { 0x00, 0x00 };
|
||||
memcpy(ctx->uwb_ctx.UWB_Configuration_Identifier, AliroUWB_Configuration_Identifier, sizeof(AliroUWB_Configuration_Identifier));
|
||||
|
||||
memcpy(ctx->uwb_ctx.UWB_Session_Identifier, &ctx->transId[12], 4);
|
||||
|
||||
// force pulse shape combo to 0x01
|
||||
ctx->uwb_ctx.Pulse_Shape_Combo = 0x01;
|
||||
|
||||
// force channel bitmask to 0x01 (channel 5)
|
||||
ctx->uwb_ctx.Channel_Bitmask = 0x01;
|
||||
|
||||
ctx->uwb_ctx.RAN_Multiplier = 0x02;
|
||||
ctx->uwb_ctx.Number_Chaps_per_Slot = 0x0C;
|
||||
ctx->uwb_ctx.Number_Responders_Nodes = 0x01;
|
||||
|
||||
ctx->uwb_ctx.Number_Slots_per_Round = 6;
|
||||
|
||||
ctx->uwb_ctx.MAC_Mode = 0x00;
|
||||
|
||||
}
|
||||
|
||||
void Fill_uwb_M3(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
|
||||
uint8_t SYNC_Code_Index_Btmsk[SYNC_CODE_INDEX_BITMASK_LEN_BYTES] = {0x00, 0x00, 0x0F, 0x00};
|
||||
memcpy(ctx->uwb_ctx.SYNC_Code_Index_Bitmask, SYNC_Code_Index_Btmsk, SYNC_CODE_INDEX_BITMASK_LEN_BYTES);
|
||||
}
|
||||
|
||||
void Handle_uwb_M2(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
}
|
||||
|
||||
void Handle_uwb_M4(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
}
|
||||
|
||||
|
||||
void Prepare_ranging_init(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
}
|
||||
|
||||
void Prepare_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout)
|
||||
{
|
||||
// if(configurationComplete())
|
||||
// {
|
||||
// *timeout = 1;//set timeout to a low value to exit loop in the main function
|
||||
// }
|
||||
}
|
||||
|
||||
static uint32_t nTimeoutCheckRanging = 0;
|
||||
void Execute_ranging_init(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
nTimeoutCheckRanging = HAL_GetTick() + TIME_CHECK_RANGING;
|
||||
//TODO: send start session command
|
||||
}
|
||||
|
||||
void Execute_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
static uint8_t is_ranging_validate = 0;
|
||||
|
||||
|
||||
//TODO: process mean_dist_cm
|
||||
if ((!is_ranging_validate) && (mean_dist_cm == DEFAULT_FAR_DISTANCE))
|
||||
{
|
||||
if (HAL_GetTick() > nTimeoutCheckRanging)
|
||||
{
|
||||
*timeout = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
is_ranging_validate = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(mean_dist_cm < DISTANCE_OPEN)
|
||||
{
|
||||
*timeout = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Close_ranging_init(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
}
|
||||
|
||||
void Close_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
//TODO: send stop and deinit session commands
|
||||
|
||||
{
|
||||
*timeout = 1;//set timeout to a low value to exit loop in the main function
|
||||
}
|
||||
}
|
||||
|
||||
void Suspend_ranging_init(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
}
|
||||
|
||||
void Suspend_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
|
||||
//TODO: send stop and deinit session commands
|
||||
*timeout = 1;//set timeout to a low value to exit loop in the main function
|
||||
}
|
||||
|
||||
void Resume_ranging_init(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
}
|
||||
|
||||
void Resume_ranging_loop(ACWG_SessionContext_t *ctx, uint32_t *timeout)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
|
||||
*timeout = 1;//set timeout to a low value to exit loop in the main function
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t Handle_distance_result(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
|
||||
if(mean_dist_cm < DISTANCE_OPEN)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Handle_lock_actuation(ACWG_SessionContext_t *ctx)
|
||||
{
|
||||
UNUSED( ctx );
|
||||
PLATFORM_LOG(VERB_VERBOSE, "\r\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Distance MEAN: %u cm\r\n\n", mean_dist_cm);
|
||||
if(mean_dist_cm < DISTANCE_OPEN)
|
||||
{
|
||||
PLATFORM_LOG(VERB_VERBOSE, "OPEN\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " OOOOOOOOO PPPPPPPPPPPPPPPPP EEEEEEEEEEEEEEEEEEEEEENNNNNNNN NNNNNNNN\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " OO:::::::::OO P::::::::::::::::P E::::::::::::::::::::EN:::::::N N::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " OO:::::::::::::OO P::::::PPPPPP:::::P E::::::::::::::::::::EN::::::::N N::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O:::::::OOO:::::::OPP:::::P P:::::PEE::::::EEEEEEEEE::::EN:::::::::N N::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O::::::O O::::::O P::::P P:::::P E:::::E EEEEEEN::::::::::N N::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O:::::O O:::::O P::::P P:::::P E:::::E N:::::::::::N N::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O:::::O O:::::O P::::PPPPPP:::::P E::::::EEEEEEEEEE N:::::::N::::N N::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O:::::O O:::::O P:::::::::::::PP E:::::::::::::::E N::::::N N::::N N::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O:::::O O:::::O P::::PPPPPPPPP E:::::::::::::::E N::::::N N::::N:::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O:::::O O:::::O P::::P E::::::EEEEEEEEEE N::::::N N:::::::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O:::::O O:::::O P::::P E:::::E N::::::N N::::::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O::::::O O::::::O P::::P E:::::E EEEEEEN::::::N N:::::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "O:::::::OOO:::::::OPP::::::PP EE::::::EEEEEEEE:::::EN::::::N N::::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " OO:::::::::::::OO P::::::::P E::::::::::::::::::::EN::::::N N:::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " OO:::::::::OO P::::::::P E::::::::::::::::::::EN::::::N N::::::N\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " OOOOOOOOO PPPPPPPPPP EEEEEEEEEEEEEEEEEEEEEENNNNNNNN NNNNNNN\r\n");
|
||||
|
||||
AliroPort_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
PLATFORM_LOG(VERB_VERBOSE, "CLOSE\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " CCCCCCCCCCCCCLLLLLLLLLLL OOOOOOOOO SSSSSSSSSSSSSSS EEEEEEEEEEEEEEEEEEEEEE\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " CCC::::::::::::CL:::::::::L OO:::::::::OO SS:::::::::::::::SE::::::::::::::::::::E\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " CC:::::::::::::::CL:::::::::L OO:::::::::::::OO S:::::SSSSSS::::::SE::::::::::::::::::::E\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " C:::::CCCCCCCC::::CLL:::::::LL O:::::::OOO:::::::OS:::::S SSSSSSSEE::::::EEEEEEEEE::::E\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " C:::::C CCCCCC L:::::L O::::::O O::::::OS:::::S E:::::E EEEEEE\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "C:::::C L:::::L O:::::O O:::::OS:::::S E:::::E \r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "C:::::C L:::::L O:::::O O:::::O S::::SSSS E::::::EEEEEEEEEE \r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "C:::::C L:::::L O:::::O O:::::O SS::::::SSSSS E:::::::::::::::E \r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "C:::::C L:::::L O:::::O O:::::O SSS::::::::SS E:::::::::::::::E \r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "C:::::C L:::::L O:::::O O:::::O SSSSSS::::S E::::::EEEEEEEEEE \r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, "C:::::C L:::::L O:::::O O:::::O S:::::S E:::::E \r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " C:::::C CCCCCC L:::::L LLLLLLO::::::O O::::::O S:::::S E:::::E EEEEEE\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " C:::::CCCCCCCC::::CLL:::::::LLLLLLLLL:::::LO:::::::OOO:::::::OSSSSSSS S:::::SEE::::::EEEEEEEE:::::E\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " CC:::::::::::::::CL::::::::::::::::::::::L OO:::::::::::::OO S::::::SSSSSS:::::SE::::::::::::::::::::E\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " CCC::::::::::::CL::::::::::::::::::::::L OO:::::::::OO S:::::::::::::::SS E::::::::::::::::::::E\r\n");
|
||||
// PLATFORM_LOG(VERB_VERBOSE, " CCCCCCCCCCCCCLLLLLLLLLLLLLLLLLLLLLLLL OOOOOOOOO SSSSSSSSSSSSSSS EEEEEEEEEEEEEEEEEEEEEE\r\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void UWB_HW_init( void )
|
||||
{
|
||||
Set_timeout_prepare_ranging( TIMEOUT_PREPARE_RANGING_DEFAULT );
|
||||
Set_timeout_execute_ranging( TIMEOUT_EXECUTE_RANGING_DEFAULT );
|
||||
Set_timeout_suspend_ranging( TIMEOUT_SUSPEND_RANGING_DEFAULT );
|
||||
Set_timeout_resume_ranging( TIMEOUT_RESUME_RANGING_DEFAULT );
|
||||
Set_timeout_door_operation( TIMEOUT_DOOR_OPERATION_DEFAULT );
|
||||
|
||||
responderReset();
|
||||
HAL_Delay(10);
|
||||
}
|
||||
|
||||
void UWB_HW_loop( void )
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : flash_mng.c
|
||||
* @brief : Flash management functions
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "flash_mng.h"
|
||||
#if defined(STM32WBA52xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx)
|
||||
#include "app_ble.h"
|
||||
#include "flash_manager.h"
|
||||
#define FLASH_MANAGER_ENABLE 1
|
||||
#endif //defined(STM32WBA52xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx)
|
||||
|
||||
#if FLASH_MANAGER_ENABLE
|
||||
#define WRITE_BUF_SZ (1400)
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static FM_CallbackNode_t Aliro_FlashCallback;
|
||||
static uint8_t writeBuf[WRITE_BUF_SZ];
|
||||
static uint32_t writeBufSz;
|
||||
static uint32_t writeBufAddr;
|
||||
|
||||
/* Callback Definition ------------------------------------------------------*/
|
||||
void Aliro_FlashManagerCallback(FM_FlashOp_Status_t Status)
|
||||
{
|
||||
FM_Cmd_Status_t fm_result;
|
||||
if(Status == FM_OPERATION_AVAILABLE)
|
||||
{
|
||||
Aliro_FlashCallback.Callback = Aliro_FlashManagerCallback;
|
||||
fm_result = FM_Write((uint32_t*)writeBuf, (uint32_t *)writeBufAddr, writeBufSz, &Aliro_FlashCallback);
|
||||
if(fm_result == FM_BUSY)
|
||||
{
|
||||
//TODO : appropriate error handling
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif //FLASH_MANAGER_ENABLE
|
||||
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/**
|
||||
* @brief Gets the page of a given address
|
||||
* @param Addr: Address of the FLASH Memory
|
||||
* @retval The page of a given address
|
||||
*/
|
||||
static uint32_t GetPage(uint32_t Addr)
|
||||
{
|
||||
return (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;;
|
||||
}
|
||||
|
||||
|
||||
/* Public functions -----------------------------------------------*/
|
||||
flashOpStatus_e EraseFlash(uint32_t nAddress, uint32_t nBytes)
|
||||
{
|
||||
FLASH_EraseInitTypeDef EraseInitStruct;
|
||||
uint32_t FirstPage = 0, NbOfPages = 0;
|
||||
uint32_t PageError = 0;
|
||||
|
||||
UNUSED(EraseInitStruct);
|
||||
UNUSED(PageError);
|
||||
|
||||
/* Erase the user Flash area
|
||||
(area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
|
||||
|
||||
/* Get the 1st page to erase */
|
||||
FirstPage = GetPage(nAddress);
|
||||
|
||||
/* Get the number of pages to erase from 1st page */
|
||||
NbOfPages = GetPage(nAddress + nBytes) - FirstPage + 1;
|
||||
|
||||
/* Fill EraseInit structure*/
|
||||
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
EraseInitStruct.Page = FirstPage;
|
||||
EraseInitStruct.NbPages = NbOfPages;
|
||||
|
||||
|
||||
|
||||
#if FLASH_MANAGER_ENABLE
|
||||
FM_Cmd_Status_t fm_result;
|
||||
|
||||
fm_result = FM_Erase(FirstPage, NbOfPages, NULL);
|
||||
if (fm_result == FM_BUSY)
|
||||
{
|
||||
return FLASH_OP_BUSY;
|
||||
}
|
||||
else if (fm_result == FM_ERROR)
|
||||
{
|
||||
return FLASH_OP_ERROR;
|
||||
}
|
||||
|
||||
#else //FLASH_MANAGER_ENABLE
|
||||
|
||||
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
|
||||
{
|
||||
/*
|
||||
Error occurred while page erase.
|
||||
User can add here some code to deal with this error.
|
||||
PageError will contain the faulty page and then to know the code error on this page,
|
||||
user can call function 'HAL_FLASH_GetError()'
|
||||
*/
|
||||
/* Infinite loop */
|
||||
while (1)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
#endif //FLASH_MANAGER_ENABLE
|
||||
return FLASH_OP_OK;
|
||||
}
|
||||
|
||||
flashOpStatus_e EraseWriteToFlash(void *datapointer, uint32_t nBytes, uint32_t nAddress)
|
||||
{
|
||||
flashOpStatus_e result = FLASH_OP_OK;
|
||||
|
||||
/* Disable instruction cache prior to internal cacheable memory update */
|
||||
#ifndef STM32WBAxx_LL_ICACHE_H
|
||||
if (HAL_ICACHE_Disable() != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
#else //STM32WBAxx_LL_ICACHE_H
|
||||
uint32_t tickstart;
|
||||
|
||||
/* Make sure BSYENDF is reset before to disable the instruction cache */
|
||||
/* as it automatically starts a cache invalidation procedure */
|
||||
LL_ICACHE_ClearFlag_BSYEND();
|
||||
|
||||
LL_ICACHE_Disable();
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for instruction cache being disabled */
|
||||
while (LL_ICACHE_IsEnabled())
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > 1U)
|
||||
{
|
||||
/* New check to avoid false timeout detection in case of preemption */
|
||||
if (LL_ICACHE_IsEnabled())
|
||||
{
|
||||
// status = HAL_TIMEOUT;
|
||||
//break;
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // STM32WBAxx_LL_ICACHE_H
|
||||
|
||||
|
||||
#if FLASH_MANAGER_ENABLE
|
||||
|
||||
result = EraseFlash(nAddress, nBytes);
|
||||
|
||||
if (result != FLASH_OP_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
FM_Cmd_Status_t fm_result;
|
||||
|
||||
int32_t int32_size = 0;
|
||||
int32_size = (int32_t)(nBytes/4);
|
||||
if (nBytes%4)
|
||||
{
|
||||
int32_size++;
|
||||
}
|
||||
|
||||
if(nBytes > WRITE_BUF_SZ)
|
||||
{
|
||||
result = FLASH_OP_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
writeBufAddr = nAddress;
|
||||
writeBufSz = int32_size;
|
||||
memcpy(writeBuf, datapointer, nBytes);
|
||||
result = FLASH_OP_BUSY;
|
||||
}
|
||||
|
||||
Aliro_FlashCallback.Callback = Aliro_FlashManagerCallback;
|
||||
fm_result = FM_Write((uint32_t*)writeBuf, (uint32_t *)writeBufAddr, writeBufSz, &Aliro_FlashCallback);
|
||||
if(fm_result == FM_BUSY)
|
||||
{
|
||||
if(nBytes > WRITE_BUF_SZ)
|
||||
{
|
||||
result = FLASH_OP_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = FLASH_OP_BUSY;
|
||||
}
|
||||
}
|
||||
else if (fm_result == FM_ERROR)
|
||||
{
|
||||
result = FLASH_OP_ERROR;
|
||||
}
|
||||
result = FLASH_OP_OK;
|
||||
}
|
||||
|
||||
#else //FLASH_MANAGER_ENABLE
|
||||
|
||||
/* Unlock the Flash to enable the flash control register access *************/
|
||||
HAL_FLASH_Unlock();
|
||||
/* Program the user Flash area word by word
|
||||
(area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
|
||||
|
||||
result = EraseFlash(nAddress, nBytes);
|
||||
|
||||
uint32_t AddressOffset = 0;
|
||||
|
||||
while (AddressOffset < nBytes)
|
||||
{
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_QUADWORD, nAddress + AddressOffset, ((uint32_t)datapointer + AddressOffset)) == HAL_OK)
|
||||
{
|
||||
AddressOffset = AddressOffset + 16; /* increment to next quad word*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Error occurred while writing data in Flash memory.
|
||||
User can add here some code to deal with this error */
|
||||
while (1)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Lock the Flash to disable the flash control register access (recommended
|
||||
to protect the FLASH memory against possible unwanted operation) *********/
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
#endif //FLASH_MANAGER_ENABLE
|
||||
|
||||
/* Re-enable instruction cache */
|
||||
#ifndef STM32WBAxx_LL_ICACHE_H
|
||||
if (HAL_ICACHE_Enable() != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
#else //STM32WBAxx_LL_ICACHE_H
|
||||
LL_ICACHE_Enable();
|
||||
#endif // STM32WBAxx_LL_ICACHE_H
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
flashOpStatus_e WriteToFlash(void *datapointer, uint32_t nBytes, uint32_t nAddress)
|
||||
{
|
||||
flashOpStatus_e result = FLASH_OP_OK;
|
||||
|
||||
/* Disable instruction cache prior to internal cacheable memory update */
|
||||
#ifndef STM32WBAxx_LL_ICACHE_H
|
||||
if (HAL_ICACHE_Disable() != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
#else //STM32WBAxx_LL_ICACHE_H
|
||||
uint32_t tickstart;
|
||||
|
||||
/* Make sure BSYENDF is reset before to disable the instruction cache */
|
||||
/* as it automatically starts a cache invalidation procedure */
|
||||
LL_ICACHE_ClearFlag_BSYEND();
|
||||
|
||||
LL_ICACHE_Disable();
|
||||
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for instruction cache being disabled */
|
||||
while (LL_ICACHE_IsEnabled())
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > 1U)
|
||||
{
|
||||
/* New check to avoid false timeout detection in case of preemption */
|
||||
if (LL_ICACHE_IsEnabled())
|
||||
{
|
||||
// status = HAL_TIMEOUT;
|
||||
//break;
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // STM32WBAxx_LL_ICACHE_H
|
||||
|
||||
|
||||
#if FLASH_MANAGER_ENABLE
|
||||
FM_Cmd_Status_t fm_result;
|
||||
|
||||
int32_t int32_size = 0;
|
||||
int32_size = (int32_t)(nBytes/4);
|
||||
if (nBytes%4)
|
||||
{
|
||||
int32_size++;
|
||||
}
|
||||
|
||||
fm_result = FM_Write((uint32_t*)datapointer, (uint32_t *)nAddress, int32_size, NULL);
|
||||
if(fm_result == FM_BUSY)
|
||||
{
|
||||
result = FLASH_OP_BUSY;
|
||||
}
|
||||
else if (fm_result == FM_ERROR)
|
||||
{
|
||||
result = FLASH_OP_ERROR;
|
||||
}
|
||||
result = FLASH_OP_OK;
|
||||
|
||||
#else //FLASH_MANAGER_ENABLE
|
||||
|
||||
/* Unlock the Flash to enable the flash control register access *************/
|
||||
HAL_FLASH_Unlock();
|
||||
/* Program the user Flash area word by word
|
||||
(area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
|
||||
uint32_t AddressOffset = 0;
|
||||
|
||||
while (AddressOffset < nBytes)
|
||||
{
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_QUADWORD, nAddress + AddressOffset, ((uint32_t)datapointer + AddressOffset)) == HAL_OK)
|
||||
{
|
||||
AddressOffset = AddressOffset + 16; /* increment to next quad word*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Error occurred while writing data in Flash memory.
|
||||
User can add here some code to deal with this error */
|
||||
while (1)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Lock the Flash to disable the flash control register access (recommended
|
||||
to protect the FLASH memory against possible unwanted operation) *********/
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
#endif //FLASH_MANAGER_ENABLE
|
||||
|
||||
|
||||
/* Re-enable instruction cache */
|
||||
#ifndef STM32WBAxx_LL_ICACHE_H
|
||||
if (HAL_ICACHE_Enable() != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
#else //STM32WBAxx_LL_ICACHE_H
|
||||
LL_ICACHE_Enable();
|
||||
#endif // STM32WBAxx_LL_ICACHE_H
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,938 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : sm_crypto_mcu.c
|
||||
* @brief : MCU cryptographic functions using hardware accelerators
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------*/
|
||||
#include "sm_crypto_mcu.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef STM32WBA65xx
|
||||
#include "hw.h"
|
||||
#endif //STM32WBA65xx
|
||||
|
||||
#define USE_MCU_HW_RNG
|
||||
#define USE_MCU_HW_ASYM
|
||||
|
||||
#define HASH_TIMEOUT ((uint32_t)5)
|
||||
#define KDH_INFO_MAX_LEN_BYTES ((uint32_t)32)
|
||||
#define SHA256_BYTE_SIZE ((uint32_t)32)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static HASH_HandleTypeDef *HHash = NULL;
|
||||
static CRYP_HandleTypeDef *HCryp = NULL;
|
||||
|
||||
#ifdef USE_MCU_HW_RNG
|
||||
static RNG_HandleTypeDef *HRng = NULL;
|
||||
#endif // USE_MCU_HW_RNG
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(STM32U545xx) || defined(STM32U585xx)
|
||||
#include "stm32u5xx_hal.h"
|
||||
#define HHASH_INIT_DATATYPE HASH_DATATYPE_8B
|
||||
#define SM_HASH_SHA256_START HAL_HASHEx_SHA256_Start
|
||||
#define SM_HASH_SHA256_ACCUMULATE(H, B, S, T) HAL_HASHEx_SHA256_Accmlt(H, B, S)
|
||||
#define SM_HASH_SHA256_ACCUMULATE_LAST HAL_HASHEx_SHA256_Accmlt_End
|
||||
#define SM_HASH_SHA1_START HAL_HASH_SHA1_Start
|
||||
#define HASH_SET_ALGORITHM(I, A)
|
||||
|
||||
#define SM_HMAC_SHA256_START HAL_HMACEx_SHA256_Start
|
||||
|
||||
#elif defined(STM32U385xx)
|
||||
#include "stm32u3xx_hal.h"
|
||||
#define HHASH_INIT_DATATYPE HASH_DATATYPE_8B
|
||||
#define SM_HASH_SHA256_START HAL_HASHEx_SHA256_Start
|
||||
#define SM_HASH_SHA256_ACCUMULATE(H, B, S, T) HAL_HASHEx_SHA256_Accmlt(H, B, S)
|
||||
#define SM_HASH_SHA256_ACCUMULATE_LAST HAL_HASHEx_SHA256_Accmlt_End
|
||||
#define SM_HASH_SHA1_START HAL_HASH_SHA1_Start
|
||||
#define HASH_SET_ALGORITHM(I, A)
|
||||
|
||||
#define SM_HMAC_SHA256_START HAL_HMACEx_SHA256_Start
|
||||
|
||||
#elif defined(STM32WBA52xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx)
|
||||
#include "stm32wbaxx_hal.h"
|
||||
#define HHASH_INIT_DATATYPE HASH_CR_DATATYPE_1
|
||||
|
||||
#define SM_HASH_SHA1_START(hhash, pInBuffer, Size, pOutBuffer, Timeout) HAL_HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout)
|
||||
|
||||
#define SM_HASH_SHA256_START(hhash, pInBuffer, Size, pOutBuffer, Timeout) HAL_HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout)
|
||||
#define SM_HMAC_SHA256_START(hhash, pInBuffer, Size, pOutBuffer, Timeout) HAL_HASH_HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout)
|
||||
|
||||
#define SM_HASH_SHA256_ACCUMULATE(H, B, S, T) HAL_HASH_Accumulate(H, B, S, T)
|
||||
#define SM_HASH_SHA256_ACCUMULATE_LAST HAL_HASH_AccumulateLast
|
||||
#define HASH_SET_ALGORITHM(I, A) I.Algorithm = A
|
||||
|
||||
#else
|
||||
#error "product not supported"
|
||||
#endif
|
||||
|
||||
#ifdef USE_MCU_HW_ASYM
|
||||
static PKA_HandleTypeDef *HPka = NULL;
|
||||
#define PKA_TIMEOUT ((uint32_t)3000)
|
||||
#define PRIVATE_KEY_SIZE_BYTES ((uint32_t)32)
|
||||
#define MODULUS_SIZE_BYTES PRIVATE_KEY_SIZE_BYTES
|
||||
#define MODULUS_SIZE_WORDS ((MODULUS_SIZE_BYTES + 3)/4)
|
||||
#define SECP256R1_ORDER_LEN_BITS ((uint32_t)256)
|
||||
#define SECP256R1_A_SIGN ((uint32_t)1)
|
||||
static const uint8_t SECP256R1_Prime[] =
|
||||
{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
static const uint8_t SECP256R1_AbsA[] =
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 };
|
||||
static const uint8_t SECP256R1_B[] =
|
||||
{ 0x5a, 0xc6, 0x35, 0xd8, 0xaa, 0x3a, 0x93, 0xe7, 0xb3, 0xeb, 0xbd, 0x55, 0x76,
|
||||
0x98, 0x86, 0xbc, 0x65, 0x1d, 0x06, 0xb0, 0xcc, 0x53, 0xb0, 0xf6, 0x3b,
|
||||
0xce, 0x3c, 0x3e, 0x27, 0xd2, 0x60, 0x4b };
|
||||
static const uint8_t SECP256R1_Gx[] =
|
||||
{ 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc, 0xe6, 0xe5, 0x63,
|
||||
0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0, 0xf4,
|
||||
0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96 };
|
||||
static const uint8_t SECP256R1_Gy[] =
|
||||
{ 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb, 0x4a, 0x7c,
|
||||
0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce, 0xcb,
|
||||
0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5 };
|
||||
static const uint8_t SECP256R1_Order[] =
|
||||
{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84, 0xf3,
|
||||
0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x51 };
|
||||
static const uint8_t SECP256R1_OrderMinus1[] =
|
||||
{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84, 0xf3,
|
||||
0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x50 };
|
||||
|
||||
#ifdef ALIRO_TEST
|
||||
// This is the static private key from the static test vectors
|
||||
const uint8_t staticPrivateKey[] = {0x7a, 0x9e, 0x50, 0xa1, 0x9a, 0xe3, 0x85, 0xe3, 0x9b, 0x3b, 0xf0, 0xc7, 0x5e, 0xb5, 0xf9, 0xc9, 0xa5, 0xeb, 0x4d, 0x51, 0xf8, 0x8, 0x23, 0x18, 0x35, 0x39, 0x5f, 0xd2, 0xc1, 0x7, 0x83, 0x67};
|
||||
#define STATIC_PRIVATE_KEY staticPrivateKey
|
||||
#else // ALIRO_TEST
|
||||
// This is the static private key for the mobile phone app.
|
||||
//ST OFFICE
|
||||
//const uint8_t staticPrivateKey[] = {0xCB, 0x64, 0xA5, 0x8A, 0x5F, 0xAE, 0x05, 0x2D, 0x45, 0x8B, 0x3B, 0xCE, 0x25, 0x99, 0xA2, 0x0A,
|
||||
// 0x66, 0x59, 0x87, 0xB5, 0x37, 0xB1, 0x57, 0xCC, 0x3C, 0xC4, 0x2E, 0x1D, 0x9C, 0x65, 0x24, 0x09};
|
||||
//HOME
|
||||
//const uint8_t staticPrivateKey[] = {0xBE, 0x08, 0x3F, 0xCD, 0xA3, 0x7B, 0xB2, 0xDA, 0x82, 0x66, 0xDC, 0x64, 0x61, 0x66, 0x35, 0x24,
|
||||
// 0xE5, 0x9A, 0xD4, 0xA0, 0xBB, 0x6B, 0x4D, 0xD3, 0x1C, 0x88, 0x53, 0xC2, 0x0F, 0xFB, 0xB4, 0x0D};
|
||||
|
||||
#include "provisioning.h"
|
||||
|
||||
#define STATIC_PRIVATE_KEY (getProvisioningFromFlash()->staticPrivateKey)
|
||||
#endif // ALIRO_TEST
|
||||
|
||||
uint8_t ephemeralPrivateKey[] = {0x3c, 0xf, 0x74, 0x11, 0x4c, 0xd2, 0xa0, 0x21, 0xe8, 0x6, 0x6e, 0xfb, 0xaa, 0x31, 0xdb, 0xb9, 0x7e, 0xf0, 0x5, 0x42, 0x72, 0x19, 0x26, 0x6, 0xfd, 0x96, 0x63, 0x3a, 0x4, 0xf6, 0x62, 0x14};
|
||||
|
||||
#endif // USE_MCU_HW_ASYM
|
||||
|
||||
#ifndef GET_UINT32_BE
|
||||
#define GET_UINT32_BE(n,b,i) \
|
||||
do { \
|
||||
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
||||
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
||||
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
|
||||
| ( (uint32_t) (b)[(i) + 3] ); \
|
||||
} while( 0 )
|
||||
#endif //GET_UINT32_BE
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializes MCU cryptographic hardware modules.
|
||||
* @param rng Pointer to RNG handle.
|
||||
* @param pka Pointer to PKA handle.
|
||||
* @param hash Pointer to HASH handle.
|
||||
* @param cryp Pointer to CRYP handle.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_initCryptoMCU(RNG_HandleTypeDef *rng, PKA_HandleTypeDef *pka, HASH_HandleTypeDef *hash, CRYP_HandleTypeDef *cryp)
|
||||
{
|
||||
#ifdef USE_MCU_HW_RNG
|
||||
HRng = rng;
|
||||
#endif // USE_MCU_HW_RNG
|
||||
#ifdef USE_MCU_HW_ASYM
|
||||
HPka = pka;
|
||||
#endif // USE_MCU_HW_ASYM
|
||||
HHash = hash;
|
||||
HCryp = cryp;
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
#ifdef USE_MCU_HW_RNG
|
||||
|
||||
/**
|
||||
* @brief Generates random bytes using MCU hardware RNG.
|
||||
* @param bytes Pointer to output buffer.
|
||||
* @param size Number of bytes to generate.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_genRandomBytes(uint8_t *bytes, uint32_t size)
|
||||
{
|
||||
uint32_t temp;
|
||||
uint32_t remain = size % 4;
|
||||
if (HRng == NULL)
|
||||
return(SM_Crypto_HW_Error);
|
||||
__HAL_RCC_RNG_CLK_ENABLE();
|
||||
__HAL_RNG_ENABLE(HRng);
|
||||
|
||||
#ifdef STM32WBA65xx
|
||||
HW_RNG_Start();
|
||||
#endif //STM32WBA65xx
|
||||
|
||||
for (uint32_t i = 0; i < size / 4; i++)
|
||||
{
|
||||
#ifdef STM32WBA65xx
|
||||
HW_RNG_Get(1, &temp);
|
||||
#endif //STM32WBA65xx
|
||||
|
||||
#if defined(STM32U545xx) || defined(STM32U585xx) || defined(STM32U385xx)
|
||||
if (HAL_RNG_GenerateRandomNumber(HRng, &temp) != HAL_OK)
|
||||
{
|
||||
/* Random number generation error */
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
#endif //defined(STM32U545xx) || defined(STM32U585xx) || defined(STM32U385xx)
|
||||
#if defined(STM32WBA52xx)||defined(STM32WBA55xx)
|
||||
if (HAL_RNG_GenerateRandomNumber(HRng, &temp) != HAL_OK)
|
||||
{
|
||||
/* Random number generation error */
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
#endif //defined(STM32WBA52xx)||defined(STM32WBA55xx)
|
||||
*(uint32_t *) bytes = temp;
|
||||
bytes += 4;
|
||||
}
|
||||
if (remain)
|
||||
{
|
||||
#ifdef STM32WBA65xx
|
||||
HW_RNG_Get(1, &temp);
|
||||
#endif //STM32WBA65xx
|
||||
|
||||
#if defined(STM32WBA52xx)||defined(STM32WBA55xx)
|
||||
if (HAL_RNG_GenerateRandomNumber(HRng, &temp) != HAL_OK)
|
||||
{
|
||||
/* Random number generation error */
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
#endif //defined(STM32WBA52xx)||defined(STM32WBA55xx)
|
||||
#if defined(STM32U545xx) || defined(STM32U585xx) || defined(STM32U385xx)
|
||||
if (HAL_RNG_GenerateRandomNumber(HRng, &temp) != HAL_OK)
|
||||
{
|
||||
/* Random number generation error */
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
#endif //defined(STM32U545xx) || defined(STM32U585xx) || defined(STM32U385xx)
|
||||
for (uint32_t i = 0; i < remain; i++)
|
||||
{
|
||||
*bytes = (temp >> i) & 0xFF;
|
||||
bytes++;
|
||||
}
|
||||
}
|
||||
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
#else //USE_MCU_HW_RNG
|
||||
#if 0
|
||||
SM_Crypto_Error_t SM_genRandomBytes(uint8_t *bytes, uint32_t size)
|
||||
{
|
||||
for(uint32_t i = 0; i< size;i++)
|
||||
{
|
||||
*bytes = i;
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
#endif
|
||||
#endif // USE_MCU_HW_RNG
|
||||
|
||||
#ifdef USE_MCU_HW_ASYM
|
||||
static uint32_t NumberOfWords(uint32_t NumberOfBytes)
|
||||
{
|
||||
return ((NumberOfBytes + 3) / 4);
|
||||
}
|
||||
static SM_Crypto_Error_t GeneratePrivateKey(uint8_t *pPrivateKey)
|
||||
{
|
||||
/* for NIST compliance (to decrease bias below 2^-64)
|
||||
* generate random with 64 extra bits (2 words)
|
||||
* perform modular reduction by n-1
|
||||
* and add 1 */
|
||||
uint8_t temp[MODULUS_SIZE_BYTES + 8] = { 0 };
|
||||
uint8_t temp2[MODULUS_SIZE_BYTES + 8] = { 0 };
|
||||
uint32_t random_bitstring_len_in_bits = 0;
|
||||
PKA_ModRedInTypeDef in_modred = { 0 };
|
||||
|
||||
random_bitstring_len_in_bits = SECP256R1_ORDER_LEN_BITS + 64;
|
||||
if (SM_genRandomBytes(temp, (random_bitstring_len_in_bits + 7) / 8) != SM_Crypto_OK)
|
||||
{
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
/* Perform modular reduction by n-1 */
|
||||
in_modred.pMod = SECP256R1_OrderMinus1;
|
||||
in_modred.modSize = sizeof(SECP256R1_Order);
|
||||
in_modred.pOp1 = (uint32_t*)temp;
|
||||
in_modred.OpSize = (random_bitstring_len_in_bits + 31) / 32;
|
||||
if (HAL_PKA_ModRed(HPka, &in_modred, PKA_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
HAL_PKA_Arithmetic_GetResult(HPka, (uint32_t*)temp2);
|
||||
|
||||
/* compute reduced_random + 1 */
|
||||
memset(temp, 0, sizeof(temp));
|
||||
temp[0] = 1;
|
||||
{
|
||||
PKA_AddInTypeDef in_add;
|
||||
in_add.pOp1 = (uint32_t*)temp2;
|
||||
in_add.pOp2 = (uint32_t*)temp;
|
||||
in_add.size = NumberOfWords(sizeof(SECP256R1_Order));
|
||||
if (HAL_PKA_Add(HPka, &in_add, PKA_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
HAL_PKA_Arithmetic_GetResult(HPka, (uint32_t*)temp2);
|
||||
}
|
||||
memcpy(pPrivateKey, temp2, sizeof(SECP256R1_Order));
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
static SM_Crypto_Error_t GeneratePublicKey(const uint8_t *pPrivateKey, uint8_t *pPublicKey)
|
||||
{
|
||||
PKA_ECCMulInTypeDef in_mult =
|
||||
{ 0 };
|
||||
|
||||
/* Compute public key */
|
||||
in_mult.modulusSize = sizeof(SECP256R1_Prime);
|
||||
in_mult.coefSign = SECP256R1_A_SIGN;
|
||||
in_mult.coefA = SECP256R1_AbsA;
|
||||
in_mult.coefB = SECP256R1_B;
|
||||
in_mult.modulus = SECP256R1_Prime;
|
||||
in_mult.pointX = SECP256R1_Gx;
|
||||
in_mult.pointY = SECP256R1_Gy;
|
||||
in_mult.primeOrder = SECP256R1_Order;
|
||||
in_mult.scalarMulSize = sizeof(SECP256R1_Order); // WRONG NAMING IN HAL STRUCT: this must be the length of the ORDER
|
||||
in_mult.scalarMul = (uint8_t *)pPrivateKey;
|
||||
|
||||
{
|
||||
PKA_ECCMulOutTypeDef mulRes;
|
||||
mulRes.ptX = &pPublicKey[0];
|
||||
mulRes.ptY = &pPublicKey[sizeof(SECP256R1_Order)];
|
||||
if (HAL_PKA_ECCMul(HPka, &in_mult, PKA_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
HAL_PKA_ECCMul_GetResult(HPka, &mulRes);
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Performs ECDH key agreement using MCU hardware.
|
||||
* @param pPublicKey Pointer to public key.
|
||||
* @param pSharedSecret Pointer to output shared secret.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_Ecdh(const uint8_t *pPublicKey, uint8_t *pSharedSecret)
|
||||
{
|
||||
PKA_ECCMulInTypeDef in_mult = { 0 };
|
||||
|
||||
/* Compute ECDH */
|
||||
in_mult.modulusSize = sizeof(SECP256R1_Prime);
|
||||
in_mult.coefSign = SECP256R1_A_SIGN;
|
||||
in_mult.coefA = SECP256R1_AbsA;
|
||||
in_mult.coefB = SECP256R1_B;
|
||||
in_mult.modulus = SECP256R1_Prime;
|
||||
in_mult.pointX = (uint8_t*)&pPublicKey[0];
|
||||
in_mult.pointY = (uint8_t*)&pPublicKey[sizeof(SECP256R1_Order)];
|
||||
in_mult.primeOrder = SECP256R1_Order;
|
||||
in_mult.scalarMulSize = sizeof(SECP256R1_Order); // WRONG NAMING IN HAL STRUCT: this must be the length of the ORDER
|
||||
in_mult.scalarMul = ephemeralPrivateKey;
|
||||
|
||||
if (HAL_PKA_ECCMul(HPka, &in_mult, PKA_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
memset(ephemeralPrivateKey, 0, sizeof(ephemeralPrivateKey));
|
||||
return SM_Crypto_Error;
|
||||
}
|
||||
memset(ephemeralPrivateKey, 0, sizeof(ephemeralPrivateKey));
|
||||
{
|
||||
PKA_ECCMulOutTypeDef pub;
|
||||
uint8_t tmp[sizeof(SECP256R1_Order)];
|
||||
pub.ptX = pSharedSecret;
|
||||
pub.ptY = tmp;
|
||||
HAL_PKA_ECCMul_GetResult(HPka, &pub);
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Signs a digest using MCU hardware.
|
||||
* @param digest Pointer to digest to sign.
|
||||
* @param digestSize Size of digest.
|
||||
* @param signature Pointer to output signature.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sign(const uint8_t *digest, uint32_t digestSize, uint8_t *signature)
|
||||
{
|
||||
uint8_t a_k[MODULUS_SIZE_WORDS*sizeof(uint32_t)] =
|
||||
{ 0 };
|
||||
PKA_ECDSASignInTypeDef in =
|
||||
{ 0 };
|
||||
|
||||
if (digestSize != SHA256_BYTE_SIZE)
|
||||
return SM_Crypto_Error;
|
||||
/* generate random k parameter in NIST compliant way */
|
||||
if (GeneratePrivateKey(a_k) != SM_Crypto_OK)
|
||||
{
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
|
||||
/* Set input parameters */
|
||||
in.primeOrderSize = sizeof(SECP256R1_Order);
|
||||
in.modulusSize = sizeof(SECP256R1_Prime);
|
||||
in.coefSign = SECP256R1_A_SIGN;
|
||||
in.coef = SECP256R1_AbsA;
|
||||
in.coefB = SECP256R1_B;
|
||||
in.modulus = SECP256R1_Prime;
|
||||
in.basePointX = SECP256R1_Gx;
|
||||
in.basePointY = SECP256R1_Gy;
|
||||
in.primeOrder = SECP256R1_Order;
|
||||
|
||||
in.integer = a_k;
|
||||
in.hash = digest;
|
||||
|
||||
in.privateKey = STATIC_PRIVATE_KEY;
|
||||
|
||||
if (HAL_PKA_ECDSASign(HPka, &in, PKA_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
{
|
||||
PKA_ECDSASignOutTypeDef out;
|
||||
out.RSign = &signature[0];
|
||||
out.SSign = &signature[sizeof(SECP256R1_Order)];
|
||||
HAL_PKA_ECDSASign_GetResult(HPka, &out, NULL);
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generates a keypair using MCU hardware.
|
||||
* @param pub Pointer to output public key.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_genKeypair(uint8_t *pub)
|
||||
{
|
||||
if (GeneratePrivateKey(ephemeralPrivateKey) != SM_Crypto_OK)
|
||||
return SM_Crypto_Error;
|
||||
|
||||
if (GeneratePublicKey(ephemeralPrivateKey, pub) != SM_Crypto_OK)
|
||||
{
|
||||
memset(ephemeralPrivateKey, 0, sizeof(ephemeralPrivateKey));
|
||||
return SM_Crypto_Error;
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Verifies a signature using MCU hardware.
|
||||
* @param pPublicKey Pointer to public key.
|
||||
* @param digest Pointer to digest.
|
||||
* @param digestSize Size of digest.
|
||||
* @param signature Pointer to signature.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_verify(const uint8_t *pPublicKey, const uint8_t *digest, const uint32_t digestSize, const uint8_t *signature)
|
||||
{
|
||||
PKA_ECDSAVerifInTypeDef in =
|
||||
{ 0 };
|
||||
if (digestSize != SHA256_BYTE_SIZE)
|
||||
return (SM_Crypto_Error);
|
||||
/* Set input parameters */
|
||||
in.primeOrderSize = sizeof(SECP256R1_Order);
|
||||
in.modulusSize = sizeof(SECP256R1_Prime);
|
||||
in.coefSign = SECP256R1_A_SIGN;
|
||||
in.coef = SECP256R1_AbsA;
|
||||
in.modulus = SECP256R1_Prime;
|
||||
in.basePointX = SECP256R1_Gx;
|
||||
in.basePointY = SECP256R1_Gy;
|
||||
in.primeOrder = SECP256R1_Order;
|
||||
|
||||
in.RSign = &signature[0];
|
||||
in.SSign = &signature[PRIVATE_KEY_SIZE_BYTES];
|
||||
in.hash = digest;
|
||||
in.pPubKeyCurvePtX = &pPublicKey[0];
|
||||
in.pPubKeyCurvePtY = &pPublicKey[MODULUS_SIZE_BYTES];
|
||||
|
||||
if (HAL_PKA_ECDSAVerif(HPka, &in, PKA_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
if (!HAL_PKA_ECDSAVerif_IsValidSignature(HPka))
|
||||
return (SM_Crypto_Error);
|
||||
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets the certificate from MCU hardware.
|
||||
* @param certificate Pointer to output certificate buffer.
|
||||
* @param certificateSize Pointer to output certificate size.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_getCertificate(uint8_t *certificate, uint32_t *certificateSize)
|
||||
{
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
#endif // USE_MCU_HW_ASYM
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Private function -----------------------------------------------*/
|
||||
static SM_Crypto_Error_t KDFKeyExpansionRound(const uint8_t* pKDK, const uint8_t *prev, const uint8_t* pFixedInfo, uint32_t fixedInfoSize, uint8_t counter, uint8_t* output)
|
||||
{
|
||||
/* counter and L must be big-endian, update least significant byte */
|
||||
uint32_t offset = 0;
|
||||
uint32_t hmac_input_size = 0;
|
||||
|
||||
uint8_t input[SHA256_BYTE_SIZE + MAX_FIXED_INFO_SIZE + 1 ];
|
||||
|
||||
if (fixedInfoSize > MAX_FIXED_INFO_SIZE)
|
||||
return SM_Crypto_Error;
|
||||
HHash->Init.DataType = HHASH_INIT_DATATYPE;
|
||||
HASH_SET_ALGORITHM(HHash->Init, HASH_ALGOSELECTION_SHA256);
|
||||
HHash->Init.KeySize = SHA256_BYTE_SIZE;
|
||||
HHash->Init.pKey = (uint8_t *)pKDK;
|
||||
if (HAL_HASH_Init(HHash) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
hmac_input_size = SHA256_BYTE_SIZE + fixedInfoSize + 1 ;
|
||||
if (counter != 1)
|
||||
{
|
||||
memcpy(input + offset, prev, SHA256_BYTE_SIZE);
|
||||
offset += SHA256_BYTE_SIZE;
|
||||
} else {
|
||||
/* No need to copy, but will hmac 32 bytes less */
|
||||
hmac_input_size -= SHA256_BYTE_SIZE;
|
||||
}
|
||||
/* Based on RFC 5869 */
|
||||
memcpy(input + offset, pFixedInfo, fixedInfoSize);
|
||||
offset += fixedInfoSize;
|
||||
memcpy(input + offset, &counter, 1);
|
||||
offset += 1;
|
||||
if (SM_HMAC_SHA256_START(HHash, input, hmac_input_size, output, 5000) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Public functions -----------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Computes SHA-1 hash using MCU hardware.
|
||||
* @param input Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @param hash Pointer to output hash buffer.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha1(uint8_t *input, uint32_t inputSize, uint8_t *hash)
|
||||
{
|
||||
HHash->Init.DataType = HHASH_INIT_DATATYPE;
|
||||
HASH_SET_ALGORITHM(HHash->Init, HASH_ALGOSELECTION_SHA1);
|
||||
if (HAL_HASH_Init(HHash) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
|
||||
if (SM_HASH_SHA1_START(HHash, input, inputSize, &hash[0], HASH_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Computes SHA-256 hash using MCU hardware.
|
||||
* @param input Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @param hash Pointer to output hash buffer.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha256(uint8_t *input, uint32_t inputSize, uint8_t *hash)
|
||||
{
|
||||
HHash->Init.DataType = HHASH_INIT_DATATYPE;
|
||||
HASH_SET_ALGORITHM(HHash->Init, HASH_ALGOSELECTION_SHA256);
|
||||
if (HAL_HASH_Init(HHash) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
|
||||
if (SM_HASH_SHA256_START(HHash, input, inputSize, &hash[0], HASH_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Starts SHA-256 computation using MCU hardware.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha256_start(void)
|
||||
{
|
||||
HHash->Init.DataType = HHASH_INIT_DATATYPE;
|
||||
HASH_SET_ALGORITHM(HHash->Init, HASH_ALGOSELECTION_SHA256);
|
||||
if (HAL_HASH_Init(HHash) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Updates SHA-256 computation with new data using MCU hardware.
|
||||
* @param input Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha256_update(const uint8_t *input, uint32_t inputSize)
|
||||
{
|
||||
if (SM_HASH_SHA256_ACCUMULATE(HHash, input, inputSize, HASH_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Finishes SHA-256 computation and returns the hash using MCU hardware.
|
||||
* @param hash Pointer to output hash buffer.
|
||||
* @param input Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_sha256_finish(uint8_t *hash, const uint8_t *input, uint32_t inputSize)
|
||||
{
|
||||
if (SM_HASH_SHA256_ACCUMULATE_LAST(HHash, input, inputSize, &hash[0], HASH_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return (SM_Crypto_HW_Error);
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Performs randomness extraction for KDF.
|
||||
* @param Z Pointer to input keying material.
|
||||
* @param ZSize Size of input keying material.
|
||||
* @param salt Pointer to salt.
|
||||
* @param saltSize Size of salt.
|
||||
* @param output Pointer to output buffer.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t KDFRandomnessExtraction(const uint8_t* Z, uint32_t ZSize,
|
||||
const uint8_t* salt, uint32_t saltSize,
|
||||
uint8_t* output)
|
||||
{
|
||||
uint8_t null_salt[SHA256_BYTE_SIZE] = {0};
|
||||
|
||||
if ((saltSize == 0) && (salt == NULL)) // no salt (optionnal), need to use string of zeros, the size is the size of the HASH
|
||||
{
|
||||
HHash->Init.KeySize = SHA256_BYTE_SIZE;
|
||||
HHash->Init.pKey = null_salt;
|
||||
} else if (salt == NULL) // saltsize is non-zero but pointer is null -> error
|
||||
{
|
||||
return SM_Crypto_Error;
|
||||
}
|
||||
else
|
||||
{
|
||||
HHash->Init.KeySize = saltSize;
|
||||
HHash->Init.pKey = (uint8_t *)salt;
|
||||
}
|
||||
HHash->Init.DataType = HHASH_INIT_DATATYPE;
|
||||
HASH_SET_ALGORITHM(HHash->Init, HASH_ALGOSELECTION_SHA256);
|
||||
if (HAL_HASH_Init(HHash) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
if (SM_HMAC_SHA256_START(HHash, (uint8_t *)Z, ZSize, output, 5000) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Key Derivation Function RFC5869 using MCU hardware.
|
||||
* @param pZ Pointer to input keying material.
|
||||
* @param ZSize Size of input keying material.
|
||||
* @param pSalt Pointer to salt.
|
||||
* @param saltSize Size of salt.
|
||||
* @param pFixedInfo Pointer to fixed info.
|
||||
* @param fixedInfoSize Size of fixed info.
|
||||
* @param L Length of output keying material.
|
||||
* @param pOutput Pointer to output buffer.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_KDFRFC5869(const uint8_t* pZ, uint32_t ZSize,
|
||||
const uint8_t* pSalt, uint32_t saltSize,
|
||||
const uint8_t* pFixedInfo, uint32_t fixedInfoSize,
|
||||
uint32_t L, uint8_t* pOutput)
|
||||
{
|
||||
uint8_t counter = 0;
|
||||
uint8_t KDK[SHA256_BYTE_SIZE] = {0};
|
||||
uint8_t *prev = NULL;
|
||||
|
||||
if(L >= 255*SHA256_BYTE_SIZE)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
if (KDFRandomnessExtraction(pZ, ZSize, pSalt, saltSize, KDK) != SM_Crypto_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
for(counter=1; counter<=L/SHA256_BYTE_SIZE; counter++)
|
||||
{
|
||||
/* compute full rounds */
|
||||
if(KDFKeyExpansionRound(KDK, prev, pFixedInfo, fixedInfoSize, counter, pOutput) != SM_Crypto_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
prev = pOutput;
|
||||
pOutput += SHA256_BYTE_SIZE;
|
||||
}
|
||||
if(L % SHA256_BYTE_SIZE)
|
||||
{
|
||||
/* compute non full round */
|
||||
uint8_t buffer[SHA256_BYTE_SIZE];
|
||||
if(KDFKeyExpansionRound(KDK, prev, pFixedInfo, fixedInfoSize, counter, buffer) != SM_Crypto_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
memcpy(pOutput, buffer, L % SHA256_BYTE_SIZE);
|
||||
}
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Derives KDH key using MCU hardware.
|
||||
* @param pZ Pointer to input keying material.
|
||||
* @param info Pointer to info data.
|
||||
* @param infoSize Size of info data.
|
||||
* @param pKdh Pointer to output KDH key.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_deriveKdh(const uint8_t *pZ, const uint8_t * info, uint32_t infoSize, uint8_t *pKdh)
|
||||
{
|
||||
uint8_t counter_be[4] = {0,0,0,1};
|
||||
uint32_t offset = 0;
|
||||
uint8_t buf[KDH_INFO_MAX_LEN_BYTES + 32 + 4];
|
||||
memcpy(&buf[offset], pZ, 32);
|
||||
offset += 32;
|
||||
memcpy(&buf[offset], counter_be, 4);
|
||||
offset += 4;
|
||||
memcpy(&buf[offset], info, infoSize);
|
||||
|
||||
HHash->Init.DataType = HHASH_INIT_DATATYPE;
|
||||
HASH_SET_ALGORITHM(HHash->Init, HASH_ALGOSELECTION_SHA256);
|
||||
if (HAL_HASH_Init(HHash) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
if (SM_HASH_SHA256_START(HHash, buf, 32 + 4 + infoSize, pKdh, 5000) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Decrypts data using AES-256 GCM with MCU hardware.
|
||||
* @param pKey Pointer to key.
|
||||
* @param pNonce Pointer to nonce.
|
||||
* @param pAad Pointer to additional authenticated data.
|
||||
* @param aadSize Size of AAD.
|
||||
* @param pPayload Pointer to encrypted payload.
|
||||
* @param payloadSize Size of payload.
|
||||
* @param pPlaintext Pointer to output plaintext buffer.
|
||||
* @param pTag Pointer to authentication tag.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_aes256GcmDecrypt(const uint8_t* pKey, const uint8_t* pNonce, const uint8_t* pAad, const uint32_t aadSize,
|
||||
const uint8_t* pPayload, const uint32_t payloadSize, uint8_t* pPlaintext,
|
||||
const uint8_t* pTag)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
uint32_t key[8] = {0};
|
||||
uint32_t iv[4] = {0};
|
||||
uint32_t tag[4] = {0};
|
||||
uint8_t tmp = 0;
|
||||
|
||||
/* !!! Beware: the last word must be padded with 0s by the caller, otherwise tag will be wrong !!! */
|
||||
if (payloadSize % 4)
|
||||
{
|
||||
/* Must check that the padding has been properly done by caller */
|
||||
if (memcmp(&pPayload[payloadSize], &i, 4 - (payloadSize % 4)))
|
||||
return SM_Crypto_Error;
|
||||
}
|
||||
/* Format and fill AES key */
|
||||
for( i=0; i < 8; i++ )
|
||||
GET_UINT32_BE( key[i], pKey, 4*i );
|
||||
/* Set IV with invert endianness */
|
||||
for( i=0; i < 3; i++ )
|
||||
GET_UINT32_BE( iv[i], pNonce, 4*i );
|
||||
|
||||
/* counter value must be set to 2 when processing the first block of payload */
|
||||
iv[3] = 0x00000002;
|
||||
|
||||
HCryp->Instance = AES;
|
||||
HCryp->Init.DataType = CRYP_DATATYPE_8B;
|
||||
HCryp->Init.KeySize = CRYP_KEYSIZE_256B;
|
||||
HCryp->Init.pKey = key;
|
||||
HCryp->Init.pInitVect = iv;
|
||||
HCryp->Init.Algorithm = CRYP_AES_GCM_GMAC;
|
||||
HCryp->Init.Header = (uint32_t *)pAad;
|
||||
HCryp->Init.HeaderSize = aadSize;
|
||||
HCryp->Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_BYTE;
|
||||
HCryp->Init.HeaderWidthUnit = CRYP_HEADERWIDTHUNIT_BYTE;
|
||||
HCryp->Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
|
||||
HCryp->Init.KeyMode = CRYP_KEYMODE_NORMAL;
|
||||
if (HAL_CRYP_Init(HCryp) != HAL_OK)
|
||||
{
|
||||
return(SM_Crypto_HW_Error);
|
||||
}
|
||||
if (HAL_CRYP_Decrypt(HCryp, (uint32_t *)pPayload, (uint16_t) payloadSize, (uint32_t *)pPlaintext, 5000) != HAL_OK)
|
||||
return(SM_Crypto_HW_Error);
|
||||
/* Last 16 bytes of plaintext is the GCM tag */
|
||||
if (HAL_CRYPEx_AESGCM_GenerateAuthTAG(HCryp, (const uint32_t *)tag, 5000) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
// constant time compare
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
tmp |= pTag[i*4] ^ (uint8_t)(tag[i] & 0xFF);
|
||||
tmp |= pTag[i*4 + 1] ^ (uint8_t)((tag[i] >> 8) & 0xFF);
|
||||
tmp |= pTag[i*4 + 2] ^ (uint8_t)((tag[i] >> 16) & 0xFF);
|
||||
tmp |= pTag[i*4 + 3] ^ (uint8_t)((tag[i] >> 24) & 0xFF);
|
||||
}
|
||||
if (tmp)
|
||||
{
|
||||
memset(pPlaintext, 0, payloadSize);
|
||||
return SM_Crypto_Error;
|
||||
}
|
||||
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Encrypts data using AES-256 GCM with MCU hardware.
|
||||
* @param pKey Pointer to key.
|
||||
* @param pNonce Pointer to nonce.
|
||||
* @param pAad Pointer to additional authenticated data.
|
||||
* @param aadSize Size of AAD.
|
||||
* @param pInput Pointer to input data.
|
||||
* @param inputSize Size of input data.
|
||||
* @param pOutput Pointer to output buffer.
|
||||
* @param pOutputSize Pointer to output size.
|
||||
* @return SM_Crypto_Error_t error code.
|
||||
*/
|
||||
SM_Crypto_Error_t SM_aes256GcmEncrypt(const uint8_t* pKey, const uint8_t* pNonce, const uint8_t* pAad, const uint32_t aadSize,
|
||||
const uint8_t* pInput, const uint32_t inputSize, uint8_t* pOutput, uint32_t* pOutputSize)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
uint32_t key[8] = {0};
|
||||
uint32_t iv[4] = {0};
|
||||
uint32_t tag[4] = {0};
|
||||
|
||||
|
||||
/* Workaround HAL: need to pad with 0s the last word of payload. Here we first copy the input into the output
|
||||
buffer (that is at least 16 bytes longer (for the tag), and then we encrypt in place */
|
||||
memcpy(pOutput, pInput, inputSize);
|
||||
if ((inputSize) % 4)
|
||||
memset(&pOutput[inputSize], 0, 4 - ((inputSize) % 4));
|
||||
|
||||
/* Format and fill AES key */
|
||||
for( i=0; i < 8; i++ )
|
||||
GET_UINT32_BE( key[i], pKey, 4*i );
|
||||
/* Set IV with invert endianness */
|
||||
for( i=0; i < 3; i++ )
|
||||
GET_UINT32_BE( iv[i], pNonce, 4*i );
|
||||
|
||||
/* counter value must be set to 2 when processing the first block of payload */
|
||||
iv[3] = 0x00000002;
|
||||
|
||||
HCryp->Instance = AES;
|
||||
HCryp->Init.DataType = CRYP_DATATYPE_8B;
|
||||
HCryp->Init.KeySize = CRYP_KEYSIZE_256B;
|
||||
HCryp->Init.pKey = key;
|
||||
HCryp->Init.pInitVect = iv;
|
||||
HCryp->Init.Algorithm = CRYP_AES_GCM_GMAC;
|
||||
HCryp->Init.Header = (uint32_t *)pAad;
|
||||
HCryp->Init.HeaderSize = aadSize;
|
||||
HCryp->Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_BYTE;
|
||||
HCryp->Init.HeaderWidthUnit = CRYP_HEADERWIDTHUNIT_BYTE;
|
||||
HCryp->Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
|
||||
HCryp->Init.KeyMode = CRYP_KEYMODE_NORMAL;
|
||||
if (HAL_CRYP_Init(HCryp) != HAL_OK)
|
||||
{
|
||||
return(SM_Crypto_HW_Error);
|
||||
}
|
||||
if (HAL_CRYP_Encrypt(HCryp, (uint32_t *)pOutput, (uint16_t)inputSize, (uint32_t *)pOutput, 5000) != HAL_OK)
|
||||
return(SM_Crypto_HW_Error);
|
||||
/* Generate the GCM tag */
|
||||
if (HAL_CRYPEx_AESGCM_GenerateAuthTAG(HCryp, (const uint32_t *)tag, 5000) != HAL_OK)
|
||||
{
|
||||
return SM_Crypto_HW_Error;
|
||||
}
|
||||
for (i = 0; i < 4; i++) {
|
||||
pOutput[inputSize + i*4] = (uint8_t)(tag[i] & 0xFF);
|
||||
pOutput[inputSize + i*4 + 1] = (uint8_t)((tag[i] >> 8) & 0xFF);
|
||||
pOutput[inputSize + i*4 + 2] = (uint8_t)((tag[i] >> 16) & 0xFF);
|
||||
pOutput[inputSize + i*4 + 3] = (uint8_t)((tag[i] >> 24) & 0xFF);
|
||||
}
|
||||
*pOutputSize = inputSize + 16;
|
||||
return SM_Crypto_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user