From a78c9459fda9204b870350a3e075cd78d448fca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Mon, 22 Sep 2014 12:39:19 +0200 Subject: Introduced struct ecc_modulo. --- ecc-random.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'ecc-random.c') diff --git a/ecc-random.c b/ecc-random.c index 765908ba..f3c83f53 100644 --- a/ecc-random.c +++ b/ecc-random.c @@ -48,7 +48,7 @@ zero_p (const struct ecc_curve *ecc, mp_limb_t t; mp_size_t i; - for (i = t = 0; i < ecc->size; i++) + for (i = t = 0; i < ecc->p.size; i++) t |= xp[i]; return t == 0; @@ -60,7 +60,7 @@ ecdsa_in_range (const struct ecc_curve *ecc, { /* Check if 0 < x < q, with data independent timing. */ return !zero_p (ecc, xp) - & (mpn_sub_n (scratch, xp, ecc->q, ecc->size) != 0); + & (mpn_sub_n (scratch, xp, ecc->q.m, ecc->p.size) != 0); } void @@ -68,19 +68,18 @@ ecc_modq_random (const struct ecc_curve *ecc, mp_limb_t *xp, void *ctx, nettle_random_func *random, mp_limb_t *scratch) { uint8_t *buf = (uint8_t *) scratch; - unsigned nbytes = (ecc->bit_size + 7)/8; + unsigned nbytes = (ecc->q.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->size * sizeof (mp_limb_t)); + assert (nbytes <= ecc->p.size * sizeof (mp_limb_t)); do { - /* q and p are of the same bitsize. */ random (ctx, nbytes, buf); - buf[0] &= 0xff >> (nbytes * 8 - ecc->bit_size); + buf[0] &= 0xff >> (nbytes * 8 - ecc->q.bit_size); - mpn_set_base256 (xp, ecc->size, buf, nbytes); + mpn_set_base256 (xp, ecc->p.size, buf, nbytes); } while (!ecdsa_in_range (ecc, xp, scratch)); } @@ -90,7 +89,7 @@ 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->size)); + TMP_ALLOC (scratch, ECC_MODQ_RANDOM_ITCH (x->ecc->p.size)); ecc_modq_random (x->ecc, x->p, random_ctx, random, scratch); } -- cgit v1.2.1