diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e7b9dce0..237aaf33 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,10 @@ ## IMPORTANT INFORMATION +### PR Checklist + +- [ ] I have updated the CHANGELOG.md file with a description of my changes. +- [ ] I have signed the Contributor License Agreement (CLA). + ### Contributor License Agreement (CLA) * The Pull Request feature will be considered by STMicroelectronics after the signature of a **Contributor License Agreement (CLA)** by the submitter. * If you did not sign such agreement, please follow the steps mentioned in the [CONTRIBUTING.md](CONTRIBUTING.md) file. diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..948ed796 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,56 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +> **Note:** This changelog starts from version v1.2.0. For prior releases, refer to the +> [GitHub Releases page](https://github.com/STMicroelectronics/STSELib/releases). + +--- + +## [Unreleased](https://github.com/STMicroelectronics/STSELib/compare/v1.1.7...HEAD) - v1.2.0 + +### Breaking Changes + +- **Renamed** `stse_Handler_t` to `stse_Handle_t` — all references to the handle type must be updated in application code ([31fb0fa](https://github.com/STMicroelectronics/STSELib/commit/31fb0fa9865828d82479e8c40fa3499c68b33fe9)) +- **API renamed** — all STSE host keys management functions must be updated in application code + - `stse_host_key_provisioning` to `stse_host_secure_channel_keys_provisioning` + - `stse_host_key_provisioning_wrapped` to `stse_host_secure_channel_keys_provisioning_wrapped` + - `stse_host_key_provisioning_wrapped_authenticated` to `stse_host_secure_channel_keys_provisioning_wrapped_authenticated` + - `stse_establish_host_key` to `stse_establish_host_secure_channel_keys` + - `stse_establish_host_key_authenticated` to `stse_establish_host_secure_channel_keys_authenticated` +- **API change** — all platform-level SecureElement initialization functions now require an additional `void *pArg` parameter ([51aa3f8](https://github.com/STMicroelectronics/STSELib/commit/51aa3f8114d33adfe38da6fd261e4b9a71a1fa9b)) +- **Platform AES API change** — all platform AES cryptographic functions now reference keys by secure storage index (`PLAT_UI32 key_idx`) instead of raw key pointer and length (`PLAT_UI8 *pKey, PLAT_UI16 key_length`). Affected functions: `stse_platform_aes_cmac_init`, `stse_platform_aes_cmac_compute`, `stse_platform_aes_cmac_verify`, `stse_platform_aes_cbc_enc`, `stse_platform_aes_cbc_dec`, `stse_platform_aes_ecb_enc` +- **Renamed** `stsafea_open_host_session` to `stsafea_open_host_session_from_idx` — signature updated to accept key indices (`PLAT_UI32 host_MAC_key_idx`, `PLAT_UI32 host_cypher_key_idx`) instead of raw key pointers +- **printf() calls replaced** with `stse_platform_printf()` in all library code to abstract away standard I/O and allow platform-specific implementations for logging and output +- **API change** — `stse_get_ecc_key_type_from_curve_id` now returns the resolved `stse_ecc_key_type_t` directly (or `STSE_ECC_KT_INVALID` if unknown) and takes a single packed `stsafea_ecc_curve_id_t` pointer, replacing the previous `PLAT_UI8 curve_id_length`, `const PLAT_UI8 *pCurve_id_value` and `stse_ecc_key_type_t *pKey_type` parameters + +### Added + +- `stse_platform_store_aes_key()` — new platform function to store an AES key into platform secure storage and retrieve its index +- `stse_platform_delete_aes_key()` — new platform function to delete an AES key from platform secure storage by index +- `stse_platform_printf()` — new platform function for formatted output, replacing all direct calls to `printf()` in the library with this abstraction to allow platform-specific implementations and avoid direct use of standard I/O in library code + +### Changed + +### Deprecated + +### Removed +- `stsafea_open_host_session` function. Now replaced by `stsafea_open_host_session_from_idx` which accepts key indices instead of raw key pointers. Note that you must first store the AES keys in platform secure storage using `stse_platform_store_aes_key()` to obtain the required indices before opening a host session. +- `stsafea_host_key_type_t` enum. Usage replaced by existing `stse_aes_key_type_t` enum. +- `stsafea_aes_128_host_keys_t` type. +- `stsafea_aes_256_host_keys_t` type. +- `stsafea_host_keys_t` type. + +### Fixed +- `stse_get_device_certificate_size()` now decodes the X.509 DER TLV header instead of assuming a fixed 2-byte length field, correctly sizing certificates that use the short form or a 1-byte long-form length. Invalid or corrupted certificates are now detected and rejected (non-`SEQUENCE` tag, forbidden indefinite length, non-minimal or zero length, sizes exceeding the 16-bit output) returning `STSE_CERT_UNEXPECTED_SEQUENCE` / `STSE_CERT_INVALID_CERTIFICATE` instead of a wrong size. +- `stse_device_authenticate()` now reuses `stse_get_device_certificate_size()` to determine the certificate size instead of duplicating the inline 2-byte length computation, so it benefits from the corrected DER TLV parsing and the malformed-certificate validation. + +### Security +- AES keys are now securely stored in platform secure storage and referenced by index, eliminating the need to handle raw key material in application memory and enhancing overall security. + +--- + +## [V1.1.7 — March 4, 2026](https://github.com/STMicroelectronics/STSELib/releases/tag/v1.1.7) diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..99ae34d3 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,140 @@ +pipeline { + agent { + label 'labo_agent' + } + environment { + GIT_REPO = 'git@github.st.com:STInternal-CS-Authentication/STSELib_Validation.git' + DATE = java.time.LocalDate.now() + } + stages { + stage('Clone repository') { + steps { + script { + dir("${BUILD_ID}") + { + bat 'git clone %GIT_REPO% .' + bat 'git checkout origin/dev/1.2.0' + bat 'git submodule update --init' + } + } + } + } + stage('Checkout STSELib dev/1.2.0 HEAD') { + steps { + dir("${BUILD_ID}/Middleware/STSELib") { + script { + if (params.STSELIB_PR?.trim()) { + bat "git fetch origin +refs/pull/%STSELIB_PR%/head:pr-%STSELIB_PR%" + bat "git checkout pr-%STSELIB_PR%" + } else { + echo "No STSELIB_PR provided, keeping submodule revision" + } + } + } + } + } + stage('Build project') { + steps { + dir("${BUILD_ID}") { + script { + bat '''"C:\\ST\\STM32CubeIDE_1.16.1\\STM32CubeIDE\\stm32cubeide.exe" ^ + --launcher.suppressErrors ^ + -nosplash ^ + -application org.eclipse.cdt.managedbuilder.core.headlessbuild ^ + -data .\\temp ^ + -importAll .\\Application\\STSE_Test_project\\STM32CubeIDE^ + -I .\\..\\..\\..\\Middleware\\EasyTest\\src ^ + -build STSE_Test_project/Debug''' + } + } + } + } + stage('Perform Functional Test') { + steps { + dir("${BUILD_ID}") { + script { + // Get the current date in YYYY-MM-DD format + bat 'c:\\ST\\STM32CubeCLT_1.18.0\\STM32CubeProgrammer\\bin\\STM32_Programmer_CLI.exe -c port=SWD freq=4000 sn=0669FF564957886687062320 -w .\\Application\\STSE_Test_project\\STM32CubeIDE\\Debug\\STSE_Test_project_Debug.elf' + bat 'c:\\ST\\STM32CubeCLT_1.18.0\\STM32CubeProgrammer\\bin\\STM32_Programmer_CLI.exe -c port=SWD freq=4000 sn=0669FF564957886687062320 -rst' + try { + bat 'python .\\Middleware\\STSE_CI_CD\\Tools\\com_logger\\com_logger.py .\\Middleware\\STSE_CI_CD\\Tools\\com_logger\\com_logger_config.json' + } catch (Exception e) { + bat """ + powershell -Command "python .\\Middleware\\STSE_CI_CD\\Tools\\com_logger\\md_to_html.py test_report.md STSELib_${BUILD_ID}_${DATE}_test_report.html" + """ + error("Build failed due to an error: ${e.message}") + } + bat """ + powershell -Command "python .\\Middleware\\STSE_CI_CD\\Tools\\com_logger\\md_to_html.py test_report.md STSELib_${BUILD_ID}_${DATE}_test_report.html" + """ + } + } + } + } + stage('Generate Documentation') { + steps { + dir("${BUILD_ID}/Middleware/STSELib/doc/resources/") { + script { + bat 'doxygen STSELib.doxyfile' + } + } + } + } + } + post { + always { + // Get the current date in YYYY-MM-DD format + dir("${BUILD_ID}") { + script { + archiveArtifacts artifacts: '*.html', fingerprint: true + } + } + dir("${BUILD_ID}/Middleware/") { + script { + // Remove everything in STSELib/doc/resources except __html and Pictures + bat ''' + REM Remove all folders except __html and Pictures + for /d %%D in ("STSELib\\doc\\resources\\*") do ( + if /i not "%%~nxD"=="__html" if /i not "%%~nxD"=="Pictures" rmdir /s /q "%%D" + ) + + REM Remove all files except those in __html and Pictures + for %%F in ("STSELib\\doc\\resources\\*") do ( + if /i not "%%~nxF"=="__html" if /i not "%%~nxF"=="Pictures" del /q "%%F" + ) + ''' + // Remove the resources@tmp folder before zipping + bat ''' + REM Remove the resources@tmp folder + if exist "STSELib\\doc\\resources@tmp" rmdir /s /q "STSELib\\doc\\resources@tmp" + ''' + // Create the documentation release package + bat """ + powershell -Command "Compress-Archive -Path 'STSELib\\doc\\*' -DestinationPath 'STSELib_nightly_${BUILD_ID}_${DATE}_documentation.zip' -Force" + """ + // Remove unwanted files and folders from STSELib + bat ''' + REM Remove unwanted folders + if exist "STSELib\\.github" rmdir /s /q "STSELib\\.github" + if exist "STSELib\\.vscode" rmdir /s /q "STSELib\\.vscode" + if exist "STSELib\\doc" rmdir /s /q "STSELib\\doc" + REM Remove unwanted files + if exist "STSELib\\.gitignore" del /q "STSELib\\.gitignore" + if exist "STSELib\\.gitmodules" del /q "STSELib\\.gitmodules" + if exist "STSELib\\.pre-commit-config.yaml" del /q "STSELib\\.pre-commit-config.yaml" + if exist "STSELib\\CODE_OF_CONDUCT.md" del /q "STSELib\\CODE_OF_CONDUCT.md" + if exist "STSELib\\CONTRIBUTING.md" del /q "STSELib\\CONTRIBUTING.md" + ''' + // Create the release file including build number and date + bat """ + powershell -Command "Compress-Archive -Path 'STSELib\\*' -DestinationPath 'STSELib_nightly_${BUILD_ID}_${DATE}.zip' -Force" + """ + // Archive the release in Jenkins + archiveArtifacts artifacts: "STSELib_nightly_${BUILD_ID}_*", fingerprint: true + } + } + // Clean-up the workspace + deleteDir() + } + } +} diff --git a/README.md b/README.md index b8052a16..3aec9fa7 100644 --- a/README.md +++ b/README.md @@ -64,10 +64,15 @@ Following applicative project can be used as reference for STSELib integration a - STSAFE-A - [stsafe-a-sdk](https://github.com/STMicroelectronics/STSAFE-A120-sdk) - [wolfssl-examples](https://github.com/wolfSSL/wolfssl-examples/tree/master/stsafe) developed and maintained by [WolfSSL](https://www.wolfssl.com/) - - [Zephyr_st-stsafe-a1xx](https://github.com/catie-aq/zephyr_st-stsafe-a1xx) developed and maintained by [CATIE](https://www.catie.fr/language/en/home/) + - [zephyr_st-stsafe-a1xx](https://github.com/catie-aq/zephyr_st-stsafe-a1xx) developed and maintained by [CATIE](https://www.catie.fr/language/en/home/) - STSAFE-L - [STSAFE-L_echo](https://github.com/STMicroelectronics/STSAFE-L_echo) - [STSAFE-L_device_authentication](https://github.com/STMicroelectronics/STSAFE-L_device_authentication) - [STSAFE-L_secure_data_storage](https://github.com/STMicroelectronics/STSAFE-L_secure_data_storage) + +## Changelog + +See [CHANGELOG.md](CHANGELOG.md) for the full history of changes. +For releases prior to v1.2.0, refer to the [GitHub Releases page](https://github.com/STMicroelectronics/STSELib/releases). diff --git a/api/stse_aes.c b/api/stse_aes.c index f019f9da..b709a8a7 100644 --- a/api/stse_aes.c +++ b/api/stse_aes.c @@ -21,7 +21,7 @@ #include "api/stse_aes.h" stse_ReturnCode_t stse_aes_ecb_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 message_length, PLAT_UI8 *pPlaintext_message, @@ -43,7 +43,7 @@ stse_ReturnCode_t stse_aes_ecb_encrypt( } stse_ReturnCode_t stse_aes_ecb_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 message_length, PLAT_UI8 *pEncrypted_message, @@ -65,7 +65,7 @@ stse_ReturnCode_t stse_aes_ecb_decrypt( } stse_ReturnCode_t stse_aes_ccm_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI8 *pNonce, @@ -96,7 +96,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt( } stse_ReturnCode_t stse_aes_ccm_encrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 Nonce_length, PLAT_UI8 *pNonce, @@ -134,7 +134,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt_start( } stse_ReturnCode_t stse_aes_ccm_encrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -158,7 +158,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt_process( } stse_ReturnCode_t stse_aes_ccm_encrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -186,7 +186,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt_finish( } stse_ReturnCode_t stse_aes_ccm_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI8 *pNonce, @@ -220,7 +220,7 @@ stse_ReturnCode_t stse_aes_ccm_decrypt( } stse_ReturnCode_t stse_aes_gcm_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI16 IV_length, @@ -254,7 +254,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt( } stse_ReturnCode_t stse_aes_ccm_decrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 Nonce_length, PLAT_UI8 *pNonce, @@ -288,7 +288,7 @@ stse_ReturnCode_t stse_aes_ccm_decrypt_start( } stse_ReturnCode_t stse_aes_ccm_decrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -312,7 +312,7 @@ stse_ReturnCode_t stse_aes_ccm_decrypt_process( } stse_ReturnCode_t stse_aes_ccm_decrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -342,7 +342,7 @@ stse_ReturnCode_t stse_aes_ccm_decrypt_finish( } stse_ReturnCode_t stse_aes_gcm_encrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -372,7 +372,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt_start( } stse_ReturnCode_t stse_aes_gcm_encrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -396,7 +396,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt_process( } stse_ReturnCode_t stse_aes_gcm_encrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -424,7 +424,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt_finish( } stse_ReturnCode_t stse_aes_gcm_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI16 IV_length, @@ -460,7 +460,7 @@ stse_ReturnCode_t stse_aes_gcm_decrypt( } stse_ReturnCode_t stse_aes_gcm_decrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -490,7 +490,7 @@ stse_ReturnCode_t stse_aes_gcm_decrypt_start( } stse_ReturnCode_t stse_aes_gcm_decrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -514,7 +514,7 @@ stse_ReturnCode_t stse_aes_gcm_decrypt_process( } stse_ReturnCode_t stse_aes_gcm_decrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, diff --git a/api/stse_aes.h b/api/stse_aes.h index fd95fede..e16ee9b6 100644 --- a/api/stse_aes.h +++ b/api/stse_aes.h @@ -43,7 +43,7 @@ * \details \include{doc} stse_aes_ecb_encrypt.dox */ stse_ReturnCode_t stse_aes_ecb_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 message_length, PLAT_UI8 *pPlaintext_message, @@ -61,7 +61,7 @@ stse_ReturnCode_t stse_aes_ecb_encrypt( * \details \include{doc} stse_aes_ecb_decrypt.dox */ stse_ReturnCode_t stse_aes_ecb_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 message_length, PLAT_UI8 *pEncrypted_message, @@ -86,7 +86,7 @@ stse_ReturnCode_t stse_aes_ecb_decrypt( * \details \include{doc} stse_aes_ccm_encrypt.dox */ stse_ReturnCode_t stse_aes_ccm_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI8 *pNonce, @@ -118,7 +118,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_ccm_encrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 Nonce_length, PLAT_UI8 *pNonce, @@ -144,7 +144,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt_start( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_ccm_encrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -165,7 +165,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt_process( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_ccm_encrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -192,7 +192,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt_finish( * \details \include{doc} stse_aes_ccm_decrypt.dox */ stse_ReturnCode_t stse_aes_ccm_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI8 *pNonce, @@ -221,7 +221,7 @@ stse_ReturnCode_t stse_aes_ccm_decrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_ccm_decrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 Nonce_length, PLAT_UI8 *pNonce, @@ -245,7 +245,7 @@ stse_ReturnCode_t stse_aes_ccm_decrypt_start( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_ccm_decrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -267,7 +267,7 @@ stse_ReturnCode_t stse_aes_ccm_decrypt_process( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_ccm_decrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -294,7 +294,7 @@ stse_ReturnCode_t stse_aes_ccm_decrypt_finish( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gcm_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI16 IV_length, @@ -321,7 +321,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gcm_encrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -343,7 +343,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt_start( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gcm_encrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -364,7 +364,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt_process( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gcm_encrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -391,7 +391,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt_finish( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gcm_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI16 IV_length, @@ -419,7 +419,7 @@ stse_ReturnCode_t stse_aes_gcm_decrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gcm_decrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -441,7 +441,7 @@ stse_ReturnCode_t stse_aes_gcm_decrypt_start( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gcm_decrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -463,7 +463,7 @@ stse_ReturnCode_t stse_aes_gcm_decrypt_process( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gcm_decrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, diff --git a/api/stse_asymmetric_keys_management.c b/api/stse_asymmetric_keys_management.c index 28b558dd..25e2c4a5 100644 --- a/api/stse_asymmetric_keys_management.c +++ b/api/stse_asymmetric_keys_management.c @@ -22,7 +22,7 @@ #include "api/stse_asymmetric_keys_management.h" stse_ReturnCode_t stse_get_ecc_key_slots_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pPrivate_key_slot_count) { #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t ret; @@ -44,7 +44,7 @@ stse_ReturnCode_t stse_get_ecc_key_slots_count( } stse_ReturnCode_t stse_get_ecc_key_table_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_count, PLAT_UI16 *pGlobal_usage_limit, stsafea_private_key_slot_information_t *private_key_table_info) { @@ -68,7 +68,7 @@ stse_ReturnCode_t stse_get_ecc_key_table_info( } stse_ReturnCode_t stse_get_ecc_key_slot_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_number, PLAT_UI16 *pGlobal_usage_limit, stsafea_private_key_slot_information_t *private_key_slot_info) { @@ -114,7 +114,7 @@ stse_ReturnCode_t stse_get_ecc_key_slot_info( } stse_ReturnCode_t stse_generate_ECDHE_key_pair( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key) { #ifdef STSE_CONF_STSAFE_A_SUPPORT @@ -137,7 +137,7 @@ stse_ReturnCode_t stse_generate_ECDHE_key_pair( } stse_ReturnCode_t stse_generate_ecc_key_pair( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI16 usage_limit, @@ -162,7 +162,7 @@ stse_ReturnCode_t stse_generate_ecc_key_pair( } stse_ReturnCode_t stse_write_generic_ecc_public_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key) { @@ -186,7 +186,7 @@ stse_ReturnCode_t stse_write_generic_ecc_public_key( } stse_ReturnCode_t stse_sign_for_generic_public_key_slot( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t private_key_type, PLAT_UI8 *pPrivate_key, stse_hash_algorithm_t hash_algo, diff --git a/api/stse_asymmetric_keys_management.h b/api/stse_asymmetric_keys_management.h index 8241b5ee..579fff0c 100644 --- a/api/stse_asymmetric_keys_management.h +++ b/api/stse_asymmetric_keys_management.h @@ -42,7 +42,7 @@ * \details \include{doc} stse_get_ecc_key_slots_count.dox */ stse_ReturnCode_t stse_get_ecc_key_slots_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pPrivate_key_slot_count); /** @@ -56,7 +56,7 @@ stse_ReturnCode_t stse_get_ecc_key_slots_count( * \details \include{doc} stse_get_ecc_key_table_info.dox */ stse_ReturnCode_t stse_get_ecc_key_table_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_count, PLAT_UI16 *pGlobal_usage_limit, stsafea_private_key_slot_information_t *private_key_table_info); @@ -72,7 +72,7 @@ stse_ReturnCode_t stse_get_ecc_key_table_info( * \details \include{doc} stse_get_ecc_key_slot_info.dox */ stse_ReturnCode_t stse_get_ecc_key_slot_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_number, PLAT_UI16 *pGlobal_usage_limit, stsafea_private_key_slot_information_t *private_key_slot_info); @@ -80,7 +80,8 @@ stse_ReturnCode_t stse_get_ecc_key_slot_info( /** * \brief Generate an ECDHE key pair * \details This API request STSE to generate an ECDHE key pair. - * If the slot is already seeded, it will be overwritten with the new key + * If the slot is already seeded, it will be overwritten with the new key. + * Note that the slot 0 can't be reprovisionned. * \param[in] pSTSE Pointer to STSE Handler * \param[in] key_type Key type to generate * \param[out] pPublic_key Public key of the generated key pair @@ -88,14 +89,15 @@ stse_ReturnCode_t stse_get_ecc_key_slot_info( * \details \include{doc} stse_generate_ECDHE_key_pair.dox */ stse_ReturnCode_t stse_generate_ECDHE_key_pair( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key); /** * \brief Generate an ECC key pair * \details This API requests the STSE to generate an ECC key pair in the private key table. - * If the slot is already seeded, it will be overwritten with the new key + * If the slot is already seeded, it will be overwritten with the new key. + * Note that the slot 0 can't be reprovisionned. * \param[in] pSTSE Pointer to STSE Handler * \param[in] slot_number Private key table slot used to generate the key pair * \param[in] key_type Key pair type @@ -105,7 +107,7 @@ stse_ReturnCode_t stse_generate_ECDHE_key_pair( * \details \include{doc} stse_generate_ecc_key_pair.dox */ stse_ReturnCode_t stse_generate_ecc_key_pair( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI16 usage_limit, @@ -122,7 +124,7 @@ stse_ReturnCode_t stse_generate_ecc_key_pair( * \details \include{doc} stse_write_generic_ecc_public_key.dox */ stse_ReturnCode_t stse_write_generic_ecc_public_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key); @@ -142,7 +144,7 @@ stse_ReturnCode_t stse_write_generic_ecc_public_key( * \warning Few specific cryptographic library required to have public key concatenated to private key for EdDSA mechanism. In such case, pPrivate_key pointer shall reference concatenated key pair buffer's address. */ stse_ReturnCode_t stse_sign_for_generic_public_key_slot( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t private_key_type, PLAT_UI8 *pPrivate_key, stse_hash_algorithm_t hash_algo, diff --git a/api/stse_data_storage.c b/api/stse_data_storage.c index b2231ae6..8f73a003 100644 --- a/api/stse_data_storage.c +++ b/api/stse_data_storage.c @@ -21,7 +21,7 @@ #include stse_ReturnCode_t stse_data_storage_get_total_partition_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *total_partition_count) { stse_ReturnCode_t ret = STSE_API_INCOMPATIBLE_DEVICE_TYPE; @@ -40,7 +40,7 @@ stse_ReturnCode_t stse_data_storage_get_total_partition_count( } stse_ReturnCode_t stse_data_storage_get_partitioning_table( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 total_partition_count, stsafea_data_partition_record_t *pPartitioning_table, PLAT_UI16 partitioning_table_size) { @@ -61,7 +61,7 @@ stse_ReturnCode_t stse_data_storage_get_partitioning_table( } stse_ReturnCode_t stse_data_storage_read_data_zone( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, PLAT_UI16 offset, PLAT_UI8 *pBuffer, @@ -141,10 +141,10 @@ stse_ReturnCode_t stse_data_storage_read_data_zone( } stse_ReturnCode_t stse_data_storage_update_data_zone( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, PLAT_UI16 offset, - PLAT_UI8 *pBuffer, + const PLAT_UI8 *pBuffer, PLAT_UI16 length, stse_zone_update_atomicity_t atomicity, stse_cmd_protection_t protection) { @@ -199,7 +199,7 @@ stse_ReturnCode_t stse_data_storage_update_data_zone( } stse_ReturnCode_t stse_data_storage_decrement_counter_zone( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, PLAT_UI32 amount, PLAT_UI16 offset, @@ -261,7 +261,7 @@ stse_ReturnCode_t stse_data_storage_decrement_counter_zone( } stse_ReturnCode_t stse_data_storage_read_counter_zone( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, PLAT_UI16 offset, PLAT_UI8 *pBuffer, @@ -336,7 +336,7 @@ stse_ReturnCode_t stse_data_storage_read_counter_zone( } stse_ReturnCode_t stse_data_storage_change_read_access_condition( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, stse_zone_ac_t ac, stse_ac_change_right_t ac_change_right, @@ -368,7 +368,7 @@ stse_ReturnCode_t stse_data_storage_change_read_access_condition( #endif /* STSE_CONF_STSAFE_A_SUPPORT */ } -stse_ReturnCode_t stse_data_storage_change_update_access_condition(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_data_storage_change_update_access_condition(stse_Handle_t *pSTSE, PLAT_UI32 zone, stse_zone_ac_t ac, stse_ac_change_right_t ac_change_right, @@ -405,7 +405,7 @@ stse_ReturnCode_t stse_data_storage_change_update_access_condition(stse_Handler_ #endif /* STSE_CONF_STSAFE_A_SUPPORT */ } -stse_ReturnCode_t stse_data_storage_change_decrement_access_condition(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_data_storage_change_decrement_access_condition(stse_Handle_t *pSTSE, PLAT_UI32 zone, stse_zone_ac_t ac, stse_ac_change_right_t ac_change_right, diff --git a/api/stse_data_storage.h b/api/stse_data_storage.h index c8b4ce12..e3cef9fa 100644 --- a/api/stse_data_storage.h +++ b/api/stse_data_storage.h @@ -40,7 +40,7 @@ * \details \include{doc} stse_data_storage_get_total_partition_count.dox */ stse_ReturnCode_t stse_data_storage_get_total_partition_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pTotal_partition_count); /** @@ -54,7 +54,7 @@ stse_ReturnCode_t stse_data_storage_get_total_partition_count( * \details \include{doc} stse_data_storage_get_partitioning_table.dox */ stse_ReturnCode_t stse_data_storage_get_partitioning_table( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 total_partition_count, stsafea_data_partition_record_t *pPartitioning_table, PLAT_UI16 partitioning_table_size); @@ -77,7 +77,7 @@ stse_ReturnCode_t stse_data_storage_get_partitioning_table( * \details \include{doc} stse_data_storage_read_zone.dox */ stse_ReturnCode_t stse_data_storage_read_data_zone( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, PLAT_UI16 offset, PLAT_UI8 *pBuffer, @@ -103,10 +103,10 @@ stse_ReturnCode_t stse_data_storage_read_data_zone( * \details \include{doc} stse_data_storage_update_zone.dox */ stse_ReturnCode_t stse_data_storage_update_data_zone( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, PLAT_UI16 offset, - PLAT_UI8 *pBuffer, + const PLAT_UI8 *pBuffer, PLAT_UI16 length, stse_zone_update_atomicity_t atomicity, stse_cmd_protection_t protection); @@ -130,7 +130,7 @@ stse_ReturnCode_t stse_data_storage_update_data_zone( * \details \include{doc} stse_data_storage_decrement_counter.dox */ stse_ReturnCode_t stse_data_storage_decrement_counter_zone( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, PLAT_UI32 amount, PLAT_UI16 offset, @@ -158,7 +158,7 @@ stse_ReturnCode_t stse_data_storage_decrement_counter_zone( * \details \include{doc} stse_data_storage_read_counter.dox */ stse_ReturnCode_t stse_data_storage_read_counter_zone( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, PLAT_UI16 offset, PLAT_UI8 *pBuffer, @@ -183,7 +183,7 @@ stse_ReturnCode_t stse_data_storage_read_counter_zone( * \details \include{doc} stse_data_storage_change_read_access_condition.dox */ stse_ReturnCode_t stse_data_storage_change_read_access_condition( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, stse_zone_ac_t ac, stse_ac_change_right_t ac_change_right, @@ -208,7 +208,7 @@ stse_ReturnCode_t stse_data_storage_change_read_access_condition( * it's not possible to revert to a less restrictive one (e.g. STSE_AC_HOST -> STSE_AC_ALWAYS). * \details \include{doc} stse_data_storage_change_update_access_condition.dox */ -stse_ReturnCode_t stse_data_storage_change_update_access_condition(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_data_storage_change_update_access_condition(stse_Handle_t *pSTSE, PLAT_UI32 zone, stse_zone_ac_t ac, stse_ac_change_right_t ac_change_right, @@ -239,7 +239,7 @@ stse_ReturnCode_t stse_data_storage_change_update_access_condition(stse_Handler_ * \details \include{doc} stse_data_storage_change_decrement_access_condition.dox */ stse_ReturnCode_t stse_data_storage_change_decrement_access_condition( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI32 zone, stse_zone_ac_t ac, stse_ac_change_right_t ac_change_right, diff --git a/api/stse_derive_keys.c b/api/stse_derive_keys.c index c6fa5f94..07d45ee8 100644 --- a/api/stse_derive_keys.c +++ b/api/stse_derive_keys.c @@ -24,7 +24,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stse_derive_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI8 *pSalt, PLAT_UI16 salt_length, @@ -78,7 +78,7 @@ stse_ReturnCode_t stse_derive_key( } stse_ReturnCode_t stse_derive_key_simple( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI8 *pContext, PLAT_UI16 context_len, @@ -97,7 +97,7 @@ stse_ReturnCode_t stse_derive_key_simple( } stse_ReturnCode_t stse_derive_key_extract( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI8 *pSalt, PLAT_UI16 salt_length, @@ -140,7 +140,7 @@ stse_ReturnCode_t stse_derive_key_extract( } stse_ReturnCode_t stse_derive_key_expand( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 prk_slot, PLAT_UI8 *pContext, PLAT_UI16 context_len, @@ -186,7 +186,7 @@ stse_ReturnCode_t stse_derive_key_expand( } stse_ReturnCode_t stse_derive_session_keys( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI32 session_id, PLAT_UI8 *pEnc_key, @@ -229,7 +229,7 @@ stse_ReturnCode_t stse_derive_session_keys( } stse_ReturnCode_t stse_derive_key_to_slot( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI8 *pSalt, PLAT_UI16 salt_length, @@ -289,7 +289,7 @@ stse_ReturnCode_t stse_derive_key_to_slot( } stse_ReturnCode_t stse_derive_key_expand_multiple( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 prk_slot, PLAT_UI8 **pContexts, PLAT_UI16 *pContext_lens, @@ -346,7 +346,7 @@ stse_ReturnCode_t stse_derive_key_expand_multiple( } stse_ReturnCode_t stse_derive_key_from_ikm( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pIkm, PLAT_UI16 ikm_length, PLAT_UI8 *pSalt, diff --git a/api/stse_derive_keys.h b/api/stse_derive_keys.h index e7ce40ca..bf2e69a2 100644 --- a/api/stse_derive_keys.h +++ b/api/stse_derive_keys.h @@ -43,7 +43,7 @@ * \details \include{doc} stse_derive_key.dox */ stse_ReturnCode_t stse_derive_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI8 *pSalt, PLAT_UI16 salt_length, @@ -66,7 +66,7 @@ stse_ReturnCode_t stse_derive_key( * \details \include{doc} stse_derive_key_simple.dox */ stse_ReturnCode_t stse_derive_key_simple( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI8 *pContext, PLAT_UI16 context_len, @@ -86,7 +86,7 @@ stse_ReturnCode_t stse_derive_key_simple( * \details \include{doc} stse_derive_key_extract.dox */ stse_ReturnCode_t stse_derive_key_extract( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI8 *pSalt, PLAT_UI16 salt_length, @@ -105,7 +105,7 @@ stse_ReturnCode_t stse_derive_key_extract( * \details \include{doc} stse_derive_key_expand.dox */ stse_ReturnCode_t stse_derive_key_expand( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 prk_slot, PLAT_UI8 *pContext, PLAT_UI16 context_len, @@ -129,7 +129,7 @@ stse_ReturnCode_t stse_derive_key_expand( * \details \include{doc} stse_derive_session_keys.dox */ stse_ReturnCode_t stse_derive_session_keys( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI32 session_id, PLAT_UI8 *pEnc_key, @@ -153,7 +153,7 @@ stse_ReturnCode_t stse_derive_session_keys( * \details \include{doc} stse_derive_key_to_slot.dox */ stse_ReturnCode_t stse_derive_key_to_slot( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 master_slot, PLAT_UI8 *pSalt, PLAT_UI16 salt_length, @@ -177,7 +177,7 @@ stse_ReturnCode_t stse_derive_key_to_slot( * \details \include{doc} stse_derive_key_expand_multiple.dox */ stse_ReturnCode_t stse_derive_key_expand_multiple( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 prk_slot, PLAT_UI8 **pContexts, PLAT_UI16 *pContext_lens, @@ -202,7 +202,7 @@ stse_ReturnCode_t stse_derive_key_expand_multiple( * \details \include{doc} stse_derive_key_from_ikm.dox */ stse_ReturnCode_t stse_derive_key_from_ikm( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pIkm, PLAT_UI16 ikm_length, PLAT_UI8 *pSalt, diff --git a/api/stse_device_authentication.c b/api/stse_device_authentication.c index bceafe2d..273df46e 100644 --- a/api/stse_device_authentication.c +++ b/api/stse_device_authentication.c @@ -17,6 +17,7 @@ /* Includes ------------------------------------------------------------------*/ #include +#include #include "api/stse_device_authentication.h" #include "api/stse_ecc.h" @@ -24,9 +25,8 @@ #include "certificate/stse_certificate.h" #include "certificate/stse_certificate_crypto.h" #include "certificate/stse_certificate_subparsing.h" +#include "certificate/stse_certificate_types.h" -#define STSE_CERTIFICATE_SIZE_OFFSET_BYTES 2U -#define STSE_CERTIFICATE_SIZE_LENGTH 2U #define STSE_CERTIFICATE_OFFSET_BYTES 0U #define STSE_CERTIFICATE_DEVICE_ID_OFFSET 15U #define STSE_CERTIFICATE_DEVICE_ID_SIZE 11U @@ -35,7 +35,7 @@ /* Exported functions --------------------------------------------------------*/ -stse_ReturnCode_t stse_get_device_id(stse_Handler_t *pSTSE, PLAT_UI8 certificate_zone, PLAT_UI8 *pDevice_id) { +stse_ReturnCode_t stse_get_device_id(stse_Handle_t *pSTSE, PLAT_UI8 certificate_zone, PLAT_UI8 *pDevice_id) { volatile stse_ReturnCode_t ret = STSE_API_INVALID_PARAMETER; /* - Check stsafe handler initialization */ @@ -55,9 +55,9 @@ stse_ReturnCode_t stse_get_device_id(stse_Handler_t *pSTSE, PLAT_UI8 certificate return ret; } -stse_ReturnCode_t stse_get_device_certificate_size(stse_Handler_t *pSTSE, PLAT_UI8 certificate_zone, PLAT_UI16 *pCertificate_size) { +stse_ReturnCode_t stse_get_device_certificate_size(stse_Handle_t *pSTSE, PLAT_UI8 certificate_zone, PLAT_UI16 *pCertificate_size) { volatile stse_ReturnCode_t ret = STSE_API_INVALID_PARAMETER; - PLAT_UI8 certificate_size_ui8[2]; + PLAT_UI8 tlv_header[4]; /* - Check stsafe handler initialization */ if (pSTSE == NULL) { @@ -69,24 +69,74 @@ stse_ReturnCode_t stse_get_device_certificate_size(stse_Handler_t *pSTSE, PLAT_U } ret = stse_data_storage_read_data_zone( - pSTSE, /* STSE handler */ - certificate_zone, /* Certificate zone */ - STSE_CERTIFICATE_SIZE_OFFSET_BYTES, /* 2 bytes offset */ - certificate_size_ui8, /* Returned certificate size */ - STSE_CERTIFICATE_SIZE_LENGTH, /* Certificate size length 2 bytes */ - 0, /* No maximum chunk size (No chunk at all) */ - STSE_NO_PROT); /* No protection */ + pSTSE, /* STSE handler */ + certificate_zone, /* Certificate zone */ + 0, /* No offset */ + tlv_header, /* Returned TLV header (tag + length bytes) */ + sizeof(tlv_header), /* TLV header length 4 bytes */ + 0, /* No maximum chunk size (No chunk at all) */ + STSE_NO_PROT); /* No protection */ if (ret != STSE_OK) { return ret; } - *pCertificate_size = (((uint16_t)certificate_size_ui8[0]) << 8) + ((uint16_t)certificate_size_ui8[1]) + 4U; + if (tlv_header[0] != TAG_SEQUENCE) { + /* Invalid X.509 DER certificate: the TAG is not SEQUENCE (0x30) */ + return STSE_CERT_UNEXPECTED_SEQUENCE; + } + + if (tlv_header[1] == 0x80) { + /* Invalid X.509 DER certificate: the indefinite length is not allowed in DER (it would also + * decode to len_of_len == 0, clashing with the short-form case below) */ + return STSE_CERT_INVALID_CERTIFICATE; + } + + /* The second byte encodes the Value length: below 0x80 it is the length itself (short form, no + * extra length bytes); otherwise bit 7 flags the long form and the low 7 bits tell how many of + * the following bytes encode the length (e.g. 0x82 means the next 2) */ + PLAT_UI8 len_of_len = (tlv_header[1] < 0x80) ? 0 : (tlv_header[1] & ~0x80); + + /* Decode the Value length and the smallest length the used encoding is allowed to carry: + * a certificate cannot be empty and DER requires the minimal length encoding */ + PLAT_UI16 min_size; + switch (len_of_len) { + case 0: + *pCertificate_size = tlv_header[1]; + min_size = 1; // 1 byte + break; + case 1: + *pCertificate_size = tlv_header[2]; + min_size = 0x80; // 128 bytes + break; + case 2: + *pCertificate_size = (tlv_header[2] << 8) | tlv_header[3]; + min_size = 0x100; // 256 bytes + break; + default: + /* Unsupported X.509 DER certificate: a length field longer than 2 bytes means a + * certificate larger than 65535 bytes, beyond what *pCertificate_size can represent */ + return STSE_CERT_INVALID_CERTIFICATE; + } + + if (*pCertificate_size < min_size) { + /* Invalid X.509 DER certificate: the length is zero or not minimally encoded */ + return STSE_CERT_INVALID_CERTIFICATE; + } + + /* Size of the Tag+Length field: tag byte + first length byte + extra length bytes. + * The parsed length covers the Value only, so add this to get the whole size */ + PLAT_UI8 tl_len = 2 + len_of_len; + if (*pCertificate_size > UINT16_MAX - tl_len) { + /* Invalid X.509 DER certificate: the total size overflows 16 bits */ + return STSE_CERT_INVALID_CERTIFICATE; + } + *pCertificate_size += tl_len; return STSE_OK; } -stse_ReturnCode_t stse_get_device_certificate(stse_Handler_t *pSTSE, PLAT_UI8 certificate_zone, PLAT_UI16 certificate_size, PLAT_UI8 *pCertificate) { +stse_ReturnCode_t stse_get_device_certificate(stse_Handle_t *pSTSE, PLAT_UI8 certificate_zone, PLAT_UI16 certificate_size, PLAT_UI8 *pCertificate) { volatile stse_ReturnCode_t ret = STSE_API_INVALID_PARAMETER; /* - Check stsafe handler initialization */ @@ -115,14 +165,13 @@ stse_ReturnCode_t stse_get_device_certificate(stse_Handler_t *pSTSE, PLAT_UI8 ce } stse_ReturnCode_t stse_device_authenticate( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, const PLAT_UI8 *pRoot_CA_certificate, PLAT_UI8 certificate_zone, PLAT_UI8 priv_key_slot_number) { stse_ReturnCode_t ret; stse_certificate_t leaf_certificate; PLAT_UI16 certificate_size; - PLAT_UI8 certificate_size_ui8[2]; if (pSTSE == NULL) { return (STSE_API_HANDLER_NOT_INITIALISED); @@ -132,21 +181,12 @@ stse_ReturnCode_t stse_device_authenticate( return (STSE_API_INVALID_PARAMETER); } - ret = stse_data_storage_read_data_zone( - pSTSE, - certificate_zone, - STSE_CERTIFICATE_SIZE_OFFSET_BYTES, /* 2 bytes offset */ - certificate_size_ui8, /* Returned certificate size */ - STSE_CERTIFICATE_SIZE_LENGTH, /* Certificate size length 2 bytes */ - 0, /* No maximum chunk size (No chunk at all) */ - STSE_NO_PROT); /* No protection */ + ret = stse_get_device_certificate_size(pSTSE, certificate_zone, &certificate_size); if (ret != STSE_OK) { return ret; } - certificate_size = (((uint16_t)certificate_size_ui8[0]) << 8) + ((uint16_t)certificate_size_ui8[1]) + 4U; - PLAT_UI8 certificate[certificate_size]; ret = stse_get_device_certificate(pSTSE, certificate_zone, certificate_size, certificate); diff --git a/api/stse_device_authentication.h b/api/stse_device_authentication.h index 4852fbda..23596166 100644 --- a/api/stse_device_authentication.h +++ b/api/stse_device_authentication.h @@ -40,7 +40,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_get_device_id.dox */ -stse_ReturnCode_t stse_get_device_id(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_get_device_id(stse_Handle_t *pSTSE, PLAT_UI8 certificate_zone, PLAT_UI8 *pDevice_id); @@ -53,7 +53,7 @@ stse_ReturnCode_t stse_get_device_id(stse_Handler_t *pSTSE, * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_get_device_certificate_size.dox */ -stse_ReturnCode_t stse_get_device_certificate_size(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_get_device_certificate_size(stse_Handle_t *pSTSE, PLAT_UI8 certificate_zone, PLAT_UI16 *pCertificate_size); @@ -68,7 +68,7 @@ stse_ReturnCode_t stse_get_device_certificate_size(stse_Handler_t *pSTSE, * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_get_device_certificate.dox */ -stse_ReturnCode_t stse_get_device_certificate(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_get_device_certificate(stse_Handle_t *pSTSE, PLAT_UI8 certificate_zone, PLAT_UI16 certificate_size, PLAT_UI8 *pCertificate); @@ -84,7 +84,7 @@ stse_ReturnCode_t stse_get_device_certificate(stse_Handler_t *pSTSE, * \details \include{doc} stse_device_authenticate.dox */ stse_ReturnCode_t stse_device_authenticate( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, const PLAT_UI8 *pRoot_CA_certificate, PLAT_UI8 certificate_zone, PLAT_UI8 priv_key_slot_number); diff --git a/api/stse_device_management.c b/api/stse_device_management.c index a8ba4f77..673e559e 100644 --- a/api/stse_device_management.c +++ b/api/stse_device_management.c @@ -25,8 +25,12 @@ #define IDLE_BUS_DELAY_MAX 0x1F /* Exported functions --------------------------------------------------------*/ -stse_ReturnCode_t stse_init(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stse_init(stse_Handle_t *pSTSE, void *pArg) { stse_ReturnCode_t ret = STSE_API_INVALID_PARAMETER; +#ifdef STSE_CONF_STSAFE_A_SUPPORT + PLAT_UI8 mask_id[STSAFEA_MASK_ID_SIZE]; + PLAT_UI16 mask_number; +#endif /* STSE_CONF_STSAFE_A_SUPPORT */ /* - Check STSAFE handler initialization */ if (pSTSE == NULL) { @@ -37,7 +41,7 @@ stse_ReturnCode_t stse_init(stse_Handler_t *pSTSE) { #if defined(STSE_CONF_STSAFE_A_SUPPORT) || \ (defined(STSE_CONF_STSAFE_L_SUPPORT) && defined(STSE_CONF_USE_I2C)) case STSE_BUS_TYPE_I2C: - ret = stse_platform_i2c_init(pSTSE->io.busID); + ret = stse_platform_i2c_init(pSTSE->io.busID, pArg); if (ret != STSE_OK) { return ret; } @@ -45,7 +49,7 @@ stse_ReturnCode_t stse_init(stse_Handler_t *pSTSE) { #endif /* STSE_CONF_STSAFE_A_SUPPORT || (STSE_CONF_STSAFE_L_SUPPORT && defined(STSE_CONF_USE_I2C) */ #ifdef STSE_CONF_USE_ST1WIRE case STSE_BUS_TYPE_ST1WIRE: - ret = stse_platform_st1wire_init(pSTSE->io.busID); + ret = stse_platform_st1wire_init(pSTSE->io.busID, pArg); if (ret != STSE_OK) { return ret; } @@ -68,23 +72,27 @@ stse_ReturnCode_t stse_init(stse_Handler_t *pSTSE) { } /* - Initialize Host platform */ - ret = stse_platform_generate_random_init(); + ret = stse_platform_generate_random_init(pArg); if (ret != STSE_OK) { return ret; } - ret = stse_platform_delay_init(); + ret = stse_platform_delay_init(pArg); if (ret != STSE_OK) { return ret; } - ret = stse_platform_power_init(); + ret = stse_platform_power_init(pArg); if (ret != STSE_OK) { return ret; } - ret = stse_platform_crc16_init(); + ret = stse_device_power_on(pSTSE); if (ret != STSE_OK) { return ret; } - ret = stse_platform_crypto_init(); + ret = stse_platform_crc16_init(pArg); + if (ret != STSE_OK) { + return ret; + } + ret = stse_platform_crypto_init(pArg); if (ret != STSE_OK) { return ret; } @@ -93,9 +101,23 @@ stse_ReturnCode_t stse_init(stse_Handler_t *pSTSE) { #ifdef STSE_CONF_STSAFE_L_SUPPORT if (pSTSE->device_type != STSAFE_L010) { #endif /* STSE_CONF_STSAFE_L_SUPPORT */ - stse_platform_Delay_ms(stsafea_boot_time[pSTSE->device_type]); - #ifndef STSE_CONF_USE_STATIC_PERSONALIZATION_INFORMATIONS + ret = stsafea_query_mask_id(pSTSE, mask_id); + if (ret != STSE_OK) { + return ret; + } + + mask_number = (mask_id[STSAFEA_MASK_ID_SIZE - 2] << 8) + mask_id[STSAFEA_MASK_ID_SIZE - 1]; + if (mask_number >= 0x6000) { + pSTSE->device_type = STSAFE_A120; + } else if (mask_number >= 0x4600) { + pSTSE->device_type = STSAFE_A110; + } else if (mask_number >= 0x4000) { + pSTSE->device_type = STSAFE_A100; + } else { + return (STSE_SERVICE_INCOMPATIBLE_DEVICE_TYPE); + } + ret = stsafea_perso_info_update(pSTSE); #endif /* STSE_CONF_USE_STATIC_PERSONALIZATION_INFORMATIONS */ #ifdef STSE_CONF_STSAFE_L_SUPPORT @@ -106,7 +128,7 @@ stse_ReturnCode_t stse_init(stse_Handler_t *pSTSE) { return ret; } -stse_ReturnCode_t stse_device_enter_hibernate(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_device_enter_hibernate(stse_Handle_t *pSTSE, stse_hibernate_wake_up_mode_t wake_up_mode) { stse_ReturnCode_t ret = STSE_API_INCOMPATIBLE_DEVICE_TYPE; @@ -135,7 +157,7 @@ stse_ReturnCode_t stse_device_enter_hibernate(stse_Handler_t *pSTSE, return ret; } -stse_ReturnCode_t stse_device_power_on(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stse_device_power_on(stse_Handle_t *pSTSE) { /* - Check STSE handler initialization */ if (pSTSE == NULL) { return (STSE_API_HANDLER_NOT_INITIALISED); @@ -169,7 +191,7 @@ stse_ReturnCode_t stse_device_power_on(stse_Handler_t *pSTSE) { return (STSE_OK); } -stse_ReturnCode_t stse_device_power_off(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stse_device_power_off(stse_Handle_t *pSTSE) { /* - Check STSE handler initialization */ if (pSTSE == NULL) { return (STSE_API_HANDLER_NOT_INITIALISED); @@ -185,7 +207,7 @@ stse_ReturnCode_t stse_device_power_off(stse_Handler_t *pSTSE) { return (STSE_OK); } -stse_ReturnCode_t stse_device_echo(stse_Handler_t *pSTSE, PLAT_UI8 *pIn, PLAT_UI8 *pOut, PLAT_UI16 size) { +stse_ReturnCode_t stse_device_echo(stse_Handle_t *pSTSE, PLAT_UI8 *pIn, PLAT_UI8 *pOut, PLAT_UI16 size) { /* - Check STSAFE handler initialization */ if (pSTSE == NULL) { return (STSE_API_HANDLER_NOT_INITIALISED); @@ -207,7 +229,7 @@ stse_ReturnCode_t stse_device_echo(stse_Handler_t *pSTSE, PLAT_UI8 *pIn, PLAT_UI } } -stse_ReturnCode_t stse_device_lock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, PLAT_UI8 password_length) { +stse_ReturnCode_t stse_device_lock(stse_Handle_t *pSTSE, PLAT_UI8 *pPassword, PLAT_UI8 password_length) { #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t ret; PLAT_UI8 password_verification_status = 0; @@ -251,7 +273,7 @@ stse_ReturnCode_t stse_device_lock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, P #endif /* STSE_CONF_STSAFE_A_SUPPORT */ } -stse_ReturnCode_t stse_device_unlock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, PLAT_UI8 password_length) { +stse_ReturnCode_t stse_device_unlock(stse_Handle_t *pSTSE, PLAT_UI8 *pPassword, PLAT_UI8 password_length) { #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t ret; PLAT_UI8 password_verification_status = 0; @@ -296,7 +318,7 @@ stse_ReturnCode_t stse_device_unlock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, #endif /* STSE_CONF_STSAFE_A_SUPPORT */ } -stse_ReturnCode_t stse_device_reset(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stse_device_reset(stse_Handle_t *pSTSE) { stse_ReturnCode_t ret = STSE_API_INCOMPATIBLE_DEVICE_TYPE; /* - Check STSAFE handler initialization */ @@ -324,7 +346,7 @@ stse_ReturnCode_t stse_device_reset(stse_Handler_t *pSTSE) { return ret; } -stse_ReturnCode_t stse_device_get_command_count(stse_Handler_t *pSTSE, PLAT_UI8 *pRecord_count) { +stse_ReturnCode_t stse_device_get_command_count(stse_Handle_t *pSTSE, PLAT_UI8 *pRecord_count) { #ifdef STSE_CONF_STSAFE_A_SUPPORT /* - Check STSAFE handler initialization */ if (pSTSE == NULL) { @@ -343,7 +365,7 @@ stse_ReturnCode_t stse_device_get_command_count(stse_Handler_t *pSTSE, PLAT_UI8 #endif /* STSE_CONF_STSAFE_A_SUPPORT */ } -stse_ReturnCode_t stse_device_get_command_AC_records(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_device_get_command_AC_records(stse_Handle_t *pSTSE, PLAT_UI8 record_count, stse_cmd_authorization_CR_t *pChange_rights, stse_cmd_authorization_record_t *pRecord_table) { @@ -365,7 +387,7 @@ stse_ReturnCode_t stse_device_get_command_AC_records(stse_Handler_t *pSTSE, #endif /* STSE_CONF_STSAFE_A_SUPPORT */ } -stse_ReturnCode_t stse_device_get_life_cycle_state(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_device_get_life_cycle_state(stse_Handle_t *pSTSE, stsafea_life_cycle_state_t *pLife_cycle_state) { #ifdef STSE_CONF_STSAFE_A_SUPPORT /* - Check STSAFE handler initialization */ @@ -386,7 +408,7 @@ stse_ReturnCode_t stse_device_get_life_cycle_state(stse_Handler_t *pSTSE, } stse_ReturnCode_t stse_put_i2c_parameters( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 i2c_address, stse_low_power_mode_t low_power_mode, PLAT_UI8 idle_bus_time_to_standby, diff --git a/api/stse_device_management.h b/api/stse_device_management.h index 63af18c9..e0b7b6a3 100644 --- a/api/stse_device_management.h +++ b/api/stse_device_management.h @@ -59,10 +59,11 @@ typedef enum stse_low_power_mode_t { * \details This function call the handler initialization function from core layer * to initialize STSE handler in argument * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pArg Argument passed as-is to the `stse_platform_xxx_init()` functions through their `pArg` parameter * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_init.dox */ -stse_ReturnCode_t stse_init(stse_Handler_t *pSTSE); +stse_ReturnCode_t stse_init(stse_Handle_t *pSTSE, void *pArg); /** * \brief Reset target device @@ -70,7 +71,7 @@ stse_ReturnCode_t stse_init(stse_Handler_t *pSTSE); * \param[in] pSTSE Pointer to STSE Handler * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_device_reset(stse_Handler_t *pSTSE); +stse_ReturnCode_t stse_device_reset(stse_Handle_t *pSTSE); /** * \brief Put target device in hibernate mode @@ -80,7 +81,7 @@ stse_ReturnCode_t stse_device_reset(stse_Handler_t *pSTSE); * listed in enum \ref stse_hibernate_wake_up_mode_t * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_device_enter_hibernate(stse_Handler_t *pSTSE, stse_hibernate_wake_up_mode_t wake_up_mode); +stse_ReturnCode_t stse_device_enter_hibernate(stse_Handle_t *pSTSE, stse_hibernate_wake_up_mode_t wake_up_mode); /** * \brief Power-on target device @@ -88,7 +89,7 @@ stse_ReturnCode_t stse_device_enter_hibernate(stse_Handler_t *pSTSE, stse_hibern * \param[in] pSTSE Pointer to STSE Handler * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_device_power_on(stse_Handler_t *pSTSE); +stse_ReturnCode_t stse_device_power_on(stse_Handle_t *pSTSE); /** * \brief Power-off target device @@ -97,7 +98,7 @@ stse_ReturnCode_t stse_device_power_on(stse_Handler_t *pSTSE); * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details Please refer to stse_device_power_on() */ -stse_ReturnCode_t stse_device_power_off(stse_Handler_t *pSTSE); +stse_ReturnCode_t stse_device_power_off(stse_Handle_t *pSTSE); /** * \brief Send echo command @@ -109,7 +110,7 @@ stse_ReturnCode_t stse_device_power_off(stse_Handler_t *pSTSE); * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_device_echo.dox */ -stse_ReturnCode_t stse_device_echo(stse_Handler_t *pSTSE, PLAT_UI8 *pIn, PLAT_UI8 *pOut, PLAT_UI16 size); +stse_ReturnCode_t stse_device_echo(stse_Handle_t *pSTSE, PLAT_UI8 *pIn, PLAT_UI8 *pOut, PLAT_UI16 size); /** * \brief Lock target device @@ -120,7 +121,7 @@ stse_ReturnCode_t stse_device_echo(stse_Handler_t *pSTSE, PLAT_UI8 *pIn, PLAT_UI * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_device_lock.dox */ -stse_ReturnCode_t stse_device_lock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, PLAT_UI8 password_length); +stse_ReturnCode_t stse_device_lock(stse_Handle_t *pSTSE, PLAT_UI8 *pPassword, PLAT_UI8 password_length); /** * \brief Unlock target device @@ -131,7 +132,7 @@ stse_ReturnCode_t stse_device_lock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, P * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_device_unlock.dox */ -stse_ReturnCode_t stse_device_unlock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, PLAT_UI8 password_length); +stse_ReturnCode_t stse_device_unlock(stse_Handle_t *pSTSE, PLAT_UI8 *pPassword, PLAT_UI8 password_length); /** * \brief Return the record count of command access conditions @@ -142,7 +143,7 @@ stse_ReturnCode_t stse_device_unlock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details Please refer to stse_device_get_command_AC() */ -stse_ReturnCode_t stse_device_get_command_count(stse_Handler_t *pSTSE, PLAT_UI8 *record_count); +stse_ReturnCode_t stse_device_get_command_count(stse_Handle_t *pSTSE, PLAT_UI8 *record_count); /** * \brief Return the command access conditions and change right @@ -155,7 +156,7 @@ stse_ReturnCode_t stse_device_get_command_count(stse_Handler_t *pSTSE, PLAT_UI8 * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_device_get_command_AC.dox */ -stse_ReturnCode_t stse_device_get_command_AC_records(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_device_get_command_AC_records(stse_Handle_t *pSTSE, PLAT_UI8 record_count, stse_cmd_authorization_CR_t *pChange_rights, stse_cmd_authorization_record_t *pRecord_table); @@ -167,7 +168,7 @@ stse_ReturnCode_t stse_device_get_command_AC_records(stse_Handler_t *pSTSE, * \param[out] pLife_cycle_state Pointer to \ref stsafea_life_cycle_state_t variable to be updated * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_device_get_life_cycle_state(stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_device_get_life_cycle_state(stse_Handle_t *pSTSE, stsafea_life_cycle_state_t *pLife_cycle_state); /** @@ -181,7 +182,7 @@ stse_ReturnCode_t stse_device_get_life_cycle_state(stse_Handler_t *pSTSE, * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_put_i2c_parameters( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 i2c_address, stse_low_power_mode_t low_power_mode, PLAT_UI8 idle_bus_time_to_standby, diff --git a/api/stse_ecc.c b/api/stse_ecc.c index 1308baa1..b6047413 100644 --- a/api/stse_ecc.c +++ b/api/stse_ecc.c @@ -21,7 +21,7 @@ #include "api/stse_ecc.h" stse_ReturnCode_t stse_ecc_verify_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, const PLAT_UI8 *pPublic_key, const PLAT_UI8 *pSignature, @@ -57,7 +57,7 @@ stse_ReturnCode_t stse_ecc_verify_signature( } stse_ReturnCode_t stse_ecc_generate_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, const PLAT_UI8 *pMessage, @@ -95,7 +95,7 @@ stse_ReturnCode_t stse_ecc_generate_signature( } stse_ReturnCode_t stse_ecc_establish_shared_secret( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key, @@ -128,7 +128,7 @@ stse_ReturnCode_t stse_ecc_establish_shared_secret( } stse_ReturnCode_t stse_ecc_decompress_public_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 point_representation_id, PLAT_UI8 *pPublic_key_X, diff --git a/api/stse_ecc.h b/api/stse_ecc.h index 5f07d903..450c8c38 100644 --- a/api/stse_ecc.h +++ b/api/stse_ecc.h @@ -58,7 +58,7 @@ * \details \include{doc} stse_ecc_verify_signature.dox */ stse_ReturnCode_t stse_ecc_verify_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, const PLAT_UI8 *pPublic_key, const PLAT_UI8 *pSignature, @@ -83,7 +83,7 @@ stse_ReturnCode_t stse_ecc_verify_signature( * \details \include{doc} stse_ecc_generate_signature.dox */ stse_ReturnCode_t stse_ecc_generate_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, const PLAT_UI8 *pMessage, @@ -105,7 +105,7 @@ stse_ReturnCode_t stse_ecc_generate_signature( * \note The public key format must match the expected ECC representation (typically concatenation of X and Y coordinates for uncompressed, or X with a prefix for compressed). */ stse_ReturnCode_t stse_ecc_establish_shared_secret( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key, @@ -122,7 +122,7 @@ stse_ReturnCode_t stse_ecc_establish_shared_secret( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_ecc_decompress_public_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 point_representation_id, PLAT_UI8 *pPublic_key_X, diff --git a/api/stse_hash.c b/api/stse_hash.c index 5ab213e8..7e4a07f5 100644 --- a/api/stse_hash.c +++ b/api/stse_hash.c @@ -27,7 +27,7 @@ defined(STSE_CONF_HASH_SHA_3_256) || defined(STSE_CONF_HASH_SHA_3_384) || defined(STSE_CONF_HASH_SHA_3_512) stse_ReturnCode_t stse_start_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size) { @@ -52,7 +52,7 @@ stse_ReturnCode_t stse_start_hash( } stse_ReturnCode_t stse_process_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pMessage, PLAT_UI16 message_size) { #ifdef STSE_CONF_STSAFE_A_SUPPORT @@ -76,7 +76,7 @@ stse_ReturnCode_t stse_process_hash( } stse_ReturnCode_t stse_finish_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size, @@ -103,7 +103,7 @@ stse_ReturnCode_t stse_finish_hash( } stse_ReturnCode_t stse_compute_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size, diff --git a/api/stse_hash.h b/api/stse_hash.h index 38319aa3..b52b7680 100644 --- a/api/stse_hash.h +++ b/api/stse_hash.h @@ -50,7 +50,7 @@ * \return \ref stse_ReturnCode_t : STSE_OK on success ; error code otherwise */ stse_ReturnCode_t stse_start_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size); @@ -64,7 +64,7 @@ stse_ReturnCode_t stse_start_hash( * \return \ref stse_ReturnCode_t : STSE_OK on success ; error code otherwise */ stse_ReturnCode_t stse_process_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pMessage, PLAT_UI16 message_size); @@ -80,7 +80,7 @@ stse_ReturnCode_t stse_process_hash( * \return \ref stse_ReturnCode_t : STSE_OK on success ; error code otherwise */ stse_ReturnCode_t stse_finish_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size, @@ -99,7 +99,7 @@ stse_ReturnCode_t stse_finish_hash( * \return \ref stse_ReturnCode_t : STSE_OK on success ; error code otherwise */ stse_ReturnCode_t stse_compute_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size, diff --git a/api/stse_mac.c b/api/stse_mac.c index 1d9756b2..1564ca5f 100644 --- a/api/stse_mac.c +++ b/api/stse_mac.c @@ -21,7 +21,7 @@ #include "api/stse_mac.h" stse_ReturnCode_t stse_cmac_hmac_compute( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pMessage, PLAT_UI8 message_length, @@ -39,7 +39,7 @@ stse_ReturnCode_t stse_cmac_hmac_compute( } stse_ReturnCode_t stse_cmac_hmac_verify( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pMac, PLAT_UI8 mac_length, @@ -58,7 +58,7 @@ stse_ReturnCode_t stse_cmac_hmac_verify( } stse_ReturnCode_t stse_aes_gmac_compute( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -78,7 +78,7 @@ stse_ReturnCode_t stse_aes_gmac_compute( } stse_ReturnCode_t stse_aes_gmac_verify( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, diff --git a/api/stse_mac.h b/api/stse_mac.h index 4e1f3e5e..3b4f43f2 100644 --- a/api/stse_mac.h +++ b/api/stse_mac.h @@ -42,7 +42,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_cmac_hmac_compute( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pMessage, PLAT_UI8 message_length, @@ -62,7 +62,7 @@ stse_ReturnCode_t stse_cmac_hmac_compute( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_cmac_hmac_verify( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pMac, PLAT_UI8 mac_length, @@ -84,7 +84,7 @@ stse_ReturnCode_t stse_cmac_hmac_verify( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gmac_compute( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -108,7 +108,7 @@ stse_ReturnCode_t stse_aes_gmac_compute( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_aes_gmac_verify( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, diff --git a/api/stse_random.c b/api/stse_random.c index a6f09493..000f039c 100644 --- a/api/stse_random.c +++ b/api/stse_random.c @@ -21,7 +21,7 @@ #include "api/stse_random.h" stse_ReturnCode_t stse_generate_random( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pRandom, PLAT_UI16 random_size) { stse_ReturnCode_t ret = STSE_API_INCOMPATIBLE_DEVICE_TYPE; diff --git a/api/stse_random.h b/api/stse_random.h index cfa75b9b..472d3903 100644 --- a/api/stse_random.h +++ b/api/stse_random.h @@ -37,7 +37,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_generate_random( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pRandom, PLAT_UI16 random_size); diff --git a/api/stse_symmetric_keys_management.c b/api/stse_symmetric_keys_management.c index cb8b1e5b..82db5368 100644 --- a/api/stse_symmetric_keys_management.c +++ b/api/stse_symmetric_keys_management.c @@ -33,7 +33,7 @@ defined(STSE_CONF_USE_SYMMETRIC_KEY_PROVISIONING_WRAPPED) static stse_ReturnCode_t stse_start_volatile_KEK_session( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_session_t *pSession, stse_ecc_key_type_t ecc_key_type) { stse_ReturnCode_t ret; @@ -161,7 +161,7 @@ static stse_ReturnCode_t stse_start_volatile_KEK_session( defined(STSE_CONF_USE_SYMMETRIC_KEY_PROVISIONING_WRAPPED_AUTHENTICATED) static stse_ReturnCode_t stse_start_volatile_KEK_session_authenticated( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_session_t *pSession, stse_ecc_key_type_t ecc_key_type, PLAT_UI8 signature_public_key_slot_number, @@ -380,7 +380,7 @@ static stse_ReturnCode_t stse_start_volatile_KEK_session_authenticated( defined(STSE_CONF_USE_HOST_KEY_PROVISIONING_WRAPPED_AUTHENTICATED) || \ defined(STSE_CONF_USE_SYMMETRIC_KEY_PROVISIONING_WRAPPED) || \ defined(STSE_CONF_USE_SYMMETRIC_KEY_PROVISIONING_WRAPPED_AUTHENTICATED) -static stse_ReturnCode_t stse_stop_volatile_KEK_session(stse_Handler_t *pSTSE, stse_session_t *pSession) { +static stse_ReturnCode_t stse_stop_volatile_KEK_session(stse_Handle_t *pSTSE, stse_session_t *pSession) { stse_ReturnCode_t ret; /* - Check function parameters */ @@ -398,7 +398,7 @@ static stse_ReturnCode_t stse_stop_volatile_KEK_session(stse_Handler_t *pSTSE, s } static stse_ReturnCode_t stse_derive_working_KEK( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_session_t *pSession, PLAT_UI8 *working_kek) { stse_ReturnCode_t ret; @@ -433,7 +433,7 @@ static stse_ReturnCode_t stse_derive_working_KEK( } static stse_ReturnCode_t stse_KEK_wrap( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_session_t *pSession, PLAT_UI8 *pPayload, PLAT_UI32 payload_length, @@ -479,10 +479,14 @@ static stse_ReturnCode_t stse_KEK_wrap( /* Exported functions --------------------------------------------------------*/ -stse_ReturnCode_t stse_host_key_provisioning( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t host_key_type, - stsafea_host_keys_t *host_keys) { +#if defined(STSE_CONF_USE_HOST_SESSION) + +stse_ReturnCode_t stse_host_secure_channel_keys_provisioning( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key, + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index) { #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t ret; @@ -490,50 +494,76 @@ stse_ReturnCode_t stse_host_key_provisioning( return (STSE_API_HANDLER_NOT_INITIALISED); } - if (host_key_type >= STSAFEA_AES_INVALID_HOST_KEY || host_keys == NULL) { + if (host_mac_key == NULL || host_mac_key_index == NULL) { return (STSE_API_INVALID_PARAMETER); } #if defined(STSE_CONF_STSAFE_A_SUPPORT) if (pSTSE->device_type == STSAFE_A120) { /* - Write host key plaintext to the STSAFE */ - ret = stsafea_host_key_provisioning( + ret = stsafea_host_secure_channel_keys_provisioning( pSTSE, - host_key_type, - host_keys); + host_mac_key, + host_cipher_key); } else { #endif /* STSE_CONF_STSAFE_A_SUPPORT */ - if (host_key_type != STSAFEA_AES_128_HOST_KEY) { - return STSE_API_INVALID_PARAMETER; - } - ret = stsafea_put_attribute_host_key( + ret = stsafea_put_attribute_host_secure_channel_keys( pSTSE, - (stsafea_aes_128_host_keys_t *)host_keys); + host_mac_key, + host_cipher_key); #if defined(STSE_CONF_STSAFE_A_SUPPORT) } #endif /* STSE_CONF_STSAFE_A_SUPPORT */ + if (ret != STSE_OK) { + return ret; + } + + /* - Store host MAC key */ + ret = stse_platform_store_aes_key(host_mac_key->key, + (host_mac_key->type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + STSE_AES_KEY_USAGE_MAC, + host_mac_key_index); + memset(host_mac_key->key, 0, sizeof(host_mac_key->key)); + + if (ret != STSE_OK) { + return ret; + } + + /* - Store host cipher key */ + ret = stse_platform_store_aes_key(host_cipher_key->key, + (host_cipher_key->type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + STSE_AES_KEY_USAGE_CIPHER, + host_cipher_key_index); + memset(host_cipher_key->key, 0, sizeof(host_cipher_key->key)); + return ret; #else return STSE_API_INCOMPATIBLE_DEVICE_TYPE; #endif /* STSE_CONF_STSAFE_A_SUPPORT */ } +#endif /* STSE_CONF_USE_HOST_SESSION */ + #ifdef STSE_CONF_USE_HOST_KEY_PROVISIONING_WRAPPED -stse_ReturnCode_t stse_host_key_provisioning_wrapped( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t host_key_type, - stsafea_host_keys_t *host_keys, - stse_ecc_key_type_t ecdhe_ecc_key_type) { +stse_ReturnCode_t stse_host_secure_channel_keys_provisioning_wrapped( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key, + stse_ecc_key_type_t ecdhe_ecc_key_type, + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index) { stse_ReturnCode_t ret; if (pSTSE == NULL) { return (STSE_API_HANDLER_NOT_INITIALISED); } - if (host_key_type >= STSAFEA_AES_INVALID_HOST_KEY || host_keys == NULL) { + if (host_mac_key == NULL || host_mac_key_index == NULL || host_mac_key->usage != STSE_AES_KEY_USAGE_MAC || host_mac_key->type >= STSE_AES_INVALID_KT || + host_cipher_key == NULL || host_cipher_key_index == NULL || host_cipher_key->usage != STSE_AES_KEY_USAGE_CIPHER || host_cipher_key->type >= STSE_AES_INVALID_KT || + host_mac_key->type != host_cipher_key->type) { return (STSE_API_INVALID_PARAMETER); } @@ -541,10 +571,9 @@ stse_ReturnCode_t stse_host_key_provisioning_wrapped( return (STSE_COMMAND_CODE_NOT_SUPPORTED); } - PLAT_UI8 host_keys_length = (host_key_type == STSAFEA_AES_128_HOST_KEY) ? STSAFEA_HOST_AES_128_KEYS_SIZE - : STSAFEA_HOST_AES_256_KEYS_SIZE; + PLAT_UI8 host_keys_length = (host_mac_key->type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE; - PLAT_UI8 host_keys_envelope_length = STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH + host_keys_length + STSE_HOST_KEY_ENVELOPE_PADDING_LENGTH + STSAFEA_HOST_KEY_WRAPPING_AUTHENTICATION_TAG_LENGTH; + PLAT_UI8 host_keys_envelope_length = STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH + (2u * host_keys_length) + STSE_HOST_KEY_ENVELOPE_PADDING_LENGTH + STSAFEA_HOST_KEY_WRAPPING_AUTHENTICATION_TAG_LENGTH; PLAT_UI8 host_key_envelope[host_keys_envelope_length]; @@ -563,15 +592,19 @@ stse_ReturnCode_t stse_host_key_provisioning_wrapped( /* - Format host key to be wrapped */ memset(host_key_envelope, 0, host_keys_envelope_length); - host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH] = host_key_type; + host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH] = host_mac_key->type; memcpy(&host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH], - host_keys, + host_mac_key->key, + host_keys_length); + + memcpy(&host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH + host_keys_length], + host_cipher_key->key, host_keys_length); host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH + - host_keys_length] = 0x80; + (2u * host_keys_length)] = 0x80; /* - Wrap */ ret = stse_KEK_wrap( @@ -581,23 +614,42 @@ stse_ReturnCode_t stse_host_key_provisioning_wrapped( (host_keys_envelope_length - STSAFEA_HOST_KEY_WRAPPING_AUTHENTICATION_TAG_LENGTH), host_key_envelope, host_keys_envelope_length); - if (ret != STSE_OK) { return ret; } /* - Write host key wrapped to the STSAFE */ - ret = stsafea_host_key_provisioning_wrapped( + ret = stsafea_host_secure_channel_keys_provisioning_wrapped( pSTSE, - host_key_type, + host_mac_key->type, host_key_envelope); - if (ret != STSE_OK) { return ret; } /* - Stop volatile KEK */ ret = stsafea_stop_volatile_KEK_session(pSTSE); + if (ret != STSE_OK) { + return ret; + } + + /* - Store host MAC key */ + ret = stse_platform_store_aes_key(host_mac_key->key, + (host_mac_key->type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + STSE_AES_KEY_USAGE_MAC, + host_mac_key_index); + memset(host_mac_key->key, 0, sizeof(host_mac_key->key)); + + if (ret != STSE_OK) { + return ret; + } + + /* - Store host cipher key */ + ret = stse_platform_store_aes_key(host_cipher_key->key, + (host_cipher_key->type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + STSE_AES_KEY_USAGE_CIPHER, + host_cipher_key_index); + memset(host_cipher_key->key, 0, sizeof(host_cipher_key->key)); return ret; } @@ -605,22 +657,26 @@ stse_ReturnCode_t stse_host_key_provisioning_wrapped( #ifdef STSE_CONF_USE_HOST_KEY_PROVISIONING_WRAPPED_AUTHENTICATED -stse_ReturnCode_t stse_host_key_provisioning_wrapped_authenticated( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t host_key_type, - stsafea_host_keys_t *host_keys, +stse_ReturnCode_t stse_host_secure_channel_keys_provisioning_wrapped_authenticated( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key, stse_ecc_key_type_t ecdhe_ecc_key_type, PLAT_UI8 signature_public_key_slot_number, stse_hash_algorithm_t signature_hash_algo, stse_ecc_key_type_t signature_private_ecc_key_type, - PLAT_UI8 *signature_private_key) { + PLAT_UI8 *signature_private_key, + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index) { stse_ReturnCode_t ret; if (pSTSE == NULL) { return (STSE_API_HANDLER_NOT_INITIALISED); } - if (host_key_type >= STSAFEA_AES_INVALID_HOST_KEY || host_keys == NULL) { + if (host_mac_key == NULL || host_mac_key_index == NULL || host_mac_key->usage != STSE_AES_KEY_USAGE_MAC || host_mac_key->type >= STSE_AES_INVALID_KT || + host_cipher_key == NULL || host_cipher_key_index == NULL || host_cipher_key->usage != STSE_AES_KEY_USAGE_CIPHER || host_cipher_key->type >= STSE_AES_INVALID_KT || + host_mac_key->type != host_cipher_key->type) { return (STSE_API_INVALID_PARAMETER); } @@ -628,10 +684,9 @@ stse_ReturnCode_t stse_host_key_provisioning_wrapped_authenticated( return (STSE_COMMAND_CODE_NOT_SUPPORTED); } - PLAT_UI8 host_keys_length = (host_key_type == STSAFEA_AES_128_HOST_KEY) ? STSAFEA_HOST_AES_128_KEYS_SIZE - : STSAFEA_HOST_AES_256_KEYS_SIZE; + PLAT_UI8 host_keys_length = (host_mac_key->type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE; - PLAT_UI8 host_keys_envelope_length = host_keys_length + STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH + STSAFEA_HOST_KEY_WRAPPING_AUTHENTICATION_TAG_LENGTH; + PLAT_UI8 host_keys_envelope_length = (2 * host_keys_length) + STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH + STSAFEA_HOST_KEY_WRAPPING_AUTHENTICATION_TAG_LENGTH; PLAT_UI8 host_key_envelope[host_keys_envelope_length]; @@ -654,10 +709,14 @@ stse_ReturnCode_t stse_host_key_provisioning_wrapped_authenticated( /* - Format host key to be wrapped */ memset(&host_key_envelope, 0, host_keys_envelope_length); - host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH] = host_key_type; + host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH] = host_mac_key->type; memcpy(&host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH], - host_keys, + host_mac_key->key, + host_keys_length); + + memcpy(&host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH + host_keys_length], + host_cipher_key->key, host_keys_length); host_key_envelope[STSE_HOST_KEY_ENVELOPE_FRONT_PADDING_LENGTH + STSE_HOST_KEY_ENVELOPE_KEY_TYPE_LENGTH + host_keys_length] = 0x80; @@ -675,9 +734,9 @@ stse_ReturnCode_t stse_host_key_provisioning_wrapped_authenticated( } /* - Write host key wrapped to the STSAFE */ - ret = stsafea_host_key_provisioning_wrapped( + ret = stsafea_host_secure_channel_keys_provisioning_wrapped( pSTSE, - host_key_type, + host_mac_key->type, host_key_envelope); if (ret != STSE_OK) { return ret; @@ -685,18 +744,39 @@ stse_ReturnCode_t stse_host_key_provisioning_wrapped_authenticated( /* - Stop volatile KEK */ ret = stse_stop_volatile_KEK_session(pSTSE, &volatile_KEK_session); + if (ret != STSE_OK) { + return ret; + } + + /* - Store host MAC key */ + ret = stse_platform_store_aes_key(host_mac_key->key, + (host_mac_key->type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + STSE_AES_KEY_USAGE_MAC, + host_mac_key_index); + memset(host_mac_key->key, 0, sizeof(host_mac_key->key)); + + if (ret != STSE_OK) { + return ret; + } + + /* - Store host cipher key */ + ret = stse_platform_store_aes_key(host_cipher_key->key, + (host_cipher_key->type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + STSE_AES_KEY_USAGE_CIPHER, + host_cipher_key_index); + memset(host_cipher_key->key, 0, sizeof(host_cipher_key->key)); return ret; } #endif /* STSE_CONF_USE_HOST_KEY_PROVISIONING_WRAPPED_AUTHENTICATED */ #ifdef STSE_CONF_USE_HOST_KEY_ESTABLISHMENT -stse_ReturnCode_t stse_establish_host_key( - stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_establish_host_secure_channel_keys( + stse_Handle_t *pSTSE, stse_ecc_key_type_t ecdh_key_type, - stsafea_host_key_type_t host_secure_channel_keys_type, - PLAT_UI8 *host_mac_key, - PLAT_UI8 *host_cipher_key) { + stse_aes_key_type_t host_secure_channel_keys_type, + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index) { stse_ReturnCode_t ret; /* - Check function parameters */ @@ -704,7 +784,8 @@ stse_ReturnCode_t stse_establish_host_key( return (STSE_API_HANDLER_NOT_INITIALISED); } - if (host_secure_channel_keys_type >= STSAFEA_AES_INVALID_HOST_KEY || host_mac_key == NULL || host_cipher_key == NULL + if (host_mac_key_index == NULL || host_cipher_key_index == NULL || + host_secure_channel_keys_type >= STSE_AES_INVALID_KT || ecdh_key_type >= STSE_ECC_KT_INVALID #ifdef STSE_CONF_ECC_EDWARD_25519 || ecdh_key_type == STSE_ECC_KT_ED25519 #endif /* STSE_CONF_ECC_EDWARD_25519 */ @@ -728,8 +809,8 @@ stse_ReturnCode_t stse_establish_host_key( PLAT_UI8 pHkdf_info[hkdf_info_size]; /* - Initialize the OKM length with the confirmation key length */ - PLAT_UI16 host_mac_key_length = host_secure_channel_keys_type == STSAFEA_AES_256_HOST_KEY ? STSAFEA_HOST_AES_256_MAC_KEY_SIZE : STSAFEA_HOST_AES_128_MAC_KEY_SIZE; - PLAT_UI16 host_cipher_key_length = host_secure_channel_keys_type == STSAFEA_AES_256_HOST_KEY ? STSAFEA_HOST_AES_256_CIPHER_KEY_SIZE : STSAFEA_HOST_AES_128_CIPHER_KEY_SIZE; + PLAT_UI16 host_mac_key_length = (host_secure_channel_keys_type == STSE_AES_256_KT) ? STSE_AES_256_KEY_SIZE : STSE_AES_128_KEY_SIZE; + PLAT_UI16 host_cipher_key_length = (host_secure_channel_keys_type == STSE_AES_256_KT) ? STSE_AES_256_KEY_SIZE : STSE_AES_128_KEY_SIZE; PLAT_UI8 okm_buffer[host_mac_key_length + host_cipher_key_length]; /* - Generate local host ECDHE key pair */ @@ -799,7 +880,7 @@ stse_ReturnCode_t stse_establish_host_key( } /* - Establish the host keys through STSAFE */ - ret = stsafea_establish_host_key( + ret = stsafea_establish_host_secure_channel_keys( pSTSE, ecdh_key_type, host_ecdhe_public_key, @@ -811,26 +892,30 @@ stse_ReturnCode_t stse_establish_host_key( return ret; } - memcpy(host_mac_key, - okm_buffer, - host_mac_key_length); - memcpy(host_cipher_key, - okm_buffer + host_mac_key_length, - host_cipher_key_length); + /* - Store host MAC key */ + ret = stse_platform_store_aes_key(okm_buffer, host_mac_key_length, STSE_AES_KEY_USAGE_MAC, host_mac_key_index); + if (ret != STSE_OK) { + memset(okm_buffer, 0, sizeof(okm_buffer)); + return ret; + } + + /* - Store host cipher key */ + ret = stse_platform_store_aes_key(okm_buffer + host_mac_key_length, host_cipher_key_length, STSE_AES_KEY_USAGE_CIPHER, host_cipher_key_index); + memset(okm_buffer, 0, sizeof(okm_buffer)); return ret; } -stse_ReturnCode_t stse_establish_host_key_authenticated( - stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_establish_host_secure_channel_keys_authenticated( + stse_Handle_t *pSTSE, stse_ecc_key_type_t ecdh_key_type, - stsafea_host_key_type_t host_secure_channel_keys_type, + stse_aes_key_type_t host_secure_channel_keys_type, stse_hash_algorithm_t tbs_hash_algo, PLAT_UI8 tbs_public_key_slot, PLAT_UI8 *tbs_private_key, - PLAT_UI8 *host_mac_key, - PLAT_UI8 *host_cipher_key) { + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index) { stse_ReturnCode_t ret; /* - Check function parameters */ @@ -838,7 +923,8 @@ stse_ReturnCode_t stse_establish_host_key_authenticated( return (STSE_API_HANDLER_NOT_INITIALISED); } - if (host_secure_channel_keys_type >= STSAFEA_AES_INVALID_HOST_KEY || host_mac_key == NULL || host_cipher_key == NULL + if (host_mac_key_index == NULL || host_cipher_key_index == NULL || tbs_private_key == NULL || + host_secure_channel_keys_type >= STSE_AES_INVALID_KT || ecdh_key_type >= STSE_ECC_KT_INVALID #ifdef STSE_CONF_ECC_EDWARD_25519 || ecdh_key_type == STSE_ECC_KT_ED25519 #endif /* STSE_CONF_ECC_EDWARD_25519 */ @@ -880,8 +966,8 @@ stse_ReturnCode_t stse_establish_host_key_authenticated( PLAT_UI8 signature[stse_ecc_info_table[tbs_key_type].signature_size]; /* - Initialize the OKM length with the confirmation key length */ - PLAT_UI16 host_mac_key_length = host_secure_channel_keys_type == STSAFEA_AES_256_HOST_KEY ? STSAFEA_HOST_AES_256_MAC_KEY_SIZE : STSAFEA_HOST_AES_128_MAC_KEY_SIZE; - PLAT_UI16 host_cipher_key_length = host_secure_channel_keys_type == STSAFEA_AES_256_HOST_KEY ? STSAFEA_HOST_AES_256_CIPHER_KEY_SIZE : STSAFEA_HOST_AES_128_CIPHER_KEY_SIZE; + PLAT_UI16 host_mac_key_length = (host_secure_channel_keys_type == STSE_AES_256_KT) ? STSE_AES_256_KEY_SIZE : STSE_AES_128_KEY_SIZE; + PLAT_UI16 host_cipher_key_length = (host_secure_channel_keys_type == STSE_AES_256_KT) ? STSE_AES_256_KEY_SIZE : STSE_AES_128_KEY_SIZE; PLAT_UI8 okm_buffer[host_mac_key_length + host_cipher_key_length]; /* - Generate local host ECDHE key pair */ @@ -1046,26 +1132,30 @@ stse_ReturnCode_t stse_establish_host_key_authenticated( } /* - Establish the host keys through STSAFE with authentication */ - ret = stsafea_establish_host_key_authenticated(pSTSE, - ecdh_key_type, - host_ecdhe_public_key, - host_secure_channel_keys_type, - tbs_public_key_slot, - tbs_key_type, - tbs_hash_algo, - signature); + ret = stsafea_establish_host_secure_channel_keys_authenticated(pSTSE, + ecdh_key_type, + host_ecdhe_public_key, + host_secure_channel_keys_type, + tbs_public_key_slot, + tbs_key_type, + tbs_hash_algo, + signature); memset(host_ecdhe_public_key, 0, sizeof(host_ecdhe_public_key)); if (ret != STSE_OK) { memset(okm_buffer, 0, sizeof(okm_buffer)); return ret; } - memcpy(host_mac_key, - okm_buffer, - host_mac_key_length); - memcpy(host_cipher_key, - okm_buffer + host_mac_key_length, - host_cipher_key_length); + /* - Store host MAC key */ + ret = stse_platform_store_aes_key(okm_buffer, host_mac_key_length, STSE_AES_KEY_USAGE_MAC, host_mac_key_index); + if (ret != STSE_OK) { + memset(okm_buffer, 0, sizeof(okm_buffer)); + return ret; + } + + /* - Store host cipher key */ + ret = stse_platform_store_aes_key(okm_buffer + host_mac_key_length, host_cipher_key_length, STSE_AES_KEY_USAGE_CIPHER, host_cipher_key_index); + memset(okm_buffer, 0, sizeof(okm_buffer)); return ret; @@ -1079,7 +1169,7 @@ stse_ReturnCode_t stse_establish_host_key_authenticated( ------------------------------------------------------------------------------------------ */ stse_ReturnCode_t stse_get_symmetric_key_slots_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pSymmetric_key_slot_count) { #ifdef STSE_CONF_STSAFE_A_SUPPORT if (pSTSE == NULL) { @@ -1093,7 +1183,7 @@ stse_ReturnCode_t stse_get_symmetric_key_slots_count( } stse_ReturnCode_t stse_get_symmetric_key_slot_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_information_t *pSymmetric_key_slot_info) { #ifdef STSE_CONF_STSAFE_A_SUPPORT @@ -1133,7 +1223,7 @@ stse_ReturnCode_t stse_get_symmetric_key_slot_info( } stse_ReturnCode_t stse_get_symmetric_key_table_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 total_slot_count, stsafea_symmetric_key_slot_information_t *pSymmetric_key_table_info) { #ifdef STSE_CONF_STSAFE_A_SUPPORT @@ -1148,7 +1238,7 @@ stse_ReturnCode_t stse_get_symmetric_key_table_info( } stse_ReturnCode_t stse_get_symmetric_key_slot_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_provisioning_ctrl_fields_t *pCtrl_fields) { #ifdef STSE_CONF_STSAFE_A_SUPPORT @@ -1163,7 +1253,7 @@ stse_ReturnCode_t stse_get_symmetric_key_slot_provisioning_ctrl_fields( } stse_ReturnCode_t stse_set_symmetric_key_slot_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_provisioning_ctrl_fields_t *pCtrl_fields) { #ifdef STSE_CONF_STSAFE_A_SUPPORT @@ -1178,7 +1268,7 @@ stse_ReturnCode_t stse_set_symmetric_key_slot_provisioning_ctrl_fields( } stse_ReturnCode_t stse_write_symmetric_key_plaintext( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pKey, stsafea_generic_key_information_t *pSymmetric_key_info) { #ifdef STSE_CONF_STSAFE_A_SUPPORT @@ -1197,7 +1287,7 @@ stse_ReturnCode_t stse_write_symmetric_key_plaintext( #ifdef STSE_CONF_USE_SYMMETRIC_KEY_PROVISIONING_WRAPPED stse_ReturnCode_t stse_write_symmetric_key_wrapped( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pKey, stsafea_generic_key_information_t *key_info, stse_ecc_key_type_t kek_session_ecc_type) { @@ -1219,7 +1309,7 @@ stse_ReturnCode_t stse_write_symmetric_key_wrapped( } /* - Format envelope to wrap */ - PLAT_UI8 envelope_key_length = key_info->type == STSAFEA_SYMMETRIC_KEY_TYPE_AES_256 ? STSAFEA_AES_256_KEY_SIZE : STSAFEA_AES_128_KEY_SIZE; + PLAT_UI8 envelope_key_length = key_info->type == STSAFEA_SYMMETRIC_KEY_TYPE_AES_256 ? STSE_AES_256_KEY_SIZE : STSE_AES_128_KEY_SIZE; PLAT_UI8 envelope_length = envelope_key_length + key_info->info_length; PLAT_UI8 envelope_padding_length = 8 - (envelope_length % 8); @@ -1272,7 +1362,7 @@ stse_ReturnCode_t stse_write_symmetric_key_wrapped( #ifdef STSE_CONF_USE_SYMMETRIC_KEY_PROVISIONING_WRAPPED_AUTHENTICATED stse_ReturnCode_t stse_write_symmetric_key_wrapped_authenticated( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pKey, stsafea_generic_key_information_t *key_info, stse_ecc_key_type_t kek_session_ecc_type, @@ -1309,7 +1399,7 @@ stse_ReturnCode_t stse_write_symmetric_key_wrapped_authenticated( } /* - Format envelope to wrap */ - PLAT_UI8 envelope_key_length = key_info->type == STSAFEA_SYMMETRIC_KEY_TYPE_AES_256 ? STSAFEA_AES_256_KEY_SIZE : STSAFEA_AES_128_KEY_SIZE; + PLAT_UI8 envelope_key_length = key_info->type == STSAFEA_SYMMETRIC_KEY_TYPE_AES_256 ? STSE_AES_256_KEY_SIZE : STSE_AES_128_KEY_SIZE; PLAT_UI8 envelope_length = envelope_key_length + key_info->info_length; PLAT_UI8 envelope_padding_length = 8 - (envelope_length % 8); @@ -1360,13 +1450,14 @@ stse_ReturnCode_t stse_write_symmetric_key_wrapped_authenticated( #ifdef STSE_CONF_USE_SYMMETRIC_KEY_ESTABLISHMENT stse_ReturnCode_t stse_establish_symmetric_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t ecc_key_type, PLAT_UI8 key_infos_count, stsafea_generic_key_information_t *key_infos_list, PLAT_UI8 *key_list) { #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t ret; + PLAT_UI32 confirmation_key_index; /* - HKDF variables */ PLAT_UI8 pHkdf_salt[STSAFEA_KEK_HKDF_SALT_SIZE] = STSAFEA_KEK_HKDF_SALT; @@ -1395,11 +1486,11 @@ stse_ReturnCode_t stse_establish_symmetric_key( PLAT_UI8 shared_secret[2 * shared_secret_size]; /* - Initialize the OKM length with the confirmation key length */ - PLAT_UI16 okm_length = STSAFEA_AES_256_KEY_SIZE; + PLAT_UI16 okm_length = STSE_AES_256_KEY_SIZE; for (PLAT_UI8 i = 0; i < key_infos_count; i++) { /* - Add the current key length (16 or 32 bytes) depending on key type */ - okm_length += key_infos_list[i].type == STSAFEA_SYMMETRIC_KEY_TYPE_AES_256 ? STSAFEA_AES_256_KEY_SIZE : STSAFEA_AES_128_KEY_SIZE; + okm_length += key_infos_list[i].type == STSAFEA_SYMMETRIC_KEY_TYPE_AES_256 ? STSE_AES_256_KEY_SIZE : STSE_AES_128_KEY_SIZE; } PLAT_UI8 okm_buffer[okm_length]; @@ -1456,21 +1547,33 @@ stse_ReturnCode_t stse_establish_symmetric_key( return ret; } + /* - Store confirmation key */ + ret = stse_platform_store_aes_key( + okm_buffer, + STSE_AES_256_KEY_SIZE, + STSE_AES_KEY_USAGE_GENERIC_SECRET, + &confirmation_key_index); + + memset(okm_buffer, 0, STSE_AES_256_KEY_SIZE); + + if (ret != STSE_OK) { + return ret; + } + /* - Send confirmation MAC + Key information list */ ret = stsafea_confirm_symmetric_key( pSTSE, - okm_buffer, + confirmation_key_index, key_infos_count, key_infos_list); - if (ret != STSE_OK) { return ret; } /* - Format OKM for return value */ memcpy(key_list, - okm_buffer + STSAFEA_AES_256_KEY_SIZE, - okm_length - STSAFEA_AES_256_KEY_SIZE); + okm_buffer + STSE_AES_256_KEY_SIZE, + okm_length - STSE_AES_256_KEY_SIZE); return ret; #else @@ -1482,7 +1585,7 @@ stse_ReturnCode_t stse_establish_symmetric_key( #ifdef STSE_CONF_USE_SYMMETRIC_KEY_ESTABLISHMENT_AUTHENTICATED stse_ReturnCode_t stse_establish_symmetric_key_authenticated( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t ecc_key_type, PLAT_UI8 key_infos_count, stsafea_generic_key_information_t *key_infos_list, @@ -1493,6 +1596,7 @@ stse_ReturnCode_t stse_establish_symmetric_key_authenticated( PLAT_UI8 *private_key) { #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t ret; + PLAT_UI32 confirmation_key_index; if (pSTSE == NULL) { return (STSE_API_HANDLER_NOT_INITIALISED); @@ -1536,11 +1640,11 @@ stse_ReturnCode_t stse_establish_symmetric_key_authenticated( PLAT_UI8 signature[signature_size]; /* - Initialize the OKM length with the confirmation key length */ - PLAT_UI16 okm_length = STSAFEA_AES_256_KEY_SIZE; + PLAT_UI16 okm_length = STSE_AES_256_KEY_SIZE; for (PLAT_UI8 i = 0; i < key_infos_count; i++) { /* - Add the current key length (16 or 32 bytes) depending on key type */ - okm_length += key_infos_list[i].type == STSAFEA_SYMMETRIC_KEY_TYPE_AES_256 ? STSAFEA_AES_256_KEY_SIZE : STSAFEA_AES_128_KEY_SIZE; + okm_length += key_infos_list[i].type == STSAFEA_SYMMETRIC_KEY_TYPE_AES_256 ? STSE_AES_256_KEY_SIZE : STSE_AES_128_KEY_SIZE; } PLAT_UI8 okm_buffer[okm_length]; @@ -1687,6 +1791,18 @@ stse_ReturnCode_t stse_establish_symmetric_key_authenticated( STSAFEA_KT_LENGTH + STSAFEA_KT_LENGTH, okm_buffer, okm_length); + if (ret != STSE_OK) { + return ret; + } + + /* - Store confirmation key */ + ret = stse_platform_store_aes_key( + okm_buffer, + STSE_AES_256_KEY_SIZE, + STSE_AES_KEY_USAGE_GENERIC_SECRET, + &confirmation_key_index); + + memset(okm_buffer, 0, STSE_AES_256_KEY_SIZE); if (ret != STSE_OK) { return ret; @@ -1695,7 +1811,7 @@ stse_ReturnCode_t stse_establish_symmetric_key_authenticated( /* - Send confirmation MAC + Key information list */ ret = stsafea_confirm_symmetric_key( pSTSE, - okm_buffer, + confirmation_key_index, key_infos_count, key_infos_list); if (ret != STSE_OK) { @@ -1704,8 +1820,8 @@ stse_ReturnCode_t stse_establish_symmetric_key_authenticated( /* - Format OKM for return value */ memcpy(key_list, - okm_buffer + STSAFEA_AES_256_KEY_SIZE, - okm_length - STSAFEA_AES_256_KEY_SIZE); + okm_buffer + STSE_AES_256_KEY_SIZE, + okm_length - STSE_AES_256_KEY_SIZE); return ret; #else diff --git a/api/stse_symmetric_keys_management.h b/api/stse_symmetric_keys_management.h index 2ad1a67c..5a2fcb31 100644 --- a/api/stse_symmetric_keys_management.h +++ b/api/stse_symmetric_keys_management.h @@ -36,104 +36,116 @@ */ /** - * \brief Host key provisioning in plaintext - * \details This API perform host key provisioning in plaintext, \n + * \brief Host secure channel keys provisioning in plaintext + * \details This API perform host secure channel keys provisioning in plaintext, \n * it use the put attribute command if the device isn't a STSAFE-A120 \n * and it use the "write host key" command if it is a STSAFE-A120 - * \param[in] pSTSE Pointer to STSE Handler - * \param[in] host_ecc_key_type Key type - * \param[in] host_keys Pointer to the key structure + * \param[in] pSTSE Pointer to STSE Handler + * \param[in] host_mac_key Pointer to host MAC key (AES key structure) to be provisioned + * \param[in] host_cipher_key Pointer to Host cipher key (AES key structure) to be provisioned + * \param[out] host_mac_key_index Pointer to the index assigned to the stored host MAC key in secure storage + * \param[out] host_mac_key_index Pointer to the index assigned to the stored host cipher key in secure storage * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_host_key_provisioning.dox */ -stse_ReturnCode_t stse_host_key_provisioning( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t host_ecc_key_type, - stsafea_host_keys_t *host_keys); +stse_ReturnCode_t stse_host_secure_channel_keys_provisioning( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key, + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index); /** - * \brief Host key provisioning wrapped - * \details This API perform host key provisioning with the key wrapped using a volatile KEK session - * \param[in] pSTSE Pointer to STSE Handler - * \param[in] host_key_type Key type - * \param[in] host_keys Pointer to the key structure + * \brief Host secure channel keys provisioning wrapped + * \details This API perform host secure channel keys provisioning with the key wrapped using a volatile KEK session + * \param[in] pSTSE Pointer to STSE Handler + * \param[in] host_mac_key Pointer to host MAC key (AES key structure) to be provisioned + * \param[in] host_cipher_key Pointer to Host cipher key (AES key structure) to be provisioned * \param[in] ecdhe_key_type ECC key type to use in KEK session + * \param[out] host_mac_key_index Pointer to the index assigned to the stored host MAC key in secure storage + * \param[out] host_mac_key_index Pointer to the index assigned to the stored host cipher key in secure storage * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_host_key_provisioning_wrapped.dox */ -stse_ReturnCode_t stse_host_key_provisioning_wrapped( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t host_key_type, - stsafea_host_keys_t *host_keys, - stse_ecc_key_type_t ecdhe_key_type); +stse_ReturnCode_t stse_host_secure_channel_keys_provisioning_wrapped( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key, + stse_ecc_key_type_t ecdhe_ecc_key_type, + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index); /** - * \brief Host key provisioning wrapped and authenticated - * \details This API perform host key provisioning with the key wrapped using an authenticated volatile KEK session + * \brief Host secure channel keys provisioning wrapped and authenticated + * \details This API perform host secure channel keys provisioning with the key wrapped using an authenticated volatile KEK session * \param[in] pSTSE Pointer to STSE Handler - * \param[in] host_key_type Key type - * \param[in] host_keys Pointer to the key structure + * \param[in] host_mac_key Pointer to host MAC key (AES key structure) to be provisioned + * \param[in] host_cipher_key Pointer to Host cipher key (AES key structure) to be provisioned * \param[in] ecdhe_key_type ECC key type to use in KEK session * \param[in] signature_public_key_slot_number Slot number of the public key used in authentication * \param[in] signature_hash_algo Hash algo used for the signature digest * \param[in] signature_private_key_type Key type of the private key used in authentication * \param[in] signature_private_key Private key used in authentication + * \param[out] host_mac_key_index Pointer to the index assigned to the stored host MAC key in secure storage + * \param[out] host_mac_key_index Pointer to the index assigned to the stored host cipher key in secure storage * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_host_key_provisioning_wrapped_authenticated.dox * \warning Few specific cryptographic library required to have public key concatenated to private key for EdDSA mechanism. In such case, pPrivate_key pointer shall reference concatenated key pair buffer's address. */ -stse_ReturnCode_t stse_host_key_provisioning_wrapped_authenticated( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t host_key_type, - stsafea_host_keys_t *host_keys, - stse_ecc_key_type_t ecdhe_key_type, +stse_ReturnCode_t stse_host_secure_channel_keys_provisioning_wrapped_authenticated( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key, + stse_ecc_key_type_t ecdhe_ecc_key_type, PLAT_UI8 signature_public_key_slot_number, stse_hash_algorithm_t signature_hash_algo, - stse_ecc_key_type_t signature_private_key_type, - PLAT_UI8 *signature_private_key); + stse_ecc_key_type_t signature_private_ecc_key_type, + PLAT_UI8 *signature_private_key, + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index); /** - * \brief Host key establishment - * \details This API establish host key (from STSAFE-A120) + * \brief Host secure channel keys establishment + * \details This API establish host secure channel keys (from STSAFE-A120) * \param[in] pSTSE Pointer to STSE Handler * \param[in] ecdh_key_type ECDH key pair type - * \param[in] host_secure_channel_keys_type Host secure channel keys type - * \param[in] host_mac_key Pointer to the host mac key buffer - * \param[in] host_cipher_key Pointer to the host cipher key buffer + * \param[in] host_secure_channel_keys_type Host secure channel keys type + * \param[out] host_mac_key_index Index of the MAC key in platform secure storage to be used under the session + * \param[out] host_cipher_key_index Index of the cipher key in platform secure storage to be used under the session * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_host_key_provisioning.dox */ -stse_ReturnCode_t stse_establish_host_key( - stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_establish_host_secure_channel_keys( + stse_Handle_t *pSTSE, stse_ecc_key_type_t ecdh_key_type, - stsafea_host_key_type_t host_secure_channel_keys_type, - PLAT_UI8 *host_mac_key, - PLAT_UI8 *host_cipher_key); + stse_aes_key_type_t host_secure_channel_keys_type, + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index); /** - * \brief Host key establishment authenticated - * \details This API establish host key after verifying entity signature (from STSAFE-A120) + * \brief Host secure channel keys establishment authenticated + * \details This API establish host secure channel keys after verifying entity signature (from STSAFE-A120) * \param[in] pSTSE Pointer to STSE Handler * \param[in] ecdh_key_type ECDH key pair type * \param[in] host_secure_channel_keys_type Host secure channel keys type * \param[in] tbs_hash_algo Hashing algorithm used for the signature * \param[in] tbs_public_key_slot Public key slot used for the signature * \param[in] tbs_private_key Private key associated to public key slot used for the signature - * \param[in] host_mac_key Pointer to the host mac key buffer - * \param[in] host_cipher_key Pointer to the host cipher key buffer + * \param[out] host_mac_key_index Index of the MAC key in platform secure storage to be used under the session + * \param[out] host_cipher_key_index Index of the cipher key in platform secure storage to be used under the session * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details \include{doc} stse_host_key_provisioning.dox * \warning Few specific cryptographic library required to have public key concatenated to private key for EdDSA mechanism. In such case, pPrivate_key pointer shall reference concatenated key pair buffer's address. */ -stse_ReturnCode_t stse_establish_host_key_authenticated( - stse_Handler_t *pSTSE, +stse_ReturnCode_t stse_establish_host_secure_channel_keys_authenticated( + stse_Handle_t *pSTSE, stse_ecc_key_type_t ecdh_key_type, - stsafea_host_key_type_t host_secure_channel_keys_type, + stse_aes_key_type_t host_secure_channel_keys_type, stse_hash_algorithm_t tbs_hash_algo, PLAT_UI8 tbs_public_key_slot, PLAT_UI8 *tbs_private_key, - PLAT_UI8 *host_mac_key, - PLAT_UI8 *host_cipher_key); + PLAT_UI32 *host_mac_key_index, + PLAT_UI32 *host_cipher_key_index); /** * \brief Get symmetric key slot count @@ -143,7 +155,7 @@ stse_ReturnCode_t stse_establish_host_key_authenticated( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_get_symmetric_key_slots_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pSymmetric_key_slot_count); /** @@ -155,7 +167,7 @@ stse_ReturnCode_t stse_get_symmetric_key_slots_count( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_get_symmetric_key_slot_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_information_t *pSymmetric_key_slot_info); @@ -168,7 +180,7 @@ stse_ReturnCode_t stse_get_symmetric_key_slot_info( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_get_symmetric_key_table_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 total_slot_count, stsafea_symmetric_key_slot_information_t *symmetric_key_table_info); @@ -181,7 +193,7 @@ stse_ReturnCode_t stse_get_symmetric_key_table_info( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_get_symmetric_key_slot_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_provisioning_ctrl_fields_t *pCtrl_fields); @@ -194,7 +206,7 @@ stse_ReturnCode_t stse_get_symmetric_key_slot_provisioning_ctrl_fields( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_set_symmetric_key_slot_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_provisioning_ctrl_fields_t *pCtrl_fields); @@ -208,7 +220,7 @@ stse_ReturnCode_t stse_set_symmetric_key_slot_provisioning_ctrl_fields( * \details \include{doc} stse_write_symmetric_key_plaintext.dox */ stse_ReturnCode_t stse_write_symmetric_key_plaintext( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pKey, stsafea_generic_key_information_t *pSymmetric_key_info); @@ -223,7 +235,7 @@ stse_ReturnCode_t stse_write_symmetric_key_plaintext( * \details \include{doc} stse_write_symmetric_key_wrapped.dox */ stse_ReturnCode_t stse_write_symmetric_key_wrapped( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pKey, stsafea_generic_key_information_t *key_info, stse_ecc_key_type_t kek_session_ecc_type); @@ -244,7 +256,7 @@ stse_ReturnCode_t stse_write_symmetric_key_wrapped( * \warning Few specific cryptographic library required to have public key concatenated to private key for EdDSA mechanism. In such case, pPrivate_key pointer shall reference concatenated key pair buffer's address. */ stse_ReturnCode_t stse_write_symmetric_key_wrapped_authenticated( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pKey, stsafea_generic_key_information_t *key_info, stse_ecc_key_type_t kek_session_ecc_type, @@ -265,7 +277,7 @@ stse_ReturnCode_t stse_write_symmetric_key_wrapped_authenticated( * \details \include{doc} stse_establish_symmetric_key.dox */ stse_ReturnCode_t stse_establish_symmetric_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t ecc_key_type, PLAT_UI8 key_infos_count, stsafea_generic_key_information_t *key_infos_list, @@ -288,7 +300,7 @@ stse_ReturnCode_t stse_establish_symmetric_key( * \warning Few specific cryptographic library required to have public key concatenated to private key for EdDSA mechanism. In such case, pPrivate_key pointer shall reference concatenated key pair buffer's address. */ stse_ReturnCode_t stse_establish_symmetric_key_authenticated( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 key_infos_count, stsafea_generic_key_information_t *key_infos_list, diff --git a/certificate/stse_certificate.c b/certificate/stse_certificate.c index 81fe3a40..aa6ee2ec 100644 --- a/certificate/stse_certificate.c +++ b/certificate/stse_certificate.c @@ -22,7 +22,7 @@ #include #include -stse_Handler_t *stsafe_x509_parser_companion_handler = NULL; +stse_Handle_t *stsafe_x509_parser_companion_handler = NULL; /** * \brief Parse the extensions part of a certificate @@ -392,7 +392,7 @@ stse_ReturnCode_t stse_certificate_parse_chain( return ret; } -void stse_certificate_set_stse_companion(stse_Handler_t *pSTSE) { +void stse_certificate_set_stse_companion(stse_Handle_t *pSTSE) { if (pSTSE != NULL) { stsafe_x509_parser_companion_handler = pSTSE; } diff --git a/certificate/stse_certificate.h b/certificate/stse_certificate.h index f85a9847..7adc4b59 100644 --- a/certificate/stse_certificate.h +++ b/certificate/stse_certificate.h @@ -104,7 +104,7 @@ stse_ReturnCode_t stse_certificate_parse_chain( * \brief Assign the certificate parser STSAFE-A companion * \param[in] pSTSE Pointer to STSAFE handler */ -void stse_certificate_set_stse_companion(stse_Handler_t *pSTSE); +void stse_certificate_set_stse_companion(stse_Handle_t *pSTSE); /** * \brief Reset the certificate parser STSAFE-A companion diff --git a/certificate/stse_certificate_prints.c b/certificate/stse_certificate_prints.c index 89250dd2..8809eeb7 100644 --- a/certificate/stse_certificate_prints.c +++ b/certificate/stse_certificate_prints.c @@ -17,8 +17,8 @@ #include "certificate/stse_certificate_prints.h" #include "certificate/stse_certificate_subparsing.h" +#include "core/stse_platform.h" #include -#include #include /** @brief print the extensionsFlags field of a certificate */ @@ -27,61 +27,61 @@ static void printExtensions(PLAT_UI32 extensionsFlags); void stse_certificate_print_tag(PLAT_I32 tag) { switch (tag) { case TAG_BOOLEAN: - printf("Boolean"); + stse_platform_printf("Boolean"); break; case TAG_INTEGER: - printf("Integer"); + stse_platform_printf("Integer"); break; case TAG_BITSTRING: - printf("Bistring"); + stse_platform_printf("Bistring"); break; case TAG_OCTETSTRING: - printf("Octectstring"); + stse_platform_printf("Octectstring"); break; case TAG_NULL: - printf("Null"); + stse_platform_printf("Null"); break; case TAG_OBJECT_IDENTIFIER: - printf("Object Identifier"); + stse_platform_printf("Object Identifier"); break; case TAG_ObjectDescriptor: - printf("Object Descriptor"); + stse_platform_printf("Object Descriptor"); break; case TAG_ENUMERATED: - printf("Enumerated"); + stse_platform_printf("Enumerated"); break; case TAG_UTF8String: - printf("UTF8"); + stse_platform_printf("UTF8"); break; case TAG_SEQUENCE: - printf("Sequence"); + stse_platform_printf("Sequence"); break; case TAG_SET: - printf("Set"); + stse_platform_printf("Set"); break; case TAG_PrintableString: - printf("PrintableString"); + stse_platform_printf("PrintableString"); break; case TAG_IA5String: - printf("IA5String"); + stse_platform_printf("IA5String"); break; case TAG_UTCTime: - printf("UTCTime"); + stse_platform_printf("UTCTime"); break; case TAG_GeneralizedTime: - printf("GeneralizedTime"); + stse_platform_printf("GeneralizedTime"); break; case TAG_x509VERSION: - printf("x509VERSION"); + stse_platform_printf("x509VERSION"); break; case TAG_subjectUniqueID: - printf("subjectUniqueID"); + stse_platform_printf("subjectUniqueID"); break; case TAG_extensions: - printf("extensions"); + stse_platform_printf("extensions"); break; case TAG_issuerUniqueID: - printf("issuerUniqueID"); + stse_platform_printf("issuerUniqueID"); break; } } @@ -89,25 +89,25 @@ void stse_certificate_print_tag(PLAT_I32 tag) { void stse_certificate_print_signature_algorithm(PLAT_I32 type) { switch (type) { case SIG_EDDSA_ED25519: - printf("eddsa-with-SHA256"); + stse_platform_printf("eddsa-with-SHA256"); break; case SIG_ECDSA_SHA1: - printf("ecdsa-with-SHA1"); + stse_platform_printf("ecdsa-with-SHA1"); break; case SIG_ECDSA_SHA224: - printf("ecdsa-with-SHA224"); + stse_platform_printf("ecdsa-with-SHA224"); break; case SIG_ECDSA_SHA256: - printf("ecdsa-with-SHA256"); + stse_platform_printf("ecdsa-with-SHA256"); break; case SIG_ECDSA_SHA384: - printf("ecdsa-with-SHA384"); + stse_platform_printf("ecdsa-with-SHA384"); break; case SIG_ECDSA_SHA512: - printf("ecdsa-with-SHA512"); + stse_platform_printf("ecdsa-with-SHA512"); break; default: - printf("Failed Identification of SignatureAlgorithm"); + stse_platform_printf("Failed Identification of SignatureAlgorithm"); break; } } @@ -115,34 +115,34 @@ void stse_certificate_print_signature_algorithm(PLAT_I32 type) { void stse_certificate_print_attribute(PLAT_I32 type) { switch (type) { case ATTR_CN: - printf("CommonName"); + stse_platform_printf("CommonName"); break; case ATTR_C: - printf("CountryName"); + stse_platform_printf("CountryName"); break; case ATTR_SN: - printf("SerialNumber"); + stse_platform_printf("SerialNumber"); break; case ATTR_DN: - printf("DistinguishedName"); + stse_platform_printf("DistinguishedName"); break; case ATTR_ON: - printf("OrganizationalName"); + stse_platform_printf("OrganizationalName"); break; case ATTR_OUN: - printf("OrganizationalUnitName"); + stse_platform_printf("OrganizationalUnitName"); break; case ATTR_SOPN: - printf("StateOrProvinceName"); + stse_platform_printf("StateOrProvinceName"); break; case ATTR_LN: - printf("LocalityName"); + stse_platform_printf("LocalityName"); break; case ATTR_UID: - printf("UniqueIdentifier"); + stse_platform_printf("UniqueIdentifier"); break; default: - printf("Failed Identification of Attribute"); + stse_platform_printf("Failed Identification of Attribute"); break; } } @@ -150,38 +150,38 @@ void stse_certificate_print_attribute(PLAT_I32 type) { void stse_certificate_print_elliptic_curve(PLAT_I32 type) { switch (type) { case EC_P256: - printf("P-256"); + stse_platform_printf("P-256"); break; case EC_P384: - printf("P-384"); + stse_platform_printf("P-384"); break; case EC_P521: - printf("P-521"); + stse_platform_printf("P-521"); break; case EC_bp256r1: - printf("brainpoolP256r1"); + stse_platform_printf("brainpoolP256r1"); break; case EC_bp256t1: - printf("brainpoolP256t1"); + stse_platform_printf("brainpoolP256t1"); break; case EC_bp384r1: - printf("brainpoolP384r1"); + stse_platform_printf("brainpoolP384r1"); break; case EC_bp384t1: - printf("brainpoolP384t1"); + stse_platform_printf("brainpoolP384t1"); break; case EC_bp512r1: - printf("brainpoolP512r1"); + stse_platform_printf("brainpoolP512r1"); break; case EC_bp512t1: - printf("brainpoolP512t1"); + stse_platform_printf("brainpoolP512t1"); break; case EC_Ed25519: - printf("ed25519"); + stse_platform_printf("ed25519"); break; default: - printf("Failed Identification of EllipticCurve"); + stse_platform_printf("Failed Identification of EllipticCurve"); break; } } @@ -192,14 +192,14 @@ PLAT_I32 stse_certificate_print_bit_string(const PLAT_UI8 *value, PLAT_I32 size) This is a feature we don't support */ if (value[0] != 0) { - printf("BITSTRING exclues some LSBits, we don't handle that, error!\n"); + stse_platform_printf("BITSTRING exclues some LSBits, we don't handle that, error!\n"); return (-1); } /* Print the remaining string */ for (i = 1; i < size; i++) { - printf("%02X", value[i]); + stse_platform_printf("%02X", value[i]); if (i % 16 == 0 && i != size - 1) - printf("\n\t\t"); + stse_platform_printf("\n\t\t"); } return (0); } @@ -208,7 +208,7 @@ PLAT_I32 stse_certificate_print_integer(const PLAT_UI8 *value, PLAT_I32 size) { PLAT_I32 i = 0; /* The first byte tells us if it's positive or negative. We don't support negative */ if (value[0] >> 7 == 1) { - printf("Integer is negative, we don't handle that, error!\n"); + stse_platform_printf("Integer is negative, we don't handle that, error!\n"); return (-1); } /* First byte might be zero in case Integer is positive and first byte >127 */ @@ -218,9 +218,9 @@ PLAT_I32 stse_certificate_print_integer(const PLAT_UI8 *value, PLAT_I32 size) { } /* And print the rest */ for (; i < size; i++) { - printf("%02X", value[i]); + stse_platform_printf("%02X", value[i]); if (i % 16 == 0 && (i != size - 1) && i != 0) - printf("\n\t\t"); + stse_platform_printf("\n\t\t"); } return (0); } @@ -228,40 +228,40 @@ PLAT_I32 stse_certificate_print_integer(const PLAT_UI8 *value, PLAT_I32 size) { /* Print a byte buffer */ static void print_buffer(const char *str, const PLAT_UI8 *buf, PLAT_I32 bufsize) { PLAT_I32 i = 0; - printf("%s", str); + stse_platform_printf("%s", str); for (i = 0; i < bufsize; i++) { - printf("%02X", buf[i]); + stse_platform_printf("%02X", buf[i]); } } void stse_certificate_print_parsed_cert(stse_certificate_t *stse_certificate) { - //printf("Fields: %08X\n", stse_certificate->fields); - //printFields(stse_certificate->fields); + //stse_platform_printf("Fields: %08X\n", stse_certificate->fields); + //stse_platform_printfields(stse_certificate->fields); - printf("\n\r\t x509 Version: %" PRIi32, stse_certificate->x509Version + 1); + stse_platform_printf("\n\r\t x509 Version: %" PRIi32, stse_certificate->x509Version + 1); if (stse_certificate->serialNumber != NULL && stse_certificate->serialNumberSize > 0) print_buffer("\n\r\tSerialNumber: ", stse_certificate->serialNumber, stse_certificate->serialNumberSize); if (stse_certificate->issuer != NULL && stse_certificate->issuerSize > 0) { - printf("\n\r\t Issuer:"); + stse_platform_printf("\n\r\t Issuer:"); stse_certificate_print_name(stse_certificate->issuer, stse_certificate->issuerSize); } if (stse_certificate->subject != NULL && stse_certificate->subjectSize > 0) { - printf("\n\r\t Subject:"); + stse_platform_printf("\n\r\t Subject:"); stse_certificate_print_name(stse_certificate->subject, stse_certificate->subjectSize); } stse_certificate_print_validity(stse_certificate->validity); - printf("\n\r\t SignatureAlgorithm: "); + stse_platform_printf("\n\r\t SignatureAlgorithm: "); stse_certificate_print_signature_algorithm(stse_certificate->SignatureAlgorithm); - printf("\n\r\t tbsSignature: "); + stse_platform_printf("\n\r\t tbsSignature: "); stse_certificate_print_signature_algorithm(stse_certificate->signature); - printf("\n\r\t EllipticCurve: "); + stse_platform_printf("\n\r\t EllipticCurve: "); stse_certificate_print_elliptic_curve(stse_certificate->EllipticCurve); - printf("\n\r\t Cert PubKey (%s): ", *stse_certificate->pPubKey_point_representation_id == 0x04 ? "Uncompressed" : "Compressed"); + stse_platform_printf("\n\r\t Cert PubKey (%s): ", *stse_certificate->pPubKey_point_representation_id == 0x04 ? "Uncompressed" : "Compressed"); print_buffer("\n\r\t\t X: ", stse_certificate->PubKey.pX, stse_certificate->PubKey.fsize); if (*stse_certificate->pPubKey_point_representation_id == 0x04) { print_buffer("\n\r\t\t Y: ", stse_certificate->PubKey.pY, stse_certificate->PubKey.fsize); } - printf("\n\r\t Cert Signature: "); + stse_platform_printf("\n\r\t Cert Signature: "); print_buffer("\n\r\t\t r: ", stse_certificate->Sign.pR, stse_certificate->Sign.rSize); print_buffer("\n\r\t\t s :", stse_certificate->Sign.pS, stse_certificate->Sign.sSize); printExtensions(stse_certificate->extensionsFlags); @@ -301,15 +301,15 @@ void stse_certificate_print_name(const PLAT_UI8 *name, PLAT_I32 nameSize) { while (next < name + nameSize) { attribute_st.type = -1; stse_certificate_simple_parse_attribute(next, &attribute_st, &next); - printf("\n\r\t\t "); + stse_platform_printf("\n\r\t\t "); stse_certificate_print_attribute(attribute_st.type); - printf(": "); + stse_platform_printf(": "); if (attribute_st.type != -1 && (attribute_st.strFormat == TAG_PrintableString || attribute_st.strFormat == TAG_UTF8String)) { PLAT_I32 i; for (i = 0; i < attribute_st.strSize; i++) { - printf("%c", attribute_st.str[i]); + stse_platform_printf("%c", attribute_st.str[i]); } } else if (attribute_st.type != -1 && attribute_st.strFormat == TAG_BITSTRING) { stse_certificate_print_bit_string(attribute_st.str, attribute_st.strSize); @@ -322,65 +322,65 @@ void stse_certificate_print_validity(const PLAT_UI8 *validity) { stse_cert_validity_t notBefore_st, notAfter_st; const PLAT_UI8 *next; stse_certificate_parse_validity(validity, ¬Before_st, ¬After_st, &next); - printf("\n\r\t Validity:"); - printf("\n\r\t\t Not Before: %04" PRIu32 "-%02d-%02d %02d:%02d:%02d", notBefore_st.year, notBefore_st.month, notBefore_st.days, notBefore_st.hours, notBefore_st.minutes, notBefore_st.seconds); - printf("\n\r\t\t Not After: %04" PRIu32 "-%02d-%02d %02d:%02d:%02d", notAfter_st.year, notAfter_st.month, notAfter_st.days, notAfter_st.hours, notAfter_st.minutes, notAfter_st.seconds); + stse_platform_printf("\n\r\t Validity:"); + stse_platform_printf("\n\r\t\t Not Before: %04" PRIu32 "-%02d-%02d %02d:%02d:%02d", notBefore_st.year, notBefore_st.month, notBefore_st.days, notBefore_st.hours, notBefore_st.minutes, notBefore_st.seconds); + stse_platform_printf("\n\r\t\t Not After: %04" PRIu32 "-%02d-%02d %02d:%02d:%02d", notAfter_st.year, notAfter_st.month, notAfter_st.days, notAfter_st.hours, notAfter_st.minutes, notAfter_st.seconds); } static void printExtensions(PLAT_UI32 extensionsFlags) { - printf("\n\r\t List of Extensions:"); + stse_platform_printf("\n\r\t List of Extensions:"); if ((extensionsFlags & 1) == 1) { - printf("\n\r\t\t BasicConstraints: "); + stse_platform_printf("\n\r\t\t BasicConstraints: "); if (((extensionsFlags >> 1) & 1) == 1) { - printf("Critical. "); + stse_platform_printf("Critical. "); } if (((extensionsFlags >> 2) & 1) == 1) { - printf("CA certificate. "); + stse_platform_printf("CA certificate. "); } else { - printf("Not a CA certificate. "); + stse_platform_printf("Not a CA certificate. "); } if (((extensionsFlags >> 3) & 1) == 1) { - printf("PathSize: %" PRIu32, (extensionsFlags >> 4) & 15); + stse_platform_printf("PathSize: %" PRIu32, (extensionsFlags >> 4) & 15); } } if (((extensionsFlags >> 8) & 1) == 1) { - printf("\n\r\t\t KeyUsage: "); + stse_platform_printf("\n\r\t\t KeyUsage: "); if (((extensionsFlags >> 9) & 1) == 1) { - printf("Critical. "); + stse_platform_printf("Critical. "); } if (((extensionsFlags >> (16 + 0)) & 1) == 1) { - printf("digitalSignature "); + stse_platform_printf("digitalSignature "); } if (((extensionsFlags >> (16 + 1)) & 1) == 1) { - printf("contentCommitment "); + stse_platform_printf("contentCommitment "); } if (((extensionsFlags >> (16 + 2)) & 1) == 1) { - printf("keyEncipherment "); + stse_platform_printf("keyEncipherment "); } if (((extensionsFlags >> (16 + 3)) & 1) == 1) { - printf("dataEncipherment "); + stse_platform_printf("dataEncipherment "); } if (((extensionsFlags >> (16 + 4)) & 1) == 1) { - printf("keyAgreement "); + stse_platform_printf("keyAgreement "); } if (((extensionsFlags >> (16 + 5)) & 1) == 1) { - printf("keyCertSign "); + stse_platform_printf("keyCertSign "); } if (((extensionsFlags >> (16 + 6)) & 1) == 1) { - printf("cRLSign "); + stse_platform_printf("cRLSign "); } if (((extensionsFlags >> (16 + 7)) & 1) == 1) { - printf("encipherOnly "); + stse_platform_printf("encipherOnly "); } if (((extensionsFlags >> (15)) & 1) == 1) { - printf("decipherOnly "); + stse_platform_printf("decipherOnly "); } } if (((extensionsFlags >> 24) & 1) == 1) { - printf("\n\r\t\t ExtendedKeyUsage: "); + stse_platform_printf("\n\r\t\t ExtendedKeyUsage: "); if (((extensionsFlags >> 25) & 1) == 1) { - printf("Critical. "); + stse_platform_printf("Critical. "); } } } diff --git a/certificate/stse_certificate_types.h b/certificate/stse_certificate_types.h index f7eb234b..b33c128e 100644 --- a/certificate/stse_certificate_types.h +++ b/certificate/stse_certificate_types.h @@ -228,7 +228,7 @@ typedef struct stse_internal_certificate stse_certificate_t; /* Exported Variables */ -extern stse_Handler_t *stsafe_x509_parser_companion_handler; +extern stse_Handle_t *stsafe_x509_parser_companion_handler; /** @}*/ diff --git a/core/stse_device.c b/core/stse_device.c index 5d779f3c..d292d93d 100644 --- a/core/stse_device.c +++ b/core/stse_device.c @@ -20,7 +20,7 @@ #include "core/stse_platform.h" #include -stse_ReturnCode_t stse_set_default_handler_value(stse_Handler_t *pStseHandler) { +stse_ReturnCode_t stse_set_default_handler_value(stse_Handle_t *pStseHandler) { if (pStseHandler == NULL) { return STSE_CORE_HANDLER_NOT_INITIALISED; } diff --git a/core/stse_device.h b/core/stse_device.h index 95191c7b..c6b73ad1 100644 --- a/core/stse_device.h +++ b/core/stse_device.h @@ -34,7 +34,7 @@ extern "C" { * @{ */ -typedef struct stse_Handler_t stse_Handler_t; +typedef struct stse_Handle_t stse_Handle_t; /* * \brief STSE Session_type type @@ -164,9 +164,9 @@ struct stse_session_t { stse_session_type_t type; union { struct { - stse_Handler_t *pSTSE; - PLAT_UI8 *pHost_MAC_key; - PLAT_UI8 *pHost_cypher_key; + stse_Handle_t *pSTSE; + PLAT_UI32 host_MAC_key_idx; + PLAT_UI32 host_cypher_key_idx; stse_aes_key_type_t key_type; PLAT_UI32 MAC_counter; } host; @@ -179,13 +179,13 @@ struct stse_session_t { } PLAT_PACKED_STRUCT; /*! - * \typedef stse_Handler_t + * \typedef stse_Handle_t * \brief STSE Handler * This handler stores all the context and working data related to a specific STSE target. \n * Pointer to a specific stsafe_Handler is the main parameters of all STSE middleware API functions. \n * A specific STSE target Handler must be initialized using the "stsafe_init" API function */ -struct stse_Handler_t { +struct stse_Handle_t { stse_device_t device_type; stse_perso_info_t perso_info; stse_session_t *pActive_host_session; @@ -201,7 +201,7 @@ struct stse_Handler_t { * \param[in] pStseHandler : Pointer to STSE handler * \return \ref stse_ReturnCode_t : STSE_OK on success ; error code otherwise */ -stse_ReturnCode_t stse_set_default_handler_value(stse_Handler_t *pStseHandler); +stse_ReturnCode_t stse_set_default_handler_value(stse_Handle_t *pStseHandler); /*! @}*/ diff --git a/core/stse_frame.c b/core/stse_frame.c index e8f92db2..eac1f533 100644 --- a/core/stse_frame.c +++ b/core/stse_frame.c @@ -164,25 +164,25 @@ void stse_frame_debug_print(stse_frame_t *pFrame) { PLAT_UI16 data_index; if (pFrame->element_count == 0) { - printf("\n\r (EMPTY)"); + stse_platform_printf("\n\r (EMPTY)"); return; } pCurrent_element = pFrame->first_element; - printf(" (%d-byte) :", pFrame->length); + stse_platform_printf(" (%d-byte) :", pFrame->length); do { - printf(" { "); + stse_platform_printf(" { "); if (pCurrent_element->length == 0) { - printf("S "); + stse_platform_printf("S "); } else { for (data_index = 0; data_index < pCurrent_element->length; data_index++) { if (pCurrent_element->pData != NULL) { - printf("0x%02X ", pCurrent_element->pData[data_index]); + stse_platform_printf("0x%02X ", pCurrent_element->pData[data_index]); } else { - printf("0x00 "); + stse_platform_printf("0x00 "); } } } - printf("}"); + stse_platform_printf("}"); pCurrent_element = pCurrent_element->next; } while (pCurrent_element != NULL); } diff --git a/core/stse_generic_typedef.c b/core/stse_generic_typedef.c index 12bab7d4..03ec0139 100644 --- a/core/stse_generic_typedef.c +++ b/core/stse_generic_typedef.c @@ -27,7 +27,7 @@ const stse_ecc_info_t stse_ecc_info_table[] = !defined(STSE_CONF_ECC_CURVE_25519) && !defined(STSE_CONF_ECC_EDWARD_25519) {0}; #else - { +{ #ifdef STSE_CONF_ECC_NIST_P_256 [STSE_ECC_KT_NIST_P_256] = {/* NIST P 256 */ .curve_id_total_length = (STSE_NIST_P_256_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE), @@ -38,7 +38,7 @@ const stse_ecc_info_t stse_ecc_info_table[] = .private_key_size = (STSE_NIST_P_256_PRIVATE_KEY_SIZE), .shared_secret_size = (STSE_NIST_P_256_X_COORDINATE_VALUE_SIZE), .signature_size = (STSE_NIST_P_256_SIGNATURE_R_VALUE_SIZE + STSE_NIST_P_256_SIGNATURE_S_VALUE_SIZE)}, -#endif +#endif /* STSE_CONF_ECC_NIST_P_256 */ #ifdef STSE_CONF_ECC_NIST_P_384 [STSE_ECC_KT_NIST_P_384] = {/* NIST P_384 */ .curve_id_total_length = (STSE_NIST_P_384_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE), @@ -48,7 +48,7 @@ const stse_ecc_info_t stse_ecc_info_table[] = .private_key_size = (STSE_NIST_P_384_PRIVATE_KEY_SIZE), .shared_secret_size = (STSE_NIST_P_384_X_COORDINATE_VALUE_SIZE), .signature_size = (STSE_NIST_P_384_SIGNATURE_R_VALUE_SIZE + STSE_NIST_P_384_SIGNATURE_S_VALUE_SIZE)}, -#endif +#endif /* STSE_CONF_ECC_NIST_P_384 */ #ifdef STSE_CONF_ECC_NIST_P_521 [STSE_ECC_KT_NIST_P_521] = {/* NIST P 521 */ .curve_id_total_length = (STSE_NIST_P_521_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE), @@ -58,7 +58,7 @@ const stse_ecc_info_t stse_ecc_info_table[] = .private_key_size = (STSE_NIST_P_521_PRIVATE_KEY_SIZE), .shared_secret_size = (STSE_NIST_P_521_X_COORDINATE_VALUE_SIZE), .signature_size = (STSE_NIST_P_521_SIGNATURE_R_VALUE_SIZE + STSE_NIST_P_521_SIGNATURE_S_VALUE_SIZE)}, -#endif +#endif /* STSE_CONF_ECC_NIST_P_521 */ #ifdef STSE_CONF_ECC_BRAINPOOL_P_256 [STSE_ECC_KT_BP_P_256] = {/* BRAINPOOL P 256 */ .curve_id_total_length = (STSE_BRAINPOOL_P_256_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE), @@ -68,7 +68,7 @@ const stse_ecc_info_t stse_ecc_info_table[] = .private_key_size = (STSE_BRAINPOOL_P_256_PRIVATE_KEY_SIZE), .shared_secret_size = (STSE_BRAINPOOL_P_256_X_COORDINATE_VALUE_SIZE), .signature_size = (STSE_BRAINPOOL_P_256_SIGNATURE_R_VALUE_SIZE + STSE_BRAINPOOL_P_256_SIGNATURE_S_VALUE_SIZE)}, -#endif +#endif /* STSE_CONF_ECC_BRAINPOOL_P_256 */ #ifdef STSE_CONF_ECC_BRAINPOOL_P_384 [STSE_ECC_KT_BP_P_384] = {/* BRAINPOOL P 384 */ .curve_id_total_length = (STSE_BRAINPOOL_P_384_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE), @@ -78,7 +78,7 @@ const stse_ecc_info_t stse_ecc_info_table[] = .private_key_size = (STSE_BRAINPOOL_P_384_PRIVATE_KEY_SIZE), .shared_secret_size = (STSE_BRAINPOOL_P_384_X_COORDINATE_VALUE_SIZE), .signature_size = (STSE_BRAINPOOL_P_384_SIGNATURE_R_VALUE_SIZE + STSE_BRAINPOOL_P_384_SIGNATURE_S_VALUE_SIZE)}, -#endif +#endif /* STSE_CONF_ECC_BRAINPOOL_P_384 */ #ifdef STSE_CONF_ECC_BRAINPOOL_P_512 [STSE_ECC_KT_BP_P_512] = {/* BRAINPOOL P 512 */ .curve_id_total_length = (STSE_BRAINPOOL_P_512_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE), @@ -88,7 +88,7 @@ const stse_ecc_info_t stse_ecc_info_table[] = .private_key_size = (STSE_BRAINPOOL_P_512_PRIVATE_KEY_SIZE), .shared_secret_size = (STSE_BRAINPOOL_P_512_X_COORDINATE_VALUE_SIZE), .signature_size = (STSE_BRAINPOOL_P_512_SIGNATURE_R_VALUE_SIZE + STSE_BRAINPOOL_P_512_SIGNATURE_S_VALUE_SIZE)}, -#endif +#endif /* STSE_CONF_ECC_BRAINPOOL_P_512 */ #ifdef STSE_CONF_ECC_CURVE_25519 [STSE_ECC_KT_CURVE25519] = {/* X25519 */ .curve_id_total_length = (STSE_X25519_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE), @@ -98,7 +98,7 @@ const stse_ecc_info_t stse_ecc_info_table[] = .private_key_size = STSE_X25519_PRIVATE_KEY_SIZE, .shared_secret_size = STSE_X25519_SHARED_SECRET_VALUE_SIZE, .signature_size = 0}, -#endif +#endif /* STSE_CONF_ECC_CURVE_25519 */ #ifdef STSE_CONF_ECC_EDWARD_25519 [STSE_ECC_KT_ED25519] = {/* ED25519 */ .curve_id_total_length = (STSE_ED25519_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE), @@ -108,7 +108,7 @@ const stse_ecc_info_t stse_ecc_info_table[] = .private_key_size = STSE_ED25519_PRIVATE_KEY_SIZE, .shared_secret_size = 0, .signature_size = (STSE_ED25519_SIGNATURE_R_VALUE_SIZE + STSE_ED25519_SIGNATURE_S_VALUE_SIZE)}, -#endif +#endif /* STSE_CONF_ECC_EDWARD_25519 */ }; #endif @@ -116,28 +116,21 @@ const stse_ecc_info_t stse_ecc_info_table[] = defined(STSE_CONF_ECC_BRAINPOOL_P_256) || defined(STSE_CONF_ECC_BRAINPOOL_P_384) || defined(STSE_CONF_ECC_BRAINPOOL_P_512) || \ defined(STSE_CONF_ECC_CURVE_25519) || defined(STSE_CONF_ECC_EDWARD_25519) -stse_ReturnCode_t stse_get_ecc_key_type_from_curve_id( - PLAT_UI8 curve_id_length, - const PLAT_UI8 *pCurve_id_value, - stse_ecc_key_type_t *pKey_type) { - stse_ReturnCode_t ret = STSE_OK; - stse_ecc_key_type_t key_type; +stse_ecc_key_type_t stse_get_ecc_key_type_from_curve_id(const stsafea_ecc_curve_id_t curve_id[static 1]) { + stse_ecc_key_type_t key_type = (stse_ecc_key_type_t)0; - for (key_type = (stse_ecc_key_type_t)0; (PLAT_I8)key_type < (PLAT_I8)STSE_ECC_KT_INVALID;) { - PLAT_UI8 info_curve_id_length = stse_ecc_info_table[key_type].curve_id_total_length - STSE_ECC_GENERIC_LENGTH_SIZE; - if (curve_id_length == info_curve_id_length) { - if (memcmp(stse_ecc_info_table[key_type].curve_id.value, - pCurve_id_value, - info_curve_id_length) == 0) { - break; - } + // Compare slot curve ID against each known curve ID + while (key_type < STSE_ECC_KT_INVALID) { + /* The curve id is compared byte-for-byte with memcmp. This is valid because + * stsafea_ecc_curve_id_t is a packed struct (PLAT_PACKED_STRUCT): its `length` and `value` + * fields sit contiguously with no padding, so the first curve_id_total_length bytes are + * exactly the curve-id byte sequence, with no padding bytes to cause a spurious mismatch. */ + if (memcmp(&(stse_ecc_info_table[key_type].curve_id), curve_id, stse_ecc_info_table[key_type].curve_id_total_length) == 0) { + break; } key_type++; } - *pKey_type = key_type; - - return ret; + return key_type; } - #endif diff --git a/core/stse_generic_typedef.h b/core/stse_generic_typedef.h index f5b37acf..abb79780 100644 --- a/core/stse_generic_typedef.h +++ b/core/stse_generic_typedef.h @@ -108,9 +108,21 @@ typedef enum stse_ecc_key_type_t { */ typedef enum stse_aes_key_type_t { STSE_AES_128_KT = 0x00, - STSE_AES_256_KT + STSE_AES_256_KT, + STSE_AES_INVALID_KT } stse_aes_key_type_t; +/*! + * \enum stse_aes_key_usage_t + * \brief STSE AES key usage + */ +typedef enum stse_aes_key_usage_t { + STSE_AES_KEY_USAGE_MAC = 0, /**< Key used for host MAC operations */ + STSE_AES_KEY_USAGE_CIPHER, /**< Key used for host cipher operations */ + STSE_AES_KEY_USAGE_GENERIC_SECRET, /**< Generic secret: AES key with variable-length keys (from 16 to 32 bytes) */ + STSE_AES_KEY_USAGE_INVALID +} stse_aes_key_usage_t; + /*! * \enum stse_hash_algorithm_t * \brief STSE Hash algorithm type @@ -164,6 +176,17 @@ typedef enum stse_cmd_protection_t { STSE_HOST_C_WRAP_R_WRAP /*!< Encrypted and authenticated command and response using HOST MAC and cipher Keys*/ } stse_cmd_protection_t; +/*! + * \struct stse_aes_key_t + * \brief STSE AES key type + */ +typedef struct +{ + stse_aes_key_type_t type; + stse_aes_key_usage_t usage; + PLAT_UI8 key[STSE_AES_256_KEY_SIZE]; +} stse_aes_key_t; + /*! * \struct stse_cmd_authorization_CR_t * \brief STSE commands authorization change request type @@ -566,24 +589,15 @@ typedef struct { extern const stse_ecc_info_t stse_ecc_info_table[]; -#if defined(STSE_CONF_ECC_NIST_P_256) || defined(STSE_CONF_ECC_NIST_P_384) || defined(STSE_CONF_ECC_NIST_P_521) || \ - defined(STSE_CONF_ECC_BRAINPOOL_P_256) || defined(STSE_CONF_ECC_BRAINPOOL_P_384) || defined(STSE_CONF_ECC_BRAINPOOL_P_512) || \ - defined(STSE_CONF_ECC_CURVE_25519) || defined(STSE_CONF_ECC_EDWARD_25519) - /** * \brief Get ECC key type from curve identifier - * \details This function resolves the ECC key type from a given curve identifier value - * \param[in] curve_id_length Length of the curve identifier - * \param[in] pCurve_id_value Pointer to the curve identifier value - * \param[out] pKey_type Pointer to store the resolved ECC key type - * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise + * \details This function resolves the ECC key type from a given curve identifier by + * comparing it against each entry of \ref stse_ecc_info_table. + * \param[in] curve_id Pointer to the curve identifier (length + value) to resolve + * \return The matching \ref stse_ecc_key_type_t ; + * \ref STSE_ECC_KT_INVALID if the curve identifier is not recognized */ -stse_ReturnCode_t stse_get_ecc_key_type_from_curve_id( - PLAT_UI8 curve_id_length, - const PLAT_UI8 *pCurve_id_value, - stse_ecc_key_type_t *pKey_type); - -#endif +stse_ecc_key_type_t stse_get_ecc_key_type_from_curve_id(const stsafea_ecc_curve_id_t curve_id[static 1]); /** \}*/ diff --git a/core/stse_platform.h b/core/stse_platform.h index 3dc775b0..6dafd3a8 100644 --- a/core/stse_platform.h +++ b/core/stse_platform.h @@ -37,33 +37,43 @@ /*! * \brief Platform delay initialization callback function + * \param[in] pArg Argument coming from \ref stse_init through its `pArg` parameter * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_platform_delay_init(void); +stse_ReturnCode_t stse_platform_delay_init(void *pArg); /*! * \brief Platform power control initialization callback function + * \param[in] pArg Argument coming from \ref stse_init through its `pArg` parameter * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_platform_power_init(void); +stse_ReturnCode_t stse_platform_power_init(void *pArg); /*! * \brief Platform CRC16 initialization callback function + * \param[in] pArg Argument coming from \ref stse_init through its `pArg` parameter * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_platform_crc16_init(void); +stse_ReturnCode_t stse_platform_crc16_init(void *pArg); /*! * \brief Platform crypto library initialization callback function + * \param[in] pArg Argument coming from \ref stse_init through its `pArg` parameter * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_platform_crypto_init(void); +stse_ReturnCode_t stse_platform_crypto_init(void *pArg); /*! * \brief Platform random number generation initialization callback function + * \param[in] pArg Argument coming from \ref stse_init through its `pArg` parameter * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_platform_generate_random_init(void); +stse_ReturnCode_t stse_platform_generate_random_init(void *pArg); + +/*! + * \brief Platform log abstraction + */ +void stse_platform_printf(const char *format, ...); /*! * \brief Platform generate random callback function @@ -210,14 +220,29 @@ stse_ReturnCode_t stse_platform_nist_kw_encrypt(PLAT_UI8 *pPayload, PLAT_UI32 pa #if defined(STSE_CONF_USE_HOST_KEY_ESTABLISHMENT) || defined(STSE_CONF_USE_SYMMETRIC_KEY_ESTABLISHMENT) || defined(STSE_CONF_USE_HOST_SESSION) /*! - * \brief Initialize AES CMAC computation - * \param[in] pKey Pointer to the key + * \brief Store aes key in platform secure storage + * \param[in] pKey Pointer to the aes key * \param[in] key_length Length of the key + * \param[in] usage Key usage type, used by the platform to set the appropriate key attributes in secure storage + * \param[out] pKey_idx Pointer to the index assigned to the stored key in secure storage + * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise + */ +stse_ReturnCode_t stse_platform_store_aes_key(PLAT_UI8 *pKey, PLAT_UI16 key_length, stse_aes_key_usage_t usage, PLAT_UI32 *pKey_idx); + +/*! + * \brief Delete aes key from platform secure storage + * \param[in] key_idx Index of the key to delete from secure storage + * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise + */ +stse_ReturnCode_t stse_platform_delete_aes_key(PLAT_UI32 key_idx); + +/*! + * \brief Initialize AES CMAC computation + * \param[in] key_idx Index of the key to use for AES CMAC computation in secure storage * \param[in] exp_tag_size Expected tag size * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_platform_aes_cmac_init(const PLAT_UI8 *pKey, - PLAT_UI16 key_length, +stse_ReturnCode_t stse_platform_aes_cmac_init(const PLAT_UI32 key_idx, PLAT_UI16 exp_tag_size); /*! @@ -247,15 +272,14 @@ stse_ReturnCode_t stse_platform_aes_cmac_verify_finish(PLAT_UI8 *pTag); * \brief Perform an AES CMAC encryption * \param[in] pPayload Pointer to Payload * \param[in] payload_length Length of the payload in bytes - * \param[in] pKey Pointer to key - * \param[in] key_length Length of the key in bytes + * \param[in] key_idx Index of the key to use for AES CMAC computation in secure storage * \param[in] exp_tag_size Expected tag size in bytes * \param[out] pTag Pointer to Tag * \param[out] pTag_length Pointer to Tag length value output * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_platform_aes_cmac_compute(const PLAT_UI8 *pPayload, PLAT_UI16 payload_length, - const PLAT_UI8 *pKey, PLAT_UI16 key_length, + const PLAT_UI32 key_idx, PLAT_UI16 exp_tag_size, PLAT_UI8 *pTag, PLAT_UI16 *pTag_length); @@ -263,14 +287,13 @@ stse_ReturnCode_t stse_platform_aes_cmac_compute(const PLAT_UI8 *pPayload, PLAT_ * \brief Perform an AES CMAC decryption * \param[in] pPayload Pointer to Payload * \param[in] payload_length Length of the payload in bytes - * \param[in] pKey Pointer to key - * \param[in] key_length Length of the key in bytes + * \param[in] key_idx Index of the key to use for AES CMAC computation in secure storage * \param[in] pTag Pointer to Tag * \param[in] tag_length Pointer to Tag length value output * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_platform_aes_cmac_verify(const PLAT_UI8 *pPayload, PLAT_UI16 payload_length, - const PLAT_UI8 *pKey, PLAT_UI16 key_length, + const PLAT_UI32 key_idx, const PLAT_UI8 *pTag, PLAT_UI16 tag_length); /*! @@ -278,15 +301,13 @@ stse_ReturnCode_t stse_platform_aes_cmac_verify(const PLAT_UI8 *pPayload, PLAT_U * \param[in] pPlaintext Pointer to the plaintext data * \param[in] plaintext_length Length of the plaintext data * \param[in] pInitial_value Pointer to encryption IV - * \param[in] pKey Pointer to the key - * \param[in] key_length Length of the key + * \param[in] key_idx Index of the key to use for AES encryption in secure storage * \param[out] pEncryptedtext Pointer to the encrypted payload * \param[out] pEncryptedtext_length Length of encrypted payload * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_platform_aes_cbc_enc(const PLAT_UI8 *pPlaintext, PLAT_UI16 plaintext_length, - PLAT_UI8 *pInitial_value, const PLAT_UI8 *pKey, - PLAT_UI16 key_length, PLAT_UI8 *pEncryptedtext, + PLAT_UI8 *pInitial_value, const PLAT_UI32 key_idx, PLAT_UI8 *pEncryptedtext, PLAT_UI16 *pEncryptedtext_length); /*! @@ -294,30 +315,26 @@ stse_ReturnCode_t stse_platform_aes_cbc_enc(const PLAT_UI8 *pPlaintext, PLAT_UI1 * \param[in] pEncryptedtext Pointer to the encrypted payload * \param[in] encryptedtext_length Length of encrypted payload * \param[in] pInitial_value Pointer to decryption IV - * \param[in] pKey Pointer to the key - * \param[in] key_length Length of the key + * \param[in] key_idx Index of the key to use for AES decryption in secure storage * \param[out] pPlaintext Pointer to PlainText payload * \param[out] pPlaintext_length Length of the PlainText payload * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_platform_aes_cbc_dec(const PLAT_UI8 *pEncryptedtext, PLAT_UI16 encryptedtext_length, - PLAT_UI8 *pInitial_value, const PLAT_UI8 *pKey, - PLAT_UI16 key_length, PLAT_UI8 *pPlaintext, + PLAT_UI8 *pInitial_value, const PLAT_UI32 key_idx, PLAT_UI8 *pPlaintext, PLAT_UI16 *pPlaintext_length); /*! * \brief Perform an AES ECB encryption * \param[in] pPlaintext Pointer to the plaintext data * \param[in] plaintext_length Length of the plaintext data - * \param[in] pKey Pointer to the key - * \param[in] key_length Length of the key + * \param[in] key_idx Index of the key to use for AES encryption in secure storage * \param[out] pEncryptedtext Pointer to the encrypted payload * \param[out] pEncryptedtext_length Length of encrypted payload * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stse_platform_aes_ecb_enc(const PLAT_UI8 *pPlaintext, PLAT_UI16 plaintext_length, - const PLAT_UI8 *pKey, PLAT_UI16 key_length, - PLAT_UI8 *pEncryptedtext, PLAT_UI16 *pEncryptedtext_length); + const PLAT_UI32 key_idx, PLAT_UI8 *pEncryptedtext, PLAT_UI16 *pEncryptedtext_length); #endif /* defined(STSE_CONF_USE_HOST_KEY_ESTABLISHMENT) || defined(STSE_CONF_USE_SYMMETRIC_KEY_ESTABLISHMENT) || defined(STSE_CONF_USE_HOST_SESSION) */ @@ -404,9 +421,10 @@ stse_ReturnCode_t stse_platform_power_off(PLAT_UI8 busID, PLAT_UI8 devAddr); /*! * \brief Initialize I2C communication * \param[in] busID I2C bus ID + * \param[in] pArg Argument coming from \ref stse_init through its `pArg` parameter * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_platform_i2c_init(PLAT_UI8 busID); +stse_ReturnCode_t stse_platform_i2c_init(PLAT_UI8 busID, void *pArg); /*! * \brief Send data over I2C @@ -551,9 +569,10 @@ stse_ReturnCode_t stse_platform_i2c_receive_stop( /*! * \brief Initialize 1-wire communication * \param[in] busID 1-wire bus ID + * \param[in] pArg Argument coming from \ref stse_init through its `pArg` parameter * \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stse_platform_st1wire_init(PLAT_UI8 busID); +stse_ReturnCode_t stse_platform_st1wire_init(PLAT_UI8 busID, void *pArg); /*! * \brief Wake up 1-wire device diff --git a/core/stse_session.c b/core/stse_session.c index e89a0873..bdf89720 100644 --- a/core/stse_session.c +++ b/core/stse_session.c @@ -34,7 +34,7 @@ void stse_session_erase_context(stse_session_t *pSession) { memset(pSession, 0x00, sizeof(stse_session_t)); } -stse_ReturnCode_t stse_set_active_session(stse_Handler_t *pSTSE, stse_session_t *pSession) { +stse_ReturnCode_t stse_set_active_session(stse_Handle_t *pSTSE, stse_session_t *pSession) { if (pSTSE == NULL) { return STSE_CORE_HANDLER_NOT_INITIALISED; } diff --git a/doc/resources/Markdown/04_PORTING_GUIDE/03_PORTINNG_GUIDE.md b/doc/resources/Markdown/04_PORTING_GUIDE/03_PORTING_GUIDE.md similarity index 99% rename from doc/resources/Markdown/04_PORTING_GUIDE/03_PORTINNG_GUIDE.md rename to doc/resources/Markdown/04_PORTING_GUIDE/03_PORTING_GUIDE.md index b1396e0a..e013287c 100644 --- a/doc/resources/Markdown/04_PORTING_GUIDE/03_PORTINNG_GUIDE.md +++ b/doc/resources/Markdown/04_PORTING_GUIDE/03_PORTING_GUIDE.md @@ -41,6 +41,7 @@ Following platform files architecture are recommended to simplify the porting of - @subpage stse_platform_power - @subpage stse_platform_i2c - @subpage stse_platform_st1wire +- @subpage stse_platform_log # Reference Implementations diff --git a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_crc.c.md b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_crc.c.md index c36930c5..d6b10d97 100644 --- a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_crc.c.md +++ b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_crc.c.md @@ -57,7 +57,7 @@ Please find below an extract * \brief Initializes the CRC16 calculation module. * \return STSE_OK on success. */ -stse_ReturnCode_t stse_platform_crc16_init(void) +stse_ReturnCode_t stse_platform_crc16_init(void *pArg) { crc16_Init(); diff --git a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platfrom_crypto_init.c.md b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_crypto_init.c.md similarity index 97% rename from doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platfrom_crypto_init.c.md rename to doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_crypto_init.c.md index b1d074f5..8952ca9f 100644 --- a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platfrom_crypto_init.c.md +++ b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_crypto_init.c.md @@ -36,7 +36,7 @@ Please find below an example of the `stse_platform_crypto_init` implementation f #include "stselib.h" #include "Middleware/STM32_Cryptographic/include/cmox_crypto.h" -stse_ReturnCode_t stse_platform_crypto_init(void) +stse_ReturnCode_t stse_platform_crypto_init(void *pArg) { stse_ReturnCode_t ret = STSE_OK; diff --git a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_log.c.md b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_log.c.md new file mode 100644 index 00000000..12c6eced --- /dev/null +++ b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_log.c.md @@ -0,0 +1,25 @@ +# stse_platform_log.c {#stse_platform_log} + +The `stse_platform_log.c` file provides string formatting and logging functions for the STSE library, abstracting the platform-specific details of standard output and debugging streams in order to don't be `stdio`-dependent and allow platform-specific implementations for logging and output. + +## stse_platform_printf: +- **Purpose**: Provides a platform abstraction for formatted output, replacing all direct calls to `printf()` in the library with this function to allow platform-specific implementations and avoid direct use of standard I/O in library code. +- **Parameters**: Accepts a format string and a variable number of arguments, similar to the standard `printf()` function. +- **Return Value**: return void + +## Implementation example: + +```c +#include "stselib.h" + +#include +#include + +void stse_platform_printf(const char *format, ...) { + va_list args; + + va_start(args, format); + vprintf(format, args); + va_end(args); +} +``` diff --git a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_power.c.md b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_power.c.md index 76281a1e..15086528 100644 --- a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_power.c.md +++ b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_power.c.md @@ -57,7 +57,7 @@ Please find below an example of the `stse_platform_power.c` implementation for t * \brief Initializes the power control lines. * \return STSE_OK on success. */ -stse_ReturnCode_t stse_platform_power_init (void) +stse_ReturnCode_t stse_platform_power_init(void *pArg) { /* -Initialize power line control (PC0 - open-drain) */ GPIOC->MODER &= ~(GPIO_MODER_MODE0_Msk); diff --git a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_random.c.md b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_random.c.md index b3079767..d81993d1 100644 --- a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_random.c.md +++ b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_random.c.md @@ -44,7 +44,7 @@ Please find below an example of the `stse_platform_random.c` implementation for * \brief Initializes the random number generator. * \return STSE_OK on success. */ -stse_ReturnCode_t stse_platform_generate_random_init(void) +stse_ReturnCode_t stse_platform_generate_random_init(void *pArg) { rng_start(); diff --git a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_wolfssl.c.md b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_wolfssl.c.md index c32103f9..daaff0a4 100644 --- a/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_wolfssl.c.md +++ b/doc/resources/Markdown/04_PORTING_GUIDE/PAL_files/stse_platform_wolfssl.c.md @@ -127,7 +127,7 @@ Public keys are expected in raw X||Y coordinate format (uncompressed, without th int main(void) { - stse_Handler_t stse_handler; + stse_Handle_t stse_handler; stse_ReturnCode_t ret; /* Initialize STSE (calls stse_platform_crypto_init internally) */ diff --git a/doc/resources/dox_files/APIs/device_management/stse_device_power_on.dox b/doc/resources/dox_files/APIs/device_management/stse_device_power_on.dox index 88c5759c..217f3d9d 100644 --- a/doc/resources/dox_files/APIs/device_management/stse_device_power_on.dox +++ b/doc/resources/dox_files/APIs/device_management/stse_device_power_on.dox @@ -35,7 +35,7 @@ int main (void) stse_handler.io.Busaddr = 1; stsafe_handler.io.PowerLineOn = power_on; stsafe_handler.io.PowerLineOff = power_off; - stse_ret = stse_init(&stse_handler); + stse_ret = stse_init(&stse_handler, NULL); if (stse_ret != STSE_OK) { /* Handle Error */ diff --git a/doc/resources/dox_files/APIs/device_management/stse_init.dox b/doc/resources/dox_files/APIs/device_management/stse_init.dox index e0d03052..accc48c3 100644 --- a/doc/resources/dox_files/APIs/device_management/stse_init.dox +++ b/doc/resources/dox_files/APIs/device_management/stse_init.dox @@ -42,7 +42,7 @@ Following diagram illustrates the interactions performed between the Host and th \code{.c} stse_ReturnCode_t stse_ret = STSE_API_INVALID_PARAMETER; - stse_Handler_t stse_handler; + stse_Handle_t stse_handler; /* - Initialize STSE device handler */ stse_ret = stse_set_default_handler_value(&stse_handler); @@ -52,7 +52,7 @@ Following diagram illustrates the interactions performed between the Host and th } stse_handler.device_type = STSAFE_A120; stse_handler.io.Busaddr = 1; - stse_ret = stse_init(&stse_handler); + stse_ret = stse_init(&stse_handler, NULL); if (stse_ret != STSE_OK) { /* Handle Error */ diff --git a/services/stsafea/stsafea_aes.c b/services/stsafea/stsafea_aes.c index 6cb88a44..9592a542 100644 --- a/services/stsafea/stsafea_aes.c +++ b/services/stsafea/stsafea_aes.c @@ -25,7 +25,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafea_aes_ecb_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 message_length, PLAT_UI8 *pPlaintext_message, @@ -73,7 +73,7 @@ stse_ReturnCode_t stsafea_aes_ecb_encrypt( } stse_ReturnCode_t stsafea_aes_ecb_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 message_length, PLAT_UI8 *pEncrypted_message, @@ -118,7 +118,7 @@ stse_ReturnCode_t stsafea_aes_ecb_decrypt( } stse_ReturnCode_t stsafea_aes_ccm_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI8 *pNonce, @@ -202,7 +202,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt( } stse_ReturnCode_t stsafea_aes_ccm_encrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 Nonce_length, PLAT_UI8 *pNonce, @@ -279,7 +279,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt_start( } stse_ReturnCode_t stsafea_aes_ccm_encrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -294,7 +294,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt_process( } stse_ReturnCode_t stsafea_aes_ccm_encrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -313,7 +313,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt_finish( } stse_ReturnCode_t stsafea_aes_ccm_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI8 *pNonce, @@ -366,7 +366,7 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt( } stse_ReturnCode_t stsafea_aes_ccm_decrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 Nonce_length, PLAT_UI8 *pNonce, @@ -420,7 +420,7 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt_start( } stse_ReturnCode_t stsafea_aes_ccm_decrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -435,7 +435,7 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt_process( } stse_ReturnCode_t stsafea_aes_ccm_decrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -456,7 +456,7 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt_finish( } stse_ReturnCode_t stsafea_aes_gcm_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI16 IV_length, @@ -510,7 +510,7 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt( } stse_ReturnCode_t stsafea_aes_gcm_encrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -558,7 +558,7 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt_start( } stse_ReturnCode_t stsafea_aes_gcm_encrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -598,7 +598,7 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt_process( } stse_ReturnCode_t stsafea_aes_gcm_encrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -641,7 +641,7 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt_finish( } stse_ReturnCode_t stsafea_aes_gcm_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI16 IV_length, @@ -698,7 +698,7 @@ stse_ReturnCode_t stsafea_aes_gcm_decrypt( } stse_ReturnCode_t stsafea_aes_gcm_decrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -745,7 +745,7 @@ stse_ReturnCode_t stsafea_aes_gcm_decrypt_start( } stse_ReturnCode_t stsafea_aes_gcm_decrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -785,7 +785,7 @@ stse_ReturnCode_t stsafea_aes_gcm_decrypt_process( } stse_ReturnCode_t stsafea_aes_gcm_decrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, diff --git a/services/stsafea/stsafea_aes.h b/services/stsafea/stsafea_aes.h index 1ca94fe3..060cfd67 100644 --- a/services/stsafea/stsafea_aes.h +++ b/services/stsafea/stsafea_aes.h @@ -52,7 +52,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ecb_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 message_length, PLAT_UI8 *pPlaintext_message, @@ -72,7 +72,7 @@ stse_ReturnCode_t stsafea_aes_ecb_encrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ecb_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 message_length, PLAT_UI8 *pEncrypted_message, @@ -99,7 +99,7 @@ stse_ReturnCode_t stsafea_aes_ecb_decrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ccm_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI8 *pNonce, @@ -133,7 +133,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ccm_encrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 Nonce_length, PLAT_UI8 *pNonce, @@ -161,7 +161,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt_start( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ccm_encrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -184,7 +184,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt_process( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ccm_encrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -213,7 +213,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt_finish( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ccm_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI8 *pNonce, @@ -244,7 +244,7 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ccm_decrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 Nonce_length, PLAT_UI8 *pNonce, @@ -270,7 +270,7 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt_start( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ccm_decrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -294,7 +294,7 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt_process( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_ccm_decrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -323,7 +323,7 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt_finish( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gcm_encrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI16 IV_length, @@ -352,7 +352,7 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gcm_encrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -376,7 +376,7 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt_start( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gcm_encrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -399,7 +399,7 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt_process( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gcm_encrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, @@ -428,7 +428,7 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt_finish( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gcm_decrypt( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 authentication_tag_length, PLAT_UI16 IV_length, @@ -458,7 +458,7 @@ stse_ReturnCode_t stsafea_aes_gcm_decrypt( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gcm_decrypt_start( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -482,7 +482,7 @@ stse_ReturnCode_t stsafea_aes_gcm_decrypt_start( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gcm_decrypt_process( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, PLAT_UI16 message_chunk_length, @@ -506,7 +506,7 @@ stse_ReturnCode_t stsafea_aes_gcm_decrypt_process( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gcm_decrypt_finish( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 authentication_tag_length, PLAT_UI16 associated_data_chunk_length, PLAT_UI8 *pAssociated_data_chunk, diff --git a/services/stsafea/stsafea_asymmetric_key_slots.c b/services/stsafea/stsafea_asymmetric_key_slots.c index b4540e1c..739525e1 100644 --- a/services/stsafea/stsafea_asymmetric_key_slots.c +++ b/services/stsafea/stsafea_asymmetric_key_slots.c @@ -25,7 +25,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafea_query_private_key_slots_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pPrivate_key_slot_count) { /* - Check stsafe handler initialization */ if (pSTSE == NULL) { @@ -56,7 +56,7 @@ stse_ReturnCode_t stsafea_query_private_key_slots_count( } stse_ReturnCode_t stsafea_query_private_key_table( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_count, PLAT_UI16 *pGlobal_usage_limit, stsafea_private_key_slot_information_t *private_key_table_info) { @@ -130,7 +130,7 @@ stse_ReturnCode_t stsafea_query_private_key_table( } stse_ReturnCode_t stsafea_generate_ecc_key_pair( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI16 usage_limit, @@ -216,7 +216,7 @@ stse_ReturnCode_t stsafea_generate_ecc_key_pair( } stse_ReturnCode_t stsafea_generate_ECDHE_key_pair( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key) { if (pSTSE == NULL) { diff --git a/services/stsafea/stsafea_asymmetric_key_slots.h b/services/stsafea/stsafea_asymmetric_key_slots.h index 118c9723..1cd37c40 100644 --- a/services/stsafea/stsafea_asymmetric_key_slots.h +++ b/services/stsafea/stsafea_asymmetric_key_slots.h @@ -79,7 +79,7 @@ typedef struct stsafea_private_key_slot_information_t { * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_query_private_key_slots_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pPrivate_key_slot_count); /** @@ -92,7 +92,7 @@ stse_ReturnCode_t stsafea_query_private_key_slots_count( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_query_private_key_table( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_count, PLAT_UI16 *pGlobal_usage_limit, stsafea_private_key_slot_information_t *private_key_table_info); @@ -108,7 +108,7 @@ stse_ReturnCode_t stsafea_query_private_key_table( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_generate_ecc_key_pair( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI16 usage_limit, @@ -123,7 +123,7 @@ stse_ReturnCode_t stsafea_generate_ecc_key_pair( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_generate_ECDHE_key_pair( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key); diff --git a/services/stsafea/stsafea_commands.c b/services/stsafea/stsafea_commands.c index 3dc81028..e3b8cb67 100644 --- a/services/stsafea/stsafea_commands.c +++ b/services/stsafea/stsafea_commands.c @@ -26,7 +26,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT -stse_ReturnCode_t stsafea_get_command_count(stse_Handler_t *pSTSE, PLAT_UI8 *pCommand_count) { +stse_ReturnCode_t stsafea_get_command_count(stse_Handle_t *pSTSE, PLAT_UI8 *pCommand_count) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; PLAT_UI8 tag = STSAFEA_SUBJECT_TAG_COMMAND_AUTHORIZATION_CONFIG; PLAT_UI8 rsp_header; @@ -54,7 +54,7 @@ stse_ReturnCode_t stsafea_get_command_count(stse_Handler_t *pSTSE, PLAT_UI8 *pCo stsafea_cmd_timings[pSTSE->device_type][cmd_header]); } -stse_ReturnCode_t stsafea_get_command_AC_table(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_get_command_AC_table(stse_Handle_t *pSTSE, PLAT_UI8 total_command_count, stse_cmd_authorization_CR_t *pChange_rights, stse_cmd_authorization_record_t *pRecord_table) { @@ -106,7 +106,7 @@ stse_ReturnCode_t stsafea_get_command_AC_table(stse_Handler_t *pSTSE, return ret; } -stse_ReturnCode_t stsafea_perso_info_update(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stsafea_perso_info_update(stse_Handle_t *pSTSE) { stse_ReturnCode_t ret; PLAT_UI8 total_command_count = 0; stse_cmd_authorization_CR_t change_rights; diff --git a/services/stsafea/stsafea_commands.h b/services/stsafea/stsafea_commands.h index a88022d3..351817cd 100644 --- a/services/stsafea/stsafea_commands.h +++ b/services/stsafea/stsafea_commands.h @@ -131,7 +131,7 @@ typedef enum stsafea_extended_cmd_code_t { STSAFEA_EXTENDED_CMD_INVALID } stsafea_extended_cmd_code_t; -stse_ReturnCode_t stsafea_get_command_count(stse_Handler_t *pSTSE, PLAT_UI8 *pCommand_count); +stse_ReturnCode_t stsafea_get_command_count(stse_Handle_t *pSTSE, PLAT_UI8 *pCommand_count); /** * \brief Get command access control table @@ -142,12 +142,12 @@ stse_ReturnCode_t stsafea_get_command_count(stse_Handler_t *pSTSE, PLAT_UI8 *pCo * \param[out] pRecord_table Pointer to record table array * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_get_command_AC_table(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_get_command_AC_table(stse_Handle_t *pSTSE, PLAT_UI8 total_command_count, stse_cmd_authorization_CR_t *pChange_rights, stse_cmd_authorization_record_t *pRecord_table); -stse_ReturnCode_t stsafea_perso_info_update(stse_Handler_t *pSTSE); +stse_ReturnCode_t stsafea_perso_info_update(stse_Handle_t *pSTSE); /** * \brief Get command access conditions from personalization info diff --git a/services/stsafea/stsafea_data_partition.c b/services/stsafea/stsafea_data_partition.c index c3ef91b7..02fd4404 100644 --- a/services/stsafea/stsafea_data_partition.c +++ b/services/stsafea/stsafea_data_partition.c @@ -30,7 +30,7 @@ #define STSAFEA_INC_DEC_AMOUT_SIZE 4U #define STSAFEA_ZONE_ACCESS_LENGTH_SIZE 2U -stse_ReturnCode_t stsafea_switch_data_partition_access_protection(stse_Handler_t *pSTSE, PLAT_UI8 command_code, stse_cmd_protection_t protection) { +stse_ReturnCode_t stsafea_switch_data_partition_access_protection(stse_Handle_t *pSTSE, PLAT_UI8 command_code, stse_cmd_protection_t protection) { switch (protection) { case STSE_HOST_C_MAC_R_MAC: @@ -48,7 +48,7 @@ stse_ReturnCode_t stsafea_switch_data_partition_access_protection(stse_Handler_t return STSE_OK; } -stse_ReturnCode_t stsafea_get_total_partition_count(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_get_total_partition_count(stse_Handle_t *pSTSE, PLAT_UI8 *pTotal_partition_count) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; PLAT_UI8 tag = STSAFEA_SUBJECT_TAG_DATA_PARTITION_CONFIGURATION; @@ -75,7 +75,7 @@ stse_ReturnCode_t stsafea_get_total_partition_count(stse_Handler_t *pSTSE, stsafea_cmd_timings[pSTSE->device_type][cmd_header]); } -stse_ReturnCode_t stsafea_get_data_partitions_configuration(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_get_data_partitions_configuration(stse_Handle_t *pSTSE, PLAT_UI8 total_partitions_count, stsafea_data_partition_record_t *pRecord_table, PLAT_UI16 record_table_size) { @@ -133,7 +133,7 @@ stse_ReturnCode_t stsafea_get_data_partitions_configuration(stse_Handler_t *pSTS return (ret); } -stse_ReturnCode_t stsafea_decrement_counter_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_decrement_counter_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafea_decrement_option_t option, PLAT_UI32 amount, @@ -204,7 +204,7 @@ stse_ReturnCode_t stsafea_decrement_counter_zone(stse_Handler_t *pSTSE, return ret; } -stse_ReturnCode_t stsafea_read_counter_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_read_counter_zone(stse_Handle_t *pSTSE, PLAT_UI32 zone_index, stsafea_read_option_t option, PLAT_UI16 offset, @@ -274,7 +274,7 @@ stse_ReturnCode_t stsafea_read_counter_zone(stse_Handler_t *pSTSE, return (ret); } -stse_ReturnCode_t stsafea_read_data_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_read_data_zone(stse_Handle_t *pSTSE, PLAT_UI32 zone_index, stsafea_read_option_t option, PLAT_UI16 offset, @@ -341,11 +341,11 @@ stse_ReturnCode_t stsafea_read_data_zone(stse_Handler_t *pSTSE, return ret; } -stse_ReturnCode_t stsafea_update_data_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_update_data_zone(stse_Handle_t *pSTSE, PLAT_UI32 zone_index, stsafea_update_option_t option, PLAT_UI16 offset, - PLAT_UI8 *pData, + const PLAT_UI8 *pData, PLAT_UI32 data_length, stse_cmd_protection_t protection) { @@ -376,7 +376,7 @@ stse_ReturnCode_t stsafea_update_data_zone(stse_Handler_t *pSTSE, stse_frame_element_allocate_push(&CmdFrame, eOption, STSAFEA_ZONE_ACCESS_OPTION_SIZE, (PLAT_UI8 *)&option); stse_frame_element_allocate_push(&CmdFrame, eZoneIndex, STSAFEA_ZONE_INDEX_SIZE, (PLAT_UI8 *)&zone_index); stse_frame_element_allocate_push(&CmdFrame, eOffset, STSAFEA_ZONE_OFFSET_SIZE, (PLAT_UI8 *)&offset); - stse_frame_element_allocate_push(&CmdFrame, eData, data_length, pData); + stse_frame_element_allocate_push(&CmdFrame, eData, data_length, (PLAT_UI8 *)pData); if (data_length >= stsafea_maximum_frame_length[pSTSE->device_type]) { return STSE_SERVICE_FRAME_SIZE_ERROR; diff --git a/services/stsafea/stsafea_data_partition.h b/services/stsafea/stsafea_data_partition.h index 9def4068..caab021e 100644 --- a/services/stsafea/stsafea_data_partition.h +++ b/services/stsafea/stsafea_data_partition.h @@ -104,7 +104,7 @@ typedef struct { * \param[out] total_partition_count total partition count in bytes * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_get_total_partition_count(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_get_total_partition_count(stse_Handle_t *pSTSE, PLAT_UI8 *total_partition_count); /** @@ -116,7 +116,7 @@ stse_ReturnCode_t stsafea_get_total_partition_count(stse_Handler_t *pSTSE, * \param[in] record_table_size Applicative record table (@p pRecord_table) size (in bytes) * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_get_data_partitions_configuration(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_get_data_partitions_configuration(stse_Handle_t *pSTSE, PLAT_UI8 total_partitions_count, stsafea_data_partition_record_t *pRecord_table, PLAT_UI16 record_table_size); @@ -139,7 +139,7 @@ stse_ReturnCode_t stsafea_get_data_partitions_configuration(stse_Handler_t *pSTS * \param[in] protection Command protection type * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_decrement_counter_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_decrement_counter_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafea_decrement_option_t option, PLAT_UI32 amount, @@ -162,7 +162,7 @@ stse_ReturnCode_t stsafea_decrement_counter_zone(stse_Handler_t *pSTSE, * \param[in] protection Command protection type * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_read_counter_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_read_counter_zone(stse_Handle_t *pSTSE, PLAT_UI32 zone_index, stsafea_read_option_t read_ac, PLAT_UI16 read_offset, @@ -183,7 +183,7 @@ stse_ReturnCode_t stsafea_read_counter_zone(stse_Handler_t *pSTSE, * \param[in] protection Command protection type * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_read_data_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_read_data_zone(stse_Handle_t *pSTSE, PLAT_UI32 zone_index, stsafea_read_option_t read_ac, PLAT_UI16 read_offset, @@ -207,11 +207,11 @@ stse_ReturnCode_t stsafea_read_data_zone(stse_Handler_t *pSTSE, * \param[in] protection Command protection type * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_update_data_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_update_data_zone(stse_Handle_t *pSTSE, PLAT_UI32 zone_index, stsafea_update_option_t option, PLAT_UI16 offset, - PLAT_UI8 *data, + const PLAT_UI8 *data, PLAT_UI32 data_length, stse_cmd_protection_t protection); diff --git a/services/stsafea/stsafea_derive_keys.c b/services/stsafea/stsafea_derive_keys.c index ae96e4ba..e7c408e2 100644 --- a/services/stsafea/stsafea_derive_keys.c +++ b/services/stsafea/stsafea_derive_keys.c @@ -24,7 +24,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafea_derive_keys( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_hkdf_input_key_t *pInput_key, PLAT_UI8 extract_flag, PLAT_UI8 expand_flag, diff --git a/services/stsafea/stsafea_derive_keys.h b/services/stsafea/stsafea_derive_keys.h index 72b8ff61..b8ef35a8 100644 --- a/services/stsafea/stsafea_derive_keys.h +++ b/services/stsafea/stsafea_derive_keys.h @@ -199,7 +199,7 @@ typedef struct stsafea_hkdf_output_t { * @see stse_hkdf_derive_session_keys */ stse_ReturnCode_t stsafea_derive_keys( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_hkdf_input_key_t *pInput_key, PLAT_UI8 extract_flag, PLAT_UI8 expand_flag, diff --git a/services/stsafea/stsafea_ecc.c b/services/stsafea/stsafea_ecc.c index b9e5fd13..9ae5f413 100644 --- a/services/stsafea/stsafea_ecc.c +++ b/services/stsafea/stsafea_ecc.c @@ -25,7 +25,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafea_start_volatile_KEK_session( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *host_ecdhe_public_key) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_START_VOLATILE_KEK_SESSION}; @@ -93,7 +93,7 @@ stse_ReturnCode_t stsafea_start_volatile_KEK_session( } stse_ReturnCode_t stsafea_start_volatile_KEK_session_authenticated( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t ecdhe_key_type, PLAT_UI8 *host_ecdhe_public_key, stse_hash_algorithm_t hash_algo, @@ -207,7 +207,7 @@ stse_ReturnCode_t stsafea_start_volatile_KEK_session_authenticated( } stse_ReturnCode_t stsafea_stop_volatile_KEK_session( - stse_Handler_t *pSTSE) { + stse_Handle_t *pSTSE) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_STOP_VOLATILE_KEK_SESSION}; /* - Check stsafe handler initialization */ @@ -230,7 +230,7 @@ stse_ReturnCode_t stsafea_stop_volatile_KEK_session( } stse_ReturnCode_t stsafea_ecc_verify_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, const PLAT_UI8 *pPublic_key, const PLAT_UI8 *pSignature, @@ -343,7 +343,7 @@ stse_ReturnCode_t stsafea_ecc_verify_signature( } stse_ReturnCode_t stsafea_ecc_generate_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, const PLAT_UI8 *pMessage, @@ -388,7 +388,7 @@ stse_ReturnCode_t stsafea_ecc_generate_signature( } stse_ReturnCode_t stsafea_ecc_establish_shared_secret( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key, @@ -468,7 +468,7 @@ stse_ReturnCode_t stsafea_ecc_establish_shared_secret( } stse_ReturnCode_t stsafea_ecc_decompress_public_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 point_representation_id, PLAT_UI8 *pPublic_key_X, diff --git a/services/stsafea/stsafea_ecc.h b/services/stsafea/stsafea_ecc.h index 26471961..005e45a3 100644 --- a/services/stsafea/stsafea_ecc.h +++ b/services/stsafea/stsafea_ecc.h @@ -50,7 +50,7 @@ typedef enum { * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_start_volatile_KEK_session( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *host_ecdhe_public_key); @@ -67,7 +67,7 @@ stse_ReturnCode_t stsafea_start_volatile_KEK_session( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_start_volatile_KEK_session_authenticated( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t ecdhe_key_type, PLAT_UI8 *host_ecdhe_public_key, stse_hash_algorithm_t hash_algo, @@ -82,7 +82,7 @@ stse_ReturnCode_t stsafea_start_volatile_KEK_session_authenticated( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_stop_volatile_KEK_session( - stse_Handler_t *pSTSE); + stse_Handle_t *pSTSE); /** * \brief Verify the signature in arguments @@ -99,7 +99,7 @@ stse_ReturnCode_t stsafea_stop_volatile_KEK_session( * \details \include{doc} stse_ecc_verify_signature.dox */ stse_ReturnCode_t stsafea_ecc_verify_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, const PLAT_UI8 *pPublic_key, const PLAT_UI8 *pSignature, @@ -121,7 +121,7 @@ stse_ReturnCode_t stsafea_ecc_verify_signature( * \details \include{doc} stse_ecc_verify_signature.dox */ stse_ReturnCode_t stsafea_ecc_generate_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, const PLAT_UI8 *pMessage, @@ -139,7 +139,7 @@ stse_ReturnCode_t stsafea_ecc_generate_signature( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_ecc_establish_shared_secret( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 private_key_slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key, @@ -156,7 +156,7 @@ stse_ReturnCode_t stsafea_ecc_establish_shared_secret( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_ecc_decompress_public_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 point_representation_id, PLAT_UI8 *pPublic_key_X, diff --git a/services/stsafea/stsafea_echo.c b/services/stsafea/stsafea_echo.c index 856dcd94..3cd49daa 100644 --- a/services/stsafea/stsafea_echo.c +++ b/services/stsafea/stsafea_echo.c @@ -24,7 +24,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT -stse_ReturnCode_t stsafea_echo(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_echo(stse_Handle_t *pSTSE, PLAT_UI8 *pMessage, PLAT_UI8 *pEchoed_message, PLAT_UI16 message_length) { diff --git a/services/stsafea/stsafea_echo.h b/services/stsafea/stsafea_echo.h index a68efc88..0ea397d0 100644 --- a/services/stsafea/stsafea_echo.h +++ b/services/stsafea/stsafea_echo.h @@ -46,7 +46,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_echo( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *message, PLAT_UI8 *echoed_message, PLAT_UI16 message_size); diff --git a/services/stsafea/stsafea_entity_auth.c b/services/stsafea/stsafea_entity_auth.c index c6df1cbf..8f02ea0e 100644 --- a/services/stsafea/stsafea_entity_auth.c +++ b/services/stsafea/stsafea_entity_auth.c @@ -25,7 +25,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafea_generate_challenge( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 challenge_size, PLAT_UI8 *pChallenge) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_GENERATE_CHALLENGE}; @@ -55,7 +55,7 @@ stse_ReturnCode_t stsafea_generate_challenge( } stse_ReturnCode_t stsafea_verify_entity_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pSignature, diff --git a/services/stsafea/stsafea_entity_auth.h b/services/stsafea/stsafea_entity_auth.h index 21dfea66..954c7a35 100644 --- a/services/stsafea/stsafea_entity_auth.h +++ b/services/stsafea/stsafea_entity_auth.h @@ -41,7 +41,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_generate_challenge( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 challenge_size, PLAT_UI8 *pChallenge); @@ -56,7 +56,7 @@ stse_ReturnCode_t stsafea_generate_challenge( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_verify_entity_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pSignature, diff --git a/services/stsafea/stsafea_frame_transfer.c b/services/stsafea/stsafea_frame_transfer.c index 38754cfd..5ce29225 100644 --- a/services/stsafea/stsafea_frame_transfer.c +++ b/services/stsafea/stsafea_frame_transfer.c @@ -18,7 +18,6 @@ /* Includes ------------------------------------------------------------------*/ #include -#include #include "services/stsafea/stsafea_commands.h" #include "services/stsafea/stsafea_frame_transfer.h" @@ -32,7 +31,7 @@ const PLAT_UI16 stsafea_maximum_frame_length[STSAFEA_PRODUCT_COUNT] = { STSAFEA_MAX_FRAME_LENGTH_A110, STSAFEA_MAX_FRAME_LENGTH_A120}; -stse_ReturnCode_t stsafea_frame_transmit(stse_Handler_t *pSTSE, stse_frame_t *pFrame) { +stse_ReturnCode_t stsafea_frame_transmit(stse_Handle_t *pSTSE, stse_frame_t *pFrame) { stse_ReturnCode_t ret = STSE_PLATFORM_BUS_ACK_ERROR; PLAT_UI16 retry_count = STSE_MAX_POLLING_RETRY; stse_frame_element_t *pCurrent_element; @@ -72,9 +71,9 @@ stse_ReturnCode_t stsafea_frame_transmit(stse_Handler_t *pSTSE, stse_frame_t *pF stse_frame_push_element(pFrame, &crc_element); #ifdef STSE_FRAME_DEBUG_LOG - printf("\n\r STSAFE Frame > "); + stse_platform_printf("\n\r STSAFE Frame > "); stse_frame_debug_print(pFrame); - printf("\n\r"); + stse_platform_printf("\n\r"); #endif /* STSE_FRAME_DEBUG_LOG */ ret = STSE_PLATFORM_BUS_ACK_ERROR; @@ -120,7 +119,7 @@ stse_ReturnCode_t stsafea_frame_transmit(stse_Handler_t *pSTSE, stse_frame_t *pF return ret; } -stse_ReturnCode_t stsafea_frame_receive(stse_Handler_t *pSTSE, stse_frame_t *pFrame) { +stse_ReturnCode_t stsafea_frame_receive(stse_Handle_t *pSTSE, stse_frame_t *pFrame) { stse_ReturnCode_t ret = STSE_PLATFORM_BUS_ACK_ERROR; stse_frame_element_t *pCurrent_element; PLAT_UI8 received_header; @@ -223,11 +222,11 @@ stse_ReturnCode_t stsafea_frame_receive(stse_Handler_t *pSTSE, stse_frame_t *pFr computed_crc = stse_platform_Crc16_Calculate(&received_header, STSE_RSP_FRAME_HEADER_SIZE); #ifdef STSE_FRAME_DEBUG_LOG - printf("\n\r STSAFE Frame < (%d-byte) : { 0x%02X } { 0x%02X 0x%02X }\n\r", - received_length + STSE_FRAME_CRC_SIZE, - received_header, - received_crc[0], - received_crc[1]); + stse_platform_printf("\n\r STSAFE Frame < (%d-byte) : { 0x%02X } { 0x%02X 0x%02X }\n\r", + received_length + STSE_FRAME_CRC_SIZE, + received_header, + received_crc[0], + received_crc[1]); #endif /* STSE_FRAME_DEBUG_LOG */ /* - Verify CRC */ @@ -367,9 +366,9 @@ stse_ReturnCode_t stsafea_frame_receive(stse_Handler_t *pSTSE, stse_frame_t *pFr } #ifdef STSE_FRAME_DEBUG_LOG - printf("\n\r STSAFE Frame < "); + stse_platform_printf("\n\r STSAFE Frame < "); stse_frame_debug_print(pFrame); - printf("\n\r"); + stse_platform_printf("\n\r"); #endif /* STSE_FRAME_DEBUG_LOG */ /* - Swap CRC */ @@ -401,7 +400,7 @@ stse_ReturnCode_t stsafea_frame_receive(stse_Handler_t *pSTSE, stse_frame_t *pFr return ret; } -stse_ReturnCode_t stsafea_frame_raw_transfer(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_frame_raw_transfer(stse_Handle_t *pSTSE, stse_frame_t *pCmdFrame, stse_frame_t *pRspFrame, PLAT_UI16 inter_frame_delay) { @@ -428,7 +427,7 @@ stse_ReturnCode_t stsafea_frame_raw_transfer(stse_Handler_t *pSTSE, return ret; } -stse_ReturnCode_t stsafea_frame_transfer(stse_Handler_t *pSTSE, stse_frame_t *pCmdFrame, +stse_ReturnCode_t stsafea_frame_transfer(stse_Handle_t *pSTSE, stse_frame_t *pCmdFrame, stse_frame_t *pRspFrame) { stse_ReturnCode_t ret = STSE_SERVICE_INVALID_PARAMETER; PLAT_UI16 inter_frame_delay = STSAFEA_EXEC_TIME_DEFAULT; diff --git a/services/stsafea/stsafea_frame_transfer.h b/services/stsafea/stsafea_frame_transfer.h index bbf3d886..a00661d5 100644 --- a/services/stsafea/stsafea_frame_transfer.h +++ b/services/stsafea/stsafea_frame_transfer.h @@ -40,7 +40,7 @@ extern const PLAT_UI16 stsafea_maximum_frame_length[STSAFEA_PRODUCT_COUNT]; * \param[in,out] pFrame Pointer to the frame to be transmitted * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_frame_transmit(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_frame_transmit(stse_Handle_t *pSTSE, stse_frame_t *pFrame); /** @@ -50,7 +50,7 @@ stse_ReturnCode_t stsafea_frame_transmit(stse_Handler_t *pSTSE, * \param[in,out] pFrame Pointer to the frame to be received * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_frame_receive(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_frame_receive(stse_Handle_t *pSTSE, stse_frame_t *pFrame); /** @@ -62,7 +62,7 @@ stse_ReturnCode_t stsafea_frame_receive(stse_Handler_t *pSTSE, * \param[in] inter_frame_delay Delay between command and response frame (in ms) * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_frame_raw_transfer(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_frame_raw_transfer(stse_Handle_t *pSTSE, stse_frame_t *pCmdFrame, stse_frame_t *pRspFrame, PLAT_UI16 inter_frame_delay); @@ -75,7 +75,7 @@ stse_ReturnCode_t stsafea_frame_raw_transfer(stse_Handler_t *pSTSE, * \param[in,out] pRspFrame Pointer to the response frame * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_frame_transfer(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_frame_transfer(stse_Handle_t *pSTSE, stse_frame_t *pCmdFrame, stse_frame_t *pRspFrame); diff --git a/services/stsafea/stsafea_hash.c b/services/stsafea/stsafea_hash.c index b61c4b6b..50353768 100644 --- a/services/stsafea/stsafea_hash.c +++ b/services/stsafea/stsafea_hash.c @@ -85,7 +85,7 @@ const stsafea_hash_info_t stsafea_hash_info_table[] = defined(STSE_CONF_HASH_SHA_3_256) || defined(STSE_CONF_HASH_SHA_3_384) || defined(STSE_CONF_HASH_SHA_3_512) stse_ReturnCode_t stsafea_start_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size) { @@ -117,7 +117,7 @@ stse_ReturnCode_t stsafea_start_hash( } stse_ReturnCode_t stsafea_process_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pMessage, PLAT_UI16 message_size) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_PROCESS_HASH}; @@ -147,7 +147,7 @@ stse_ReturnCode_t stsafea_process_hash( } stse_ReturnCode_t stsafea_finish_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size, diff --git a/services/stsafea/stsafea_hash.h b/services/stsafea/stsafea_hash.h index bff5f09e..8f5679d2 100644 --- a/services/stsafea/stsafea_hash.h +++ b/services/stsafea/stsafea_hash.h @@ -116,7 +116,7 @@ extern const stsafea_hash_info_t stsafea_hash_info_table[]; * - STSAFE-A120 : STSAFEA_MAX_FRAME_LENGTH_A120 - 15 * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_start_hash(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_start_hash(stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size); @@ -132,7 +132,7 @@ stse_ReturnCode_t stsafea_start_hash(stse_Handler_t *pSTSE, * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_process_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pMessage, PLAT_UI16 message_size); @@ -150,7 +150,7 @@ stse_ReturnCode_t stsafea_process_hash( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_finish_hash( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_hash_algorithm_t sha_algorithm, PLAT_UI8 *pMessage, PLAT_UI16 message_size, diff --git a/services/stsafea/stsafea_host_key_slot.c b/services/stsafea/stsafea_host_key_slot.c index 3ca0f766..15fe4d6f 100644 --- a/services/stsafea/stsafea_host_key_slot.c +++ b/services/stsafea/stsafea_host_key_slot.c @@ -27,7 +27,7 @@ /* Exported functions --------------------------------------------------------*/ stse_ReturnCode_t stsafea_query_host_key_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_host_key_provisioning_ctrl_fields_t *pCtrl_fields) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; @@ -59,7 +59,7 @@ stse_ReturnCode_t stsafea_query_host_key_provisioning_ctrl_fields( } stse_ReturnCode_t stsafea_put_host_key_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_host_key_provisioning_ctrl_fields_t *pCtrl_fields) { PLAT_UI8 cmd_header = STSAFEA_CMD_PUT_ATTRIBUTE; @@ -91,7 +91,7 @@ stse_ReturnCode_t stsafea_put_host_key_provisioning_ctrl_fields( } stse_ReturnCode_t stsafea_query_host_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_host_key_slot_t *pHost_key_slot) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; @@ -123,7 +123,7 @@ stse_ReturnCode_t stsafea_query_host_key( } stse_ReturnCode_t stsafea_query_host_key_v2( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_host_key_slot_v2_t *pHost_key_slot_v2) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; @@ -155,9 +155,10 @@ stse_ReturnCode_t stsafea_query_host_key_v2( stsafea_cmd_timings[pSTSE->device_type][cmd_header]); } -stse_ReturnCode_t stsafea_put_attribute_host_key( - stse_Handler_t *pSTSE, - stsafea_aes_128_host_keys_t *host_keys) { +stse_ReturnCode_t stsafea_put_attribute_host_secure_channel_keys( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key) { PLAT_UI8 cmd_header = STSAFEA_CMD_PUT_ATTRIBUTE; /* - Check stsafe handler initialization */ @@ -165,7 +166,9 @@ stse_ReturnCode_t stsafea_put_attribute_host_key( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if (host_keys == NULL) { + if (host_mac_key == NULL || host_cipher_key == NULL || host_mac_key->type != host_cipher_key->type || + host_mac_key->type != STSE_AES_128_KT || host_cipher_key->type != STSE_AES_128_KT || + host_mac_key->usage != STSE_AES_KEY_USAGE_MAC || host_cipher_key->usage != STSE_AES_KEY_USAGE_CIPHER) { return (STSE_SERVICE_INVALID_PARAMETER); } @@ -175,7 +178,8 @@ stse_ReturnCode_t stsafea_put_attribute_host_key( stse_frame_allocate(CmdFrame); stse_frame_element_allocate_push(&CmdFrame, eCmd_header, STSAFEA_HEADER_SIZE, &cmd_header); stse_frame_element_allocate_push(&CmdFrame, eSubject_tag, 1, &subject_tag); - stse_frame_element_allocate_push(&CmdFrame, eHost_keys, sizeof(stsafea_aes_128_host_keys_t), (PLAT_UI8 *)host_keys); + stse_frame_element_allocate_push(&CmdFrame, e_host_mac_key, STSE_AES_128_KEY_SIZE, host_mac_key->key); + stse_frame_element_allocate_push(&CmdFrame, e_host_cipher_key, STSE_AES_128_KEY_SIZE, host_cipher_key->key); stse_frame_allocate(RspFrame); stse_frame_element_allocate_push(&RspFrame, eRsp_header, STSAFEA_HEADER_SIZE, &rsp_header); @@ -187,10 +191,10 @@ stse_ReturnCode_t stsafea_put_attribute_host_key( stsafea_cmd_timings[pSTSE->device_type][cmd_header]); } -stse_ReturnCode_t stsafea_host_key_provisioning( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t key_type, - stsafea_host_keys_t *host_keys) { +stse_ReturnCode_t stsafea_host_secure_channel_keys_provisioning( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_WRITE_HOST_KEY_V2_PLAINTEXT}; /* - Check stsafe handler initialization */ @@ -198,11 +202,13 @@ stse_ReturnCode_t stsafea_host_key_provisioning( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if (key_type == STSAFEA_AES_INVALID_HOST_KEY || host_keys == NULL) { + if (host_mac_key == NULL || host_cipher_key == NULL || host_mac_key->type != host_cipher_key->type || + host_mac_key->type >= STSE_AES_INVALID_KT || host_cipher_key->type >= STSE_AES_INVALID_KT || + host_mac_key->usage != STSE_AES_KEY_USAGE_MAC || host_cipher_key->usage != STSE_AES_KEY_USAGE_CIPHER) { return (STSE_SERVICE_INVALID_PARAMETER); } - PLAT_UI8 host_keys_length = (key_type == STSAFEA_AES_128_HOST_KEY ? STSAFEA_HOST_AES_128_KEYS_SIZE : STSAFEA_HOST_AES_256_KEYS_SIZE); + PLAT_UI8 host_keys_length = (host_mac_key->type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE; PLAT_UI8 pPadding[3] = {0}; PLAT_UI8 rsp_header; @@ -210,8 +216,9 @@ stse_ReturnCode_t stsafea_host_key_provisioning( stse_frame_allocate(CmdFrame); stse_frame_element_allocate_push(&CmdFrame, eCmd_header, STSAFEA_EXT_HEADER_SIZE, cmd_header); stse_frame_element_allocate_push(&CmdFrame, ePadding, 3, pPadding); - stse_frame_element_allocate_push(&CmdFrame, eKey_type, 1, (PLAT_UI8 *)&key_type); - stse_frame_element_allocate_push(&CmdFrame, eHost_keys, host_keys_length, (PLAT_UI8 *)host_keys); + stse_frame_element_allocate_push(&CmdFrame, eKey_type, 1, (PLAT_UI8 *)host_mac_key->type); + stse_frame_element_allocate_push(&CmdFrame, e_host_mac_key, host_keys_length, host_mac_key->key); + stse_frame_element_allocate_push(&CmdFrame, e_host_cipher_key, host_keys_length, host_cipher_key->key); stse_frame_allocate(RspFrame); stse_frame_element_allocate_push(&RspFrame, eRsp_header, STSAFEA_HEADER_SIZE, &rsp_header); @@ -222,9 +229,9 @@ stse_ReturnCode_t stsafea_host_key_provisioning( &RspFrame); } -stse_ReturnCode_t stsafea_host_key_provisioning_wrapped( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t key_type, +stse_ReturnCode_t stsafea_host_secure_channel_keys_provisioning_wrapped( + stse_Handle_t *pSTSE, + stse_aes_key_type_t key_type, PLAT_UI8 *pHost_key_envelope) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_WRITE_HOST_KEY_V2_WRAPPED}; @@ -233,11 +240,11 @@ stse_ReturnCode_t stsafea_host_key_provisioning_wrapped( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if (key_type == STSAFEA_AES_INVALID_HOST_KEY || pHost_key_envelope == NULL) { + if (key_type > STSE_AES_INVALID_KT || pHost_key_envelope == NULL) { return (STSE_SERVICE_INVALID_PARAMETER); } - PLAT_UI8 host_keys_envelope_length = key_type == STSAFEA_AES_128_HOST_KEY ? STSAFEA_HOST_AES_128_KEYS_ENVELOPE_SIZE : STSAFEA_HOST_AES_256_KEYS_ENVELOPE_SIZE; + PLAT_UI8 host_keys_envelope_length = (key_type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE; PLAT_UI8 rsp_header; @@ -254,11 +261,11 @@ stse_ReturnCode_t stsafea_host_key_provisioning_wrapped( &RspFrame); } -stse_ReturnCode_t stsafea_establish_host_key( - stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_establish_host_secure_channel_keys( + stse_Handle_t *pSTSE, stse_ecc_key_type_t host_ecdh_public_key_type, PLAT_UI8 *pPublic_key, - stsafea_host_key_type_t host_keys_type) { + stse_aes_key_type_t host_keys_type) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_ESTABLISH_HOST_KEY_V2}; /* - Check stsafe handler initialization */ @@ -266,7 +273,7 @@ stse_ReturnCode_t stsafea_establish_host_key( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((host_ecdh_public_key_type >= STSE_ECC_KT_INVALID) || (pPublic_key == NULL) || (host_keys_type >= STSAFEA_AES_INVALID_HOST_KEY)) { + if ((host_ecdh_public_key_type >= STSE_ECC_KT_INVALID) || (pPublic_key == NULL) || (host_keys_type >= STSE_AES_INVALID_KT)) { return (STSE_SERVICE_INVALID_PARAMETER); } @@ -322,11 +329,11 @@ stse_ReturnCode_t stsafea_establish_host_key( &RspFrame); } -stse_ReturnCode_t stsafea_establish_host_key_authenticated( - stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_establish_host_secure_channel_keys_authenticated( + stse_Handle_t *pSTSE, stse_ecc_key_type_t host_ecdh_public_key_type, PLAT_UI8 *pPublic_key, - stsafea_host_key_type_t host_keys_type, + stse_aes_key_type_t host_keys_type, PLAT_UI8 signature_public_key_slot, stse_ecc_key_type_t signature_public_key_type, stse_hash_algorithm_t signature_hash_algo, @@ -339,7 +346,7 @@ stse_ReturnCode_t stsafea_establish_host_key_authenticated( } if ((host_ecdh_public_key_type >= STSE_ECC_KT_INVALID) || (pPublic_key == NULL) || - (host_keys_type >= STSAFEA_AES_INVALID_HOST_KEY) || (signature_public_key_type >= STSE_ECC_KT_INVALID) || + (host_keys_type >= STSE_AES_INVALID_KT) || (signature_public_key_type >= STSE_ECC_KT_INVALID) || (signature_hash_algo >= STSE_SHA_INVALID) || (pSignature == NULL)) { return (STSE_SERVICE_INVALID_PARAMETER); } diff --git a/services/stsafea/stsafea_host_key_slot.h b/services/stsafea/stsafea_host_key_slot.h index 6a05a2a1..a6c6ac61 100644 --- a/services/stsafea/stsafea_host_key_slot.h +++ b/services/stsafea/stsafea_host_key_slot.h @@ -33,21 +33,11 @@ */ #define STSAFEA_HOST_AES_BLOCK_SIZE 16U -#define STSAFEA_HOST_AES_128_MAC_KEY_SIZE 16U -#define STSAFEA_HOST_AES_128_CIPHER_KEY_SIZE 16U -#define STSAFEA_HOST_AES_128_KEYS_ENVELOPE_SIZE 48U -#define STSAFEA_HOST_AES_128_KEYS_SIZE \ - STSAFEA_HOST_AES_128_MAC_KEY_SIZE \ - +STSAFEA_HOST_AES_128_CIPHER_KEY_SIZE -#define STSAFEA_HOST_AES_256_MAC_KEY_SIZE 32U -#define STSAFEA_HOST_AES_256_CIPHER_KEY_SIZE 32U +#define STSAFEA_HOST_AES_128_KEYS_ENVELOPE_SIZE 48U #define STSAFEA_HOST_AES_256_KEYS_ENVELOPE_SIZE 80U -#define STSAFEA_HOST_AES_256_KEYS_SIZE \ - STSAFEA_HOST_AES_256_MAC_KEY_SIZE \ - +STSAFEA_HOST_AES_256_CIPHER_KEY_SIZE -#define STSAFEA_KEK_KEY_SIZE STSAFEA_AES_256_KEY_SIZE +#define STSAFEA_KEK_KEY_SIZE STSE_AES_256_KEY_SIZE #define STSAFEA_KEK_HKDF_SALT_SIZE STSAFEA_SHA_256_HASH_SIZE #define STSAFEA_KEK_HKDF_SALT \ {0xE4, 0x5D, 0x4C, 0xFD, 0x20, 0x15, 0xDE, 0x9E, \ @@ -55,40 +45,20 @@ 0x0F, 0x99, 0xD9, 0x63, 0x3F, 0xB1, 0xB2, 0xDD, \ 0xDB, 0xEE, 0xE6, 0x75, 0xD5, 0x4D, 0xE2, 0x5B} #define STSAFEA_WORKING_KEK_HKDF_INFO_SIZE 3U -typedef enum { - STSAFEA_AES_128_HOST_KEY = 0, - STSAFEA_AES_256_HOST_KEY, - STSAFEA_AES_INVALID_HOST_KEY -} stsafea_host_key_type_t; -typedef struct { +typedef struct +{ PLAT_UI8 key_presence_flag; PLAT_UI8 cmac_sequence_counter[3]; } stsafea_host_key_slot_t; -typedef struct { +typedef struct +{ PLAT_UI8 key_presence_flag; PLAT_UI8 key_type; PLAT_UI8 cmac_sequence_counter[4]; } stsafea_host_key_slot_v2_t; -typedef struct -{ - PLAT_UI8 host_mac_key[STSAFEA_HOST_AES_128_MAC_KEY_SIZE]; - PLAT_UI8 host_cipher_key[STSAFEA_HOST_AES_128_CIPHER_KEY_SIZE]; -} stsafea_aes_128_host_keys_t; - -typedef struct -{ - PLAT_UI8 host_mac_key[STSAFEA_HOST_AES_256_MAC_KEY_SIZE]; - PLAT_UI8 host_cipher_key[STSAFEA_HOST_AES_256_CIPHER_KEY_SIZE]; -} stsafea_aes_256_host_keys_t; - -typedef union { - stsafea_aes_128_host_keys_t aes_128_key; - stsafea_aes_256_host_keys_t aes_256_key; -} stsafea_host_keys_t; - typedef struct { PLAT_UI8 wrapped_anonymous : STSE_1BIT_LEN; @@ -107,7 +77,7 @@ typedef struct * \return \ref stse_ReturnCode_t : STSAFEA_OK on success ; error code otherwise */ stse_ReturnCode_t stsafea_query_host_key_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_host_key_provisioning_ctrl_fields_t *pCtrl_fields); /** @@ -118,86 +88,87 @@ stse_ReturnCode_t stsafea_query_host_key_provisioning_ctrl_fields( * \return \ref stse_ReturnCode_t : STSAFEA_OK on success ; error code otherwise */ stse_ReturnCode_t stsafea_put_host_key_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_host_key_provisioning_ctrl_fields_t *pCtrl_fields); /** * \brief Query host key informations (host key V1) * \details This service format and send query host key informations command - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[out] pHostKeySlot Pointer to the structure to output key informations * \return \ref stse_ReturnCode_t : STSAFEA_OK on success ; error code otherwise */ stse_ReturnCode_t stsafea_query_host_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_host_key_slot_t *pHostKeySlot); /** * \brief Query host key informations (host key V2) * \details This service format and send query host key informations command - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[out] pHostKeySlotV2 Pointer to the structure to output key informations * \return \ref stse_ReturnCode_t : STSAFEA_OK on success ; error code otherwise */ stse_ReturnCode_t stsafea_query_host_key_v2( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_host_key_slot_v2_t *pHostKeySlotV2); /** - * \brief Provision host key V1 - * \details Provision host key using the put attributes command - * \param[in] pSTSE Pointer to STSE Handler - * \param[in] host_keys Host key structure to be provisioned + * \brief Provision host secure channel keys V1 + * \details Provision host secure channel keys using the put attributes command + * \param[in] pSTSE Pointer to STSE Handler + * \param[in] host_mac_key Pointer to 128 bits host MAC key (AES key structure) to be provisioned + * \param[in] host_cipher_key Pointer to 128 bits Host cipher key (AES key structure) to be provisioned * \return \ref stse_ReturnCode_t : STSAFEA_OK on success ; error code otherwise */ -stse_ReturnCode_t stsafea_put_attribute_host_key( - stse_Handler_t *pSTSE, - stsafea_aes_128_host_keys_t *host_keys); - +stse_ReturnCode_t stsafea_put_attribute_host_secure_channel_keys( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key); /** - * \brief Provision host key V2 - * \details Provision host key using the write host key command - * \param[in] pSTSE Pointer to STSE Handler - * \param[in] key_type Host key type - * \param[in] host_keys Host key structure to be provisioned + * \brief Provision host secure channel keys V2 + * \details Provision host secure channel keys using the write host key command + * \param[in] pSTSE Pointer to STSE Handler + * \param[in] host_mac_key Pointer to host MAC key (AES key structure) to be provisioned + * \param[in] host_cipher_key Pointer to Host cipher key (AES key structure) to be provisioned * \return \ref stse_ReturnCode_t : STSAFEA_OK on success ; error code otherwise */ -stse_ReturnCode_t stsafea_host_key_provisioning( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t key_type, - stsafea_host_keys_t *host_keys); +stse_ReturnCode_t stsafea_host_secure_channel_keys_provisioning( + stse_Handle_t *pSTSE, + stse_aes_key_t *host_mac_key, + stse_aes_key_t *host_cipher_key); /** - * \brief Provision host key V2 wrapped - * \details Provision host key using the write host key command - * \param[in] pSTSE Pointer to STSE Handler + * \brief Provision host secure channel keys V2 wrapped + * \details Provision host secure channel keys using the write host key command + * \param[in] pSTSE Pointer to STSE Handler * \param[in] key_type Host key type * \param[in] pHost_key_envelope Envelope containing host key to be provisioned * \return \ref stse_ReturnCode_t : STSAFEA_OK on success ; error code otherwise */ -stse_ReturnCode_t stsafea_host_key_provisioning_wrapped( - stse_Handler_t *pSTSE, - stsafea_host_key_type_t key_type, +stse_ReturnCode_t stsafea_host_secure_channel_keys_provisioning_wrapped( + stse_Handle_t *pSTSE, + stse_aes_key_type_t key_type, PLAT_UI8 *pHost_key_envelope); /** - * \brief Establish host key using ECDH & HKDF processes - * \details Provision host key using the establish host key command + * \brief Establish host secure channel keys using ECDH & HKDF processes + * \details Provision host secure channel keys using the establish host key command * \param[in] pSTSE Pointer to STSE Handler * \param[in] host_ecdh_public_key_type ECDHE host public key type * \param[in] pPublic_key ECDHE host public key * \param[in] host_keys_type Host key type * \return \ref stse_ReturnCode_t : STSAFEA_OK on success ; error code otherwise */ -stse_ReturnCode_t stsafea_establish_host_key( - stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_establish_host_secure_channel_keys( + stse_Handle_t *pSTSE, stse_ecc_key_type_t host_ecdh_public_key_type, PLAT_UI8 *pPublic_key, - stsafea_host_key_type_t host_keys_type); + stse_aes_key_type_t host_keys_type); /** - * \brief Authenticated establish host key using ECDH & HKDF processes - * \details Provision host key using the authenticated establish host key command + * \brief Authenticated establish host secure channel keys using ECDH & HKDF processes + * \details Provision host secure channel keys using the authenticated establish host secure channel keys command * \param[in] pSTSE Pointer to STSE Handler * \param[in] host_ecdh_public_key_type ECDHE host public key type * \param[in] pPublic_key ECDHE host public key @@ -208,11 +179,11 @@ stse_ReturnCode_t stsafea_establish_host_key( * \param[in] pSignature Pointer to buffer containing signature * \return \ref stse_ReturnCode_t : STSAFEA_OK on success ; error code otherwise */ -stse_ReturnCode_t stsafea_establish_host_key_authenticated( - stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_establish_host_secure_channel_keys_authenticated( + stse_Handle_t *pSTSE, stse_ecc_key_type_t host_ecdh_public_key_type, PLAT_UI8 *pPublic_key, - stsafea_host_key_type_t host_keys_type, + stse_aes_key_type_t host_keys_type, PLAT_UI8 signature_public_key_slot, stse_ecc_key_type_t signature_public_key_type, stse_hash_algorithm_t signature_hash_algo, diff --git a/services/stsafea/stsafea_low_power.c b/services/stsafea/stsafea_low_power.c index 36486829..7487ebd8 100644 --- a/services/stsafea/stsafea_low_power.c +++ b/services/stsafea/stsafea_low_power.c @@ -24,7 +24,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT -stse_ReturnCode_t stsafea_hibernate(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_hibernate(stse_Handle_t *pSTSE, stse_hibernate_wake_up_mode_t wake_up_mode) { diff --git a/services/stsafea/stsafea_low_power.h b/services/stsafea/stsafea_low_power.h index 302405c8..96411801 100644 --- a/services/stsafea/stsafea_low_power.h +++ b/services/stsafea/stsafea_low_power.h @@ -40,7 +40,7 @@ * listed in enum \ref stse_hibernate_wake_up_mode_t * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_hibernate(stse_Handler_t *pSTSAFE, +stse_ReturnCode_t stsafea_hibernate(stse_Handle_t *pSTSAFE, stse_hibernate_wake_up_mode_t wake_up_mode); /** \}*/ diff --git a/services/stsafea/stsafea_mac.c b/services/stsafea/stsafea_mac.c index b80d3417..3aa203a9 100644 --- a/services/stsafea/stsafea_mac.c +++ b/services/stsafea/stsafea_mac.c @@ -24,7 +24,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafea_cmac_hmac_compute( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pMessage, PLAT_UI8 message_length, @@ -64,7 +64,7 @@ stse_ReturnCode_t stsafea_cmac_hmac_compute( } stse_ReturnCode_t stsafea_cmac_hmac_verify( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pMac, PLAT_UI8 mac_length, @@ -106,7 +106,7 @@ stse_ReturnCode_t stsafea_cmac_hmac_verify( } stse_ReturnCode_t stsafea_aes_gmac_compute( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -133,7 +133,7 @@ stse_ReturnCode_t stsafea_aes_gmac_compute( } stse_ReturnCode_t stsafea_aes_gmac_verify( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, diff --git a/services/stsafea/stsafea_mac.h b/services/stsafea/stsafea_mac.h index 9cd653e2..a6688fce 100644 --- a/services/stsafea/stsafea_mac.h +++ b/services/stsafea/stsafea_mac.h @@ -51,7 +51,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_cmac_hmac_compute( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pMessage, PLAT_UI8 message_length, @@ -74,7 +74,7 @@ stse_ReturnCode_t stsafea_cmac_hmac_compute( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_cmac_hmac_verify( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pMac, PLAT_UI8 mac_length, @@ -98,7 +98,7 @@ stse_ReturnCode_t stsafea_cmac_hmac_verify( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gmac_compute( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, @@ -124,7 +124,7 @@ stse_ReturnCode_t stsafea_aes_gmac_compute( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_aes_gmac_verify( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI16 IV_length, PLAT_UI8 *pIV, diff --git a/services/stsafea/stsafea_password.c b/services/stsafea/stsafea_password.c index 67db1621..a31994b4 100644 --- a/services/stsafea/stsafea_password.c +++ b/services/stsafea/stsafea_password.c @@ -25,7 +25,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafea_verify_password( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pPassword_buffer, PLAT_UI8 password_length, PLAT_UI8 *pVerification_status, @@ -58,7 +58,7 @@ stse_ReturnCode_t stsafea_verify_password( &RspFrame); } -stse_ReturnCode_t stsafea_delete_password(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stsafea_delete_password(stse_Handle_t *pSTSE) { PLAT_UI8 cmd_header = STSAFEA_CMD_DELETE; PLAT_UI8 tag = STSAFEA_DELETE_TAG_PASSWORD; PLAT_UI8 rsp_header; diff --git a/services/stsafea/stsafea_password.h b/services/stsafea/stsafea_password.h index a4be3dc2..91b8ce1f 100644 --- a/services/stsafea/stsafea_password.h +++ b/services/stsafea/stsafea_password.h @@ -45,7 +45,7 @@ * \param[out] pRemaining_tries Pointer to remaining tries * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_verify_password(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_verify_password(stse_Handle_t *pSTSE, PLAT_UI8 *pPassword_buffer, PLAT_UI8 password_length, PLAT_UI8 *pVerification_status, @@ -57,7 +57,7 @@ stse_ReturnCode_t stsafea_verify_password(stse_Handler_t *pSTSE, * \param[in] pSTSE Pointer to target SE handler * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_delete_password(stse_Handler_t *pSTSE); +stse_ReturnCode_t stsafea_delete_password(stse_Handle_t *pSTSE); /** \}*/ diff --git a/services/stsafea/stsafea_patch.c b/services/stsafea/stsafea_patch.c index bffdf454..f9f2966a 100644 --- a/services/stsafea/stsafea_patch.c +++ b/services/stsafea/stsafea_patch.c @@ -21,7 +21,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafe_get_patch_update_command_counter( - stse_Handler_t *pSTSAFE, + stse_Handle_t *pSTSAFE, PLAT_UI8 pPatch_update_command_counter) { (void)pSTSAFE; (void)pPatch_update_command_counter; @@ -29,19 +29,19 @@ stse_ReturnCode_t stsafe_get_patch_update_command_counter( } stse_ReturnCode_t stsafe_patch_start( - stse_Handler_t *pSTSAFE) { + stse_Handle_t *pSTSAFE) { (void)pSTSAFE; return STSE_SERVICE_INVALID_PARAMETER; /* TODO */ } stse_ReturnCode_t stsafe_patch_update( - stse_Handler_t *pSTSAFE) { + stse_Handle_t *pSTSAFE) { (void)pSTSAFE; return STSE_SERVICE_INVALID_PARAMETER; /* TODO */ } stse_ReturnCode_t stsafe_patch_finalize( - stse_Handler_t *pSTSAFE) { + stse_Handle_t *pSTSAFE) { (void)pSTSAFE; return STSE_SERVICE_INVALID_PARAMETER; /* TODO */ } diff --git a/services/stsafea/stsafea_patch.h b/services/stsafea/stsafea_patch.h index 303941e2..e1c8daca 100644 --- a/services/stsafea/stsafea_patch.h +++ b/services/stsafea/stsafea_patch.h @@ -40,7 +40,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_get_patch_update_command_counter( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 pCounter); /** @@ -50,7 +50,7 @@ stse_ReturnCode_t stsafea_get_patch_update_command_counter( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_patch_start( - stse_Handler_t *pSTSE); + stse_Handle_t *pSTSE); /** * \brief STSAFEA Update Patch service @@ -59,7 +59,7 @@ stse_ReturnCode_t stsafea_patch_start( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_patch_update( - stse_Handler_t *pSTSE); + stse_Handle_t *pSTSE); /** * \brief STSAFEA Finalize Patch service @@ -68,7 +68,7 @@ stse_ReturnCode_t stsafea_patch_update( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_patch_finalize( - stse_Handler_t *pSTSE); + stse_Handle_t *pSTSE); /** \}*/ diff --git a/services/stsafea/stsafea_public_key_slots.c b/services/stsafea/stsafea_public_key_slots.c index 14a12a0b..0d9a2364 100644 --- a/services/stsafea/stsafea_public_key_slots.c +++ b/services/stsafea/stsafea_public_key_slots.c @@ -25,7 +25,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafea_query_generic_public_key_slots_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pGeneric_public_key_slot_count) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; @@ -57,7 +57,7 @@ stse_ReturnCode_t stsafea_query_generic_public_key_slots_count( } stse_ReturnCode_t stsafea_query_generic_public_key_slot_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pPresence_flag, stsafea_generic_public_key_configuration_flags_t *pConfiguration_flags, @@ -130,7 +130,7 @@ stse_ReturnCode_t stsafea_query_generic_public_key_slot_info( } stse_ReturnCode_t stsafea_query_generic_public_key_slot_value( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key) { @@ -208,7 +208,7 @@ stse_ReturnCode_t stsafea_query_generic_public_key_slot_value( } stse_ReturnCode_t stsafea_write_generic_ecc_public_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key) { @@ -283,7 +283,7 @@ stse_ReturnCode_t stsafea_write_generic_ecc_public_key( } stse_ReturnCode_t stsafea_set_generic_public_slot_configuration_flag( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_generic_public_key_configuration_flags_t configuration_flags) { PLAT_UI8 cmd_header = STSAFEA_CMD_PUT_ATTRIBUTE; diff --git a/services/stsafea/stsafea_public_key_slots.h b/services/stsafea/stsafea_public_key_slots.h index 6b63bf85..aca0bfef 100644 --- a/services/stsafea/stsafea_public_key_slots.h +++ b/services/stsafea/stsafea_public_key_slots.h @@ -57,7 +57,7 @@ typedef struct stsafea_generic_public_key_configuration_flags_t { * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_query_generic_public_key_slots_count( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pGeneric_public_key_slot_count); /*! @@ -71,7 +71,7 @@ stse_ReturnCode_t stsafea_query_generic_public_key_slots_count( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_query_generic_public_key_slot_info( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, PLAT_UI8 *pPresence_flag, stsafea_generic_public_key_configuration_flags_t *pConfiguration_flags, @@ -87,7 +87,7 @@ stse_ReturnCode_t stsafea_query_generic_public_key_slot_info( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_query_generic_public_key_slot_value( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key); @@ -102,7 +102,7 @@ stse_ReturnCode_t stsafea_query_generic_public_key_slot_value( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_write_generic_ecc_public_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stse_ecc_key_type_t key_type, PLAT_UI8 *pPublic_key); @@ -116,7 +116,7 @@ stse_ReturnCode_t stsafea_write_generic_ecc_public_key( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_set_generic_public_slot_configuration_flag( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_generic_public_key_configuration_flags_t configuration_flags); diff --git a/services/stsafea/stsafea_put_query.c b/services/stsafea/stsafea_put_query.c index 664ba001..d636ab2a 100644 --- a/services/stsafea/stsafea_put_query.c +++ b/services/stsafea/stsafea_put_query.c @@ -24,8 +24,10 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT +#define STSAFEA_SUB_TAG_MASK_ID 0x01 + stse_ReturnCode_t stsafea_put_life_cyle_state( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_life_cycle_state_t life_cycle_state) { PLAT_UI8 cmd_header = STSAFEA_CMD_PUT_ATTRIBUTE; PLAT_UI8 tag = STSAFEA_SUBJECT_TAG_LIFE_CYCLE_STATE; @@ -53,7 +55,7 @@ stse_ReturnCode_t stsafea_put_life_cyle_state( } stse_ReturnCode_t stsafea_query_life_cycle_state( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_life_cycle_state_t *pLife_cycle_state) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; PLAT_UI8 tag = STSAFEA_SUBJECT_TAG_LIFE_CYCLE_STATE; @@ -81,7 +83,7 @@ stse_ReturnCode_t stsafea_query_life_cycle_state( } stse_ReturnCode_t stsafea_put_i2c_parameters( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_i2c_parameters_t *pI2c_parameters) { PLAT_UI8 cmd_header = STSAFEA_CMD_PUT_ATTRIBUTE; PLAT_UI8 tag = STSAFEA_SUBJECT_TAG_I2C_PARAMETERS; @@ -120,7 +122,7 @@ stse_ReturnCode_t stsafea_put_i2c_parameters( } stse_ReturnCode_t stsafea_query_i2c_parameters( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_i2c_parameters_t *pI2c_parameters) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; PLAT_UI8 tag = STSAFEA_SUBJECT_TAG_I2C_PARAMETERS; @@ -147,4 +149,43 @@ stse_ReturnCode_t stsafea_query_i2c_parameters( stsafea_cmd_timings[pSTSE->device_type][cmd_header]); } +stse_ReturnCode_t stsafea_query_mask_id( + stse_Handle_t *pSTSE, + PLAT_UI8 mask_id[STSAFEA_MASK_ID_SIZE]) { + PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; + PLAT_UI8 tag = STSAFEA_SUBJECT_TAG_PRODUCT_DATA; + PLAT_UI8 rsp_header; + PLAT_UI8 sub_tag; + PLAT_UI8 sub_tag_size; + stse_ReturnCode_t ret; + + if (pSTSE == NULL) { + return (STSE_SERVICE_HANDLER_NOT_INITIALISED); + } + + /*- Create CMD frame and populate elements */ + stse_frame_allocate(CmdFrame); + stse_frame_element_allocate_push(&CmdFrame, eCmd_header, 1, &cmd_header); + stse_frame_element_allocate_push(&CmdFrame, eTag, 1, &tag); + + /*- Create Rsp frame and populate elements*/ + stse_frame_allocate(RspFrame); + stse_frame_element_allocate_push(&RspFrame, eRsp_header, 1, &rsp_header); + stse_frame_element_allocate_push(&RspFrame, e_sub_tag, 1, &sub_tag); + stse_frame_element_allocate_push(&RspFrame, e_sub_tag_size, 1, &sub_tag_size); + stse_frame_element_allocate_push(&RspFrame, e_mask_id, STSAFEA_MASK_ID_SIZE, mask_id); + + /*- Perform Transfer*/ + ret = stsafea_frame_raw_transfer(pSTSE, + &CmdFrame, + &RspFrame, + stsafea_cmd_timings[pSTSE->device_type][cmd_header]); + + if (sub_tag != STSAFEA_SUB_TAG_MASK_ID) { + return (STSE_SERVICE_INCOMPATIBLE_DEVICE_TYPE); + } + + return ret; +} + #endif /* STSE_CONF_STSAFE_A_SUPPORT */ diff --git a/services/stsafea/stsafea_put_query.h b/services/stsafea/stsafea_put_query.h index a3e9a915..ec16ea32 100644 --- a/services/stsafea/stsafea_put_query.h +++ b/services/stsafea/stsafea_put_query.h @@ -74,6 +74,8 @@ #define STSAFEA_SUBJECT_TAG_GENERIC_PUBLIC_KEY_SLOT 0x4C /*!< Generic public key slot subject-tag */ #define STSAFEA_SUBJECT_TAG_GENERIC_PUBLIC_KEY_CONFIGURATION_FLAGS 0x4D /*!< Generic public key configuration flags subject-tag */ +#define STSAFEA_MASK_ID_SIZE 3 /*!< Mask identification size */ + /*! * \enum stsafea_life_cycle_state_t * STSAFEA Life cycle state type @@ -108,7 +110,7 @@ typedef struct * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_put_life_cyle_state( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_life_cycle_state_t life_cycle_state); /** @@ -119,7 +121,7 @@ stse_ReturnCode_t stsafea_put_life_cyle_state( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_query_life_cycle_state( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_life_cycle_state_t *pLife_cycle_state); /** @@ -130,20 +132,31 @@ stse_ReturnCode_t stsafea_query_life_cycle_state( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_put_i2c_parameters( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_i2c_parameters_t *pI2c_parameters); /** - * \brief STSAFEA put life cycle service - * \details This service format and send/receive the put life cycle command/response - * \param[in] pSTSE Pointer to STSE Handler - * \param[out] pLife_cycle_state Life cycle state + * \brief STSAFEA query I2C parameters service + * \details This service format and send/receive the query I2C parameters command/response + * \param[in] pSTSE Pointer to STSE Handler + * \param[out] pI2c_parameters I2C parameters * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_query_i2c_parameters( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafea_i2c_parameters_t *pI2c_parameters); +/** + * \brief STSAFEA query mask identification service + * \details This service format and send/receive the mask identification command/response + * \param[in] pSTSE Pointer to STSE Handler + * \param[out] mask_id Mask identification (3 bytes) + * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise + */ +stse_ReturnCode_t stsafea_query_mask_id( + stse_Handle_t *pSTSE, + PLAT_UI8 mask_id[STSAFEA_MASK_ID_SIZE]); + /** \}*/ #endif /* STSAFEA_PUT_QUERY_H */ diff --git a/services/stsafea/stsafea_random.c b/services/stsafea/stsafea_random.c index 89ad0f2d..9047ddf4 100644 --- a/services/stsafea/stsafea_random.c +++ b/services/stsafea/stsafea_random.c @@ -26,7 +26,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT stse_ReturnCode_t stsafea_generate_random( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pRandom, PLAT_UI8 random_size) { stse_ReturnCode_t ret; diff --git a/services/stsafea/stsafea_random.h b/services/stsafea/stsafea_random.h index ee3793d1..cbf52593 100644 --- a/services/stsafea/stsafea_random.h +++ b/services/stsafea/stsafea_random.h @@ -43,7 +43,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_generate_random( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pRandom, PLAT_UI8 random_size); diff --git a/services/stsafea/stsafea_reset.c b/services/stsafea/stsafea_reset.c index ded816c6..f57947cc 100644 --- a/services/stsafea/stsafea_reset.c +++ b/services/stsafea/stsafea_reset.c @@ -24,7 +24,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT -stse_ReturnCode_t stsafea_reset(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stsafea_reset(stse_Handle_t *pSTSE) { PLAT_UI8 cmd_header = STSAFEA_CMD_RESET; PLAT_UI8 rsp_header; diff --git a/services/stsafea/stsafea_reset.h b/services/stsafea/stsafea_reset.h index a2512706..d595aa40 100644 --- a/services/stsafea/stsafea_reset.h +++ b/services/stsafea/stsafea_reset.h @@ -38,7 +38,7 @@ * \param[in] pSTSAFE Pointer to STSE Handler * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_reset(stse_Handler_t *pSTSAFE); +stse_ReturnCode_t stsafea_reset(stse_Handle_t *pSTSAFE); /** \}*/ diff --git a/services/stsafea/stsafea_sessions.c b/services/stsafea/stsafea_sessions.c index dcb6d212..3349cff1 100644 --- a/services/stsafea/stsafea_sessions.c +++ b/services/stsafea/stsafea_sessions.c @@ -41,7 +41,7 @@ #ifdef STSE_CONF_USE_HOST_SESSION -stse_ReturnCode_t stsafea_open_host_session(stse_Handler_t *pSTSE, stse_session_t *pSession, PLAT_UI8 *pHost_MAC_key, PLAT_UI8 *pHost_cypher_key) { +stse_ReturnCode_t stsafea_open_host_session_from_idx(stse_Handle_t *pSTSE, stse_session_t *pSession, PLAT_UI32 host_MAC_key_idx, PLAT_UI32 host_cipher_key_idx) { stse_ReturnCode_t ret; if (pSTSE == NULL) { @@ -81,8 +81,8 @@ stse_ReturnCode_t stsafea_open_host_session(stse_Handler_t *pSTSE, stse_session_ } pSession->type = STSE_HOST_SESSION; - pSession->context.host.pHost_MAC_key = pHost_MAC_key; - pSession->context.host.pHost_cypher_key = pHost_cypher_key; + pSession->context.host.host_MAC_key_idx = host_MAC_key_idx; + pSession->context.host.host_cypher_key_idx = host_cipher_key_idx; pSession->context.host.pSTSE = pSTSE; pSTSE->pActive_host_session = pSession; @@ -116,7 +116,7 @@ void stsafea_session_clear_context(stse_session_t *pSession) { memset(pSession, 0x00, sizeof(stse_session_t)); } -stse_ReturnCode_t stsafea_set_active_host_session(stse_Handler_t *pSTSE, stse_session_t *pSession) { +stse_ReturnCode_t stsafea_set_active_host_session(stse_Handle_t *pSTSE, stse_session_t *pSession) { if (pSTSE == NULL) { return STSE_SERVICE_HANDLER_NOT_INITIALISED; } @@ -169,8 +169,7 @@ stse_ReturnCode_t stsafea_session_frame_encrypt(stse_session_t *pSession, /* - Perform first AES ECB round on IV */ ret = stse_platform_aes_ecb_enc(initial_value, STSAFEA_HOST_AES_BLOCK_SIZE, - pSession->context.host.pHost_cypher_key, - (pSession->context.host.key_type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + pSession->context.host.host_cypher_key_idx, initial_value, &encrypted_iv_len); if (ret != STSE_OK) { @@ -201,8 +200,7 @@ stse_ReturnCode_t stsafea_session_frame_encrypt(stse_session_t *pSession, pEnc_payload_element->pData, pEnc_payload_element->length, initial_value, - pSession->context.host.pHost_cypher_key, - (pSession->context.host.key_type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + pSession->context.host.host_cypher_key_idx, pEnc_payload_element->pData, &encrypted_payload_len); if (ret != 0) { @@ -261,8 +259,7 @@ static stse_ReturnCode_t stsafea_session_frame_decrypt(stse_session_t *pSession, /* - Transform IV using AES ECB */ ret = stse_platform_aes_ecb_enc(initial_value, STSAFEA_HOST_AES_BLOCK_SIZE, - pSession->context.host.pHost_cypher_key, - (pSession->context.host.key_type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + pSession->context.host.host_cypher_key_idx, initial_value, &out_len); @@ -276,8 +273,7 @@ static stse_ReturnCode_t stsafea_session_frame_decrypt(stse_session_t *pSession, ret = stse_platform_aes_cbc_dec(decrypt_buffer, encrypted_payload_len, initial_value, - pSession->context.host.pHost_cypher_key, - (pSession->context.host.key_type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + pSession->context.host.host_cypher_key_idx, decrypt_buffer, &decrypted_payload_len); @@ -333,8 +329,7 @@ static stse_ReturnCode_t stsafea_session_frame_c_mac_compute(stse_session_t *pSe /*- Initialize AES C-MAC computation */ - ret = stse_platform_aes_cmac_init(pSession->context.host.pHost_MAC_key, - (pSession->context.host.key_type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + ret = stse_platform_aes_cmac_init(pSession->context.host.host_MAC_key_idx, STSAFEA_MAC_SIZE); if (ret != STSE_OK) { return ret; @@ -425,8 +420,7 @@ static stse_ReturnCode_t stsafea_session_frame_r_mac_verify(stse_session_t *pSes /*- Initialize AES CMAC computation */ stse_platform_aes_cmac_init( - pSession->context.host.pHost_MAC_key, - (pSession->context.host.key_type == STSE_AES_128_KT) ? STSE_AES_128_KEY_SIZE : STSE_AES_256_KEY_SIZE, + pSession->context.host.host_MAC_key_idx, STSAFEA_MAC_SIZE); /*- Perform First AES-CMAC round */ diff --git a/services/stsafea/stsafea_sessions.h b/services/stsafea/stsafea_sessions.h index fd36b9e8..738361ca 100644 --- a/services/stsafea/stsafea_sessions.h +++ b/services/stsafea/stsafea_sessions.h @@ -26,17 +26,19 @@ #include "core/stse_return_codes.h" /*! - * \brief This Core function Create a session context and associate it to STSAFE handler - * \param[in] *pSession \ref stse_session_t Pointer to session - * \param[in] *pHost_MAC_key Pointer to MAC key buffer to be used under the session - * \param[in] *pHost_cypher_key Pointer to cypher key buffer to be used under the session + * \brief This Core function creates a session context and associates it to STSAFE handler using keys stored in platform secure storage + * \param[in] *pSTSE Pointer to STSE handler + * \param[in] *pSession \ref stse_session_t Pointer to session + * \param[in] host_MAC_key_idx Index of the MAC key in platform secure storage to be used under the session + * \param[in] host_cipher_key_idx Index of the cipher key in platform secure storage to be used under the session * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise - * \details \include{doc} stsafe_erase_context.dox + * \details \include{doc} stsafe_erase_context.dox + * \details \include{doc} stse_platform_store_aes_key.dox */ -stse_ReturnCode_t stsafea_open_host_session(stse_Handler_t *pSTSE, - stse_session_t *pSession, - PLAT_UI8 *pHost_MAC_key, - PLAT_UI8 *pHost_cypher_key); +stse_ReturnCode_t stsafea_open_host_session_from_idx(stse_Handle_t *pSTSE, + stse_session_t *pSession, + PLAT_UI32 host_MAC_key_idx, + PLAT_UI32 host_cipher_key_idx); /*! * \brief This Core function Close an existing host session context diff --git a/services/stsafea/stsafea_symmetric_key_slots.c b/services/stsafea/stsafea_symmetric_key_slots.c index 33f9d958..f2c098db 100644 --- a/services/stsafea/stsafea_symmetric_key_slots.c +++ b/services/stsafea/stsafea_symmetric_key_slots.c @@ -28,7 +28,7 @@ /* Exported functions --------------------------------------------------------*/ stse_ReturnCode_t stsafea_query_symmetric_key_slot_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_provisioning_ctrl_fields_t *pCtrl_fields) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; @@ -61,7 +61,7 @@ stse_ReturnCode_t stsafea_query_symmetric_key_slot_provisioning_ctrl_fields( } stse_ReturnCode_t stsafea_put_symmetric_key_slot_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_provisioning_ctrl_fields_t *pCtrl_fields) { PLAT_UI8 cmd_header = STSAFEA_CMD_PUT_ATTRIBUTE; @@ -93,7 +93,7 @@ stse_ReturnCode_t stsafea_put_symmetric_key_slot_provisioning_ctrl_fields( stsafea_cmd_timings[pSTSE->device_type][cmd_header]); } -stse_ReturnCode_t stsafea_query_symmetric_key_slots_count(stse_Handler_t *pSTSE, PLAT_UI8 *pSymmetric_key_slot_count) { +stse_ReturnCode_t stsafea_query_symmetric_key_slots_count(stse_Handle_t *pSTSE, PLAT_UI8 *pSymmetric_key_slot_count) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; /* - Check stsafe handler initialization */ @@ -124,7 +124,7 @@ stse_ReturnCode_t stsafea_query_symmetric_key_slots_count(stse_Handler_t *pSTSE, } stse_ReturnCode_t stsafea_query_symmetric_key_table( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 symmetric_key_slot_count, stsafea_symmetric_key_slot_information_t *symmetric_key_table_info) { stse_ReturnCode_t ret; @@ -214,7 +214,7 @@ stse_ReturnCode_t stsafea_query_symmetric_key_table( } stse_ReturnCode_t stsafea_establish_symmetric_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *host_ecdhe_public_key) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_ESTABLISH_SYMMETRIC_KEYS}; @@ -287,7 +287,7 @@ stse_ReturnCode_t stsafea_establish_symmetric_key( } stse_ReturnCode_t stsafea_establish_symmetric_key_authenticated( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *host_ecdhe_public_key, stse_hash_algorithm_t hash_algo, @@ -391,8 +391,8 @@ stse_ReturnCode_t stsafea_establish_symmetric_key_authenticated( defined(STSE_CONF_USE_SYMMETRIC_KEY_ESTABLISHMENT_AUTHENTICATED) stse_ReturnCode_t stsafea_confirm_symmetric_key( - stse_Handler_t *pSTSE, - PLAT_UI8 *pMac_confirmation_key, + stse_Handle_t *pSTSE, + PLAT_UI32 confirmation_key_index, PLAT_UI8 key_count, stsafea_generic_key_information_t *pKey_information_list) { stse_ReturnCode_t ret; @@ -403,7 +403,7 @@ stse_ReturnCode_t stsafea_confirm_symmetric_key( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((pMac_confirmation_key == NULL) || (pKey_information_list == NULL) || (key_count == 0)) { + if ((pKey_information_list == NULL) || (key_count == 0)) { return (STSE_SERVICE_INVALID_PARAMETER); } @@ -416,8 +416,7 @@ stse_ReturnCode_t stsafea_confirm_symmetric_key( stse_frame_element_allocate_push(&CmdFrame, eConfirmation_mac, STSE_KEY_CONFIRMATION_MAC_SIZE, pConfirmation_mac); ret = stse_platform_aes_cmac_init( - pMac_confirmation_key, - STSAFEA_AES_256_KEY_SIZE, + confirmation_key_index, STSE_KEY_CONFIRMATION_MAC_SIZE); if (ret != STSE_OK) { return (ret); @@ -472,7 +471,7 @@ stse_ReturnCode_t stsafea_confirm_symmetric_key( defined(STSE_CONF_USE_SYMMETRIC_KEY_PROVISIONING_WRAPPED_AUTHENTICATED) stse_ReturnCode_t stsafea_write_symmetric_key_wrapped( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pSymmetric_key_envelope, PLAT_UI8 symmetric_key_envelope_length) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_WRITE_SYMMETRIC_KEY_WRAPPED}; @@ -503,7 +502,7 @@ stse_ReturnCode_t stsafea_write_symmetric_key_wrapped( #endif stse_ReturnCode_t stsafea_write_symmetric_key_plaintext( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pSymmetric_key_value, stsafea_generic_key_information_t *pSymmetric_key_info) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_WRITE_SYMMETRIC_KEY_PLAINTEXT}; @@ -523,10 +522,10 @@ stse_ReturnCode_t stsafea_write_symmetric_key_plaintext( switch (pSymmetric_key_info->type) { case STSAFEA_SYMMETRIC_KEY_TYPE_AES_128: - key_value_length = STSAFEA_AES_128_KEY_SIZE; + key_value_length = STSE_AES_128_KEY_SIZE; break; case STSAFEA_SYMMETRIC_KEY_TYPE_AES_256: - key_value_length = STSAFEA_AES_256_KEY_SIZE; + key_value_length = STSE_AES_256_KEY_SIZE; break; case STSAFEA_SYMMETRIC_KEY_TYPE_GENERIC_SECRET: key_value_length = pSymmetric_key_info->HMAC.generic_secret_key_length; /* HMAC or HKDF */ @@ -548,7 +547,7 @@ stse_ReturnCode_t stsafea_write_symmetric_key_plaintext( &RspFrame); } -stse_ReturnCode_t stsafea_generate_wrap_unwrap_key(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_generate_wrap_unwrap_key(stse_Handle_t *pSTSE, PLAT_UI8 wrap_key_slot, stse_aes_key_type_t key_type) { PLAT_UI8 cmd_header = STSAFEA_CMD_GENERATE_KEY; @@ -579,7 +578,7 @@ stse_ReturnCode_t stsafea_generate_wrap_unwrap_key(stse_Handler_t *pSTSE, } stse_ReturnCode_t stsafea_erase_symmetric_key_slot( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 symmetric_key_slot_number) { PLAT_UI8 cmd_header[STSAFEA_EXT_HEADER_SIZE] = {STSAFEA_EXTENDED_COMMAND_PREFIX, STSAFEA_EXTENDED_CMD_ERASE_SYMMETRIC_KEY_SLOT}; diff --git a/services/stsafea/stsafea_symmetric_key_slots.h b/services/stsafea/stsafea_symmetric_key_slots.h index 61f3734c..47f17fe1 100644 --- a/services/stsafea/stsafea_symmetric_key_slots.h +++ b/services/stsafea/stsafea_symmetric_key_slots.h @@ -34,8 +34,6 @@ * @{ */ -#define STSAFEA_AES_128_KEY_SIZE 16U -#define STSAFEA_AES_256_KEY_SIZE 32U #define STSAFEA_CA_PUB_KEY_SIZE 32U /*! < Certificate Authority public key size*/ #define STSAFEA_SYMMETRIC_KEY_USAGE_ENCRYPTION_Msk (0b1 << 3) #define STSAFEA_SYMMETRIC_KEY_USAGE_DECRYPTION_Msk (0b1 << 2) @@ -218,13 +216,13 @@ typedef struct stsafe_generic_key_information_t { /** * \brief Query symmetric key slot provisioning control fields * \details This service format and send query symmetric key slot provisioning control fields - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] slot_number Slot number of the slot to query * \param[out] pCtrl_fields Output structure for the provisioning control fields of the target slot * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_query_symmetric_key_slot_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_provisioning_ctrl_fields_t *pCtrl_fields); @@ -237,49 +235,49 @@ stse_ReturnCode_t stsafea_query_symmetric_key_slot_provisioning_ctrl_fields( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_put_symmetric_key_slot_provisioning_ctrl_fields( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 slot_number, stsafea_symmetric_key_slot_provisioning_ctrl_fields_t *pCtrl_fields); /** * \brief Query symmetric key slot count * \details This service format and send query symmetric key slot count - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[out] pSymmetric_key_slot_count Slot count output * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_query_symmetric_key_slots_count(stse_Handler_t *pSTSE, PLAT_UI8 *pSymmetric_key_slot_count); +stse_ReturnCode_t stsafea_query_symmetric_key_slots_count(stse_Handle_t *pSTSE, PLAT_UI8 *pSymmetric_key_slot_count); /** * \brief Query symmetric key table informations * \details This service format and send query symmetric key table informations - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] symmetric_key_slot_count Expected table slot count * \param[out] symmetric_key_table_info Output key slot info list of length equal to symmetric_key_slot_count * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_query_symmetric_key_table( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 symmetric_key_slot_count, stsafea_symmetric_key_slot_information_t *symmetric_key_table_info); /** * \brief Establish symmetric key in stsafe symmetric key table * \details This service format and send establish symmetric key command - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] key_type Type of the key used in ECDHE * \param[in] host_ecdhe_public_key Key used in ECDHE * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_establish_symmetric_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *host_ecdhe_public_key); /** * \brief Authenticate establish symmetric key in stsafe symmetric key table * \details This service format and send establish symmetric key command with an authentication signature - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] key_type Type of the key used in ECDHE * \param[in] host_ecdhe_public_key Key used in ECDHE * \param[in] hash_algo Signature hash algorithm ID @@ -289,7 +287,7 @@ stse_ReturnCode_t stsafea_establish_symmetric_key( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_establish_symmetric_key_authenticated( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, PLAT_UI8 *host_ecdhe_public_key, stse_hash_algorithm_t hash_algo, @@ -300,28 +298,28 @@ stse_ReturnCode_t stsafea_establish_symmetric_key_authenticated( /** * \brief Confirm symmetric key establishment in stsafe symmetric key table * \details This service format and send confirm symmetric key command - * \param[in] pSTSE Pointer to STSE Handler - * \param[in] pMac_confirmation_key Key used to MAC the confirmation command payload + * \param[in] pSTSE Pointer to STSE Handler + * \param[in] confirmation_key_index Index of key used to MAC the confirmation command payload * \param[in] key_count Number of key to populate * \param[in] pKey_information_list Key information list used to populate the symmetric key table * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_confirm_symmetric_key( - stse_Handler_t *pSTSE, - PLAT_UI8 *pMac_confirmation_key, + stse_Handle_t *pSTSE, + PLAT_UI32 confirmation_key_index, PLAT_UI8 key_count, stsafea_generic_key_information_t *pKey_information_list); /** * \brief Write symmetric key envelope in stsafe symmetric key table * \details This service format and send write symmetric key command - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] pSymmetric_key_envelope Envelope containing key materials to write in STSAFE * \param[in] symmetric_key_envelope_length Envelope length in bytes * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_write_symmetric_key_wrapped( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pSymmetric_key_envelope, PLAT_UI8 symmetric_key_envelope_length); @@ -334,7 +332,7 @@ stse_ReturnCode_t stsafea_write_symmetric_key_wrapped( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_write_symmetric_key_plaintext( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pSymmetric_key_value, stsafea_generic_key_information_t *pSymmetric_key_info); @@ -347,7 +345,7 @@ stse_ReturnCode_t stsafea_write_symmetric_key_plaintext( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_generate_wrap_unwrap_key( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 wrap_key_slot, stse_aes_key_type_t key_type); @@ -359,7 +357,7 @@ stse_ReturnCode_t stsafea_generate_wrap_unwrap_key( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_erase_symmetric_key_slot( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 symmetric_key_slot_number); /** \}*/ diff --git a/services/stsafea/stsafea_wrap_unwrap.c b/services/stsafea/stsafea_wrap_unwrap.c index 5cf2dbd8..a6db311e 100644 --- a/services/stsafea/stsafea_wrap_unwrap.c +++ b/services/stsafea/stsafea_wrap_unwrap.c @@ -24,7 +24,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT -stse_ReturnCode_t stsafea_wrap_payload(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_wrap_payload(stse_Handle_t *pSTSE, PLAT_UI8 wrap_key_slot, PLAT_UI8 *pPayload, PLAT_UI16 payload_size, @@ -58,7 +58,7 @@ stse_ReturnCode_t stsafea_wrap_payload(stse_Handler_t *pSTSE, &RspFrame); } -stse_ReturnCode_t stsafea_unwrap_payload(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafea_unwrap_payload(stse_Handle_t *pSTSE, PLAT_UI8 wrap_key_slot, PLAT_UI8 *pWrapped_Payload, PLAT_UI16 wrapped_payload_size, diff --git a/services/stsafea/stsafea_wrap_unwrap.h b/services/stsafea/stsafea_wrap_unwrap.h index d7a22c63..c00793c5 100644 --- a/services/stsafea/stsafea_wrap_unwrap.h +++ b/services/stsafea/stsafea_wrap_unwrap.h @@ -45,7 +45,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_wrap_payload( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 wrap_key_slot, PLAT_UI8 *pPayload, PLAT_UI16 payload_size, @@ -64,7 +64,7 @@ stse_ReturnCode_t stsafea_wrap_payload( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafea_unwrap_payload( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 wrap_key_slot, PLAT_UI8 *pWrapped_Payload, PLAT_UI16 wrapped_payload_size, diff --git a/services/stsafel/stsafel_data_partition.c b/services/stsafel/stsafel_data_partition.c index 4386f3bd..86dceb3a 100644 --- a/services/stsafel/stsafel_data_partition.c +++ b/services/stsafel/stsafel_data_partition.c @@ -25,7 +25,7 @@ #ifdef STSE_CONF_STSAFE_L_SUPPORT -stse_ReturnCode_t stsafel_read_data_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_read_data_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafel_read_option_t option, PLAT_UI16 offset, @@ -65,11 +65,11 @@ stse_ReturnCode_t stsafel_read_data_zone(stse_Handler_t *pSTSE, &RspFrame); } -stse_ReturnCode_t stsafel_update_data_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_update_data_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafel_update_option_t option, PLAT_UI16 offset, - PLAT_UI8 *pData, + const PLAT_UI8 *pData, PLAT_UI16 data_length, stse_cmd_protection_t protection) { PLAT_UI8 cmd_header = STSAFEL_CMD_UPDATE; @@ -89,7 +89,7 @@ stse_ReturnCode_t stsafel_update_data_zone(stse_Handler_t *pSTSE, stse_frame_element_allocate_push(&CmdFrame, eUpdate_option, sizeof(stsafel_update_option_t), (PLAT_UI8 *)&option); stse_frame_element_allocate_push(&CmdFrame, eZone_index, 1, &zone_index); stse_frame_element_allocate_push(&CmdFrame, eOffset, 2, (PLAT_UI8 *)&offset); - stse_frame_element_allocate_push(&CmdFrame, eData, data_length, pData); + stse_frame_element_allocate_push(&CmdFrame, eData, data_length, (PLAT_UI8 *)pData); /*- Create Rsp frame and populate elements */ stse_frame_allocate(RspFrame); @@ -104,7 +104,7 @@ stse_ReturnCode_t stsafel_update_data_zone(stse_Handler_t *pSTSE, &RspFrame); } -stse_ReturnCode_t stsafel_read_counter_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_read_counter_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafel_read_option_t option, PLAT_UI16 offset, @@ -154,7 +154,7 @@ stse_ReturnCode_t stsafel_read_counter_zone(stse_Handler_t *pSTSE, return (ret); } -stse_ReturnCode_t stsafel_decrement_counter_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_decrement_counter_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafel_decrement_option_t option, PLAT_UI32 amount, diff --git a/services/stsafel/stsafel_data_partition.h b/services/stsafel/stsafel_data_partition.h index 7f6c8437..ea482732 100644 --- a/services/stsafel/stsafel_data_partition.h +++ b/services/stsafel/stsafel_data_partition.h @@ -75,7 +75,7 @@ typedef struct stsafel_decrement_option_t { * \param[in] protection \ref stse_cmd_protection_t Command protection flag * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_read_data_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_read_data_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafel_read_option_t option, PLAT_UI16 offset, @@ -95,11 +95,11 @@ stse_ReturnCode_t stsafel_read_data_zone(stse_Handler_t *pSTSE, * \param[in] protection \ref stse_cmd_protection_t Command protection flag * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_update_data_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_update_data_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafel_update_option_t option, PLAT_UI16 offset, - PLAT_UI8 *pData, + const PLAT_UI8 *pData, PLAT_UI16 data_length, stse_cmd_protection_t protection); @@ -116,7 +116,7 @@ stse_ReturnCode_t stsafel_update_data_zone(stse_Handler_t *pSTSE, * \param[in] protection \ref stse_cmd_protection_t Command protection flag * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_read_counter_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_read_counter_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafel_read_option_t option, PLAT_UI16 offset, @@ -139,7 +139,7 @@ stse_ReturnCode_t stsafel_read_counter_zone(stse_Handler_t *pSTSE, * \param[in] protection \ref stse_cmd_protection_t Command protection flag * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_decrement_counter_zone(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_decrement_counter_zone(stse_Handle_t *pSTSE, PLAT_UI8 zone_index, stsafel_decrement_option_t option, PLAT_UI32 amount, diff --git a/services/stsafel/stsafel_device_info.c b/services/stsafel/stsafel_device_info.c index 3268b2ee..402f16e1 100644 --- a/services/stsafel/stsafel_device_info.c +++ b/services/stsafel/stsafel_device_info.c @@ -26,7 +26,7 @@ #ifdef STSE_CONF_STSAFE_L_SUPPORT stse_ReturnCode_t stsafel_get_device_UID( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pDevice_UID) { return stsafel_get_data( pSTSE, @@ -38,7 +38,7 @@ stse_ReturnCode_t stsafel_get_device_UID( } stse_ReturnCode_t stsafel_get_device_traceability( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafel_device_traceability_t *pDevice_traceability) { return stsafel_get_data( pSTSE, @@ -50,7 +50,7 @@ stse_ReturnCode_t stsafel_get_device_traceability( } stse_ReturnCode_t stsafel_get_data( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafel_device_info_tag_t tag, PLAT_UI16 additional_data_length, PLAT_UI8 *pAdditional_data, @@ -86,7 +86,7 @@ stse_ReturnCode_t stsafel_get_data( } stse_ReturnCode_t stsafel_put_data( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafel_device_info_tag_t tag, PLAT_UI16 device_info_length, PLAT_UI8 *pDevice_info) { diff --git a/services/stsafel/stsafel_device_info.h b/services/stsafel/stsafel_device_info.h index 24fc0d04..d0284dec 100644 --- a/services/stsafel/stsafel_device_info.h +++ b/services/stsafel/stsafel_device_info.h @@ -72,7 +72,7 @@ typedef struct /*!< Device traceability info */ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafel_get_device_UID( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *pDevice_UID); /** @@ -83,7 +83,7 @@ stse_ReturnCode_t stsafel_get_device_UID( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafel_get_device_traceability( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafel_device_traceability_t *pDevice_traceability); /** @@ -98,7 +98,7 @@ stse_ReturnCode_t stsafel_get_device_traceability( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafel_get_data( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafel_device_info_tag_t tag, PLAT_UI16 additional_data_length, PLAT_UI8 *pAdditional_data, @@ -115,7 +115,7 @@ stse_ReturnCode_t stsafel_get_data( * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafel_put_data( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafel_device_info_tag_t tag, PLAT_UI16 device_info_length, PLAT_UI8 *pDevice_info); diff --git a/services/stsafel/stsafel_ecc.c b/services/stsafel/stsafel_ecc.c index 5826400e..65973275 100644 --- a/services/stsafel/stsafel_ecc.c +++ b/services/stsafel/stsafel_ecc.c @@ -26,7 +26,7 @@ #ifdef STSE_CONF_STSAFE_L_SUPPORT stse_ReturnCode_t stsafel_ecc_generate_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, const PLAT_UI8 *pChallenge, PLAT_UI16 challenge_length, diff --git a/services/stsafel/stsafel_ecc.h b/services/stsafel/stsafel_ecc.h index 4ffa9570..358772a1 100644 --- a/services/stsafel/stsafel_ecc.h +++ b/services/stsafel/stsafel_ecc.h @@ -46,7 +46,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafel_ecc_generate_signature( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stse_ecc_key_type_t key_type, const PLAT_UI8 *pChallenge, PLAT_UI16 challenge_length, diff --git a/services/stsafel/stsafel_echo.c b/services/stsafel/stsafel_echo.c index 1c6b9fba..23dbd269 100644 --- a/services/stsafel/stsafel_echo.c +++ b/services/stsafel/stsafel_echo.c @@ -25,7 +25,7 @@ #ifdef STSE_CONF_STSAFE_L_SUPPORT -stse_ReturnCode_t stsafel_echo(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_echo(stse_Handle_t *pSTSE, PLAT_UI8 *pMessage, PLAT_UI8 *pEchoed_message, PLAT_UI16 message_length) { diff --git a/services/stsafel/stsafel_echo.h b/services/stsafel/stsafel_echo.h index bd33dc66..341eff4d 100644 --- a/services/stsafel/stsafel_echo.h +++ b/services/stsafel/stsafel_echo.h @@ -42,7 +42,7 @@ * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ stse_ReturnCode_t stsafel_echo( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, PLAT_UI8 *message, PLAT_UI8 *echoed_message, PLAT_UI16 message_size); diff --git a/services/stsafel/stsafel_frame_transfer.c b/services/stsafel/stsafel_frame_transfer.c index 1ddcd948..c3b32dcc 100644 --- a/services/stsafel/stsafel_frame_transfer.c +++ b/services/stsafel/stsafel_frame_transfer.c @@ -18,7 +18,6 @@ /* Includes ------------------------------------------------------------------*/ #include -#include #include "services/stsafel/stsafel_frame_transfer.h" #include "services/stsafel/stsafel_timings.h" @@ -29,7 +28,7 @@ const PLAT_UI16 stsafel_maximum_frame_length[STSAFEL_PRODUCT_COUNT] = { STSAFEL_MAX_FRAME_LENGTH_L010, /*!< STSAFE-L Maximum command length (bytes) */ }; -stse_ReturnCode_t stsafel_frame_transmit(stse_Handler_t *pSTSE, stse_frame_t *pFrame) { +stse_ReturnCode_t stsafel_frame_transmit(stse_Handle_t *pSTSE, stse_frame_t *pFrame) { stse_ReturnCode_t ret = STSE_PLATFORM_BUS_ACK_ERROR; PLAT_UI16 retry_count = STSE_MAX_POLLING_RETRY; stse_frame_element_t *pCurrent_element; @@ -69,9 +68,9 @@ stse_ReturnCode_t stsafel_frame_transmit(stse_Handler_t *pSTSE, stse_frame_t *pF stse_frame_push_element(pFrame, &crc_element); #ifdef STSE_FRAME_DEBUG_LOG - printf("\n\r STSAFE Frame > "); + stse_platform_printf("\n\r STSAFE Frame > "); stse_frame_debug_print(pFrame); - printf("\n\r"); + stse_platform_printf("\n\r"); #endif /* STSE_FRAME_DEBUG_LOG */ ret = STSE_PLATFORM_BUS_ACK_ERROR; @@ -118,7 +117,7 @@ stse_ReturnCode_t stsafel_frame_transmit(stse_Handler_t *pSTSE, stse_frame_t *pF } #ifdef STSE_CONF_USE_I2C -stse_ReturnCode_t stsafel_i2c_frame_receive(stse_Handler_t *pSTSE, stse_frame_t *pFrame) { +stse_ReturnCode_t stsafel_i2c_frame_receive(stse_Handle_t *pSTSE, stse_frame_t *pFrame) { stse_ReturnCode_t ret = STSE_PLATFORM_BUS_ACK_ERROR; stse_frame_element_t *pCurrent_element; PLAT_UI8 received_header; @@ -324,9 +323,9 @@ stse_ReturnCode_t stsafel_i2c_frame_receive(stse_Handler_t *pSTSE, stse_frame_t } #ifdef STSE_FRAME_DEBUG_LOG - printf("\n\r STSAFE Frame < "); + stse_platform_printf("\n\r STSAFE Frame < "); stse_frame_debug_print(pFrame); - printf("\n\r"); + stse_platform_printf("\n\r"); #endif /* STSE_FRAME_DEBUG_LOG */ /* - Swap CRC */ @@ -359,7 +358,7 @@ stse_ReturnCode_t stsafel_i2c_frame_receive(stse_Handler_t *pSTSE, stse_frame_t #endif /* STSE_CONF_USE_I2C */ #ifdef STSE_CONF_USE_ST1WIRE -stse_ReturnCode_t stsafel_st1wire_frame_receive(stse_Handler_t *pSTSE, stse_frame_t *pFrame) { +stse_ReturnCode_t stsafel_st1wire_frame_receive(stse_Handle_t *pSTSE, stse_frame_t *pFrame) { stse_ReturnCode_t ret = STSE_PLATFORM_BUS_ACK_ERROR; stse_frame_element_t *pCurrent_element; PLAT_UI16 received_length; @@ -451,9 +450,9 @@ stse_ReturnCode_t stsafel_st1wire_frame_receive(stse_Handler_t *pSTSE, stse_fram } #ifdef STSE_FRAME_DEBUG_LOG - printf("\n\r STSE Frame < "); + stse_platform_printf("\n\r STSE Frame < "); stse_frame_debug_print(pFrame); - printf("\n\r"); + stse_platform_printf("\n\r"); #endif /* - Swap CRC */ @@ -479,7 +478,7 @@ stse_ReturnCode_t stsafel_st1wire_frame_receive(stse_Handler_t *pSTSE, stse_fram } #endif /* STSE_CONF_USE_ST1WIRE */ -stse_ReturnCode_t stsafel_frame_raw_transfer(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_frame_raw_transfer(stse_Handle_t *pSTSE, stse_frame_t *pCmdFrame, stse_frame_t *pRspFrame, PLAT_UI16 inter_frame_delay) { @@ -520,7 +519,7 @@ stse_ReturnCode_t stsafel_frame_raw_transfer(stse_Handler_t *pSTSE, return ret; } -stse_ReturnCode_t stsafel_frame_transfer(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_frame_transfer(stse_Handle_t *pSTSE, stse_frame_t *pCmdFrame, stse_frame_t *pRspFrame) { stse_ReturnCode_t ret = STSE_SERVICE_INVALID_PARAMETER; diff --git a/services/stsafel/stsafel_frame_transfer.h b/services/stsafel/stsafel_frame_transfer.h index 5b6555cb..868f145d 100644 --- a/services/stsafel/stsafel_frame_transfer.h +++ b/services/stsafel/stsafel_frame_transfer.h @@ -40,7 +40,7 @@ extern const PLAT_UI16 stsafel_maximum_frame_length[STSAFEL_PRODUCT_COUNT]; * \param[in,out] pFrame Pointer to the frame to be transmitted * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_frame_transmit(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_frame_transmit(stse_Handle_t *pSTSE, stse_frame_t *pFrame); /** @@ -50,7 +50,7 @@ stse_ReturnCode_t stsafel_frame_transmit(stse_Handler_t *pSTSE, * \param[in,out] pFrame Pointer to the frame to be received * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_frame_receive(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_frame_receive(stse_Handle_t *pSTSE, stse_frame_t *pFrame); /** @@ -62,7 +62,7 @@ stse_ReturnCode_t stsafel_frame_receive(stse_Handler_t *pSTSE, * \param[in] inter_frame_delay Delay between command and response frame (in ms) * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_frame_raw_transfer(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_frame_raw_transfer(stse_Handle_t *pSTSE, stse_frame_t *pCmdFrame, stse_frame_t *pRspFrame, PLAT_UI16 inter_frame_delay); @@ -76,7 +76,7 @@ stse_ReturnCode_t stsafel_frame_raw_transfer(stse_Handler_t *pSTSE, * \param[in] inter_frame_delay Delay between command and response frame (in ms) * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_frame_transfer(stse_Handler_t *pSTSE, +stse_ReturnCode_t stsafel_frame_transfer(stse_Handle_t *pSTSE, stse_frame_t *pCmdFrame, stse_frame_t *pRspFrame); diff --git a/services/stsafel/stsafel_low_power.c b/services/stsafel/stsafel_low_power.c index 65c8090f..07b0bef0 100644 --- a/services/stsafel/stsafel_low_power.c +++ b/services/stsafel/stsafel_low_power.c @@ -26,7 +26,7 @@ #ifdef STSE_CONF_STSAFE_L_SUPPORT -stse_ReturnCode_t stsafel_hibernate(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stsafel_hibernate(stse_Handle_t *pSTSE) { PLAT_UI8 cmd_header = STSAFEL_CMD_HIBERNATE; PLAT_UI8 rsp_header; @@ -48,7 +48,7 @@ stse_ReturnCode_t stsafel_hibernate(stse_Handler_t *pSTSE) { &RspFrame); } -stse_ReturnCode_t stsafel_wakeup(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stsafel_wakeup(stse_Handle_t *pSTSE) { stse_ReturnCode_t ret; if (pSTSE == NULL) { diff --git a/services/stsafel/stsafel_low_power.h b/services/stsafel/stsafel_low_power.h index 2828e389..379fadc1 100644 --- a/services/stsafel/stsafel_low_power.h +++ b/services/stsafel/stsafel_low_power.h @@ -37,7 +37,7 @@ * \param[in] pSTSE Pointer to STSE Handler * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_hibernate(stse_Handler_t *pSTSE); +stse_ReturnCode_t stsafel_hibernate(stse_Handle_t *pSTSE); /** * \brief Send wakeup command to target device @@ -45,7 +45,7 @@ stse_ReturnCode_t stsafel_hibernate(stse_Handler_t *pSTSE); * \param[in] pSTSE Pointer to STSE Handler * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_wakeup(stse_Handler_t *pSTSE); +stse_ReturnCode_t stsafel_wakeup(stse_Handle_t *pSTSE); /** \}*/ diff --git a/services/stsafel/stsafel_reset.c b/services/stsafel/stsafel_reset.c index c453d00d..7bff16ec 100644 --- a/services/stsafel/stsafel_reset.c +++ b/services/stsafel/stsafel_reset.c @@ -25,7 +25,7 @@ #ifdef STSE_CONF_STSAFE_L_SUPPORT -stse_ReturnCode_t stsafel_reset(stse_Handler_t *pSTSE) { +stse_ReturnCode_t stsafel_reset(stse_Handle_t *pSTSE) { PLAT_UI8 cmd_header = STSAFEL_CMD_RESET; PLAT_UI8 rsp_header; diff --git a/services/stsafel/stsafel_reset.h b/services/stsafel/stsafel_reset.h index e788d0e9..c06357f5 100644 --- a/services/stsafel/stsafel_reset.h +++ b/services/stsafel/stsafel_reset.h @@ -37,7 +37,7 @@ * \param[in] pSTSE Pointer to STSE Handler * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafel_reset(stse_Handler_t *pSTSE); +stse_ReturnCode_t stsafel_reset(stse_Handle_t *pSTSE); /** \}*/ diff --git a/services/stsafel/stsafel_timings.c b/services/stsafel/stsafel_timings.c index 6063cf96..ff13712e 100644 --- a/services/stsafel/stsafel_timings.c +++ b/services/stsafel/stsafel_timings.c @@ -48,7 +48,7 @@ const PLAT_UI16 stsafel_wakeup_time[STSAFEL_PRODUCT_COUNT] = { }; inline PLAT_UI16 stsafel_cmd_exec_duration( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafel_cmd_code_t command_code) { PLAT_UI8 CommandCode = command_code; diff --git a/services/stsafel/stsafel_timings.h b/services/stsafel/stsafel_timings.h index a76cc23a..db13755c 100644 --- a/services/stsafel/stsafel_timings.h +++ b/services/stsafel/stsafel_timings.h @@ -47,7 +47,7 @@ extern const PLAT_UI16 stsafel_wakeup_time[STSAFEL_PRODUCT_COUNT]; * \return PLAT_UI16 : specific command execution time */ PLAT_UI16 stsafel_cmd_exec_duration( - stse_Handler_t *pSTSE, + stse_Handle_t *pSTSE, stsafel_cmd_code_t command_code); /** @}*/