Remove curve parameter from (semi-)internal functions
By semi-internal I mean functions that are only public because they're used in
more than once compilation unit in the library (for example in ecc.c and
ecc_dsa.c) but should not really be part of the public-facing API.
diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c
index 03645c0..0c53f9d 100644
--- a/tinycrypt/ecc.c
+++ b/tinycrypt/ecc.c
@@ -608,15 +608,13 @@
/* ------ Point operations ------ */
void double_jacobian_default(uECC_word_t * X1, uECC_word_t * Y1,
- uECC_word_t * Z1, uECC_Curve curve)
+ uECC_word_t * Z1)
{
/* t1 = X, t2 = Y, t3 = Z */
uECC_word_t t4[NUM_ECC_WORDS];
uECC_word_t t5[NUM_ECC_WORDS];
wordcount_t num_words = NUM_ECC_WORDS;
- (void) curve;
-
if (uECC_vli_isZero(Z1)) {
return;
}
@@ -663,13 +661,10 @@
* @param curve IN -- elliptic curve
*/
static void x_side_default(uECC_word_t *result,
- const uECC_word_t *x,
- uECC_Curve curve)
+ const uECC_word_t *x)
{
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 */
@@ -783,9 +778,8 @@
}
}
-uECC_word_t EccPoint_isZero(const uECC_word_t *point, uECC_Curve curve)
+uECC_word_t EccPoint_isZero(const uECC_word_t *point)
{
- (void) curve;
return uECC_vli_isZero(point);
}
@@ -802,8 +796,7 @@
/* P = (x1, y1) => 2P, (x2, y2) => P' */
static void XYcZ_initial_double(uECC_word_t * X1, uECC_word_t * Y1,
uECC_word_t * X2, uECC_word_t * Y2,
- const uECC_word_t * const initial_Z,
- uECC_Curve curve)
+ const uECC_word_t * const initial_Z)
{
uECC_word_t z[NUM_ECC_WORDS];
if (initial_Z) {
@@ -817,7 +810,7 @@
uECC_vli_set(Y2, Y1);
apply_z(X1, Y1, z);
- double_jacobian_default(X1, Y1, z, curve);
+ double_jacobian_default(X1, Y1, z);
apply_z(X2, Y2, z);
}
@@ -847,10 +840,8 @@
}
void XYcZ_add(uECC_word_t * X1, uECC_word_t * Y1,
- uECC_word_t * X2, uECC_word_t * Y2,
- uECC_Curve curve)
+ uECC_word_t * X2, uECC_word_t * Y2)
{
- (void) curve;
XYcZ_add_rnd(X1, Y1, X2, Y2, NULL);
}
@@ -907,14 +898,13 @@
uECC_word_t nb;
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;
uECC_vli_set(Rx[1], point);
uECC_vli_set(Ry[1], point + num_words);
- XYcZ_initial_double(Rx[1], Ry[1], Rx[0], Ry[0], initial_Z, curve);
+ XYcZ_initial_double(Rx[1], Ry[1], Rx[0], Ry[0], initial_Z);
for (i = num_bits - 2; i > 0; --i) {
ecc_wait_state_reset(ws);
@@ -976,7 +966,7 @@
return 0;
/* Protects against invalid curves attacks */
- if (uECC_valid_point(point, curve) != 0 ) {
+ if (uECC_valid_point(point) != 0 ) {
return 0;
}
@@ -998,7 +988,7 @@
/* Protect against fault injections that would make the resulting
* point not lie on the intended curve */
- if (uECC_valid_point(result, curve) != 0 ) {
+ if (uECC_valid_point(result) != 0 ) {
r = 0;
goto clear_and_out;
}
@@ -1071,14 +1061,14 @@
}
-int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve)
+int uECC_valid_point(const uECC_word_t *point)
{
uECC_word_t tmp1[NUM_ECC_WORDS];
uECC_word_t tmp2[NUM_ECC_WORDS];
wordcount_t num_words = NUM_ECC_WORDS;
/* The point at infinity is invalid. */
- if (EccPoint_isZero(point, curve)) {
+ if (EccPoint_isZero(point)) {
return -1;
}
@@ -1089,7 +1079,7 @@
}
uECC_vli_modMult_fast(tmp1, point + num_words, point + num_words);
- x_side_default(tmp2, point, curve); /* tmp2 = x^3 + ax + b */
+ x_side_default(tmp2, point); /* tmp2 = x^3 + ax + b */
/* Make sure that y^2 == x^3 + ax + b */
if (uECC_vli_equal(tmp1, tmp2) != 0)
@@ -1098,7 +1088,7 @@
return 0;
}
-int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve)
+int uECC_valid_public_key(const uint8_t *public_key)
{
uECC_word_t _public[NUM_ECC_WORDS * 2];
@@ -1113,7 +1103,7 @@
return -4;
}
- return uECC_valid_point(_public, curve);
+ return uECC_valid_point(_public);
}
int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key,
diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c
index 82e159c..0f7a9fd 100644
--- a/tinycrypt/ecc_dsa.c
+++ b/tinycrypt/ecc_dsa.c
@@ -261,7 +261,7 @@
uECC_vli_set(tx, curve_G);
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);
+ XYcZ_add(tx, ty, sum, sum + num_words);
uECC_vli_modInv(z, z, curve_p); /* z = 1/z */
apply_z(sum, sum + num_words, z);
@@ -282,7 +282,7 @@
for (i = num_bits - 2; i >= 0; --i) {
uECC_word_t index;
- double_jacobian_default(rx, ry, z, curve);
+ double_jacobian_default(rx, ry, z);
index = (!!uECC_vli_testBit(u1, i)) | ((!!uECC_vli_testBit(u2, i)) << 1);
point = points[index];
@@ -291,7 +291,7 @@
uECC_vli_set(ty, point + num_words);
apply_z(tx, ty, z);
uECC_vli_modSub(tz, rx, tx, curve_p); /* Z = x2 - x1 */
- XYcZ_add(tx, ty, rx, ry, curve);
+ XYcZ_add(tx, ty, rx, ry);
uECC_vli_modMult_fast(z, z, tz);
}
}