Remove num_words member from curve structure

Saves code size, and makes the curve structure simpler.
This commit is contained in:
Manuel Pégourié-Gonnard 2019-11-21 09:27:38 +01:00
parent 1c6f7eae2d
commit 1765933ab2
4 changed files with 8 additions and 10 deletions

View File

@ -124,7 +124,6 @@ typedef uint64_t uECC_dword_t;
struct uECC_Curve_t;
typedef const struct uECC_Curve_t * uECC_Curve;
struct uECC_Curve_t {
wordcount_t num_words;
wordcount_t num_bytes;
bitcount_t num_n_bits;
uECC_word_t p[NUM_ECC_WORDS];
@ -160,7 +159,6 @@ void vli_mmod_fast_secp256r1(unsigned int *result, unsigned int *product);
/* definition of curve NIST p-256: */
static const struct uECC_Curve_t curve_secp256r1 = {
NUM_ECC_WORDS,
NUM_ECC_BYTES,
256, /* num_n_bits */ {
BYTES_TO_WORDS_8(FF, FF, FF, FF, FF, FF, FF, FF),

View File

@ -581,7 +581,7 @@ void double_jacobian_default(uECC_word_t * X1, uECC_word_t * Y1,
/* t1 = X, t2 = Y, t3 = Z */
uECC_word_t t4[NUM_ECC_WORDS];
uECC_word_t t5[NUM_ECC_WORDS];
wordcount_t num_words = curve->num_words;
wordcount_t num_words = NUM_ECC_WORDS;
if (uECC_vli_isZero(Z1)) {
return;
@ -1042,7 +1042,7 @@ int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve)
{
uECC_word_t tmp1[NUM_ECC_WORDS];
uECC_word_t tmp2[NUM_ECC_WORDS];
wordcount_t num_words = curve->num_words;
wordcount_t num_words = NUM_ECC_WORDS;
/* The point at infinity is invalid. */
if (EccPoint_isZero(point, curve)) {
@ -1072,7 +1072,7 @@ int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve)
uECC_vli_bytesToNative(_public, public_key, curve->num_bytes);
uECC_vli_bytesToNative(
_public + curve->num_words,
_public + NUM_ECC_WORDS,
public_key + curve->num_bytes,
curve->num_bytes);
@ -1112,7 +1112,7 @@ int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key,
uECC_vli_nativeToBytes(public_key, curve->num_bytes, _public);
uECC_vli_nativeToBytes(
public_key +
curve->num_bytes, curve->num_bytes, _public + curve->num_words);
curve->num_bytes, curve->num_bytes, _public + NUM_ECC_WORDS);
return 1;
}
#else

View File

@ -96,7 +96,7 @@ int uECC_make_key_with_d(uint8_t *public_key, uint8_t *private_key,
_public);
uECC_vli_nativeToBytes(public_key + curve->num_bytes,
curve->num_bytes,
_public + curve->num_words);
_public + NUM_ECC_WORDS);
/* erasing temporary buffer used to store secret: */
mbedtls_platform_memset(_private, 0, NUM_ECC_BYTES);
@ -137,7 +137,7 @@ int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve)
_public);
uECC_vli_nativeToBytes(public_key + curve->num_bytes,
curve->num_bytes,
_public + curve->num_words);
_public + NUM_ECC_WORDS);
/* erasing temporary buffer that stored secret: */
mbedtls_platform_memset(_private, 0, NUM_ECC_BYTES);
@ -154,7 +154,7 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
uECC_word_t _public[NUM_ECC_WORDS * 2];
uECC_word_t _private[NUM_ECC_WORDS];
wordcount_t num_words = curve->num_words;
wordcount_t num_words = NUM_ECC_WORDS;
wordcount_t num_bytes = curve->num_bytes;
int r;

View File

@ -219,7 +219,7 @@ int uECC_verify(const uint8_t *public_key, const uint8_t *message_hash,
uECC_word_t _public[NUM_ECC_WORDS * 2];
uECC_word_t r[NUM_ECC_WORDS], s[NUM_ECC_WORDS];
wordcount_t num_words = curve->num_words;
wordcount_t num_words = NUM_ECC_WORDS;
wordcount_t num_n_words = BITS_TO_WORDS(curve->num_n_bits);
if (curve != uECC_secp256r1())