Remove num_n_bits member from curve structure
diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h
index 0cb47d4..5a41845 100644
--- a/include/tinycrypt/ecc.h
+++ b/include/tinycrypt/ecc.h
@@ -124,7 +124,6 @@
struct uECC_Curve_t;
typedef const struct uECC_Curve_t * uECC_Curve;
struct uECC_Curve_t {
- bitcount_t num_n_bits;
uECC_word_t p[NUM_ECC_WORDS];
uECC_word_t n[NUM_ECC_WORDS];
uECC_word_t G[NUM_ECC_WORDS * 2];
@@ -158,7 +157,7 @@
/* definition of curve NIST p-256: */
static const struct uECC_Curve_t curve_secp256r1 = {
- 256, /* num_n_bits */ {
+ {
BYTES_TO_WORDS_8(FF, FF, FF, FF, FF, FF, FF, FF),
BYTES_TO_WORDS_8(FF, FF, FF, FF, 00, 00, 00, 00),
BYTES_TO_WORDS_8(00, 00, 00, 00, 00, 00, 00, 00),
diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c
index cfdbc4b..c43ee72 100644
--- a/tinycrypt/ecc.c
+++ b/tinycrypt/ecc.c
@@ -88,7 +88,8 @@
int uECC_curve_private_key_size(uECC_Curve curve)
{
- return BITS_TO_BYTES(curve->num_n_bits);
+ (void) curve;
+ return BITS_TO_BYTES(NUM_ECC_BITS);
}
int uECC_curve_public_key_size(uECC_Curve curve)
@@ -1094,7 +1095,7 @@
uECC_vli_bytesToNative(
_private,
private_key,
- BITS_TO_BYTES(curve->num_n_bits));
+ BITS_TO_BYTES(NUM_ECC_BITS));
/* Make sure the private key is in the range [1, n-1]. */
if (uECC_vli_isZero(_private)) {
diff --git a/tinycrypt/ecc_dh.c b/tinycrypt/ecc_dh.c
index a1d7483..5c5bc13 100644
--- a/tinycrypt/ecc_dh.c
+++ b/tinycrypt/ecc_dh.c
@@ -89,7 +89,7 @@
/* Converting buffers to correct bit order: */
uECC_vli_nativeToBytes(private_key,
- BITS_TO_BYTES(curve->num_n_bits),
+ BITS_TO_BYTES(NUM_ECC_BITS),
_private);
uECC_vli_nativeToBytes(public_key,
NUM_ECC_BYTES,
@@ -130,7 +130,7 @@
/* Converting buffers to correct bit order: */
uECC_vli_nativeToBytes(private_key,
- BITS_TO_BYTES(curve->num_n_bits),
+ BITS_TO_BYTES(NUM_ECC_BITS),
_private);
uECC_vli_nativeToBytes(public_key,
NUM_ECC_BYTES,
@@ -161,7 +161,7 @@
/* Converting buffers to correct bit order: */
uECC_vli_bytesToNative(_private,
private_key,
- BITS_TO_BYTES(curve->num_n_bits));
+ BITS_TO_BYTES(NUM_ECC_BITS));
uECC_vli_bytesToNative(_public,
public_key,
num_bytes);
diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c
index 5c4ca15..591c880 100644
--- a/tinycrypt/ecc_dsa.c
+++ b/tinycrypt/ecc_dsa.c
@@ -78,8 +78,8 @@
static void bits2int(uECC_word_t *native, const uint8_t *bits,
unsigned bits_size, uECC_Curve curve)
{
- unsigned num_n_bytes = BITS_TO_BYTES(curve->num_n_bits);
- unsigned num_n_words = BITS_TO_WORDS(curve->num_n_bits);
+ unsigned num_n_bytes = BITS_TO_BYTES(NUM_ECC_BITS);
+ unsigned num_n_words = BITS_TO_WORDS(NUM_ECC_BITS);
int shift;
uECC_word_t carry;
uECC_word_t *ptr;
@@ -90,10 +90,10 @@
uECC_vli_clear(native);
uECC_vli_bytesToNative(native, bits, bits_size);
- if (bits_size * 8 <= (unsigned)curve->num_n_bits) {
+ if (bits_size * 8 <= (unsigned)NUM_ECC_BITS) {
return;
}
- shift = bits_size * 8 - curve->num_n_bits;
+ shift = bits_size * 8 - NUM_ECC_BITS;
carry = 0;
ptr = native + num_n_words;
while (ptr-- > native) {
@@ -116,7 +116,7 @@
uECC_word_t tmp[NUM_ECC_WORDS];
uECC_word_t s[NUM_ECC_WORDS];
uECC_word_t p[NUM_ECC_WORDS * 2];
- wordcount_t num_n_words = BITS_TO_WORDS(curve->num_n_bits);
+ wordcount_t num_n_words = BITS_TO_WORDS(NUM_ECC_BITS);
int r;
@@ -150,7 +150,7 @@
uECC_vli_nativeToBytes(signature, NUM_ECC_BYTES, p); /* store r */
/* tmp = d: */
- uECC_vli_bytesToNative(tmp, private_key, BITS_TO_BYTES(curve->num_n_bits));
+ uECC_vli_bytesToNative(tmp, private_key, BITS_TO_BYTES(NUM_ECC_BITS));
s[num_n_words - 1] = 0;
uECC_vli_set(s, p);
@@ -220,7 +220,7 @@
uECC_word_t _public[NUM_ECC_WORDS * 2];
uECC_word_t r[NUM_ECC_WORDS], s[NUM_ECC_WORDS];
wordcount_t num_words = NUM_ECC_WORDS;
- wordcount_t num_n_words = BITS_TO_WORDS(curve->num_n_bits);
+ wordcount_t num_n_words = BITS_TO_WORDS(NUM_ECC_BITS);
if (curve != uECC_secp256r1())
return 0;