Use macros for number of bits and words
diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h
index ac3e3ad..026febc 100644
--- a/include/tinycrypt/ecc.h
+++ b/include/tinycrypt/ecc.h
@@ -111,6 +111,7 @@
#define NUM_ECC_WORDS 8
/* Number of bytes to represent an element of the the curve p-256: */
#define NUM_ECC_BYTES (uECC_WORD_SIZE*NUM_ECC_WORDS)
+#define NUM_ECC_BITS 256
/* structure that represents an elliptic curve (e.g. p256):*/
struct uECC_Curve_t;
diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c
index 08e24dd..a5145bc 100644
--- a/tinycrypt/ecc.c
+++ b/tinycrypt/ecc.c
@@ -336,7 +336,7 @@
uECC_word_t r1 = 0;
uECC_word_t r2 = 0;
wordcount_t i, k;
- const uint8_t num_words = 8;
+ const uint8_t num_words = NUM_ECC_WORDS;
/* Fetch 8 bit worth of delay from the state; 0 if we have no state */
uint8_t delays = s ? s->delays[s->i++] : 0;
@@ -796,7 +796,7 @@
/* t1 = X1, t2 = Y1, t3 = X2, t4 = Y2 */
uECC_word_t t5[NUM_ECC_WORDS];
const uECC_Curve curve = &curve_secp256r1;
- const wordcount_t num_words = 8;
+ const wordcount_t num_words = NUM_ECC_WORDS;
uECC_vli_modSub(t5, X2, X1, curve->p, num_words); /* t5 = x2 - x1 */
uECC_vli_modMult_rnd(t5, t5, t5, s); /* t5 = (x2 - x1)^2 = A */
@@ -837,7 +837,7 @@
uECC_word_t t6[NUM_ECC_WORDS];
uECC_word_t t7[NUM_ECC_WORDS];
const uECC_Curve curve = &curve_secp256r1;
- const wordcount_t num_words = 8;
+ const wordcount_t num_words = NUM_ECC_WORDS;
uECC_vli_modSub(t5, X2, X1, curve->p, num_words); /* t5 = x2 - x1 */
uECC_vli_modMult_rnd(t5, t5, t5, s); /* t5 = (x2 - x1)^2 = A */
@@ -877,8 +877,8 @@
uECC_word_t z[NUM_ECC_WORDS];
bitcount_t i;
uECC_word_t nb;
- const wordcount_t num_words = 8;
- const bitcount_t num_bits = 256 + 1; /* from regularize_k */
+ const wordcount_t num_words = NUM_ECC_WORDS;
+ const bitcount_t num_bits = NUM_ECC_BITS + 1; /* from regularize_k */
const uECC_Curve curve = uECC_secp256r1();
ecc_wait_state_t wait_state;
ecc_wait_state_t * const ws = g_rng_function ? &wait_state : NULL;
@@ -921,8 +921,8 @@
uECC_word_t *k1)
{
- wordcount_t num_n_words = 8;
- bitcount_t num_n_bits = 256;
+ wordcount_t num_n_words = NUM_ECC_WORDS;
+ bitcount_t num_n_bits = NUM_ECC_BITS;
const uECC_Curve curve = uECC_secp256r1();
uECC_word_t carry = uECC_vli_add(k0, k, curve->n, num_n_words) ||
@@ -940,7 +940,7 @@
uECC_word_t tmp[NUM_ECC_WORDS];
uECC_word_t s[NUM_ECC_WORDS];
uECC_word_t *k2[2] = {tmp, s};
- wordcount_t num_words = 8;
+ wordcount_t num_words = NUM_ECC_WORDS;
uECC_word_t carry;
uECC_word_t *initial_Z = 0;
int r;