Skip to content

Commit d775036

Browse files
authored
Fix: Potential Vulnerability in Cloned Function (#2087)
* Fix for #168 * Adapt style ecc_dsa.c * Update ecc_dsa.c
1 parent 08002e0 commit d775036

File tree

1 file changed

+11
-2
lines changed
  • source/Core/BSP/Pinecilv2/bl_mcu_sdk/components/ble/ble_stack/common/tinycrypt/source

1 file changed

+11
-2
lines changed

source/Core/BSP/Pinecilv2/bl_mcu_sdk/components/ble/ble_stack/common/tinycrypt/source/ecc_dsa.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ static void bits2int(uECC_word_t *native, const uint8_t *bits, unsigned bits_siz
100100
int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash, unsigned hash_size, uECC_word_t *k, uint8_t *signature, uECC_Curve curve) {
101101
uECC_word_t tmp[NUM_ECC_WORDS];
102102
uECC_word_t s[NUM_ECC_WORDS];
103-
uECC_word_t *k2[2] = {tmp, s};
103+
uECC_word_t *k2[2] = {tmp, s};
104+
uECC_word_t *initial_Z = 0;
104105
uECC_word_t p[NUM_ECC_WORDS * 2];
105106
uECC_word_t carry;
106107
wordcount_t num_words = curve->num_words;
@@ -113,7 +114,15 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash, un
113114
}
114115

115116
carry = regularize_k(k, tmp, s, curve);
116-
EccPoint_mult(p, curve->G, k2[!carry], 0, num_n_bits + 1, curve);
117+
/* If an RNG function was specified, try to get a random initial Z value to improve
118+
protection against side-channel attacks. */
119+
if (g_rng_function) {
120+
if (!uECC_generate_random_int(k2[carry], curve->p, num_words)) {
121+
return 0;
122+
}
123+
initial_Z = k2[carry];
124+
}
125+
EccPoint_mult(p, curve->G, k2[!carry], initial_Z, num_n_bits + 1, curve);
117126
if (uECC_vli_isZero(p, num_words)) {
118127
return 0;
119128
}

0 commit comments

Comments
 (0)