diff --git a/Jenkinsfile b/Jenkinsfile index 224aae4..bbadd3d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { { bat 'git clone %GIT_REPO% .' bat 'git checkout main' - bat 'git submodule update --init' + bat 'git submodule update --init' } } } @@ -97,7 +97,7 @@ pipeline { for /d %%D in ("STSELib\\doc\\resources\\*") do ( if /i not "%%~nxD"=="__html" if /i not "%%~nxD"=="Pictures" rmdir /s /q "%%D" ) - + REM Remove all files except those in __html and Pictures for %%F in ("STSELib\\doc\\resources\\*") do ( if /i not "%%~nxF"=="__html" if /i not "%%~nxF"=="Pictures" del /q "%%F" @@ -108,7 +108,7 @@ pipeline { REM Remove the resources@tmp folder if exist "STSELib\\doc\\resources@tmp" rmdir /s /q "STSELib\\doc\\resources@tmp" ''' - // Create the documentation release package + // Create the documentation release package bat """ powershell -Command "Compress-Archive -Path 'STSELib\\doc\\*' -DestinationPath 'STSELib_nightly_${BUILD_ID}_${DATE}_documentation.zip' -Force" """ diff --git a/api/stse_aes.c b/api/stse_aes.c index f019f9d..f066ca3 100644 --- a/api/stse_aes.c +++ b/api/stse_aes.c @@ -84,9 +84,10 @@ stse_ReturnCode_t stse_aes_ccm_encrypt( slot_number, authentication_tag_length, pNonce, - associated_data_length, pAssociated_data, + authentication_tag_length == 0 ? 0 : associated_data_length, + authentication_tag_length == 0 ? NULL : pAssociated_data, message_length, - pPlaintext_message, + message_length == 0 ? NULL : pPlaintext_message, pEncrypted_message, pEncrypted_authentication_tag, counter_presence, pCounter); @@ -207,8 +208,8 @@ stse_ReturnCode_t stse_aes_ccm_decrypt( slot_number, authentication_tag_length, pNonce, - associated_data_length, - pAssociated_data, + authentication_tag_length == 0 ? 0 : associated_data_length, + authentication_tag_length == 0 ? NULL : pAssociated_data, message_length, pEncrypted_message, pEncrypted_authentication_tag, @@ -243,7 +244,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt( IV_length, pIV, associated_data_length, - pAssociated_data, + associated_data_length == 0 ? NULL : pAssociated_data, message_length, pPlaintext_message, pEncrypted_message, @@ -448,7 +449,7 @@ stse_ReturnCode_t stse_aes_gcm_decrypt( IV_length, pIV, associated_data_length, - pAssociated_data, + associated_data_length == 0 ? NULL : pAssociated_data, message_length, pEncrypted_message, pAuthentication_tag, diff --git a/api/stse_aes.h b/api/stse_aes.h index fd95fed..7556ffe 100644 --- a/api/stse_aes.h +++ b/api/stse_aes.h @@ -183,7 +183,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt_finish( * \param[in] pNonce Buffer containing the nonce * \param[in] associated_data_length Length of the associated data * \param[in] pAssociated_data Buffer containing associated data - * \param[in] message_length Length of the message to encrypt + * \param[in] message_length Length of the original message (before encryption) * \param[in] pEncrypted_message Buffer containing the message to decrypt * \param[in] pEncrypted_authentication_tag Buffer containing the encrypted authentication tag * \param[out] pVerification_result Verification result flag diff --git a/api/stse_device_management.h b/api/stse_device_management.h index 63af18c..e481ecc 100644 --- a/api/stse_device_management.h +++ b/api/stse_device_management.h @@ -75,8 +75,8 @@ stse_ReturnCode_t stse_device_reset(stse_Handler_t *pSTSE); /** * \brief Put target device in hibernate mode * \details This function call hibernate service to put the device in hibernate - * \param[in] pSTSE Pointer to STSE Handler - * \param[in] wake_up_mode Event to wake up from, + * \param[in] pSTSE Pointer to STSE Handler + * \param[in] wake_up_mode Event to wake up from (only significant with STSAFE-A devices), * listed in enum \ref stse_hibernate_wake_up_mode_t * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ @@ -102,7 +102,7 @@ stse_ReturnCode_t stse_device_power_off(stse_Handler_t *pSTSE); /** * \brief Send echo command * \details This function call send service to send an echo command - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] pIn Pointer to data buffer to be sent * \param[out] pOut Pointer to received data buffer * \param[in] size Size in bytes of pIn buffer @@ -125,7 +125,7 @@ stse_ReturnCode_t stse_device_lock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, P /** * \brief Unlock target device * \details This function unlock the target device using the password in argument - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] pPassword Pointer to the password buffer * \param[in] password_length Length of the password buffer in bytes * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise @@ -137,7 +137,7 @@ stse_ReturnCode_t stse_device_unlock(stse_Handler_t *pSTSE, PLAT_UI8 *pPassword, * \brief Return the record count of command access conditions * \details This function query the access conditions * of the target device command set and return the number of records - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[out] record_count Command authorization records count * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details Please refer to stse_device_get_command_AC() @@ -148,7 +148,7 @@ stse_ReturnCode_t stse_device_get_command_count(stse_Handler_t *pSTSE, PLAT_UI8 * \brief Return the command access conditions and change right * \details This function query the access conditions * of the target device command set - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] record_count Command authorization records count * \param[out] pChange_rights Pointer to change rights structure of the commands AC and host encrytpion flag * \param[out] pRecord_table Command authorization records table diff --git a/api/stse_symmetric_keys_management.c b/api/stse_symmetric_keys_management.c index cb8b1e5..a396d56 100644 --- a/api/stse_symmetric_keys_management.c +++ b/api/stse_symmetric_keys_management.c @@ -464,7 +464,7 @@ static stse_ReturnCode_t stse_KEK_wrap( ret = stse_platform_nist_kw_encrypt( pPayload, payload_length, working_kek, STSAFEA_KEK_KEY_SIZE, - pEnvelope, NULL); + pEnvelope, &envelope_length); memset(working_kek, 0, STSAFEA_KEK_KEY_SIZE); diff --git a/core/stse_frame.c b/core/stse_frame.c index e8f92db..e09330c 100644 --- a/core/stse_frame.c +++ b/core/stse_frame.c @@ -143,7 +143,7 @@ void stse_frame_pop_element(stse_frame_t *pFrame) { /* Select first Frame Element*/ pCurrent_element = pFrame->first_element; /* Parse Frame until previous to last element */ - while (pCurrent_element->next != pFrame->last_element) { + while (pCurrent_element->next != pFrame->last_element && pCurrent_element->next->next != NULL) { pCurrent_element = pCurrent_element->next; } /* Remove references/link to the last element */ diff --git a/services/stsafea/stsafea_aes.c b/services/stsafea/stsafea_aes.c index 6cb88a4..8c61115 100644 --- a/services/stsafea/stsafea_aes.c +++ b/services/stsafea/stsafea_aes.c @@ -171,7 +171,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt( } stse_frame_element_allocate_push(&CmdFrame, eMessage_length, STSAFEA_GENERIC_LENGTH_SIZE, (PLAT_UI8 *)&message_length); stse_frame_element_allocate(ePlaintext_message, message_length, pPlaintext_message); - if (associated_data_length != 0) { + if (message_length != 0) { stse_frame_push_element(&CmdFrame, &ePlaintext_message); } @@ -227,7 +227,13 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt_start( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((pNonce == NULL) || (pAssociated_data_chunk == NULL && associated_data_chunk_length != 0) || (pAssociated_data_chunk != NULL && associated_data_chunk_length == 0) || (pPlaintext_message_chunk == NULL && message_chunk_length != 0) || (pPlaintext_message_chunk != NULL && message_chunk_length == 0) || (pEncrypted_message_chunk == NULL && message_chunk_length != 0) || (pEncrypted_message_chunk != NULL && message_chunk_length == 0)) { + if ((pNonce == NULL) || + (pAssociated_data_chunk == NULL && associated_data_chunk_length != 0) || + (pAssociated_data_chunk != NULL && associated_data_chunk_length == 0) || + (pPlaintext_message_chunk == NULL && message_chunk_length != 0) || + (pPlaintext_message_chunk != NULL && message_chunk_length == 0) || + (pEncrypted_message_chunk == NULL && message_chunk_length != 0) || + (pEncrypted_message_chunk != NULL && message_chunk_length == 0)) { return (STSE_SERVICE_INVALID_PARAMETER); } @@ -334,7 +340,16 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((pNonce == NULL) || (pAssociated_data == NULL && associated_data_length != 0) || (pAssociated_data != NULL && associated_data_length == 0) || (pEncrypted_message == NULL && message_length != 0) || (pEncrypted_message != NULL && message_length == 0) || (pPlaintext_message == NULL && message_length != 0) || (pPlaintext_message != NULL && message_length == 0) || (pEncrypted_authentication_tag == NULL && authentication_tag_length != 0) || (pEncrypted_authentication_tag != NULL && authentication_tag_length == 0) || (pVerification_result == NULL)) { + if ((pNonce == NULL) || + (pAssociated_data == NULL && associated_data_length != 0) || + (pAssociated_data != NULL && associated_data_length == 0) || + (pEncrypted_message == NULL && message_length != 0) || + (pEncrypted_message != NULL && message_length == 0) || + (pPlaintext_message == NULL && message_length != 0) || + (pPlaintext_message != NULL && message_length == 0) || + (pEncrypted_authentication_tag == NULL && authentication_tag_length != 0) || + (pEncrypted_authentication_tag != NULL && authentication_tag_length == 0) || + (pVerification_result == NULL)) { return (STSE_SERVICE_INVALID_PARAMETER); } @@ -385,7 +400,13 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt_start( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((pNonce == NULL) || (pAssociated_data_chunk == NULL && associated_data_chunk_length != 0) || (pAssociated_data_chunk != NULL && associated_data_chunk_length == 0) || (pEncrypted_message_chunk == NULL && message_chunk_length != 0) || (pEncrypted_message_chunk != NULL && message_chunk_length == 0) || (pPlaintext_message_chunk == NULL && message_chunk_length != 0) || (pPlaintext_message_chunk != NULL && message_chunk_length == 0)) { + if ((pNonce == NULL) || + (pAssociated_data_chunk == NULL && associated_data_chunk_length != 0) || + (pAssociated_data_chunk != NULL && associated_data_chunk_length == 0) || + (pEncrypted_message_chunk == NULL && message_chunk_length != 0) || + (pEncrypted_message_chunk != NULL && message_chunk_length == 0) || + (pPlaintext_message_chunk == NULL && message_chunk_length != 0) || + (pPlaintext_message_chunk != NULL && message_chunk_length == 0)) { return (STSE_SERVICE_INVALID_PARAMETER); } @@ -476,7 +497,14 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((pIV == NULL || IV_length == 0) || (pAssociated_data == NULL && pPlaintext_message == NULL) || (pAssociated_data == NULL && associated_data_length != 0) || (pAssociated_data != NULL && associated_data_length == 0) || (pPlaintext_message == NULL && message_length != 0) || (pPlaintext_message != NULL && message_length == 0) || (pEncrypted_message == NULL && pPlaintext_message != NULL) || (pAuthentication_tag == NULL)) { + if ((pIV == NULL || IV_length == 0) || + (pAssociated_data == NULL && pPlaintext_message == NULL) || + (pAssociated_data == NULL && associated_data_length != 0) || + (pAssociated_data != NULL && associated_data_length == 0) || + (pPlaintext_message == NULL && message_length != 0) || + (pPlaintext_message != NULL && message_length == 0) || + (pEncrypted_message == NULL && pPlaintext_message != NULL) || + (pAuthentication_tag == NULL)) { return (STSE_SERVICE_INVALID_PARAMETER); } diff --git a/services/stsafea/stsafea_frame_transfer.c b/services/stsafea/stsafea_frame_transfer.c index 38754cf..787d60d 100644 --- a/services/stsafea/stsafea_frame_transfer.c +++ b/services/stsafea/stsafea_frame_transfer.c @@ -87,7 +87,7 @@ stse_ReturnCode_t stsafea_frame_transmit(stse_Handler_t *pSTSE, stse_frame_t *pF if (ret == STSE_OK) { pCurrent_element = pFrame->first_element; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { ret = pSTSE->io.BusSendContinue( pSTSE->io.busID, pSTSE->io.Devaddr, @@ -326,7 +326,7 @@ stse_ReturnCode_t stsafea_frame_receive(stse_Handler_t *pSTSE, stse_frame_t *pFr /* - Perform frame element reception and populate local RSP Frame */ pCurrent_element = pFrame->first_element->next; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { if (received_length < pCurrent_element->length) { pCurrent_element->length = received_length; } diff --git a/services/stsafel/stsafel_frame_transfer.c b/services/stsafel/stsafel_frame_transfer.c index 1ddcd94..0c27191 100644 --- a/services/stsafel/stsafel_frame_transfer.c +++ b/services/stsafel/stsafel_frame_transfer.c @@ -84,7 +84,7 @@ stse_ReturnCode_t stsafel_frame_transmit(stse_Handler_t *pSTSE, stse_frame_t *pF if (ret == STSE_OK) { pCurrent_element = pFrame->first_element; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { ret = pSTSE->io.BusSendContinue( pSTSE->io.busID, pSTSE->io.Devaddr, @@ -284,7 +284,7 @@ stse_ReturnCode_t stsafel_i2c_frame_receive(stse_Handler_t *pSTSE, stse_frame_t /* - Perform frame element reception and populate local RSP Frame */ pCurrent_element = pFrame->first_element->next; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { if (received_length < pCurrent_element->length) { pCurrent_element->length = received_length; } @@ -423,7 +423,7 @@ stse_ReturnCode_t stsafel_st1wire_frame_receive(stse_Handler_t *pSTSE, stse_fram /* - Perform frame element reception and populate local RSP Frame */ pCurrent_element = pFrame->first_element->next; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { if (received_length < pCurrent_element->length) { pCurrent_element->length = received_length; }