mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
feat(hal/ecdsa): Add HAL API for operation successful check
This commit is contained in:
parent
dd8080e164
commit
b5347ef02b
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user