X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=ecdsa%2Fecdsa_sign.c;h=217da031ce27dcdc7ea465a585fb3bf2e695ae9d;hp=e6fe11bd2ec3a052eb3fa16a1c418f80da2879c0;hb=4b5da1dc27a791b5c448274a3db09cd035b33493;hpb=3a9f9d918fb95474996af535c225a7e187d88372 diff --git a/ecdsa/ecdsa_sign.c b/ecdsa/ecdsa_sign.c index e6fe11b..217da03 100644 --- a/ecdsa/ecdsa_sign.c +++ b/ecdsa/ecdsa_sign.c @@ -1,7 +1,7 @@ /* ecdsa.c */ /* This file is part of the AVR-Crypto-Lib. - Copyright (C) 2006-2012 Daniel Otte (daniel.otte@rub.de) + Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -76,28 +76,14 @@ uint8_t ecdsa_sign_bigint(ecdsa_signature_t *s, const bigint_t *m, return 2; } ecc_chudnovsky_to_affine_point(&q.affine, &q.chudnovsky, ctx->curve); - bigint_inverse(&s->s, k, ctx->curve->p); + bigint_inverse(&s->s, k, ctx->curve->n); + bigint_mul_u(&t, &q.affine.x, ctx->priv); - ctx->curve->reduce_p(&t); - printf_P(PSTR("msg: ")); - bigint_print_hex(m); - putchar('\n'); - printf_P(PSTR("k: ")); - bigint_print_hex(k); - putchar('\n'); - printf_P(PSTR("k-inv: ")); - bigint_print_hex(&s->s); - putchar('\n'); - printf_P(PSTR("t (1): ")); - bigint_print_hex(&t); - putchar('\n'); + bigint_reduce(&t, ctx->curve->n); bigint_add_u(&t, &t, m); - ctx->curve->reduce_p(&t); - printf_P(PSTR("t (2): ")); - bigint_print_hex(&t); - putchar('\n'); + bigint_reduce(&t, ctx->curve->n); bigint_mul_u(&t, &t, &s->s); - ctx->curve->reduce_p(&t); + bigint_reduce(&t, ctx->curve->n); if(t.length_W == 0){ printf_P(PSTR("DBG: XXX <%S %s %d>\n"), PSTR(__FILE__), __func__, __LINE__); return 2; @@ -151,6 +137,7 @@ uint8_t ecdsa_sign_hash(ecdsa_signature_t *s, const void *hash, ((uint8_t*)m_int.wordv)[idx++] = ((uint8_t*)hash)[--hash_len_B]; } } + bigint_adjust(&m_int); do{ if(rand_in == NULL){ size_t i;