Remove num_n_bits member from curve structure

This commit is contained in:
Manuel Pégourié-Gonnard 2019-11-21 09:46:52 +01:00
parent 72c1764c00
commit 30833f2a07
4 changed files with 14 additions and 14 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 {
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 @@ 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 = {
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),

View File

@ -88,7 +88,8 @@ uECC_RNG_Function uECC_get_rng(void)
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 @@ int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key,
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)) {

View File

@ -89,7 +89,7 @@ int uECC_make_key_with_d(uint8_t *public_key, uint8_t *private_key,
/* 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 @@ int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve)
/* 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 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
/* 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);

View File

@ -78,8 +78,8 @@ static uECC_RNG_Function g_rng_function = 0;
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 @@ static void bits2int(uECC_word_t *native, const uint8_t *bits,
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 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
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 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
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 @@ 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 = 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;