ecc_test.c ecc_map.c \
ecc_mulmod.c ecc_points.c ecc_projective_dbl_point_3.c \
ecc_projective_add_point.c ecc_projective_dbl_point.c \
- mp_unsigned_bin.c ecc_sign_hash.c ecc_verify_hash.c
+ ecc_sign_hash.c ecc_verify_hash.c
#include <gmp.h>
#include <nettle/nettle-types.h>
#include <nettle/dsa.h>
+#include <nettle/bignum.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
/* helper functions */
int mp_init_multi(mpz_t *a, ...);
void mp_clear_multi(mpz_t *a, ...);
-unsigned long mp_unsigned_bin_size(mpz_t a);
-int mp_to_unsigned_bin(mpz_t a, unsigned char *b);
-int mp_read_unsigned_bin(mpz_t a, unsigned char *b, unsigned long len);
#define mp_isodd(a) (mpz_size(a) > 0 ? (mpz_getlimbn(a, 0) & 1 ? 1 : 0) : 0)
#define MP_DIGIT_BIT (sizeof(mp_limb_t) * 8 - GMP_NAIL_BITS)
assert (key != NULL);
assert (random != NULL);
- keysize = mp_unsigned_bin_size (order);
+ keysize = nettle_mpz_sizeinbase_256_u (order);
/* allocate ram */
base = NULL;
mpz_set (base->x, key->Gx);
mpz_set (base->y, key->Gy);
mpz_set_ui (base->z, 1);
- if ((err =
- mp_read_unsigned_bin (key->k, (unsigned char *) buf, keysize)) != 0)
- {
- goto errkey;
- }
+
+ nettle_mpz_set_str_256_u (key->k, keysize, buf);
/* the key should be smaller than the order of base point */
if (mpz_cmp (key->k, key->order) >= 0)
goto done;
}
- x = (unsigned long) mp_unsigned_bin_size (private_key->prime);
+ x = nettle_mpz_sizeinbase_256_u (private_key->prime);
if (*outlen < x)
{
*outlen = x;
goto done;
}
memset (out, 0, x);
- if ((err =
- mp_to_unsigned_bin (result->x,
- out + (x - mp_unsigned_bin_size (result->x)))) !=
- 0)
- {
- goto done;
- }
+ nettle_mpz_get_str_256(x, out + (x - nettle_mpz_sizeinbase_256_u (result->x)), result->x);
err = 0;
*outlen = x;
{
return err;
}
- if ((err =
- mp_read_unsigned_bin (e, (unsigned char *) in, (int) inlen)) != 0)
- {
- goto errnokey;
- }
+
+ nettle_mpz_set_str_256_u (e, inlen, in);
/* make up a key and export the public copy */
for (;;)
}
/* read hash */
- if ((err =
- mp_read_unsigned_bin (e, (unsigned char *) hash, (int) hashlen)) != 0)
- {
- goto error;
- }
+ nettle_mpz_set_str_256_u (e, hashlen, hash);
/* w = s^-1 mod n */
mpz_invert (w, signature->s, key->order);
+++ /dev/null
-#include "ecc.h"
-
-unsigned long mp_unsigned_bin_size(mpz_t a)
-{
- unsigned long t;
- assert(a != NULL);
-
- t = mpz_sizeinbase(a, 2);
- if (mpz_cmp_ui((a), 0) == 0) return 0;
- return (t>>3) + ((t&7)?1:0);
-}
-
-int mp_to_unsigned_bin(mpz_t a, unsigned char *b)
-{
- assert(a != NULL);
- assert(b != NULL);
- mpz_export(b, NULL, 1, 1, 1, 0, a);
-
- return 0;
-}
-
-int mp_read_unsigned_bin(mpz_t a, unsigned char *b, unsigned long len)
-{
- assert(a != NULL);
- assert(b != NULL);
- mpz_import(a, len, 1, 1, 1, 0, b);
- return 0;
-}