forked from espressif/esp-idf
Merge branch 'esp32p4/deterministic_ecdsa_support_v5.1' into 'release/v5.1'
Add operation successful check in ECDSA (v5.1) See merge request espressif/esp-idf!30181
This commit is contained in:
@@ -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
|
* 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);
|
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,
|
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)
|
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);
|
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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -276,7 +276,7 @@ static inline bool ecdsa_ll_sha_is_busy(void)
|
|||||||
/**
|
/**
|
||||||
* @brief Write the ECDSA parameter
|
* @brief Write the ECDSA parameter
|
||||||
*
|
*
|
||||||
* @param param Parameter to be writen
|
* @param param Parameter to be written
|
||||||
* @param buf Buffer containing data
|
* @param buf Buffer containing data
|
||||||
* @param len Length of buffer
|
* @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 ECDSA operation succeeds
|
||||||
*
|
|
||||||
* @return - 1, if signature verification succeeds
|
|
||||||
* - 0, otherwise
|
* - 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);
|
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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "hal/ecdsa_types.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,
|
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);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
* 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();
|
esp_ecdsa_acquire_hardware();
|
||||||
|
|
||||||
|
bool process_again = false;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ecdsa_hal_config_t conf = {
|
ecdsa_hal_config_t conf = {
|
||||||
.mode = ECDSA_MODE_SIGN_GEN,
|
.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);
|
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();
|
esp_ecdsa_release_hardware();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user