#include "bigint_io.h"
-uint8_t ecdsa_signature_alloc(ecdsa_signature_t* s, size_t length_B){
+uint8_t ecdsa_signature_alloc(ecdsa_signature_t *s, size_t length_B){
if(!(s->r.wordv = malloc(length_B))){
printf_P(PSTR("DBG: XXX <%S %s %d>\n"), PSTR(__FILE__), __func__, __LINE__);
return 1;
return 0;
}
-void ecdsa_signature_free(ecdsa_signature_t* s){
+void ecdsa_signature_free(ecdsa_signature_t *s){
free(s->r.wordv);
free(s->s.wordv);
}
-uint8_t ecdsa_sign_bigint(ecdsa_signature_t* s, const bigint_t* m,
- const ecdsa_ctx_t* ctx, const bigint_t* k){
+uint8_t ecdsa_sign_bigint(ecdsa_signature_t *s, const bigint_t *m,
+ const ecdsa_ctx_t *ctx, const bigint_t *k){
bigint_t t;
ecc_combi_point_t q;
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;
return 0;
}
-uint8_t ecdsa_sign_hash(ecdsa_signature_t* s, const void* hash,
- size_t hash_len_B, const ecdsa_ctx_t* ctx,
+uint8_t ecdsa_sign_hash(ecdsa_signature_t *s, const void *hash,
+ size_t hash_len_B, const ecdsa_ctx_t *ctx,
const void *rand_in){
bigint_t m_int;
bigint_t r_int;
((uint8_t*)m_int.wordv)[idx++] = ((uint8_t*)hash)[--hash_len_B];
}
}
+ bigint_adjust(&m_int);
do{
if(rand_in == NULL){
size_t i;
return r;
}
-uint8_t ecdsa_sign_message(ecdsa_signature_t* s, const void* m, uint16_t m_len_b,
- const hfdesc_t* hash_desc, const ecdsa_ctx_t* ctx,
+uint8_t ecdsa_sign_message(ecdsa_signature_t *s, const void *m, uint16_t m_len_b,
+ const hfdesc_t *hash_desc, const ecdsa_ctx_t *ctx,
const void *rand_in){
uint8_t *hash;