Hardcode numwords in vli_modInv
diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c
index 81464e1..6740375 100644
--- a/tinycrypt/ecc.c
+++ b/tinycrypt/ecc.c
@@ -514,8 +514,7 @@
#define EVEN(vli) (!(vli[0] & 1))
static void vli_modInv_update(uECC_word_t *uv,
- const uECC_word_t *mod,
- wordcount_t num_words)
+ const uECC_word_t *mod)
{
uECC_word_t carry = 0;
@@ -525,12 +524,12 @@
}
uECC_vli_rshift1(uv);
if (carry) {
- uv[num_words - 1] |= HIGH_BIT_SET;
+ uv[NUM_ECC_WORDS - 1] |= HIGH_BIT_SET;
}
}
void uECC_vli_modInv(uECC_word_t *result, const uECC_word_t *input,
- const uECC_word_t *mod, wordcount_t num_words)
+ const uECC_word_t *mod)
{
uECC_word_t a[NUM_ECC_WORDS], b[NUM_ECC_WORDS];
uECC_word_t u[NUM_ECC_WORDS], v[NUM_ECC_WORDS];
@@ -549,10 +548,10 @@
while ((cmpResult = uECC_vli_cmp_unsafe(a, b)) != 0) {
if (EVEN(a)) {
uECC_vli_rshift1(a);
- vli_modInv_update(u, mod, num_words);
+ vli_modInv_update(u, mod);
} else if (EVEN(b)) {
uECC_vli_rshift1(b);
- vli_modInv_update(v, mod, num_words);
+ vli_modInv_update(v, mod);
} else if (cmpResult > 0) {
uECC_vli_sub(a, a, b);
uECC_vli_rshift1(a);
@@ -560,7 +559,7 @@
uECC_vli_add(u, u, mod);
}
uECC_vli_sub(u, u, v);
- vli_modInv_update(u, mod, num_words);
+ vli_modInv_update(u, mod);
} else {
uECC_vli_sub(b, b, a);
uECC_vli_rshift1(b);
@@ -568,7 +567,7 @@
uECC_vli_add(v, v, mod);
}
uECC_vli_sub(v, v, u);
- vli_modInv_update(v, mod, num_words);
+ vli_modInv_update(v, mod);
}
}
uECC_vli_set(result, u);
@@ -892,7 +891,7 @@
uECC_vli_modSub(z, Rx[1], Rx[0], curve->p); /* X1 - X0 */
uECC_vli_modMult_fast(z, z, Ry[1 - nb]); /* Yb * (X1 - X0) */
uECC_vli_modMult_fast(z, z, point); /* xP * Yb * (X1 - X0) */
- uECC_vli_modInv(z, z, curve->p, num_words); /* 1 / (xP * Yb * (X1 - X0))*/
+ uECC_vli_modInv(z, z, curve->p); /* 1 / (xP * Yb * (X1 - X0))*/
/* yP / (xP * Yb * (X1 - X0)) */
uECC_vli_modMult_fast(z, z, point + num_words);
/* Xb * yP / (xP * Yb * (X1 - X0)) */
diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c
index 09b2b84..b3a08cf 100644
--- a/tinycrypt/ecc_dsa.c
+++ b/tinycrypt/ecc_dsa.c
@@ -143,7 +143,7 @@
/* Prevent side channel analysis of uECC_vli_modInv() to determine
bits of k / the private key by premultiplying by a random number */
uECC_vli_modMult(k, k, tmp, curve->n); /* k' = rand * k */
- uECC_vli_modInv(k, k, curve->n, num_n_words); /* k = 1 / k' */
+ uECC_vli_modInv(k, k, curve->n); /* k = 1 / k' */
uECC_vli_modMult(k, k, tmp, curve->n); /* k = 1 / k */
uECC_vli_nativeToBytes(signature, curve->num_bytes, p); /* store r */
@@ -242,7 +242,7 @@
}
/* Calculate u1 and u2. */
- uECC_vli_modInv(z, s, curve->n, num_n_words); /* z = 1/s */
+ uECC_vli_modInv(z, s, curve->n); /* z = 1/s */
u1[num_n_words - 1] = 0;
bits2int(u1, message_hash, hash_size, curve);
uECC_vli_modMult(u1, u1, z, curve->n); /* u1 = e/s */
@@ -255,7 +255,7 @@
uECC_vli_set(ty, curve->G + num_words);
uECC_vli_modSub(z, sum, tx, curve->p); /* z = x2 - x1 */
XYcZ_add(tx, ty, sum, sum + num_words, curve);
- uECC_vli_modInv(z, z, curve->p, num_words); /* z = 1/z */
+ uECC_vli_modInv(z, z, curve->p); /* z = 1/z */
apply_z(sum, sum + num_words, z);
/* Use Shamir's trick to calculate u1*G + u2*Q */
@@ -289,7 +289,7 @@
}
}
- uECC_vli_modInv(z, z, curve->p, num_words); /* Z = 1/Z */
+ uECC_vli_modInv(z, z, curve->p); /* Z = 1/Z */
apply_z(rx, ry, z);
/* v = x1 (mod n) */