Move b from curve structure to its own constant
Same motivation as for the other parameters. This is the last one, making the
curve structure empty, so it's left with a dummy parameter for legal reasons.
diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h
index 70bd5ad..6b88aee 100644
--- a/include/tinycrypt/ecc.h
+++ b/include/tinycrypt/ecc.h
@@ -124,7 +124,7 @@
struct uECC_Curve_t;
typedef const struct uECC_Curve_t * uECC_Curve;
struct uECC_Curve_t {
- uECC_word_t b[NUM_ECC_WORDS];
+ unsigned char dummy;
};
/*
@@ -155,15 +155,11 @@
extern const uECC_word_t curve_p[NUM_ECC_WORDS];
extern const uECC_word_t curve_n[NUM_ECC_WORDS];
extern const uECC_word_t curve_G[2 * NUM_ECC_WORDS];
+extern const uECC_word_t curve_b[NUM_ECC_WORDS];
/* definition of curve NIST p-256: */
static const struct uECC_Curve_t curve_secp256r1 = {
- {
- BYTES_TO_WORDS_8(4B, 60, D2, 27, 3E, 3C, CE, 3B),
- BYTES_TO_WORDS_8(F6, B0, 53, CC, B0, 06, 1D, 65),
- BYTES_TO_WORDS_8(BC, 86, 98, 76, 55, BD, EB, B3),
- BYTES_TO_WORDS_8(E7, 93, 3A, AA, D8, 35, C6, 5A)
- },
+ 0
};
uECC_Curve uECC_secp256r1(void);
diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c
index 9cbed3f..56580f4 100644
--- a/tinycrypt/ecc.c
+++ b/tinycrypt/ecc.c
@@ -91,6 +91,12 @@
BYTES_TO_WORDS_8(16, 9E, 0F, 7C, 4A, EB, E7, 8E),
BYTES_TO_WORDS_8(9B, 7F, 1A, FE, E2, 42, E3, 4F)
};
+const uECC_word_t curve_b[NUM_ECC_WORDS] = {
+ BYTES_TO_WORDS_8(4B, 60, D2, 27, 3E, 3C, CE, 3B),
+ BYTES_TO_WORDS_8(F6, B0, 53, CC, B0, 06, 1D, 65),
+ BYTES_TO_WORDS_8(BC, 86, 98, 76, 55, BD, EB, B3),
+ BYTES_TO_WORDS_8(E7, 93, 3A, AA, D8, 35, C6, 5A)
+};
/* IMPORTANT: Make sure a cryptographically-secure PRNG is set and the platform
* has access to enough entropy in order to feed the PRNG regularly. */
@@ -662,11 +668,13 @@
{
uECC_word_t _3[NUM_ECC_WORDS] = {3}; /* -a = 3 */
+ (void) curve;
+
uECC_vli_modMult_fast(result, x, x); /* r = x^2 */
uECC_vli_modSub(result, result, _3, curve_p); /* r = x^2 - 3 */
uECC_vli_modMult_fast(result, result, x); /* r = x^3 - 3x */
/* r = x^3 - 3x + b: */
- uECC_vli_modAdd(result, result, curve->b, curve_p);
+ uECC_vli_modAdd(result, result, curve_b, curve_p);
}
uECC_Curve uECC_secp256r1(void)