mirror of
https://github.com/espressif/esp-idf.git
synced 2026-08-18 06:35:35 +03:00
Merge branch 'bugfix/fix_software_ecc_v5.3' into 'release/v5.3'
fix(nimble): Fix Software ecc issue in tinycrpyt (v5.3) See merge request espressif/esp-idf!47735
This commit is contained in:
@@ -58,6 +58,7 @@
|
||||
|
||||
#include <tinycrypt/ecc.h>
|
||||
#include <tinycrypt/ecc_platform_specific.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -664,7 +665,6 @@ void apply_z(uECC_word_t * X1, uECC_word_t * Y1, const uECC_word_t * const Z,
|
||||
}
|
||||
|
||||
#if !SOC_ECC_SUPPORTED || SOC_ESP_NIMBLE_CONTROLLER
|
||||
/* Keep ESP32-C6 on the software micro-ecc path for BLE SC compatibility. */
|
||||
/* P = (x1, y1) => 2P, (x2, y2) => P' */
|
||||
static void XYcZ_initial_double(uECC_word_t * X1, uECC_word_t * Y1,
|
||||
uECC_word_t * X2, uECC_word_t * Y2,
|
||||
@@ -935,7 +935,7 @@ int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve)
|
||||
return -2;
|
||||
}
|
||||
|
||||
#if SOC_ECC_SUPPORTED
|
||||
#if SOC_ECC_SUPPORTED && !SOC_ESP_NIMBLE_CONTROLLER
|
||||
/* Only p256r1 is supported currently. */
|
||||
if (curve != uECC_secp256r1()) {
|
||||
return -5;
|
||||
|
||||
@@ -147,7 +147,7 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
|
||||
uECC_word_t _private[NUM_ECC_WORDS];
|
||||
|
||||
uECC_word_t tmp[NUM_ECC_WORDS];
|
||||
#if !SOC_ECC_SUPPORTED
|
||||
#if !SOC_ECC_SUPPORTED || SOC_ESP_NIMBLE_CONTROLLER
|
||||
uECC_word_t *p2[2] = {_private, tmp};
|
||||
uECC_word_t *initial_Z = 0;
|
||||
uECC_word_t carry;
|
||||
@@ -167,7 +167,7 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
|
||||
public_key + num_bytes,
|
||||
num_bytes);
|
||||
|
||||
#if SOC_ECC_SUPPORTED
|
||||
#if SOC_ECC_SUPPORTED && !SOC_ESP_NIMBLE_CONTROLLER
|
||||
EccPoint_mult(_public, _public, _private, 0, curve->num_n_bits, curve);
|
||||
#else
|
||||
/* Regularize the bitcount for the private key so that attackers cannot use a
|
||||
@@ -194,7 +194,7 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
|
||||
|
||||
clear_and_out:
|
||||
/* erasing temporary buffer used to store secret: */
|
||||
#if !SOC_ECC_SUPPORTED
|
||||
#if !SOC_ECC_SUPPORTED || SOC_ESP_NIMBLE_CONTROLLER
|
||||
memset(p2, 0, sizeof(p2));
|
||||
__asm__ __volatile__("" :: "g"(p2) : "memory");
|
||||
#endif
|
||||
|
||||
@@ -101,7 +101,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
|
||||
uECC_word_t tmp[NUM_ECC_WORDS];
|
||||
uECC_word_t s[NUM_ECC_WORDS];
|
||||
#if !SOC_ECC_SUPPORTED
|
||||
#if !SOC_ECC_SUPPORTED || SOC_ESP_NIMBLE_CONTROLLER
|
||||
uECC_word_t *k2[2] = {tmp, s};
|
||||
uECC_word_t carry;
|
||||
#endif
|
||||
@@ -116,7 +116,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if SOC_ECC_SUPPORTED
|
||||
#if SOC_ECC_SUPPORTED && !SOC_ESP_NIMBLE_CONTROLLER
|
||||
EccPoint_mult(p, curve->G, k, 0, num_n_bits, curve);
|
||||
#else
|
||||
carry = regularize_k(k, tmp, s, curve);
|
||||
|
||||
Reference in New Issue
Block a user