feat(hal/ecdsa): Add HAL API for operation successful check

release/v5.1
harshal.patil 2024-03-28 17:51:27 +05:30
rodzic dd8080e164
commit b5347ef02b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 5B5EC97C35B9A2E5
4 zmienionych plików z 32 dodań i 12 usunięć

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -21,6 +21,11 @@ static void configure_ecdsa_periph(ecdsa_hal_config_t *conf)
ecdsa_ll_set_z_mode(conf->sha_mode);
}
bool ecdsa_hal_get_operation_result(void)
{
return ecdsa_ll_get_operation_result();
}
void ecdsa_hal_gen_signature(ecdsa_hal_config_t *conf, const uint8_t *hash,
uint8_t *r_out, uint8_t *s_out, uint16_t len)
{
@ -93,7 +98,7 @@ int ecdsa_hal_verify_signature(ecdsa_hal_config_t *conf, const uint8_t *hash, co
;
}
int res = ecdsa_ll_get_verification_result();
bool res = ecdsa_hal_get_operation_result();
return (res ? 0 : -1);
}

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -276,7 +276,7 @@ static inline bool ecdsa_ll_sha_is_busy(void)
/**
* @brief Write the ECDSA parameter
*
* @param param Parameter to be writen
* @param param Parameter to be written
* @param buf Buffer containing data
* @param len Length of buffer
*/
@ -346,14 +346,12 @@ static inline void ecdsa_ll_read_param(ecdsa_ll_param_t param, uint8_t *buf, uin
}
/**
* @brief Get result of ECDSA verification operation
* @brief Check if the ECDSA operation is successful
*
* This is only valid for ECDSA verify mode
*
* @return - 1, if signature verification succeeds
* @return - 1, if ECDSA operation succeeds
* - 0, otherwise
*/
static inline int ecdsa_ll_get_verification_result(void)
static inline int ecdsa_ll_get_operation_result(void)
{
return REG_GET_BIT(ECDSA_RESULT_REG, ECDSA_OPERATION_RESULT);
}

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -12,6 +12,7 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "hal/ecdsa_types.h"
@ -57,6 +58,15 @@ void ecdsa_hal_gen_signature(ecdsa_hal_config_t *conf, const uint8_t *hash,
*/
int ecdsa_hal_verify_signature(ecdsa_hal_config_t *conf, const uint8_t *hash, const uint8_t *r, const uint8_t *s,
const uint8_t *pub_x, const uint8_t *pub_y, uint16_t len);
/**
* @brief Check if the ECDSA operation is successful
*
* @return - true, if the ECDSA operation is successful
* - false, if the ECDSA operation fails
*/
bool ecdsa_hal_get_operation_result(void);
#ifdef __cplusplus
}
#endif

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -135,6 +135,8 @@ static int esp_ecdsa_sign(mbedtls_ecp_group *grp, mbedtls_mpi* r, mbedtls_mpi* s
esp_ecdsa_acquire_hardware();
bool process_again = false;
do {
ecdsa_hal_config_t conf = {
.mode = ECDSA_MODE_SIGN_GEN,
@ -144,7 +146,12 @@ static int esp_ecdsa_sign(mbedtls_ecp_group *grp, mbedtls_mpi* r, mbedtls_mpi* s
};
ecdsa_hal_gen_signature(&conf, sha_le, r_le, s_le, len);
} while (!memcmp(r_le, zeroes, len) || !memcmp(s_le, zeroes, len));
process_again = !ecdsa_hal_get_operation_result()
|| !memcmp(r_le, zeroes, len)
|| !memcmp(s_le, zeroes, len);
} while (process_again);
esp_ecdsa_release_hardware();