From 0eb2633ba0012a17089e740f2523bbe7b92e0b11 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 17 Apr 2026 12:59:47 +0530 Subject: [PATCH] fix(nimble): Fix Software ecc issue in tinycrpyt --- components/bt/common/tinycrypt/src/ecc.c | 4 ++-- components/bt/common/tinycrypt/src/ecc_dh.c | 6 +++--- components/bt/common/tinycrypt/src/ecc_dsa.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/bt/common/tinycrypt/src/ecc.c b/components/bt/common/tinycrypt/src/ecc.c index fd865e4ddbc..d35031be68d 100644 --- a/components/bt/common/tinycrypt/src/ecc.c +++ b/components/bt/common/tinycrypt/src/ecc.c @@ -58,6 +58,7 @@ #include #include +#include #include #include @@ -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; diff --git a/components/bt/common/tinycrypt/src/ecc_dh.c b/components/bt/common/tinycrypt/src/ecc_dh.c index 8bc59014c7e..eeee90d6aa2 100644 --- a/components/bt/common/tinycrypt/src/ecc_dh.c +++ b/components/bt/common/tinycrypt/src/ecc_dh.c @@ -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 diff --git a/components/bt/common/tinycrypt/src/ecc_dsa.c b/components/bt/common/tinycrypt/src/ecc_dsa.c index c86ea6204a6..d167ee9104a 100644 --- a/components/bt/common/tinycrypt/src/ecc_dsa.c +++ b/components/bt/common/tinycrypt/src/ecc_dsa.c @@ -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);