mcux: hal_nxp: remove css_pkc and els_pkc

Remove css and els PKC

Signed-off-by: David Leach <david.leach@nxp.com>
This commit is contained in:
David Leach 2024-04-05 22:34:44 -05:00 committed by Mahesh Mahadevan
parent 14160a1c14
commit 4ab0e7bc9c
861 changed files with 0 additions and 138800 deletions

View File

@ -359,22 +359,3 @@ if (CONFIG_USB_DEVICE_DRIVER)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/middleware/mcux-sdk-middleware-usb/phy)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/middleware/mcux-sdk-middleware-usb/include)
endif()
if(CONFIG_ENTROPY_MCUX_CSS)
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc
)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/comps/mcuxClCss/inc)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/comps/mcuxCsslFlowProtection/inc)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/comps/mcuxCsslSecureCounter/inc)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/comps/mcuxCsslCPreProcessor/inc)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/comps/mcuxClMemory/inc)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/platforms)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/platforms/LPC55S3x/inc)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/compiler/iar)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/platforms/crypto_ip/inc/css/2.13.4)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/platforms/crypto_ip/inc/fame)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/comps/mcuxClKey/src)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/mcux-sdk/components/css_pkc/src/comps/mcuxClSession/inc)
include(component_css)
endif()

File diff suppressed because it is too large Load Diff

View File

@ -1,49 +0,0 @@
CLNS Niobe4aSDK V2.3.0 (RFP) Release Notes
- Release: Niobe4aSDK_RFP
- Version: V2.3.0
- Date: 2021-11-04
- Link to Nexus RepositoryManager: https://nl-nxrm.sw.nxp.com/service/rest/repository/browse/cccs-releases-raw/
- Link to Bitbucket: tags/niobe4asdk_2020_rfp
- Compiler: IAR Compiler v.8.40.1
--- Test Target:
- CoSim: CSSV2 v1.9
- CoSim CSS IP: 0.2.19
- N4Silicon: X-N4A-QFP100
--- CLNS memory consumption: delivery/niobe4aSdk_2020/static_library/libclns.a
TEXT RO RW ZI TOTAL_CONSUMPTION
255478 154240 168 2772 412658
--- New Features in version 2.3.0:
- Obfuscation of some design details
- Improved test coverage
- Bugfixes
--- Features in version 2.3.0:
- Components: mcuxClCss, mcuxClMac, mcuxClHash, mcuxClSession, mcuxClKey, mcuxClMemory
- Components: mcuxClPkc, mcuxClMath, mcuxClEcc, mcuxClRsa
- Components: mcuxMbedTLS [v2.25 (2021-03-09)]
- Components: mcuxCsslCPreProcessor, mcuxCsslFlowProtection, mcuxCsslMemory, mcuxCsslParamIntegrity, mcuxCsslSecureCounter
- mcuxClCss supports the following functionality
- AES-128/192/256 encryption/decryption, modes ECB/CBC/CTR/GCM/CMAC
- SHA2-224/256/384/512 (including sha-direct mode)
- KDF: CKDF (NIST SP 800-108 / SP800-56C), HKDF (RFC5869)
- HMAC
- ECC Sign/Verify/Keygen/Keyexchange (P-256)
- RFC3394 key wrapping/unwrapping
- Key Import/Export/Utilities/Provisioning
- Random number Generation (DRBG/PRNG)
- TLS Master/Session Key generation
- GDET
- base address of CSS is link-time configuratble (using scatter file): CSS_BASE_ADDRESS
--- Known Limitations:
- Initialization of PRNG (workaround): call keydelete on any slot during startup: this will assure prng is ready
- The CSS DTRNG internal entropy is limited to 128 bits, therefore any keys generated by the CLNS are also limited to this inherent entropythis will assure prng is ready
--- Notes:
- MbedTLS: the alternative implementation of the RNG is not backward compatible with the mbedTLS release (most functions do nothing)
- MbedTLS: the alternative implementation for ECC does not support Curve25519 or Curve448

View File

@ -1,24 +0,0 @@
#Description: Component css; user_visible: True
include_guard(GLOBAL)
message("component_css component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_Aead.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_Cipher.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_Cmac.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_Common.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_Ecc.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_Hash.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_Hmac.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_Kdf.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_KeyManagement.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/src/mcuxClCss_Rng.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClCss/inc
)
include(component_css_hash)

View File

@ -1,16 +0,0 @@
#Description: Component css_hash; user_visible: True
include_guard(GLOBAL)
message("component_css_hash component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClHash/src/mcuxClHash.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClHash/src/mcuxClHash_Algorithms.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClHash/inc
)
include(component_css)

View File

@ -1,18 +0,0 @@
#Description: Component css_pkc_common; user_visible: False
include_guard(GLOBAL)
message("component_css_pkc_common component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/platforms/fsl_css_pkc.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/compiler/iar
${CMAKE_CURRENT_LIST_DIR}/src/platforms
${CMAKE_CURRENT_LIST_DIR}/src/platforms/LPC55S3x/inc
${CMAKE_CURRENT_LIST_DIR}/src/platforms/crypto_ip/inc/css/2.13.4
${CMAKE_CURRENT_LIST_DIR}/src/platforms/crypto_ip/inc/fame
)

View File

@ -1,51 +0,0 @@
#Description: Component css_pkc_ecc; user_visible: True
include_guard(GLOBAL)
message("component_css_pkc_ecc component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Constants.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_GenerateMultiplicativeBlinding.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_KeyGen.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_KeyGen_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_NIST.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_PointArithmetic.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_PointCheck.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_PointCheck_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_PointMult.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_SecurePointMult_CoZMontLadder.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_SecurePointMult_CoZMontLadder_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_SecureScalarMult_XZMontLadder.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_SecureScalarMult_XZMontLadder_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_SetupEnvironment.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Internal_SetupEnvironment_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_KeyGen.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_KeyGen_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Mont_DhKeyAgreement.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Mont_DhKeyGeneration.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Mont_Internal.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Mont_MontDhX.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Mont_MontDhX_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_NIST_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_PointMult.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_PointMult_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Sign.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Sign_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Verify.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Verify_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Verify_P384.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/mcuxClEcc_Verify_P384_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/src/size/size.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/inc
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClEcc/inc/internal
)
include(component_css_pkc_key)
include(component_pkc)

View File

@ -1,14 +0,0 @@
#Description: Component css_pkc_flow_protection; user_visible: True
include_guard(GLOBAL)
message("component_css_pkc_flow_protection component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslFlowProtection/inc
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslFlowProtection/inc/internal
)

View File

@ -1,17 +0,0 @@
#Description: Component css_pkc_key; user_visible: False
include_guard(GLOBAL)
message("component_css_pkc_key component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClKey/src/mcuxClKey.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClKey/src/mcuxClKey_KeyTypes.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClKey/src/mcuxClKey_Protection.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClKey/inc
)
include(component_css)

View File

@ -1,18 +0,0 @@
#Description: Component css_pkc_mac; user_visible: False
include_guard(GLOBAL)
message("component_css_pkc_mac component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMac/src/mcuxClCMac.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMac/src/mcuxClHMac.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMac/src/mcuxClMac.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMac/inc
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMac/inc/internal
)
include(component_css_pkc_key)

View File

@ -1,31 +0,0 @@
#Description: Component css_pkc_math; user_visible: False
include_guard(GLOBAL)
message("component_css_pkc_math component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_ExactDivideOdd.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_ExactDivideOdd_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_ModExp_SqrMultL2R.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_ModInv.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_NDash.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_QDash.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_ReduceModEven.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_SecModExp.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_SecModExp_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_Utils.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_ModInv_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_NDash_FUP.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/src/mcuxClMath_QDash_FUP.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMath/inc
)
include(component_css_pkc_flow_protection)
include(component_css_pkc_secure_counter)
include(component_css_pkc_pre_processor)
include(component_css_pkc_common)
include(component_pkc)

View File

@ -1,20 +0,0 @@
#Description: Component css_pkc_memory; user_visible: False
include_guard(GLOBAL)
message("component_css_pkc_memory component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMemory/src/mcuxClMemory.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslMemory/src/mcuxCsslMemory_Clear.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslMemory/src/mcuxCsslMemory_Compare.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslMemory/src/mcuxCsslMemory_Copy.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClMemory/inc
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslMemory/inc
)
include(component_css_pkc_param_integrity)
include(component_css_pkc_common)

View File

@ -1,17 +0,0 @@
#Description: Component css_pkc_param_integrity; user_visible: False
include_guard(GLOBAL)
message("component_css_pkc_param_integrity component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslParamIntegrity/src/mcuxCsslParamIntegrity.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslParamIntegrity/inc
)
include(component_css_pkc_flow_protection)
include(component_css_pkc_secure_counter)
include(component_css_pkc_pre_processor)

View File

@ -1,14 +0,0 @@
#Description: Component css_pkc_pre_processor; user_visible: False
include_guard(GLOBAL)
message("component_css_pkc_pre_processor component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslCPreProcessor/inc
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslCPreProcessor/inc/internal
)

View File

@ -1,27 +0,0 @@
#Description: Component css_pkc_rsa; user_visible: True
include_guard(GLOBAL)
message("component_css_pkc_rsa component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_Mgf1.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_NoEncode.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_NoVerify.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_Pkcs1v15Encode.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_Pkcs1v15Verify.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_PrivateCrt.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_PrivatePlain.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_PssEncode.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_PssVerify.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_Public.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_Sign.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/src/mcuxClRsa_Verify.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClRsa/inc
)
include(component_css_pkc_memory)
include(component_pkc)

View File

@ -1,14 +0,0 @@
#Description: Component css_pkc_secure_counter; user_visible: True
include_guard(GLOBAL)
message("component_css_pkc_secure_counter component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslSecureCounter/inc
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxCsslSecureCounter/inc/internal
)

View File

@ -1,15 +0,0 @@
#Description: Component css_pkc_session; user_visible: False
include_guard(GLOBAL)
message("component_css_pkc_session component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClSession/src/mcuxClSession.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClSession/inc
)
include(component_css_pkc_memory)

View File

@ -1,20 +0,0 @@
#Description: Component pkc; user_visible: True
include_guard(GLOBAL)
message("component_pkc component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClPkc/src/mcuxClPkc_Calculate.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClPkc/src/mcuxClPkc_ImportExport.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClPkc/src/mcuxClPkc_Initialize.c
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClPkc/src/mcuxClPkc_UPTRT.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/.
${CMAKE_CURRENT_LIST_DIR}/src/comps/mcuxClPkc/inc
)
include(component_css_pkc_math)
include(component_css_pkc_rsa)
include(component_css_pkc_ecc)

View File

@ -1,27 +0,0 @@
--------------------------------------------
NXP Software Content Register
Package: clns-niobe4aSdk_2020_RFP.zip
Outgoing License: LA_OPT_NXP_Software_License - Distribution permitted, license in Section 2.3 applies.
License Files: LICENSE.htm
Type of content: Static library, headers, sources
Description and comments: Cryptographic library running on NXP CSSv2 and PKC Crypto Hardware IP
Release Location: Nexus
Origin: Crypto Library (LA_OPT_NXP_Software_License)
CMSIS header files (Apache License 2.0; https://github.com/ARM-software/CMSIS_5)
mbedTLS v2.25 (2021-03-09) (Apache License 2.0; https://github.com/ARMmbed/mbedtls/releases/tag/v2.25.0)
--------------------------------------------

View File

@ -1,129 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClCss_Internal.h
* @brief Provide macros for mcuxClCss internal use.
* This header declares internal macros to deduplicate code and support for internal use only. */
#ifndef MCUXCLCSS_INTERNAL_H_
#define MCUXCLCSS_INTERNAL_H_
#include <platform_specific_headers.h>
/** Asserts the correctness of the supplied parameters*/
#define MCUXCLCSS_INPUT_PARAM_CHECK(x) if((x)) { return MCUXCLCSS_STATUS_SW_INVALID_PARAM; }
#define MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(funcid, x) if((x)) { MCUX_CSSL_FP_FUNCTION_EXIT(funcid, MCUXCLCSS_STATUS_SW_INVALID_PARAM); }
#define MCUXCLCSS_REVERSEFETCH_ENABLE ((uint32_t) 1U) ///< Reverse fetch enabled
#define MCUXCLCSS_REVERSEFETCH_DISABLE ((uint32_t) 0U) ///< Reverse fetch disabled
#define CSS_CMD_BIG_ENDIAN ((uint8_t) 0x01U) ///< CSS command option specifying big-endian byte order
#define CSS_CMD_LITTLE_ENDIAN ((uint8_t) 0x00U) ///< CSS command option specifying little-endian byte order
// Utility code of mcuxClCss implementation
/** Tests if the CSS is in BUSY state.
* @retval @c true if the CSS is in BUSY state */
#define MCUXCLCSS_ISBUSY (1U == IP_CSS->CSS_STATUS_b.CSS_BUSY)
/** Sets the variable-size input buffer from which the input 0 of the CSS operation will be transferred via DMA. */
#define MCUXCLCSS_SETCSSINPUT0(pInput, inputSize) \
{ \
IP_CSS->CSS_DMA_SRC0_b.ADDR_SRC0 = (uint32_t) ((uintptr_t) (pInput)); \
IP_CSS->CSS_DMA_SRC0_LEN_b.SIZE_SRC0_LEN = (uint32_t) (inputSize); \
}
/** Sets the fixed-size input buffer from which the input 0 of the CSS operation will be transferred via DMA. */
#define MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pInput) \
{ \
IP_CSS->CSS_DMA_SRC0_b.ADDR_SRC0 = (uint32_t) ((uintptr_t) (pInput)); \
}
/** Sets the variable-size input buffer from which the input 1 of the CSS operation will be transferred via DMA. */
#define MCUXCLCSS_SETCSSINPUT1(pInput, inputSize) \
{ \
IP_CSS->CSS_DMA_SRC2_b.ADDR_SRC1 = (uint32_t) ((uintptr_t) (pInput)); \
IP_CSS->CSS_DMA_SRC2_LEN_b.SIZE_SRC1_LEN = (uint32_t) (inputSize); \
}
/** Sets the fixed-size input buffer from which the input 1 of the CSS operation will be transferred via DMA. */
#define MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pInput) \
{ \
IP_CSS->CSS_DMA_SRC1_b.ADDR_SRC1 = (uint32_t) ((uintptr_t) (pInput)); \
}
/** Sets the variable-size input buffer from which the input 2 of the CSS operation will be transferred via DMA. */
#define MCUXCLCSS_SETCSSINPUT2(pInput, inputSize) \
{ \
IP_CSS->CSS_DMA_SRC2_b.ADDR_SRC2 = (uint32_t) ((uintptr_t) (pInput)); \
IP_CSS->CSS_DMA_SRC2_LEN_b.SIZE_SRC2_LEN = (uint32_t) (inputSize); \
}
/** Sets the fixed-size input buffer from which the input 2 of the CSS operation will be transferred via DMA. */
#define MCUXCLCSS_SETCSSINPUT2_FIXEDSIZE(pInput) \
{ \
IP_CSS->CSS_DMA_SRC2_b.ADDR_SRC2 = (uint32_t) ((uintptr_t) (pInput)); \
}
/** Sets the variable-size output buffer to which the result of the CSS operation will be transferred via DMA. */
#define MCUXCLCSS_SETCSSOUTPUT(pOutput, outputSize) \
{ \
IP_CSS->CSS_DMA_RES0_b.ADDR_RES0 = (uint32_t) ((uintptr_t) (pOutput)); \
IP_CSS->CSS_DMA_RES0_LEN = (uint32_t) (outputSize); \
}
/** Sets the output buffer to which the result of the CSS operation will be transferred via DMA. */
#define MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput) \
{ \
IP_CSS->CSS_DMA_RES0_b.ADDR_RES0 = (uint32_t) ((uintptr_t) (pOutput)); \
}
/** Sets the CSS keystore index 0, for commands that access a single key. */
#define MCUXCLCSS_SETKEYSTOREINDEX0(index) \
{ \
IP_CSS->CSS_KIDX0_b.KIDX0 = (uint8_t) (index); \
}
/** Sets the CSS keystore index 1, for commands that access 2 keys. */
#define MCUXCLCSS_SETKEYSTOREINDEX1(index) \
{ \
IP_CSS->CSS_KIDX1_b.KIDX1 = (uint8_t) (index); \
}
#ifdef CSS_KIDX2_KIDX2_Pos
/** Sets the CSS keystore index 2, for commands that access 3 keys. */
#define MCUXCLCSS_SETKEYSTOREINDEX2(index) \
{ \
IP_CSS->CSS_KIDX2_b.KIDX2 = (uint8_t) (index); \
}
#endif /* CSS_KIDX2_KIDX2_Pos */
/** Sets the CSS requested key properties, for commands that create a key. */
#define MCUXCLCSS_SETREQUESTEDKEYPROPERTIES(properties) \
{ \
IP_CSS->CSS_KPROPIN_b.KPROPIN = (properties).word.value; \
}
/** Starts a CSS command. */
#define MCUXCLCSS_STARTCOMMAND(command, cmdcfg0, byteOrder) \
{ \
IP_CSS->CSS_CMDCFG0_b.CMDCFG0 = (cmdcfg0); \
uint32_t ctrl = 0U; \
ctrl |= ((uint32_t) (command)) << CSS_CTRL_CSS_CMD_Pos; \
ctrl |= 0x01U << CSS_CTRL_CSS_START_Pos; \
ctrl |= 0x01U << CSS_CTRL_CSS_EN_Pos; \
ctrl |= ((uint32_t) (byteOrder)) << CSS_CTRL_BYTE_ORDER_Pos; \
IP_CSS->CSS_CTRL = ctrl; \
}
#endif /* MCUXCLCSS_INTERNAL_H_ */

View File

@ -1,125 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss.h
* @brief Top-level include file for the CSSv2 driver
*
* This includes headers for all of the functionality provided by the CSSv2 IP.
*
* @defgroup mcuxClCss mcuxClCss
* @brief Css driver
*
* This component abstracts the hardware access to the CSSv2 IP.
* The library exposes the following hardware functionality:
* <ol>
* <li> COMMON
* <ul>
* <li> CSSv2 Software Reset
* <ul> <li> #mcuxClCss_Reset_Async </ul>
* </ul>
* <li> HASH
* <ul>
* <li> SHA-2 hashing
* <ul> <li> #mcuxClCss_Hash_Async </ul>
* <li> SHA-2 hashing in direct mode
* <ul> <li> #mcuxClCss_Hash_ShaDirect </ul>
* </ul>
* <li> HMAC (Keyed-Hash Message Authentication Code)
* <ul>
* <li> HMAC
* <ul> <li> #mcuxClCss_Hmac_Async </ul>
* </ul>
* <li> CMAC (Cipher-Based Message Authentication Code)
* <ul>
* <li> CMAC
* <ul> <li> #mcuxClCss_Cmac_Async </ul>
* </ul>
* <li> CIPHER (Symmetric Encryption)
* <ul>
* <li> AES
* <ul> <li> #mcuxClCss_Cipher_Async </ul>
* </ul>
* <li> AEAD (Authenticated Encryption with Associated Data)
* <ul>
* <li> Authenticated Encryption with Associated Data
* <ul>
* <li> #mcuxClCss_Aead_Init_Async
* <li> #mcuxClCss_Aead_UpdateAad_Async
* <li> #mcuxClCss_Aead_UpdateData_Async
* <li> #mcuxClCss_Aead_Finalize_Async
* </ul>
* </ul>
* <li> KEY MANAGEMENT
* <ul>
* <li> Key deletion
* <ul> <li> #mcuxClCss_KeyDelete_Async </ul>
* <li> Key import
* <ul> <li> #mcuxClCss_KeyImport_Async </ul>
* <li> Key export
* <ul> <li> #mcuxClCss_KeyExport_Async </ul>
* </ul>
* <li> RNG
* <ul>
* <li> Random data generation using DRBG
* <ul> <li> #mcuxClCss_Rng_DrbgRequest_Async </ul>
* <li> Configuration of the DTRNG
* <ul> <li> #mcuxClCss_Rng_Dtrng_ConfigLoad_Async </ul>
* </ul>
* <li> ECC (Elliptic Curve Cryptography)
* <ul>
* <li> ECC Key generation
* <ul> <li> #mcuxClCss_EccKeyGen_Async </ul>
* <li> ECC key exchange
* <ul> <li> #mcuxClCss_EccKeyExchange_Async </ul>
* <li> ECC signature generation
* <ul> <li> #mcuxClCss_EccSign_Async </ul>
* <li> ECC signature verification
* <ul> <li> #mcuxClCss_EccVerify_Async </ul>
* </ul>
* <li> KEY DERIVATION
* <ul>
* <li> Key derivation
* <ul>
* <li> #mcuxClCss_Ckdf_Sp800108_Async
* <li> #mcuxClCss_Hkdf_Rfc5869_Async
* <li> #mcuxClCss_Hkdf_Sp80056c_Async
* </ul>
* <li> Master Key and Session Key derivation
* <ul>
* <li> #mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async
* <li> #mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async
* </ul>
* </ul>
* </ol>
*
* After each call to a function ending in <tt>_Async</tt>, one of the waiting functions #mcuxClCss_WaitForOperation or #mcuxClCss_LimitedWaitForOperation must be called to ensure completion.
* The waiting functions may fail, e.g., when the CSSv2 enters an error state.
*/
#ifndef MCUXCLCSS_H_
#define MCUXCLCSS_H_
#include <mcuxClCss_Types.h>
#include <mcuxClCss_Common.h>
#include <mcuxClCss_Hash.h>
#include <mcuxClCss_Hmac.h>
#include <mcuxClCss_Cmac.h>
#include <mcuxClCss_Cipher.h>
#include <mcuxClCss_Aead.h>
#include <mcuxClCss_KeyManagement.h>
#include <mcuxClCss_Rng.h>
#include <mcuxClCss_Ecc.h>
#include <mcuxClCss_Kdf.h>
#endif /* MCUXCLCSS_H_ */

View File

@ -1,399 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Aead.h
* @brief CSSv2 header for Authenticated Encryption with Associated Data (AEAD).
*
* This header exposes functions that enable using the CSSv2 for Authenticated Encryption with Associated Data (AEAD).
* The AEAD algorithm supported by CSSv2 is AES in Galois/Counter Mode (GCM), as described in NIST Special Publication
* 800-38D.
*/
/**
* @defgroup mcuxClCss_Aead mcuxClCss_Aead
* @brief This part of the @ref mcuxClCss driver supports Authenticated Encryption with Associated Data (AEAD).
* @ingroup mcuxClCss
* @{
*/
#ifndef MCUXCLCSS_AEAD_H_
#define MCUXCLCSS_AEAD_H_
#include <mcuxClCss_Common.h> // Common functionality
/**********************************************
* CONSTANTS
**********************************************/
/**
* @defgroup mcuxClCss_Aead_Macros mcuxClCss_Aead_Macros
* @brief Defines all macros of @ref mcuxClCss_Aead
* @ingroup mcuxClCss_Aead
* @{
*/
/**
* @defgroup MCUXCLCSS_AEAD_ MCUXCLCSS_AEAD_
* @brief Defines macros used to initialize #mcuxClCss_AeadOption_t
* @ingroup mcuxClCss_Aead_Macros
* @{
*/
#define MCUXCLCSS_AEAD_ENCRYPT ((uint32_t) 0U) ///< Set #mcuxClCss_AeadOption_t.dcrpt to this value to encrypt data
#define MCUXCLCSS_AEAD_DECRYPT ((uint32_t) 1U) ///< Set #mcuxClCss_AeadOption_t.dcrpt to this value to decrypt data
#define MCUXCLCSS_AEAD_STATE_IN_DISABLE ((uint32_t) 0U) ///< Set #mcuxClCss_AeadOption_t.acpsie to this value to load the GCM state from CSSv2
#define MCUXCLCSS_AEAD_STATE_IN_ENABLE ((uint32_t) 1U) ///< Set #mcuxClCss_AeadOption_t.acpsie to this value to load the GCM state from the context
#define MCUXCLCSS_AEAD_LASTINIT_TRUE ((uint32_t) 1U) ///< Set #mcuxClCss_AeadOption_t.lastinit to this value if this is the last call to init
#define MCUXCLCSS_AEAD_LASTINIT_FALSE ((uint32_t) 0U) ///< Set #mcuxClCss_AeadOption_t.lastinit to this value if this is not the last call to init
#define MCUXCLCSS_AEAD_EXTERN_KEY ((uint32_t) 1U) ///< Set #mcuxClCss_AeadOption_t.extkey to this value to use an external key
#define MCUXCLCSS_AEAD_INTERN_KEY ((uint32_t) 0U) ///< Set #mcuxClCss_AeadOption_t.extkey to this value to use a key from the CSS keystore
/**
* @}
*/
#define MCUXCLCSS_AEAD_IV_BLOCK_SIZE 16U ///< AES-GCM IV Granularity: 128 bit (16 bytes)
#define MCUXCLCSS_AEAD_AAD_BLOCK_SIZE 16U ///< AES-GCM AAD Granularity: 128 bit (16 bytes)
#define MCUXCLCSS_AEAD_CONTEXT_SIZE 80U ///< context size: 512 bit (64 bytes) + 16 bytes for finalize
/**
* @}
*/
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_Aead_Macros mcuxClCss_Aead_Macros
* @brief Defines all macros of @ref mcuxClCss_Aead
* @ingroup mcuxClCss_Aead
* @{
*/
/**
* @brief Command option bit field for #mcuxClCss_Aead_Init_Async, #mcuxClCss_Aead_UpdateAad_Async, #mcuxClCss_Aead_UpdateData_Async and #mcuxClCss_Aead_Finalize_Async.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_AeadOption_t word-wise
struct
{
uint32_t :1; ///< RFU
uint32_t dcrpt :1; ///< Defines if encryption or decryption shall be performed
uint32_t acpmod :2; ///< This field is managed internally
uint32_t acpsoe :1; ///< This field is managed internally
uint32_t acpsie :1; ///< This field is managed internally
uint32_t msgendw :4; ///< The size of the last data block (plain/cipher text) in bytes, without padding
uint32_t lastinit :1; ///< Defines whether this is the last call to init
uint32_t :2; ///< RFU
uint32_t extkey :1; ///< Defines whether an external key shall be used
uint32_t :18; ///< RFU
} bits; ///< Access #mcuxClCss_AeadOption_t bit-wise
} mcuxClCss_AeadOption_t;
/**
* @}
*/
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_Aead_Functions mcuxClCss_Aead_Functions
* @brief Defines all functions of @ref mcuxClCss_Aead
* @ingroup mcuxClCss_Aead
* @{
*/
/**
* @brief AES-GCM initialization
*
* This is the first stage of AEAD encryption/decryption. This generates the initial context out of the IV @p pIV and the key (@p pKey or @p keyIdx).
*
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options The AEAD command options. For more information, see #mcuxClCss_AeadOption_t.
* @param[in] keyIdx Index of the key inside the CSSv2 keystore
* @param[in] pKey Pointer to the key
* @param[in] keyLength Size of @p pKey in bytes
* @param[in] pIV Pointer to memory area that contains the IV
* @param[in] ivLength Size of @p pIV in bytes, with padding
* @param [out] pAeadCtx Pointer to the memory area that receives the AEAD context structure. Must be at least #MCUXCLCSS_AEAD_CONTEXT_SIZE bytes long.
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_EXTERN_KEY</dt>
* <dd>@p keyIdx is ignored.
*
* @p pKey must be a valid AES key and @p keyLength a valid AES key size (see @ref MCUXCLCSS_CIPHER_KEY_SIZE_AES_).</dd>
*
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_INTERN_KEY</dt>
* <dd>@p keyIdx must be a valid key index with the correct usage rights.
*
* @p pKey and @p keyLength are ignored.</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Aead_Init_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_Init_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pIV,
size_t ivLength,
uint8_t * pAeadCtx
);
/**
* @brief AES-GCM partial initialization
*
* This is the first stage of AEAD encryption/decryption. This generates the initial context out of the IV @p pIV and the key (@p pKey or @p keyIdx).
*
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options The AEAD command options. For more information, see #mcuxClCss_AeadOption_t.
* @param[in] keyIdx Index of the key inside the CSSv2 keystore
* @param[in] pKey Pointer to the key
* @param[in] keyLength Size of @p pKey in bytes
* @param[in] pIV Pointer to memory area that contains the IV
* @param[in] ivLength Size of @p pIV in bytes, with padding
* @param [out] pAeadCtx Pointer to the memory area that receives the AEAD context structure. Must be at least #MCUXCLCSS_AEAD_CONTEXT_SIZE bytes long.
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_EXTERN_KEY</dt>
* <dd>@p keyIdx is ignored.
*
* @p pKey must be a valid AES key and @p keyLength a valid AES key size (see @ref MCUXCLCSS_CIPHER_KEY_SIZE_AES_).</dd>
*
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_INTERN_KEY</dt>
* <dd>@p keyIdx must be a valid key index with the correct usage rights.
*
* @p pKey and @p keyLength are ignored.</dd>
*
* <dt>@p options.msgendw</dt>
* <dd>This field is ignored</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Aead_PartialInit_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_PartialInit_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pIV,
size_t ivLength,
uint8_t * pAeadCtx
);
/**
* @brief AES-GCM update of the Additional Authenticated Data (AAD)
*
* This is the second stage of AEAD encryption/decryption. This updates the internal authentication tag with the AAD.
*
* #mcuxClCss_Aead_Init_Async must have been called before calling this function.
*
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options The AEAD command options. For more information, see #mcuxClCss_AeadOption_t.
* @param[in] keyIdx Index of the key inside the CSSv2 keystore
* @param[in] pKey Pointer to the key
* @param[in] keyLength Size of @p pKey in bytes
* @param[in] pAad Memory area that contains the AAD
* @param[in] aadLength Length of the @p pAad in bytes with padding
* @param[in, out] pAeadCtx Pointer to the AEAD context structure. Must be at least #MCUXCLCSS_AEAD_CONTEXT_SIZE bytes long.
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_EXTERN_KEY</dt>
* <dd>@p keyIdx is ignored.
*
* @p pKey must be a valid AES key and @p keyLength a valid AES key size (see @ref MCUXCLCSS_CIPHER_KEY_SIZE_AES_).</dd>
*
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_INTERN_KEY</dt>
* <dd>@p keyIdx must be a valid key index with the correct usage rights.
*
* @p pKey and @p keyLength are ignored.</dd>
*
* <dt>@p options.msgendw</dt>
* <dd>This field is ignored</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Aead_UpdateAad_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_UpdateAad_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pAad,
size_t aadLength,
uint8_t * pAeadCtx
);
/**
* @brief AES-GCM update of the encrypted data
*
* This is the third stage of AEAD encryption/decryption. This updates the internal authentication tag with the AAD
* and outputs the ciphertext (in case of encryption) or plaintext (in case of decryption).
*
* #mcuxClCss_Aead_Init_Async, #mcuxClCss_Aead_UpdateAad_Async must have been called before calling this function.
*
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options The AEAD command options. For more information, see #mcuxClCss_AeadOption_t.
* @param[in] keyIdx Index of the key inside the CSSv2 keystore
* @param[in] pKey Pointer to the key
* @param[in] keyLength Size of @p pKey in bytes
* @param[in] pInput Pointer to the memory location of the data to be processed
* @param[in] inputLength Size of @p pInput in bytes with padding
* @param [out] pOutput Pointer to the processed data memory location
* @param[in, out] pAeadCtx Pointer to the AEAD context structure. Must be at least #MCUXCLCSS_AEAD_CONTEXT_SIZE bytes long.
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_EXTERN_KEY</dt>
* <dd>@p keyIdx is ignored.
*
* @p pKey must be a valid AES key and @p keyLength a valid AES key size (see @ref MCUXCLCSS_CIPHER_KEY_SIZE_AES_).</dd>
*
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_INTERN_KEY</dt>
* <dd>@p keyIdx must be a valid key index with the correct usage rights.
*
* @p pKey and @p keyLength are ignored.</dd>
*
* <dt>@p options.msgendw</dt>
* <dd>This field is ignored</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Aead_UpdateData_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_UpdateData_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pOutput,
uint8_t * pAeadCtx
);
/**
* @brief AES-GCM final encryption/decryption
*
* This is the fourth stage of AEAD encryption/decryption. This updates the authentication tag with the final data
* length block and outputs the tag at the desired location.
*
* #mcuxClCss_Aead_Init_Async, #mcuxClCss_Aead_UpdateAad_Async and #mcuxClCss_Aead_UpdateData_Async must have been called
* before calling this function.
*
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options The AEAD command options. For more information, see #mcuxClCss_AeadOption_t.
* @param[in] keyIdx Index of the key inside the CSSv2 keystore
* @param[in] pKey Pointer to the key
* @param[in] keyLength Size of @p pKey in bytes
* @param[in] aadLength Length of the complete Additional Authenticated Data (AAD) in bytes, without padding.
* @param[in] dataLength Length of the complete plaintext/ciphertext in bytes, without padding.
* @param [out] pTag Pointer where the resulting tag will be stored
* @param[in] pAeadCtx Pointer to the AEAD context structure. Must be at least #MCUXCLCSS_AEAD_CONTEXT_SIZE bytes long.
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_EXTERN_KEY</dt>
* <dd>@p keyIdx is ignored.
*
* @p pKey must be a valid AES key and @p keyLength a valid AES key size (see @ref MCUXCLCSS_CIPHER_KEY_SIZE_AES_).</dd>
*
* <dt>@p options.extkey == #MCUXCLCSS_AEAD_INTERN_KEY</dt>
* <dd>@p keyIdx must be a valid key index with the correct usage rights.
*
* @p pKey and @p keyLength are ignored.</dd>
*
* <dt>@p options.msgendw</dt>
* <dd>This field has to be set to the size of the last data block (plain/cipher text) in bytes, without padding</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Aead_Finalize_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_Finalize_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
size_t aadLength,
size_t dataLength,
uint8_t * pTag,
uint8_t * pAeadCtx
);
#endif /* MCUXCLCSS_AEAD_H_ */
/**
* @}
*
* @}
*/

View File

@ -1,214 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Cipher.h
* @brief CSSv2 header for symmetric ciphers.
*
* This header exposes functions that enable using the CSSv2 for symmetric encryption/decryption.
* The cipher algorithm supported by CSSv2 is AES in the following modes:
* - Electronic Code Book (ECB) mode,
* - Cipher Block Chaining (CBC) mode, and
* - Counter (CTR) mode.
* Supported key sizes are 128, 192, and 256 bits.
*/
/**
* @defgroup mcuxClCss_Cipher mcuxClCss_Cipher
* @brief This part of the @ref mcuxClCss driver supports functionality for symmetric ciphers
* @ingroup mcuxClCss
* @{
*/
#ifndef MCUXCLCSS_CIPHER_H_
#define MCUXCLCSS_CIPHER_H_
#include <mcuxClCss_Common.h> // Common functionality
/**********************************************
* CONSTANTS
**********************************************/
/**
* @defgroup mcuxClCss_Cipher_Macros mcuxClCss_Cipher_Macros
* @brief Defines all macros of @ref mcuxClCss_Cipher
* @ingroup mcuxClCss_Cipher
* @{
*/
/**
* @defgroup MCUXCLCSS_CIPHER_ MCUXCLCSS_CIPHER_
* @brief Defines valid options to be used by #mcuxClCss_CipherOption_t
* @ingroup mcuxClCss_Cipher_Macros
*
* Valid AES key sizes in bytes
* @{
*/
#define MCUXCLCSS_CIPHER_ENCRYPT 0U ///< Set this option at #mcuxClCss_CipherOption_t.dcrpt to perform an encryption
#define MCUXCLCSS_CIPHER_DECRYPT 1U ///< Set this option at #mcuxClCss_CipherOption_t.dcrpt to perform a decryption
#define MCUXCLCSS_CIPHER_STATE_OUT_ENABLE 1U ///< Set this option at #mcuxClCss_CipherOption_t.cphsoe to export the internal CSS state to @p pIV
#define MCUXCLCSS_CIPHER_STATE_OUT_DISABLE 0U ///< Set this option at #mcuxClCss_CipherOption_t.cphsoe to not export the internal CSS state
#define MCUXCLCSS_CIPHER_STATE_IN_ENABLE 1U ///< Set this option at #mcuxClCss_CipherOption_t.cphsie to import an external CSS state from @p pIV
#define MCUXCLCSS_CIPHER_STATE_IN_DISABLE 0U ///< Set this option at #mcuxClCss_CipherOption_t.cphsie to not import an external CSS state
#define MCUXCLCSS_CIPHER_EXTERNAL_KEY 1U ///< Set this option at #mcuxClCss_CipherOption_t.extkey to use a key located in CPU memory provided by @p pKey
#define MCUXCLCSS_CIPHER_INTERNAL_KEY 0U ///< Set this option at #mcuxClCss_CipherOption_t.extkey to use a key located in CSS keystore privded by @p keyIdx
#define MCUXCLCSS_CIPHERPARAM_ALGORITHM_AES_ECB 0x00U ///< Set this option at #mcuxClCss_CipherOption_t.cphmde to use AES engine in Electornic Code Book (ECB) mode
#define MCUXCLCSS_CIPHERPARAM_ALGORITHM_AES_CBC 0x01U ///< Set this option at #mcuxClCss_CipherOption_t.cphmde to use AES engine in Cipher Block Chaining (CBC) mode
#define MCUXCLCSS_CIPHERPARAM_ALGORITHM_AES_CTR 0x02U ///< Set this option at #mcuxClCss_CipherOption_t.cphmde to use AES engine in Counter (CTR) mode
/**
* @}
*/
/**
* @ingroup mcuxClCss_Cipher_Macros
*/
#define MCUXCLCSS_CIPHER_BLOCK_SIZE_AES ((size_t) 16U) ///< Size of an AES input block: 128 bit (16 bytes)
/**
* @defgroup MCUXCLCSS_CIPHER_KEY_SIZE_AES_ MCUXCLCSS_CIPHER_KEY_SIZE_AES_
* @brief Defines valid AES key sizes in bytes
* @ingroup mcuxClCss_Cipher_Macros
* @{
*/
#define MCUXCLCSS_CIPHER_KEY_SIZE_AES_128 ((size_t) 16U) ///< Size of an AES128 key: 128 bit (16 bytes)
#define MCUXCLCSS_CIPHER_KEY_SIZE_AES_192 ((size_t) 24U) ///< Size of an AES192 key: 192 bit (24 bytes)
#define MCUXCLCSS_CIPHER_KEY_SIZE_AES_256 ((size_t) 32U) ///< Size of an AES192 key: 256 bit (32 bytes)
/**
* @}
*
* @}
*/
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_Cipher_Types mcuxClCss_Cipher_Types
* @brief Defines all types of @ref mcuxClCss_Cipher
* @ingroup mcuxClCss_Cipher
* @{
*/
/**
* @brief Command option bit field for #mcuxClCss_Cipher_Async
*
* Bit field to configure #mcuxClCss_Cipher_Async. See @ref MCUXCLCSS_CIPHER_ for possible options.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_CipherOption_t word-wise
struct
{
uint32_t :1; ///< RFU
uint32_t dcrpt :1; ///< Define operation mode
uint32_t cphmde :2; ///< Define cipher mode
uint32_t cphsoe :1; ///< Define whether the CSSv2 internal cipher state should be extracted to external memory or kept internally
uint32_t cphsie :1; ///< Define whether an external provided cipher state should be imported from external memory
uint32_t :7; ///< RFU
uint32_t extkey :1; ///< Define whether an external key from memory or CSSv2 internal key should be used
uint32_t :18; ///< RFU
} bits; ///< Access #mcuxClCss_CipherOption_t bit-wise
} mcuxClCss_CipherOption_t;
/**
* @}
*/
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_Cipher_Functions mcuxClCss_Cipher_Functions
* @brief Defines all functions of @ref mcuxClCss_Cipher
* @ingroup mcuxClCss_Cipher
* @{
*/
/**
* @brief Performs AES encryption/decryption.
*
*
* Performs an AES encryption/decryption. Call #mcuxClCss_WaitForOperation to complete the operation.
* @param[in] options Encryption/decryption command options. For detailed information, see #mcuxClCss_CipherOption_t.
* @param[in] keyIdx Index of the key inside the CSSv2 keystore. See parameter properties section in function description.
* @param[in] pKey Memory area that contains the key. See parameter properties section in function description.
* @param[in] keyLength Size of @p pKey in bytes. Must be a valid key size of @ref MCUXCLCSS_CIPHER_KEY_SIZE_AES_. See parameter properties section in function description.
* @param[in] pInput Pointer to the input data to be encrypted/decrypted. Padding must be already applied.
* @param[in] inputLength Size of @p pInput in bytes, must be a multiple of the block size.
* @param[in, out] pIV A pointer to the memory location which contains/receives the IV/state of cipher. See parameter properties section in function description.
* @param[out] pOutput Pointer to the output buffer to store encrypted/decrypted data.
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.cphmde == #MCUXCLCSS_CIPHERPARAM_ALGORITHM_AES_ECB</dt>
* <dd>@p pIV is ignored.
*
* <dt>@p options.cphmde == #MCUXCLCSS_CIPHERPARAM_ALGORITHM_AES_CBC</dt>
* <dd>@p pIV must be set to the IV (when encrypting the first block) or to the last block of the ciphertext of the previous operation.
* CSSv2 will always read and write to this location.
*
*
* @p options.cphsoe is ignored.</dd>
*
* <dt>@p options.cphmde == #MCUXCLCSS_CIPHERPARAM_ALGORITHM_AES_CTR</dt>
* <dd>@p pIV must be set to the IV (when encrypting the first block) or to the state output of the previous
* encryption/decryption operation. CSSv2 will write to this location if @p options.cphsoe == #MCUXCLCSS_CIPHER_STATE_OUT_ENABLE.</dd>
*
* <dt>@p options.extkey == #MCUXCLCSS_CIPHER_EXTERNAL_KEY</dt>
* <dd>@p keyIdx is ignored.</dd>
*
* <dt>@p options.extkey == #MCUXCLCSS_CIPHER_INTERNAL_KEY</dt>
* <dd>@p pKey is ignored.
*
* @p keyLength is ignored.</dd>
*
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Cipher_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Cipher_Async(
mcuxClCss_CipherOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pIV,
uint8_t * pOutput
);
/**
* @}
*/
#endif /* MCUXCLCSS_CIPHER_H_ */
/**
* @}
*/

View File

@ -1,179 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Cmac.h
* @brief CSSv2 header for CMAC support.
* This header exposes functions that enable using the CSSv2 for the generation of cipher-based message authentication
* codes (CMAC).
* The supported cipher algorithm is AES-128 and AES-256.
*/
/**
* @defgroup mcuxClCss_Cmac mcuxClCss_Cmac
* @brief This part of the @ref mcuxClCss driver supports functionality for cipher-based message authentication codes (CMAC).
* @ingroup mcuxClCss
* @{
*/
#ifndef MCUXCLCSS_CMAC_H_
#define MCUXCLCSS_CMAC_H_
#include <mcuxClCss_Common.h> // Common functionality
/**********************************************
* MACROS
**********************************************/
/**
* @defgroup mcuxClCss_Cmac_Macros mcuxClCss_Cmac_Macros
* @brief Defines all macros of @ref mcuxClCss_Cmac
* @ingroup mcuxClCss_Cmac
* @{
*/
/**
* @defgroup MCUXCLCSS_CMAC_KEY_SIZE_ MCUXCLCSS_CMAC_KEY_SIZE_
* @brief Valid CMAC key sizes in bytes
* @ingroup mcuxClCss_Cmac_Macros
* @{ */
#define MCUXCLCSS_CMAC_KEY_SIZE_128 ((size_t) 16U) ///< Size of 128 bit CMAC key (16 bytes)
#define MCUXCLCSS_CMAC_KEY_SIZE_256 ((size_t) 32U) ///< Size of 256 bit CMAC key (32 bytes)
/** @} */
/**
* @defgroup MCUXCLCSS_CMAC_ MCUXCLCSS_CMAC_
* @brief Option values for #mcuxClCss_CmacOption_t
* @ingroup mcuxClCss_Cmac_Macros
* @{ */
#define MCUXCLCSS_CMAC_EXTERNAL_KEY_ENABLE 1U ///< Set #mcuxClCss_CmacOption_t.extkey to this value to use an external key
#define MCUXCLCSS_CMAC_EXTERNAL_KEY_DISABLE 0U ///< Set #mcuxClCss_CmacOption_t.extkey to this value to use a key from the CSSv2 keystore
#define MCUXCLCSS_CMAC_INITIALIZE_DISABLE 0U ///< Set #mcuxClCss_CmacOption_t.initialize to this value if the message chunk does not include the first block of the message
#define MCUXCLCSS_CMAC_INITIALIZE_ENABLE 1U ///< Set #mcuxClCss_CmacOption_t.initialize to this value if the message chunk includes the first block of the message
#define MCUXCLCSS_CMAC_FINALIZE_DISABLE 0U ///< Set #mcuxClCss_CmacOption_t.finalize to this value if the message chunk does not include the last block of the message
#define MCUXCLCSS_CMAC_FINALIZE_ENABLE 1U ///< Set #mcuxClCss_CmacOption_t.finalize to this value if the message chunk includes the last block of the message
#define MCUXCLCSS_CMAC_STATE_IN_DISABLE 0U ///< Set #mcuxClCss_CmacOption_t.sie to this value to use the CMAC state that is present inside CSS
#define MCUXCLCSS_CMAC_STATE_IN_ENABLE 1U ///< Set #mcuxClCss_CmacOption_t.sie to this value to import the CMAC state from memory
#define MCUXCLCSS_CMAC_STATE_OUT_DISABLE 0U ///< Set #mcuxClCss_CmacOption_t.soe to this value to keep the CMAC state inside CSS at the end of the command
#define MCUXCLCSS_CMAC_STATE_OUT_ENABLE 1U ///< Set #mcuxClCss_CmacOption_t.soe to this value to export the CMAC state to memory at the end of the command
/**
* @}
*/
#define MCUXCLCSS_CMAC_OUT_SIZE ((size_t) 16U) ///< Size of CMAC output: 128 bit (16 bytes)
/**
* @}
*/
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_Cmac_Types mcuxClCss_Cmac_Types
* @brief Defines all types of @ref mcuxClCss_Cmac
* @ingroup mcuxClCss_Cmac
* @{
*/
/**
* @brief Command option bit field for #mcuxClCss_Cmac_Async.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_CmacOption_t word-wise
struct
{
uint32_t initialize : 1; ///< Request initial processing for the first block of the message
uint32_t finalize : 1; ///< Request final processing for the last block of the message
uint32_t soe : 1; ///< This field is managed internally
uint32_t sie : 1; ///< This field is managed internally
uint32_t :9; ///< RFU
uint32_t extkey :1; ///< An external key should be used
uint32_t :18; ///< RFU
} bits; ///< Access #mcuxClCss_CmacOption_t bit-wise
} mcuxClCss_CmacOption_t;
/**
* @}
*/
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_Cmac_Functions mcuxClCss_Cmac_Functions
* @brief Defines all functions of @ref mcuxClCss_Cmac
* @ingroup mcuxClCss_Cmac
* @{
*/
/**
* @brief Performs CMAC with AES-128 or AES-256
*
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options The command options. For more information, see #mcuxClCss_CmacOption_t.
* @param[in] keyIdx The CMAC key index
* @param[in] pKey Pointer to the padded CMAC key
* @param[in] keyLength Size of @p pKey in bytes. Must be a @ref MCUXCLCSS_CMAC_KEY_SIZE_ "valid CMAC key size". See the parameter properties section in the function description.
* @param[in] pInput Pointer to a memory location which contains the data, padded via SP 800-38b standard, to be authenticated
* @param[in] inputLength Size of @p pInput in bytes before padding
* @param[in, out] pMac Pointer to the CMAC command state input/output. See the parameter properties section in the function description.
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.extkey == #MCUXCLCSS_CMAC_EXTERNAL_KEY_ENABLE</dt>
* <dd>@p keyIdx is ignored.</dd>
*
* <dt>@p options.extkey == #MCUXCLCSS_CMAC_EXTERNAL_KEY_DISABLE</dt>
* <dd>@p pKey is ignored.
*
* @p keyLength is ignored.</dd>
*
* <dt>(@p options.finalize == #MCUXCLCSS_CMAC_FINALIZE_DISABLE) && (@p options.soe == #MCUXCLCSS_CMAC_STATE_OUT_ENABLE)</dt>
* <dd>The intermediate state is written to @p pMac. </dd>
*
* <dt>@p options.finalize == #MCUXCLCSS_CMAC_FINALIZE_ENABLE</dt>
* <dd>The resulting MAC is written to @p pMac.
*
* @p options.soe is ignored.</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if an invalid parameter was specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Cmac_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Cmac_Async(
mcuxClCss_CmacOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pMac
);
#endif /* MCUXCLCSS_CMAC_H_ */
/**
* @}
*
* @}
*/

View File

@ -1,606 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Common.h
* @brief CSSv2 header for common functionality.
*
* This header exposes functions that support hardware state management for other CSSv2 commands.
*/
/**
* @defgroup mcuxClCss_Common mcuxClCss_Common
* @brief This part of the @ref mcuxClCss driver supports common functionality
* @ingroup mcuxClCss
* @{
*/
#ifndef MCUXCLCSS_COMMON_H_
#define MCUXCLCSS_COMMON_H_
#include <mcuxClCss_Types.h> // Common types
#include <mcuxCsslFlowProtection.h>
/**
* @defgroup mcuxClCss_Common_Macros mcuxClCss_Common_Macros
* @brief Defines all macros of @ref mcuxClCss_Common
* @ingroup mcuxClCss_Common
* @{
*/
#define MCUXCLCSS_API ///< Marks a function as a public API function of the mcuxClCss component
/**********************************************
* CONSTANTS
**********************************************/
/**
* @def MCUXCLCSS_HW_VERSION
* @brief Compatible CSS hardware IP version for the CLNS release that this header is part of.
* <table>
* <caption>Compatible CSS hardware IP version</caption>
* <tr><th>Version component<th>Value
* <tr><td>Level <td>0
* <tr><td>Major <td>2
* <tr><td>Minor <td>19
* <tr><td>Revision <td>0
* </table> */
#define MCUXCLCSS_HW_VERSION ((mcuxClCss_HwVersion_t) { \
.bits = { \
.level = (uint32_t) 0, \
.major = (uint32_t) 2, \
.minor = (uint32_t) 19, \
.revision = (uint32_t) 0 \
} \
})
/**
* @defgroup mcuxClCss_InterruptOptionEn_t_Macros mcuxClCss_InterruptOptionEn_t
* @brief Defines interrupt enable option values
* @ingroup mcuxClCss_Common_Macros
* @{
*/
#define MCUXCLCSS_CSS_INTERRUPT_ENABLE ((uint32_t) 1U) ///< Set this option at #mcuxClCss_InterruptOptionEn_t.cssint to allow CSS to trigger an interrupt
#define MCUXCLCSS_CSS_INTERRUPT_DISABLE ((uint32_t) 0U) ///< Set this option at #mcuxClCss_InterruptOptionEn_t.cssint to prevent CSS from triggering an interrupt
/**@}*/
/**
* @defgroup mcuxClCss_InterruptOptionRst_t_Macros mcuxClCss_InterruptOptionRst_t
* @brief Defines interrupt reset option values
* @ingroup mcuxClCss_Common_Macros
* @{
*/
#define MCUXCLCSS_CSS_RESET_CLEAR ((uint32_t) 1U) ///< Set this option at #mcuxClCss_InterruptOptionRst_t.cssint to reset the CSS interrupt flag
#define MCUXCLCSS_CSS_RESET_KEEP ((uint32_t) 0U) ///< Set this option at #mcuxClCss_InterruptOptionRst_t.cssint to keep the CSS interrupt flag
/**@}*/
/**
* @defgroup mcuxClCss_InterruptOptionSet_t_Macros mcuxClCss_InterruptOptionSet_t
* @brief Defines interrupt set option values
* @ingroup mcuxClCss_Common_Macros
* @{
*/
#define MCUXCLCSS_CSS_INTERRUPT_SET ((uint32_t) 1U) ///< Set this option at #mcuxClCss_InterruptOptionSet_t.cssint to set the CSS interrupt flag
#define MCUXCLCSS_CSS_INTERRUPT_KEEP ((uint32_t) 0U) ///< Set this option at #mcuxClCss_InterruptOptionSet_t.cssint to leave the CSS interrupt flag unchanged
/**@}*/
/**
* @defgroup MCUXCLCSS_ERROR_FLAGS_ MCUXCLCSS_ERROR_FLAGS_
* @brief Options for error flag clearing
* @ingroup mcuxClCss_Common_Macros
* @{
*/
#define MCUXCLCSS_ERROR_FLAGS_KEEP ((mcuxClCss_ErrorHandling_t) 0x0u) ///< Set this option at #mcuxClCss_ErrorHandling_t to not clear any error flags
#define MCUXCLCSS_ERROR_FLAGS_CLEAR ((mcuxClCss_ErrorHandling_t) 0x1u) ///< Set this option at #mcuxClCss_ErrorHandling_t to clear all CSS error flags
/**@}*/
/**
* @defgroup MCUXCLCSS_RESET_ MCUXCLCSS_RESET_
* @brief Options for reset handling
* @ingroup mcuxClCss_Common_Macros
* @{
*/
#define MCUXCLCSS_RESET_DO_NOT_CANCEL ((mcuxClCss_ResetOption_t) 0x0u) ///< Set this option at #mcuxClCss_ResetOption_t to abort the requested command if another CSS operation is still running
#define MCUXCLCSS_RESET_CANCEL ((mcuxClCss_ResetOption_t) 0x1u) ///< Set this option at #mcuxClCss_ResetOption_t to execute the requested command even if another CSS operation is still running
/**@}*/
/**
* @defgroup MCUXCLCSS_STATUS_PPROT_ MCUXCLCSS_STATUS_PPROT_
* @brief Values for the privilege/security level of CSS commands
*
* Note that some keys and memory areas may only be accessible when CSS is on a certain privilege/security level.
*
* The default value, before any command has been executed, is #MCUXCLCSS_STATUS_PPROT_UNPRIVILEGED_NONSECURE.
*
* @ingroup mcuxClCss_Common_Macros
* @{
*/
#define MCUXCLCSS_STATUS_PPROT_UNPRIVILEGED_SECURE ((uint32_t) 0x0u) ///< This value of #mcuxClCss_HwState_t.pprot means that the most recently started CSS operation was or is running in unprivileged secure mode
#define MCUXCLCSS_STATUS_PPROT_PRIVILEGED_SECURE ((uint32_t) 0x1u) ///< This value of #mcuxClCss_HwState_t.pprot means that the most recently started CSS operation was or is running in privileged secure mode
#define MCUXCLCSS_STATUS_PPROT_UNPRIVILEGED_NONSECURE ((uint32_t) 0x2u) ///< This value of #mcuxClCss_HwState_t.pprot means that the most recently started CSS operation was or is running in unprivileged non-secure mode
#define MCUXCLCSS_STATUS_PPROT_PRIVILEGED_NONSECURE ((uint32_t) 0x3u) ///< This value of #mcuxClCss_HwState_t.pprot means that the most recently started CSS operation was or is running in privileged non-secure mode
/**@}*/
/**
* @defgroup MCUXCLCSS_STATUS_ECDSAVFY_ MCUXCLCSS_STATUS_ECDSAVFY_
* @brief ECDSA verify check values
* @ingroup mcuxClCss_Common_Macros
* @{
*/
#define MCUXCLCSS_STATUS_ECDSAVFY_NORUN ((uint32_t) 0x0u) ///< This value of #mcuxClCss_HwState_t.ecdsavfy means that no ECDSA verify operation has been executed
#define MCUXCLCSS_STATUS_ECDSAVFY_FAIL ((uint32_t) 0x1u) ///< This value of #mcuxClCss_HwState_t.ecdsavfy means that the most recently finished ECDSA signature verification failed
#define MCUXCLCSS_STATUS_ECDSAVFY_OK ((uint32_t) 0x2u) ///< This value of #mcuxClCss_HwState_t.ecdsavfy means that the most recently finished ECDSA signature verification passed
#define MCUXCLCSS_STATUS_ECDSAVFY_ERROR ((uint32_t) 0x3u) ///< This value of #mcuxClCss_HwState_t.ecdsavfy means that an error has occurred
/**@}*/
/**
* @defgroup MCUXCLCSS_STATUS_DRBGENTLVL_ MCUXCLCSS_STATUS_DRBGENTLVL_
* @brief Constants for Entropy quality of the current DRBG instance
* @ingroup mcuxClCss_Common_Macros
* @{ */
#define MCUXCLCSS_STATUS_DRBGENTLVL_NONE ((uint32_t) 0x0u) ///< This value of #mcuxClCss_HwState_t.drbgentlvl means that the DRBG is not running
#define MCUXCLCSS_STATUS_DRBGENTLVL_LOW ((uint32_t) 0x1u) ///< This value of #mcuxClCss_HwState_t.drbgentlvl means that the DRBG can generate random numbers with a low security strength (sufficient for commands with a low DRBG security strength requirement, see the function description to check which level is required)
#define MCUXCLCSS_STATUS_DRBGENTLVL_HIGH ((uint32_t) 0x2u) ///< This value of #mcuxClCss_HwState_t.drbgentlvl means that the DRBG can generate random numbers with 128 bits of security strength (sufficient for commands with a high DRBG security strength requirement, see the function description to check which level is required)
/** @} */
/**
* @}
*/
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_Common_Types mcuxClCss_Common_Types
* @brief Defines all types of @ref mcuxClCss_Common
* @ingroup mcuxClCss_Common
* @{
*/
/**
* @brief Result type of #mcuxClCss_GetHwVersion
*
* Contains the CSS version value.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_HwVersion_t word-wise
struct
{
uint32_t revision :4; ///< Revision number
uint32_t minor :8; ///< Minor version
uint32_t major :4; ///< Major version
uint32_t level :4; ///< Release level version
uint32_t :12; ///< RFU
} bits; ///< Access #mcuxClCss_HwVersion_t bit-wise
} mcuxClCss_HwVersion_t;
/**
* @brief Result type of #mcuxClCss_GetHwState
*
* Contains CSS status information.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_HwState_t word-wise
struct
{
uint32_t busy :1; ///< CSS is busy
uint32_t irq :1; ///< CSS interrupt activated
uint32_t err :1; ///< CSS is in error state
uint32_t prngready :1; ///< CSS PRNG is seeded and ready to use
uint32_t ecdsavfy :2; ///< ECDSA verify operation state (For possible values of this field, see @ref MCUXCLCSS_STATUS_ECDSAVFY_)
uint32_t pprot :2; ///< The privilege/security level of the most recently started CSS command (For possible values of this field, see @ref MCUXCLCSS_STATUS_PPROT_)
uint32_t drbgentlvl :2; ///< Entropy quality of the current DRBG instance (For possible values of this field, see @ref MCUXCLCSS_STATUS_DRBGENTLVL_)
uint32_t dtrng_busy: 1; ///< Indicates the DTRNG is gathering entropy
uint32_t :2; ///< RFU
uint32_t :3; ///< RFU
uint32_t :1; ///< RFU
uint32_t :15; ///< RFU
} bits; ///< Access #mcuxClCss_HwState_t bit-wise
} mcuxClCss_HwState_t;
/**
* @brief Type to handle CSS error clearing options
*
* For possible values, see @ref MCUXCLCSS_ERROR_FLAGS_.
*/
typedef uint32_t mcuxClCss_ErrorHandling_t;
/**
* @brief Type to handle CSS reset options
*
* For possible values, see @ref MCUXCLCSS_RESET_.
*/
typedef uint32_t mcuxClCss_ResetOption_t;
/**
* @brief Command option type for #mcuxClCss_SetIntEnableFlags and #mcuxClCss_GetIntEnableFlags
*
* Used to get/set CSS interrupt enable options.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_InterruptOptionEn_t word-wise
struct
{
uint32_t cssint :1; ///< Whether CSS interrupt should be used. (For possible values of this field, see @ref mcuxClCss_InterruptOptionEn_t_Macros)
uint32_t :1; ///< RFU
uint32_t :30; ///< RFU
} bits; ///< Access #mcuxClCss_InterruptOptionEn_t bit-wise
} mcuxClCss_InterruptOptionEn_t;
/**
* @brief Type to control which CSS interrupts should be reset when calling #mcuxClCss_ResetIntFlags
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_InterruptOptionRst_t word-wise
struct
{
uint32_t cssint :1; ///< Whether CSS interrupt should be reset. (For possible values of this field, see @ref mcuxClCss_InterruptOptionRst_t_Macros)
uint32_t :1; ///< RFU
uint32_t :30; ///< RFU
} bits; ///< Access #mcuxClCss_InterruptOptionRst_t bit-wise
} mcuxClCss_InterruptOptionRst_t;
/**
* @brief Type to control which CSS interrupts should be set when calling #mcuxClCss_SetIntFlags
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_InterruptOptionSet_t word-wise
struct
{
uint32_t cssint :1; ///< Whether CSS interrupt should be set. (For possible values of this field, see @ref mcuxClCss_InterruptOptionSet_t_Macros)
uint32_t :2; ///< RFU
uint32_t :29; ///< RFU
} bits; ///< Access #mcuxClCss_InterruptOptionSet_t bit-wise
} mcuxClCss_InterruptOptionSet_t;
/**
* @brief Result type of #mcuxClCss_GetHwConfig
*
* Contains CSS configuration values.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_InterruptOptionSet_t word-wise
struct
{
uint32_t ciphersup :1; ///< Indicates whether the cipher command is supported
uint32_t authciphersup :1; ///< Indicates whether the auth_cipher command is supported
uint32_t ecsignsup :1; ///< Indicates whether the ecsign command is supported
uint32_t ecvfysup :1; ///< Indicates whether the ecvfy command is supported
uint32_t eckxchsup :1; ///< Indicates whether the dhkey_xch command is supported
uint32_t keygensup :1; ///< Indicates whether the keygen command is supported
uint32_t keyinsup :1; ///< Indicates whether the keyin command is supported
uint32_t keyoutsup :1; ///< Indicates whether the keyout command is supported
uint32_t kdeletesup :1; ///< Indicates whether the kdelete command is supported
uint32_t keyprovsup :1; ///< Indicates whether the keyprov command is supported
uint32_t ckdfsup :1; ///< Indicates whether the ckdf command is supported
uint32_t hkdfsup :1; ///< Indicates whether the hkdf command is supported
uint32_t tlsinitsup :1; ///< Indicates whether the tls_init command is supported
uint32_t hashsup :1; ///< Indicates whether the hash command is supported
uint32_t hmacsup :1; ///< Indicates whether the hmac command is supported
uint32_t cmacsup :1; ///< Indicates whether the cmac command is supported
uint32_t drbgreqsup :1; ///< Indicates whether the drbg_req command is supported
uint32_t drbgtestsup :1; ///< Indicates whether the drbg_test command is supported
uint32_t dtrgncfgloadsup :1; ///< Indicates whether the dtrng_cfg_load command is is supported
uint32_t dtrngevalsup :1; ///< Indicates whether the dtrng_eval command is supported
uint32_t gdetcfgloadsup :1; ///< Indicates whether the gdet_cfg_load command is supported
uint32_t gdettrimsup :1; ///< Indicates whether the gdet_trim command is supported
uint32_t :10; ///< RFU
} bits; ///< Access #mcuxClCss_InterruptOptionSet_t bit-wise
} mcuxClCss_HwConfig_t;
#define drbgreqsub drbgreqsup ///< Deprecated name for #mcuxClCss_HwConfig_t.drbgreqsup
/**
* @}
*/
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_Common_Functions mcuxClCss_Common_Functions
* @brief Defines all functions of @ref mcuxClCss_Common
* @ingroup mcuxClCss_Common
* @{
*/
/**
* @brief Determines the version of the underlying CSS hardware IP.
*
* @attention This header was delivered as part of a CLNS release which is compatible with a specific CSS hardware IP version,
* which is defined by the macro #MCUXCLCSS_HW_VERSION.
*
* @param[out] result Pointer which will be filled with the CSS hardware version
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_GetHwVersion)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetHwVersion(
mcuxClCss_HwVersion_t * result
);
/**
* @brief Determines the hardware configuration of the underlying CSS hardware IP.
*
* @param[out] result Pointer which will be filled with the CSS hardware configuration
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_GetHwConfig)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetHwConfig(
mcuxClCss_HwConfig_t * result
);
/**
* @brief Determines the current state of the CSS.
*
* @param[out] result Pointer which will be filled with the CSS status information
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_GetHwState)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetHwState(
mcuxClCss_HwState_t * result
);
/**
* @brief Enables the CSS.
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK_WAIT
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Enable_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Enable_Async(
void
);
/**
* @brief Perform a synchronous reset of the CSS.
*
* This means that:
* - any running CSS command will be stopped,
* - all errors will be cleared,
* - all keys will be deleted,
* - any RNG entropy will be discarded,
* - the glitch detector will be reset and
* - the run-time fingerprint will be restored to its default value.
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options A value indicating whether any running CSS operations shall be canceled
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
*
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the reset
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Reset_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Reset_Async(
mcuxClCss_ResetOption_t options
);
/**
* @brief Disable the CSSv2.
*
* This is useful as a power saving mechanism.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Disable)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Disable(
void
);
/**
* @brief Set interrupt enable flags.
*
* @param[in] options The command options, determining which interrupts should be enabled or disabled. For more information, see #mcuxClCss_InterruptOptionEn_t.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_SetIntEnableFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_SetIntEnableFlags(
mcuxClCss_InterruptOptionEn_t options
);
/**
* @brief Get interrupt enable flags.
*
* @param[out] result Pointer which is filled with the configuration of the interrupts enable register.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_GetIntEnableFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetIntEnableFlags(
mcuxClCss_InterruptOptionEn_t * result
);
/**
* @brief Clear the interrupt status register.
*
* @param[in] options The command options, determining which interrupt status bits should be cleared. For more information, see #mcuxClCss_InterruptOptionRst_t.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_ResetIntFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_ResetIntFlags(
mcuxClCss_InterruptOptionRst_t options
);
/**
* @brief Set the interrupt status register, for debug and testing purposes.
*
* @param[in] options The command options, determining which interrupt status bits should be set. For more information, see #mcuxClCss_InterruptOptionSet_t.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_SetIntFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_SetIntFlags(
mcuxClCss_InterruptOptionSet_t options
);
/**
* @brief Wait for a CSS operation and optionally clear the error status.
*
* If a CSS operation is active, this function waits for completion of that operation. For this, the
* busy flag of CSS is polled. Additionally, this function checks and returns any applicable error indication.
* If no operation is active, the function returns immediately.
*
* @param[in] errorHandling Define if error flags shall be cleared.
*
* @retval #MCUXCLCSS_STATUS_OK if the last operation was successful, or no operation was active
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_WaitForOperation)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_WaitForOperation(
mcuxClCss_ErrorHandling_t errorHandling
);
/**
* @brief Await the completion of a CSS operation for a limited amount of time and optionally clear the error status.
*
* If a CSS operation is active, this function waits for completion of that operation until a counter expires.
* For this, the busy flag of CSS is polled. The counting mechanism behaves like a simple for-loop from
* @p counterLimit to one. This counter does not have a well-defined relationship to real-world time.
* Additionally, this function checks and returns any applicable error indication.
* If no operation is active, the function returns immediately.
*
* @param[in] counterLimit The limit of the wait counter.
* @param[in] errorHandling Define if error flags shall be cleared.
*
* @retval #MCUXCLCSS_STATUS_OK if the last operation was successful, or no operation was active
* @retval #MCUXCLCSS_STATUS_SW_COUNTER_EXPIRED if the counter expired while waiting for the operation to complete
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_LimitedWaitForOperation)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_LimitedWaitForOperation(
uint32_t counterLimit,
mcuxClCss_ErrorHandling_t errorHandling
);
/**
* @brief Resets all error flags that have been set by a previous operation.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code is always #MCUXCLCSS_STATUS_OK
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_ResetErrorFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_ResetErrorFlags(
void);
/**
* @brief Get the last CSS error code and optionally clear the error status.
*
* @param[in] errorHandling Define if error flags shall be cleared.
*
* @retval #MCUXCLCSS_STATUS_OK if the last operation was successful or no operation was active
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_GetErrorCode)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetErrorCode(
mcuxClCss_ErrorHandling_t errorHandling
);
/**
* @brief Get the last CSS error code and level and optionally clear the error status.
*
* @param[in] errorHandling Define if error flags shall be cleared.
* @param[out] errorLevel Pointer to the location that will receive the value of the error level.
*
* @retval #MCUXCLCSS_STATUS_OK if the last operation was successful or no operation was active
* @retval #MCUXCLCSS_STATUS_ if the last operation resulted in an error
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_GetErrorLevel)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetErrorLevel(
mcuxClCss_ErrorHandling_t errorHandling,
uint32_t *errorLevel
);
/**
* @brief Set the random start delay for AES based operations. This impacts mcuxClCss_Aead_*, mcuxClCss_Cipher_*, mcuxClCss_Cmac_*, ncpClCss_Ckdf_*, mcuxClCss_KeyImport_Async, mcuxClCss_KeyExport_Async
*
* @param[in] delay Define the max random start delay. Acceptable values are a power of 2 minus one, starting from 0 to 1023 (0, 1, 3, 7, ..., 1023).
*
* @retval #MCUXCLCSS_STATUS_OK if the operation was successful
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_SetRandomStartDelay)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_SetRandomStartDelay(
uint32_t delay
);
/**
* @brief Get the random start delay for AES based operations.
*
* @param[out] delay Pointer to store random start delay configuration.
*
* @retval #MCUXCLCSS_STATUS_OK if the operation was successful
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_GetRandomStartDelay)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetRandomStartDelay(
uint32_t * delay
);
#endif /* MCUXCLCSS_COMMON_H_ */
/**
* @}
*
* @}
*/

View File

@ -1,428 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Ecc.h
* @brief CSSv2 header for elliptic curve cryptography
* This header exposes functions that enable using the CSSv2 for elliptic curve cryptography.
* All functions operate on the NIST P-256 curve.
* The ECC operations supported are:
* - ECC key generation
* - ECC Diffie-Hellman key exchange
* - ECDSA signature generation/verification
*/
#ifndef MCUXCLCSS_ECC_H_
#define MCUXCLCSS_ECC_H_
#include <mcuxClCss_Common.h> // Common types & functionality
/**
* @defgroup mcuxClCss_Ecc mcuxClCss_Ecc
* @brief This part of the @ref mcuxClCss driver supports functionality for elliptic curve cryptography
* @ingroup mcuxClCss
* @{
*/
/**********************************************
* CONSTANTS
**********************************************/
/**
* @defgroup mcuxClCss_Ecc_Macros mcuxClCss_Ecc_Macros
* @brief Defines all macros of @ref mcuxClCss_Ecc
* @ingroup mcuxClCss_Ecc
* @{
*/
/**
* @defgroup MCUXCLCSS_ECC_VALUE_ MCUXCLCSS_ECC (Sign and Verify) option word values
* @brief Constants for #mcuxClCss_EccSignOption_t and #mcuxClCss_EccVerifyOption_t
* @ingroup mcuxClCss_Ecc_Macros
* @{
*/
#define MCUXCLCSS_ECC_VALUE_HASHED ((uint32_t) 0u<< 0u) ///< Set this option at #mcuxClCss_EccSignOption_t.value or #mcuxClCss_EccVerifyOption_t.value to specify input is the hash of the message
#define MCUXCLCSS_ECC_VALUE_NOT_HASHED ((uint32_t) 1u<< 0u) ///< Set this option at #mcuxClCss_EccSignOption_t.value or #mcuxClCss_EccVerifyOption_t.value to specify input is the plain message
#define MCUXCLCSS_ECC_VALUE_RTF ((uint32_t) 1u<< 1u) ///< Set this option at #mcuxClCss_EccSignOption_t.value to include the RTF in the signature, only for #mcuxClCss_EccSignOption_t
#define MCUXCLCSS_ECC_VALUE_NO_RTF ((uint32_t) 0u<< 1u) ///< Set this option at #mcuxClCss_EccSignOption_t.value to not include the RTF in the signature, only for #mcuxClCss_EccSignOption_t
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_KEYGEN_VALUE_ MCUXCLCSS_KEYGEN option word values
* @brief Constants for #mcuxClCss_EccKeyGenOption_t
* @ingroup mcuxClCss_Ecc_Macros
* @{
*/
#define MCUXCLCSS_KEYGEN_VALUE_SIGN_PUBLICKEY ((uint32_t) 1u<< 0u) ///< Set this option at #mcuxClCss_EccKeyGenOption_t.value to sign the public key
#define MCUXCLCSS_KEYGEN_VALUE_TYPE_SIGN ((uint32_t) 0u<< 1u) ///< Set this option at #mcuxClCss_EccKeyGenOption_t.value to specify output key will be a signing key usable by #mcuxClCss_EccSign_Async
#define MCUXCLCSS_KEYGEN_VALUE_TYPE_KEYEXCHANGE ((uint32_t) 1u<< 1u) ///< Set this option at #mcuxClCss_EccKeyGenOption_t.value to specify output key will be a Diffie Helman key usable by #mcuxClCss_EccKeyExchange_Async
#define MCUXCLCSS_KEYGEN_VALUE_DETERMINISTIC ((uint32_t) 0u<< 2u) ///< Set this option at #mcuxClCss_EccKeyGenOption_t.value to specify output key is deterministic
#define MCUXCLCSS_KEYGEN_VALUE_RANDOM ((uint32_t) 1u<< 2u) ///< Set this option at #mcuxClCss_EccKeyGenOption_t.value to specify output key is random
#define NXFCLCSS_KEYGEN_VALUE_GEN_PUB_KEY ((uint32_t) 0u<< 3u) ///< Set this option at #mcuxClCss_EccKeyGenOption_t.value to generate a public key
#define NXFCLCSS_KEYGEN_VALUE_NO_PUB_KEY ((uint32_t) 1u<< 3u) ///< Set this option at #mcuxClCss_EccKeyGenOption_t.value to not generate a public key
#define MCUXCLCSS_KEYGEN_VALUE_NO_RANDOM_DATA ((uint32_t) 0u<< 5u) ///< Set this option at #mcuxClCss_EccKeyGenOption_t.value to not use random data for signing the public key
#define MCUXCLCSS_KEYGEN_VALUE_USE_RANDOM_DATA ((uint32_t) 1u<< 5u) ///< Set this option at #mcuxClCss_EccKeyGenOption_t.value to use random data for signing the public key
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_ECC_VALUE_BITS MCUXCLCSS_ECC (Sign and Verify) option bit field values
* @brief Bit field constants for #mcuxClCss_EccSignOption_t and #mcuxClCss_EccVerifyOption_t
* @ingroup mcuxClCss_Ecc_Macros
* @{
*/
#define MCUXCLCSS_ECC_HASHED 0U ///< Set this option at #mcuxClCss_EccSignOption_t.echashchl or #mcuxClCss_EccVerifyOption_t.echashchl to specify input is the hash of the message
#define MCUXCLCSS_ECC_NOT_HASHED 1U ///< Set this option at #mcuxClCss_EccSignOption_t.echashchl or #mcuxClCss_EccVerifyOption_t.echashchl to specify input is the plain message
#define MCUXCLCSS_ECC_RTF 1U ///< Set this option at #mcuxClCss_EccSignOption_t.signrtf to include the RTF in the signature
#define MCUXCLCSS_ECC_NO_RTF 0U ///< Set this option at #mcuxClCss_EccSignOption_t.signrtf to not include the RTF in the signature
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_KEYGEN_VALUE_BITS MCUXCLCSS_KEYGEN option bit field values
* @brief Bit field constants for #mcuxClCss_EccKeyGenOption_t
* @ingroup mcuxClCss_Ecc_Macros
* @{
*/
#define MCUXCLCSS_ECC_PUBLICKEY_SIGN_ENABLE 1U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.kgsign to sign the public key (signature will be concatenated to the output public key)
#define MCUXCLCSS_ECC_PUBLICKEY_SIGN_DISABLE 0U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.kgsign to not sign the public key
#define MCUXCLCSS_ECC_OUTPUTKEY_SIGN 0U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.kgtypedh to specify output key will be a signing key usable by #mcuxClCss_EccSign_Async
#define MCUXCLCSS_ECC_OUTPUTKEY_KEYEXCHANGE 1U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.kgtypedh to specify output key will be a Diffie Helman key usable by #mcuxClCss_EccKeyExchange_Async
#define MCUXCLCSS_ECC_OUTPUTKEY_DETERMINISTIC 0U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.kgsrc to specify output key is deterministic
#define MCUXCLCSS_ECC_OUTPUTKEY_RANDOM 1U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.kgsrc to specify output key is random
#define MCUXCLCSS_ECC_GEN_PUBLIC_KEY 0U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.skip_pbk to generate a public key
#define MCUXCLCSS_ECC_SKIP_PUBLIC_KEY 1U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.skip_pbk to not generate a public key.
///< If #MCUXCLCSS_ECC_OUTPUTKEY_KEYEXCHANGE set, this option will be ignored and a public key will be generated.
#define MCUXCLCSS_ECC_NO_RANDOM_DATA 0U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.kgsign_rnd to not include user provided random data for the signature
#define MCUXCLCSS_ECC_INCLUDE_RANDOM_DATA 1U ///< Set this option at #mcuxClCss_EccKeyGenOption_t.kgsign_rnd to include user provided random data for the signature.
///< #MCUXCLCSS_ECC_PUBLICKEY_SIGN_ENABLE must be set in this case.
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_ECC_SIZE MCUXCLCSS_ECC_SIZE
* @brief Defines size of public key and signature in bytes
* @ingroup mcuxClCss_Ecc_Macros
* @{
*/
#define MCUXCLCSS_ECC_PUBLICKEY_SIZE ((size_t) 64U) ///< Size of the public key
#define MCUXCLCSS_ECC_SIGNATURE_SIZE ((size_t) 64U) ///< Size of the signature
#define MCUXCLCSS_ECC_SIGNATURE_R_SIZE ((size_t) 32U) ///< Size of the signature part r
/**
* @}
*/
/**
* @}
*/ /* mcuxClCss_Ecc_Macros */
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_Ecc_Types mcuxClCss_Ecc_Types
* @brief Defines all types of @ref mcuxClCss_Ecc
* @ingroup mcuxClCss_Ecc
* @{
*/
/**
* @brief Data type for ECC parameters in CSS format
* @deprecated All CSS ECC functions now operate on uint8_t. This type will be removed soon.
*/
typedef uint8_t mcuxClCss_EccByte_t;
/**
* @brief Command option bit field for #mcuxClCss_EccSign_Async
* Bit field to configure #mcuxClCss_EccSign_Async. See @ref MCUXCLCSS_ECC_VALUE_BITS for possible options.
*/
typedef union
{
struct
{
uint32_t value; ///< Access the bit field as a full word; initialize with a combination of constants from @ref MCUXCLCSS_ECC_VALUE_
} word; ///< Access #mcuxClCss_EccSignOption_t word-wise
struct
{
uint32_t echashchl :1; ///< Define type of input, plain message or hash of message
uint32_t signrtf :1; ///< Define if signing the Run-Time Fingerprint
uint32_t :2; ///< RFU
uint32_t revf :1; ///< This field is managed internally
uint32_t :27; ///< RFU
} bits; ///< Access #mcuxClCss_EccSignOption_t bit-wise
} mcuxClCss_EccSignOption_t;
/**
* @brief Command option bit field for #mcuxClCss_EccVerify_Async
* Bit field to configure #mcuxClCss_EccVerifyOption_t. See @ref MCUXCLCSS_ECC_VALUE_BITS for possible options.
*/
typedef union
{
struct
{
uint32_t value; ///< Access the bit field as a full word; initialize with a combination of constants from @ref MCUXCLCSS_ECC_VALUE_
} word; ///< Access #mcuxClCss_EccVerifyOption_t word-wise
struct
{
uint32_t echashchl :1; ///< Define type of input, plain message or hash of message
uint32_t :3; ///< RFU
uint32_t revf :1; ///< This field is managed internally
uint32_t :27; ///< RFU
} bits; ///< Access #mcuxClCss_EccVerifyOption_t bit-wise
} mcuxClCss_EccVerifyOption_t;
/**
* @brief Command option bit field for #mcuxClCss_EccKeyGen_Async
* Bit field to configure #mcuxClCss_EccKeyGenOption_t. See @ref MCUXCLCSS_KEYGEN_VALUE_BITS for possible options.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word; initialize with a combination of constants from @ref MCUXCLCSS_KEYGEN_VALUE_
} word; ///< Access #mcuxClCss_EccKeyGenOption_t word-wise
struct
{
uint32_t kgsign :1; ///< Define if signing the output public key
uint32_t kgtypedh :1; ///< Define the usage of the output key
uint32_t kgsrc :1; ///< Define if the output key is deterministic or random
uint32_t skip_pbk :1; ///< Define if generating a public key
uint32_t revf :1; ///< This field is managed internally
uint32_t kgsign_rnd :1; ///< Define if using user provided random data for the signature.
uint32_t :26; ///< RFU
} bits; ///< Access #mcuxClCss_EccKeyGenOption_t bit-wise
} mcuxClCss_EccKeyGenOption_t;
/**
* @}
*/ /* mcuxClCss_Ecc_Types */
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_Ecc_Functions mcuxClCss_Ecc_Functions
* @brief Defines all functions of @ref mcuxClCss_Ecc
* @ingroup mcuxClCss_Ecc
* @{
*/
/**
* @brief Generates an ECC key pair on the NIST P-256 curve.
*
* Before execution, CSS will wait until #mcuxClCss_HwState_t.drbgentlvl == #MCUXCLCSS_STATUS_DRBGENTLVL_HIGH. This can lead to a delay if the DRBG is in a state with less security strength at the time of the call.
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
* The public key will be stored in the standard ANSI X9.62 byte order (big-endian).
*
* @param[in] options The command options. For more information, see #mcuxClCss_EccKeyGenOption_t.
* @param[in] signingKeyIdx The index of the key to sign the generated public key.
* @param[in] privateKeyIdx Output key index.
* @param[in] generatedKeyProperties The desired key properties of the generated key.
* @param[in] pRandomData Random data provided by the user.
* @param[out] pPublicKey Pointer to the memory area which receives the public key and optionally the key signature.
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>@p options.kgsign == #MCUXCLCSS_ECC_PUBLICKEY_SIGN_DISABLE</dt>
* <dd>@p signingKeyIdx is ignored.</dd>
* <dt>@p options.kgsrc == #MCUXCLCSS_ECC_OUTPUTKEY_DETERMINISTIC</dt>
* <dd>@p privateKeyIdx also defines the key index of the source key material.
* The source key material will be overwritten by the output public key.</dd>
* <dt>@p options.kgsign_rnd == #MCUXCLCSS_ECC_NO_RANDOM_DATA</dt>
* <dd>@p pRandomData is ignored.</dd>
* <dt>@p pPublicKey must be aligned on a 4-byte boundary.</dt>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_EccKeyGen_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_EccKeyGen_Async(
mcuxClCss_EccKeyGenOption_t options,
mcuxClCss_KeyIndex_t signingKeyIdx,
mcuxClCss_KeyIndex_t privateKeyIdx,
mcuxClCss_KeyProp_t generatedKeyProperties,
uint8_t const * pRandomData,
uint8_t * pPublicKey
);
/**
* @brief Performs a Diffie-Hellman key exchange with an internal ECC private key and an external ECC public key.
*
* Before execution, CSS will wait until #mcuxClCss_HwState_t.drbgentlvl == #MCUXCLCSS_STATUS_DRBGENTLVL_LOW. This can lead to a delay if the DRBG is in a state with less security strength at the time of the call.
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
* The public key must be stored in the standard ANSI X9.62 byte order (big-endian).
*
* @param[in] privateKeyIdx The private key index.
* @param[in] pPublicKey Pointer to the public key of a third party.
* @param[in] sharedSecretIdx The index in the CSSv2 keystore that receives the shared secret that is generated by the ECDH operation.
* @param[in] sharedSecretProperties The desired key properties of the shared secret.
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>@p pPublicKey </dt>
* <dd>The public key consists of the 256-bit X coordinate and the 256-bit Y coordinate.
* The point must lie on the NIST P-256 curve, be encoded in X9.62 format and aligned on a 4-byte boundary.</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_EccKeyExchange_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_EccKeyExchange_Async(
mcuxClCss_KeyIndex_t privateKeyIdx,
uint8_t const * pPublicKey,
mcuxClCss_KeyIndex_t sharedSecretIdx,
mcuxClCss_KeyProp_t sharedSecretProperties
);
/**
* @brief Generates an ECDSA signature of a given message.
*
* The curve is NIST P-256.
* The message hash, must be stored in the standard ANSI X9.62 format.
* If the message is provided in plain, no prior conversion is necessary.
* The signature will be stored in the standard ANSI X9.62 byte order (big-endian).
* No matter the value of @p options.echashchl, it must be ensured that SHA-Direct mode is disabled when calling this function (see #mcuxClCss_ShaDirect_Disable).
*
* Before execution, CSS will wait until #mcuxClCss_HwState_t.drbgentlvl == #MCUXCLCSS_STATUS_DRBGENTLVL_HIGH. This can lead to a delay if the DRBG is in a state with less security strength at the time of the call.
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options The command options. For more information, see #mcuxClCss_EccSignOption_t.
* @param[in] keyIdx The private key index.
* @param[in] pInputHash The hash of the message to sign in X9.62 format.
* @param[in] pInputMessage The message to sign.
* @param[in] inputMessageLength Size of @p pInputMessage in bytes.
* @param[out] pOutput Pointer to the memory area which receives the generated signature in X9.62 format. (64 bytes)
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>@p options.echashchl == #MCUXCLCSS_ECC_HASHED</dt>
* <dd>@p pInputHash is used, and it must be aligned on a 4-byte boundary.
* @p pInputMessage is ignored.</dd>
* <dt>@p options.echashchl == #MCUXCLCSS_ECC_NOT_HASHED</dt>
* <dd>@p pInputHash is ignored.
* @p pInputMessage and @p inputMessageLength are used.</dd>
* <dt>@p pOptput must be aligned on a 4-byte boundary.</dt>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_EccSign_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_EccSign_Async(
mcuxClCss_EccSignOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pInputHash,
uint8_t const * pInputMessage,
size_t inputMessageLength,
uint8_t * pOutput
);
/**
* @brief Verifies an ECDSA signature of a given message.
*
* The curve is NIST P-256.
* The message hash, must be stored in the standard ANSI X9.62 format.
* If the message is provided in plain, no prior conversion is necessary.
* The signature and public key must be stored in the standard ANSI X9.62 byte order (big-endian).
* No matter the value of @p options.echashchl, it must be ensured that SHA-Direct mode is disabled when calling this function (see #mcuxClCss_ShaDirect_Disable).
*
* Before execution, CSS will wait until #mcuxClCss_HwState_t.drbgentlvl == #MCUXCLCSS_STATUS_DRBGENTLVL_LOW. This can lead to a delay if the DRBG is in a state with less security strength at the time of the call.
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options The command options. For more information, see #mcuxClCss_EccVerifyOption_t.
* @param[in] pInputHash The hash of the signed message in X9.62 format.
* @param[in] pInputMessage The message to sign.
* @param[in] inputMessageLength Size of @p pInputMessage in bytes.
* @param[in] pSignatureAndPubKey Pointer to the memory area which contains the concatenation of the signature and the public key.
* @param[out] pOutput Pointer to the memory area which will receive the recalculated value of the R component in case of a successful
* signature verification.
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>@p options.echashchl == #MCUXCLCSS_ECC_HASHED</dt>
* <dd>@p pInputHash is used, and it must be aligned on a 4-byte boundary.
* @p pInputMessage is ignored.</dd>
* <dt>@p options.echashchl == #MCUXCLCSS_ECC_NOT_HASHED</dt>
* <dd>@p pInputHash is ignored.
* @p pInputMessage and @p inputMessageLength are used.</dd>
* <dt>@p pSignatureAndPubKey </dt>
* <dd>It must be aligned on a 4-byte boundary.
* The signature to be verified consists of the 256-bit R component and the 256-bit S component.
* The public key is the one for verification. (Uncompressed, X and Y components)
* The signature and the public key are in X9.62 format.</dd>
* <dt>@p pOutput </dt>
* <dd>It must be aligned on a 4-byte boundary.
* The output shall be compared to the first 32 bytes stored at @p pSignatureAndPublicKey.</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_EccVerify_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_EccVerify_Async(
mcuxClCss_EccVerifyOption_t options,
uint8_t const * pInputHash,
uint8_t const * pInputMessage,
size_t inputMessageLength,
uint8_t const * pSignatureAndPubKey,
uint8_t * pOutput
);
/**
* @}
*/ /* mcuxClCss_Ecc_Functions */
/**
* @}
*/ /* mcuxClCss_Ecc */
#endif /* MCUXCLCSS_ECC_H_ */

View File

@ -1,319 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Hash.h
* @brief CSSv2 header for hashing.
*
* This header exposes functions that enable using the CSSv2 for hashing.
* There are two modes to hash a message: The asynchronous way as a CSSv2 command, and the SHA-Direct mode which feeds
* data to the internal registers of the CSSv2 and is synchronous (blocking).
* The SHA-Direct mode is meant to be used when another command should be executed in parallel on the CSSv2 while the
* hash operation is still ongoing. For this, use the DMA callback option in #mcuxClCss_Hash_ShaDirect.
*/
/**
* @defgroup mcuxClCss_Hash mcuxClCss_Hash
* @brief This part of the @ref mcuxClCss driver supports hashing
* @ingroup mcuxClCss
* @{
*/
#ifndef MCUXCLCSS_HASH_H_
#define MCUXCLCSS_HASH_H_
#include <mcuxClCss_Common.h> // Common functionality
/**********************************************
* CONSTANTS
**********************************************/
/**
* @defgroup mcuxClCss_Hash_Macros mcuxClCss_Hash_Macros
* @brief Defines all macros of @ref mcuxClCss_Hash
* @ingroup mcuxClCss_Hash
* @{
*/
/**
* @defgroup MCUXCLCSS_HASH_ MCUXCLCSS_HASH_
* @brief Defines valid options to be used by #mcuxClCss_HashOption_t
* @ingroup mcuxClCss_Hash_Macros
* @{
*/
#define MCUXCLCSS_HASH_INIT_ENABLE 1U ///< Set this option at #mcuxClCss_HashOption_t.hashini to initialize the hash
#define MCUXCLCSS_HASH_INIT_DISABLE 0U ///< Set this option at #mcuxClCss_HashOption_t.hashini to continue the hash
#define MCUXCLCSS_HASH_LOAD_ENABLE 1U ///< Set this option at #mcuxClCss_HashOption_t.hashld to load the hash state from @p pDigest
#define MCUXCLCSS_HASH_LOAD_DISABLE 0U ///< Set this option at #mcuxClCss_HashOption_t.hashld to not load the hash state
#define MCUXCLCSS_HASH_OUTPUT_ENABLE 1U ///< Set this option at #mcuxClCss_HashOption_t.hashoe to output the hash to @p pDigest
#define MCUXCLCSS_HASH_OUTPUT_DISABLE 0U ///< Set this option at #mcuxClCss_HashOption_t.hashoe to not output the hash
#define MCUXCLCSS_HASH_RTF_UPDATE_ENABLE 1U ///< Set this option at #mcuxClCss_HashOption_t.rtfupd to update the run-time fingerprint (only supported by #mcuxClCss_Hash_Async)
#define MCUXCLCSS_HASH_RTF_UPDATE_DISABLE 0U ///< Set this option at #mcuxClCss_HashOption_t.rtfupd to not update the run-time fingerprint
#define MCUXCLCSS_HASH_RTF_OUTPUT_ENABLE 1U ///< Set this option at #mcuxClCss_HashOption_t.rtfoe to output the run-time fingerprint (only supported by #mcuxClCss_Hash_Async)
#define MCUXCLCSS_HASH_RTF_OUTPUT_DISABLE 0U ///< Set this option at #mcuxClCss_HashOption_t.rtfoe to not output the run-time fingerprint
#define MCUXCLCSS_HASH_MODE_SHA_224 1U ///< Set this option at #mcuxClCss_HashOption_t.hashmd to use the hash algorithm SHA-224
#define MCUXCLCSS_HASH_MODE_SHA_256 0U ///< Set this option at #mcuxClCss_HashOption_t.hashmd to use the hash algorithm SHA-256
#define MCUXCLCSS_HASH_MODE_SHA_384 2U ///< Set this option at #mcuxClCss_HashOption_t.hashmd to use the hash algorithm SHA-384
#define MCUXCLCSS_HASH_MODE_SHA_512 3U ///< Set this option at #mcuxClCss_HashOption_t.hashmd to use the hash algorithm SHA-512
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_HASH_BLOCK_SIZE_ MCUXCLCSS_HASH_BLOCK_SIZE_
* @brief Defines block sizes used by the supported hash algorithms
* @ingroup mcuxClCss_Hash_Macros
* @{
*/
#define MCUXCLCSS_HASH_BLOCK_SIZE_SHA_224 64U ///< SHA-224 output size: 512 bit (64 bytes)
#define MCUXCLCSS_HASH_BLOCK_SIZE_SHA_256 64U ///< SHA-256 output size: 512 bit (64 bytes)
#define MCUXCLCSS_HASH_BLOCK_SIZE_SHA_384 128U ///< SHA-384 output size: 1024 bit (128 bytes)
#define MCUXCLCSS_HASH_BLOCK_SIZE_SHA_512 128U ///< SHA-512 output size: 1024 bit (128 bytes)
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_HASH_STATE_SIZE_ MCUXCLCSS_HASH_STATE_SIZE_
* @brief Defines the intermediate state sizes of the supported hash algorithms
* @ingroup mcuxClCss_Hash_Macros
* @{
*/
#define MCUXCLCSS_HASH_STATE_SIZE_SHA_224 32U ///< SHA-224 state size: 256 bit (32 bytes)
#define MCUXCLCSS_HASH_STATE_SIZE_SHA_256 32U ///< SHA-256 state size: 256 bit (32 bytes)
#define MCUXCLCSS_HASH_STATE_SIZE_SHA_384 64U ///< SHA-384 state size: 512 bit (64 bytes)
#define MCUXCLCSS_HASH_STATE_SIZE_SHA_512 64U ///< SHA-512 state size: 512 bit (64 bytes)
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_HASH_OUTPUT_SIZE_ MCUXCLCSS_HASH_OUTPUT_SIZE_
* @brief Defines the output sizes of the supported hash algorithms (do not use for allocation)
* @ingroup mcuxClCss_Hash_Macros
* @{
*/
#define MCUXCLCSS_HASH_OUTPUT_SIZE_SHA_224 28U ///< SHA-224 output size: 224 bit (28 bytes)
#define MCUXCLCSS_HASH_OUTPUT_SIZE_SHA_256 32U ///< SHA-256 output size: 256 bit (32 bytes)
#define MCUXCLCSS_HASH_OUTPUT_SIZE_SHA_384 48U ///< SHA-384 output size: 384 bit (48 bytes)
#define MCUXCLCSS_HASH_OUTPUT_SIZE_SHA_512 64U ///< SHA-512 output size: 512 bit (64 bytes)
/**
* @}
*/
/**
* @ingroup mcuxClCss_Hash_Macros
* @{
*/
#define MCUXCLCSS_HASH_RTF_OUTPUT_SIZE ((size_t)32U) ///< Size of run-time fingerprint appended to the hash in @p pDigest in bytes, if #MCUXCLCSS_HASH_RTF_OUTPUT_ENABLE was specified
/**
* @}
*
* @}
*/
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_Hash_Types mcuxClCss_Hash_Types
* @brief Defines all types of @ref mcuxClCss_Hash
* @ingroup mcuxClCss_Hash
* @{
*/
/**
* @brief Command option bit field for #mcuxClCss_Hash_Async and #mcuxClCss_Hash_ShaDirect.
*
* Bit field to configure #mcuxClCss_Hash_Async and #mcuxClCss_Hash_ShaDirect. See @ref MCUXCLCSS_HASH_ for possible options.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_HashOption_t word-wise
struct
{
uint32_t :2; ///< RFU
uint32_t hashini :1; ///< Defines if the hash engine shall be initialized
uint32_t hashld :1; ///< Defines if the hash engine shall be initialized with an externally provided digest
uint32_t hashmd :2; ///< Defines which hash algorithm shall be used
uint32_t hashoe :1; ///< Defines if the hash digest shall be moved to the output buffer
uint32_t rtfupd :1; ///< RTF (Runtime Fingerprint) Update
uint32_t rtfoe :1; ///< RTF (Runtime Fingerprint) Output Enabled
uint32_t :23; ///< RFU
} bits; ///< Access #mcuxClCss_HashOption_t bit-wise
} mcuxClCss_HashOption_t;
/**
* @}
*/
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_Hash_Functions mcuxClCss_Hash_Functions
* @brief Defines all functions of @ref mcuxClCss_Hash
* @ingroup mcuxClCss_Hash
* @{
*/
/**
* @brief Computes the hash of a message.
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
* It must be ensured that SHA-Direct mode is disabled when calling this function (see #mcuxClCss_ShaDirect_Disable).
*
* @param[in] options The command options. For more information, see #mcuxClCss_HashOption_t.
* @param[in] pInput Padded input data to be hashed
* @param[in] inputLength Size of @p pInput in bytes. Since the input is padded, the length must be a multiple of the block size, see @ref MCUXCLCSS_HASH_BLOCK_SIZE_.
* @param[in, out] pDigest Pointer to the memory area that contains/receives the (intermediate) hash digest, allocated by the caller, see @ref MCUXCLCSS_HASH_STATE_SIZE_.
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.hashini == #MCUXCLCSS_HASH_INIT_ENABLE</dt>
* <dd>@p options.hashld has no effect and shall be #MCUXCLCSS_HASH_LOAD_DISABLE. No data is read from @p pDigest.</dd>
*
* <dt>@p options.hashld == #MCUXCLCSS_HASH_LOAD_DISABLE</dt>
* <dd>@p pDigest is not expected to contain an initial state. No data is read from @p pDigest.</dd>
*
* <dt>@p options.rtfoe == #MCUXCLCSS_HASH_RTF_UPDATE_ENABLE</dt>
* <dd>When this option is used the current runtime fingerprint (RTF) value will be appended to the output @p pDigest; an additional #MCUXCLCSS_HASH_RTF_OUTPUT_SIZE bytes has to be allocated for @p pDigest.</dd>
*
* <dt>@p options.hashoe == #MCUXCLCSS_HASH_OUTPUT_ENABLE</dt>
* <dd>The hash state is written to @p pDigest. The size varies depending on the choice of @p options.hashmd, for more information see @ref MCUXCLCSS_HASH_STATE_SIZE_ . In cases where the state size and output size differ - see @ref MCUXCLCSS_HASH_OUTPUT_SIZE_ -, the state must be truncated by the caller to obtain the final hash value.</dd>
*
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Hash_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hash_Async(
mcuxClCss_HashOption_t options,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pDigest
);
/**
* @brief Enables SHA-direct mode.
*
* If this mode is enabled, it allows the application processor to access the CSS hash
* engine, but at the same time it stops CSS operations from using the hash engine.
*
* Therefore, in SHA-direct mode, hashing can only be done with #mcuxClCss_Hash_ShaDirect.
* When SHA-direct mode is active, CSS operations which internally use the CSS hash engine
* will result in an operational error (see #MCUXCLCSS_STATUS_HW_OPERATIONAL). To use those
* operations, disable SHA-direct mode. Please consult function descriptions to check
* whether and under which circumstances they internally use the CSS hash engine.
*
* CSS operations which do not internally use the CSS hash engine can be performed in
* parallel with a SHA-direct hash operation.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection)
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK on success
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_ShaDirect_Enable)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_ShaDirect_Enable(
void);
/**
* @brief Disables SHA-direct mode.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK on success
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_ShaDirect_Disable)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_ShaDirect_Disable(
void);
/**
* @brief Calculates the hash of a message using SHA-Direct mode.
*
* SHA-Direct mode must be enabled before calling this function. For more information, see #mcuxClCss_ShaDirect_Enable.
*
* In order to perform a hash calculation in SHA-Direct mode, the CPU must feed the input data to a register in CSSv2's SHA core, or configure a DMA to copy the input data to that register. A DMA can be used because feeding input data to the SHA core while the SHA core is busy results in an AHB bus stall, and there is no need to check any further flags before copying further data.
* If a DMA shall be used to perform this copy, a callback function must be provided by the caller that will configure and start the DMA.
* If no callback function is specified, this function will resort to using the CPU.
*
* @param[in] options The command options. For more information, see #mcuxClCss_HashOption_t.
* @param[in] pInput Padded input data to be hashed.
* @param[in] inputLength Size of @p pInput in bytes. Since the input is padded, the length must be a multiple of the block size, see @ref MCUXCLCSS_HASH_BLOCK_SIZE_.
* @param[in, out] pDigest Pointer to the memory area that contains/receives the (intermediate) hash digest, allocated by the caller, see @ref MCUXCLCSS_HASH_STATE_SIZE_.
* @param[in] pCallback Callback function to load data into Sha core.
* @param[in, out] pCallerData Pointer forwarded by the operation to the callback function.
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.hashini == #MCUXCLCSS_HASH_INIT_ENABLE</dt>
* <dd>@p options.hashld has no effect and shall be #MCUXCLCSS_HASH_LOAD_DISABLE. No data is read from @p pDigest. </dd>
*
* <dt>@p options.hashld == #MCUXCLCSS_HASH_LOAD_DISABLE</dt>
* <dd>@p pDigest is not expected to contain an initial state. No data is read from @p pDigest. </dd>
*
* <dt>@p options.hashoe == #MCUXCLCSS_HASH_OUTPUT_ENABLE</dt>
* <dd>The hash state is written to @p pDigest. The size varies depending on the choice of @p options.hashmd, for more information see @ref MCUXCLCSS_HASH_STATE_SIZE_ . In cases where the state size and output size differ - see @ref MCUXCLCSS_HASH_OUTPUT_SIZE_ -, the state must be truncated by the caller to obtain the final hash value.</dd>
*
* <dt>@p pCallback != @c NULL </dt>
* <dd>The callback function referenced by @p pCallback is called. Otherwise, the function uses a default implementation for the copy.</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_SW_FAULT if the callback returned an error
* @retval #MCUXCLCSS_STATUS_OK on success
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Hash_ShaDirect)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hash_ShaDirect(
mcuxClCss_HashOption_t options,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pDigest,
mcuxClCss_TransferToRegisterFunction_t pCallback,
void * pCallerData
);
#endif /* MCUXCLCSS_HASH_H_ */
/**
* @}
*
* @}
*/

View File

@ -1,156 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Hmac.h
* @brief CSSv2 header for HMAC support.
*
* This header exposes functions that enable using the CSSv2 for the generation of hashed-key message authentication
* codes (HMAC).
* The supported hash algorithm is SHA2-256.
*/
/**
* @defgroup mcuxClCss_Hmac mcuxClCss_Hmac
* @brief This part of the @ref mcuxClCss driver supports functionality for hashed-key message authentication codes.
* @ingroup mcuxClCss
* @{
*/
#ifndef MCUXCLCSS_HMAC_H_
#define MCUXCLCSS_HMAC_H_
#include <mcuxClCss_Common.h> // Common functionality
/**********************************************
* MACROS
**********************************************/
/**
* @defgroup mcuxClCss_Hmac_Macros mcuxClCss_Hmac_Macros
* @brief Defines all macros of @ref mcuxClCss_Hmac
* @ingroup mcuxClCss_Hmac
* @{
*/
/**
* @defgroup MCUXCLCSS_HMAC_EXTERNAL_KEY_ MCUXCLCSS_HMAC_EXTERNAL_KEY_
* @brief Defines valid options to be used by #mcuxClCss_HmacOption_t
* @ingroup mcuxClCss_Hmac_Macros
* @{
*/
#define MCUXCLCSS_HMAC_EXTERNAL_KEY_ENABLE 1U ///< Set #mcuxClCss_HmacOption_t.extkey to this value to use an external key
#define MCUXCLCSS_HMAC_EXTERNAL_KEY_DISABLE 0U ///< Set #mcuxClCss_HmacOption_t.extkey to this value to use a key from the CSSv2 keystore
/**
* @}
*/
#define MCUXCLCSS_HMAC_PADDED_KEY_SIZE ((size_t) 64U) ///< HMAC Key size: 64 bytes
#define MCUXCLCSS_HMAC_OUTPUT_SIZE ((size_t) 32U) ///< HMAC Output size: 32 bytes
/**
* @}
*/
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_Hmac_Types mcuxClCss_Hmac_Types
* @brief Defines all types of @ref mcuxClCss_Hmac
* @ingroup mcuxClCss_Hmac
* @{
*/
/**
* @brief Command option bit field for #mcuxClCss_Hmac_Async.
*
* Valid option values can be found under @ref MCUXCLCSS_HMAC_EXTERNAL_KEY_.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word
} word; ///< Access #mcuxClCss_CipherOption_t word-wise
struct
{
uint32_t :13; ///< RFU
uint32_t extkey :1; ///< Whether an external key should be used
uint32_t :18; ///< RFU
} bits; ///< Access #mcuxClCss_CipherOption_t word-wise
} mcuxClCss_HmacOption_t;
/**
* @}
*/
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_Hmac_Functions mcuxClCss_Hmac_Functions
* @brief Defines all functions of @ref mcuxClCss_Hmac
* @ingroup mcuxClCss_Hmac
* @{
*/
/**
* @brief Performs HMAC with SHA-256.
*
* It must be ensured that SHA-Direct mode is disabled when calling this function (see #mcuxClCss_ShaDirect_Disable).
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options The command options. For more information, see #mcuxClCss_HmacOption_t.
* @param[in] keyIdx The HMAC key index, if an internal key shall be used
* @param[in] pPaddedKey Pointer to a memory location containing the padded HMAC key
* @param[in] pInput Pointer to a memory location which contains the data to be authenticated
* @param[in] inputLength Size of @p pInput in bytes
* @param [out] pOutput The output message authentication code
*
* The properties of some parameters change with respect to selected options.
*
* <dl>
* <dt>Parameter properties</dt>
*
* <dd><dl>
* <dt>@p options.extkey == #MCUXCLCSS_HMAC_EXTERNAL_KEY_ENABLE</dt>
* <dd>@p keyIdx is ignored.
*
* @p pPaddedKey must contain the padded HMAC key, which can mean one of two things depending on the length of the original HMAC key, L<sub>kHMAC</sub>:
* <ul><li>If L<sub>kHMAC</sub> &le; #MCUXCLCSS_HMAC_PADDED_KEY_SIZE, @p pPaddedKey must be the HMAC key padded with zero-bytes to fill the required length of #MCUXCLCSS_HMAC_PADDED_KEY_SIZE bytes.</li>
*
* <li>If L<sub>kHMAC</sub> &gt; #MCUXCLCSS_HMAC_PADDED_KEY_SIZE, @p pPaddedKey must contain the SHA-256 hash of the HMAC key, padded with zero-bytes to fill the required length of #MCUXCLCSS_HMAC_PADDED_KEY_SIZE bytes.</li></ul></dd>
*
* <dt>@p options.extkey == #MCUXCLCSS_HMAC_EXTERNAL_KEY_DISABLE</dt>
* <dd>@p keyIdx must be a valid key index with the correct usage rights for HMAC.
*
* @p pPaddedKey is ignored.</dd>
*
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if an invalid parameter was specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Hmac_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hmac_Async(
mcuxClCss_HmacOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pPaddedKey,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pOutput
);
#endif /* MCUXCLCSS_HMAC_H_ */
/**
* @}
*
* @}
*/

View File

@ -1,304 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/// @file mcuxClCss_Kdf.h
/// @brief CSSv2 header for key derivation.
/// This header exposes functions that enable using the CSSv2 for various key derivation commands.
/// The supported key derivation algorithms are:
/// <ul>
/**
* @file mcuxClCss_Kdf.h
* @brief CSSv2 header for key derivation.
*
* This header exposes functions that enable using the CSSv2 for various key derivation commands.
* The supported key derivation algorithms are CKDF, HKDF, TLS
*/
/**
* @defgroup mcuxClCss_Kdf mcuxClCss_Kdf
* @brief This part of the @ref mcuxClCss driver supports functionality for key derivation
* @ingroup mcuxClCss
* @{
*/
/**
* @defgroup mcuxClCss_Kdf_Macros mcuxClCss_Kdf_Macros
* @brief Defines all macros of @ref mcuxClCss_Kdf
* @ingroup mcuxClCss_Kdf
* @{
*/
#ifndef MCUXCLCSS_KDF_H_
#define MCUXCLCSS_KDF_H_
#include <mcuxClCss_Common.h> // Common functionality
/**********************************************
* CONSTANTS
**********************************************/
/**
* @defgroup mcuxClCss_Kdf_Define mcuxClCss_Kdf_Define
* @brief constants
* @ingroup mcuxClCss_Kdf_Macros
* @{
*/
#define MCUXCLCSS_HKDF_VALUE_RTF_DERIV ((uint32_t) 1u<< 0u) ///< Use RTF as derivation input
#define MCUXCLCSS_HKDF_VALUE_MEMORY_DERIV ((uint32_t) 0u<< 0u) ///< Use derivation input from system memory
#define MCUXCLCSS_CKDF_RTF_DERIV 1U ///< Use RTF as derivation input
#define MCUXCLCSS_CKDF_SYSTEM_MEMORY_DERIV 0U ///< Use derivation input from system memory
#define MCUXCLCSS_CKDF_DERIVATIONDATA_SIZE 12u ///< Size of CKDF derivation data
#define MCUXCLCSS_CKDF_ALGO_SP800108 0x0u ///< Use SP800-108 algorithm
#define MCUXCLCSS_HKDF_RFC5869_DERIVATIONDATA_SIZE 32u ///< Size of HKDF derivation data
#define MCUXCLCSS_HKDF_SP80056C_TARGETKEY_SIZE 32u ///< Size of HKDF SP800-56C derived key
#define MCUXCLCSS_HKDF_ALGO_RFC5869 0x0u ///< Use RFC5869 algorithm
#define MCUXCLCSS_HKDF_ALGO_SP80056C 0x1u ///< Use SP800-56C algorithm
#define MCUXCLCSS_TLS_DERIVATIONDATA_SIZE ((size_t) 80u) ///< Size of TLS derivation data
#define MCUXCLCSS_TLS_RANDOM_SIZE ((size_t) 32u) ///< Size of random bytes for TLS
#define MCUXCLCSS_TLS_INIT 0u ///< Perform master key generation
#define MCUXCLCSS_TLS_FINALIZE 1u ///< Perform session key generation
/**
* @}
*/ /* MCUXCLCSS_KDF_DEFINE */
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_Kdf_Types mcuxClCss_Kdf_Types
* @brief Defines all types of @ref mcuxClCss_Kdf
* @ingroup mcuxClCss_Kdf
* @{
*/
/** Internal command option bit field for CKDF functions. */
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word; initialize with a combination of constants from @ref MCUXCLCSS_HKDF_VALUE_
} word;
struct
{
uint32_t :12;
uint32_t ckdf_algo :2; ///< Defines which algorithm and mode shall be used. This option is set internally and will be ignored:
///< #MCUXCLCSS_CKDF_ALGO_SP800108 = Use SP800-108 algorithm
uint32_t :18;
} bits;
} mcuxClCss_CkdfOption_t;
/** Command option bit field for #mcuxClCss_Hkdf_Rfc5869_Async. */
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word; initialize with a combination of constants from @ref MCUXCLCSS_HKDF_VALUE_
} word;
struct
{
uint32_t rtfdrvdat :1; ///< #MCUXCLCSS_CKDF_SYSTEM_MEMORY_DERIV=use derivation input from system memory, #MCUXCLCSS_CKDF_RTF_DERIV=use RTF (runtime fingerprint) as derivation input
uint32_t hkdf_algo :1; ///< Defines which algorithm shall be used. This option is set internally and will be ignored:
///< #MCUXCLCSS_HKDF_ALGO_RFC5869 = Use RFC5869 algorithm
///< #MCUXCLCSS_HKDF_ALGO_SP80056C = Use SP800-56C algorithm
uint32_t :30;
} bits;
} mcuxClCss_HkdfOption_t;
/** Internal command option bit field for #mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async, and #mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async. */
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word; initialize with a combination of constants from @ref MCUXCLCSS_HKDF_VALUE_
} word;
struct
{
uint32_t :10;
uint32_t mode :1; ///< Defines which phase of the key generation is performed. This option is set internally and will be ignored:
///< #MCUXCLCSS_TLS_INIT = Calculate master key from premaster key
///< #MCUXCLCSS_TLS_FINALIZE = Calculate session keys from master key
uint32_t :21;
} bits;
} mcuxClCss_TlsOption_t;
/**
* @}
*/ /* mcuxClCss_Kdf_Types */
/**
* @}
*/ /* mcuxClCss_Kdf_Macros */
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_Kdf_Functions mcuxClCss_Kdf_Functions
* @brief Defines all functions of @ref mcuxClCss_Kdf
* @ingroup mcuxClCss_Kdf
* @{
*/
/**
* @brief Derives a key using the HKDF (HMAC-based key derivation function) according to RFC5869.
* It must be ensured that SHA-Direct mode is disabled when calling this function (see #mcuxClCss_ShaDirect_Disable).
* Call #mcuxClCss_WaitForOperation to complete the operation.
* @param[in] options The command options. For more information, see #mcuxClCss_HkdfOption_t.
* @param[in] derivationKeyIdx Key index used for derivation. Must be a 256-bit key with HKDF property bit set to 1.
* @param[in] targetKeyIdx Key bank number of the derived key. Will be a 256-bit key, the user must ensure there is enough space in the keystore to hold the derived key.
* @param[in] targetKeyProperties Requested properties for the derived key. The ksize field will be ignored.
* @param[in] pDerivationData The algorithm-specific derivation data, the length is #MCUXCLCSS_HKDF_RFC5869_DERIVATIONDATA_SIZE bytes
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
*
*
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Hkdf_Rfc5869_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hkdf_Rfc5869_Async(
mcuxClCss_HkdfOption_t options,
mcuxClCss_KeyIndex_t derivationKeyIdx,
mcuxClCss_KeyIndex_t targetKeyIdx,
mcuxClCss_KeyProp_t targetKeyProperties,
uint8_t const * pDerivationData
);
/** Derives a key using the HKDF (HMAC-based key derivation function) according to SP800-56C one-step approach with Sha2-256.
* It must be ensured that SHA-Direct mode is disabled when calling this function (see #mcuxClCss_ShaDirect_Disable).
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] derivationKeyIdx Key index used for derivation. Must be a 256-bit key with HKDF property bit set to 1.
* @param[out] pTagetKey Memory area to store the derived key. Will be a 256-bit key, the user must ensure there is enough space in the keystore to hold the derived key.
* @param[in] pDerivationData The algorithm-specific derivation data
* @param[in] derivationDataLength Length of the derivation data
*
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Hkdf_Sp80056c_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hkdf_Sp80056c_Async(
mcuxClCss_KeyIndex_t derivationKeyIdx,
uint8_t * pTagetKey,
uint8_t const * pDerivationData,
size_t derivationDataLength
);
/** Derives a key using the NIST SP 800-108 CMAC-based Extract-and-Expand Key Derivation Function.
*
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] derivationKeyIdx Key index used for derivation
* @param[in] targetKeyIdx Key bank number of the derived key
* @param[in] targetKeyProperties Requested properties for the derived key. Only set usage bits.
* @param[in] pDerivationData The algorithm-specific derivation data, the length is #MCUXCLCSS_CKDF_DERIVATIONDATA_SIZE bytes
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Ckdf_Sp800108_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Ckdf_Sp800108_Async(
mcuxClCss_KeyIndex_t derivationKeyIdx,
mcuxClCss_KeyIndex_t targetKeyIdx,
mcuxClCss_KeyProp_t targetKeyProperties,
uint8_t const * pDerivationData
);
/** Generates a TLS master key based on a pre-master key and derivation data, according to the TLS 1.2 specification.
* The pre-master key is overwritten in this operation.
* It must be ensured that SHA-Direct mode is disabled when calling this function (see #mcuxClCss_ShaDirect_Disable).
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] pDerivationData The TLS derivation data, consisting of Label, Client Random and Server Random from the TLS 1.2 specification.
* Note: The order is different from #mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async.
* @param[in] keyProperties Desired key properties. Only #mcuxClCss_KeyProp_t::upprot_priv and #mcuxClCss_KeyProp_t::upprot_sec are used, the rest are ignored.
* @param[in] keyIdx The index of the TLS pre-master key, which is overwritten with the master key
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async(
uint8_t const * pDerivationData,
mcuxClCss_KeyProp_t keyProperties,
mcuxClCss_KeyIndex_t keyIdx
);
/** Generates TLS session keys based on a master key and derivation data, according to the TLS 1.2 specification.
* The master key and the following five key indices are overwritten in this operation.
* The keys are written in the following order:
* <ol>
* <li> Client Encryption Key
* <li> Client Message Authentication Key
* <li> Server Encryption Key
* <li> Server Message Authentication Key
* </ol>
* It must be ensured that SHA-Direct mode is disabled when calling this function (see #mcuxClCss_ShaDirect_Disable).
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] pDerivationData The TLS derivation data, consisting of Label, Server Random and Client Random from the TLS 1.2 specification.
* Note: The order is different from #mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async.
* @param[in] keyProperties Desired key properties. Only #mcuxClCss_KeyProp_t::upprot_priv and #mcuxClCss_KeyProp_t::upprot_sec are used, the rest are ignored.
* @param[in] keyIdx The index of the TLS master key, which is overwritten with one of the session keys.
* There must be three further consecutive unoccupied key indices following this index.
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async(
uint8_t const * pDerivationData,
mcuxClCss_KeyProp_t keyProperties,
mcuxClCss_KeyIndex_t keyIdx
);
/**
* @}
*/ /* mcuxClCss_Kdf_Functions */
/**
* @}
*/ /* mcuxClCss_Kdf */
#endif /* MCUXCLCSS_KDF_H_ */

View File

@ -1,245 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_KeyManagement.h
* @brief CSSv2 header for key management.
*
* This header exposes functions that can be used to manage the keystore of CSSv2.
* This includes:
* - Importing keys
* - Exporting keys
* - Deleting keys
*/
/**
* @defgroup mcuxClCss_KeyManagement mcuxClCss_KeyManagement
* @brief This part of the @ref mcuxClCss driver supports functionality for keys management
* @ingroup mcuxClCss
* @{
*/
#ifndef MCUXCLCSS_KEYMANAGEMENT_H_
#define MCUXCLCSS_KEYMANAGEMENT_H_
#include <mcuxClCss_Common.h> // Common functionality
/**********************************************
* CONSTANTS
**********************************************/
/**
* @defgroup mcuxClCss_KeyManagement_Macros mcuxClCss_KeyManagement_Macros
* @brief Defines all macros of @ref mcuxClCss_KeyManagement
* @ingroup mcuxClCss_KeyManagement
* @{
*/
/**
* @defgroup MCUXCLCSS_KEYIMPORT_VALUE_KFMT_ MCUXCLCSS_KEYIMPORT_VALUE_KFMT_
* @brief Defines valid options (word value) to be used by #mcuxClCss_KeyImport_Async
* @ingroup mcuxClCss_KeyManagement_Macros
*
* @{
*/
#define MCUXCLCSS_KEYIMPORT_VALUE_KFMT_UDF ((uint32_t) 0u<< 6u) ///< Key format UDF with shares in RTL or memory
#define MCUXCLCSS_KEYIMPORT_VALUE_KFMT_RFC3394 ((uint32_t) 1u<< 6u) ///< Key format RFC3394 with shares in memory
#define MCUXCLCSS_KEYIMPORT_VALUE_KFMT_PUF ((uint32_t) 2u<< 6u) ///< Key from PUF
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_KEYIMPORT_KFMT_ MCUXCLCSS_KEYIMPORT_KFMT_
* @brief Defines valid options (bit values) to be used by #mcuxClCss_KeyImport_Async
* @ingroup mcuxClCss_KeyManagement_Macros
*
* @{
*/
#define MCUXCLCSS_KEYIMPORT_KFMT_UDF ((uint32_t) 0x00u) ///< Key format UDF with shares in RTL or memory
#define MCUXCLCSS_KEYIMPORT_KFMT_RFC3394 ((uint32_t) 0x01u) ///< Key format RFC3394 with shares in memory
#define MCUXCLCSS_KEYIMPORT_KFMT_PUF ((uint32_t) 0x02u) ///< Key from PUF
#define MCUXCLCSS_RFC3394_OVERHEAD ((size_t) 16u) ///< Overhead between RFC3394 blob and key size
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_RFC3394_ MCUXCLCSS_RFC3394_
* @brief Defines specifying the length of RFC3394 containers
* @ingroup mcuxClCss_KeyManagement_Macros
*
* @{
*/
#define MCUXCLCSS_RFC3394_CONTAINER_SIZE_128 ((size_t) 256u/8u) ///< Size of RFC3394 container for 128 bit key
#define MCUXCLCSS_RFC3394_CONTAINER_SIZE_256 ((size_t) 384u/8u) ///< Size of RFC3394 container for 256 bit key
/**
* @}
*/
/**
* @}
*/
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_KeyManagement_Types mcuxClCss_KeyManagement_Types
* @brief Defines all types of @ref mcuxClCss_KeyManagement
* @ingroup mcuxClCss_KeyManagement
* @{
*/
/**
* @brief Command option bit field for #mcuxClCss_KeyImport_Async
*
* Bit field to configure #mcuxClCss_KeyImport_Async.
* See @ref MCUXCLCSS_KEYIMPORT_KFMT_ for possible options in case the struct is accessed bit-wise.
* See @ref MCUXCLCSS_KEYIMPORT_VALUE_KFMT_ for possible options in case the struct is accessed word-wise.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word; initialize with a combination of constants from @ref MCUXCLCSS_KEYIMPORT_VALUE_KFMT_
} word; ///< Access #mcuxClCss_KeyImportOption_t word-wise
struct
{
uint32_t :4; ///< RFU
uint32_t revf :1; ///< This field is managed internally
uint32_t :1; ///< RFU
uint32_t kfmt :2; ///< Defines the key import format, one of @ref MCUXCLCSS_KEYIMPORT_KFMT_
uint32_t :24; ///< RFU
} bits; ///< Access #mcuxClCss_KeyImportOption_t bit-wise
} mcuxClCss_KeyImportOption_t;
/**
* @}
*/
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_KeyManagement_Functions mcuxClCss_KeyManagement_Functions
* @brief Defines all functions of @ref mcuxClCss_KeyManagement
* @ingroup mcuxClCss_KeyManagement
* @{
*/
/**
* @brief Deletes a key from keystore at the given index.
*
* Before execution, CSS will wait until #mcuxClCss_HwState_t.drbgentlvl == #MCUXCLCSS_STATUS_DRBGENTLVL_LOW. This can lead to a delay if the DRBG is in a state with less security strength at the time of the call.
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] keyIdx The index of the key to be deleted
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_KeyDelete_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_KeyDelete_Async(
mcuxClCss_KeyIndex_t keyIdx
);
/** @brief Imports a key from external storage to an internal key register.
*
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] options One of @ref MCUXCLCSS_KEYIMPORT_KFMT_
* @param[in] pImportKey Pointer to the RFC3394 container of the key to be imported
* @param[in] importKeyLength Length of the RFC3394 container of the key to be imported
* @param[in] wrappingKeyIdx Index of the key wrapping key, if importing RFC3394 format
* @param[in] targetKeyIdx The desired key index of the imported key
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>@p options.kfmt != #MCUXCLCSS_KEYIMPORT_KFMT_RFC3394</dt><dd>
* <ul style="list-style: none;">
* <li>@p pImportKey is ignored.</li>
* <li>@p importKeyLength is ignored.</li>
* <li>@p wrappingKeyIdx is ignored.</li>
* <li>@p targetKeyIdx is ignored. The unpacked key is automatically stored in key slots 0, 1.</li>
* </ul></dd>
* </dt>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_KeyImport_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_KeyImport_Async(
mcuxClCss_KeyImportOption_t options,
uint8_t const * pImportKey,
size_t importKeyLength,
mcuxClCss_KeyIndex_t wrappingKeyIdx,
mcuxClCss_KeyIndex_t targetKeyIdx
);
/** @brief Exports a key from an internal key register to external storage, using a wrapping key.
*
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] wrappingKeyIdx The key used for key wrapping
* @param[in] exportKeyIdx The key to export
* @param[out] pOutput The memory address of the exported key
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_KeyExport_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_KeyExport_Async(
mcuxClCss_KeyIndex_t wrappingKeyIdx, ///< [in] The key used for key wrapping
mcuxClCss_KeyIndex_t exportKeyIdx, ///< [in] The key to export
uint8_t * pOutput ///< [out] The memory address of the exported key
);
/** @brief Exports the properties of the keys stored in the CSS internal keystore
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[in] keyIdx Request key properties of the index defined here
* @param[out] pKeyProp Key properties of the index provided
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK on successful request */
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_GetKeyProperties)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetKeyProperties(
mcuxClCss_KeyIndex_t keyIdx,
mcuxClCss_KeyProp_t * pKeyProp
);
/**
* @}
*/
#endif /* MCUXCLCSS_KEYMANAGEMENT_H_ */
/**
* @}
*/

View File

@ -1,316 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Rng.h
* @brief CSSv2 header for random number generation.
* This header exposes functions to configure the CSSv2 RNGs (DRBG and DTRNG) and to generate random data.
*/
#ifndef MCUXCLCSS_RNG_H_
#define MCUXCLCSS_RNG_H_
#include <mcuxClCss_Common.h> // Common functionality
/**
* @defgroup mcuxClCss_Rng mcuxClCss_Rng
* @brief This part of the @ref mcuxClCss driver supports functionality for random number generation
* @ingroup mcuxClCss
* @{
*/
/**********************************************
* CONSTANTS
**********************************************/
/**
* @defgroup mcuxClCss_Rng_Macros mcuxClCss_Rng_Macros
* @brief Defines all macros of @ref mcuxClCss_Rng
* @ingroup mcuxClCss_Rng
* @{
*/
#define MCUXCLCSS_RNG_DTRNG_CONFIG_SIZE ((uint8_t) 84) ///< Size of DTRNG configuration
#define MCUXCLCSS_RNG_DTRNG_EVAL_CONFIG_SIZE ((uint8_t) 52) ///< Size of DTRNG characterization data
#define MCUXCLCSS_RNG_DTRNG_EVAL_RESULT_SIZE ((uint8_t) 188) ///< Size of DTRNG characterization result
#define MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MIN_SIZE 4U ///< Minimum output size of #mcuxClCss_Rng_DrbgTestExtract_Async
#define MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MAX_SIZE ((uint32_t) 1U << 16U) ///< Maximum output size of #mcuxClCss_Rng_DrbgTestExtract_Async
/**
* @}
*/
/**********************************************
* FUNCTIONS
**********************************************/
/**
* @defgroup mcuxClCss_Rng_Functions mcuxClCss_Rng_Functions
* @brief Defines all functions of @ref mcuxClCss_Rng
* @ingroup mcuxClCss_Rng
* @{
*/
/**
* @brief Writes random data from the CSS DRBG to the given buffer.
*
* This function fills a buffer with random values from the DRBG. The DRBG provides 128 bits of security strength.
*
* Before execution, CSS will wait until #mcuxClCss_HwState_t.drbgentlvl == #MCUXCLCSS_STATUS_DRBGENTLVL_HIGH. This can lead to a delay if the DRBG is in a state with less security strength at the time of the call.
*
* If the random values from the DRBG are later used as a cryptographic key, the security strength of the cryptographic operation using the generated key should not exceed that of the DRBG.
*
* To name a few examples, this means (as per NIST SP 800-57 Part 1 Rev. 5):
* - AES-192 or AES-256 keys generated with this function will provide only 128 bits of security strength
* - RSA keys longer than 3072 bits will provide only 128 bits of security strength
* - ECC keys longer than 383 bits will provide only 128 bits of security strength
*
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @param[out] pOutput Pointer to the beginning of the memory area to fill with random data
* @param[in] outputLength Number of requested random bytes
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>@p outputLength </dt>
* <dd>supported values are #MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MIN_SIZE bytes up to
* #MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MAX_SIZE bytes. The size must be a multiple of 4.</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Rng_DrbgRequest_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgRequest_Async(
uint8_t * pOutput,
size_t outputLength
);
/**
* @brief Instantiates the DRBG in test mode.
*
* This function is a support function for FIPS CAVP testing. This function turns the CSS internal DRBG in test mode by loading known entropy from system memory.
* Call #mcuxClCss_WaitForOperation to complete the operation.
* Note that this function will alter the CSS internal entropy state which needs to be updated by the TRNG to use the DRBG in normal mode.
* The update process is majorly impacted by the time the TRNG needs to provide fresh entropy.
*
* @param[in] pEntropy Pointer to the input entropy data
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Rng_DrbgTestInstantiate_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgTestInstantiate_Async(
uint8_t const * pEntropy
);
/**
* @brief Performs a DRBG extraction.
*
* This function is a support function for FIPS CAVP testing. This function mimics the behavior of #mcuxClCss_Rng_DrbgRequest_Async and fills a buffer with random data when DRBG is in test mode.
* Call #mcuxClCss_WaitForOperation to complete the operation.
* Note that this function will alter the CSS internal entropy state which needs to be updated by the TRNG to use the DRBG in normal mode.
* The update process is majorly impacted by the time the TRNG needs to provide fresh entropy.
*
* @attention #mcuxClCss_Rng_DrbgTestInstantiate_Async must be called prior to this function.
*
* @param[out] pOutput Pointer to the output random number
* @param[in] outputLength Length of the random number
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>@p outputLength </dt>
* <dd>supported values are #MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MIN_SIZE bytes up to
* #MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MAX_SIZE bytes. The size must be a multiple of 4.</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref MCUXCLCSS_STATUS_ and @ref mcuxCsslFlowProtection)
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Rng_DrbgTestExtract_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgTestExtract_Async(
uint8_t * pOutput,
size_t outputLength
);
/**
* @brief Encrypts data using the AES-ECB engine of the DRBG.
*
* This function is a support function for FIPS CAVP testing. This function performs an AES-ECB encryption on system data to evaluate the encryption engine of the DRBG.
* Call #mcuxClCss_WaitForOperation to complete the operation.
* Note that this function will alter the CSS internal entropy state which needs to be updated by the TRNG to use the DRBG in normal mode.
* The update process is majorly impacted by the time the TRNG needs to provide fresh entropy.
*
* @param[in] pDataKey Pointer to the data and key
* @param[out] pOutput Pointer to the encrypted output
*
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Rng_DrbgTestAesEcb_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgTestAesEcb_Async(
uint8_t const * pDataKey,
uint8_t * pOutput
);
/**
* @brief Encrypts data using the AES-CTR engine of the DRBG.
*
* This function is a support function for FIPS CAVP testing. This function performs an AES-CTR encryption on system data to evaluate the encryption engine of the DRBG in test mode.
* Call #mcuxClCss_WaitForOperation to complete the operation.
* Note that this function will alter the CSS internal entropy state which needs to be updated by the TRNG to use the DRBG in normal mode.
* The update process is majorly impacted by the time the TRNG needs to provide fresh entropy.
*
* @param[in] pData Pointer to the data to be encrypted
* @param[in] dataLength Length of the data to be encrypted
* @param[in] pIvKey Pointer to the IV and key
* @param[out] pOutput Pointer to the encrypted output
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Rng_DrbgTestAesCtr_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgTestAesCtr_Async(
uint8_t const * pData,
size_t dataLength,
uint8_t const * pIvKey,
uint8_t * pOutput
);
/**
* @brief Loads a configuration of the CSS DTRNG.
*
* This function overwrites the default DTRNG configuration in order to optimize or fine tune the DTRNG entropy gathering process.
* Call #mcuxClCss_WaitForOperation to complete the operation.
* Note that the TRNG configuration set by this function is non-persistent and any reset of the Css (e.g. a power-cycle or calling #mcuxClCss_Reset_Async) will resets the DTRNG configuration to its default value.
*
* It must be ensured that SHA-Direct mode is disabled when calling this function (see #mcuxClCss_ShaDirect_Disable).
*
* @param[in] pInput The pointer to DTRNG initialization data
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>@p pInput </dt>
* <dd>The size is #MCUXCLCSS_RNG_DTRNG_CONFIG_SIZE bytes.</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Rng_Dtrng_ConfigLoad_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_Dtrng_ConfigLoad_Async(
uint8_t const * pInput
);
/**
* @brief Performs characterization of the CSS DTRNG.
*
* This function evaluates a DTRNG configuration for device specific characterization. The configuration used for characterization has to be placed in system memory.
* Call #mcuxClCss_WaitForOperation to complete the operation.
*
* @attention If this function is called once, all other CSS commands except #mcuxClCss_Rng_Dtrng_ConfigEvaluate_Async are blocked until any reset of the Css (e.g. a power-cycle or calling #mcuxClCss_Reset_Async) is triggered.
*
* @param[in] pInput The pointer to DTRNG initialization data
* @param[out] pOutput The pointer to the evaluation result
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>@p pInput </dt>
* <dd>The size is #MCUXCLCSS_RNG_DTRNG_EVAL_CONFIG_SIZE bytes.</dd>
* <dt>@p pOutput </dt>
* <dd>The size is #MCUXCLCSS_RNG_DTRNG_EVAL_RESULT_SIZE bytes.</dd>
* </dl></dd>
* </dl>
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_SW_INVALID_PARAM if invalid parameters were specified
* @retval #MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT if a running operation prevented the request
* @retval #MCUXCLCSS_STATUS_OK_WAIT on successful request
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Rng_Dtrng_ConfigEvaluate_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_Dtrng_ConfigEvaluate_Async(
uint8_t const * pInput,
uint8_t * pOutput
);
/**
* @brief Returns one random word from the CSS PRNG.
*
* This function returns one low-quality random CPU word gathered from the PRNG.
*
* @attention PRNG has to be initialized prior to the first time calling this function.
*
* @param[out] pWord The pointer to the random word
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_OK on successful request
* @retval #MCUXCLCSS_STATUS_HW_PRNG in case of insufficient entropy
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Prng_GetRandomWord)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Prng_GetRandomWord(
uint32_t * pWord
);
/**
* @brief Writes random data from the CSS PRNG to the given buffer.
*
* This function fills a buffer with low-quality random values gathered from the PRNG.
*
* @attention PRNG has to be initialized prior to the first time calling this function.
*
* @param[out] pOutput Pointer to the beginning of the memory area to fill with random data from PRNG
* @param[in] outputLength Size of @p pOutput in bytes
*
* @return A code-flow protected error code (see @ref mcuxCsslFlowProtection). The error code can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
* @retval #MCUXCLCSS_STATUS_OK on successful request
* @retval #MCUXCLCSS_STATUS_HW_PRNG in case of insufficient entropy
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClCss_Prng_GetRandom)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Prng_GetRandom(
uint8_t * pOutput,
size_t outputLength
);
/**
* @}
*/ /* mcuxClCss_Rng_Functions */
/**
* @}
*/ /* mcuxClCss_Rng */
#endif /* MCUXCLCSS_RNG_H_ */

View File

@ -1,262 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Types.h
* @brief CSSv2 type header.
*
* This header defines types that are used by other mcuxClCss headers.
*/
/**
* @defgroup mcuxClCss_Types mcuxClCss_Types
* @brief This part of the @ref mcuxClCss driver defines common types
* @ingroup mcuxClCss
* @{
*/
#ifndef MCUXCLCSS_TYPES_H_
#define MCUXCLCSS_TYPES_H_
#include <stdint.h>
#include <stddef.h>
/**********************************************
* MACROS
**********************************************/
/**
* @defgroup mcuxClCss_Types_Macros mcuxClCss_Types_Macros
* @brief Defines all macros of @ref mcuxClCss_Types
* @ingroup mcuxClCss_Types
* @{
*/
#define MCUXCLCSS_KEY_SLOTS (20U) ///< Number of key slots in the CSS key store.
/** @defgroup MCUXCLCSS_KEYPROPERTY_VALUE_ MCUXCLCSS_KEYPROPERTY_VALUE_
* @brief Constants for initalizing #mcuxClCss_KeyProp_t.word
* @ingroup mcuxClCss_Types_Macros
* @{
*/
#define MCUXCLCSS_KEYPROPERTY_VALUE_KEY_SIZE_128 ((uint32_t) 0u<< 0u) ///< 128-bit key
#define MCUXCLCSS_KEYPROPERTY_VALUE_KEY_SIZE_256 ((uint32_t) 1u<< 0u) ///< 256-bit key
#define MCUXCLCSS_KEYPROPERTY_VALUE_ACTIVE ((uint32_t) 1u<< 5u) ///< Key is active (loaded)
#define MCUXCLCSS_KEYPROPERTY_VALUE_BASE_SLOT ((uint32_t) 1u<< 6u) ///< First part of multi-slot key
#define MCUXCLCSS_KEYPROPERTY_VALUE_GENERAL_PURPOSE_SLOT ((uint32_t) 1u<< 7u) ///< General purpose key slot
#define MCUXCLCSS_KEYPROPERTY_VALUE_RETENTION_SLOT ((uint32_t) 1u<< 8u) ///< Retention key slot
#define MCUXCLCSS_KEYPROPERTY_VALUE_HW_OUT_SLOT ((uint32_t) 1u<< 9u) ///< Hardware output key slot
#define MCUXCLCSS_KEYPROPERTY_VALUE_CMAC ((uint32_t) 1u<<13u) ///< CMAC key
#define MCUXCLCSS_KEYPROPERTY_VALUE_KSK ((uint32_t) 1u<<14u) ///< Key signing key
#define MCUXCLCSS_KEYPROPERTY_VALUE_RTF ((uint32_t) 1u<<15u) ///< RTF signing key
#define MCUXCLCSS_KEYPROPERTY_VALUE_CKDF ((uint32_t) 1u<<16u) ///< CKDF signing key
#define MCUXCLCSS_KEYPROPERTY_VALUE_HKDF ((uint32_t) 1u<<17u) ///< HKDF signing key
#define MCUXCLCSS_KEYPROPERTY_VALUE_ECSGN ((uint32_t) 1u<<18u) ///< ECC signing key
#define MCUXCLCSS_KEYPROPERTY_VALUE_ECDH ((uint32_t) 1u<<19u) ///< ECC Diffie Hellman private key
#define MCUXCLCSS_KEYPROPERTY_VALUE_AES ((uint32_t) 1u<<20u) ///< AES key
#define MCUXCLCSS_KEYPROPERTY_VALUE_HMAC ((uint32_t) 1u<<21u) ///< HMAC key
#define MCUXCLCSS_KEYPROPERTY_VALUE_KWK ((uint32_t) 1u<<22u) ///< Key Wrapping Key
#define MCUXCLCSS_KEYPROPERTY_VALUE_KUOK ((uint32_t) 1u<<23u) ///< Key Unwrapping Only Key
#define MCUXCLCSS_KEYPROPERTY_VALUE_TLS_PREMASTER_SECRET ((uint32_t) 1u<<24u) ///< TLS Premaster Secret
#define MCUXCLCSS_KEYPROPERTY_VALUE_TLS_MASTER_SECRET ((uint32_t) 1u<<25u) ///< TLS Master Secret
#define MCUXCLCSS_KEYPROPERTY_VALUE_KGSRC ((uint32_t) 1u<<26u) ///< Can provide key material input for ECC key generation
#define MCUXCLCSS_KEYPROPERTY_VALUE_HW_OUT ((uint32_t) 1u<<27u) ///< A key to be used in a hardware out key slot
#define MCUXCLCSS_KEYPROPERTY_VALUE_WRPOK ((uint32_t) 1u<<28u) ///< The key can be wrapped
#define MCUXCLCSS_KEYPROPERTY_VALUE_DUK ((uint32_t) 1u<<29u) ///< Device Unique Key
#define MCUXCLCSS_KEYPROPERTY_VALUE_PRIVILEGED ((uint32_t) 1u<<30u) ///< Caller must be in privileged mode to use the key
#define MCUXCLCSS_KEYPROPERTY_VALUE_NOTPRIVILEGED ((uint32_t) 0u<<30u) ///< Caller does not have to be in privileged mode to use the key
#define MCUXCLCSS_KEYPROPERTY_VALUE_SECURE ((uint32_t) 0u<<31u) ///< Caller must be in secure mode to use the key
#define MCUXCLCSS_KEYPROPERTY_VALUE_NOTSECURE ((uint32_t) 1u<<31u) ///< Caller does not have to be in secure mode to use the key
/**
* @}
*/
/** @defgroup MCUXCLCSS_KEYPROPERTY_ MCUXCLCSS_KEYPROPERTY_
* @brief Constants for initalizing #mcuxClCss_KeyProp_t.bits
* @ingroup mcuxClCss_Types_Macros
* @{
*/
#define MCUXCLCSS_KEYPROPERTY_KEY_SIZE_128 0U ///< This value of #mcuxClCss_KeyProp_t.ksize indicates a 128 bit key
#define MCUXCLCSS_KEYPROPERTY_KEY_SIZE_256 1U ///< This value of #mcuxClCss_KeyProp_t.ksize indicates a 256 bit key
#define MCUXCLCSS_KEYPROPERTY_ACTIVE_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.kactv indicates that the slot contains an active key
#define MCUXCLCSS_KEYPROPERTY_ACTIVE_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.kactv indicates that the slot does not contain active key
#define MCUXCLCSS_KEYPROPERTY_BASE_SLOT 1U ///< This value of #mcuxClCss_KeyProp_t.kbase indicates that the slot is the base slot of a 2-slot key
#define MCUXCLCSS_KEYPROPERTY_SECOND_SLOT 0U ///< This value of #mcuxClCss_KeyProp_t.kbase indicates that the slot is the second slot of a 2-slot key
#define MCUXCLCSS_KEYPROPERTY_GENERAL_PURPOSE_SLOT_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.fgp indicates that the slot is a retention key slot or a hardware out key slot
#define MCUXCLCSS_KEYPROPERTY_GENERAL_PURPOSE_SLOT_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.fgp indicates that the slot is a neither retention key slot nor hardware out key slot
#define MCUXCLCSS_KEYPROPERTY_RETENTION_SLOT_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.frtn indicates that the slot is a retention key slot
#define MCUXCLCSS_KEYPROPERTY_RETENTION_SLOT_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.frtn indicates that the slot is not a retention key slot
#define MCUXCLCSS_KEYPROPERTY_HW_OUT_SLOT_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.fhwo indicates that the slot is a hardware out key slot
#define MCUXCLCSS_KEYPROPERTY_HW_OUT_SLOT_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.fhwo indicates that the slot is not a hardware out key slot
#define MCUXCLCSS_KEYPROPERTY_CMAC_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.ucmac indicates that the key can be used for CMAC
#define MCUXCLCSS_KEYPROPERTY_CMAC_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.ucmac indicates that the key cannot be used for CMAC
#define MCUXCLCSS_KEYPROPERTY_KSK_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.uksk indicates that the key can be used for key signing
#define MCUXCLCSS_KEYPROPERTY_KSK_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.uksk indicates that the key cannot be used for key signing
#define MCUXCLCSS_KEYPROPERTY_RTF_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.urtf indicates that the key can be used for RTF signing
#define MCUXCLCSS_KEYPROPERTY_RTF_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.urtf indicates that the key cannot be used for RTF signing
#define MCUXCLCSS_KEYPROPERTY_CKDF_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.uckdf indicates that the key can be used for CKDF
#define MCUXCLCSS_KEYPROPERTY_CKDF_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.uckdf indicates that the key cannot be used for CKDF
#define MCUXCLCSS_KEYPROPERTY_HKDF_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.uhkdf indicates that the key can be used for HKDF
#define MCUXCLCSS_KEYPROPERTY_HKDF_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.uhkdf indicates that the key cannot be used for HKDF
#define MCUXCLCSS_KEYPROPERTY_ECC_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.uecsg indicates that the key can be used for ECC signing
#define MCUXCLCSS_KEYPROPERTY_ECC_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.uecsg indicates that the key cannot be used for ECC signing
#define MCUXCLCSS_KEYPROPERTY_ECC_DH_PRIVATE_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.uecdh indicates that the key is a ECC Diffie Hellman private key
#define MCUXCLCSS_KEYPROPERTY_ECC_DH_PRIVATE_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.uecdh indicates that the key is not an ECC Diffie Hellman private key
#define MCUXCLCSS_KEYPROPERTY_AES_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.uaes indicates that the key is an AES key
#define MCUXCLCSS_KEYPROPERTY_AES_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.uaes indicates that the key is not an AES key
#define MCUXCLCSS_KEYPROPERTY_HMAC_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.uhmac indicates that the key is an HMAC key
#define MCUXCLCSS_KEYPROPERTY_HMAC_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.uhmac indicates that the key is not an HMAC key
#define MCUXCLCSS_KEYPROPERTY_KWK_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.ukwk indicates that the key is a Key Wrapping Key
#define MCUXCLCSS_KEYPROPERTY_KWK_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.ukwk indicates that the key is not a Key Wrapping Key
#define MCUXCLCSS_KEYPROPERTY_KUOK_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.ukuok indicates that the key is a Key Unwrapping Only Key
#define MCUXCLCSS_KEYPROPERTY_KUOK_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.ukuok indicates that the key is not a Key Unwrapping Only Key
#define MCUXCLCSS_KEYPROPERTY_TLS_PREMASTER_SECRET_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.utlspms indicates that the key is a TLS Premaster Secret
#define MCUXCLCSS_KEYPROPERTY_TLS_PREMASTER_SECRET_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.utlspms indicates that the key is not a TLS Premaster Secret
#define MCUXCLCSS_KEYPROPERTY_TLS_MASTER_SECRET_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.utlsms indicates that the key is a TLS Master Secret
#define MCUXCLCSS_KEYPROPERTY_TLS_MASTER_SECRET_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.utlsms indicates that the key is not a TLS Master Secret
#define MCUXCLCSS_KEYPROPERTY_INPUT_FOR_ECC_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.ukgsrc indicates that the key can be used as key material input for ECC key generation
#define MCUXCLCSS_KEYPROPERTY_INPUT_FOR_ECC_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.ukgsrc indicates that the key cannot be used as key material input for ECC key generation
#define MCUXCLCSS_KEYPROPERTY_HW_OUT_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.uhwo indicates that the key can be used in a hardware out key slot
#define MCUXCLCSS_KEYPROPERTY_HW_OUT_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.uhwo indicates that the key cannot be used in a hardware out key slot
#define MCUXCLCSS_KEYPROPERTY_WRAP_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.wrpok indicates that the key can be wrapped
#define MCUXCLCSS_KEYPROPERTY_WRAP_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.wrpok indicates that the key cannot be wrapped
#define MCUXCLCSS_KEYPROPERTY_DEVICE_UNIQUE_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.duk indicates that the key is a Device Unique Key
#define MCUXCLCSS_KEYPROPERTY_DEVICE_UNIQUE_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.duk indicates that the key is not a Device Unique Key
#define MCUXCLCSS_KEYPROPERTY_PRIVILEGED_TRUE 1U ///< This value of #mcuxClCss_KeyProp_t.upprot_priv indicates that the caller must be in privileged mode to use the key
#define MCUXCLCSS_KEYPROPERTY_PRIVILEGED_FALSE 0U ///< This value of #mcuxClCss_KeyProp_t.upprot_priv indicates that the caller does not need to be in privileged mode to use the key
#define MCUXCLCSS_KEYPROPERTY_SECURE_TRUE 0U ///< This value of #mcuxClCss_KeyProp_t.upprot_sec indicates that the caller must be in secure mode to use the key
#define MCUXCLCSS_KEYPROPERTY_SECURE_FALSE 1U ///< This value of #mcuxClCss_KeyProp_t.upprot_sec indicates that the caller does not need to be in secure mode to use the key
/**
* @}
*/
/**
* @defgroup MCUXCLCSS_STATUS_ MCUXCLCSS_STATUS_
* @brief Return code definitions
* @ingroup mcuxClCss_Types_Macros
* @{
*/
#define MCUXCLCSS_STATUS_OK ((mcuxClCss_Status_t) 0xF0F0F0F0U) ///< No error occurred
#define MCUXCLCSS_STATUS_OK_WAIT ((mcuxClCss_Status_t) 0xF0F0F0E1U) ///< An <tt>_Async</tt> function successfully started a CSS command. Call #mcuxClCss_WaitForOperation to complete it
#define MCUXCLCSS_STATUS_HW_FAULT ((mcuxClCss_Status_t) 0xF0F0E1E1U) ///< CSSv2 hardware detected a fault
#define MCUXCLCSS_STATUS_HW_ALGORITHM ((mcuxClCss_Status_t) 0xF0F0E1E2U) ///< An algorithm failed in hardware
#define MCUXCLCSS_STATUS_HW_OPERATIONAL ((mcuxClCss_Status_t) 0xF0F0E1E4U) ///< CSSv2 was operated incorrectly
#define MCUXCLCSS_STATUS_HW_BUS ((mcuxClCss_Status_t) 0xF0F0E1E8U) ///< A bus access failed
#define MCUXCLCSS_STATUS_HW_INTEGRITY ((mcuxClCss_Status_t) 0xF0F0E1D1U) ///< An integrity check failed in hardware
#define MCUXCLCSS_STATUS_HW_PRNG ((mcuxClCss_Status_t) 0xF0F0E1D2U) ///< Read access to PRNG output while PRNG is not in ready state
#define MCUXCLCSS_STATUS_HW_DTRNG ((mcuxClCss_Status_t) 0xF0F0E1D4U) ///< Unable to get entropy from dTRNG with current configuration
#define MCUXCLCSS_STATUS_SW_FAULT ((mcuxClCss_Status_t) 0xF0F0F0E2U) ///< Software detected a fault
#define MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT ((mcuxClCss_Status_t) 0xF0F0F0E4U) ///< A CSS command was started while the CSS was still busy, or a SHA-Direct command was started while the SHA kernel was still busy
#define MCUXCLCSS_STATUS_SW_INVALID_PARAM ((mcuxClCss_Status_t) 0xF0F0F0E8U) ///< Incorrect parameters were supplied
#define MCUXCLCSS_STATUS_SW_INVALID_STATE ((mcuxClCss_Status_t) 0xF0F0F0D1U) ///< This can happen when CSS is in a wrong state for the requested CSS command
#define MCUXCLCSS_STATUS_SW_COUNTER_EXPIRED ((mcuxClCss_Status_t) 0xF0F0F0D2U) ///< A software counter expired while waiting for a CSS operation to finish
#define MCUXCLCSS_STATUS_SW_COMPARISON_FAILED ((mcuxClCss_Status_t) 0xF0F0F0D4U) ///< A comparison between a CSS flag and its expected value failed
/** @} */
#define MCUXCLCSS_STATUS_IS_HW_ERROR(x) ((((mcuxClCss_Status_t) (x)) & 0x0000FF00U) == 0x0000E100U) ///< Checks whether an error code is a hardware error. Indicates that an error was reported by CSSv2 hardware.
#define MCUXCLCSS_STATUS_IS_SW_ERROR(x) ((((mcuxClCss_Status_t) (x)) & 0x0000FF00U) == 0x0000F000U) ///< Checks whether an error code is a software error. Indicates that the error was detected by the driver software and not by CSSv2 hardware.
/**
* @}
*/
/**********************************************
* TYPEDEFS
**********************************************/
/**
* @defgroup mcuxClCss_Types_Types mcuxClCss_Types_Types
* @brief Defines all types of @ref mcuxClCss_Types
* @ingroup mcuxClCss_Types
* @{
*/
/**
* @brief Type for CSS driver protected status codes
*/
typedef uint64_t mcuxClCss_Status_Protected_t;
/**
* @brief Type for CSS driver status codes
*/
typedef uint32_t mcuxClCss_Status_t;
/**
* @brief Type for CSS keystore indices
*/
typedef uint8_t mcuxClCss_KeyIndex_t;
/** Type for CSS key store key properties */
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word; initialize with a combination of constants from @ref MCUXCLCSS_KEYPROPERTY_VALUE_
} word; ///< Access #mcuxClCss_KeyProp_t word-wise
struct
{
uint32_t ksize :2; ///< Key size
uint32_t :3; ///< RFU
uint32_t kactv :1; ///< Status flag to indicate whether the key slot contains an active key or not
uint32_t kbase :1; ///< Status flag to indicate whether the key slot is a base slot or the second slot of a 256-bit key
uint32_t fgp :1; ///< Hardware feature flag: General purpose key slot
uint32_t frtn :1; ///< Hardware feature flag: Retention key slot
uint32_t fhwo :1; ///< Hardware feature flag: Hardware-out key slot
uint32_t :3; ///< RFU
uint32_t ucmac :1; ///< Usage permission for CMAC
uint32_t uksk :1; ///< Usage permission for key signing
uint32_t urtf :1; ///< Usage permission for RTF signing
uint32_t uckdf :1; ///< Usage permission for CKDF
uint32_t uhkdf :1; ///< Usage permission for HKDF
uint32_t uecsg :1; ///< Usage permission for ECDSA signing
uint32_t uecdh :1; ///< Usage permission for Elliptic Curve Diffie-Hellman
uint32_t uaes :1; ///< Usage permission for AES
uint32_t uhmac :1; ///< Usage permission for HMAC
uint32_t ukwk :1; ///< Usage permission for key wrapping
uint32_t ukuok :1; ///< Usage permission for key unwrapping, but not for key wrapping
uint32_t utlspms :1; ///< Usage permission as a TLS premaster secret
uint32_t utlsms :1; ///< Usage permission as a TLS master secret
uint32_t ukgsrc :1; ///< Usage permission as input for ECC key generation
uint32_t uhwo :1; ///< Usage permission in a hardware-out key slot
uint32_t wrpok :1; ///< Usage permission to wrap
uint32_t duk :1; ///< Device-unique key flag
uint32_t upprot_priv :1; ///< Access restriction to privileged mode
uint32_t upprot_sec :1; ///< Access restriction to TrustZone secure mode
} bits; ///< Access #mcuxClCss_KeyProp_t bit-wise
} mcuxClCss_KeyProp_t;
#define utlpsms utlspms ///< Deprecated name for #mcuxClCss_KeyProp_t.utlspms
/**
* @brief Function type for transfer of data to a memory-mapped register
*
* This function type is used as a callback for handling data transfer from memory to a memory-mapped register.
* Such a function shall read data from the @c uint8_t array source, and write data via a sequence of writes to @p destRegister.
* Further specification of this function's behavior can be found in the documentation of the function that accepts this function as a callback parameter.
*
* @param [out] destRegister Memory-mapped register that the output data shall be written to
* @param [in] source Array containing the input data
* @param [in] size Size of @p source in bytes
* @param [in, out] pCallerData Custom pointer that is provided by the caller and forwarded to the callback function by the operation
* @return An error code that can be any error code in @ref MCUXCLCSS_STATUS_, see individual documentation for more information
*/
typedef mcuxClCss_Status_t (*mcuxClCss_TransferToRegisterFunction_t)(
uint32_t volatile * destRegister,
uint8_t const * source,
size_t size,
void * pCallerData);
#endif /* MCUXCLCSS_TYPES_H_ */
/**
* @}
*
* @}
*/

View File

@ -1,229 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClCss_Aead.c
* @brief CSSv2 implementation for Authenticated Encryption with Associated Data (AEAD).
* This file implements the functions declared in mcuxClCss_Aead.h. */
#include <mcuxClMemory.h>
#include <mcuxCsslFlowProtection.h>
#include <platform_specific_headers.h>
#include <mcuxClCss.h>
#include <internal/mcuxClCss_Internal.h>
/* Constants for mcuxClCss_AeadOption_t.acpmod */
#define MCUXCLCSS_AEAD_ACPMOD_INIT ((uint32_t) 0U) ///< Init (Auth Cipher mode)
#define MCUXCLCSS_AEAD_ACPMOD_AADPROC ((uint32_t) 1U) ///< Process Additional Authenticated Data (Auth Cipher mode)
#define MCUXCLCSS_AEAD_ACPMOD_MSGPROC ((uint32_t) 2U) ///< Process Message (Auth Cipher mode)
#define MCUXCLCSS_AEAD_ACPMOD_FINAL ((uint32_t) 3U) ///< Finalize (Auth Cipher mode)
/* Constants for mcuxClCss_AeadOption_t.acpsoe */
#define MCUXCLCSS_AEAD_STATE_OUT_ENABLE 1U ///< Set #mcuxClCss_AeadOption_t.acpsoe to this value to save the GCM state to the context
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Aead_Init_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_Init_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pIV,
size_t ivLength,
uint8_t * pAeadCtx)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Aead_Init_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Aead_Init_Async, (MCUXCLCSS_AEAD_INTERN_KEY == options.bits.extkey && CSS_KS_CNT <= keyIdx) || ((MCUXCLCSS_AEAD_EXTERN_KEY == options.bits.extkey && ((MCUXCLCSS_CIPHER_KEY_SIZE_AES_128 != keyLength && MCUXCLCSS_CIPHER_KEY_SIZE_AES_192 != keyLength && MCUXCLCSS_CIPHER_KEY_SIZE_AES_256 != keyLength))))
|| (0u == ivLength) || (0u != ivLength % MCUXCLCSS_AEAD_IV_BLOCK_SIZE));
uint8_t * pStartIpCtxArea = pAeadCtx + MCUXCLCSS_CIPHER_BLOCK_SIZE_AES;
/* Set init mode */
options.bits.acpmod = MCUXCLCSS_AEAD_ACPMOD_INIT;
options.bits.lastinit = MCUXCLCSS_AEAD_LASTINIT_TRUE;
options.bits.acpsie = MCUXCLCSS_AEAD_STATE_IN_DISABLE;
options.bits.acpsoe = MCUXCLCSS_AEAD_STATE_OUT_ENABLE;
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_Init_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT0(pIV, ivLength);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pStartIpCtxArea);
MCUXCLCSS_SETCSSINPUT2(pKey, keyLength);
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_AUTH_CIPHER, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_Init_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Aead_PartialInit_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_PartialInit_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pIV,
size_t ivLength,
uint8_t * pAeadCtx)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Aead_PartialInit_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Aead_PartialInit_Async, (MCUXCLCSS_AEAD_INTERN_KEY == options.bits.extkey && CSS_KS_CNT <= keyIdx) || ((MCUXCLCSS_AEAD_EXTERN_KEY == options.bits.extkey && ((MCUXCLCSS_CIPHER_KEY_SIZE_AES_128 != keyLength && MCUXCLCSS_CIPHER_KEY_SIZE_AES_192 != keyLength && MCUXCLCSS_CIPHER_KEY_SIZE_AES_256 != keyLength))))
|| (0u == ivLength) || (0u != ivLength % MCUXCLCSS_AEAD_IV_BLOCK_SIZE));
uint8_t * pStartIpCtxArea = pAeadCtx + MCUXCLCSS_CIPHER_BLOCK_SIZE_AES;
/* Set init mode */
options.bits.acpmod = MCUXCLCSS_AEAD_ACPMOD_INIT;
options.bits.acpsoe = MCUXCLCSS_AEAD_STATE_OUT_ENABLE;
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_PartialInit_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT0(pIV, ivLength);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pStartIpCtxArea);
MCUXCLCSS_SETCSSINPUT2(pKey, keyLength);
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_AUTH_CIPHER, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_PartialInit_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Aead_UpdateAad_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_UpdateAad_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pAad,
size_t aadLength,
uint8_t * pAeadCtx)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Aead_UpdateAad_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Aead_UpdateAad_Async, (0U == aadLength) || (0u != aadLength % MCUXCLCSS_AEAD_AAD_BLOCK_SIZE));
uint8_t * pStartIpCtxArea = pAeadCtx + MCUXCLCSS_CIPHER_BLOCK_SIZE_AES;
options.bits.acpmod = MCUXCLCSS_AEAD_ACPMOD_AADPROC;
options.bits.acpsie = MCUXCLCSS_AEAD_STATE_IN_ENABLE;
options.bits.acpsoe = MCUXCLCSS_AEAD_STATE_OUT_ENABLE;
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_UpdateAad_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT2(pKey, keyLength);
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
MCUXCLCSS_SETCSSINPUT0(pAad, aadLength);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pStartIpCtxArea);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_AUTH_CIPHER, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_UpdateAad_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Aead_UpdateData_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_UpdateData_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pOutput,
uint8_t * pAeadCtx)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Aead_UpdateData_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Aead_UpdateData_Async, (0U == inputLength) || (0u != inputLength % MCUXCLCSS_CIPHER_BLOCK_SIZE_AES) || (MCUXCLCSS_AEAD_INTERN_KEY == options.bits.extkey && CSS_KS_CNT <= keyIdx)
|| (MCUXCLCSS_AEAD_EXTERN_KEY == options.bits.extkey && (MCUXCLCSS_CIPHER_KEY_SIZE_AES_128 != keyLength && MCUXCLCSS_CIPHER_KEY_SIZE_AES_192 != keyLength && MCUXCLCSS_CIPHER_KEY_SIZE_AES_256 != keyLength)));
uint8_t * pStartIpCtxArea = pAeadCtx + MCUXCLCSS_CIPHER_BLOCK_SIZE_AES;
options.bits.acpmod = MCUXCLCSS_AEAD_ACPMOD_MSGPROC;
options.bits.acpsie = MCUXCLCSS_AEAD_STATE_IN_ENABLE;
options.bits.acpsoe = MCUXCLCSS_AEAD_STATE_OUT_ENABLE;
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_UpdateData_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT2(pKey, keyLength);
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
MCUXCLCSS_SETCSSINPUT0(pInput, inputLength);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pStartIpCtxArea);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_AUTH_CIPHER, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_UpdateData_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Aead_Finalize_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Aead_Finalize_Async(
mcuxClCss_AeadOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
size_t aadLength,
size_t dataLength,
uint8_t * pTag,
uint8_t * pAeadCtx)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Aead_Finalize_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Aead_Finalize_Async, (MCUXCLCSS_AEAD_INTERN_KEY == options.bits.extkey && CSS_KS_CNT <= keyIdx) || (MCUXCLCSS_AEAD_EXTERN_KEY == options.bits.extkey && (16U != keyLength && 24U != keyLength && 32U != keyLength)));
uint8_t * pStartIpCtxArea = pAeadCtx + MCUXCLCSS_CIPHER_BLOCK_SIZE_AES;
options.bits.acpsie = MCUXCLCSS_AEAD_STATE_IN_ENABLE;
/* Update the length of the AAD to store in the context */
aadLength <<= 3;
/* Update the length of the data to store in the context */
dataLength <<= 3;
/* Store both in the context */
mcuxClMemory_StoreBigEndian32(&pAeadCtx[ 0u], (uint32_t) 0U);
mcuxClMemory_StoreBigEndian32(&pAeadCtx[ 4u], aadLength );
mcuxClMemory_StoreBigEndian32(&pAeadCtx[ 8u], (uint32_t) 0U);
mcuxClMemory_StoreBigEndian32(&pAeadCtx[12u], dataLength);
options.bits.acpmod = MCUXCLCSS_AEAD_ACPMOD_FINAL;
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_Finalize_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT2(pKey, keyLength);
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pAeadCtx);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pStartIpCtxArea);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pTag);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_AUTH_CIPHER, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Aead_Finalize_Async, MCUXCLCSS_STATUS_OK_WAIT);
}

View File

@ -1,71 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file impl/mcuxClCss_Cipher.c
* @brief CSSv2 implementation for symmetric ciphers.
* This file implements the functions declared in mcuxClCss_Cipher.h. */
#include <mcuxCsslFlowProtection.h>
#include <platform_specific_headers.h>
#include <mcuxClCss.h>
#include <internal/mcuxClCss_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Cipher_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Cipher_Async(mcuxClCss_CipherOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const *pKey,
size_t keyLength,
uint8_t const *pInput,
size_t inputLength,
uint8_t *pIV,
uint8_t *pOutput)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Cipher_Async);
// ignored misra violation -> false positive
// misra_c_2012_rule_11_9_violation: Literal 0 shall not be used as null pointer constant.
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(
mcuxClCss_Cipher_Async,
(0U == inputLength) || (0U != (inputLength % MCUXCLCSS_CIPHER_BLOCK_SIZE_AES)) ||
(MCUXCLCSS_CIPHER_INTERNAL_KEY == options.bits.extkey && CSS_KS_CNT <= keyIdx) ||
((MCUXCLCSS_CIPHER_EXTERNAL_KEY == options.bits.extkey) &&
((MCUXCLCSS_CIPHER_KEY_SIZE_AES_128 != keyLength) && (MCUXCLCSS_CIPHER_KEY_SIZE_AES_192 != keyLength) &&
(MCUXCLCSS_CIPHER_KEY_SIZE_AES_256 != keyLength))) ||
(MCUXCLCSS_CIPHERPARAM_ALGORITHM_AES_CTR < options.bits.cphmde)
/* ECB doesn't support importing or exporting an IV */
|| ((MCUXCLCSS_CIPHERPARAM_ALGORITHM_AES_ECB == options.bits.cphmde) &&
((MCUXCLCSS_CIPHER_STATE_IN_ENABLE == options.bits.cphsie) ||
(MCUXCLCSS_CIPHER_STATE_OUT_ENABLE == options.bits.cphsoe))));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Cipher_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT0(pInput, inputLength);
if (0U == options.bits.extkey)
{
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
}
else
{
MCUXCLCSS_SETCSSINPUT2(pKey, keyLength);
}
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pIV);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_CIPHER, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Cipher_Async, MCUXCLCSS_STATUS_OK_WAIT);
}

View File

@ -1,79 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClCss_Cmac.c
* @brief CSSv2 implementation for CMAC support.
* This file implements the functions declared in mcuxClCss_Cmac.h. */
#include <mcuxClCss_Types.h>
#include <mcuxClCss_Cmac.h>
#include <mcuxCsslFlowProtection.h>
#include <platform_specific_headers.h>
#include <mcuxClCss.h>
#include <internal/mcuxClCss_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Cmac_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Cmac_Async(
mcuxClCss_CmacOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pKey,
size_t keyLength,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pMac)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Cmac_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Cmac_Async, (MCUXCLCSS_CMAC_EXTERNAL_KEY_DISABLE == options.bits.extkey && CSS_KS_CNT <= keyIdx) || (MCUXCLCSS_CMAC_EXTERNAL_KEY_ENABLE == options.bits.extkey && ((MCUXCLCSS_CMAC_KEY_SIZE_128 != keyLength) && (MCUXCLCSS_CMAC_KEY_SIZE_256 != keyLength))));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Cmac_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
if(MCUXCLCSS_CMAC_INITIALIZE_ENABLE == options.bits.initialize)
{
options.bits.sie = MCUXCLCSS_CMAC_STATE_IN_DISABLE;
}
else
{
options.bits.sie = MCUXCLCSS_CMAC_STATE_IN_ENABLE;
}
if(MCUXCLCSS_CMAC_FINALIZE_ENABLE == options.bits.finalize)
{
options.bits.soe = MCUXCLCSS_CMAC_STATE_OUT_DISABLE;
}
else
{
options.bits.soe = MCUXCLCSS_CMAC_STATE_OUT_ENABLE;
}
if (0U == options.bits.extkey)
{
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
}
else
{
MCUXCLCSS_SETCSSINPUT2(pKey, keyLength);
}
MCUXCLCSS_SETCSSINPUT0(pInput, inputLength);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pMac);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pMac);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_CMAC, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Cmac_Async, MCUXCLCSS_STATUS_OK_WAIT);
}

View File

@ -1,283 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClCss_Common.c
* @brief CSSv2 implementation for common functionality.
* This file implements the functions declared in mcuxClCss_Common.h and adds helper functions used by other implementation headers. */
#include <stdbool.h>
#include <platform_specific_headers.h>
#include <mcuxClCss_Types.h>
#include <mcuxClMemory.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClCss.h>
#include <internal/mcuxClCss_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_GetHwVersion)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetHwVersion(
mcuxClCss_HwVersion_t * result)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_GetHwVersion);
result->word.value = IP_CSS->CSS_VERSION;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_GetHwVersion, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_GetHwConfig)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetHwConfig(
mcuxClCss_HwConfig_t * result)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_GetHwConfig);
result->word.value = IP_CSS->CSS_CONFIG;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_GetHwConfig, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_GetHwState)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetHwState(
mcuxClCss_HwState_t * result)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_GetHwState);
result->word.value = IP_CSS->CSS_STATUS;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_GetHwState, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Enable_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Enable_Async(
void)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Enable_Async);
IP_CSS->CSS_CTRL_b.CSS_EN = 1U;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Enable_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Disable)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Disable(
void)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Disable);
IP_CSS->CSS_CTRL_b.CSS_EN = 0U;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Disable, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_GetErrorCode)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetErrorCode(
mcuxClCss_ErrorHandling_t errorHandling)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_GetErrorCode);
mcuxClCss_Status_t result = MCUXCLCSS_STATUS_SW_FAULT;
if (1U == IP_CSS->CSS_STATUS_b.CSS_ERR)
{
if (1U == IP_CSS->CSS_ERR_STATUS_b.FLT_ERR)
{
result = MCUXCLCSS_STATUS_HW_FAULT;
}
else if (1U == IP_CSS->CSS_ERR_STATUS_b.ITG_ERR)
{
result = MCUXCLCSS_STATUS_HW_INTEGRITY;
}
else if (1U == IP_CSS->CSS_ERR_STATUS_b.OPN_ERR)
{
result = MCUXCLCSS_STATUS_HW_OPERATIONAL;
}
else if (1U == IP_CSS->CSS_ERR_STATUS_b.ALG_ERR)
{
result = MCUXCLCSS_STATUS_HW_ALGORITHM;
}
else if (1U == IP_CSS->CSS_ERR_STATUS_b.BUS_ERR)
{
result = MCUXCLCSS_STATUS_HW_BUS;
}
else if (1U == IP_CSS->CSS_ERR_STATUS_b.PRNG_ERR)
{
result = MCUXCLCSS_STATUS_HW_PRNG;
}
else if (1U == IP_CSS->CSS_ERR_STATUS_b.DTRNG_ERR)
{
result = MCUXCLCSS_STATUS_HW_DTRNG;
}
else
{
result = MCUXCLCSS_STATUS_SW_FAULT;
}
}
else
{
result = MCUXCLCSS_STATUS_OK;
}
if (MCUXCLCSS_ERROR_FLAGS_CLEAR == errorHandling){
(void) mcuxClCss_ResetErrorFlags(); /* always returns MCUXCLCSS_STATUS_OK. */
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_GetErrorCode, result);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_GetErrorLevel)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetErrorLevel(
mcuxClCss_ErrorHandling_t errorHandling,
uint32_t *errorLevel)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_GetErrorLevel);
*errorLevel = IP_CSS->CSS_ERR_STATUS_b.ERR_LVL;
MCUX_CSSL_FP_FUNCTION_CALL(result, mcuxClCss_GetErrorCode(errorHandling));
/* Exit function with expectation: mcuxClCss_GetErrorCode was called unconditionally */
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_GetErrorLevel, result,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_GetErrorCode));
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_WaitForOperation)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_WaitForOperation(
mcuxClCss_ErrorHandling_t errorHandling)
{
/* Enter flow-protected function with expectation: mcuxClCss_GetErrorCode will be called (unconditionally) */
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_WaitForOperation,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_GetErrorCode));
while (MCUXCLCSS_ISBUSY)
{
// Do nothing
}
MCUX_CSSL_FP_FUNCTION_CALL(result, mcuxClCss_GetErrorCode(errorHandling));
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_WaitForOperation, result);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_LimitedWaitForOperation)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_LimitedWaitForOperation(
uint32_t counterLimit,
mcuxClCss_ErrorHandling_t errorHandling)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_LimitedWaitForOperation);
bool counterExpired = true;
while (0U != counterLimit)
{
if (!MCUXCLCSS_ISBUSY)
{
counterExpired = false;
break;
}
counterLimit--;
}
if (true == counterExpired)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_LimitedWaitForOperation, MCUXCLCSS_STATUS_SW_COUNTER_EXPIRED);
}
MCUX_CSSL_FP_FUNCTION_CALL(result, mcuxClCss_GetErrorCode(errorHandling));
/* Exit function with expectation: mcuxClCss_GetErrorCode was called */
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_LimitedWaitForOperation, result,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_GetErrorCode));
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_ResetErrorFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_ResetErrorFlags(
void)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_ResetErrorFlags);
IP_CSS->CSS_ERR_STATUS_CLR = (uint32_t) MCUXCLCSS_ERROR_FLAGS_CLEAR;
// Poll error bit to be sure that error bits has been cleared. Required by HW spec.
while (1U == IP_CSS->CSS_STATUS_b.CSS_ERR)
{
// Do nothing
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_ResetErrorFlags, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Reset_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Reset_Async(
mcuxClCss_ResetOption_t options)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Reset_Async);
if (MCUXCLCSS_ISBUSY && (MCUXCLCSS_RESET_DO_NOT_CANCEL == options))
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Reset_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
IP_CSS->CSS_CTRL_b.CSS_RESET = 1U;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Reset_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_SetIntEnableFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_SetIntEnableFlags(
mcuxClCss_InterruptOptionEn_t options)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_SetIntEnableFlags);
IP_CSS->CSS_INT_ENABLE = options.word.value;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_SetIntEnableFlags, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_GetIntEnableFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetIntEnableFlags(
mcuxClCss_InterruptOptionEn_t * result)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_GetIntEnableFlags);
result->word.value = IP_CSS->CSS_INT_ENABLE_b.INT_EN;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_GetIntEnableFlags, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_ResetIntFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_ResetIntFlags(
mcuxClCss_InterruptOptionRst_t options)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_ResetIntFlags);
IP_CSS->CSS_INT_STATUS_CLR = options.word.value;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_ResetIntFlags, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_SetIntFlags)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_SetIntFlags(
mcuxClCss_InterruptOptionSet_t options)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_SetIntFlags);
IP_CSS->CSS_INT_STATUS_SET = options.word.value;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_SetIntFlags, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_SetRandomStartDelay)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_SetRandomStartDelay(
uint32_t delay)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_SetRandomStartDelay);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_SetRandomStartDelay, 1024u < delay);
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_SetRandomStartDelay, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
IP_CSS->CSS_CFG_b.ADCTRL = delay;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_SetRandomStartDelay, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_GetRandomStartDelay)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetRandomStartDelay(
uint32_t *delay)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_GetRandomStartDelay);
* delay = IP_CSS->CSS_CFG_b.ADCTRL;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_GetRandomStartDelay, MCUXCLCSS_STATUS_OK);
}

View File

@ -1,166 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Ecc.c
* @brief CSSv2 implementation for elliptic curve cryptography.
* This file implements the functions declared in mcuxClCss_Ecc.h.
*/
#include <mcuxClCss_Ecc.h>
#include <mcuxClMemory.h>
#include <mcuxCsslFlowProtection.h>
#include <platform_specific_headers.h>
#include <mcuxClCss.h>
#include <internal/mcuxClCss_Internal.h>
/**
* @brief Command option bit field for #mcuxClCss_EccKeyExch_Async
* Bit field to configure #mcuxClCss_EccKeyExchOption_t. See @ref MCUXCLCSS_KEYGEN_VALUE_BITS for possible options.
*/
typedef union
{
struct
{
uint32_t value; ///< Accesses the bit field as a full word; initialize with a combination of constants from @ref MCUXCLCSS_KEYGEN_VALUE_
} word; ///< Access #mcuxClCss_EccKeyExchOption_t word-wise
struct
{
uint32_t :4; ///< RFU
uint32_t revf :1; ///< This field is managed internally
uint32_t :8; ///< RFU
uint32_t extkey :1; ///< This field is managed internally
uint32_t :18; ///< RFU
} bits; ///< Access #mcuxClCss_EccKeyExchOption_t bit-wise
} mcuxClCss_EccKeyExchOption_t;
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_EccKeyGen_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_EccKeyGen_Async(
mcuxClCss_EccKeyGenOption_t options,
mcuxClCss_KeyIndex_t signingKeyIdx,
mcuxClCss_KeyIndex_t privateKeyIdx,
mcuxClCss_KeyProp_t generatedKeyProperties,
uint8_t const * pRandomData,
uint8_t * pPublicKey)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_EccKeyGen_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_EccKeyGen_Async, (CSS_KS_CNT <= signingKeyIdx) || (CSS_KS_CNT <= privateKeyIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_EccKeyGen_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
options.bits.revf = MCUXCLCSS_REVERSEFETCH_ENABLE;
MCUXCLCSS_SETKEYSTOREINDEX0(privateKeyIdx);
MCUXCLCSS_SETKEYSTOREINDEX1(signingKeyIdx);
MCUXCLCSS_SETREQUESTEDKEYPROPERTIES(generatedKeyProperties);
MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pRandomData);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pPublicKey);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_KEYGEN, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_EccKeyGen_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_EccKeyExchange_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_EccKeyExchange_Async(
mcuxClCss_KeyIndex_t privateKeyIdx,
uint8_t const * pPublicKey,
mcuxClCss_KeyIndex_t sharedSecretIdx,
mcuxClCss_KeyProp_t sharedSecretProperties)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_EccKeyExchange_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_EccKeyExchange_Async, (CSS_KS_CNT <= privateKeyIdx) || (CSS_KS_CNT <= sharedSecretIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_EccKeyExchange_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
mcuxClCss_EccKeyExchOption_t options = {0};
options.bits.revf = MCUXCLCSS_REVERSEFETCH_ENABLE;
MCUXCLCSS_SETKEYSTOREINDEX0(privateKeyIdx);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pPublicKey);
MCUXCLCSS_SETKEYSTOREINDEX1(sharedSecretIdx);
MCUXCLCSS_SETREQUESTEDKEYPROPERTIES(sharedSecretProperties);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_ECKXH, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_EccKeyExchange_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_EccSign_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_EccSign_Async(
mcuxClCss_EccSignOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pInputHash,
uint8_t const * pInputMessage,
size_t inputMessageLength,
uint8_t * pOutput)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_EccSign_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_EccSign_Async, (CSS_KS_CNT <= keyIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_EccSign_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
options.bits.revf = MCUXCLCSS_REVERSEFETCH_ENABLE;
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
MCUXCLCSS_SETCSSINPUT0((options.bits.echashchl == 0u) ? pInputHash : pInputMessage, inputMessageLength);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_ECSIGN, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_EccSign_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_EccVerify_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_EccVerify_Async(
mcuxClCss_EccVerifyOption_t options,
uint8_t const * pInputHash,
uint8_t const * pInputMessage,
size_t inputMessageLength,
uint8_t const * pSignatureAndPubKey,
uint8_t * pOutput)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_EccVerify_Async);
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_EccVerify_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
options.bits.revf = MCUXCLCSS_REVERSEFETCH_ENABLE;
MCUXCLCSS_SETCSSINPUT0((options.bits.echashchl == 0u) ? pInputHash : pInputMessage, inputMessageLength);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pSignatureAndPubKey);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_ECVFY, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_EccVerify_Async, MCUXCLCSS_STATUS_OK_WAIT);
}

View File

@ -1,216 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClCss_Hash.c
* @brief CSSv2 implementation for hashing.
* This file implements the functions declared in mcuxClCss_Hash.h. */
#include <mcuxClCss_Hash.h>
#include <mcuxClMemory.h>
#include <mcuxCsslFlowProtection.h>
#include <stdbool.h>
#include <mcuxClCss.h>
#include <internal/mcuxClCss_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Hash_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hash_Async(
mcuxClCss_HashOption_t options,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pDigest)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Hash_Async);
/* Length must not be zero and aligned with the block length */
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Hash_Async,
false
|| ((MCUXCLCSS_HASH_MODE_SHA_224 == options.bits.hashmd) && (0u != (inputLength % MCUXCLCSS_HASH_BLOCK_SIZE_SHA_224)))
|| ((MCUXCLCSS_HASH_MODE_SHA_256 == options.bits.hashmd) && (0u != (inputLength % MCUXCLCSS_HASH_BLOCK_SIZE_SHA_256)))
|| ((MCUXCLCSS_HASH_RTF_UPDATE_ENABLE == options.bits.rtfupd) && (MCUXCLCSS_HASH_MODE_SHA_256 != options.bits.hashmd))
|| ((MCUXCLCSS_HASH_RTF_UPDATE_ENABLE != options.bits.rtfupd) && (MCUXCLCSS_HASH_RTF_OUTPUT_ENABLE == options.bits.rtfoe))
|| ((MCUXCLCSS_HASH_OUTPUT_ENABLE != options.bits.hashoe) && (MCUXCLCSS_HASH_RTF_OUTPUT_ENABLE == options.bits.rtfoe))
|| ((MCUXCLCSS_HASH_MODE_SHA_384 == options.bits.hashmd) && (0u != (inputLength % MCUXCLCSS_HASH_BLOCK_SIZE_SHA_384)))
|| ((MCUXCLCSS_HASH_MODE_SHA_512 == options.bits.hashmd) && (0u != (inputLength % MCUXCLCSS_HASH_BLOCK_SIZE_SHA_512)))
);
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hash_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT0(pInput, inputLength);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pDigest);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pDigest);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_HASH, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hash_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_ShaDirect_Enable)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_ShaDirect_Enable(
void)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_ShaDirect_Enable);
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_ShaDirect_Enable, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
IP_CSS->CSS_CFG_b.SHA2_DIRECT = 1;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_ShaDirect_Enable, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_ShaDirect_Disable)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_ShaDirect_Disable(
void)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_ShaDirect_Disable);
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_ShaDirect_Disable, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
IP_CSS->CSS_CFG_b.SHA2_DIRECT = 0;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_ShaDirect_Disable, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Hash_ShaDirect)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hash_ShaDirect(
mcuxClCss_HashOption_t options,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pDigest,
mcuxClCss_TransferToRegisterFunction_t pCallback,
void * pCallerData)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Hash_ShaDirect);
/* Length must not be zero and aligned with the block length */
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Hash_ShaDirect,
false
|| (0u == inputLength)
|| ((MCUXCLCSS_HASH_MODE_SHA_224 == options.bits.hashmd) && (0u != (inputLength % MCUXCLCSS_HASH_BLOCK_SIZE_SHA_224)))
|| ((MCUXCLCSS_HASH_MODE_SHA_256 == options.bits.hashmd) && (0u != (inputLength % MCUXCLCSS_HASH_BLOCK_SIZE_SHA_256)))
|| ((MCUXCLCSS_HASH_MODE_SHA_384 == options.bits.hashmd) && (0u != (inputLength % MCUXCLCSS_HASH_BLOCK_SIZE_SHA_384)))
|| ((MCUXCLCSS_HASH_MODE_SHA_512 == options.bits.hashmd) && (0u != (inputLength % MCUXCLCSS_HASH_BLOCK_SIZE_SHA_512)))
);
size_t state_size = MCUXCLCSS_HASH_STATE_SIZE_SHA_256;
if (MCUXCLCSS_HASH_MODE_SHA_512 == options.bits.hashmd)
{
state_size = MCUXCLCSS_HASH_STATE_SIZE_SHA_512;
}
#ifdef MCUXCLCSS_HASH_MODE_SHA_384
if (MCUXCLCSS_HASH_MODE_SHA_384 == options.bits.hashmd)
{
state_size = MCUXCLCSS_HASH_STATE_SIZE_SHA_512;
}
#endif
/* Check for SHA Direct mode */
if (1u != IP_CSS->CSS_CFG_b.SHA2_DIRECT)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hash_ShaDirect, MCUXCLCSS_STATUS_SW_INVALID_STATE);
}
/* Check if SHA Direct is busy */
if (1u == IP_CSS->CSS_SHA2_STATUS_b.SHA2_BUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hash_ShaDirect, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
/* Get hash mode */
uint32_t hash_mode = options.bits.hashmd;
if (1u == options.bits.hashini) {
/* Set the SHA IV */
IP_CSS->CSS_SHA2_CTRL = 0u;
IP_CSS->CSS_SHA2_CTRL = ((uint32_t) 1u << CSS_SHA2_CTRL_SHA2_START_Pos) | ((uint32_t) 1u << CSS_SHA2_CTRL_SHA2_INIT_Pos)
| (hash_mode << CSS_SHA2_CTRL_SHA2_MODE_Pos)
| ((uint32_t) 1u << CSS_SHA2_CTRL_SHA2_BYTE_ORDER_Pos);
}
if (1u == options.bits.hashld) {
/* Load previous state from pHash */
IP_CSS->CSS_SHA2_CTRL = 0u;
IP_CSS->CSS_SHA2_CTRL = ((uint32_t) 1u << CSS_SHA2_CTRL_SHA2_LOAD_Pos)
| (hash_mode << CSS_SHA2_CTRL_SHA2_MODE_Pos)
| ((uint32_t) 1u << CSS_SHA2_CTRL_SHA2_BYTE_ORDER_Pos);
for (size_t i = 0; i < state_size; i += sizeof(uint32_t))
{
IP_CSS->CSS_SHA2_DIN = mcuxClMemory_LoadLittleEndian32(&pDigest[i]);
}
IP_CSS->CSS_SHA2_CTRL = 0u;
IP_CSS->CSS_SHA2_CTRL = ((uint32_t) 1u << CSS_SHA2_CTRL_SHA2_START_Pos)
| (hash_mode << CSS_SHA2_CTRL_SHA2_MODE_Pos)
| ((uint32_t) 1u << CSS_SHA2_CTRL_SHA2_BYTE_ORDER_Pos);
}
if (NULL != pCallback)
{
/* Use callback function to import data into CSS */
if ( MCUXCLCSS_STATUS_OK != pCallback(&(IP_CSS->CSS_SHA2_DIN), pInput, inputLength, pCallerData))
{
/* Callback function returned with an error */
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hash_ShaDirect, MCUXCLCSS_STATUS_SW_FAULT);
}
}
else
{
/* Use CPU copy to import data into CSS */
for (size_t i = 0; i < inputLength; i += sizeof(uint32_t))
{
IP_CSS->CSS_SHA2_DIN = mcuxClMemory_LoadLittleEndian32(&pInput[i]);
}
}
/* Busy wait to */
while (1u == IP_CSS->CSS_SHA2_STATUS_b.SHA2_BUSY)
{
// Do nothing
}
/* Output the result */
if (1u == options.bits.hashoe)
{
/* Final hash value will be written to pDigest */
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 0U], IP_CSS->CSS_SHA2_DOUT0);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 1U], IP_CSS->CSS_SHA2_DOUT1);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 2U], IP_CSS->CSS_SHA2_DOUT2);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 3U], IP_CSS->CSS_SHA2_DOUT3);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 4U], IP_CSS->CSS_SHA2_DOUT4);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 5U], IP_CSS->CSS_SHA2_DOUT5);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 6U], IP_CSS->CSS_SHA2_DOUT6);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 7U], IP_CSS->CSS_SHA2_DOUT7);
#ifdef MCUXCLCSS_HASH_MODE_SHA_512
if (MCUXCLCSS_HASH_STATE_SIZE_SHA_512 == state_size)
{
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 8U], IP_CSS->CSS_SHA2_DOUT8);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 9U], IP_CSS->CSS_SHA2_DOUT9);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 10U], IP_CSS->CSS_SHA2_DOUT10);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 11U], IP_CSS->CSS_SHA2_DOUT11);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 12U], IP_CSS->CSS_SHA2_DOUT12);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 13U], IP_CSS->CSS_SHA2_DOUT13);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 14U], IP_CSS->CSS_SHA2_DOUT14);
mcuxClMemory_StoreLittleEndian32(&pDigest[sizeof(uint32_t) * 15U], IP_CSS->CSS_SHA2_DOUT15);
}
#endif
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hash_ShaDirect, MCUXCLCSS_STATUS_OK);
}

View File

@ -1,55 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClCss_Hmac.c
* @brief CSSv2 implementation for HMAC support.
* This file implements the functions declared in mcuxClCss_Hmac.h. */
#include <mcuxClCss_Hmac.h>
#include <mcuxCsslFlowProtection.h>
#include <platform_specific_headers.h>
#include <mcuxClCss.h>
#include <internal/mcuxClCss_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Hmac_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hmac_Async(
mcuxClCss_HmacOption_t options,
mcuxClCss_KeyIndex_t keyIdx,
uint8_t const * pPaddedKey,
uint8_t const * pInput,
size_t inputLength,
uint8_t * pOutput)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Hmac_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Hmac_Async, (0U == inputLength) || (MCUXCLCSS_HMAC_EXTERNAL_KEY_DISABLE == options.bits.extkey && CSS_KS_CNT <= keyIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hmac_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
if (0U == options.bits.extkey)
{
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
}
else
{
MCUXCLCSS_SETCSSINPUT2_FIXEDSIZE(pPaddedKey);
}
MCUXCLCSS_SETCSSINPUT0(pInput, inputLength);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_HMAC, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hmac_Async, MCUXCLCSS_STATUS_OK_WAIT);
}

View File

@ -1,161 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClCss_Kdf.c
* @brief CSSv2 implementation for key derivation.
* This file implements the functions declared in mcuxClCss_Kdf.h. */
#include <mcuxClCss_Kdf.h>
#include <mcuxClCss_Hash.h>
#include <mcuxCsslFlowProtection.h>
#include <platform_specific_headers.h>
#include <mcuxClCss.h>
#include <internal/mcuxClCss_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Ckdf_Sp800108_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Ckdf_Sp800108_Async(
mcuxClCss_KeyIndex_t derivationKeyIdx,
mcuxClCss_KeyIndex_t targetKeyIdx,
mcuxClCss_KeyProp_t targetKeyProperties,
uint8_t const * pDerivationData)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Ckdf_Sp800108_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Ckdf_Sp800108_Async, (CSS_KS_CNT <= derivationKeyIdx) || (CSS_KS_CNT <= targetKeyIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Ckdf_Sp800108_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
mcuxClCss_CkdfOption_t option = {0};
option.bits.ckdf_algo = MCUXCLCSS_CKDF_ALGO_SP800108 ;
MCUXCLCSS_SETKEYSTOREINDEX0(derivationKeyIdx);
MCUXCLCSS_SETKEYSTOREINDEX1(targetKeyIdx);
MCUXCLCSS_SETREQUESTEDKEYPROPERTIES(targetKeyProperties);
MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pDerivationData);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_CKDF, option.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Ckdf_Sp800108_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Hkdf_Rfc5869_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hkdf_Rfc5869_Async(
mcuxClCss_HkdfOption_t options,
mcuxClCss_KeyIndex_t derivationKeyIdx,
mcuxClCss_KeyIndex_t targetKeyIdx,
mcuxClCss_KeyProp_t targetKeyProperties,
uint8_t const * pDerivationData)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Hkdf_Rfc5869_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Hkdf_Rfc5869_Async, (CSS_KS_CNT <= derivationKeyIdx) || (CSS_KS_CNT <= targetKeyIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hkdf_Rfc5869_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
options.bits.hkdf_algo = MCUXCLCSS_HKDF_ALGO_RFC5869;
MCUXCLCSS_SETKEYSTOREINDEX0(derivationKeyIdx);
MCUXCLCSS_SETKEYSTOREINDEX1(targetKeyIdx);
MCUXCLCSS_SETREQUESTEDKEYPROPERTIES(targetKeyProperties);
MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pDerivationData);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_HKDF, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hkdf_Rfc5869_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Hkdf_Sp80056c_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Hkdf_Sp80056c_Async(
mcuxClCss_KeyIndex_t derivationKeyIdx,
uint8_t * pTagetKey,
uint8_t const * pDerivationData,
size_t derivationDataLength)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Hkdf_Sp80056c_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Hkdf_Rfc5869_Async, (CSS_KS_CNT <= derivationKeyIdx) );
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hkdf_Rfc5869_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
mcuxClCss_HkdfOption_t options = {0};
options.bits.hkdf_algo = MCUXCLCSS_HKDF_ALGO_SP80056C;
MCUXCLCSS_SETKEYSTOREINDEX0(derivationKeyIdx);
MCUXCLCSS_SETCSSINPUT0(pDerivationData, derivationDataLength);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pTagetKey);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_HKDF, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Hkdf_Sp80056c_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async(
uint8_t const * pDerivationData,
mcuxClCss_KeyProp_t keyProperties,
mcuxClCss_KeyIndex_t keyIdx)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async, (CSS_KS_CNT <= keyIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
mcuxClCss_TlsOption_t options = {0};
options.bits.mode = MCUXCLCSS_TLS_INIT;
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
MCUXCLCSS_SETREQUESTEDKEYPROPERTIES(keyProperties);
MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pDerivationData);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_TLS, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_TlsGenerateMasterKeyFromPreMasterKey_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async(
uint8_t const * pDerivationData,
mcuxClCss_KeyProp_t keyProperties,
mcuxClCss_KeyIndex_t keyIdx)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async, ((CSS_KS_CNT - 4U) <= keyIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
mcuxClCss_TlsOption_t options = {0};
options.bits.mode = MCUXCLCSS_TLS_FINALIZE;
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
MCUXCLCSS_SETREQUESTEDKEYPROPERTIES(keyProperties);
MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pDerivationData);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_TLS, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_TlsGenerateSessionKeysFromMasterKey_Async, MCUXCLCSS_STATUS_OK_WAIT);
}

View File

@ -1,269 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClCss_KeyManagement.c
* @brief CSSv2 implementation for key management.
* This file implements the functions declared in mcuxClCss_KeyManagement.h. */
#include <mcuxClCss_KeyManagement.h> // Implement mcuxClCss interface "KeyManagement"
#include <mcuxCsslFlowProtection.h>
#include <platform_specific_headers.h>
#include <mcuxClCss.h>
#include <mcuxClMemory.h>
#include <internal/mcuxClCss_Internal.h>
// Implementation of mcuxClCss interface "KeyManagement"
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_KeyDelete_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_KeyDelete_Async(
mcuxClCss_KeyIndex_t keyIdx)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_KeyDelete_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_KeyDelete_Async, (CSS_KS_CNT <= keyIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyDelete_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETKEYSTOREINDEX0(keyIdx);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_KDELETE, 0U, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyDelete_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_KeyImport_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_KeyImport_Async(
mcuxClCss_KeyImportOption_t options,
uint8_t const * pImportKey,
size_t importKeyLength,
mcuxClCss_KeyIndex_t wrappingKeyIdx,
mcuxClCss_KeyIndex_t targetKeyIdx)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_KeyImport_Async);
/* Key indices out of bounds or the source key pointer is NULL although the key format indicates that it should be imported from memory */
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_KeyImport_Async,
(wrappingKeyIdx >= CSS_KS_CNT)
|| (targetKeyIdx >= CSS_KS_CNT)
|| ((options.bits.kfmt == MCUXCLCSS_KEYIMPORT_KFMT_RFC3394) && (importKeyLength == 0u)));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyImport_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETKEYSTOREINDEX0(wrappingKeyIdx);
MCUXCLCSS_SETKEYSTOREINDEX1(targetKeyIdx);
MCUXCLCSS_SETCSSINPUT0(pImportKey, importKeyLength);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_KEYIN, options.word.value, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyImport_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
static mcuxClCss_Status_Protected_t handleKeyExportError(uint8_t *pOutput, size_t key_length, mcuxClCss_InterruptOptionEn_t interrupt_state_old)
{
/* Clear the interrupt state */
mcuxClCss_InterruptOptionRst_t interrupt_options_1 = {0U};
interrupt_options_1.bits.cssint = MCUXCLCSS_CSS_RESET_CLEAR;
// no FP in this call since mcuxClCss_ResetIntFlags always returns OK
(void)mcuxClCss_ResetIntFlags(interrupt_options_1);
/* Restore the CSS interrupt settings */
// no FP in this call since mcuxClCss_SetIntEnableFlags always returns OK
(void)mcuxClCss_SetIntEnableFlags(interrupt_state_old);
/* clear the memory to which the key was exported */
// no FP in this call since MCUXCLCSS_STATUS_SW_FAULT gets returned anyway
(void)mcuxClMemory_set(pOutput, 0x00, key_length, key_length);
return MCUXCLCSS_STATUS_SW_FAULT;
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_KeyExport_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_KeyExport_Async(
mcuxClCss_KeyIndex_t wrappingKeyIdx,
mcuxClCss_KeyIndex_t exportKeyIdx,
uint8_t * pOutput)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_KeyExport_Async);
/* Key indices out of bounds or the source key pointer is NULL although the key format indicates that it should be imported from memory */
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_KeyExport_Async, wrappingKeyIdx >= CSS_KS_CNT || exportKeyIdx >= CSS_KS_CNT);
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
/* CSS KEYOUT */
MCUXCLCSS_SETKEYSTOREINDEX0(wrappingKeyIdx);
MCUXCLCSS_SETKEYSTOREINDEX1(exportKeyIdx);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput);
MCUX_CSSL_FP_EXPECT(
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_GetIntEnableFlags),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_SetIntEnableFlags));
/* Save current CSS interrupts state */
mcuxClCss_InterruptOptionEn_t interrupt_state;
MCUX_CSSL_FP_FUNCTION_CALL(status_get, mcuxClCss_GetIntEnableFlags(&interrupt_state));
if(MCUXCLCSS_STATUS_OK != status_get)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async, MCUXCLCSS_STATUS_SW_FAULT);
}
/* Disable CSS interrupts */
mcuxClCss_InterruptOptionEn_t interrupt_state_new = interrupt_state;
interrupt_state_new.bits.cssint = MCUXCLCSS_CSS_INTERRUPT_DISABLE;
MCUX_CSSL_FP_FUNCTION_CALL(status_set, mcuxClCss_SetIntEnableFlags(interrupt_state_new));
if(MCUXCLCSS_STATUS_OK != status_set)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async, MCUXCLCSS_STATUS_SW_FAULT);
}
/* Start KEYOUT command */
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_KEYOUT, 0U, CSS_CMD_BIG_ENDIAN);
MCUX_CSSL_FP_EXPECT(
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_WaitForOperation));
/* Wait for operation CSS KEYOUT */
MCUX_CSSL_FP_FUNCTION_CALL(status_wait, mcuxClCss_WaitForOperation(MCUXCLCSS_ERROR_FLAGS_KEEP)); // flags not cleared because the error is caught in the wait for operation after this function exits
if(MCUXCLCSS_STATUS_OK != status_wait)
{
// no FP in this call since mcuxClCss_SetIntEnableFlags always returns OK
// In case of interrupt driven operation the error will be caught by the interrupt handler since re-enabling the interrupt when CSS_IRQ is set will immediately trigger an interrupt
(void)mcuxClCss_SetIntEnableFlags(interrupt_state);
// OK_WAIT is returned here so that the error can be captured by the wait for operation following this function
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_EXPECT(
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_GetKeyProperties),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_KeyDelete_Async),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_WaitForOperation),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_KeyImport_Async),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_WaitForOperation),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_SetIntEnableFlags));
/* Save key properties */
mcuxClCss_KeyProp_t key_properties;
MCUX_CSSL_FP_FUNCTION_CALL(status_keyprop, mcuxClCss_GetKeyProperties(exportKeyIdx, &key_properties));
if(MCUXCLCSS_STATUS_OK != status_keyprop)
{
// no FP in this call since mcuxClCss_SetIntEnableFlags always returns OK
(void)mcuxClCss_SetIntEnableFlags(interrupt_state);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async, MCUXCLCSS_STATUS_SW_FAULT);
}
size_t key_length = (key_properties.bits.ksize == MCUXCLCSS_KEYPROPERTY_KEY_SIZE_128) ? MCUXCLCSS_RFC3394_CONTAINER_SIZE_128 : MCUXCLCSS_RFC3394_CONTAINER_SIZE_256;
/* CSS KDELETE */
MCUX_CSSL_FP_FUNCTION_CALL(status_delete, mcuxClCss_KeyDelete_Async(exportKeyIdx));
if(MCUXCLCSS_STATUS_OK_WAIT != status_delete)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async,
handleKeyExportError(pOutput, key_length, interrupt_state),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_set));
}
/* wait for CSS KDELETE */
MCUX_CSSL_FP_FUNCTION_CALL(status_wait1, mcuxClCss_WaitForOperation(MCUXCLCSS_ERROR_FLAGS_CLEAR));
if(MCUXCLCSS_STATUS_OK != status_wait1)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async,
handleKeyExportError(pOutput, key_length, interrupt_state),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_set));
}
/* CSS KEYIN */
mcuxClCss_KeyImportOption_t import_options;
import_options.word.value = 0U;
import_options.bits.kfmt = MCUXCLCSS_KEYIMPORT_KFMT_RFC3394;
MCUX_CSSL_FP_FUNCTION_CALL(status_import,
mcuxClCss_KeyImport_Async(
import_options,
pOutput,
key_length,
wrappingKeyIdx,
exportKeyIdx
));
if(MCUXCLCSS_STATUS_OK_WAIT != status_import)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async,
handleKeyExportError(pOutput, key_length, interrupt_state),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_set));
}
/* wait for CSS KEYIN */
MCUX_CSSL_FP_FUNCTION_CALL(status_wait2, mcuxClCss_WaitForOperation(MCUXCLCSS_ERROR_FLAGS_CLEAR));
if(MCUXCLCSS_STATUS_OK != status_wait2)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async,
handleKeyExportError(pOutput, key_length, interrupt_state),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_set));
}
/* Restore CSS interrupt state - will trigger an interrupt immediately if interrupt is enabled since CSS_IRQ is expected to be set at this point */
MCUX_CSSL_FP_FUNCTION_CALL(status_set1, mcuxClCss_SetIntEnableFlags(interrupt_state));
if(MCUXCLCSS_STATUS_OK != status_set1)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async, MCUXCLCSS_STATUS_SW_FAULT);
}
/* Exit function */
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_KeyExport_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
/** Exports the properties of the keys stored in the CSS internal keystore */
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_GetKeyProperties)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_GetKeyProperties(
mcuxClCss_KeyIndex_t keyIdx,
mcuxClCss_KeyProp_t * pKeyProp
)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_GetKeyProperties);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_GetKeyProperties, (CSS_KS_CNT <= keyIdx));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_GetKeyProperties, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
pKeyProp->word.value = ((const volatile uint32_t *) (&IP_CSS->CSS_KS0))[keyIdx];
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_GetKeyProperties, MCUXCLCSS_STATUS_OK);
}

View File

@ -1,281 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClCss_Rng.c
* @brief CSSv2 implementation for random number generation.
* This file implements the functions declared in mcuxClCss_Rng.h.
*/
#include <mcuxClCss_Rng.h> // Implement mcuxClCss interface "Rng"
#include <mcuxClMemory.h>
#include <mcuxCsslFlowProtection.h>
#include <toolchain.h>
#include <mcuxClCss.h>
#include <internal/mcuxClCss_Internal.h>
#define RANDOM_BIT_ARRAY_SIZE 4U
#define DRBG_TEST_MODE_INSTANTIATE ((uint32_t)0U)
#define DRBG_TEST_MODE_EXTRACT ((uint32_t)1U)
#define DRBG_TEST_MODE_AES_ECB ((uint32_t)3U)
#define DRBG_TEST_MODE_AES_CTR ((uint32_t)2U)
// Command name change -- should move to top level platform header
#ifndef ID_CFG_CSS_CMD_RND_REQ
#define ID_CFG_CSS_CMD_RND_REQ ID_CFG_CSS_CMD_DRBG_REQ
#endif
// Utility code of mcuxClCss implementation for PRNG access
/**
* Gets a pseudo-random 32-bit integer from the CSS PRNG.
*/
static inline uint32_t css_getPRNGWord(
void)
{
return IP_CSS->CSS_PRNG_DATOUT_b.PRNG_DATOUT;
}
// Implementation of mcuxClCss interface "Rng"
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Rng_DrbgRequest_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgRequest_Async(
uint8_t * pOutput,
size_t outputLength)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Rng_DrbgRequest_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Rng_DrbgRequest_Async, (MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MIN_SIZE > outputLength) ||
(MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MAX_SIZE < outputLength) ||
(0U != outputLength % 4U));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgRequest_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSOUTPUT(pOutput, outputLength);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_RND_REQ, 0U, CSS_CMD_LITTLE_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgRequest_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Rng_DrbgTestInstantiate_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgTestInstantiate_Async(
uint8_t const * pEntropy)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Rng_DrbgTestInstantiate_Async);
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgTestInstantiate_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pEntropy);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_DRBG_TEST, DRBG_TEST_MODE_INSTANTIATE, CSS_CMD_LITTLE_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgTestInstantiate_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Rng_DrbgTestExtract_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgTestExtract_Async(
uint8_t * pOutput,
size_t outputLength)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Rng_DrbgTestExtract_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Rng_DrbgTestExtract_Async, (MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MIN_SIZE > outputLength) ||
(MCUXCLCSS_RNG_DRBG_TEST_EXTRACT_OUTPUT_MAX_SIZE < outputLength) ||
(0U != outputLength % 4U));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgTestExtract_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSOUTPUT(pOutput, outputLength);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_DRBG_TEST, DRBG_TEST_MODE_EXTRACT, CSS_CMD_LITTLE_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgTestExtract_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Rng_DrbgTestAesEcb_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgTestAesEcb_Async(
uint8_t const * pDataKey,
uint8_t * pOutput)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Rng_DrbgTestAesEcb_Async);
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgTestAesEcb_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pDataKey);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_DRBG_TEST, DRBG_TEST_MODE_AES_ECB, CSS_CMD_LITTLE_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgTestAesEcb_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Rng_DrbgTestAesCtr_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_DrbgTestAesCtr_Async(
uint8_t const * pData,
size_t dataLength,
uint8_t const * pIvKey,
uint8_t * pOutput)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Rng_DrbgTestAesCtr_Async);
MCUXCLCSS_INPUT_PARAM_CHECK_PROTECTED(mcuxClCss_Rng_DrbgTestAesCtr_Async, (0U != (dataLength % 16U)) || (0U == dataLength));
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgTestAesCtr_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT0(pData, dataLength);
MCUXCLCSS_SETCSSINPUT1_FIXEDSIZE(pIvKey);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_DRBG_TEST, DRBG_TEST_MODE_AES_CTR, CSS_CMD_LITTLE_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_DrbgTestAesCtr_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Rng_Dtrng_ConfigLoad_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_Dtrng_ConfigLoad_Async(
uint8_t const * pInput)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Rng_Dtrng_ConfigLoad_Async);
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_Dtrng_ConfigLoad_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pInput);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_DTRNG_CFG_LOAD, 0U, CSS_CMD_LITTLE_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_Dtrng_ConfigLoad_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Rng_Dtrng_ConfigEvaluate_Async)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Rng_Dtrng_ConfigEvaluate_Async(
uint8_t const * pInput,
uint8_t * pOutput)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Rng_Dtrng_ConfigEvaluate_Async);
/* CSS SFRs are not cached => Tell SW to wait for CSS to come back from BUSY state before modifying the SFRs */
if (MCUXCLCSS_ISBUSY)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_Dtrng_ConfigEvaluate_Async, MCUXCLCSS_STATUS_SW_CANNOT_INTERRUPT);
}
MCUXCLCSS_SETCSSINPUT0_FIXEDSIZE(pInput);
MCUXCLCSS_SETCSSOUTPUT_FIXEDSIZE(pOutput);
MCUXCLCSS_STARTCOMMAND(ID_CFG_CSS_CMD_DTRNG_EVAL, 0U, CSS_CMD_LITTLE_ENDIAN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Rng_Dtrng_ConfigEvaluate_Async, MCUXCLCSS_STATUS_OK_WAIT);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Prng_GetRandomWord)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Prng_GetRandomWord(
uint32_t * pWord)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Prng_GetRandomWord);
*pWord = css_getPRNGWord();
/* check if enough entropy is available */
if (1U == IP_CSS->CSS_ERR_STATUS_b.PRNG_ERR)
{
/* clear CSS error flags */
(void) mcuxClCss_ResetErrorFlags(); /* always returns MCUXCLCSS_STATUS_OK. */
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Prng_GetRandomWord, MCUXCLCSS_STATUS_HW_PRNG);
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Prng_GetRandomWord, MCUXCLCSS_STATUS_OK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClCss_Prng_GetRandom)
MCUXCLCSS_API mcuxClCss_Status_Protected_t mcuxClCss_Prng_GetRandom(
uint8_t * pOutput,
size_t outputLength)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClCss_Prng_GetRandom);
uint8_t * bytePtr = pOutput;
uint8_t * const pOutputEnd = pOutput + outputLength;
/* Fetch one word of PRNG and fill the leading "not word aligned" bytes */
if (0u != ((uint32_t) bytePtr & 0x03u))
{
uint32_t randomWord = css_getPRNGWord();
do
{
*bytePtr = (uint8_t) (randomWord & 0xFFu);
bytePtr += 1u;
randomWord >>= 8u;
} while ((0u != ((uint32_t) bytePtr & 0x03u)) && (pOutputEnd > bytePtr));
}
/* Fill the specified buffer wordwise */
uint8_t * const pOutputWordEnd = (uint8_t*) ((uint32_t) pOutputEnd & 0xFFFFFFFCu);
while (pOutputWordEnd > bytePtr)
{
mcuxClMemory_StoreLittleEndian32(bytePtr, css_getPRNGWord());
bytePtr += 4;
}
/* Fetch one word of PRNG and fill the remaining "less than one word" bytes */
if (pOutputEnd > bytePtr)
{
uint32_t randomWord = css_getPRNGWord();
do
{
*bytePtr = (uint8_t) (randomWord & 0xFFu);
bytePtr += 1u;
randomWord >>= 8u;
} while (pOutputEnd > bytePtr);
}
/* check if enough entropy is available */
if (1U == IP_CSS->CSS_ERR_STATUS_b.PRNG_ERR)
{
/* clear CSS error flags */
(void) mcuxClCss_ResetErrorFlags(); /* always returns MCUXCLCSS_STATUS_OK. */
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Prng_GetRandom, MCUXCLCSS_STATUS_HW_PRNG);
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClCss_Prng_GetRandom, MCUXCLCSS_STATUS_OK);
}

View File

@ -1,75 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Curve_P384.h
* @brief Curve P-384 parameters
*/
#ifndef MCUXCLECC_CURVE_P384_H_
#define MCUXCLECC_CURVE_P384_H_
#define MCUXCLECC_CURVE_P384_PRIME_P_LO192 \
0xFFFFFFFFu, 0x00000000u, 0x00000000u, 0xFFFFFFFFu, 0xFFFFFFFEu, 0xFFFFFFFFu
#define MCUXCLECC_CURVE_P384_PRIME_P_HI192 \
0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu
#define MCUXCLECC_CURVE_P384_PRIME_P \
MCUXCLECC_CURVE_P384_PRIME_P_LO192, MCUXCLECC_CURVE_P384_PRIME_P_HI192
#define MCUXCLECC_CURVE_P384_PRIME_P_BYTELEN 48u
#define MCUXCLECC_CURVE_P384_PRIME_P_LOWHALF_BYTELEN 24u
#define MCUXCLECC_CURVE_P384_PRIME_P_NDASH \
0x00000001u, 0x00000001u
#define MCUXCLECC_CURVE_P384_PRIME_P_QSQR \
0x00000001u, 0xFFFFFFFEu, 0x00000000u, 0x00000002u, 0x00000000u, 0xFFFFFFFEu, \
0x00000000u, 0x00000002u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u
#define MCUXCLECC_CURVE_P384_COEFFICIENT_A \
0xFFFFFFFCu, 0x00000000u, 0x00000000u, 0xFFFFFFFFu, 0xFFFFFFFEu, 0xFFFFFFFFu, \
0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu
#define MCUXCLECC_CURVE_P384_COEFFICIENT_B \
0xD3EC2AEFu, 0x2A85C8EDu, 0x8A2ED19Du, 0xC656398Du, 0x5013875Au, 0x0314088Fu, \
0xFE814112u, 0x181D9C6Eu, 0xE3F82D19u, 0x988E056Bu, 0xE23EE7E4u, 0xB3312FA7u
#define MCUXCLECC_CURVE_P384_BASEPOINT_X \
0x72760AB7u, 0x3A545E38u, 0xBF55296Cu, 0x5502F25Du, 0x82542A38u, 0x59F741E0u, \
0x8BA79B98u, 0x6E1D3B62u, 0xF320AD74u, 0x8EB1C71Eu, 0xBE8B0537u, 0xAA87CA22u
#define MCUXCLECC_CURVE_P384_BASEPOINT_Y \
0x90EA0E5Fu, 0x7A431D7Cu, 0x1D7E819Du, 0x0A60B1CEu, 0xB5F0B8C0u, 0xE9DA3113u, \
0x289A147Cu, 0xF8F41DBDu, 0x9292DC29u, 0x5D9E98BFu, 0x96262C6Fu, 0x3617DE4Au
#define MCUXCLECC_CURVE_P384_ORDER_N_LO192 \
0xCCC52973u, 0xECEC196Au, 0x48B0A77Au, 0x581A0DB2u, 0xF4372DDFu, 0xC7634D81u
#define MCUXCLECC_CURVE_P384_ORDER_N_HI192 \
0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu
#define MCUXCLECC_CURVE_P384_ORDER_N \
MCUXCLECC_CURVE_P384_ORDER_N_LO192, MCUXCLECC_CURVE_P384_ORDER_N_HI192
#define MCUXCLECC_CURVE_P384_ORDER_N_BYTELEN 48u
#define MCUXCLECC_CURVE_P384_ORDER_N_LOWHALF_BYTELEN 24u
#define MCUXCLECC_CURVE_P384_ORDER_N_NDASH \
0xE88FDC45u, 0x6ED46089u
#define MCUXCLECC_CURVE_P384_PRECBP_X \
0xAA03BD53u, 0xA628B09Au, 0xA4F52D78u, 0xBA065458u, 0x4D10DDEAu, 0xDB298789u, \
0x8A3E297Du, 0xB42A31AFu, 0x06421279u, 0x40F7F9E7u, 0x800119C4u, 0xC19E0B4Cu
#define MCUXCLECC_CURVE_P384_PRECBP_Y \
0xE6C88C41u, 0x822D0FC5u, 0xE639D858u, 0xAF68AA6Du, 0x35F6EBF2u, 0xC1C7CAD1u, \
0xE3567AF9u, 0x577A30EAu, 0x1F5B77F6u, 0xE5A0191Du, 0x0356B301u, 0x16F3FDBFu
#endif

View File

@ -1,393 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal.h
* @brief Internal header of mcuxClEcc component
*/
#ifndef MCUXCLECC_INTERNAL_H_
#define MCUXCLECC_INTERNAL_H_
#include <stdbool.h>
#include <mcuxClMemory.h>
#include <mcuxCsslFlowProtection.h>
#include <internal/mcuxClPkc_FupMacros.h>
#include <mcuxClEcc_FUP.h>
#include <mcuxClEcc_Internal_KeyGen_FUP.h>
#include <mcuxClEcc_KeyGen_FUP.h>
#include <mcuxClEcc_Sign_FUP.h>
#include <mcuxClEcc_PointMult_FUP.h>
#include <mcuxClEcc_Internal_PointCheck_FUP.h>
#include <mcuxClEcc_Internal_SecurePointMult_CoZMontLadder_FUP.h>
#include <mcuxClEcc_Internal_FUP.h>
#include <mcuxClEcc.h>
/**********************************************************/
/* Internal return codes of mcuxClEcc */
/**********************************************************/
#define MCUXCLECC_INTSTATUS_POINTCHECK_OK ((mcuxClEcc_Status_t) 0x55AAC33Cu)
#define MCUXCLECC_INTSTATUS_POINTCHECK_NOTOK ((mcuxClEcc_Status_t) 0x55AAE817u)
#define MCUXCLECC_INTSTATUS_POINTADD_OK ((mcuxClEcc_Status_t) 0x55AAC639u)
#define MCUXCLECC_INTSTATUS_POINTADD_NEUTRAL_POINT ((mcuxClEcc_Status_t) 0x55AAD12Eu)
#define MCUXCLECC_INTSTATUS_RNG_ERROR ((mcuxClEcc_Status_t) 0x55AAD827u)
/* Rule of ECC return codes:
* All return codes are of the format: 0x55XXYYTT
* API : XX = 55
* Internal : XX = AA
* HammingWeight(YY) = HammingWeight(TT) = 4, according to coding guidelines
* YY needs to be a balanced byte, and TT = ~YY
*
* General OK : YYTT = 5555
* Fault Attack : YYTT = F00F
*/
/**********************************************************/
/* Indices of operands in PKC workarea and UPTR table */
/**********************************************************/
#define ECC_P 0x00u
#define ECC_N 0x01u
#define ECC_VT2 0x02u
#define ECC_VT3 0x03u
#define ECC_VX0 0x04u
#define ECC_VY0 0x05u
#define ECC_VZ0 0x06u
#define ECC_VZ 0x07u
#define ECC_VX1 0x08u
#define ECC_VY1 0x09u
#define ECC_VA 0x0Au
#define ECC_VB 0x0Bu
#define ECC_VX2 0x0Cu
#define ECC_VY2 0x0Du
#define ECC_VZ2 0x0Eu
#define ECC_VT 0x0Fu
#define ECC_PS 0x10u
#define ECC_NS 0x11u
#define ECC_R0 0x12u
#define ECC_R1 0x13u
#define ECC_PFULL 0x14u
#define ECC_NFULL 0x15u
#define ECC_PQSQR 0x16u
#define ECC_NQSQR 0x17u
#define ECC_S0 0x18u
#define ECC_S1 0x19u
#define ECC_S2 0x1Au
#define ECC_S3 0x1Bu
#define ECC_T0 0x1Cu
#define ECC_T1 0x1Du
#define ECC_T2 0x1Eu
#define ECC_T3 0x1Fu
#define ECC_XA 0x20u
#define ECC_YA 0x21u
#define ECC_ZA 0x22u
#define ECC_Z 0x23u
#define ECC_X0 0x24u
#define ECC_Y0 0x25u
#define ECC_X1 0x26u
#define ECC_Y1 0x27u
#define ECC_X2 0x28u
#define ECC_Y2 0x29u
#define ECC_X3 0x2Au
#define ECC_Y3 0x2Bu
#define ECC_KEYGEN_NO_OF_VIRTUALS 0x10u
#define ECC_KEYGEN_NO_OF_BUFFERS0 0x8u /* PS ~ NQSQR */
#define ECC_KEYGEN_NO_OF_BUFFERS1 0x8u /* S0 ~ T3, interleaved (double-size) */
#define ECC_KEYGEN_NO_OF_BUFFERS2 0x8u /* XA ~ Y1 */
#define ECC_KEYGEN_NO_OF_BUFFERS 0x18u
#define ECC_SIGN_NO_OF_VIRTUALS 0x10u
#define ECC_SIGN_NO_OF_BUFFERS0 0x8u /* PS ~ NQSQR */
#define ECC_SIGN_NO_OF_BUFFERS1 0x8u /* S0 ~ T3, interleaved (double-size) */
#define ECC_SIGN_NO_OF_BUFFERS2 0x8u /* XA ~ Y1 */
#define ECC_SIGN_NO_OF_BUFFERS 0x18u
#define ECC_VERIFY_NO_OF_VIRTUALS 0x10u
#define ECC_VERIFY_NO_OF_BUFFERS 0x1Cu
#define ECC_POINTMULT_NO_OF_VIRTUALS 0x10u
#define ECC_POINTMULT_NO_OF_BUFFERS 0x18u
/**********************************************************/
/* Helper macros for accessing UPTRT table */
/**********************************************************/
/** Macro for reading 2 offsets in UPTRT table.
* [in] pOps: pointer to 16-bit offset table. This pointer must be 32-bit aligned;
* [in] idx0, idx1: compile-time-constant indices of offsets in the table.
* @attention not compile-time-constant indices will cause extra code size.
* @attention if the two offsets are not in the same CPU word, this macro might cause extra code size.
*/
#define MCUXCLECC_LOAD_2OFFSETS(pOps, idx0, idx1) \
({ \
uint32_t offset1_offset0; \
if ( (0u == ((idx0) & (0x01u))) && ((idx1) == ((idx0) + (0x01u))) ) \
{ /* MISRA Ex. 9 - Rule 11.3 - UPTR table is 32-bit aligned in ECC component */ \
offset1_offset0 = ((uint32_t *) (pOps))[(idx0) / 2u]; \
} \
else \
{ /* MISRA Ex. 9 - Rule 11.3 - Cast to 16-bit pointer table */ \
offset1_offset0 = (uint32_t) ((uint16_t *) (pOps))[idx0] | ((uint32_t) ((uint16_t *) (pOps))[idx1] << 16); \
} \
(offset1_offset0); \
})
/** Macro for writing 2 offsets to UPTRT table.
* [in] pOps: pointer to 16-bit offset table. This pointer must be 32-bit aligned;
* [in] idx0, idx1: compile-time-constant indices of offsets in the table.
* @attention not compile-time-constant indices will cause extra code size.
* @attention if the two offsets are not in the same CPU word, this macro might cause extra code size.
*/
#define MCUXCLECC_STORE_2OFFSETS(pOps, idx0, idx1, ofs1_ofs0) \
do{ \
if ( (0u == ((idx0) & (0x01u))) && ((idx1) == ((idx0) + (0x01u))) ) \
{ /* MISRA Ex. 9 - Rule 11.3 - UPTR table is 32-bit aligned in ECC component */ \
((uint32_t *) (pOps))[(idx0) / 2u] = (ofs1_ofs0); \
} \
else \
{ /* MISRA Ex. 9 - Rule 11.3 - Cast to 16-bit pointer table */ \
((uint16_t *) (pOps))[idx0] = (uint16_t) ((ofs1_ofs0) & 0xFFFFu); \
((uint16_t *) (pOps))[idx1] = (uint16_t) ((ofs1_ofs0) >> 16); \
} \
} while(false)
/** Macro for copying 2 offsets in UPTRT table.
* [in] pOps: pointer to 16-bit offset table. This pointer must be 32-bit aligned;
* [in] dIdx0, dIdx1, sIdx0, sIdx1: compile-time-constant indices of offsets in the table.
* @attention not compile-time-constant indices will cause extra code size.
*/
#define MCUXCLECC_COPY_2OFFSETS(pOps, dIdx0, dIdx1, sIdx0, sIdx1) \
do{ \
if ( (0u == ((dIdx0) & (0x01u))) \
&& ((dIdx1) == ((dIdx0) + (0x01u))) \
&& (0u == ((sIdx0) & (0x01u))) \
&& ((sIdx1) == ((sIdx0) + (0x01u))) ) \
{ /* MISRA Ex. 9 - Rule 11.3 - UPTR table is 32-bit aligned in ECC component */ \
((uint32_t *) (pOps))[(dIdx0) / 2u] = ((uint32_t *) (pOps))[(sIdx0) / 2u]; \
} \
else \
{ /* MISRA Ex. 9 - Rule 11.3 - Cast to 16-bit pointer table */ \
((uint16_t *) (pOps))[dIdx0] = ((uint16_t *) (pOps))[sIdx0]; \
((uint16_t *) (pOps))[dIdx1] = ((uint16_t *) (pOps))[sIdx1]; \
} \
} while (false)
/**********************************************************/
/* Helper macros of import/export with flow protection */
/**********************************************************/
/** Helper macro to call #mcuxClMemory_copy with flow protection. */
#define MCUXCLECC_FP_MEMORY_COPY(pTarget, pSource, byteLen) \
do { \
MCUX_CSSL_FP_FUNCTION_CALL(retCodeTemp, \
mcuxClMemory_copy((uint8_t *) (pTarget), (const uint8_t *) (pSource), byteLen, byteLen)); \
(void) retCodeTemp; \
} while(false)
/** Helper macro to call #mcuxClMemory_copy for importing data to PKC workarea with flow protection. */
#define MCUXCLECC_FP_IMPORT_TO_PKC_BUFFER(pOffsetTable, iTarget, pSource, byteLen) \
MCUXCLECC_FP_MEMORY_COPY(MCUXCLPKC_OFFSET2PTR((pOffsetTable)[iTarget]), pSource, byteLen)
#define MCUXCLECC_FP_CALLED_MEMORY_COPY MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_copy)
#define MCUXCLECC_FP_CALLED_IMPORT_TO_PKC_BUFFER MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_copy)
/**********************************************************/
/* Internal function declaration */
/**********************************************************/
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Interleave(uint16_t iScalar0_iScalar1, uint32_t bitLenScalar);
/** Helper macro to call #mcuxClEcc_Interleave with flow protection. */
#define MCUXCLECC_FP_INTERLEAVE(iS0_iS1, bitLenScalar) \
do{ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_Interleave(iS0_iS1, bitLenScalar)); \
(void) retValTemp; /* Checking is unnecessary, because it always returns OK. */ \
} while (false)
/**********************************************************/
/* Internal function declaration - point check */
/**********************************************************/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_PointCheckAffineNR)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_PointCheckAffineNR(void);
/** Helper macro to call #mcuxClEcc_PointCheckAffineNR with flow protection. */
#define MCUXCLECC_FP_POINTCHECKAFFINENR() \
({ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_PointCheckAffineNR()); \
(retValTemp); \
})
/**********************************************************/
/* Internal function declaration - point arithmetic */
/**********************************************************/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_RepeatPointDouble)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_RepeatPointDouble(uint32_t iteration);
/** Helper macro to call #mcuxClEcc_RepeatPointDouble with flow protection. */
#define MCUXCLECC_FP_REPEATPOINTDOUBLE(iteration) \
do{ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_RepeatPointDouble(iteration)); \
(void) retValTemp; /* Checking is unnecessary, because it always returns OK. */ \
} while (false)
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_PointFullAdd)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_PointFullAdd(void);
/** Helper macro to call #mcuxClEcc_PointFullAdd with flow protection. */
#define MCUXCLECC_FP_POINTFULLADD() \
({ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_PointFullAdd()); \
(retValTemp); \
})
/**********************************************************/
/* Internal function declaration - point multiplication */
/**********************************************************/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Int_PointMult)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Int_PointMult(uint8_t iScalar, uint32_t scalarBitLen);
/** Helper macro to call #mcuxClEcc_Int_PointMult with flow protection. */
#define MCUXCLECC_FP_INT_POINTMULT(iScalar, scalarBitLen) \
do{ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_Int_PointMult(iScalar, scalarBitLen)); \
(void) retValTemp; /* Checking is unnecessary, because it always returns OK. */ \
} while (false)
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_SecurePointMult)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_SecurePointMult(uint8_t iScalar,
uint32_t scalarBitLen);
/** Helper macro to call #mcuxClEcc_SecurePointMult with flow protection. */
#define MCUXCLECC_FP_SECUREPOINTMULT(iScalar, scalarBitLen) \
do{ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_SecurePointMult(iScalar, scalarBitLen)); \
(void) retValTemp; /* Checking is unnecessary, because it always returns OK. */ \
} while (false)
/**********************************************************/
/* Internal function declaration - key generation */
/**********************************************************/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Int_CoreKeyGen)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Int_CoreKeyGen(mcuxClSession_Handle_t pSession,
uint32_t byteLenN);
/**********************************************************/
/* FUP program declaration */
/**********************************************************/
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Fup_RepeatDouble);
#define mcuxClEcc_Fup_RepeatDouble_Len1 5u
#define mcuxClEcc_Fup_RepeatDouble_Len2 16u
#define mcuxClEcc_Fup_RepeatDouble_Len3 3u
#define mcuxClEcc_Fup_RepeatDouble_Len 24u
#define MCUXCLECC_CALCFUP_ONE_DOUBLE() \
mcuxClPkc_CalcFup(mcuxClEcc_Fup_RepeatDouble, \
mcuxClEcc_Fup_RepeatDouble_Len1 \
+ mcuxClEcc_Fup_RepeatDouble_Len2)
#define MCUXCLECC_FP_CALCFUP_ONE_DOUBLE() \
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_RepeatDouble, \
mcuxClEcc_Fup_RepeatDouble_Len1 \
+ mcuxClEcc_Fup_RepeatDouble_Len2)
#define MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup)
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Fup_DoubleAdd);
#define mcuxClEcc_Fup_DoubleAdd_Len1 5u
#define mcuxClEcc_Fup_DoubleAdd_Len2 15u
#define mcuxClEcc_Fup_DoubleAdd_Len 20u
#define MCUXCLECC_CALCFUP_ADD_ONLY() \
mcuxClPkc_CalcFup(mcuxClEcc_Fup_DoubleAdd, mcuxClEcc_Fup_DoubleAdd_Len)
#define MCUXCLECC_FP_CALCFUP_ADD_ONLY() \
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_DoubleAdd, mcuxClEcc_Fup_DoubleAdd_Len)
#define MCUXCLECC_FP_CALLED_CALCFUP_ADD_ONLY MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup)
#define MCUXCLECC_CALCFUP_DOUBLE_ADD() \
do{ \
mcuxClPkc_CalcFup(mcuxClEcc_Fup_DoubleAdd, mcuxClEcc_Fup_DoubleAdd_Len); \
mcuxClPkc_CalcFup(mcuxClEcc_Fup_DoubleAdd + (mcuxClEcc_Fup_DoubleAdd_Len1 * 3u), \
mcuxClEcc_Fup_DoubleAdd_Len2); \
} while (false)
#define MCUXCLECC_FP_CALCFUP_DOUBLE_ADD() \
do{ \
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_DoubleAdd, mcuxClEcc_Fup_DoubleAdd_Len); \
MCUXCLPKC_FP_CALCFUP_OFFSET(mcuxClEcc_Fup_DoubleAdd, mcuxClEcc_Fup_DoubleAdd_Len1, \
mcuxClEcc_Fup_DoubleAdd_Len2); \
} while (false)
#define MCUXCLECC_FP_CALLED_CALCFUP_DOUBLE_ADD \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup)
/* mcuxClEcc_Internal_KeyGen.fup.c */
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Int_CoreKeyGen_Steps34);
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Int_CoreKeyGen_Steps56);
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Int_CoreKeyGen_Steps78);
#define mcuxClEcc_Int_CoreKeyGen_Steps34_LEN 6u
#define mcuxClEcc_Int_CoreKeyGen_Steps56_LEN 8u
#define mcuxClEcc_Int_CoreKeyGen_Steps78_LEN 11u
/* mcuxClEcc_KeyGen.fup.c */
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_KeyGen_Convert_PubKey);
#define mcuxClEcc_KeyGen_Convert_PubKey_LEN 11u
/* mcuxClEcc_Sign.fup.c */
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Sign_CalculateS);
#define mcuxClEcc_Sign_CalculateS_LEN 13u
/* mcuxClEcc_PointMult.fup.c */
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_PointMult_SplitScalar_ConvertPoint2MR);
#define mcuxClEcc_PointMult_SplitScalar_ConvertPoint2MR_LEN 10u
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Fup_PointCheckAffNR);
#define mcuxClEcc_Fup_PointCheckAffNR_LEN 10u
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Fup_CoZPointAddSub);
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1);
#define mcuxClEcc_Fup_CoZPointAddSub_LEN1 16u
#define mcuxClEcc_Fup_CoZPointAddSub_LEN2 7u
#define mcuxClEcc_Fup_CoZPointAddSub_LEN \
(mcuxClEcc_Fup_CoZPointAddSub_LEN1 + mcuxClEcc_Fup_CoZPointAddSub_LEN2)
#define mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN1 4u
#define mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN2 9u
#define mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN3 5u
#define mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN \
( mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN1 \
+ mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN2 \
+ mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN3 )
//MCUXCLPKC_FUP_EXT_ROM_DECLARE(mcuxClEcc_Fup_Interleave);
#define mcuxClEcc_Fup_Interleave_LEN 7u
#endif /* MCUXCLECC_INTERNAL_H_ */

View File

@ -1,214 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_FP.h
* @brief Internal header of flow protection in mcuxClEcc component
*/
#ifndef MCUXCLECC_INTERNAL_FP_H_
#define MCUXCLECC_INTERNAL_FP_H_
#define MCUXCLECC_FP_KEYGEN_INIT \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Initialize), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_GenerateUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_RandomizeUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_GenerateUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_RandomizeUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_GenerateUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_RandomizeUPTRT)
#define MCUXCLECC_FP_KEYGEN_CURVE_PARAM_0 \
MCUXCLECC_FP_KEYGEN_INIT, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc)
#define MCUXCLECC_FP_KEYGEN_CURVE_PARAM \
MCUXCLECC_FP_KEYGEN_CURVE_PARAM_0, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_NDash), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_NDash), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ShiftModulus), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ShiftModulus), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_QSquared), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_QSquared), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUXCLPKC_FP_CALLED_CALC_MC1_MM, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc)
#define MCUXCLECC_FP_KEYGEN_BASE_POINT \
MCUXCLECC_FP_KEYGEN_CURVE_PARAM, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_PointCheckAffineNR)
#define MCUXCLECC_FP_KEYGEN_GENERATE_PRIKEY \
MCUXCLECC_FP_KEYGEN_BASE_POINT, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Int_CoreKeyGen)
#define MCUXCLECC_FP_KEYGEN_CALC_PUBKEY \
MCUXCLECC_FP_KEYGEN_GENERATE_PRIKEY, \
MCUXCLPKC_FP_CALLED_CALC_MC1_MM, \
MCUXCLPKC_FP_CALLED_CALC_MC1_MM, \
MCUXCLPKC_FP_CALLED_CALC_OP1_NEG, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_SecurePointMult), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_SecurePointMult)
#define MCUXCLECC_FP_KEYGEN_CONVERT_PUBKEY \
MCUXCLECC_FP_KEYGEN_CALC_PUBKEY, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ModInv), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_PointCheckAffineNR)
#define MCUXCLECC_FP_KEYGEN_FINAL \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUXCLPKC_FP_CALLED_CALC_OP1_CMP, \
MCUXCLPKC_FP_CALLED_CALC_OP1_CMP, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_SecureExportBigEndianFromPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ExportBigEndianFromPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ExportBigEndianFromPkc), \
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize)
#define MCUXCLECC_FP_SIGN_INIT \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Initialize), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_GenerateUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_RandomizeUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_GenerateUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_RandomizeUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_GenerateUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_RandomizeUPTRT)
#define MCUXCLECC_FP_SIGN_CURVE_PARAM_0 \
MCUXCLECC_FP_SIGN_INIT, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc)
#define MCUXCLECC_FP_SIGN_CURVE_PARAM \
MCUXCLECC_FP_SIGN_CURVE_PARAM_0, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_NDash), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_NDash), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ShiftModulus), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ShiftModulus), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_QSquared), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_QSquared), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUXCLPKC_FP_CALLED_CALC_MC1_MM, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc)
#define MCUXCLECC_FP_SIGN_BEFORE_LOOP \
MCUXCLECC_FP_SIGN_CURVE_PARAM
#define MCUXCLECC_FP_SIGN_LOOP_R_0 \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_PointCheckAffineNR)
#define MCUXCLECC_FP_SIGN_LOOP_R_1 \
MCUXCLECC_FP_SIGN_LOOP_R_0, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Int_CoreKeyGen)
#define MCUXCLECC_FP_SIGN_LOOP_R \
MCUXCLECC_FP_SIGN_LOOP_R_1, \
MCUXCLPKC_FP_CALLED_CALC_MC1_MM, \
MCUXCLPKC_FP_CALLED_CALC_MC1_MM, \
MCUXCLPKC_FP_CALLED_CALC_OP1_NEG, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_SecurePointMult), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_SecurePointMult), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ModInv), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_PointCheckAffineNR), \
MCUXCLPKC_FP_CALLED_CALC_MC1_MS
#define MCUXCLECC_FP_SIGN_LOOP_S \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_SecureImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
\
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ModInv), \
MCUXCLPKC_FP_CALLED_CALC_MC1_MM, \
MCUXCLPKC_FP_CALLED_CALC_MC1_MS
#define MCUXCLECC_FP_SIGN_FINAL \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUXCLPKC_FP_CALLED_CALC_OP1_CMP, \
MCUXCLPKC_FP_CALLED_CALC_OP1_CMP, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ExportBigEndianFromPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ExportBigEndianFromPkc), \
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize)
#define MCUXCLECC_FP_POINTMULT_INIT \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Initialize), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_GenerateUPTRT), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_RandomizeUPTRT)
#define MCUXCLECC_FP_POINTMULT_CURVE_PARAM_0 \
MCUXCLECC_FP_POINTMULT_INIT, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc)
#define MCUXCLECC_FP_POINTMULT_CURVE_PARAM \
MCUXCLECC_FP_POINTMULT_CURVE_PARAM_0, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_NDash), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_NDash), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ShiftModulus), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ShiftModulus), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_QSquared), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_QDash), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUXCLPKC_FP_CALLED_CALC_MC1_MM, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc)
#define MCUXCLECC_FP_POINTMULT_BASE_POINT \
MCUXCLECC_FP_POINTMULT_CURVE_PARAM, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_PointCheckAffineNR)
#define MCUXCLECC_FP_POINTMULT_SCALAR \
MCUXCLECC_FP_POINTMULT_BASE_POINT, \
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST, \
MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ModInv), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_SecureImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom), \
MCUXCLPKC_FP_CALLED_CALC_OP1_SHR, \
MCUXCLPKC_FP_CALLED_CALC_OP1_ADD, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup)
#define MCUXCLECC_FP_POINTMULT_SCALAR_MULTIPLICATION \
MCUXCLECC_FP_POINTMULT_SCALAR, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_SecurePointMult), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_SecurePointMult)
#define MCUXCLECC_FP_POINTMULT_CONVERT_POINT \
MCUXCLECC_FP_POINTMULT_SCALAR_MULTIPLICATION, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ModInv), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_PointCheckAffineNR)
#define MCUXCLECC_FP_POINTMULT_FINAL \
\
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ImportBigEndianToPkc), \
MCUXCLPKC_FP_CALLED_CALC_OP1_CMP, \
MCUXCLPKC_FP_CALLED_CALC_OP1_CMP, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_SecureExportBigEndianFromPkc), \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_SecureExportBigEndianFromPkc), \
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST, \
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize)
#endif

View File

@ -1,73 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_MontDH.h
* @brief Internal header of mcuxClEcc component
*/
#ifndef MCUXCLECC_INTERNAL_MONTDH_H_
#define MCUXCLECC_INTERNAL_MONTDH_H_
#define ECC_P 0x00u
#define ECC_N 0x01u
#define MONT_VX1 0x02u
#define MONT_VZ1 0x03u
#define MONT_VX2 0x04u
#define MONT_VZ2 0x05u
#define MONT_V0 0x06u
#define MONT_V1 0x07u
#define MONT_V2 0x08u
#define MONT_V3 0x09u
#define MONT_V4 0x0Au
#define MONT_V5 0x0Bu
#define MONT_V6 0x0Cu
#define MONT_V7 0x0Du
#define MONT_V8 0x0Eu
#define MONT_V9 0x0Fu
#define ECC_PS 0x10u
#define ECC_NS 0x11u
#define ECC_CP0 0x12u
#define ECC_CP1 0x13u
#define ECC_PFULL 0x14u
#define ECC_NFULL 0x15u
#define ECC_PQSQR 0x16u
#define ECC_NQSQR 0x17u
#define ECC_S0 0x18u
#define ECC_S1 0x19u
#define ECC_S2 0x1Au
#define ECC_S3 0x1Bu
#define ECC_T0 0x1Cu
#define ECC_T1 0x1Du
#define ECC_T2 0x1Eu
#define ECC_T3 0x1Fu
#define MONT_X0 0x20u
#define MONT_Z0 0x21u
#define MONT_X1 0x22u
#define MONT_Z1 0x23u
#define MONT_X2 0x24u
#define MONT_Z2 0x25u
#define ECC_MONTDH_NO_OF_VIRTUALS 0x10u
#define ECC_MONTDH_NO_OF_BUFFERS 0x18u
#define MCUXCLECC_PROJECTIVE (0xA5A5A5A5u)
#define MCUXCLECC_AFFINE (0x5A5A5A5Au)
#endif

View File

@ -1,75 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_NIST.h
* @brief Internal definitions supporting only NIST curves
*/
#include <mcuxClEcc_NIST_FUP.h>
#ifndef MCUXCLECC_INTERNAL_NIST_H_
#define MCUXCLECC_INTERNAL_NIST_H_
#define ECC_VERIFY_P384_NO_OF_BUFFERS 0x1Au
#define ECC_VERIFY_P384_NO_OF_VIRTUALS 0x12u
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_RepeatPointDouble_NIST)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_RepeatPointDouble_NIST(uint32_t iteration);
#define MCUXCLECC_FP_REPEATPOINTDOUBLE_NIST(iteration) \
do{ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_RepeatPointDouble_NIST(iteration)); \
(void) retValTemp; \
} while (false)
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Int_PointMult_NIST)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Int_PointMult_NIST(uint8_t iScalar, uint32_t scalarBitLen);
#define MCUXCLECC_FP_INT_POINTMULT_NIST(iScalar, scalarBitLen) \
do{ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_Int_PointMult_NIST(iScalar, scalarBitLen)); \
(void) retValTemp; \
} while (false)
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_PointCheckAffineNR_NIST)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_PointCheckAffineNR_NIST(void);
#define MCUXCLECC_FP_POINTCHECKAFFINENR_NIST() \
({ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_PointCheckAffineNR_NIST()); \
(retValTemp); \
})
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_PointFullAdd_NIST)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_PointFullAdd_NIST(void);
#define MCUXCLECC_FP_POINTFULLADD_NIST() \
({ \
MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClEcc_PointFullAdd_NIST()); \
(retValTemp); \
})
#define mcuxClEcc_Fup_RepeatDouble_NIST_Len1 3u
#define mcuxClEcc_Fup_RepeatDouble_NIST_Len2 18u
#define mcuxClEcc_Fup_RepeatDouble_NIST_Len3 3u
#define mcuxClEcc_Fup_RepeatDouble_NIST_Len 24u
#define MCUXCLECC_FP_CALCFUP_ONE_DOUBLE_NIST() \
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_RepeatDouble_NIST, \
mcuxClEcc_Fup_RepeatDouble_NIST_Len1 \
+ mcuxClEcc_Fup_RepeatDouble_NIST_Len2)
#define MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE_NIST MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup)
#define mcuxClEcc_Fup_PointCheckAffNR_NIST_Len 11u
#endif

View File

@ -1,64 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_SecurePointSelect.h
* @brief Internal header of mcuxClEcc SecurePointSelect macro
*/
#ifndef MCUXCLECC_INTERNAL_SECUREPOINTSELECT_H_
#define MCUXCLECC_INTERNAL_SECUREPOINTSELECT_H_
#include <stdint.h>
#include <stdbool.h>
#include <internal/mcuxClEcc_Internal.h>
#if defined(__ICCARM__) || defined(__ARMCC_VERSION) || defined(__CC_ARM) || defined(__GNUC__)
#define MCUXCLECC_SECUREPOINTSELECT(ofsP0_, ofsP1_, pOps_, scalarW0_, scalarW1_, randomWord_, bitOffset_) \
do{ \
uint32_t temp0; \
uint32_t temp1 = (bitOffset_); \
uint32_t temp2 = (randomWord_); \
__asm volatile ( \
"SUBS %[tmp1], %[tmp1], #2\n"\
"ROR %[tmp0], %[s0], %[tmp1]\n" \
"BIC %[tmp2], %[tmp2], #4\n" \
"EORS %[tmp0], %[tmp0], %[tmp2]\n" \
"ROR %[tmp1], %[s1], %[tmp1]\n" \
"EORS %[tmp0], %[tmp0], %[tmp1]\n" \
"ORRS %[tmp0], %[tmp0], %[tmp2]\n" \
"SUBS %[tmp1], %[pOps], %[tmp2]\n"\
"ADDS %[tmp2], %[tmp2], #4\n" \
"ADDS %[tmp1], %[tmp1], %[ofsX0]\n"\
"ANDS %[tmp2], %[tmp2], %[tmp0]\n" \
"LDR %[tmp0], [%[tmp1], %[tmp2]]\n"\
"EOR %[tmp2], %[tmp2], #4\n" \
"LDR %[tmp1], [%[tmp1], %[tmp2]]\n"\
: [tmp0] "=&r" (temp0), \
[tmp1] "+&r" (temp1), \
[tmp2] "+&r" (temp2) \
: [pOps] "r" (pOps_), \
[s0] "r" (scalarW0_), \
[s1] "r" (scalarW1_), \
[ofsX0] "i" (ECC_X0 * 2u) \
: "cc" \
); \
(ofsP0_) = temp0; \
(ofsP1_) = temp1; \
} while (false)
#else
#error Unsupported compiler. The above section must be manually adapted to support the inline assembly syntax.
#endif
#endif

View File

@ -1,199 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Mont_Internal.h
* @brief internal header of mcuxClEcc MontDh functionalities
*/
#ifndef MCUXCLECC_MONT_INTERNAL_H_
#define MCUXCLECC_MONT_INTERNAL_H_
#include <stdint.h>
#include <mcuxClSession.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <internal/mcuxClPkc_FupMacros.h>
#include <mcuxClEcc_Internal_SetupEnvironment_FUP.h>
#include <mcuxClEcc_Mont_MontDhX_FUP.h>
#include <mcuxClEcc_Internal_SecureScalarMult_XZMontLadder_FUP.h>
#include <mcuxClEcc.h>
#define ECC_P 0x00u
#define ECC_N 0x01u
#define ECC_V0 0x02u
#define ECC_V1 0x03u
#define ECC_V2 0x04u
#define ECC_V3 0x05u
#define ECC_V4 0x06u
#define ECC_V5 0x07u
#define ECC_V6 0x08u
#define ECC_V7 0x09u
#define ECC_V8 0x0Au
#define ECC_V9 0x0Bu
#define ECC_VA 0x0Cu
#define ECC_VB 0x0Du
#define ECC_VC 0x0Eu
#define ECC_VD 0x0Fu
#define ECC_PS 0x10u
#define ECC_NS 0x11u
#define ECC_CP0 0x12u
#define ECC_CP1 0x13u
#define ECC_PFULL 0x14u
#define ECC_NFULL 0x15u
#define ECC_PQSQR 0x16u
#define ECC_NQSQR 0x17u
#define ECC_S0 0x18u
#define ECC_T0 0x19u
#define ECC_S1 0x1Au
#define ECC_T1 0x1Bu
#define ECC_S2 0x1Cu
#define ECC_T2 0x1Du
#define ECC_S3 0x1Eu
#define ECC_T3 0x1Fu
#define ECC_COORD0 0x20u
#define ECC_COORD1 0x21u
#define ECC_COORD2 0x22u
#define ECC_COORD3 0x23u
#define ECC_COORD4 0x24u
#define ECC_COORD5 0x25u
#define ECC_COORD6 0x26u
#define ECC_COORD7 0x27u
#define ECC_COORD8 0x28u
#define ECC_COORD9 0x29u
#define ECC_COORDA 0x2Au
#define ECC_COORDB 0x2Bu
#define ECC_NO_OF_VIRTUALS ECC_PS
#define MONT_V0 ECC_V0
#define MONT_V1 ECC_V1
#define MONT_V2 ECC_V2
#define MONT_V3 ECC_V3
#define MONT_V4 ECC_V4
#define MONT_V5 ECC_V5
#define MONT_V6 ECC_V6
#define MONT_V7 ECC_V7
#define MONT_V8 ECC_V8
#define MONT_V9 ECC_V9
#define MONT_VX1 ECC_VA
#define MONT_VZ1 ECC_VB
#define MONT_VX2 ECC_VC
#define MONT_VZ2 ECC_VD
#define MONT_X0 ECC_COORD0
#define MONT_Z0 ECC_COORD1
#define MONT_X1 ECC_COORD2
#define MONT_Z1 ECC_COORD3
#define MONT_X2 ECC_COORD4
#define MONT_Z2 ECC_COORD5
#define MCUXCLECC_INTSTATUS_POINTMULT_NEUTRAL_POINT ((mcuxClEcc_Status_t) 0x55AAD22Du)
typedef struct
{
uint32_t wordNumCpuWa;
uint32_t wordNumPkcWa;
mcuxClPkc_State_t pkcStateBackup;
uint32_t pOperands32[];
} mcuxClEcc_CpuWa_t;
typedef struct
{
uint32_t curveID;
uint16_t byteLenP;
uint16_t byteLenN;
uint8_t *pFullModulusP;
uint8_t *pFullModulusN;
uint8_t *pR2P;
uint8_t *pR2N;
} mcuxClEcc_CommonDomainParams_t;
struct mcuxClEcc_Mont_DomainParams_t
{
mcuxClEcc_CommonDomainParams_t common;
uint16_t c;
uint16_t t;
uint8_t *pA;
uint8_t *pB;
uint8_t *pGx;
uint8_t *pGy;
uint8_t *pA24;
};
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_SetupEnvironment)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_SetupEnvironment(
mcuxClSession_Handle_t pSession,
mcuxClEcc_CommonDomainParams_t *pCommonDomainParams,
uint8_t noOfBuffers
);
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Mont_DhSetupEnvironment)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_DhSetupEnvironment(
mcuxClSession_Handle_t pSession,
mcuxClEcc_Mont_DomainParams_t *pDomainParams,
uint8_t noOfBuffers
);
#define MCUXCLECC_MONT_DH_SCALAR_BLINDING_BYTELEN 4u
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_GenerateMultiplicativeBlinding)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_GenerateMultiplicativeBlinding(mcuxClSession_Handle_t pSession);
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Mont_DhDecodeScalar)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_DhDecodeScalar(
mcuxClEcc_Mont_DomainParams_t *pDomainParameters
);
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Mont_DhDecodeCoordinate)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_DhDecodeCoordinate(
mcuxClEcc_Mont_DomainParams_t *pDomainParameters,
const uint8_t *pCoordinateEnc
);
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_SecureScalarMult_XZMontLadder(
uint8_t iScalar,
uint32_t scalarBitLen,
uint32_t optionAffineOrProjective
);
#define MCUXCLECC_PROJECTIVE (0xA5A5A5A5u)
#define MCUXCLECC_AFFINE (0x5A5A5A5Au)
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Mont_DhX)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_DhX(
mcuxClSession_Handle_t pSession,
mcuxClEcc_Mont_DomainParams_t *pDomainParameters,
const uint8_t *pCoordinateUEnc
);
#define mcuxClEcc_FUP_SetupEnvironment_ClearBuffers_LEN 5u
#define mcuxClEcc_FUP_MontDhDecodeScalar_LEN 5u
#define mcuxClEcc_FUP_MontDhX_CalcAffineX_LEN 5u
#define mcuxClEcc_Fup_SecureScalarMult_XZMontLadder_LadderStep_Affine_LEN 19u
#define mcuxClEcc_Fup_SecureScalarMult_XZMontLadder_LadderStep_Projective_LEN 22u
#define ECC_MONTDH_NO_OF_VIRTUALS 0x10u
#define ECC_MONTDH_NO_OF_BUFFERS 0x19u
#endif

View File

@ -1,51 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Verify_FUUP_programs.h
* @brief Header of ECDSA signature verification supporting curve P-384
*/
#ifndef MCUXCLECC_VERIFY_FUP_PROGRAMS_H_
#define MCUXCLECC_VERIFY_FUP_PROGRAMS_H_
#include <internal/mcuxClPkc_FupMacros.h>
#include <mcuxClEcc_Verify_FUP.h>
#include <mcuxClEcc_Verify_P384_FUP.h>
#define mcuxClEcc_Fup_Verify_InitZ_CalcU1U2_LEN 6u
#define mcuxClEcc_Fup_Verify_Convert_G_PrecG_toMR_LEN 5u
#define mcuxClEcc_Fup_Verify_Update_G_to_Prec1_LEN 5u
#define mcuxClEcc_Fup_Verify_Convert_pubkeyQ_toJacobianMR_LEN 6u
#define mcuxClEcc_Fup_Verify_Update_pubkeyQ_P1_z_LEN 9u
#define mcuxClEcc_Fup_Verify_Convert_P1plusP2_toAffineNR_CalcR_LEN 10u
#define mcuxClEcc_Fup_InitZ_CalcU1U2_LEN 6u
#define mcuxClEcc_Fup_Convert_G_PrecG_toMR_LEN 5u
#define mcuxClEcc_Fup_Update_G_to_Prec1_LEN 5u
#define mcuxClEcc_Fup_Convert_pubkeyQ_toJacobianMR_LEN 6u
#define mcuxClEcc_Fup_Update_pubkeyQ_P1_z_LEN 9u
#define mcuxClEcc_Fup_Convert_P1plusP2_toAffineNR_CalcR_LEN 9u
#endif

View File

@ -1,33 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc.h
* @brief Top level header of mcuxClEcc component
*
* @defgroup mcuxClEcc mcuxClEcc
* @brief Elliptic Curve Cryptography component
*/
#ifndef MCUXCLECC_H_
#define MCUXCLECC_H_
#include <ip_platform.h>
#include <mcuxClEcc_Types.h>
#include <mcuxClEcc_Functions.h>
#include <mcuxClEcc_MemoryConsumption.h>
#include <mcuxClEcc_Constants.h>
#endif /* MCUXCLECC_H_ */

View File

@ -1,47 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Constants.h
* @brief Constants definition for domain parameters of supported curves
*/
#ifndef MCUXCLECC_CONSTANTS_H_
#define MCUXCLECC_CONSTANTS_H_
#include <mcuxClEcc_Types.h>
/**
* @defgroup mcuxClEcc_Constants mcuxClEcc_Constants
* @brief Defines constants of @ref mcuxClEcc
* @ingroup mcuxClEcc
* @{
*/
/** Curve25519 domain parameters */
extern const mcuxClEcc_Mont_DomainParams_t mcuxClEcc_Mont_DomainParams_Curve25519;
/* https://docs.oracle.com/en/java/javacard/3.1/jc_api_srvc/api_classic/constant-values.html#javacard.security.NamedParameterSpec.X25519
* Supported curveID based on javacard api
*/
#define MCUXCLECC_CURVEID_MONT_X25519 (259u)
/**
* @}
*/ /* mcuxClEcc_Constants */
#endif /* MCUXCLECC_CONSTANTS_H_ */

View File

@ -1,24 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_FUP_H_
#define MCUXCLECC_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_DoubleAdd[20];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_RepeatDouble[24];
#endif /* MCUXCLECC_FUP_H_ */

View File

@ -1,205 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Functions.h
* @brief Top level APIs of mcuxClEcc component
*/
#ifndef MCUXCLECC_FUNCTIONS_H_
#define MCUXCLECC_FUNCTIONS_H_
#include <stdint.h>
#include <mcuxClSession.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClEcc_Types.h>
#include <mcuxClKey.h>
/**********************************************************/
/* Public APIs of mcuxClEcc */
/**********************************************************/
/**
* @defgroup mcuxClEcc_Functions mcuxClEcc_Functions
* @brief Defines all functions of @ref mcuxClEcc
* @ingroup mcuxClEcc
* @{
*/
/** implements ECDSA key generation.
* @retval #MCUXCLECC_STATUS_KEYGEN_OK if private key and public key are generated successfully;
* @retval #MCUXCLECC_STATUS_KEYGEN_INVALID_PARAMS if parameter(s) is invalid;
* @retval #MCUXCLECC_STATUS_KEYGEN_RNG_ERROR if random number (DRBG / PRNG) error (unexpected behavior);
* @retval #MCUXCLECC_STATUS_FAULT_ATTACK if fault attack (unexpected behavior) is detected.
* @attention This function uses DRBG and PRNG. Caller needs to check if DRBG and PRNG are ready.
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_KeyGen)
mcuxClEcc_Status_Protected_t mcuxClEcc_KeyGen(
mcuxClSession_Handle_t pSession, ///< [in] pointer to #mcuxClSession_Descriptor.
const mcuxClEcc_KeyGen_Param_t * pParam ///< [in] pointer to ECDSA Key Generation parameter structure.
);
/** implements ECDSA signature generation.
* @retval #MCUXCLECC_STATUS_SIGN_OK if signature is generated successfully;
* @retval #MCUXCLECC_STATUS_SIGN_INVALID_PARAMS if parameter(s) is invalid;
* @retval #MCUXCLECC_STATUS_SIGN_RNG_ERROR if random number (DRBG / PRNG) error (unexpected behavior);
* @retval #MCUXCLECC_STATUS_FAULT_ATTACK if fault attack (unexpected behavior) is detected.
* @attention This function uses DRBG and PRNG. Caller needs to check if DRBG and PRNG are ready.
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Sign)
mcuxClEcc_Status_Protected_t mcuxClEcc_Sign(
mcuxClSession_Handle_t pSession, ///< [in] pointer to #mcuxClSession_Descriptor.
const mcuxClEcc_Sign_Param_t * pParam ///< [in] pointer to ECDSA Sign parameter structure.
);
#if 0
/** implements EC pre-computed point calculation.
* @retval #MCUXCLECC_STATUS_CALCPP_OK if pre-computed point is calculated successfully;
* @retval #MCUXCLECC_STATUS_CALCPP_INVALID_PARAMS if parameter(s) is invalid;
* @retval #MCUXCLECC_STATUS_FAULT_ATTACK if fault attack (unexpected behavior) is detected.
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_CalcPrecomputedPoint)
mcuxClEcc_Status_Protected_t mcuxClEcc_CalcPrecomputedPoint(
uint8_t * pPkcWorkarea, ///< [in] pointer to PKC workarea to be used in this function.
const mcuxClEcc_CalcPrecomputedPoint_Param_t * pParam ///< [in] pointer to EC Calculate Pre-computed Point parameter structure.
);
#endif
/** implements ECDSA signature verification.
* @retval #MCUXCLECC_STATUS_VERIFY_OK if ECDSA Signature is valid;
* @retval #MCUXCLECC_STATUS_VERIFY_NOT_OK if ECDSA Signature is invalid;
* @retval #MCUXCLECC_STATUS_VERIFY_INVALID_PARAMS if parameter(s) is invalid;
* @retval #MCUXCLECC_STATUS_FAULT_ATTACK if fault attack (unexpected behavior) is detected.
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Verify)
mcuxClEcc_Status_Protected_t mcuxClEcc_Verify(
mcuxClSession_Handle_t pSession, ///< [in] pointer to #mcuxClSession_Descriptor.
const mcuxClEcc_Verify_Param_t * pParam ///< [in] pointer to ECDSA Verify parameter structure.
);
/**
* @brief implements ECC point multiplication.
*
* This API performs elliptic curve point multiplication on the given elliptic curve in short Weierstrass form.
* This API does not check if the curve parameters and the given point are valid or not.
* Invalid curve parameters or point might cause the return of #MCUXCLECC_STATUS_POINTMULT_INVALID_PARAMS,
* invalid result, and unexpected behavior (e.g., the return of #MCUXCLECC_STATUS_FAULT_ATTACK).
*
* @param[in] pSession pointer to #mcuxClSession_Descriptor.
* @param[in] pParam pointer to ECC point multiplication parameter structure.
*
* <dl>
* <dt>Parameter properties</dt>
* <dd><dl>
* <dt>pParam.curveParam.pG</dt>
* <dd> the base point is not used in this API. This pointer can be left unspecified. </dd>
* </dl></dd>
* </dl>
*
*
* @return A code-flow protected error code (see @ref MCUXCLECC_STATUS_)
* @retval #MCUXCLECC_STATUS_POINTMULT_OK if point multiplication is calculated successfully, and the result is not the neutral point;
* @retval #MCUXCLECC_STATUS_POINTMULT_INVALID_PARAMS if parameter(s) is invalid;
* @retval #MCUXCLECC_STATUS_POINTMULT_NEUTRAL_POINT if result is the neutral point;
* @retval #MCUXCLECC_STATUS_FAULT_ATTACK if fault attack (unexpected behavior) is detected.
*
* @attention This function uses PRNG. Caller needs to check if PRNG is ready.
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_PointMult)
mcuxClEcc_Status_Protected_t mcuxClEcc_PointMult(
mcuxClSession_Handle_t pSession,
const mcuxClEcc_PointMult_Param_t * pParam
);
/**
* @brief implements ECC key pair generation step for a MontDh key agreement according to rfc7748.
*
* This API performs elliptic curve key generation of the private key and calculates corresponding public key for MontDh key agreement
* This API does not check if the curve parameters are correct.
* This API might return MCUXCLECC_STATUS_MONT_RNG_ERROR when RNG behave in unexpected way
* Unexpected behavior will return MCUXCLECC_STATUS_FAULT_ATTACK.
*
* @param[in] session #mcuxClSession_Descriptor structure
* @param[in] type type structure specifying requested key type to be generated. Also contains domain parameters
* @param[in] protection #mcuxClKey_Protection structure
* @param[out] privKey private key handling structure
* @param[out] pPrivData buffer for private key of the MCUXCLECC_MONT_CURVE25519_SIZE_PRIVATEKEY length
* @param[out] pPrivDataSize private key length
* @param[out] pubKey public key handling structure
* @param[out] pPubData buffer for public key x-coordinate of MCUXCLECC_MONT_CURVE25519_SIZE_PUBLICKEY length
* @param[out] pPubDataSize public key x-coordinate length
*
*
* @return A code-flow protected error code (see @ref MCUXCLECC_STATUS_ and @ref MCUXCLECC_MONT_STATUS_)
* @retval #MCUXCLECC_STATUS_MONT_DHKEYGENERATION_OK if key generation correctly calculate private and public keys, public key does not belong to the small subgroup.
* @retval #MCUXCLECC_STATUS_MONT_RNG_ERROR if RNG return an error.
* @retval #MCUXCLECC_STATUS_FAULT_ATTACK if fault attack (unexpected behavior) is detected.
*
* @attention This function uses PRNG. Caller needs to check if PRNG is ready.
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Mont_DhKeyGeneration)
mcuxClEcc_Status_Protected_t mcuxClEcc_Mont_DhKeyGeneration(
mcuxClSession_Handle_t session,
mcuxClKey_Type_t type,
mcuxClKey_Protection_t protection,
mcuxClKey_Handle_t privKey,
uint8_t * pPrivData,
uint32_t * const pPrivDataSize,
mcuxClKey_Handle_t pubKey,
uint8_t * pPubData,
uint32_t * const pPubDataSize
);
/**
* @brief implements ECC key agreement according to rfc7748.
*
* This API performs elliptic curve key agreement to compute shared secret between two parties using the function X25519
* This API does not check if the curve parameters are correct.
* This API might return MCUXCLECC_STATUS_MONT_RNG_ERROR when RNG behave in unexpected way
* This API might return MCUXCLECC_STATUS_MONT_DHKEYAGREEMENT_ERROR_SMALL_SUBGROUP if generated public key lies in the small subgroup
* Unexpected behavior will return MCUXCLECC_STATUS_FAULT_ATTACK.
*
* @param[in] session pointer to #mcuxClSession_Descriptor.
* @param[in] key private key handling structure
* @param[in] otherKey public key handling structure
* @param[out] pOut buffer for shared secret of length MCUXCLECC_MONT_CURVE25519_SIZE_SHAREDSECRET
* @param[out] pOutSize shared secret length
*
*
* @return A code-flow protected error code (see @ref MCUXCLECC_STATUS_ and @ref MCUXCLECC_MONT_STATUS_)
* @retval #MCUXCLECC_STATUS_MONT_DHKEYAGREEMENT_OK if key generation correctly calculate private and public keys, public key does not belong to the small subgroup.
* @retval #MCUXCLECC_STATUS_MONT_RNG_ERROR if RNG return an error.
* @retval #MCUXCLECC_STATUS_MONT_DHKEYAGREEMENT_ERROR_SMALL_SUBGROUP if calculated public key lies in small subgroup.
* @retval #MCUXCLECC_STATUS_FAULT_ATTACK if fault attack (unexpected behavior) is detected.
*
* @attention This function uses PRNG. Caller needs to check if PRNG is ready.
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Mont_DhKeyAgreement)
mcuxClEcc_Status_Protected_t mcuxClEcc_Mont_DhKeyAgreement(
mcuxClSession_Handle_t session,
mcuxClKey_Handle_t key,
mcuxClKey_Handle_t otherKey,
uint8_t * pOut,
uint32_t * const pOutSize
);
/**
* @}
*/ /* mcuxClEcc_Functions */
#endif /* MCUXCLECC_FUNCTIONS_H_ */

View File

@ -1,23 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_INTERNAL_FUP_H_
#define MCUXCLECC_INTERNAL_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Interleave[7];
#endif /* MCUXCLECC_INTERNAL_FUP_H_ */

View File

@ -1,25 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_KeyGen_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_INTERNAL_KEYGEN_FUP_H_
#define MCUXCLECC_INTERNAL_KEYGEN_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Int_CoreKeyGen_Steps34[6];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Int_CoreKeyGen_Steps56[8];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Int_CoreKeyGen_Steps78[11];
#endif /* MCUXCLECC_INTERNAL_KEYGEN_FUP_H_ */

View File

@ -1,23 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_PointCheck_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_INTERNAL_POINTCHECK_FUP_H_
#define MCUXCLECC_INTERNAL_POINTCHECK_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_PointCheckAffNR[10];
#endif /* MCUXCLECC_INTERNAL_POINTCHECK_FUP_H_ */

View File

@ -1,24 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_SecurePointMult_CoZMontLadder_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef mcuxCLECC_INTERNAL_SECUREPOINTMULT_COZMONTLADDER_FUP_H_
#define mcuxCLECC_INTERNAL_SECUREPOINTMULT_COZMONTLADDER_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_CoZPointAddSub[23];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1[18];
#endif /* mcuxCLECC_INTERNAL_SECUREPOINTMULT_COZMONTLADDER_FUP*/

View File

@ -1,23 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_SecureScalarMult_XZMontLadder_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_INTERNAL_SECURESCALARMULT_XZMONTLADDER_FUP_H_
#define MCUXCLECC_INTERNAL_SECURESCALARMULT_XZMONTLADDER_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_SecureScalarMult_XZMontLadder_LadderStep[22];
#endif /* MCUXCLECC_INTERNAL_SECURESCALARMULT_XZMONTLADDER_FUP_H_ */

View File

@ -1,23 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_SetupEnvironment_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_INTERNAL_SETUPENVIRONMENT_FUP_H_
#define MCUXCLECC_INTERNAL_SETUPENVIRONMENT_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_FUP_SetupEnvironment_ClearBuffers[5];
#endif /* MCUXCLECC_INTERNAL_SETUPENVIRONMENT_FUP_H_ */

View File

@ -1,23 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_KeyGen_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_KEYGEN_FUP_H_
#define MCUXCLECC_KEYGEN_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_KeyGen_Convert_PubKey[11];
#endif /* MCUXCLECC_KEYGEN_FUP_H_ */

View File

@ -1,135 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_MemoryConsumption.h
* @brief Defines the memory consumption for the mcuxClEcc component
*/
#ifndef MCUXCLECC_MEMORYCONSUMPTION_H_
#define MCUXCLECC_MEMORYCONSUMPTION_H_
/**
* @defgroup mcuxClEcc_MemoryConsumption mcuxClEcc_MemoryConsumption
* @brief Defines the memory consumption for the @ref mcuxClEcc component
* @ingroup mcuxClEcc
* @{
*/
/**
* @addtogroup MCUXCLECC_WACPU_
* @brief Define the CPU workarea size required by mcuxClEcc APIs.
* @{
*/
#define MCUXCLECC_KEYGEN_WACPU_SIZE 0u ///< CPU workarea size (in bytes) for #mcuxClEcc_KeyGen.
#define MCUXCLECC_SIGN_WACPU_SIZE 0u ///< CPU workarea size (in bytes) for #mcuxClEcc_Sign.
#define MCUXCLECC_VERIFY_WACPU_SIZE 0u ///< CPU workarea size (in bytes) for #mcuxClEcc_Verify.
#define MCUXCLECC_POINTMULT_WACPU_SIZE 0u ///< CPU workarea size (in bytes) for #mcuxClEcc_PointMult.
/**
* @}
*/ /* MCUXCLECC_WACPU_ */
#ifdef MCUXCL_FEATURE_ECC_MONTGOMERY_DH
/**
* @addtogroup MCUXCLECC_MONT_WACPU_
* @brief Define the CPU workarea size required by mcuxClEcc_Mont APIs.
* @{
*/
#define MCUXCLECC_MONT_DHKEYGENERATION_WACPU_SIZE 100u ///< CPU workarea size (in bytes) for #mcuxClEcc_Mont_DhKeyGeneration.
#define MCUXCLECC_MONT_DHKEYAGREEMENT_WACPU_SIZE 100u ///< CPU workarea size (in bytes) for #mcuxClEcc_Mont_DhKeyAgreement.
/**
* @}
*/ /* MCUXCLECC_MONT_WACPU_ */
#endif
/**
* @addtogroup MCUXCLECC_WAPKC_
* @brief Define the PKC workarea size required by mcuxClEcc APIs.
* @{
*/
/**
* @brief PKC wordsize in ECC component.
*/
#define MCUXCLECC_PKC_WORDSIZE 8u
/**
* @brief Helper macro to get the maximum of two given constants.
*/
#define MCUXCLECC_MAX(value0, value1) (((value0) > (value1)) ? (value0) : (value1))
/**
* @brief Helper macro to calculate size aligned to PKC word.
*/
#define MCUXCLECC_ALIGN_SIZE_PKC(size) ((((size) + MCUXCLECC_PKC_WORDSIZE - 1u) / MCUXCLECC_PKC_WORDSIZE) * MCUXCLECC_PKC_WORDSIZE)
/**
* PKC workarea size (in bytes) for #mcuxClEcc_KeyGen for arbitrary lengths of p and n (in bytes).
*/
#define MCUXCLECC_KEYGEN_WAPKC_SIZE(pByteLen,nByteLen) \
(24u * (MCUXCLECC_ALIGN_SIZE_PKC(MCUXCLECC_MAX(pByteLen,nByteLen)) + MCUXCLECC_PKC_WORDSIZE))
/**
* PKC workarea size (in bytes) for #mcuxClEcc_Sign for arbitrary lengths of p and n (in bytes).
*/
#define MCUXCLECC_SIGN_WAPKC_SIZE(pByteLen,nByteLen) \
(24u * (MCUXCLECC_ALIGN_SIZE_PKC(MCUXCLECC_MAX(pByteLen,nByteLen)) + MCUXCLECC_PKC_WORDSIZE))
/**
* PKC workarea size (in bytes) for #mcuxClEcc_Verify for arbitrary lengths of p and n (in bytes).
*/
#define MCUXCLECC_VERIFY_WAPKC_SIZE(pByteLen,nByteLen) \
(28u * (MCUXCLECC_ALIGN_SIZE_PKC(MCUXCLECC_MAX(pByteLen,nByteLen)) + MCUXCLECC_PKC_WORDSIZE))
/**
* PKC workarea size (in bytes) for #mcuxClEcc_PointMult for arbitrary lengths of p and n (in bytes).
*/
#define MCUXCLECC_POINTMULT_WAPKC_SIZE(pByteLen,nByteLen) \
(24u * (MCUXCLECC_ALIGN_SIZE_PKC(MCUXCLECC_MAX(pByteLen,nByteLen)) + MCUXCLECC_PKC_WORDSIZE))
/**
* @}
*/ /* MCUXCLECC_WAPKC_ */
#ifdef MCUXCL_FEATURE_ECC_MONTGOMERY_DH
/**
* @addtogroup MCUXCLECC_WAPKC_
* @brief Define the PKC workarea size required by mcuxClEcc APIs.
* @{
*/
/**
* PKC workarea size (in bytes) for #mcuxClEcc_KeyGen for arbitrary lengths of p and n (in bytes).
*/
#define MCUXCLECC_MONT_DHKEYGENERATION_CURVE25519_WAPKC_SIZE \
(1000u)
/**
* PKC workarea size (in bytes) for #mcuxClEcc_Sign for arbitrary lengths of p and n (in bytes).
*/
#define MCUXCLECC_MONT_DHKEYAGREEMENT_CURVE25519_WAPKC_SIZE \
(1000u)
/**
* @}
*/ /* MCUXCLECC_WAPKC_ */
#endif
/**
* @}
*/ /* mcuxClEcc_MemoryConsumption */
#endif /* MCUXCLECC_MEMORYCONSUMPTION_H_ */

View File

@ -1,24 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Mont_MontDhX_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_MONT_MONTDHX_FUP_H_
#define MCUXCLECC_MONT_MONTDHX_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_FUP_MontDhDecodeScalar[5];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_FUP_MontDhX_CalcAffineX[5];
#endif /* MCUXCLECC_MONT_MONTDHX_FUP_H_ */

View File

@ -1,24 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_NIST_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_NIST_FUP_H_
#define MCUXCLECC_NIST_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_PointCheckAffNR_NIST[11];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_RepeatDouble_NIST[24];
#endif /* MCUXCLECC_NIST_FUP_H_ */

View File

@ -1,23 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_PointMult_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_POINTMULT_FUP_H_
#define MCUXCLECC_POINTMULT_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_PointMult_SplitScalar_ConvertPoint2MR[10];
#endif /* MCUXCLECC_POINTMULT_FUP_H_ */

View File

@ -1,23 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Sign_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_SIGN_FUP_H_
#define MCUXCLECC_SIGN_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Sign_CalculateS[13];
#endif /* MCUXCLECC_SIGN_FUP_H_ */

View File

@ -1,215 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Types.h
* @brief Type definitions of mcuxClEcc component
*/
#ifndef MCUXCLECC_TYPES_H_
#define MCUXCLECC_TYPES_H_
#include <stdint.h>
/**********************************************************/
/* Return codes of mcuxClEcc */
/**********************************************************/
/**
* @defgroup mcuxClEcc_Macros mcuxClEcc_Macros
* @brief Defines all macros of @ref mcuxClEcc
* @ingroup mcuxClEcc
* @{
*/
/** Type for mcuxClEcc component return codes. */
typedef uint32_t mcuxClEcc_Status_t;
/** Type for mcuxClEcc component return codes. */
typedef uint64_t mcuxClEcc_Status_Protected_t;
/** Type for mcuxClEcc Mont domainParameters type */
typedef struct mcuxClEcc_Mont_DomainParams_t mcuxClEcc_Mont_DomainParams_t;
/** @addtogroup MCUXCLECC_STATUS_
* mcuxClEcc return code definitions
* @{ */
#define MCUXCLECC_STATUS_OK ((mcuxClEcc_Status_t) 0x55555555u) ///< Operation was successful.
#define MCUXCLECC_STATUS_KEYGEN_OK ((mcuxClEcc_Status_t) 0x55553CC3u) ///< ECDSA private key and public key are generated successfully.
#define MCUXCLECC_STATUS_KEYGEN_INVALID_PARAMS ((mcuxClEcc_Status_t) 0x55551DE2u) ///< Parameter(s) is invalid.
#define MCUXCLECC_STATUS_KEYGEN_RNG_ERROR ((mcuxClEcc_Status_t) 0x555527D8u) ///< Random number (DRBG / PRNG) error (unexpected behavior).
#define MCUXCLECC_STATUS_SIGN_OK ((mcuxClEcc_Status_t) 0x55555AA5u) ///< ECDSA signature is generated successfully.
#define MCUXCLECC_STATUS_SIGN_INVALID_PARAMS ((mcuxClEcc_Status_t) 0x55551EE1u) ///< Parameter(s) is invalid.
#define MCUXCLECC_STATUS_SIGN_RNG_ERROR ((mcuxClEcc_Status_t) 0x55552DD2u) ///< Random number (DRBG / PRNG) error (unexpected behavior).
#if 0
#define MCUXCLECC_STATUS_CALCPP_OK ((mcuxClEcc_Status_t) 0x555539C6u) ///< Pre-computed point is calculated successfully.
#define MCUXCLECC_STATUS_CALCPP_INVALID_PARAMS ((mcuxClEcc_Status_t) 0x55551BE4u) ///< Parameter(s) is invalid.
#endif
#define MCUXCLECC_STATUS_VERIFY_OK ((mcuxClEcc_Status_t) 0x55556996u) ///< ECDSA Signature is valid.
#define MCUXCLECC_STATUS_VERIFY_NOT_OK ((mcuxClEcc_Status_t) 0x555517E8u) ///< ECDSA Signature is invalid.
#define MCUXCLECC_STATUS_VERIFY_INVALID_PARAMS ((mcuxClEcc_Status_t) 0x55552BD4u) ///< Parameter(s) is invalid.
#define MCUXCLECC_STATUS_POINTMULT_OK ((mcuxClEcc_Status_t) 0x55553AC5u) ///< Point multiplication is calculated successfully, and the result is not the neutral point;
#define MCUXCLECC_STATUS_POINTMULT_INVALID_PARAMS ((mcuxClEcc_Status_t) 0x55554BB4u) ///< Parameter(s) is invalid.
#define MCUXCLECC_STATUS_POINTMULT_NEUTRAL_POINT ((mcuxClEcc_Status_t) 0x55558778u) ///< The result of point multiplication is the neutral point.
#define MCUXCLECC_STATUS_POINTMULT_RNG_ERROR ((mcuxClEcc_Status_t) 0x55552ED1u) ///< Random number (DRBG / PRNG) error (unexpected behavior).
#define MCUXCLECC_STATUS_FAULT_ATTACK ((mcuxClEcc_Status_t) 0x5555F00Fu) ///< Fault attack (unexpected behavior) is detected.
/** @} */
/** @addtogroup MCUXCLECC_MONT_STATUS_
* mcuxClEcc_Mont return code definitions
* @{ */
#define MCUXCLECC_STATUS_MONT_DHKEYGENERATION_OK ((mcuxClEcc_Status_t) 0x555533CCu) ///< MONTDH keys are generated successfully.
#define MCUXCLECC_STATUS_MONT_DHKEYAGREEMENT_OK ((mcuxClEcc_Status_t) 0x555535CAu) ///< MONTDH shared secred computed successfully.
#define MCUXCLECC_STATUS_MONT_DHKEYAGREEMENT_ERROR_SMALL_SUBGROUP ((mcuxClEcc_Status_t) 0x55554DB2u) ///< MONTDH public key lies in small subgroup.
#define MCUXCLECC_STATUS_MONT_RNG_ERROR ((mcuxClEcc_Status_t) 0x55551BE4u) ///< Random number (DRBG / PRNG) error (unexpected behavior).
/** @} */
/** @addtogroup MCUXCLECC_MONT_CURVE25519_SIZE_
* mcuxClEcc_Mont_size definitions for curve25519 input buffers
* @{ */
#define MCUXCLECC_MONT_CURVE25519_SIZE_PRIVATEKEY (32u) ///< Byte length of a Curve25519 private key.
#define MCUXCLECC_MONT_CURVE25519_SIZE_PUBLICKEY (32u) ///< Byte length of a Curve25519 public key.
#define MCUXCLECC_MONT_CURVE25519_SIZE_SHAREDSECRET (32u) ///< Byte length of a Curve25519 shared secret.
#define MCUXCLECC_MONT_CURVE25519_SIZE_PRIMEP (32u) ///< Byte length of the underlying prime p used in Curve25519.
#define MCUXCLECC_MONT_CURVE25519_SIZE_BASEPOINTORDER (32u) ///< Byte length of the base point order n used in Curve25519.
/** @} */
/**
* @}
*/ /* mcuxClEcc_Macros */
/**********************************************************/
/* Parameter structure of mcuxClEcc APIs */
/**********************************************************/
/**
* @defgroup mcuxClEcc_Types mcuxClEcc_Types
* @brief Defines all types of @ref mcuxClEcc
* @ingroup mcuxClEcc
* @{
*/
/** Parameter structure of elliptic curve of the form, y^2 = x^3 + a*x + b modulo prime p.
* Each curve parameter is stored as a Big-endian octet string with exact byte length specified.
* For a small parameter, padding zero(s) is placed in the beginning of the octet string.
* This structure contains pointers to the octet strings and the lengths.
*/
typedef struct
{
const uint8_t *pA; ///< [in] pointer to octet string of curve parameter a (< p), of which the length is byteLenP.
const uint8_t *pB; ///< [in] pointer to octet string of curve parameter b (< p), of which the length is byteLenP.
const uint8_t *pP; ///< [in] pointer to octet string of prime modulus p, of which the length is byteLenP.
///< The leading byte of this octet string shall be nonzero (i.e., != 0x00).
const uint8_t *pG; ///< [in] pointer to octet string of base point G. Each coordinate is an octet string of the length byteLenP.
///< The string of x coordinate is followed by the string of y coordinate.
const uint8_t *pN; ///< [in] pointer to octet string of base point order n, of which the length is byteLenN.
///< The leading byte of this octet string shall be nonzero (i.e., != 0x00).
uint32_t misc; ///< [in] packed lengths, via #mcuxClEcc_DomainParam_misc_Pack:
///< bits 0~ 7: byteLenP: length of the octet string of curve parameters a, b and p, and x and y coordinates of base point G;
///< bits 8~15: byteLenN: length of the octet string of curve parameter n;
///< bits 16~31: reserved.
} mcuxClEcc_DomainParam_t;
/** mcuxClEcc macros and defines to pack or access components of misc parameter of #mcuxClEcc_DomainParam_t */
#define mcuxClEcc_DomainParam_misc_Pack(byteLenN, byteLenP) MCUXCLPKC_PACKARGS4(0u, 0u, (uint8_t) byteLenN, (uint8_t) byteLenP) ///< Helper macro to pack misc parameter of #mcuxClEcc_DomainParam_t
#define mcuxClEcc_DomainParam_misc_byteLenP_offset 0 ///< Offset of byteLenP in packed misc parameter of #mcuxClEcc_DomainParam_t
#define mcuxClEcc_DomainParam_misc_byteLenP_mask ((uint32_t) 0x000000FFu) ///< Mask to extract byteLenP from packed misc parameter of #mcuxClEcc_DomainParam_t
#define mcuxClEcc_DomainParam_misc_byteLenN_offset 8 ///< Offset of byteLenN in packed misc parameter of #mcuxClEcc_DomainParam_t
#define mcuxClEcc_DomainParam_misc_byteLenN_mask ((uint32_t) 0x0000FF00u) ///< Mask to extract byteLenN from packed misc parameter of #mcuxClEcc_DomainParam_t
/** Parameter structure for function #mcuxClEcc_KeyGen. */
typedef struct
{
mcuxClEcc_DomainParam_t curveParam; ///< [in] structure of pointers to curve parameters and length of parameters.
uint8_t * pPrivateKey; ///< [out] pointer to memory area, where the private key will be exported if KeyGen is executed successfully.
///< It will be stored as a Big-endian octet string of the exact length curveParam.byteLenN.
uint8_t * pPublicKey; ///< [out] pointer to memory area, where the public key will be exported if KeyGen is executed successfully.
///< It will be stored in the same format as the base point G.
uint32_t optLen; ///< [in] packed options (reserved):
///< bits 0~31: reserved. **CAUTION** always set optLen = 0.
} mcuxClEcc_KeyGen_Param_t;
/** Parameter structure for function #mcuxClEcc_Sign. */
typedef struct
{
mcuxClEcc_DomainParam_t curveParam; ///< [in] structure of pointers to curve parameters and length of parameters.
const uint8_t * pHash; ///< [in] pointer to string of message digest (hash), of which the length is byteLenHash (in optLen).
const uint8_t * pPrivateKey; ///< [in] pointer to octet string of private key, which is of the same format as base point order n.
uint8_t * pSignature; ///< [out] pointer to memory area in which signature R and S will be exported if signature is generated successfully.
///< They will be stored as Big-endian octet strings of the exact length curveParam.byteLenN.
///< The string of R is followed by the string of S.
uint32_t optLen; ///< [in] packed options (reserved) and lengths:
///< bits 0~7: byteLenHash: length of the string of message digest;
///< bits 8~31: reserved.
} mcuxClEcc_Sign_Param_t;
/** mcuxClEcc macros and defines to pack or access components of optLen parameter of #mcuxClEcc_Sign_Param_t */
#define mcuxClEcc_Sign_Param_optLen_Pack(byteLenHash) ((uint32_t) (byteLenHash) & 0xFFu) ///< Helper macro to pack optLen parameter of #mcuxClEcc_Sign_Param_t
#define mcuxClEcc_Sign_Param_optLen_byteLenHash_offset 0 ///< Offset of byteLenHash in packed optLen parameter of #mcuxClEcc_Sign_Param_t
#define mcuxClEcc_Sign_Param_optLen_byteLenHash_mask ((uint32_t) 0x000000FFu) ///< Mask to extract byteLenHash from packed optLen parameter of #mcuxClEcc_Sign_Param_t
#if 0
/** Parameter structure for function #mcuxClEcc_CalcPrecomputedPoint. */
typedef struct
{
mcuxClEcc_DomainParam_t curveParam; ///< [in] structure of pointers to curve parameters and length of parameters.
uint8_t * pPrecG; ///< [out] pointer to memory area in which calculated pre-computed point of base point G will be exported.
///< It is calculated as (2 ^ (nByteLength * 4)) * G.
///< It will be stored in the same format as the base point G, of which the length is 2*curveParam.byteLenP.
} mcuxClEcc_CalcPrecomputedPoint_Param_t;
#endif
/** Parameter structure for function #mcuxClEcc_Verify. */
typedef struct
{
mcuxClEcc_DomainParam_t curveParam; ///< [in] structure of pointers to curve parameters and length of parameters.
const uint8_t * pPrecG; ///< [in] pointer to octet string of pre-computed point of base point G, which is of the same format as base point G.
///< It is calculated as (2 ^ (nByteLength * 4)) * G.
const uint8_t * pHash; ///< [in] pointer to string of message digest (hash), of which the length is byteLenHash (in optLen).
const uint8_t * pSignature; ///< [in] pointer to octet string of signature R and S. Each of R and S is a Big-endian octet string of the exact length curveParam.byteLenN.
///< The string of R is followed by the string of S.
const uint8_t * pPublicKey; ///< [in] pointer to octet string of public key, which is of the same format as base point G.
uint8_t * pOutputR; ///< [out] pointer to memory area in which signature R calculated by verify function will be exported if signature is valid.
///< It will be stored as a Big-endian octet string of the exact length curveParam.byteLenN.
uint32_t optLen; ///< [in] packed options (reserved) and lengths:
///< bits 0~7: byteLenHash: length of the string of message digest;
///< bits 8~31: reserved.
} mcuxClEcc_Verify_Param_t;
/** mcuxClEcc macros and defines to pack or access components of optLen parameter of #mcuxClEcc_Verify_Param_t */
#define mcuxClEcc_Verify_Param_optLen_Pack(byteLenHash) ((uint32_t) (byteLenHash) & 0xFFu) ///< Helper macro to pack optLen parameter of #mcuxClEcc_Verify_Param_t
#define mcuxClEcc_Verify_Param_optLen_byteLenHash_offset 0 ///< Offset of byteLenHash in packed optLen parameter of #mcuxClEcc_Verify_Param_t
#define mcuxClEcc_Verify_Param_optLen_byteLenHash_mask ((uint32_t) 0x000000FFu) ///< Mask to extract byteLenHash from packed optLen parameter of #mcuxClEcc_Verify_Param_t
/** Parameter structure for function #mcuxClEcc_PointMult. */
typedef struct
{
mcuxClEcc_DomainParam_t curveParam; ///< [in] structure of pointers to curve parameters and length of parameters.
const uint8_t * pScalar; ///< [in] pointer to octet string of scalar d, which is of the same format as base point order n.
const uint8_t * pPoint; ///< [in] pointer to octet string of EC point Q, which is of the same format as base point G.
uint8_t * pResult; ///< [out] pointer to memory area, where the result R = dQ will be exported if PointMult is executed successfully.
///< It will be stored in the same format as the base point G.
uint32_t optLen; ///< [in] packed options (reserved):
///< bits 0~31: reserved. **CAUTION** always set optLen = 0.
} mcuxClEcc_PointMult_Param_t;
/**
* @}
*/ /* mcuxClEcc_Types */
#endif /* MCUXCLECC_TYPES_H_ */

View File

@ -1,28 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Verify_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_VERIFY_FUP_H_
#define MCUXCLECC_VERIFY_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Verify_Convert_G_PrecG_toMR[5];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Verify_Convert_P1plusP2_toAffineNR_CalcR[10];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Verify_Convert_pubkeyQ_toJacobianMR[6];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Verify_InitZ_CalcU1U2[6];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Verify_Update_G_to_Prec1[5];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Verify_Update_pubkeyQ_P1_z[9];
#endif /* MCUXCLECC_VERIFY_FUP_H_ */

View File

@ -1,62 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Verify_P384.h
* @brief Header of ECDSA signature verification supporting curve P-384
*/
#ifndef MCUXCLECC_VERIFY_P384_H_
#define MCUXCLECC_VERIFY_P384_H_
#include <mcuxClEcc.h>
#include <mcuxCsslFlowProtection.h>
/**
* @defgroup mcuxClEcc_Verify_P384 mcuxClEcc_Verify_P384
* @brief Definitions for the ECDSA signature verification for curve P-384 of @ref mcuxClEcc
* @ingroup mcuxClEcc
* @{
*/
/** @addtogroup MCUXCLECC_SIZE_P384_
* mcuxClEcc size definitions for curve P-384
* @{ */
#define MCUXCLECC_COORDINATE_SIZE_P384 0x30U ///< Byte length of coordinates of points on curve P-384
#define MCUXCLECC_SIGNATURE_SIZE_P384 0x60U ///< Byte length of signatures generated using curve P-384
/** @} */
/** implements ECDSA signature verification, supporting curve P-384.
* @retval #MCUXCLECC_STATUS_VERIFY_OK if ECDSA Signature is valid;
* @retval #MCUXCLECC_STATUS_VERIFY_NOT_OK if ECDSA Signature is invalid;
* @retval #MCUXCLECC_STATUS_VERIFY_INVALID_PARAMS if Parameter(s) is invalid;
* @retval #MCUXCLECC_STATUS_FAULT_ATTACK if Fault attack (unexpected behavior) is detected.
*/
MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEcc_Verify_P384)
mcuxClEcc_Status_Protected_t mcuxClEcc_Verify_P384(
const uint8_t * pHash, ///< [in] pointer to hash of message (at least 48 bytes). The first 48 bytes of hash will be used.
const uint8_t * pSignature, ///< [in] pointer to signature R and S. R is followed by S, and each is 48-byte and in Big-endian.
const uint8_t * pPublicKey, ///< [in] pointer to public key. The x coordinate is followed by y coordinate, and each coordinate is 48-byte (384-bit) and in Big-endian.
uint8_t * pOutputR ///< [out] pointer to memory area (48-byte) in which signature R calculated by verify function will be exported (in Big-endian) if signature is valid.
);
/**
* @}
*/ /* mcuxClEcc_Verify_P384 */
#endif /* MCUXCLECC_VERIFY_P384_H_ */

View File

@ -1,28 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Verify_P384_FUP.h
* @brief defines FUP programs byte arrays
*/
#ifndef MCUXCLECC_VERIFY_P384_FUP_H_
#define MCUXCLECC_VERIFY_P384_FUP_H_
#include <internal/mcuxClPkc_FupMacros.h>
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Convert_G_PrecG_toMR[5];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Convert_P1plusP2_toAffineNR_CalcR[9];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Convert_pubkeyQ_toJacobianMR[6];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_InitZ_CalcU1U2[6];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Update_G_to_Prec1[5];
extern const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Update_pubkeyQ_P1_z[9];
#endif /* MCUXCLECC_VERIFY_P384_FUP_H_ */

View File

@ -1,96 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Constants.c
* @brief Provides constans definitions for domain parameters
*/
#include <internal/mcuxClEcc_Mont_Internal.h>
#include <mcuxClEcc.h>
#define CURVE25519_BYTE_LEN_P (MCUXCLECC_MONT_CURVE25519_SIZE_PRIMEP)
#define CURVE25519_BYTE_LEN_N (MCUXCLECC_MONT_CURVE25519_SIZE_BASEPOINTORDER)
static const uint8_t pCurve25519_FullP[CURVE25519_BYTE_LEN_P + 8u] __attribute__ ((aligned (4))) =
{
0x1bu, 0xcau, 0x6bu, 0x28u, 0xafu, 0xa1u, 0xbcu, 0x86u,
0xedu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0x7fu
};
static const uint8_t pCurve25519_FullN[CURVE25519_BYTE_LEN_N + 8u] __attribute__ ((aligned (4))) =
{
0x1bu, 0x7eu, 0x54u, 0x12u, 0xa3u, 0x1du, 0xb5u, 0xd2u,
0xedu, 0xd3u, 0xf5u, 0x5cu, 0x1au, 0x63u, 0x12u, 0x58u, 0xd6u, 0x9cu, 0xf7u, 0xa2u, 0xdeu, 0xf9u, 0xdeu, 0x14u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x10u
};
static const uint8_t pCurve25519_R2P[CURVE25519_BYTE_LEN_P] __attribute__ ((aligned (4))) =
{
0xa4u, 0x05u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
};
static const uint8_t pCurve25519_R2N[CURVE25519_BYTE_LEN_N] __attribute__ ((aligned (4))) =
{
0x01u, 0x0fu, 0x9cu, 0x44u, 0xe3u, 0x11u, 0x06u, 0xa4u, 0x47u, 0x93u, 0x85u, 0x68u, 0xa7u, 0x1bu, 0x0eu, 0xd0u,
0x65u, 0xbeu, 0xf5u, 0x17u, 0xd2u, 0x73u, 0xecu, 0xceu, 0x3du, 0x9au, 0x30u, 0x7cu, 0x1bu, 0x41u, 0x99u, 0x03u
};
static const uint8_t pCurve25519_PointGX[CURVE25519_BYTE_LEN_P] __attribute__ ((aligned (4))) =
{
0x09u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u ,0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u
};
static const uint8_t pCurve25519_PointGY[CURVE25519_BYTE_LEN_P] __attribute__ ((aligned (4))) =
{
0xD9u, 0xD3u, 0xCEu, 0x7Eu, 0xA2u, 0xC5u, 0xE9u, 0x29u, 0xB2u, 0x61u, 0x7Cu, 0x6Du, 0x7Eu, 0x4Du, 0x3Du, 0x92u,
0x4Cu, 0xD1u, 0x48u, 0x77u, 0x2Cu, 0xDDu, 0x1Eu, 0xE0u, 0xB4u, 0x86u, 0xA0u, 0xB8u, 0xA1u, 0x19u, 0xAEu, 0x20u
};
static const uint8_t pCurve25519_LadderConst[CURVE25519_BYTE_LEN_P] __attribute__ ((aligned (4))) =
{
0x42u, 0xDBu, 0x01u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u
};
static const uint8_t pCurve25519_A[CURVE25519_BYTE_LEN_P] __attribute__ ((aligned (4))) =
{
0x06u, 0x6Du, 0x07u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u
};
static const uint8_t pCurve25519_B[CURVE25519_BYTE_LEN_P] __attribute__ ((aligned (4))) =
{
0x01u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u
};
const mcuxClEcc_Mont_DomainParams_t mcuxClEcc_Mont_DomainParams_Curve25519 =
{
.common.curveID = MCUXCLECC_CURVEID_MONT_X25519,
.common.byteLenP = CURVE25519_BYTE_LEN_P,
.common.byteLenN = CURVE25519_BYTE_LEN_N,
.common.pFullModulusP = (uint8_t*)&pCurve25519_FullP,
.common.pFullModulusN = (uint8_t*)&pCurve25519_FullN,
.common.pR2P = (uint8_t*)&pCurve25519_R2P,
.common.pR2N = (uint8_t*)&pCurve25519_R2N,
.c = 3u,
.t = 254u,
.pA = (uint8_t*)&pCurve25519_A,
.pB = (uint8_t*)&pCurve25519_B,
.pGx = (uint8_t*)&pCurve25519_PointGX,
.pGy = (uint8_t*)&pCurve25519_PointGY,
.pA24 = (uint8_t*)&pCurve25519_LadderConst
};

View File

@ -1,25 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_FUP.c
* @brief mcuxClEcc: FUP programs used in ECC functions
*/
#include <mcuxClEcc_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_DoubleAdd[20], 4u) = {{0x10u,0x00u,0x15u,0x3du,0xf6u,0x47u},{0x80u,0x00u,0x06u,0x06u,0x00u,0x1cu},{0x80u,0x00u,0x1cu,0x06u,0x00u,0x1du},{0x80u,0x00u,0x08u,0x1cu,0x00u,0x02u},{0x80u,0x00u,0x09u,0x1du,0x00u,0x03u},{0x10u,0x00u,0xf2u,0x00u,0xc3u,0xd4u},{0x80u,0x2au,0x10u,0x05u,0x03u,0x1du},{0x80u,0x2au,0x10u,0x04u,0x02u,0x03u},{0x80u,0x00u,0x06u,0x03u,0x00u,0x1cu},{0x00u,0x0eu,0x00u,0x1cu,0x1cu,0x06u},{0x80u,0x00u,0x03u,0x03u,0x00u,0x1cu},{0x80u,0x00u,0x04u,0x1cu,0x00u,0x02u},{0x80u,0x00u,0x1cu,0x03u,0x00u,0x04u},{0x80u,0x00u,0x05u,0x04u,0x00u,0x03u},{0x80u,0x00u,0x1du,0x1du,0x00u,0x1cu},{0x81u,0x2au,0x10u,0x04u,0x02u,0x04u},{0x80u,0x21u,0x10u,0x04u,0x1cu,0x04u},{0x80u,0x2au,0x10u,0x02u,0x04u,0x05u},{0x80u,0x00u,0x05u,0x1du,0x00u,0x1cu},{0x80u,0x2au,0x10u,0x1cu,0x03u,0x05u}};
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_RepeatDouble[24], 4U) = {{0x10u,0x00u,0x24u,0xf3u,0x23u,0xacu},{0x80u,0x00u,0x0eu,0x07u,0x00u,0x1cu},{0x80u,0x00u,0x1cu,0x1cu,0x00u,0x0fu},{0x80u,0x00u,0x0fu,0x0fu,0x00u,0x1cu},{0x80u,0x00u,0x0au,0x1cu,0x00u,0x0fu},{0x10u,0x00u,0x96u,0xd5u,0x52u,0xc5u},{0x80u,0x00u,0x0cu,0x0cu,0x00u,0x1du},{0x80u,0x21u,0x10u,0x0fu,0x1du,0x1cu},{0x81u,0x21u,0x10u,0x1cu,0x1du,0x1cu},{0x80u,0x21u,0x10u,0x0du,0x0du,0x1du},{0x80u,0x00u,0x1du,0x0eu,0x00u,0x1eu},{0x00u,0x0eu,0x00u,0x1eu,0x1eu,0x06u},{0x80u,0x00u,0x1du,0x0du,0x00u,0x1eu},{0x80u,0x21u,0x10u,0x1eu,0x1eu,0x1du},{0x80u,0x00u,0x0cu,0x1du,0x00u,0x1fu},{0x80u,0x00u,0x1cu,0x1cu,0x00u,0x04u},{0x81u,0x2au,0x10u,0x04u,0x1fu,0x04u},{0x80u,0x2au,0x10u,0x1fu,0x04u,0x1fu},{0x80u,0x00u,0x1cu,0x1fu,0x00u,0x05u},{0x80u,0x00u,0x1du,0x1eu,0x00u,0x1cu},{0x80u,0x2au,0x10u,0x05u,0x1cu,0x05u},{0x10u,0x00u,0x3eu,0xd8u,0xecu,0xefu},{0x80u,0x21u,0x10u,0x0fu,0x0fu,0x1du},{0x80u,0x00u,0x1cu,0x1du,0x00u,0x0fu}};

View File

@ -1,68 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal.c
* @brief mcuxClEcc: implementation of ECC internal functions
*/
#include <stdint.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Interleave)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Interleave(uint16_t iScalar0_iScalar1, uint32_t bitLenScalar)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Interleave);
uint32_t ps1LenRegBackup = MCUXCLPKC_PS1_GETLENGTH_REG();
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint32_t *pOperands32 = (uint32_t *) pOperands;
uint8_t iScalar0 = (uint8_t) (iScalar0_iScalar1 >> 8);
uint8_t iScalar1 = (uint8_t) (iScalar0_iScalar1 & 0xFFu);
uint32_t bitLenHalfScalar = bitLenScalar - (bitLenScalar >> 1);
uint32_t byteLenHalfScalar_PKCWord = ((bitLenHalfScalar + (MCUXCLPKC_WORDSIZE * 8u) - 1u) / (MCUXCLPKC_WORDSIZE * 8u)) * MCUXCLPKC_WORDSIZE;
uint32_t offsets_VY0_VX0 = (uint32_t) pOperands[iScalar0]
+ (((uint32_t) pOperands[ECC_T0] + byteLenHalfScalar_PKCWord) << 16);
uint32_t offsets_VZ_VZ0 = 0x01u
+ ((0u - bitLenHalfScalar) << 16);
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, offsets_VY0_VX0);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VZ0, ECC_VZ, offsets_VZ_VZ0);
MCUXCLPKC_ENABLEGF2();
MCUXCLPKC_PS1_SETLENGTH(0u, 2u * byteLenHalfScalar_PKCWord);
MCUXCLPKC_PS2_SETLENGTH(byteLenHalfScalar_PKCWord, byteLenHalfScalar_PKCWord);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_Interleave, mcuxClEcc_Fup_Interleave_LEN);
MCUXCLPKC_WAITFORREADY();
pOperands[ECC_VX0] = pOperands[iScalar1];
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_Interleave, mcuxClEcc_Fup_Interleave_LEN);
MCUXCLPKC_WAITFORREADY();
MCUXCLPKC_DISABLEGF2();
MCUXCLPKC_PS1_SETLENGTH_REG(ps1LenRegBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Interleave, MCUXCLECC_STATUS_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
}

View File

@ -1,22 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal.c
* @brief mcuxClEcc: implementation of ECC internal functions
*/
#include <mcuxClEcc_Internal_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_Interleave[7], 4u) = {{0x10u,0x00u,0x50u,0xddu,0xacu,0x4cu},{0x00u,0x14u,0x00u,0x04u,0x07u,0x1cu},{0xc0u,0x13u,0x05u,0x05u,0x00u,0x1du},{0x00u,0x14u,0x00u,0x1du,0x06u,0x1du},{0x40u,0x15u,0x00u,0x1cu,0x07u,0x04u},{0xc0u,0x13u,0x04u,0x04u,0x00u,0x1cu},{0x00u,0x0eu,0x00u,0x1cu,0x1du,0x04u}};

View File

@ -1,73 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Internal_GenerateMultiplicativeBlinding.c
* @brief mcuxClEcc: implementation of GenerateMultiplicativeBlinding functions
*/
#include <stdint.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClCss.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <internal/mcuxClPkc_Operations.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Mont_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_GenerateMultiplicativeBlinding)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_GenerateMultiplicativeBlinding(mcuxClSession_Handle_t pSession)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_GenerateMultiplicativeBlinding);
MCUXCLPKC_FP_CALC_OP1_CONST(ECC_S0, 0u);
const uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint8_t *pS0 = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S0]);
MCUXCLPKC_WAITFORFINISH();
volatile uint32_t *p32S0 = (volatile uint32_t *) pS0;
MCUX_CSSL_FP_FUNCTION_CALL(retGetRandom, mcuxClCss_Prng_GetRandom(pS0, MCUXCLECC_MONT_DH_SCALAR_BLINDING_BYTELEN));
if (MCUXCLCSS_STATUS_OK != retGetRandom)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_GenerateMultiplicativeBlinding, MCUXCLECC_STATUS_MONT_RNG_ERROR,
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST );
}
*p32S0 |= 0x80000001u;
MCUXCLPKC_FP_CALC_OP1_OR_CONST(ECC_S1, ECC_S0, 0u);
MCUXCLMATH_FP_MODINV(ECC_T0, ECC_S1, ECC_N, ECC_T1);
MCUXCLPKC_FP_CALC_MC1_MM(ECC_S1, ECC_S3, ECC_T0, ECC_N);
MCUXCLPKC_FP_CALC_MC1_MM(ECC_T0, ECC_S1, ECC_NQSQR, ECC_N);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_S1, ECC_T0, ECC_N, ECC_N);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_GenerateMultiplicativeBlinding, MCUXCLECC_STATUS_OK,
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom),
MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ModInv),
MCUXCLPKC_FP_CALLED_CALC_MC1_MM,
MCUXCLPKC_FP_CALLED_CALC_MC1_MM,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS
);
}

View File

@ -1,141 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_KeyGen.c
* @brief mcuxClEcc: implementation of ECC internal key generation functions
*/
#include <stdint.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClCss_Rng.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <mcuxClSession.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClPkc_Operations.h>
#include <internal/mcuxClEcc_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Int_CoreKeyGen)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Int_CoreKeyGen(mcuxClSession_Handle_t pSession,
uint32_t byteLenN)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Int_CoreKeyGen,
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST,
MCUXCLPKC_FP_CALLED_CALC_OP2_CONST,
MCUXCLPKC_FP_CALLED_CALC_OP2_CONST );
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
const uint32_t mcLen_opLen = MCUXCLPKC_PS1_GETLENGTH_REG();
const uint32_t opLen = MCUXCLPKC_PS1_UNPACK_OPLEN(mcLen_opLen);
const uint32_t *ptr32N = (const uint32_t *) MCUXCLPKC_OFFSET2PTR(pOperands[ECC_N]);
const uint32_t wordNumN = (byteLenN + (sizeof(uint32_t)) - 1u) / (sizeof(uint32_t));
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
uint32_t nMSWord = ptr32N[wordNumN - 1u];
uint32_t nMSWord_LeadZeros = __CLZ(nMSWord);
uint32_t bitLenN65 = (wordNumN * (sizeof(uint32_t)) * 8u) - nMSWord_LeadZeros + 65u;
uint32_t pkcByteLenN65 = (bitLenN65 + (MCUXCLPKC_WORDSIZE * 8u) - 1u) / (MCUXCLPKC_WORDSIZE * 8u) * MCUXCLPKC_WORDSIZE;
MCUXCLPKC_FP_CALC_OP1_CONST(ECC_S0, 0u);
MCUXCLPKC_PS2_SETLENGTH(0u, pkcByteLenN65);
MCUXCLPKC_FP_CALC_OP2_CONST(ECC_S2, 0u);
MCUXCLPKC_FP_CALC_OP2_CONST(ECC_S3, 0u);
uint32_t *ptr32S0 = (uint32_t *) MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S0]);
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(ret_Prng1, mcuxClCss_Prng_GetRandom((uint8_t*)&ptr32S0[0], (2U * sizeof(uint32_t))));
if (MCUXCLCSS_STATUS_OK != ret_Prng1)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Int_CoreKeyGen, MCUXCLECC_INTSTATUS_RNG_ERROR);
}
ptr32S0[0] |= 0x00000001u;
ptr32S0[1] |= 0x80000000u;
uint8_t *ptrS2 = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S2]);
MCUX_CSSL_FP_FUNCTION_CALL(ret_DRBG_GetRandom_c, mcuxClCss_Rng_DrbgRequest_Async(ptrS2, (wordNumN * (sizeof(uint32_t))) + 8u));
if (MCUXCLCSS_STATUS_OK_WAIT != ret_DRBG_GetRandom_c)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Int_CoreKeyGen, MCUXCLECC_INTSTATUS_RNG_ERROR,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Rng_DrbgRequest_Async));
}
MCUX_CSSL_FP_FUNCTION_CALL(ret_DRBG_Wait, mcuxClCss_WaitForOperation(MCUXCLCSS_ERROR_FLAGS_CLEAR));
if (MCUXCLCSS_STATUS_OK != ret_DRBG_Wait)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Int_CoreKeyGen, MCUXCLECC_INTSTATUS_RNG_ERROR,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Rng_DrbgRequest_Async),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_WaitForOperation) );
}
uint8_t *ptrS3 = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S3]);
MCUX_CSSL_FP_FUNCTION_CALL(ret_PRNG_GetRandom_r, mcuxClCss_Prng_GetRandom(ptrS3, (wordNumN * (sizeof(uint32_t))) + 8u));
if (MCUXCLCSS_STATUS_OK != ret_PRNG_GetRandom_r)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Int_CoreKeyGen, MCUXCLECC_INTSTATUS_RNG_ERROR);
}
pOperands[ECC_VT] = (uint16_t) nMSWord_LeadZeros;
const uint32_t constants_0000_0001 = 1u;
MCUXCLECC_STORE_2OFFSETS(pOperands, ECC_VT2, ECC_VT3, constants_0000_0001);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Int_CoreKeyGen_Steps34,
mcuxClEcc_Int_CoreKeyGen_Steps34_LEN);
MCUXCLMATH_FP_MODINV(ECC_T0, ECC_ZA, ECC_N, ECC_S1);
MCUXCLPKC_WAITFORREADY();
MCUXCLPKC_PS1_SETLENGTH(pkcByteLenN65, opLen);
MCUXCLMATH_FP_REDUCEMODEVEN(ECC_S1, ECC_S2, ECC_Z, ECC_XA, ECC_S1, ECC_YA, ECC_ZA);
MCUXCLMATH_FP_REDUCEMODEVEN(ECC_S2, ECC_S3, ECC_Z, ECC_XA, ECC_S2, ECC_YA, ECC_ZA);
MCUXCLPKC_WAITFORREADY();
MCUXCLPKC_PS1_SETLENGTH_REG(mcLen_opLen);
MCUXCLPKC_PS2_SETLENGTH(0u, opLen * 2u);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Int_CoreKeyGen_Steps56,
mcuxClEcc_Int_CoreKeyGen_Steps56_LEN);
MCUXCLPKC_WAITFORREADY();
MCUXCLPKC_PS2_SETLENGTH(opLen * 2u, opLen);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Int_CoreKeyGen_Steps78,
mcuxClEcc_Int_CoreKeyGen_Steps78_LEN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Int_CoreKeyGen, MCUXCLECC_STATUS_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Rng_DrbgRequest_Async),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_WaitForOperation),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ModInv),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ReduceModEven),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ReduceModEven),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
}

View File

@ -1,26 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_KeyGen.fup.c
* @brief mcuxClEcc: PKC FUP programs of ECC internal key generation function
*/
#include <mcuxClEcc_Internal_KeyGen_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Int_CoreKeyGen_Steps34[6], 4u) = {{0x10u,0x00u,0x5bu,0x56u,0x1du,0xaau},{0x40u,0x15u,0x00u,0x1au,0x0fu,0x1au},{0x40u,0x15u,0x00u,0x1bu,0x0fu,0x1bu},{0x40u,0x0au,0x00u,0x1au,0x1bu,0x1au},{0x00u,0x1eu,0x00u,0x18u,0x03u,0x22u},{0x00u,0x1bu,0x00u,0x01u,0x02u,0x23u}};
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Int_CoreKeyGen_Steps56[8], 4u) = {{0x10u,0x00u,0xc4u,0x6eu,0xcdu,0x28u},{0x80u,0x13u,0x1cu,0x1au,0x00u,0x1bu},{0x80u,0x13u,0x1cu,0x19u,0x00u,0x1au},{0x80u,0x13u,0x1cu,0x23u,0x00u,0x19u},{0xc0u,0x2au,0x19u,0x1au,0x1bu,0x1au},{0x40u,0x3eu,0x00u,0x00u,0x03u,0x19u},{0x00u,0x1eu,0x00u,0x1cu,0x03u,0x19u},{0x40u,0x0au,0x00u,0x1au,0x19u,0x1au}};
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Int_CoreKeyGen_Steps78[11], 4u) = {{0x10u,0x00u,0x2fu,0xd1u,0xa0u,0x0cu},{0xc0u,0x00u,0x1au,0x17u,0x01u,0x19u},{0x80u,0x00u,0x19u,0x17u,0x01u,0x1cu},{0x80u,0x33u,0x1cu,0x00u,0x01u,0x19u},{0x80u,0x2au,0x01u,0x19u,0x01u,0x19u},{0x80u,0x33u,0x1bu,0x00u,0x01u,0x1au},{0x80u,0x00u,0x1au,0x18u,0x01u,0x1bu},{0x80u,0x21u,0x01u,0x1cu,0x1au,0x1cu},{0x80u,0x00u,0x1cu,0x18u,0x01u,0x1au},{0x80u,0x2au,0x01u,0x1au,0x01u,0x1au},{0x80u,0x2au,0x01u,0x1au,0x1bu,0x1au}};

View File

@ -1,255 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_NIST.c
* @brief mcuxClEcc: implementation of ECC internal functions for NIST prime curves (a=-3)
*/
#include <mcuxClPkc.h>
#include <internal/mcuxClPkc_Operations.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Internal.h>
#include <internal/mcuxClEcc_Internal_NIST.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_RepeatPointDouble_NIST)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_RepeatPointDouble_NIST(uint32_t iteration)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_RepeatPointDouble_NIST);
if (1u == iteration)
{
MCUXCLECC_FP_CALCFUP_ONE_DOUBLE_NIST();
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_RepeatPointDouble_NIST, MCUXCLECC_STATUS_OK,
MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE_NIST );
}
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_RepeatDouble_NIST,
mcuxClEcc_Fup_RepeatDouble_NIST_Len);
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint32_t *pOperands32 = (uint32_t *) pOperands;
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX2, ECC_VY2, ECC_VX0, ECC_VY0);
pOperands[ECC_VZ2] = pOperands[ECC_VZ0];
uint32_t remIter = iteration - 1u;
MCUX_CSSL_FP_LOOP_DECL(Doublings);
while(remIter > 1u)
{
MCUX_CSSL_FP_LOOP_ITERATION(Doublings,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
MCUXCLPKC_FP_CALCFUP_OFFSET(mcuxClEcc_Fup_RepeatDouble_NIST, mcuxClEcc_Fup_RepeatDouble_NIST_Len1,
mcuxClEcc_Fup_RepeatDouble_NIST_Len2 + mcuxClEcc_Fup_RepeatDouble_NIST_Len3);
remIter--;
}
MCUXCLPKC_FP_CALCFUP_OFFSET(mcuxClEcc_Fup_RepeatDouble_NIST, mcuxClEcc_Fup_RepeatDouble_NIST_Len1,
mcuxClEcc_Fup_RepeatDouble_NIST_Len2);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_RepeatPointDouble_NIST, MCUXCLECC_STATUS_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUX_CSSL_FP_LOOP_ITERATIONS(Doublings, iteration - 2u),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Int_PointMult_NIST)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Int_PointMult_NIST(uint8_t iScalar, uint32_t scalarBitLen)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Int_PointMult_NIST);
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint32_t *pOperands32 = (uint32_t *) pOperands;
const uint32_t *pScalar = (const uint32_t *) MCUXCLPKC_OFFSET2PTR(pOperands[iScalar]);
uint32_t scalarWord;
uint32_t scalarBits;
uint32_t index = scalarBitLen;
MCUX_CSSL_FP_LOOP_DECL(PointMult_Double);
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
do
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Double);
index -= 2u;
scalarWord = pScalar[index / 32u];
scalarBits = (scalarWord >> (index & 31u)) & 0x3u;
} while (0u == scalarBits);
uint32_t offsets_VY_VX = pOperands32[(ECC_X1 / 2u) - 1u + scalarBits];
uint32_t offsets_VYA_VXA = MCUXCLECC_LOAD_2OFFSETS(pOperands32, ECC_XA, ECC_YA);
MCUXCLPKC_FP_CALC_OP1_NEG(ECC_ZA, ECC_P);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX2, ECC_VY2, offsets_VY_VX);
uint32_t NoOfAdd = 0u;
MCUX_CSSL_FP_LOOP_DECL(PointMult_Add);
if (0u == index)
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Add,
MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST,
MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST );
NoOfAdd += 1u;
MCUXCLPKC_FP_CALC_OP1_OR_CONST(ECC_XA, ECC_VX2, 0u);
MCUXCLPKC_FP_CALC_OP1_OR_CONST(ECC_YA, ECC_VY2, 0u);
}
else
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Double,
MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE_NIST );
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VT2, ECC_VT3, ECC_T2, ECC_T3);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, offsets_VYA_VXA);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VZ0, ECC_VZ, ECC_ZA, ECC_Z);
pOperands[ECC_VZ2] = pOperands[ECC_ZA];
MCUXCLECC_FP_CALCFUP_ONE_DOUBLE_NIST();
index -= 2u;
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
scalarWord = pScalar[index / 32u];
scalarBits = (scalarWord >> (index & 31u)) & 0x3u;
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX2, ECC_VY2, offsets_VYA_VXA);
if (0u != scalarBits)
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Add,
MCUXCLECC_FP_CALLED_CALCFUP_ADD_ONLY );
NoOfAdd += 1u;
offsets_VY_VX = pOperands32[(ECC_X1 / 2u) - 1u + scalarBits];
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX1, ECC_VY1, offsets_VY_VX);
MCUXCLECC_FP_CALCFUP_ADD_ONLY();
}
}
while (0u != index)
{
index -= 2u;
if (0x1Eu == (index & 0x1Fu))
{
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
scalarWord = pScalar[index / 32u];
}
scalarBits = (scalarWord >> (index & 0x1Fu)) & 0x3u;
if (0u == scalarBits)
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Double,
MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE_NIST );
MCUXCLECC_FP_CALCFUP_ONE_DOUBLE_NIST();
}
else
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Double);
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Add,
MCUXCLECC_FP_CALLED_CALCFUP_DOUBLE_ADD );
NoOfAdd += 1u;
offsets_VY_VX = pOperands32[(ECC_X1 / 2u) - 1u + scalarBits];
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX1, ECC_VY1, offsets_VY_VX);
MCUXCLECC_FP_CALCFUP_DOUBLE_ADD();
}
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Int_PointMult_NIST, MCUXCLECC_STATUS_OK,
MCUXCLPKC_FP_CALLED_CALC_OP1_NEG,
MCUX_CSSL_FP_LOOP_ITERATIONS(PointMult_Double, scalarBitLen / 2u),
MCUX_CSSL_FP_LOOP_ITERATIONS(PointMult_Add, NoOfAdd) );
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_PointCheckAffineNR_NIST)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_PointCheckAffineNR_NIST(void)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_PointCheckAffineNR_NIST);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_PointCheckAffNR_NIST,
mcuxClEcc_Fup_PointCheckAffNR_NIST_Len);
if (MCUXCLPKC_FLAG_NONZERO == MCUXCLPKC_WAITFORFINISH_GETZERO())
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointCheckAffineNR_NIST, MCUXCLECC_INTSTATUS_POINTCHECK_NOTOK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
}
MCUXCLPKC_FP_CALC_OP1_SUB_CONST(ECC_T1, ECC_T0, 1u);
if (MCUXCLPKC_FLAG_CARRY == MCUXCLPKC_WAITFORFINISH_GETCARRY())
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointCheckAffineNR_NIST, MCUXCLECC_INTSTATUS_POINTCHECK_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUXCLPKC_FP_CALLED_CALC_OP1_SUB_CONST );
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointCheckAffineNR_NIST, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_PointFullAdd_NIST)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_PointFullAdd_NIST(void)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_PointFullAdd_NIST,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUXCLPKC_FP_CALLED_CALC_MC1_MS,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS );
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint32_t *pOperands32 = (uint32_t *) pOperands;
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VT2, ECC_VT3, ECC_T2, ECC_T3);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_DoubleAdd, mcuxClEcc_Fup_DoubleAdd_Len1);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_T0, ECC_VX0, ECC_VT2, ECC_PS);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_T0, ECC_T0, ECC_P, ECC_P);
if (MCUXCLPKC_FLAG_ZERO != MCUXCLPKC_WAITFORFINISH_GETZERO())
{
MCUXCLPKC_FP_CALCFUP_OFFSET(mcuxClEcc_Fup_DoubleAdd, mcuxClEcc_Fup_DoubleAdd_Len1,
mcuxClEcc_Fup_DoubleAdd_Len2);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointFullAdd_NIST, MCUXCLECC_INTSTATUS_POINTADD_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
}
MCUXCLPKC_FP_CALC_MC1_MA(ECC_T0, ECC_VY0, ECC_VT3, ECC_PS);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_T0, ECC_T0, ECC_P, ECC_P);
if (MCUXCLPKC_FLAG_ZERO == MCUXCLPKC_WAITFORFINISH_GETZERO())
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointFullAdd_NIST, MCUXCLECC_INTSTATUS_POINTADD_NEUTRAL_POINT,
MCUXCLPKC_FP_CALLED_CALC_MC1_MA,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS );
}
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX2, ECC_VY2, ECC_VX0, ECC_VY0);
MCUXCLECC_FP_CALCFUP_ONE_DOUBLE_NIST();
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointFullAdd_NIST, MCUXCLECC_INTSTATUS_POINTADD_OK,
MCUXCLPKC_FP_CALLED_CALC_MC1_MA,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS,
MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE_NIST );
}

View File

@ -1,122 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_PointArithmetic.c
* @brief mcuxClEcc: implementation of ECC internal point arithmetic functions
*/
#include <stdint.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <internal/mcuxClPkc_Operations.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_RepeatPointDouble)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_RepeatPointDouble(uint32_t iteration)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_RepeatPointDouble);
if (1u == iteration)
{
MCUXCLECC_FP_CALCFUP_ONE_DOUBLE();
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_RepeatPointDouble, MCUXCLECC_STATUS_OK,
MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE );
}
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_RepeatDouble,
mcuxClEcc_Fup_RepeatDouble_Len);
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint32_t *pOperands32 = (uint32_t *) pOperands;
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX2, ECC_VY2, ECC_VX0, ECC_VY0);
pOperands[ECC_VZ2] = pOperands[ECC_VZ0];
uint32_t remIter = iteration - 1u;
MCUX_CSSL_FP_LOOP_DECL(Doublings);
while(remIter > 1u)
{
MCUX_CSSL_FP_LOOP_ITERATION(Doublings,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
MCUXCLPKC_FP_CALCFUP_OFFSET(mcuxClEcc_Fup_RepeatDouble, mcuxClEcc_Fup_RepeatDouble_Len1,
mcuxClEcc_Fup_RepeatDouble_Len2 + mcuxClEcc_Fup_RepeatDouble_Len3);
remIter--;
}
MCUXCLPKC_FP_CALCFUP_OFFSET(mcuxClEcc_Fup_RepeatDouble, mcuxClEcc_Fup_RepeatDouble_Len1,
mcuxClEcc_Fup_RepeatDouble_Len2);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_RepeatPointDouble, MCUXCLECC_STATUS_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUX_CSSL_FP_LOOP_ITERATIONS(Doublings, iteration - 2u),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_PointFullAdd)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_PointFullAdd(void)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_PointFullAdd,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUXCLPKC_FP_CALLED_CALC_MC1_MS,
MCUXCLPKC_FP_CALLED_CALC_MC1_MR,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS );
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint32_t *pOperands32 = (uint32_t *) pOperands;
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VT2, ECC_VT3, ECC_T2, ECC_T3);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_DoubleAdd, mcuxClEcc_Fup_DoubleAdd_Len1);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_T1, ECC_VX0, ECC_VT2, ECC_PS);
MCUXCLPKC_FP_CALC_MC1_MR(ECC_T0, ECC_T1, ECC_P);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_T0, ECC_T0, ECC_P, ECC_P);
if (MCUXCLPKC_FLAG_ZERO != MCUXCLPKC_WAITFORFINISH_GETZERO())
{
MCUXCLPKC_FP_CALCFUP_OFFSET(mcuxClEcc_Fup_DoubleAdd, mcuxClEcc_Fup_DoubleAdd_Len1,
mcuxClEcc_Fup_DoubleAdd_Len2);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointFullAdd, MCUXCLECC_INTSTATUS_POINTADD_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
}
MCUXCLPKC_FP_CALC_MC1_MA(ECC_T1, ECC_VY0, ECC_VT3, ECC_PS);
MCUXCLPKC_FP_CALC_MC1_MR(ECC_T0, ECC_T1, ECC_P);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_T0, ECC_T0, ECC_P, ECC_P);
if (MCUXCLPKC_FLAG_ZERO == MCUXCLPKC_WAITFORFINISH_GETZERO())
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointFullAdd, MCUXCLECC_INTSTATUS_POINTADD_NEUTRAL_POINT,
MCUXCLPKC_FP_CALLED_CALC_MC1_MA,
MCUXCLPKC_FP_CALLED_CALC_MC1_MR,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS );
}
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX2, ECC_VY2, ECC_VX0, ECC_VY0);
MCUXCLECC_FP_CALCFUP_ONE_DOUBLE();
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointFullAdd, MCUXCLECC_INTSTATUS_POINTADD_OK,
MCUXCLPKC_FP_CALLED_CALC_MC1_MA,
MCUXCLPKC_FP_CALLED_CALC_MC1_MR,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS,
MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE );
}

View File

@ -1,52 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_PointCheck.c
* @brief mcuxClEcc: implementation of ECC internal point check function
*/
#include <stdint.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <internal/mcuxClPkc_Operations.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_PointCheckAffineNR)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_PointCheckAffineNR(void)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_PointCheckAffineNR);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_PointCheckAffNR,
mcuxClEcc_Fup_PointCheckAffNR_LEN);
if (MCUXCLPKC_FLAG_NONZERO == MCUXCLPKC_WAITFORFINISH_GETZERO())
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointCheckAffineNR, MCUXCLECC_INTSTATUS_POINTCHECK_NOTOK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
}
MCUXCLPKC_FP_CALC_OP1_SUB_CONST(ECC_T1, ECC_T0, 1u);
if (MCUXCLPKC_FLAG_CARRY == MCUXCLPKC_WAITFORFINISH_GETCARRY())
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointCheckAffineNR, MCUXCLECC_INTSTATUS_POINTCHECK_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUXCLPKC_FP_CALLED_CALC_OP1_SUB_CONST );
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointCheckAffineNR, MCUXCLECC_STATUS_FAULT_ATTACK);
}

View File

@ -1,22 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_PointCheck_FUP.c
* @brief mcuxClEcc: implementation of ECC internal point check function
*/
#include <mcuxClEcc_Internal_PointCheck_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_PointCheckAffNR[10], 4u) = {{0x10u,0x00u,0xe9u,0x8eu,0xdau,0xb1u},{0x80u,0x00u,0x04u,0x16u,0x00u,0x1cu},{0x80u,0x00u,0x1cu,0x1cu,0x00u,0x1du},{0x80u,0x21u,0x10u,0x1du,0x0au,0x1du},{0x80u,0x00u,0x1cu,0x1du,0x00u,0x1eu},{0x80u,0x00u,0x05u,0x16u,0x00u,0x1cu},{0x80u,0x00u,0x1cu,0x1cu,0x00u,0x1du},{0x80u,0x2au,0x10u,0x1du,0x1eu,0x1du},{0x80u,0x33u,0x1du,0x00u,0x00u,0x1cu},{0x80u,0x2au,0x00u,0x0bu,0x1cu,0x1cu}};

View File

@ -1,144 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_PointMult.c
* @brief mcuxClEcc: implementation of ECC internal PointMult function
*/
#include <stdint.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <internal/mcuxClPkc_Operations.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Int_PointMult)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Int_PointMult(uint8_t iScalar, uint32_t scalarBitLen)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Int_PointMult);
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint32_t *pOperands32 = (uint32_t *) pOperands;
const uint32_t *pScalar = (const uint32_t *) MCUXCLPKC_OFFSET2PTR(pOperands[iScalar]);
uint32_t scalarWord;
uint32_t scalarBits;
uint32_t index = scalarBitLen;
MCUX_CSSL_FP_LOOP_DECL(PointMult_Double);
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
do
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Double);
index -= 2u;
scalarWord = pScalar[index / 32u];
scalarBits = (scalarWord >> (index & 31u)) & 0x3u;
} while (0u == scalarBits);
uint32_t offsets_VY_VX = pOperands32[(ECC_X1 / 2u) - 1u + scalarBits];
uint32_t offsets_VYA_VXA = MCUXCLECC_LOAD_2OFFSETS(pOperands32, ECC_XA, ECC_YA);
MCUXCLPKC_FP_CALC_OP1_NEG(ECC_ZA, ECC_P);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX2, ECC_VY2, offsets_VY_VX);
uint32_t NoOfAdd = 0u;
MCUX_CSSL_FP_LOOP_DECL(PointMult_Add);
if (0u == index)
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Add,
MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST,
MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST );
NoOfAdd += 1u;
MCUXCLPKC_FP_CALC_OP1_OR_CONST(ECC_XA, ECC_VX2, 0u);
MCUXCLPKC_FP_CALC_OP1_OR_CONST(ECC_YA, ECC_VY2, 0u);
}
else
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Double,
MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE );
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VT2, ECC_VT3, ECC_T2, ECC_T3);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, offsets_VYA_VXA);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VZ0, ECC_VZ, ECC_ZA, ECC_Z);
pOperands[ECC_VZ2] = pOperands[ECC_ZA];
MCUXCLECC_FP_CALCFUP_ONE_DOUBLE();
index -= 2u;
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
scalarWord = pScalar[index / 32u];
scalarBits = (scalarWord >> (index & 31u)) & 0x3u;
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX2, ECC_VY2, offsets_VYA_VXA);
if (0u != scalarBits)
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Add,
MCUXCLECC_FP_CALLED_CALCFUP_ADD_ONLY );
NoOfAdd += 1u;
offsets_VY_VX = pOperands32[(ECC_X1 / 2u) - 1u + scalarBits];
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX1, ECC_VY1, offsets_VY_VX);
MCUXCLECC_FP_CALCFUP_ADD_ONLY();
}
}
while (0u != index)
{
index -= 2u;
if (0x1Eu == (index & 0x1Fu))
{
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
scalarWord = pScalar[index / 32u];
}
scalarBits = (scalarWord >> (index & 0x1Fu)) & 0x3u;
if (0u == scalarBits)
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Double,
MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE );
MCUXCLECC_FP_CALCFUP_ONE_DOUBLE();
}
else
{
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Double);
MCUX_CSSL_FP_LOOP_ITERATION(PointMult_Add,
MCUXCLECC_FP_CALLED_CALCFUP_DOUBLE_ADD );
NoOfAdd += 1u;
offsets_VY_VX = pOperands32[(ECC_X1 / 2u) - 1u + scalarBits];
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX1, ECC_VY1, offsets_VY_VX);
MCUXCLECC_FP_CALCFUP_DOUBLE_ADD();
}
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Int_PointMult, MCUXCLECC_STATUS_OK,
MCUXCLPKC_FP_CALLED_CALC_OP1_NEG,
MCUX_CSSL_FP_LOOP_ITERATIONS(PointMult_Double, scalarBitLen / 2u),
MCUX_CSSL_FP_LOOP_ITERATIONS(PointMult_Add, NoOfAdd) );
}

View File

@ -1,168 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_SecurePointMult_CoZMontLadder.c
* @brief mcuxClEcc: implementation of ECC internal secure PointMult function
*/
#include <stdint.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClCss_Rng.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <internal/mcuxClPkc_Operations.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Internal.h>
#include <internal/mcuxClEcc_Internal_SecurePointSelect.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_SecurePointMult)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_SecurePointMult(uint8_t iScalar,
uint32_t scalarBitLen)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_SecurePointMult,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandomWord),
MCUXCLPKC_FP_CALLED_CALC_OP1_NEG,
MCUXCLECC_FP_CALLED_CALCFUP_ONE_DOUBLE,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint32_t *pOperands32 = (uint32_t *) pOperands;
const uint32_t *pScalar = (const uint32_t *) MCUXCLPKC_OFFSET2PTR(pOperands[iScalar]);
uint8_t *pZA = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_ZA]);
uint32_t operandSize = MCUXCLPKC_PS1_GETOPLEN();
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(ret_Prng_GetRandom0, mcuxClCss_Prng_GetRandom(pZA, operandSize));
if (MCUXCLCSS_STATUS_OK != ret_Prng_GetRandom0)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_SecurePointMult, MCUXCLECC_INTSTATUS_RNG_ERROR);
}
pOperands[ECC_VT] = 0x01u;
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1,
mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN1
+ mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN2);
uint32_t scalarBitIndex = scalarBitLen - 1u;
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
uint32_t scalarWord0 = pScalar[scalarBitIndex / 32u];
uint32_t scalarWord1;
MCUX_CSSL_FP_FUNCTION_CALL(ret_Prng_GetRandWord, mcuxClCss_Prng_GetRandomWord(&scalarWord1));
if (MCUXCLCSS_STATUS_OK != ret_Prng_GetRandWord)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_SecurePointMult, MCUXCLECC_INTSTATUS_RNG_ERROR);
}
while (0u == scalarWord0)
{
scalarBitIndex -= 32u;
scalarWord0 = pScalar[scalarBitIndex / 32u];
}
scalarBitIndex = (scalarBitIndex | 31u) - __CLZ(scalarWord0);
scalarWord0 ^= scalarWord1;
MCUXCLPKC_FP_CALC_OP1_NEG(ECC_ZA, ECC_P);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, ECC_X1, ECC_Y1);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VZ0, ECC_VZ, ECC_ZA, ECC_Z);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX2, ECC_VY2, ECC_X0, ECC_Y0);
pOperands[ECC_VZ2] = pOperands[ECC_ZA];
pOperands[ECC_VT] = pOperands[ECC_T3];
MCUXCLECC_FP_CALCFUP_ONE_DOUBLE();
MCUXCLPKC_FP_CALCFUP_OFFSET(mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1,
mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN1,
mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN2);
MCUX_CSSL_FP_LOOP_DECL(MainLoop);
MCUX_CSSL_FP_LOOP_DECL(RandomizeInMainLoop);
MCUX_CSSL_FP_EXPECT(
MCUX_CSSL_FP_LOOP_ITERATIONS(MainLoop, scalarBitIndex),
MCUX_CSSL_FP_LOOP_ITERATIONS(RandomizeInMainLoop, scalarBitIndex/32u) );
pOperands[ECC_VT] = 0x01u;
while (0u != scalarBitIndex)
{
MCUX_CSSL_FP_LOOP_ITERATION(MainLoop,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandomWord),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
scalarBitIndex -= 1u;
uint32_t bitOffset = scalarBitIndex & 0x1Fu;
if (0x1Fu == bitOffset)
{
MCUX_CSSL_FP_LOOP_ITERATION(RandomizeInMainLoop,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_ReRandomizeUPTRT),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandom),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Prng_GetRandomWord));
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(retReRandomUptrt,
mcuxClPkc_ReRandomizeUPTRT(&pOperands[ECC_X0],
(uint16_t) operandSize,
(ECC_Y1 - ECC_X0 + 1u)) );
if (MCUXCLPKC_STATUS_OK != retReRandomUptrt)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_SecurePointMult, MCUXCLECC_INTSTATUS_RNG_ERROR);
}
MCUX_CSSL_FP_FUNCTION_CALL(ret_Prng_GetRandom1, mcuxClCss_Prng_GetRandom(pZA, operandSize));
if (MCUXCLCSS_STATUS_OK != ret_Prng_GetRandom1)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_SecurePointMult, MCUXCLECC_INTSTATUS_RNG_ERROR);
}
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1,
mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1_LEN);
MCUX_CSSL_FP_FUNCTION_CALL(ret_PRNG_innerloop, mcuxClCss_Prng_GetRandomWord(&scalarWord1));
if (MCUXCLCSS_STATUS_OK != ret_PRNG_innerloop)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_SecurePointMult, MCUXCLECC_INTSTATUS_RNG_ERROR);
}
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
scalarWord0 = pScalar[scalarBitIndex / 32u] ^ scalarWord1;
}
uint32_t offsetsP0;
uint32_t offsetsP1;
uint32_t randomMask;
MCUX_CSSL_FP_FUNCTION_CALL(ret_PRNG_loop, mcuxClCss_Prng_GetRandomWord(&randomMask));
if (MCUXCLCSS_STATUS_OK != ret_PRNG_loop)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_SecurePointMult, MCUXCLECC_INTSTATUS_RNG_ERROR);
}
MCUXCLECC_SECUREPOINTSELECT(offsetsP0, offsetsP1, pOperands,
scalarWord0, scalarWord1, randomMask, bitOffset);
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, offsetsP0);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_VX1, ECC_VY1, offsetsP1);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_CoZPointAddSub, mcuxClEcc_Fup_CoZPointAddSub_LEN);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_CoZPointAddSub, mcuxClEcc_Fup_CoZPointAddSub_LEN1);
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_SecurePointMult, MCUXCLECC_STATUS_OK);
}

View File

@ -1,24 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_SecurePointMult_CoZMontLadder_FUP.c
* @brief mcuxClEcc: implementation of ECC internal secure PointMult function
*/
#include <mcuxClEcc_Internal_SecurePointMult_CoZMontLadder_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_CoZPointAddSub[23], 4u) = {{0x10u,0x00u,0x03u,0x8eu,0x17u,0xbcu},{0x80u,0x2au,0x10u,0x04u,0x08u,0x1eu},{0x80u,0x00u,0x07u,0x1eu,0x00u,0x1du},{0x00u,0x0eu,0x00u,0x1du,0x1du,0x07u},{0x80u,0x00u,0x1eu,0x1eu,0x00u,0x1du},{0x80u,0x00u,0x04u,0x1du,0x00u,0x08u},{0x80u,0x00u,0x1du,0x1eu,0x00u,0x1cu},{0x80u,0x21u,0x10u,0x05u,0x09u,0x1du},{0x80u,0x2au,0x10u,0x05u,0x09u,0x1eu},{0x80u,0x00u,0x05u,0x1cu,0x00u,0x09u},{0x81u,0x2au,0x10u,0x1cu,0x08u,0x1cu},{0x80u,0x00u,0x1eu,0x1eu,0x00u,0x04u},{0x80u,0x21u,0x10u,0x04u,0x1cu,0x04u},{0x80u,0x2au,0x10u,0x08u,0x04u,0x1fu},{0x80u,0x00u,0x1eu,0x1fu,0x00u,0x05u},{0x80u,0x2au,0x10u,0x05u,0x09u,0x05u},{0x10u,0x00u,0x45u,0xdeu,0xf0u,0x34u},{0x00u,0x0eu,0x00u,0x08u,0x08u,0x1eu},{0x80u,0x00u,0x1du,0x1du,0x00u,0x08u},{0x80u,0x21u,0x10u,0x08u,0x1cu,0x08u},{0x80u,0x2au,0x10u,0x1eu,0x08u,0x1eu},{0x80u,0x00u,0x1du,0x1eu,0x00u,0x1cu},{0x80u,0x2au,0x10u,0x1cu,0x09u,0x09u}};
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_SecurePointMult_PrepareZA_UpdateZ_P0_P1[18], 4u) = {{0x10u,0x00u,0x90u,0x45u,0x06u,0x37u},{0x80u,0x33u,0x22u,0x00u,0x00u,0x1cu},{0x00u,0x15u,0x00u,0x1cu,0x0fu,0x22u},{0x00u,0x1au,0x00u,0x22u,0x0fu,0x22u},{0x10u,0x00u,0xabu,0x4cu,0xf7u,0x1eu},{0x80u,0x00u,0x23u,0x22u,0x00u,0x1cu},{0x00u,0x0eu,0x00u,0x1cu,0x1cu,0x23u},{0x80u,0x00u,0x22u,0x22u,0x00u,0x1cu},{0x80u,0x00u,0x22u,0x1cu,0x00u,0x1du},{0x80u,0x00u,0x24u,0x1cu,0x00u,0x1eu},{0x80u,0x00u,0x25u,0x1du,0x00u,0x1fu},{0x00u,0x0eu,0x00u,0x1eu,0x1eu,0x24u},{0x00u,0x0eu,0x00u,0x1fu,0x1fu,0x25u},{0x10u,0x00u,0x02u,0x67u,0x7au,0x53u},{0x80u,0x00u,0x26u,0x1cu,0x00u,0x1eu},{0x80u,0x00u,0x27u,0x1du,0x00u,0x1fu},{0x00u,0x0eu,0x00u,0x1eu,0x1eu,0x26u},{0x00u,0x0eu,0x00u,0x1fu,0x1fu,0x27u}};

View File

@ -1,128 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_SecureScalarMult_XZMontLadder.c
* @brief mcuxClEcc: implementation of ECC internal secure scalar multiplication function montgomery ladder based
*/
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <internal/mcuxClPkc_Operations.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Mont_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_SecureScalarMult_XZMontLadder(uint8_t iScalar, uint32_t scalarBitLen, uint32_t optionAffineOrProjective)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder);
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
const uint32_t *pScalar = (const uint32_t *) MCUXCLPKC_OFFSET2PTR(pOperands[iScalar]);
MCUXCLPKC_FP_CALC_OP1_NEG(MONT_X1, ECC_P);
MCUXCLPKC_FP_CALC_OP1_CONST(MONT_Z1, 0u);
MCUX_CSSL_FP_SWITCH_DECL(optionAffineOrProjectiveSwitch);
if(MCUXCLECC_AFFINE == optionAffineOrProjective)
{
MCUXCLPKC_FP_CALC_OP1_OR_CONST(MONT_X2, MONT_X0, 0u);
MCUXCLPKC_FP_CALC_OP1_NEG(MONT_Z2, ECC_P);
MCUX_CSSL_FP_SWITCH_CASE(optionAffineOrProjectiveSwitch, MCUXCLECC_AFFINE, MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST, MCUXCLPKC_FP_CALLED_CALC_OP1_NEG);
}
else if(MCUXCLECC_PROJECTIVE == optionAffineOrProjective)
{
MCUXCLPKC_FP_CALC_OP1_OR_CONST(MONT_X2, MONT_X0, 0u);
MCUXCLPKC_FP_CALC_OP1_OR_CONST(MONT_Z2, MONT_Z0, 0u);
MCUX_CSSL_FP_SWITCH_CASE(optionAffineOrProjectiveSwitch, MCUXCLECC_PROJECTIVE, MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST, MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST);
}
else
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder, MCUXCLECC_STATUS_FAULT_ATTACK);
}
uint32_t i = scalarBitLen;
MCUX_CSSL_FP_LOOP_DECL(whileLoop);
while(0u < i)
{
--i;
MCUXCLPKC_WAITFORFINISH();
uint32_t currentScalarBitInWord = i % 32u;
uint32_t currentScalarWordIndex = i / 32u;
uint32_t currentScalarWord = pScalar[currentScalarWordIndex];
uint32_t mask = (((uint32_t)1u) << (currentScalarBitInWord + 1u)) - 1u;
uint32_t currentScalarBit = (currentScalarWord & mask) >> currentScalarBitInWord;
MCUX_CSSL_FP_SWITCH_DECL(currentScalarBitSwitch);
MCUXCLPKC_WAITFORFINISH();
if(1u == currentScalarBit)
{
pOperands[MONT_VX1] = pOperands[MONT_X2];
pOperands[MONT_VZ1] = pOperands[MONT_Z2];
pOperands[MONT_VX2] = pOperands[MONT_X1];
pOperands[MONT_VZ2] = pOperands[MONT_Z1];
MCUX_CSSL_FP_SWITCH_CASE(currentScalarBitSwitch, 1u);
}
else if (0u == currentScalarBit)
{
pOperands[MONT_VX1] = pOperands[MONT_X1];
pOperands[MONT_VZ1] = pOperands[MONT_Z1];
pOperands[MONT_VX2] = pOperands[MONT_X2];
pOperands[MONT_VZ2] = pOperands[MONT_Z2];
MCUX_CSSL_FP_SWITCH_CASE(currentScalarBitSwitch, 0u);
}
else {
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUXCLPKC_WAITFORFINISH();
if(MCUXCLECC_PROJECTIVE == optionAffineOrProjective)
{
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_SecureScalarMult_XZMontLadder_LadderStep,
mcuxClEcc_Fup_SecureScalarMult_XZMontLadder_LadderStep_Projective_LEN);
}
else
{
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Fup_SecureScalarMult_XZMontLadder_LadderStep,
mcuxClEcc_Fup_SecureScalarMult_XZMontLadder_LadderStep_Affine_LEN);
}
MCUX_CSSL_FP_LOOP_ITERATION(whileLoop,
MCUX_CSSL_FP_SWITCH_TAKEN(currentScalarBitSwitch, 1u, 1u == currentScalarBit),
MCUX_CSSL_FP_SWITCH_TAKEN(currentScalarBitSwitch, 0u, 0u == currentScalarBit),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup)
);
}
MCUXCLPKC_FP_CALC_OP1_OR_CONST(MONT_X0, MONT_X1, 0u);
MCUXCLPKC_FP_CALC_OP1_OR_CONST(MONT_Z0, MONT_Z1, 0u);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder, MCUXCLECC_STATUS_OK,
MCUXCLPKC_FP_CALLED_CALC_OP1_NEG,
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST,
MCUX_CSSL_FP_SWITCH_TAKEN(optionAffineOrProjectiveSwitch, MCUXCLECC_AFFINE, MCUXCLECC_AFFINE == optionAffineOrProjective),
MCUX_CSSL_FP_SWITCH_TAKEN(optionAffineOrProjectiveSwitch, MCUXCLECC_PROJECTIVE, MCUXCLECC_PROJECTIVE == optionAffineOrProjective),
MCUX_CSSL_FP_LOOP_ITERATIONS(whileLoop, scalarBitLen),
MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST,
MCUXCLPKC_FP_CALLED_CALC_OP1_OR_CONST
);
}

View File

@ -1,22 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Internal_SecureScalarMult_XZMontLadder.c
* @brief mcuxClEcc: implementation of ECC internal secure scalar multiplication function montgomery ladder based
*/
#include <mcuxClEcc_Internal_SecureScalarMult_XZMontLadder_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_SecureScalarMult_XZMontLadder_LadderStep[22], 4u) = {{0x10u,0x00u,0x7du,0x8cu,0x47u,0x56u},{0x80u,0x21u,0x10u,0x0cu,0x0du,0x19u},{0x80u,0x00u,0x19u,0x19u,0x00u,0x1du},{0x80u,0x2au,0x10u,0x0cu,0x0du,0x1bu},{0x80u,0x00u,0x1bu,0x1bu,0x00u,0x1fu},{0x80u,0x00u,0x1du,0x1fu,0x00u,0x0cu},{0x80u,0x2au,0x10u,0x1du,0x1fu,0x1du},{0x80u,0x00u,0x12u,0x1du,0x00u,0x0du},{0x80u,0x21u,0x10u,0x1fu,0x0du,0x1fu},{0x80u,0x00u,0x1du,0x1fu,0x00u,0x0du},{0x80u,0x21u,0x10u,0x0eu,0x0fu,0x1du},{0x80u,0x00u,0x1du,0x1bu,0x00u,0x1fu},{0x80u,0x2au,0x10u,0x0eu,0x0fu,0x1bu},{0x80u,0x00u,0x1bu,0x19u,0x00u,0x1du},{0x80u,0x2au,0x10u,0x1du,0x1fu,0x19u},{0x80u,0x00u,0x19u,0x19u,0x00u,0x1bu},{0x80u,0x00u,0x20u,0x1bu,0x00u,0x0fu},{0x80u,0x21u,0x10u,0x1du,0x1fu,0x19u},{0x80u,0x00u,0x19u,0x19u,0x00u,0x0eu},{0x10u,0x00u,0xc1u,0xbeu,0x00u,0x91u},{0x00u,0x0eu,0x00u,0x0eu,0x0eu,0x1bu},{0x80u,0x00u,0x21u,0x1bu,0x00u,0x0eu}};

View File

@ -1,113 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Internal_SetupEnvironment.c
* @brief mcuxClEcc: implementation of mcuxClEcc_SetupEnvironment
*/
#include <mcuxClSession.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <mcuxClMemory.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Mont_Internal.h>
#define ALIGNED_SIZE(byteLen) ((((byteLen) + (sizeof(uint32_t)) - 1u) / (sizeof(uint32_t))) * (sizeof(uint32_t)))
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_SetupEnvironment)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_SetupEnvironment(mcuxClSession_Handle_t pSession,
mcuxClEcc_CommonDomainParams_t *pCommonDomainParams,
uint8_t noOfBuffers)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_SetupEnvironment);
const uint32_t byteLenP = (uint32_t) pCommonDomainParams->byteLenP;
const uint32_t byteLenN = (uint32_t) pCommonDomainParams->byteLenN;
const uint32_t byteLenMax = ((byteLenP > byteLenN) ? byteLenP : byteLenN);
const uint32_t operandSize = MCUXCLPKC_ROUNDUP_SIZE(byteLenMax);
const uint32_t bufferSize = operandSize + MCUXCLPKC_WORDSIZE;
mcuxClEcc_CpuWa_t *pCpuWorkarea = (mcuxClEcc_CpuWa_t *) (& pSession->cpuWa.buffer[pSession->cpuWa.used]);
uint32_t byteLenOperandsTable = (sizeof(uint16_t)) * (ECC_NO_OF_VIRTUALS + (uint32_t) noOfBuffers);
uint32_t alignedByteLenCpuWa = (sizeof(mcuxClEcc_CpuWa_t)) + ALIGNED_SIZE(byteLenOperandsTable);
uint32_t wordNumCpuWa = alignedByteLenCpuWa / (sizeof(uint32_t));
pSession->cpuWa.used += wordNumCpuWa;
pCpuWorkarea->wordNumCpuWa = wordNumCpuWa;
const uint8_t *pPkcWorkarea = (uint8_t *) (& pSession->pkcWa.buffer[pSession->pkcWa.used]);
const uint32_t wordNumPkcWa = (bufferSize * (uint32_t) noOfBuffers) / (sizeof(uint32_t));
pSession->pkcWa.used += wordNumPkcWa;
pCpuWorkarea->wordNumPkcWa = wordNumPkcWa;
MCUXCLPKC_FP_INITIALIZE(& pCpuWorkarea->pkcStateBackup);
MCUXCLPKC_PS1_SETLENGTH(operandSize, operandSize);
uint16_t *pOperands = (uint16_t *) pCpuWorkarea->pOperands32;
MCUXCLPKC_FP_GENERATEUPTRT(& pOperands[ECC_NO_OF_VIRTUALS],
pPkcWorkarea,
(uint16_t) bufferSize,
noOfBuffers);
MCUXCLPKC_SETUPTRT(pOperands);
pOperands[ECC_P] = pOperands[ECC_PFULL] + MCUXCLPKC_WORDSIZE;
pOperands[ECC_N] = pOperands[ECC_NFULL] + MCUXCLPKC_WORDSIZE;
pOperands[ECC_V0] = 0u;
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_FUP_SetupEnvironment_ClearBuffers,
mcuxClEcc_FUP_SetupEnvironment_ClearBuffers_LEN);
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(retCodeImportP,
mcuxClMemory_copy(MCUXCLPKC_OFFSET2PTR(pOperands[ECC_PFULL]),
pCommonDomainParams->pFullModulusP,
MCUXCLPKC_WORDSIZE + byteLenP, MCUXCLPKC_WORDSIZE + byteLenP));
(void) retCodeImportP;
MCUX_CSSL_FP_FUNCTION_CALL(retCodeImportN,
mcuxClMemory_copy(MCUXCLPKC_OFFSET2PTR(pOperands[ECC_NFULL]),
pCommonDomainParams->pFullModulusN,
MCUXCLPKC_WORDSIZE + byteLenN, MCUXCLPKC_WORDSIZE + byteLenN));
(void) retCodeImportN;
MCUX_CSSL_FP_FUNCTION_CALL(retCodeImportR2P,
mcuxClMemory_copy(MCUXCLPKC_OFFSET2PTR(pOperands[ECC_PQSQR]),
pCommonDomainParams->pR2P,
byteLenP, byteLenP));
(void) retCodeImportR2P;
MCUX_CSSL_FP_FUNCTION_CALL(retCodeImportR2N,
mcuxClMemory_copy(MCUXCLPKC_OFFSET2PTR(pOperands[ECC_NQSQR]),
pCommonDomainParams->pR2N,
byteLenN, byteLenN));
(void) retCodeImportR2N;
MCUXCLMATH_FP_SHIFTMODULUS(ECC_PS, ECC_P);
MCUXCLMATH_FP_SHIFTMODULUS(ECC_NS, ECC_N);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_SetupEnvironment, MCUXCLECC_STATUS_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Initialize),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_GenerateUPTRT),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ShiftModulus),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ShiftModulus) );
}

View File

@ -1,23 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Internal_SetupEnvironment.c
* @brief mcuxClEcc: implementation of mcuxClEcc_SetupEnvironment
*/
#include <mcuxClEcc_Internal_SetupEnvironment_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_FUP_SetupEnvironment_ClearBuffers[5], 4u) = {{0x10u,0x00u,0xfdu,0x0eu,0xa8u,0xbbu},{0x00u,0x3eu,0x00u,0x00u,0x02u,0x00u},{0x00u,0x3eu,0x00u,0x00u,0x02u,0x01u},{0x00u,0x3eu,0x00u,0x00u,0x02u,0x16u},{0x00u,0x3eu,0x00u,0x00u,0x02u,0x17u}};

View File

@ -1,225 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_KeyGen.c
* @brief mcuxClEcc: implementation of ECDSA key generation
*/
#include <stdint.h>
#include <stddef.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <mcuxClSession.h>
#include <mcuxCsslFlowProtection.h>
#include <internal/mcuxClPkc_Operations.h>
#include <internal/mcuxClPkc_ImportExport.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Internal.h>
#include <internal/mcuxClEcc_Internal_FP.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_KeyGen)
mcuxClEcc_Status_Protected_t mcuxClEcc_KeyGen(mcuxClSession_Handle_t pSession,
const mcuxClEcc_KeyGen_Param_t * pParam)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_KeyGen);
const uint32_t byteLenP = (pParam->curveParam.misc & mcuxClEcc_DomainParam_misc_byteLenP_mask) >> mcuxClEcc_DomainParam_misc_byteLenP_offset;
const uint32_t byteLenN = (pParam->curveParam.misc & mcuxClEcc_DomainParam_misc_byteLenN_mask) >> mcuxClEcc_DomainParam_misc_byteLenN_offset;
const uint32_t byteLenMax = ((byteLenP > byteLenN) ? byteLenP : byteLenN);
const uint32_t operandSize = MCUXCLPKC_ROUNDUP_SIZE(byteLenMax);
const uint32_t bufferSize = operandSize + MCUXCLPKC_WORDSIZE;
uint8_t *pPkcWorkarea = (uint8_t *) (& pSession->pkcWa.buffer[pSession->pkcWa.used]);
const uint32_t wordSizePkcWa = (bufferSize * ECC_KEYGEN_NO_OF_BUFFERS) / (sizeof(uint32_t));
pSession->pkcWa.used += wordSizePkcWa;
mcuxClPkc_State_t pkcStateBackup;
MCUXCLPKC_FP_INITIALIZE(& pkcStateBackup);
uint32_t pOperands32[(ECC_KEYGEN_NO_OF_VIRTUALS + ECC_KEYGEN_NO_OF_BUFFERS + 1u) / 2u];
uint16_t *pOperands = (uint16_t *) pOperands32;
MCUXCLPKC_SETUPTRT(pOperands);
MCUXCLPKC_PS1_SETLENGTH(operandSize, operandSize);
uint16_t * pOperands_group0 = & pOperands[ECC_KEYGEN_NO_OF_VIRTUALS];
MCUXCLPKC_FP_GENERATEUPTRT(pOperands_group0, pPkcWorkarea,
(uint16_t) bufferSize, ECC_KEYGEN_NO_OF_BUFFERS0);
MCUX_CSSL_FP_FUNCTION_CALL(retRandomUptrt0,
mcuxClPkc_RandomizeUPTRT(pOperands_group0, ECC_KEYGEN_NO_OF_BUFFERS0) );
if (MCUXCLPKC_STATUS_OK != retRandomUptrt0)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_KEYGEN_RNG_ERROR);
}
uint16_t * pOperands_group1 = & pOperands[ECC_KEYGEN_NO_OF_VIRTUALS + ECC_KEYGEN_NO_OF_BUFFERS0];
const uint8_t * pPkcWorkarea_group1 = & pPkcWorkarea[bufferSize * ECC_KEYGEN_NO_OF_BUFFERS0];
MCUXCLPKC_FP_GENERATEUPTRT(pOperands_group1, pPkcWorkarea_group1,
(uint16_t) (bufferSize * 2u), ECC_KEYGEN_NO_OF_BUFFERS1 / 2u);
MCUX_CSSL_FP_FUNCTION_CALL(retRandomUptrt1,
mcuxClPkc_RandomizeUPTRT(pOperands_group1, ECC_KEYGEN_NO_OF_BUFFERS1 / 2u) );
if (MCUXCLPKC_STATUS_OK != retRandomUptrt1)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_KEYGEN_RNG_ERROR);
}
uint32_t offsetsS0S1 = MCUXCLECC_LOAD_2OFFSETS(pOperands32, ECC_S0, ECC_S1);
uint32_t offsetsS2S3 = MCUXCLECC_LOAD_2OFFSETS(pOperands32, ECC_S2, ECC_S3);
uint32_t offsetsT0T1 = offsetsS0S1 + ((bufferSize << 16) + bufferSize);
uint32_t offsetsT2T3 = offsetsS2S3 + ((bufferSize << 16) + bufferSize);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_T0, ECC_T1, offsetsT0T1);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_T2, ECC_T3, offsetsT2T3);
uint16_t * pOperands_group2 = & pOperands[ECC_KEYGEN_NO_OF_VIRTUALS + ECC_KEYGEN_NO_OF_BUFFERS0 + ECC_KEYGEN_NO_OF_BUFFERS1];
const uint8_t * pPkcWorkarea_group2 = & pPkcWorkarea[bufferSize * (ECC_KEYGEN_NO_OF_BUFFERS0 + ECC_KEYGEN_NO_OF_BUFFERS1)];
MCUXCLPKC_FP_GENERATEUPTRT(pOperands_group2, pPkcWorkarea_group2,
(uint16_t) bufferSize, ECC_KEYGEN_NO_OF_BUFFERS2);
MCUX_CSSL_FP_FUNCTION_CALL(retRandomUptrt2,
mcuxClPkc_RandomizeUPTRT(pOperands_group2, ECC_KEYGEN_NO_OF_BUFFERS2) );
if (MCUXCLPKC_STATUS_OK != retRandomUptrt2)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_KEYGEN_RNG_ERROR);
}
uint32_t nOffset_pOffset = MCUXCLECC_LOAD_2OFFSETS(pOperands32, ECC_PFULL, ECC_NFULL);
nOffset_pOffset += (((uint32_t) MCUXCLPKC_WORDSIZE << 16) | (uint32_t) MCUXCLPKC_WORDSIZE);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_P, ECC_N, nOffset_pOffset);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_P, pParam->curveParam.pP, byteLenP);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_N, pParam->curveParam.pN, byteLenN);
const volatile uint8_t * ptrP = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_P]);
const volatile uint8_t * ptrN = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_N]);
uint32_t p0 = ((const volatile uint32_t *) ptrP)[0];
uint32_t n0 = ((const volatile uint32_t *) ptrN)[0];
if (0x01u != (0x01u & p0 & n0))
{
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_KEYGEN_INVALID_PARAMS,
MCUXCLECC_FP_KEYGEN_CURVE_PARAM_0,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize) );
}
MCUXCLMATH_FP_NDASH(ECC_P, ECC_T0);
MCUXCLMATH_FP_NDASH(ECC_N, ECC_T0);
MCUXCLMATH_FP_SHIFTMODULUS(ECC_PS, ECC_P);
MCUXCLMATH_FP_SHIFTMODULUS(ECC_NS, ECC_N);
MCUXCLMATH_FP_QSQUARED(ECC_PQSQR, ECC_PS, ECC_P, ECC_T0);
MCUXCLMATH_FP_QSQUARED(ECC_NQSQR, ECC_NS, ECC_N, ECC_T0);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_T0, pParam->curveParam.pA, byteLenP);
MCUXCLPKC_FP_CALC_MC1_MM(ECC_R0, ECC_T0, ECC_PQSQR, ECC_P);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_R1, pParam->curveParam.pB, byteLenP);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VA, ECC_VB, ECC_R0, ECC_R1);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_X1, pParam->curveParam.pG, byteLenP);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_Y1, pParam->curveParam.pG + byteLenP, byteLenP);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, ECC_X1, ECC_Y1);
if (MCUXCLECC_INTSTATUS_POINTCHECK_OK != MCUXCLECC_FP_POINTCHECKAFFINENR())
{
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_KEYGEN_INVALID_PARAMS,
MCUXCLECC_FP_KEYGEN_BASE_POINT,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize) );
}
MCUX_CSSL_FP_FUNCTION_CALL(ret_CoreKeyGen, mcuxClEcc_Int_CoreKeyGen(pSession, byteLenN));
if (MCUXCLECC_STATUS_OK != ret_CoreKeyGen)
{
if (MCUXCLECC_INTSTATUS_RNG_ERROR == ret_CoreKeyGen)
{
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_KEYGEN_RNG_ERROR,
MCUXCLECC_FP_KEYGEN_GENERATE_PRIKEY,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize) );
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUXCLPKC_FP_CALC_MC1_MM(ECC_X0, ECC_X1, ECC_PQSQR, ECC_P);
MCUXCLPKC_FP_CALC_MC1_MM(ECC_Y0, ECC_Y1, ECC_PQSQR, ECC_P);
MCUXCLPKC_FP_CALC_OP1_NEG(ECC_Z, ECC_P);
MCUXCLECC_FP_SECUREPOINTMULT(ECC_S0, 64u);
volatile uint32_t *ptrS1 = (volatile uint32_t *)MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S1]);
MCUX_CSSL_FP_BRANCH_DECL(scalarEvenBranch);
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
uint32_t d1Lsbit = (*ptrS1 & 0x01u);
if(d1Lsbit == 0u)
{
MCUXCLPKC_FP_CALC_OP1_SUB(ECC_S1, ECC_N, ECC_S1);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_Y0, ECC_PS, ECC_Y0, ECC_PS);
MCUX_CSSL_FP_BRANCH_POSITIVE(scalarEvenBranch,
MCUXCLPKC_FP_CALLED_CALC_OP1_SUB,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS);
}
MCUXCLECC_FP_SECUREPOINTMULT(ECC_S1, byteLenN * 8u);
MCUX_CSSL_FP_EXPECT(MCUX_CSSL_FP_BRANCH_TAKEN_POSITIVE(scalarEvenBranch, d1Lsbit == 0u));
MCUXCLMATH_FP_MODINV(ECC_T0, ECC_Z, ECC_P, ECC_T1);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_KeyGen_Convert_PubKey,
mcuxClEcc_KeyGen_Convert_PubKey_LEN);
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, ECC_XA, ECC_YA);
if (MCUXCLECC_INTSTATUS_POINTCHECK_OK != MCUXCLECC_FP_POINTCHECKAFFINENR())
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_T0, pParam->curveParam.pP, byteLenP);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_T1, pParam->curveParam.pN, byteLenN);
MCUXCLPKC_FP_CALC_OP1_CMP(ECC_T0, ECC_P);
uint32_t zeroFlag_checkP = MCUXCLPKC_WAITFORFINISH_GETZERO();
MCUXCLPKC_FP_CALC_OP1_CMP(ECC_T1, ECC_N);
uint32_t zeroFlag_checkN = MCUXCLPKC_WAITFORFINISH_GETZERO();
if ( (zeroFlag_checkP == MCUXCLPKC_FLAG_ZERO)
&& (zeroFlag_checkN == MCUXCLPKC_FLAG_ZERO) )
{
MCUXCLPKC_FP_SECUREEXPORTBIGENDIANFROMPKC(pParam->pPrivateKey, ECC_S2, ECC_T0, byteLenN);
MCUXCLPKC_FP_EXPORTBIGENDIANFROMPKC(pParam->pPublicKey, ECC_XA, byteLenP);
MCUXCLPKC_FP_EXPORTBIGENDIANFROMPKC(pParam->pPublicKey + byteLenP, ECC_YA, byteLenP);
MCUXCLPKC_PS1_SETLENGTH(0u, bufferSize * ECC_KEYGEN_NO_OF_BUFFERS);
pOperands[ECC_P] = MCUXCLPKC_PTR2OFFSET(pPkcWorkarea);
MCUXCLPKC_FP_CALC_OP1_CONST(ECC_P, 0u);
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_EXPECT(MCUXCLECC_FP_KEYGEN_CONVERT_PUBKEY);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_KEYGEN_OK,
MCUXCLECC_FP_KEYGEN_FINAL );
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_KeyGen, MCUXCLECC_STATUS_FAULT_ATTACK);
}

View File

@ -1,22 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_KeyGen.fup.c
* @brief mcuxClEcc: FUP program of ECDSA key generation
*/
#include <mcuxClEcc_KeyGen_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_KeyGen_Convert_PubKey[11], 4u) = {{0x10u,0x00u,0xccu,0xc9u,0x9du,0xbeu},{0x80u,0x00u,0x1cu,0x16u,0x00u,0x1du},{0x80u,0x00u,0x1du,0x16u,0x00u,0x1cu},{0x80u,0x00u,0x1cu,0x1cu,0x00u,0x1eu},{0x80u,0x00u,0x1eu,0x1cu,0x00u,0x1fu},{0x80u,0x00u,0x24u,0x1eu,0x00u,0x1cu},{0x80u,0x00u,0x25u,0x1fu,0x00u,0x1du},{0x80u,0x33u,0x1cu,0x00u,0x00u,0x20u},{0x80u,0x33u,0x1du,0x00u,0x00u,0x21u},{0x80u,0x2au,0x00u,0x20u,0x00u,0x20u},{0x80u,0x2au,0x00u,0x21u,0x00u,0x21u}};

View File

@ -1,139 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Mont_DhKeyAgreement.c
* @brief mcuxClEcc: implementation of MontDh key agreement function acc to rfc 7748
*/
#include <stdint.h>
#include <mcuxClSession.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <mcuxClEcc.h>
#include <mcuxClEcc_MemoryConsumption.h>
#include <mcuxCsslParamIntegrity.h>
#include <mcuxCsslMemory.h>
#include <internal/mcuxClPkc_ImportExport.h>
#include <internal/mcuxClEcc_Mont_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Mont_DhKeyAgreement)
mcuxClEcc_Status_Protected_t mcuxClEcc_Mont_DhKeyAgreement(
mcuxClSession_Handle_t session,
mcuxClKey_Handle_t key,
mcuxClKey_Handle_t otherKey,
uint8_t * pOut,
uint32_t * const pOutSize
)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Mont_DhKeyAgreement);
mcuxClKey_Descriptor_t * pKey = (mcuxClKey_Descriptor_t *)key;
mcuxClKey_Descriptor_t * pOtherKey = (mcuxClKey_Descriptor_t *)otherKey;
uint32_t backup_cpuWaUsed = session->cpuWa.used;
uint32_t backup_pkcWaUsed = session->pkcWa.used;
if(((MCUXCLKEY_ALGO_ID_ECC_MONT_GFP | MCUXCLKEY_ALGO_ID_PRIVATE_KEY) != pKey->type.algoId) || (MCUXCLKEY_SIZE_NOTUSED != pKey->type.size)
||((MCUXCLKEY_ALGO_ID_ECC_MONT_GFP | MCUXCLKEY_ALGO_ID_PUBLIC_KEY) != pOtherKey->type.algoId) || (MCUXCLKEY_SIZE_NOTUSED != pOtherKey->type.size)
)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyAgreement, MCUXCLECC_STATUS_FAULT_ATTACK);
}
mcuxClEcc_Mont_DomainParams_t *pDomainParameters = (mcuxClEcc_Mont_DomainParams_t *)(pKey->type.info);
mcuxClEcc_CommonDomainParams_t *pCommonDomainParameters = &(pDomainParameters->common);
if(MCUXCLECC_CURVEID_MONT_X25519 != pCommonDomainParameters->curveID)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyAgreement, MCUXCLECC_STATUS_FAULT_ATTACK);
}
uint16_t keyLen = pCommonDomainParameters->byteLenP;
mcuxClEcc_CpuWa_t *pCpuWorkarea = (mcuxClEcc_CpuWa_t *) (& session->cpuWa.buffer[session->cpuWa.used]);
MCUX_CSSL_FP_FUNCTION_CALL(retCode_Mont_DhSetupEnvironment, mcuxClEcc_Mont_DhSetupEnvironment(session,
pDomainParameters,
ECC_MONTDH_NO_OF_BUFFERS));
if(MCUXCLECC_STATUS_OK != retCode_Mont_DhSetupEnvironment)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyAgreement, MCUXCLECC_STATUS_FAULT_ATTACK);
}
mcuxClPkc_State_t *pPkcStateBackup = &pCpuWorkarea->pkcStateBackup;
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(retCode_importPrivKey, mcuxCsslMemory_Copy(
mcuxCsslParamIntegrity_Protect(4u, pKey->pSrcKeyData, MCUXCLPKC_OFFSET2PTR((pOperands)[ECC_S2]), keyLen, keyLen),
pKey->pSrcKeyData,
MCUXCLPKC_OFFSET2PTR((pOperands)[ECC_S2]),
keyLen,
keyLen));
if(MCUXCSSLMEMORY_COPY_SUCCESS != retCode_importPrivKey)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyAgreement, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUX_CSSL_FP_FUNCTION_CALL(retCode_Mont_Dhx, mcuxClEcc_Mont_DhX(session, pDomainParameters, pOtherKey->pSrcKeyData));
if(MCUXCLECC_STATUS_MONT_RNG_ERROR == retCode_Mont_Dhx)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyAgreement, MCUXCLECC_STATUS_MONT_RNG_ERROR);
}
else if(MCUXCLECC_STATUS_OK != retCode_Mont_Dhx)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyAgreement, MCUXCLECC_STATUS_MONT_DHKEYAGREEMENT_ERROR_SMALL_SUBGROUP,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhSetupEnvironment),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxCsslMemory_Copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhX)
);
}
else
{
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(retCode_exportSS, mcuxCsslMemory_Copy(
mcuxCsslParamIntegrity_Protect(4u, MCUXCLPKC_OFFSET2PTR((pOperands)[MONT_X0]), pOut, keyLen, keyLen),
MCUXCLPKC_OFFSET2PTR((pOperands)[MONT_X0]),
pOut,
keyLen,
keyLen));
if(MCUXCSSLMEMORY_COPY_SUCCESS != retCode_exportSS)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyAgreement, MCUXCLECC_STATUS_FAULT_ATTACK);
}
(*pOutSize) = keyLen;
MCUXCLPKC_FP_DEINITIALIZE(pPkcStateBackup);
session->pkcWa.used = backup_pkcWaUsed;
session->cpuWa.used = backup_cpuWaUsed;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyAgreement, MCUXCLECC_STATUS_MONT_DHKEYAGREEMENT_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhSetupEnvironment),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxCsslMemory_Copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhX),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxCsslMemory_Copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize)
);
}
}

View File

@ -1,153 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Mont_DhKeyGeneration.c
* @brief mcuxClEcc: implementation of MontDh key generation function
*/
#include <stdint.h>
#include <mcuxClSession.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <mcuxClEcc.h>
#include <mcuxClEcc_MemoryConsumption.h>
#include <mcuxCsslMemory.h>
#include <mcuxCsslParamIntegrity.h>
#include <mcuxClKey.h>
#include <internal/mcuxClPkc_ImportExport.h>
#include <internal/mcuxClEcc_Mont_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Mont_DhKeyGeneration)
mcuxClEcc_Status_Protected_t mcuxClEcc_Mont_DhKeyGeneration(
mcuxClSession_Handle_t session,
mcuxClKey_Type_t type,
mcuxClKey_Protection_t protection,
mcuxClKey_Handle_t privKey,
uint8_t * pPrivData,
uint32_t * const pPrivDataSize,
mcuxClKey_Handle_t pubKey,
uint8_t * pPubData,
uint32_t * const pPubDataSize
)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Mont_DhKeyGeneration);
mcuxClKey_Descriptor_t * pPrivKey = (mcuxClKey_Descriptor_t *)privKey;
mcuxClKey_Descriptor_t * pPubKey = (mcuxClKey_Descriptor_t *)pubKey;
uint32_t backup_cpuWaUsed = session->cpuWa.used;
uint32_t backup_pkcWaUsed = session->pkcWa.used;
if((MCUXCLKEY_ALGO_ID_ECC_MONT_GFP | MCUXCLKEY_ALGO_ID_KEY_PAIR) != type.algoId || MCUXCLKEY_SIZE_NOTUSED != type.size)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyGeneration, MCUXCLECC_STATUS_FAULT_ATTACK);
}
mcuxClEcc_Mont_DomainParams_t *pDomainParameters = (mcuxClEcc_Mont_DomainParams_t *)(type.info);
mcuxClEcc_CommonDomainParams_t *pCommonDomainParameters = (mcuxClEcc_CommonDomainParams_t *)&(pDomainParameters->common);
if(MCUXCLECC_CURVEID_MONT_X25519 != pCommonDomainParameters->curveID)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyAgreement, MCUXCLECC_STATUS_FAULT_ATTACK);
}
uint16_t keyLen = pCommonDomainParameters->byteLenP;
mcuxClEcc_CpuWa_t *pCpuWorkarea = (mcuxClEcc_CpuWa_t *) (& session->cpuWa.buffer[session->cpuWa.used]);
MCUX_CSSL_FP_FUNCTION_CALL(retCode_Mont_DhSetupEnvironment, mcuxClEcc_Mont_DhSetupEnvironment(session,
pDomainParameters,
ECC_MONTDH_NO_OF_BUFFERS));
if(MCUXCLECC_STATUS_OK != retCode_Mont_DhSetupEnvironment)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyGeneration, MCUXCLECC_STATUS_FAULT_ATTACK);
}
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
mcuxClPkc_State_t *pPkcStateBackup = &pCpuWorkarea->pkcStateBackup;
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
uint8_t * ptrS2 = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S2]);
MCUX_CSSL_FP_FUNCTION_CALL(retCode_Drbg_GetRandom, mcuxClCss_Rng_DrbgRequest_Async(ptrS2, keyLen));
if(MCUXCLCSS_STATUS_OK_WAIT != retCode_Drbg_GetRandom)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyGeneration, MCUXCLECC_STATUS_MONT_RNG_ERROR);
}
MCUX_CSSL_FP_FUNCTION_CALL(retCode_WaitForOperation, mcuxClCss_WaitForOperation(MCUXCLCSS_ERROR_FLAGS_CLEAR));
if(MCUXCLCSS_STATUS_OK != retCode_WaitForOperation)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyGeneration, MCUXCLECC_STATUS_MONT_RNG_ERROR);
}
MCUX_CSSL_FP_FUNCTION_CALL(retCode_Mont_Dhx, mcuxClEcc_Mont_DhX(session, pDomainParameters, pDomainParameters->pGx));
if(MCUXCLECC_STATUS_MONT_RNG_ERROR == retCode_Mont_Dhx)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyGeneration, MCUXCLECC_STATUS_MONT_RNG_ERROR);
}
else if(MCUXCLECC_STATUS_OK != retCode_Mont_Dhx)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyGeneration, MCUXCLECC_STATUS_FAULT_ATTACK);
}
else
{
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(retCode_exportPrivKey, mcuxCsslMemory_Copy(
mcuxCsslParamIntegrity_Protect(4u, MCUXCLPKC_OFFSET2PTR((pOperands)[ECC_S2]), pPrivData, keyLen, keyLen),
MCUXCLPKC_OFFSET2PTR((pOperands)[ECC_S2]),
pPrivData,
keyLen,
keyLen));
if(MCUXCSSLMEMORY_COPY_SUCCESS != retCode_exportPrivKey)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyGeneration, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUX_CSSL_FP_FUNCTION_CALL(ret_ExportPubKey, mcuxClMemory_copy(pPubData, MCUXCLPKC_OFFSET2PTR((pOperands)[MONT_X0]), keyLen, keyLen));
(void) ret_ExportPubKey;
pPrivKey->type = type;
pPrivKey->type.algoId ^= (MCUXCLKEY_ALGO_ID_KEY_PAIR ^ MCUXCLKEY_ALGO_ID_PRIVATE_KEY);
pPrivKey->protection = &protection;
pPrivKey->pSrcKeyData = pPrivData;
pPubKey->type = type;
pPubKey->type.algoId ^= (MCUXCLKEY_ALGO_ID_KEY_PAIR ^ MCUXCLKEY_ALGO_ID_PUBLIC_KEY);
pPubKey->protection = &protection;
pPubKey->pSrcKeyData = pPubData;
*(pPrivDataSize) = keyLen;
*(pPubDataSize) = keyLen;
MCUXCLPKC_FP_DEINITIALIZE(pPkcStateBackup);
session->pkcWa.used = backup_pkcWaUsed;
session->cpuWa.used = backup_cpuWaUsed;
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhKeyGeneration, MCUXCLECC_STATUS_MONT_DHKEYGENERATION_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhSetupEnvironment),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_Rng_DrbgRequest_Async),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClCss_WaitForOperation),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxCsslMemory_Copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhX),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize)
);
}
}

View File

@ -1,60 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Mont_Internal.c
* @brief mcuxClEcc: implementation of MontDh internal functions
*/
#include <stdint.h>
#include <mcuxClSession.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClMemory.h>
#include <internal/mcuxClPkc_Operations.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Mont_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Mont_DhSetupEnvironment)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_DhSetupEnvironment(mcuxClSession_Handle_t pSession,
mcuxClEcc_Mont_DomainParams_t *pDomainParams,
uint8_t noOfBuffers)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Mont_DhSetupEnvironment);
MCUX_CSSL_FP_FUNCTION_CALL(retSetupEnv,
mcuxClEcc_SetupEnvironment(pSession, &(pDomainParams->common), noOfBuffers));
(void) retSetupEnv;
const uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
MCUXCLPKC_FP_CALC_OP1_CONST(ECC_T0, 0u);
uint32_t byteLenP = (uint32_t) pDomainParams->common.byteLenP;
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(retCodeImport,
mcuxClMemory_copy(MCUXCLPKC_OFFSET2PTR(pOperands[ECC_T0]),
pDomainParams->pA24,
byteLenP, byteLenP));
(void) retCodeImport;
MCUXCLPKC_FP_CALC_MC1_MM(ECC_CP0, ECC_T0, ECC_PQSQR, ECC_P);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhSetupEnvironment, MCUXCLECC_STATUS_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_SetupEnvironment),
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_copy),
MCUXCLPKC_FP_CALLED_CALC_MC1_MM );
}

View File

@ -1,187 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Mont_MontDhX.c
* @brief mcuxClEcc: implementation of MontDhX functions
*/
#include <stdint.h>
#include <mcuxCsslFlowProtection.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <mcuxClMemory.h>
#include <internal/mcuxClPkc_Operations.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Mont_Internal.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Mont_DhDecodeScalar)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_DhDecodeScalar(
mcuxClEcc_Mont_DomainParams_t *pDomainParameters)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Mont_DhDecodeScalar);
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint32_t c = (uint32_t) pDomainParameters->c;
uint32_t t = (uint32_t) pDomainParameters->t;
MCUXCLPKC_WAITFORREADY();
pOperands[MONT_V0] = (uint16_t) c;
pOperands[MONT_V1] = (uint16_t) (c - t);
pOperands[MONT_V2] = (uint16_t) 1u;
pOperands[MONT_V3] = (uint16_t) (0u - t);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_FUP_MontDhDecodeScalar,
mcuxClEcc_FUP_MontDhDecodeScalar_LEN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhDecodeScalar, MCUXCLECC_STATUS_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup));
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Mont_DhDecodeCoordinate)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_DhDecodeCoordinate(
mcuxClEcc_Mont_DomainParams_t *pDomainParameters,
const uint8_t *pCoordinateEnc)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Mont_DhDecodeCoordinate);
const uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
uint8_t *pT0 = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_T0]);
uint32_t byteLenP = (uint32_t) pDomainParameters->common.byteLenP;
MCUX_CSSL_FP_FUNCTION_CALL(retCodeMemCopy,
mcuxClMemory_copy(pT0, pCoordinateEnc, byteLenP, byteLenP));
(void) retCodeMemCopy;
uint32_t leadingZerosP = MCUXCLMATH_FP_LEADINGZEROS(ECC_P);
if (0u != leadingZerosP)
{
uint32_t operandSize = MCUXCLPKC_PS1_GETOPLEN();
uint32_t bitLenP = (operandSize * 8u) - leadingZerosP;
uint32_t mask = ((uint32_t) 1u << (bitLenP % 32u)) - 1u;
uint32_t *p32T0 = (uint32_t *) pT0;
p32T0[bitLenP / 32u] &= mask;
}
MCUXCLPKC_FP_CALC_MC1_MM(MONT_X0, ECC_T0, ECC_PQSQR, ECC_P);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhDecodeCoordinate, MCUXCLECC_STATUS_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMemory_copy),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_LeadingZeros),
MCUXCLPKC_FP_CALLED_CALC_MC1_MM);
}
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Mont_DhX)
MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEcc_Status_t) mcuxClEcc_Mont_DhX(
mcuxClSession_Handle_t pSession,
mcuxClEcc_Mont_DomainParams_t *pDomainParameters,
const uint8_t *pCoordinateUEnc)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Mont_DhX);
MCUX_CSSL_FP_FUNCTION_CALL(retDecodeScalar,
mcuxClEcc_Mont_DhDecodeScalar(pDomainParameters));
(void) retDecodeScalar;
MCUXCLPKC_FP_CALC_OP1_SHR(ECC_S3,ECC_S3, pDomainParameters->c);
MCUX_CSSL_FP_FUNCTION_CALL(retGenMulBlind,
mcuxClEcc_GenerateMultiplicativeBlinding(pSession));
if (MCUXCLECC_STATUS_OK != retGenMulBlind)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhX, MCUXCLECC_STATUS_MONT_RNG_ERROR);
};
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(retDecodeCoordinate,
mcuxClEcc_Mont_DhDecodeCoordinate(pDomainParameters, pCoordinateUEnc));
(void) retDecodeCoordinate;
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
uint32_t operandSize = MCUXCLPKC_PS1_GETOPLEN();
uint32_t leadingZeroN = MCUXCLMATH_FP_LEADINGZEROS(ECC_N);
uint32_t bitLenN = (operandSize * 8u) - leadingZeroN;
MCUX_CSSL_FP_FUNCTION_CALL(retSecScalarMult0,
mcuxClEcc_Mont_SecureScalarMult_XZMontLadder(ECC_S1, bitLenN, MCUXCLECC_AFFINE));
if (MCUXCLECC_STATUS_OK != retSecScalarMult0)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhX, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUX_CSSL_FP_FUNCTION_CALL(retSecScalarMult1,
mcuxClEcc_Mont_SecureScalarMult_XZMontLadder(ECC_S0, MCUXCLECC_MONT_DH_SCALAR_BLINDING_BYTELEN * 8u, MCUXCLECC_PROJECTIVE));
if (MCUXCLECC_STATUS_OK != retSecScalarMult1)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhX, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUXCLPKC_FP_CALC_OP1_CONST(ECC_S0, 0u);
uint16_t *pOperands = MCUXCLPKC_GETUPTRT();
uint8_t *pS0 = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S0]);
*(pS0) = (1u << pDomainParameters->c);
MCUX_CSSL_FP_FUNCTION_CALL(retSecScalarMult2,
mcuxClEcc_Mont_SecureScalarMult_XZMontLadder(ECC_S0, (uint32_t)(pDomainParameters->c) + 1u, MCUXCLECC_PROJECTIVE));
if (MCUXCLECC_STATUS_OK != retSecScalarMult2)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhX, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUXCLPKC_FP_CALC_MC1_MR(ECC_T0, MONT_Z0, ECC_P);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_T0, ECC_T0, ECC_P, ECC_P);
uint32_t pkcStatus = MCUXCLPKC_WAITFORFINISH_GETSTATUS();
uint32_t zeroFlag = (pkcStatus & MCUXCLPKC_STATUS_ZERO_MSK) >> MCUXCLPKC_STATUS_ZERO_POS;
if (MCUXCLPKC_FLAG_ZERO == zeroFlag)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhX, MCUXCLECC_INTSTATUS_POINTMULT_NEUTRAL_POINT,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhDecodeScalar),
MCUXCLPKC_FP_CALLED_CALC_OP1_SHR,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_GenerateMultiplicativeBlinding),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhDecodeCoordinate),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_LeadingZeros),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder),
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder),
MCUXCLPKC_FP_CALLED_CALC_MC1_MR,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS );
}
MCUXCLMATH_FP_MODINV(ECC_T1, ECC_T0, ECC_P, MONT_Z0);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_FUP_MontDhX_CalcAffineX,
mcuxClEcc_FUP_MontDhX_CalcAffineX_LEN);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Mont_DhX, MCUXCLECC_STATUS_OK,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhDecodeScalar),
MCUXCLPKC_FP_CALLED_CALC_OP1_SHR,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_GenerateMultiplicativeBlinding),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_DhDecodeCoordinate),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_LeadingZeros),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder),
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_Mont_SecureScalarMult_XZMontLadder),
MCUXCLPKC_FP_CALLED_CALC_MC1_MR,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClMath_ModInv),
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_CalcFup) );
}

View File

@ -1,25 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_Mont_MontDhX.c
* @brief mcuxClEcc: implementation of MontDhX functions
*/
#include <mcuxClEcc_Mont_MontDhX_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_FUP_MontDhDecodeScalar[5], 4u) = {{0x10u,0x00u,0x3bu,0xfbu,0x7bu,0xf5u},{0x00u,0x15u,0x00u,0x1cu,0x02u,0x1eu},{0x00u,0x14u,0x00u,0x1eu,0x03u,0x1eu},{0x00u,0x1au,0x00u,0x1eu,0x04u,0x1eu},{0x00u,0x17u,0x00u,0x1eu,0x05u,0x1eu}};
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_FUP_MontDhX_CalcAffineX[5], 4u) = {{0x10u,0x00u,0x11u,0x0bu,0x8fu,0x7du},{0x80u,0x00u,0x1bu,0x16u,0x00u,0x19u},{0x80u,0x00u,0x20u,0x19u,0x00u,0x1bu},{0x80u,0x33u,0x1bu,0x00u,0x00u,0x20u},{0x80u,0x2au,0x00u,0x20u,0x00u,0x20u}};

View File

@ -1,24 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_NIST_FUP.c
* @brief mcuxClEcc: FUP programs used in ECC functions for NIST curves
*/
#include <mcuxClEcc_NIST_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_PointCheckAffNR_NIST[11], 4u) = {{0x10u,0x00u,0xf5u,0xd9u,0x1fu,0xb9u},{0x80u,0x2au,0x10u,0x0bu,0x04u,0x1du},{0x81u,0x2au,0x10u,0x1du,0x04u,0x1du},{0x80u,0x33u,0x1du,0x00u,0x00u,0x1cu},{0x80u,0x00u,0x05u,0x05u,0x00u,0x1du},{0x80u,0x2au,0x10u,0x1du,0x1cu,0x1du},{0x80u,0x33u,0x1du,0x00u,0x00u,0x1cu},{0x80u,0x00u,0x04u,0x04u,0x00u,0x1du},{0x80u,0x00u,0x1du,0x04u,0x00u,0x1eu},{0x80u,0x2au,0x10u,0x1cu,0x1eu,0x1cu},{0x80u,0x2au,0x00u,0x1cu,0x00u,0x1cu}};
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Fup_RepeatDouble_NIST[24], 4u) = {{0x10u,0x00u,0x62u,0xc1u,0xf6u,0x20u},{0x80u,0x00u,0x0eu,0x07u,0x00u,0x1cu},{0x80u,0x00u,0x1cu,0x1cu,0x00u,0x0fu},{0x10u,0x00u,0x09u,0x4eu,0xc9u,0x75u},{0x80u,0x2au,0x10u,0x0cu,0x0fu,0x1cu},{0x80u,0x21u,0x10u,0x0cu,0x0fu,0x1du},{0x80u,0x00u,0x1cu,0x1du,0x00u,0x1eu},{0x80u,0x21u,0x10u,0x1eu,0x1eu,0x1cu},{0x80u,0x21u,0x10u,0x1cu,0x1eu,0x1cu},{0x80u,0x21u,0x10u,0x0du,0x0du,0x1du},{0x80u,0x00u,0x1du,0x0eu,0x00u,0x1eu},{0x00u,0x0eu,0x00u,0x1eu,0x1eu,0x06u},{0x80u,0x00u,0x1du,0x0du,0x00u,0x1eu},{0x80u,0x21u,0x10u,0x1eu,0x1eu,0x1du},{0x80u,0x00u,0x0cu,0x1du,0x00u,0x1fu},{0x80u,0x00u,0x1cu,0x1cu,0x00u,0x04u},{0x81u,0x2au,0x10u,0x04u,0x1fu,0x04u},{0x80u,0x00u,0x1du,0x1eu,0x00u,0x05u},{0x80u,0x2au,0x10u,0x1fu,0x04u,0x1fu},{0x80u,0x00u,0x1cu,0x1fu,0x00u,0x1eu},{0x80u,0x2au,0x10u,0x1eu,0x05u,0x05u},{0x10u,0x00u,0x66u,0xfau,0xe1u,0xcau},{0x00u,0x0eu,0x00u,0x0fu,0x0fu,0x1eu},{0x80u,0x00u,0x1du,0x1eu,0x00u,0x0fu}};

View File

@ -1,230 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020-2021 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/**
* @file mcuxClEcc_PointMult.c
* @brief mcuxClEcc: implementation of ECC point multiplication
*/
#include <stdint.h>
#include <stddef.h>
#include <mcuxClCss_Rng.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <mcuxClSession.h>
#include <mcuxCsslFlowProtection.h>
#include <internal/mcuxClPkc_Operations.h>
#include <internal/mcuxClPkc_ImportExport.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Internal.h>
#include <internal/mcuxClEcc_Internal_FP.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_PointMult)
mcuxClEcc_Status_Protected_t mcuxClEcc_PointMult(mcuxClSession_Handle_t pSession,
const mcuxClEcc_PointMult_Param_t * pParam)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_PointMult);
const uint32_t byteLenP = (pParam->curveParam.misc & mcuxClEcc_DomainParam_misc_byteLenP_mask) >> mcuxClEcc_DomainParam_misc_byteLenP_offset;
const uint32_t byteLenN = (pParam->curveParam.misc & mcuxClEcc_DomainParam_misc_byteLenN_mask) >> mcuxClEcc_DomainParam_misc_byteLenN_offset;
const uint32_t byteLenMax = ((byteLenP > byteLenN) ? byteLenP : byteLenN);
const uint32_t operandSize = MCUXCLPKC_ROUNDUP_SIZE(byteLenMax);
const uint32_t bufferSize = operandSize + MCUXCLPKC_WORDSIZE;
uint8_t *pPkcWorkarea = (uint8_t *) (& pSession->pkcWa.buffer[pSession->pkcWa.used]);
const uint32_t wordSizePkcWa = (bufferSize * ECC_POINTMULT_NO_OF_BUFFERS) / (sizeof(uint32_t));
pSession->pkcWa.used += wordSizePkcWa;
mcuxClPkc_State_t pkcStateBackup;
MCUXCLPKC_FP_INITIALIZE(& pkcStateBackup);
uint32_t pOperands32[(ECC_POINTMULT_NO_OF_VIRTUALS + ECC_POINTMULT_NO_OF_BUFFERS + 1u) / 2u];
uint16_t *pOperands = (uint16_t *) pOperands32;
MCUXCLPKC_SETUPTRT(pOperands);
MCUXCLPKC_PS1_SETLENGTH(operandSize, operandSize);
uint16_t * pOperands_realBuffer = & pOperands[ECC_POINTMULT_NO_OF_VIRTUALS];
MCUXCLPKC_FP_GENERATEUPTRT(pOperands_realBuffer, pPkcWorkarea,
(uint16_t) bufferSize, ECC_POINTMULT_NO_OF_BUFFERS);
MCUX_CSSL_FP_FUNCTION_CALL(retRandomUptrt, mcuxClPkc_RandomizeUPTRT(pOperands_realBuffer, ECC_POINTMULT_NO_OF_BUFFERS));
if (MCUXCLPKC_STATUS_OK != retRandomUptrt)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointMult, MCUXCLECC_STATUS_POINTMULT_RNG_ERROR);
}
uint32_t nOffset_pOffset = MCUXCLECC_LOAD_2OFFSETS(pOperands32, ECC_PFULL, ECC_NFULL);
nOffset_pOffset += (((uint32_t) MCUXCLPKC_WORDSIZE << 16) | (uint32_t) MCUXCLPKC_WORDSIZE);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_P, ECC_N, nOffset_pOffset);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_P, pParam->curveParam.pP, byteLenP);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_N, pParam->curveParam.pN, byteLenN);
const volatile uint8_t * ptrP = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_P]);
const volatile uint8_t * ptrN = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_N]);
uint32_t p0 = ((const volatile uint32_t *) ptrP)[0];
uint32_t n0 = ((const volatile uint32_t *) ptrN)[0];
if (0x01u != (0x01u & p0 & n0))
{
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointMult, MCUXCLECC_STATUS_POINTMULT_INVALID_PARAMS,
MCUXCLECC_FP_POINTMULT_CURVE_PARAM_0,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize) );
}
MCUXCLMATH_FP_NDASH(ECC_P, ECC_T0);
MCUXCLMATH_FP_NDASH(ECC_N, ECC_T0);
MCUXCLMATH_FP_SHIFTMODULUS(ECC_PS, ECC_P);
MCUXCLMATH_FP_SHIFTMODULUS(ECC_NS, ECC_N);
MCUXCLMATH_FP_QSQUARED(ECC_PQSQR, ECC_PS, ECC_P, ECC_T0);
MCUXCLMATH_FP_QDASH(ECC_NQSQR, ECC_NS, ECC_N, ECC_T0, (uint16_t) (operandSize + bufferSize));
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_T0, pParam->curveParam.pA, byteLenP);
MCUXCLPKC_FP_CALC_MC1_MM(ECC_R0, ECC_T0, ECC_PQSQR, ECC_P);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_R1, pParam->curveParam.pB, byteLenP);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VA, ECC_VB, ECC_R0, ECC_R1);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_X1, pParam->pPoint, byteLenP);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_Y1, pParam->pPoint + byteLenP, byteLenP);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, ECC_X1, ECC_Y1);
if (MCUXCLECC_INTSTATUS_POINTCHECK_OK != MCUXCLECC_FP_POINTCHECKAFFINENR())
{
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointMult, MCUXCLECC_STATUS_POINTMULT_INVALID_PARAMS,
MCUXCLECC_FP_POINTMULT_BASE_POINT,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize) );
}
MCUXCLPKC_FP_CALC_OP1_CONST(ECC_S0, 0u);
uint32_t *ptr32S0 = (uint32_t *) MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S0]);
MCUXCLPKC_WAITFORFINISH();
MCUX_CSSL_FP_FUNCTION_CALL(ret_PRNG_randWord1,mcuxClCss_Prng_GetRandom((uint8_t*)&ptr32S0[0],(2u * sizeof(uint32_t))));
if (MCUXCLCSS_STATUS_OK != ret_PRNG_randWord1)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointMult, MCUXCLECC_STATUS_POINTMULT_RNG_ERROR);
}
ptr32S0[0] |= 0x00000001u;
ptr32S0[1] |= 0x80000000u;
MCUXCLPKC_FP_CALC_OP1_OR_CONST(ECC_S1, ECC_S0, 0u);
MCUXCLMATH_FP_MODINV(ECC_T0, ECC_S1, ECC_N, ECC_T1);
MCUXCLPKC_WAITFORREADY();
MCUXCLPKC_PS1_SETLENGTH(0u, bufferSize);
MCUXCLPKC_FP_SECUREIMPORTBIGENDIANTOPKC(ECC_S1, pParam->pScalar, ECC_T1, byteLenN);
uint8_t *ptrS2 = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S2]);
MCUX_CSSL_FP_FUNCTION_CALL(ret_PRNG_GetRandom, mcuxClCss_Prng_GetRandom(ptrS2, bufferSize));
if (MCUXCLCSS_STATUS_OK != ret_PRNG_GetRandom)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointMult, MCUXCLECC_STATUS_POINTMULT_RNG_ERROR);
}
MCUXCLPKC_FP_CALC_OP1_SHR(ECC_S2, ECC_S2, 1u);
MCUXCLPKC_FP_CALC_OP1_ADD(ECC_S3, ECC_S1, ECC_S2);
MCUXCLPKC_WAITFORREADY();
MCUXCLPKC_PS1_SETLENGTH(operandSize, operandSize);
MCUXCLPKC_PS2_SETLENGTH(bufferSize, operandSize);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_PointMult_SplitScalar_ConvertPoint2MR,
mcuxClEcc_PointMult_SplitScalar_ConvertPoint2MR_LEN);
if (MCUXCLPKC_FLAG_ZERO == MCUXCLPKC_WAITFORFINISH_GETZERO())
{
MCUXCLPKC_PS1_SETLENGTH(0u, bufferSize * ECC_POINTMULT_NO_OF_BUFFERS);
pOperands[ECC_P] = MCUXCLPKC_PTR2OFFSET(pPkcWorkarea);
MCUXCLPKC_FP_CALC_OP1_CONST(ECC_P, 0u);
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointMult, MCUXCLECC_STATUS_POINTMULT_NEUTRAL_POINT,
MCUXCLECC_FP_POINTMULT_SCALAR,
MCUXCLPKC_FP_CALLED_CALC_OP1_CONST,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize) );
}
MCUXCLECC_FP_SECUREPOINTMULT(ECC_S0, 64u);
volatile uint32_t *ptrS1 = (volatile uint32_t *)MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S1]);
MCUX_CSSL_FP_BRANCH_DECL(scalarEvenBranch);
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
uint32_t d1Lsbit = (*ptrS1 & 0x01u);
if(d1Lsbit == 0u)
{
MCUXCLPKC_FP_CALC_OP1_SUB(ECC_S1, ECC_N, ECC_S1);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_Y0, ECC_PS, ECC_Y0, ECC_PS);
MCUX_CSSL_FP_BRANCH_POSITIVE(scalarEvenBranch,
MCUXCLPKC_FP_CALLED_CALC_OP1_SUB,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS);
}
MCUXCLECC_FP_SECUREPOINTMULT(ECC_S1, byteLenN * 8u);
MCUX_CSSL_FP_EXPECT(MCUX_CSSL_FP_BRANCH_TAKEN_POSITIVE(scalarEvenBranch, d1Lsbit == 0u));
MCUXCLMATH_FP_MODINV(ECC_T0, ECC_Z, ECC_P, ECC_T1);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_KeyGen_Convert_PubKey,
mcuxClEcc_KeyGen_Convert_PubKey_LEN);
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, ECC_XA, ECC_YA);
if (MCUXCLECC_INTSTATUS_POINTCHECK_OK != MCUXCLECC_FP_POINTCHECKAFFINENR())
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointMult, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_T0, pParam->curveParam.pP, byteLenP);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_T1, pParam->curveParam.pN, byteLenN);
MCUXCLPKC_FP_CALC_OP1_CMP(ECC_T0, ECC_P);
uint32_t zeroFlag_checkP = MCUXCLPKC_WAITFORFINISH_GETZERO();
MCUXCLPKC_FP_CALC_OP1_CMP(ECC_T1, ECC_N);
uint32_t zeroFlag_checkN = MCUXCLPKC_WAITFORFINISH_GETZERO();
if ( (zeroFlag_checkP == MCUXCLPKC_FLAG_ZERO)
&& (zeroFlag_checkN == MCUXCLPKC_FLAG_ZERO) )
{
MCUXCLPKC_FP_SECUREEXPORTBIGENDIANFROMPKC(pParam->pResult, ECC_XA, ECC_T0, byteLenP);
MCUXCLPKC_FP_SECUREEXPORTBIGENDIANFROMPKC(pParam->pResult + byteLenP, ECC_YA, ECC_T1, byteLenP);
MCUXCLPKC_PS1_SETLENGTH(0u, bufferSize * ECC_POINTMULT_NO_OF_BUFFERS);
pOperands[ECC_P] = MCUXCLPKC_PTR2OFFSET(pPkcWorkarea);
MCUXCLPKC_FP_CALC_OP1_CONST(ECC_P, 0u);
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_EXPECT(MCUXCLECC_FP_POINTMULT_CONVERT_POINT);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointMult, MCUXCLECC_STATUS_POINTMULT_OK,
MCUXCLECC_FP_POINTMULT_FINAL );
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_PointMult, MCUXCLECC_STATUS_FAULT_ATTACK);
}

View File

@ -1,22 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_PointMult.fup.fup.c
* @brief mcuxClEcc: FUP program of ECDSA point multiplication
*/
#include <mcuxClEcc_PointMult_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_PointMult_SplitScalar_ConvertPoint2MR[10], 4u) = {{0x10u,0x00u,0x42u,0xa3u,0x3fu,0x9fu},{0x80u,0x00u,0x1cu,0x17u,0x01u,0x19u},{0xc0u,0x00u,0x1au,0x19u,0x01u,0x1cu},{0xc0u,0x00u,0x1bu,0x19u,0x01u,0x1du},{0x80u,0x00u,0x26u,0x16u,0x00u,0x24u},{0x80u,0x00u,0x27u,0x16u,0x00u,0x25u},{0x00u,0x09u,0x00u,0x00u,0x00u,0x23u},{0x80u,0x2au,0x11u,0x1du,0x1cu,0x1du},{0x80u,0x33u,0x1du,0x00u,0x01u,0x1cu},{0x80u,0x2au,0x01u,0x1cu,0x01u,0x19u}};

View File

@ -1,299 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Sign.c
* @brief mcuxClEcc: implementation of ECDSA signature generation
*/
#include <stdint.h>
#include <stddef.h>
#include <mcuxClCss_Rng.h>
#include <mcuxClPkc.h>
#include <mcuxClMath.h>
#include <mcuxClSession.h>
#include <mcuxCsslFlowProtection.h>
#include <internal/mcuxClPkc_Operations.h>
#include <internal/mcuxClPkc_ImportExport.h>
#include <mcuxClEcc.h>
#include <internal/mcuxClEcc_Internal.h>
#include <internal/mcuxClEcc_Internal_FP.h>
MCUX_CSSL_FP_FUNCTION_DEF(mcuxClEcc_Sign)
mcuxClEcc_Status_Protected_t mcuxClEcc_Sign(mcuxClSession_Handle_t pSession,
const mcuxClEcc_Sign_Param_t * pParam)
{
MCUX_CSSL_FP_FUNCTION_ENTRY(mcuxClEcc_Sign);
const uint32_t byteLenP = (pParam->curveParam.misc & mcuxClEcc_DomainParam_misc_byteLenP_mask) >> mcuxClEcc_DomainParam_misc_byteLenP_offset;
const uint32_t byteLenN = (pParam->curveParam.misc & mcuxClEcc_DomainParam_misc_byteLenN_mask) >> mcuxClEcc_DomainParam_misc_byteLenN_offset;
const uint32_t byteLenMax = ((byteLenP > byteLenN) ? byteLenP : byteLenN);
const uint32_t operandSize = MCUXCLPKC_ROUNDUP_SIZE(byteLenMax);
const uint32_t bufferSize = operandSize + MCUXCLPKC_WORDSIZE;
uint8_t *pPkcWorkarea = (uint8_t *) (& pSession->pkcWa.buffer[pSession->pkcWa.used]);
const uint32_t wordSizePkcWa = (bufferSize * ECC_SIGN_NO_OF_BUFFERS) / (sizeof(uint32_t));
pSession->pkcWa.used += wordSizePkcWa;
mcuxClPkc_State_t pkcStateBackup;
MCUXCLPKC_FP_INITIALIZE(& pkcStateBackup);
uint32_t pOperands32[(ECC_SIGN_NO_OF_VIRTUALS + ECC_SIGN_NO_OF_BUFFERS + 1u) / 2u];
uint16_t *pOperands = (uint16_t *) pOperands32;
MCUXCLPKC_SETUPTRT(pOperands);
MCUXCLPKC_PS1_SETLENGTH(operandSize, operandSize);
uint16_t * pOperands_group0 = & pOperands[ECC_SIGN_NO_OF_VIRTUALS];
MCUXCLPKC_FP_GENERATEUPTRT(pOperands_group0, pPkcWorkarea,
(uint16_t) bufferSize, ECC_SIGN_NO_OF_BUFFERS0);
MCUX_CSSL_FP_FUNCTION_CALL(retRandomUptrt0,
mcuxClPkc_RandomizeUPTRT(pOperands_group0, ECC_SIGN_NO_OF_BUFFERS0) );
if (MCUXCLPKC_STATUS_OK != retRandomUptrt0)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_SIGN_RNG_ERROR);
}
uint16_t * pOperands_group1 = & pOperands[ECC_SIGN_NO_OF_VIRTUALS + ECC_SIGN_NO_OF_BUFFERS0];
const uint8_t * pPkcWorkarea_group1 = & pPkcWorkarea[bufferSize * ECC_SIGN_NO_OF_BUFFERS0];
MCUXCLPKC_FP_GENERATEUPTRT(pOperands_group1, pPkcWorkarea_group1,
(uint16_t) (bufferSize * 2u), ECC_SIGN_NO_OF_BUFFERS1 / 2u);
MCUX_CSSL_FP_FUNCTION_CALL(retRandomUptrt1,
mcuxClPkc_RandomizeUPTRT(pOperands_group1, ECC_SIGN_NO_OF_BUFFERS1 / 2u) );
if (MCUXCLPKC_STATUS_OK != retRandomUptrt1)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_SIGN_RNG_ERROR);
}
uint32_t offsetsS0S1 = MCUXCLECC_LOAD_2OFFSETS(pOperands32, ECC_S0, ECC_S1);
uint32_t offsetsS2S3 = MCUXCLECC_LOAD_2OFFSETS(pOperands32, ECC_S2, ECC_S3);
uint32_t offsetsT0T1 = offsetsS0S1 + ((bufferSize << 16) + bufferSize);
uint32_t offsetsT2T3 = offsetsS2S3 + ((bufferSize << 16) + bufferSize);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_T0, ECC_T1, offsetsT0T1);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_T2, ECC_T3, offsetsT2T3);
uint16_t * pOperands_group2 = & pOperands[ECC_SIGN_NO_OF_VIRTUALS + ECC_SIGN_NO_OF_BUFFERS0 + ECC_SIGN_NO_OF_BUFFERS1];
const uint8_t * pPkcWorkarea_group2 = & pPkcWorkarea[bufferSize * (ECC_SIGN_NO_OF_BUFFERS0 + ECC_SIGN_NO_OF_BUFFERS1)];
MCUXCLPKC_FP_GENERATEUPTRT(pOperands_group2, pPkcWorkarea_group2,
(uint16_t) bufferSize, ECC_SIGN_NO_OF_BUFFERS2);
MCUX_CSSL_FP_FUNCTION_CALL(retRandomUptrt2,
mcuxClPkc_RandomizeUPTRT(pOperands_group2, ECC_SIGN_NO_OF_BUFFERS2) );
if (MCUXCLPKC_STATUS_OK != retRandomUptrt2)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_SIGN_RNG_ERROR);
}
uint32_t nOffset_pOffset = MCUXCLECC_LOAD_2OFFSETS(pOperands32, ECC_PFULL, ECC_NFULL);
nOffset_pOffset += (((uint32_t) MCUXCLPKC_WORDSIZE << 16) | (uint32_t) MCUXCLPKC_WORDSIZE);
MCUXCLECC_STORE_2OFFSETS(pOperands32, ECC_P, ECC_N, nOffset_pOffset);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_P, pParam->curveParam.pP, byteLenP);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_N, pParam->curveParam.pN, byteLenN);
const volatile uint8_t * ptrP = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_P]);
const volatile uint8_t * ptrN = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_N]);
uint32_t p0 = ((const volatile uint32_t *) ptrP)[0];
uint32_t n0 = ((const volatile uint32_t *) ptrN)[0];
if (0x01u != (0x01u & p0 & n0))
{
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_SIGN_INVALID_PARAMS,
MCUXCLECC_FP_SIGN_CURVE_PARAM_0,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize) );
}
MCUXCLMATH_FP_NDASH(ECC_P, ECC_T0);
MCUXCLMATH_FP_NDASH(ECC_N, ECC_T0);
MCUXCLMATH_FP_SHIFTMODULUS(ECC_PS, ECC_P);
MCUXCLMATH_FP_SHIFTMODULUS(ECC_NS, ECC_N);
MCUXCLMATH_FP_QSQUARED(ECC_PQSQR, ECC_PS, ECC_P, ECC_T0);
MCUXCLMATH_FP_QSQUARED(ECC_NQSQR, ECC_NS, ECC_N, ECC_T0);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_T0, pParam->curveParam.pA, byteLenP);
MCUXCLPKC_FP_CALC_MC1_MM(ECC_R0, ECC_T0, ECC_PQSQR, ECC_P);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_R1, pParam->curveParam.pB, byteLenP);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VA, ECC_VB, ECC_R0, ECC_R1);
uint32_t fail_r = 0u;
uint32_t fail_s = 0u;
MCUX_CSSL_FP_LOOP_DECL(MainLoop_R);
MCUX_CSSL_FP_LOOP_DECL(MainLoop_S);
do
{
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_X1, pParam->curveParam.pG, byteLenP);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_Y1, pParam->curveParam.pG + byteLenP, byteLenP);
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, ECC_X1, ECC_Y1);
if (MCUXCLECC_INTSTATUS_POINTCHECK_OK != MCUXCLECC_FP_POINTCHECKAFFINENR())
{
if ((0u == fail_r) && (0u == fail_s))
{
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_SIGN_INVALID_PARAMS,
MCUXCLECC_FP_SIGN_CURVE_PARAM,
MCUXCLECC_FP_SIGN_LOOP_R_0,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize) );
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUX_CSSL_FP_FUNCTION_CALL(ret_CoreKeyGen, mcuxClEcc_Int_CoreKeyGen(pSession, byteLenN));
if (MCUXCLECC_STATUS_OK != ret_CoreKeyGen)
{
if ( (MCUXCLECC_INTSTATUS_RNG_ERROR == ret_CoreKeyGen)
&& (0u == fail_r) && (0u == fail_s) )
{
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_SIGN_RNG_ERROR,
MCUXCLECC_FP_SIGN_CURVE_PARAM,
MCUXCLECC_FP_SIGN_LOOP_R_1,
MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClPkc_Deinitialize) );
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUX_CSSL_FP_LOOP_ITERATION(MainLoop_R,
MCUXCLECC_FP_SIGN_LOOP_R );
MCUXCLPKC_FP_CALC_MC1_MM(ECC_X0, ECC_X1, ECC_PQSQR, ECC_P);
MCUXCLPKC_FP_CALC_MC1_MM(ECC_Y0, ECC_Y1, ECC_PQSQR, ECC_P);
MCUXCLPKC_FP_CALC_OP1_NEG(ECC_Z, ECC_P);
MCUXCLECC_FP_SECUREPOINTMULT(ECC_S0, 64u);
volatile uint32_t *ptrS1 = (volatile uint32_t *)MCUXCLPKC_OFFSET2PTR(pOperands[ECC_S1]);
MCUX_CSSL_FP_BRANCH_DECL(scalarEvenBranch);
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
uint32_t k1Lsbit = (*ptrS1 & 0x01u);
if(k1Lsbit == 0u)
{
MCUXCLPKC_FP_CALC_OP1_SUB(ECC_S1, ECC_N, ECC_S1);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_Y0, ECC_PS, ECC_Y0, ECC_PS);
MCUX_CSSL_FP_BRANCH_POSITIVE(scalarEvenBranch,
MCUXCLPKC_FP_CALLED_CALC_OP1_SUB,
MCUXCLPKC_FP_CALLED_CALC_MC1_MS
);
}
MCUXCLECC_FP_SECUREPOINTMULT(ECC_S1, byteLenN * 8u);
MCUX_CSSL_FP_EXPECT(MCUX_CSSL_FP_BRANCH_TAKEN_POSITIVE(scalarEvenBranch, k1Lsbit == 0u));
MCUXCLMATH_FP_MODINV(ECC_T0, ECC_Z, ECC_P, ECC_T1);
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_KeyGen_Convert_PubKey,
mcuxClEcc_KeyGen_Convert_PubKey_LEN);
MCUXCLPKC_WAITFORREADY();
MCUXCLECC_COPY_2OFFSETS(pOperands32, ECC_VX0, ECC_VY0, ECC_XA, ECC_YA);
if (MCUXCLECC_INTSTATUS_POINTCHECK_OK != MCUXCLECC_FP_POINTCHECKAFFINENR())
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_FAULT_ATTACK);
}
MCUXCLPKC_FP_CALC_MC1_MS(ECC_XA, ECC_XA, ECC_N, ECC_N);
fail_r += MCUXCLPKC_WAITFORFINISH_GETZERO();
if (MCUXCLPKC_FLAG_ZERO == MCUXCLPKC_GETZERO())
{
continue;
}
MCUXCLPKC_FP_SECUREIMPORTBIGENDIANTOPKC(ECC_ZA, pParam->pPrivateKey, ECC_T0, byteLenN);
MCUXCLPKC_PKC_CPU_ARBITRATION_WORKAROUND();
uint8_t * ptrZ = MCUXCLPKC_OFFSET2PTR(pOperands[ECC_Z]);
MCUX_CSSL_FP_FUNCTION_CALL(ret_PRNG_GetRandom, mcuxClCss_Prng_GetRandom(ptrZ, operandSize));
if (MCUXCLCSS_STATUS_OK != ret_PRNG_GetRandom)
{
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_SIGN_RNG_ERROR);
}
uint32_t byteLenHash = (pParam->optLen & mcuxClEcc_Verify_Param_optLen_byteLenHash_mask) >> mcuxClEcc_Verify_Param_optLen_byteLenHash_offset;
uint32_t byteLenHashImport = ((byteLenHash < byteLenN) ? byteLenHash: byteLenN);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_S2, pParam->pHash, byteLenHashImport);
if (byteLenHash >= byteLenN)
{
uint8_t nMSByte = ptrN[byteLenN - 1u];
uint32_t nMSByte_LeadZeros = (uint32_t) __CLZ((uint32_t) nMSByte) - (8u * ((sizeof(uint32_t)) - 1u));
MCUXCLPKC_FP_CALC_OP1_SHR(ECC_S2, ECC_S2, (uint8_t) nMSByte_LeadZeros);
}
MCUX_CSSL_FP_LOOP_ITERATION(MainLoop_S,
MCUX_CSSL_FP_CONDITIONAL((byteLenHash >= byteLenN),
MCUXCLPKC_FP_CALLED_CALC_OP1_SHR ),
MCUXCLECC_FP_SIGN_LOOP_S );
if(k1Lsbit == 0u)
{
MCUXCLPKC_FP_CALC_OP1_SUB(ECC_S1, ECC_N, ECC_S1);
MCUX_CSSL_FP_EXPECT(MCUXCLPKC_FP_CALLED_CALC_OP1_SUB);
}
MCUXCLPKC_FP_CALCFUP(mcuxClEcc_Sign_CalculateS,
mcuxClEcc_Sign_CalculateS_LEN);
MCUXCLMATH_FP_MODINV(ECC_T0, ECC_T2, ECC_N, ECC_T3);
MCUXCLPKC_FP_CALC_MC1_MM(ECC_YA, ECC_T0, ECC_T1, ECC_N);
MCUXCLPKC_FP_CALC_MC1_MS(ECC_YA, ECC_YA, ECC_N, ECC_N);
fail_s += MCUXCLPKC_WAITFORFINISH_GETZERO();
} while(MCUXCLPKC_FLAG_ZERO == MCUXCLPKC_GETZERO());
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_T0, pParam->curveParam.pP, byteLenP);
MCUXCLPKC_FP_IMPORTBIGENDIANTOPKC(ECC_T1, pParam->curveParam.pN, byteLenN);
MCUXCLPKC_FP_CALC_OP1_CMP(ECC_T0, ECC_P);
uint32_t zeroFlag_checkP = MCUXCLPKC_WAITFORFINISH_GETZERO();
MCUXCLPKC_FP_CALC_OP1_CMP(ECC_T1, ECC_N);
uint32_t zeroFlag_checkN = MCUXCLPKC_WAITFORFINISH_GETZERO();
if ( (zeroFlag_checkP == MCUXCLPKC_FLAG_ZERO)
&& (zeroFlag_checkN == MCUXCLPKC_FLAG_ZERO) )
{
MCUXCLPKC_FP_EXPORTBIGENDIANFROMPKC(pParam->pSignature, ECC_XA, byteLenN);
MCUXCLPKC_FP_EXPORTBIGENDIANFROMPKC(pParam->pSignature + byteLenN, ECC_YA, byteLenN);
MCUXCLPKC_PS1_SETLENGTH(0u, bufferSize * ECC_SIGN_NO_OF_BUFFERS);
pOperands[ECC_P] = MCUXCLPKC_PTR2OFFSET(pPkcWorkarea);
MCUXCLPKC_FP_CALC_OP1_CONST(ECC_P, 0u);
pSession->pkcWa.used -= wordSizePkcWa;
MCUXCLPKC_FP_DEINITIALIZE(& pkcStateBackup);
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_SIGN_OK,
MCUXCLECC_FP_SIGN_BEFORE_LOOP,
MCUX_CSSL_FP_LOOP_ITERATIONS(MainLoop_R, fail_r + fail_s + 1u),
MCUX_CSSL_FP_LOOP_ITERATIONS(MainLoop_S, fail_s + 1u),
MCUXCLECC_FP_SIGN_FINAL );
}
MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClEcc_Sign, MCUXCLECC_STATUS_FAULT_ATTACK);
}

View File

@ -1,22 +0,0 @@
/*--------------------------------------------------------------------------*/
/* Copyright 2020 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
/** @file mcuxClEcc_Sign.fup.c
* @brief mcuxClEcc: FUP program of ECDSA signature generation
*/
#include <mcuxClEcc_Sign_FUP.h>
SDK_ALIGN(const mcuxClPkc_FUPEntry_t mcuxClEcc_Sign_CalculateS[13], 4u) = {{0x10u,0x00u,0x7cu,0x8cu,0xafu,0x57u},{0x80u,0x00u,0x20u,0x17u,0x01u,0x21u},{0x80u,0x21u,0x01u,0x22u,0x23u,0x22u},{0x80u,0x00u,0x21u,0x22u,0x01u,0x1eu},{0x80u,0x21u,0x11u,0x1au,0x1eu,0x1eu},{0x80u,0x00u,0x19u,0x1eu,0x01u,0x1cu},{0x80u,0x00u,0x21u,0x23u,0x01u,0x1fu},{0x80u,0x00u,0x19u,0x1fu,0x01u,0x1du},{0x80u,0x2au,0x11u,0x1cu,0x1du,0x1cu},{0x80u,0x33u,0x1cu,0x00u,0x01u,0x1du},{0x80u,0x33u,0x18u,0x00u,0x01u,0x1cu},{0x80u,0x00u,0x19u,0x19u,0x01u,0x1fu},{0x80u,0x00u,0x1cu,0x1fu,0x01u,0x1eu}};

Some files were not shown because too many files have changed in this diff Show More