mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(nimble): Fix Software ecc issue in tinycrpyt
This commit is contained in:
@@ -665,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
|
#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' */
|
/* P = (x1, y1) => 2P, (x2, y2) => P' */
|
||||||
static void XYcZ_initial_double(uECC_word_t * X1, uECC_word_t * Y1,
|
static void XYcZ_initial_double(uECC_word_t * X1, uECC_word_t * Y1,
|
||||||
uECC_word_t * X2, uECC_word_t * Y2,
|
uECC_word_t * X2, uECC_word_t * Y2,
|
||||||
@@ -936,7 +935,7 @@ int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve)
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SOC_ECC_SUPPORTED
|
#if SOC_ECC_SUPPORTED && !SOC_ESP_NIMBLE_CONTROLLER
|
||||||
/* Only p256r1 is supported currently. */
|
/* Only p256r1 is supported currently. */
|
||||||
if (curve != uECC_secp256r1()) {
|
if (curve != uECC_secp256r1()) {
|
||||||
return -5;
|
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 _private[NUM_ECC_WORDS];
|
||||||
|
|
||||||
uECC_word_t tmp[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 *p2[2] = {_private, tmp};
|
||||||
uECC_word_t *initial_Z = 0;
|
uECC_word_t *initial_Z = 0;
|
||||||
uECC_word_t carry;
|
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,
|
public_key + num_bytes,
|
||||||
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);
|
EccPoint_mult(_public, _public, _private, 0, curve->num_n_bits, curve);
|
||||||
#else
|
#else
|
||||||
/* Regularize the bitcount for the private key so that attackers cannot use a
|
/* 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:
|
clear_and_out:
|
||||||
/* erasing temporary buffer used to store secret: */
|
/* erasing temporary buffer used to store secret: */
|
||||||
#if !SOC_ECC_SUPPORTED
|
#if !SOC_ECC_SUPPORTED || SOC_ESP_NIMBLE_CONTROLLER
|
||||||
memset(p2, 0, sizeof(p2));
|
memset(p2, 0, sizeof(p2));
|
||||||
__asm__ __volatile__("" :: "g"(p2) : "memory");
|
__asm__ __volatile__("" :: "g"(p2) : "memory");
|
||||||
#endif
|
#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 tmp[NUM_ECC_WORDS];
|
||||||
uECC_word_t s[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 *k2[2] = {tmp, s};
|
||||||
uECC_word_t carry;
|
uECC_word_t carry;
|
||||||
#endif
|
#endif
|
||||||
@@ -116,7 +116,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
|||||||
return 0;
|
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);
|
EccPoint_mult(p, curve->G, k, 0, num_n_bits, curve);
|
||||||
#else
|
#else
|
||||||
carry = regularize_k(k, tmp, s, curve);
|
carry = regularize_k(k, tmp, s, curve);
|
||||||
|
|||||||
Reference in New Issue
Block a user