#define ecc_mod_submul_1 _nettle_ecc_mod_submul_1
#define ecc_mod_mul _nettle_ecc_mod_mul
#define ecc_mod_sqr _nettle_ecc_mod_sqr
-#define ecc_modq_random _nettle_ecc_modq_random
+#define ecc_mod_random _nettle_ecc_mod_random
#define ecc_mod _nettle_ecc_mod
#define ecc_mod_inv _nettle_ecc_mod_inv
#define ecc_hash _nettle_ecc_hash
/* mod q operations. */
void
-ecc_modq_random (const struct ecc_curve *ecc, mp_limb_t *xp,
- void *ctx, nettle_random_func *random, mp_limb_t *scratch);
+ecc_mod_random (const struct ecc_modulo *m, mp_limb_t *xp,
+ void *ctx, nettle_random_func *random, mp_limb_t *scratch);
void
ecc_hash (const struct ecc_curve *ecc,
(((3 << ECC_MUL_A_EH_WBITS) + 10) * (size))
#endif
#define ECC_ECDSA_SIGN_ITCH(size) (12*(size))
-#define ECC_MODQ_RANDOM_ITCH(size) (size)
+#define ECC_MOD_RANDOM_ITCH(size) (size)
#define ECC_HASH_ITCH(size) (1+(size))
#endif /* NETTLE_ECC_INTERNAL_H_INCLUDED */
#include "nettle-internal.h"
static int
-zero_p (const struct ecc_curve *ecc,
+zero_p (const struct ecc_modulo *m,
const mp_limb_t *xp)
{
mp_limb_t t;
mp_size_t i;
- for (i = t = 0; i < ecc->p.size; i++)
+ for (i = t = 0; i < m->size; i++)
t |= xp[i];
return t == 0;
}
static int
-ecdsa_in_range (const struct ecc_curve *ecc,
+ecdsa_in_range (const struct ecc_modulo *m,
const mp_limb_t *xp, mp_limb_t *scratch)
{
/* Check if 0 < x < q, with data independent timing. */
- return !zero_p (ecc, xp)
- & (mpn_sub_n (scratch, xp, ecc->q.m, ecc->p.size) != 0);
+ return !zero_p (m, xp)
+ & (mpn_sub_n (scratch, xp, m->m, m->size) != 0);
}
void
-ecc_modq_random (const struct ecc_curve *ecc, mp_limb_t *xp,
- void *ctx, nettle_random_func *random, mp_limb_t *scratch)
+ecc_mod_random (const struct ecc_modulo *m, mp_limb_t *xp,
+ void *ctx, nettle_random_func *random, mp_limb_t *scratch)
{
uint8_t *buf = (uint8_t *) scratch;
- unsigned nbytes = (ecc->q.bit_size + 7)/8;
+ unsigned nbytes = (m->bit_size + 7)/8;
/* The bytes ought to fit in the scratch area, unless we have very
unusual limb and byte sizes. */
- assert (nbytes <= ecc->p.size * sizeof (mp_limb_t));
+ assert (nbytes <= m->size * sizeof (mp_limb_t));
do
{
random (ctx, nbytes, buf);
- buf[0] &= 0xff >> (nbytes * 8 - ecc->q.bit_size);
+ buf[0] &= 0xff >> (nbytes * 8 - m->bit_size);
- mpn_set_base256 (xp, ecc->p.size, buf, nbytes);
+ mpn_set_base256 (xp, m->size, buf, nbytes);
}
- while (!ecdsa_in_range (ecc, xp, scratch));
+ while (!ecdsa_in_range (m, xp, scratch));
}
void
ecc_scalar_random (struct ecc_scalar *x,
void *random_ctx, nettle_random_func *random)
{
- TMP_DECL (scratch, mp_limb_t, ECC_MODQ_RANDOM_ITCH (ECC_MAX_SIZE));
- TMP_ALLOC (scratch, ECC_MODQ_RANDOM_ITCH (x->ecc->p.size));
+ TMP_DECL (scratch, mp_limb_t, ECC_MOD_RANDOM_ITCH (ECC_MAX_SIZE));
+ TMP_ALLOC (scratch, ECC_MOD_RANDOM_ITCH (x->ecc->q.size));
- ecc_modq_random (x->ecc, x->p, random_ctx, random, scratch);
+ ecc_mod_random (&x->ecc->q, x->p, random_ctx, random, scratch);
}
-
-
timing is still independent of the secret k finally used. */
do
{
- ecc_modq_random (key->ecc, k, random_ctx, random, k + size);
+ ecc_mod_random (&key->ecc->q, k, random_ctx, random, k + size);
ecc_ecdsa_sign (key->ecc, key->p, k, digest_length, digest,
rp, sp, k + size);
mpz_limbs_finish (signature->r, size);