Remove function pointers from curve structure
They're not needed in practice, and removing them decreases the code size
slightly and provides less opportunities for an attacker.
diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h
index 0d1d9ec..7d57f0f 100644
--- a/include/tinycrypt/ecc.h
+++ b/include/tinycrypt/ecc.h
@@ -131,10 +131,6 @@
uECC_word_t n[NUM_ECC_WORDS];
uECC_word_t G[NUM_ECC_WORDS * 2];
uECC_word_t b[NUM_ECC_WORDS];
- void (*double_jacobian)(uECC_word_t * X1, uECC_word_t * Y1, uECC_word_t * Z1,
- uECC_Curve curve);
- void (*x_side)(uECC_word_t *result, const uECC_word_t *x, uECC_Curve curve);
- void (*mmod_fast)(uECC_word_t *result, uECC_word_t *product);
};
/*
@@ -148,15 +144,6 @@
uECC_word_t * Z1, uECC_Curve curve);
/*
- * @brief Computes x^3 + ax + b. result must not overlap x.
- * @param result OUT -- x^3 + ax + b
- * @param x IN -- value of x
- * @param curve IN -- elliptic curve
- */
-void x_side_default(uECC_word_t *result, const uECC_word_t *x,
- uECC_Curve curve);
-
-/*
* @brief Computes result = product % curve_p
* from http://www.nsa.gov/ia/_files/nist-routines.pdf
* @param result OUT -- product % curve_p
@@ -201,9 +188,6 @@
BYTES_TO_WORDS_8(BC, 86, 98, 76, 55, BD, EB, B3),
BYTES_TO_WORDS_8(E7, 93, 3A, AA, D8, 35, C6, 5A)
},
- &double_jacobian_default,
- &x_side_default,
- &vli_mmod_fast_secp256r1
};
uECC_Curve uECC_secp256r1(void);
diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c
index b480832..7659e54 100644
--- a/tinycrypt/ecc.c
+++ b/tinycrypt/ecc.c
@@ -622,7 +622,13 @@
uECC_vli_set(Y1, t4);
}
-void x_side_default(uECC_word_t *result,
+/*
+ * @brief Computes x^3 + ax + b. result must not overlap x.
+ * @param result OUT -- x^3 + ax + b
+ * @param x IN -- value of x
+ * @param curve IN -- elliptic curve
+ */
+static void x_side_default(uECC_word_t *result,
const uECC_word_t *x,
uECC_Curve curve)
{
@@ -775,7 +781,7 @@
uECC_vli_set(Y2, Y1);
apply_z(X1, Y1, z);
- curve->double_jacobian(X1, Y1, z, curve);
+ double_jacobian_default(X1, Y1, z, curve);
apply_z(X2, Y2, z);
}
@@ -1050,7 +1056,7 @@
}
uECC_vli_modMult_fast(tmp1, point + num_words, point + num_words);
- curve->x_side(tmp2, point, curve); /* tmp2 = x^3 + ax + b */
+ x_side_default(tmp2, point, curve); /* tmp2 = x^3 + ax + b */
/* Make sure that y^2 == x^3 + ax + b */
if (uECC_vli_equal(tmp1, tmp2) != 0)
diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c
index 6c171c3..a3b91b8 100644
--- a/tinycrypt/ecc_dsa.c
+++ b/tinycrypt/ecc_dsa.c
@@ -280,7 +280,7 @@
for (i = num_bits - 2; i >= 0; --i) {
uECC_word_t index;
- curve->double_jacobian(rx, ry, z, curve);
+ double_jacobian_default(rx, ry, z, curve);
index = (!!uECC_vli_testBit(u1, i)) | ((!!uECC_vli_testBit(u2, i)) << 1);
point = points[index];