fixing ecdsa signature generation (stupid me confused p and n)
This commit is contained in:
parent
2f89c4687b
commit
109c9312f3
|
@ -42,6 +42,7 @@ typedef union __attribute__((packed)){
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bigint_t *p;
|
bigint_t *p;
|
||||||
|
bigint_t *n;
|
||||||
bigint_t *b;
|
bigint_t *b;
|
||||||
int (*reduce_p)(bigint_t*);
|
int (*reduce_p)(bigint_t*);
|
||||||
} ecc_curve_sp_t;
|
} ecc_curve_sp_t;
|
||||||
|
|
|
@ -76,35 +76,14 @@ uint8_t ecdsa_sign_bigint(ecdsa_signature_t *s, const bigint_t *m,
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
ecc_chudnovsky_to_affine_point(&q.affine, &q.chudnovsky, ctx->curve);
|
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);
|
||||||
|
|
||||||
printf_P(PSTR("x: "));
|
|
||||||
bigint_print_hex(&q.affine.x);
|
|
||||||
putchar('\n');
|
|
||||||
|
|
||||||
bigint_mul_u(&t, &q.affine.x, ctx->priv);
|
bigint_mul_u(&t, &q.affine.x, ctx->priv);
|
||||||
ctx->curve->reduce_p(&t);
|
bigint_reduce(&t, ctx->curve->n);
|
||||||
|
|
||||||
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_add_u(&t, &t, m);
|
bigint_add_u(&t, &t, m);
|
||||||
ctx->curve->reduce_p(&t);
|
bigint_reduce(&t, ctx->curve->n);
|
||||||
printf_P(PSTR("t (2): "));
|
|
||||||
bigint_print_hex(&t);
|
|
||||||
putchar('\n');
|
|
||||||
bigint_mul_u(&t, &t, &s->s);
|
bigint_mul_u(&t, &t, &s->s);
|
||||||
ctx->curve->reduce_p(&t);
|
bigint_reduce(&t, ctx->curve->n);
|
||||||
if(t.length_W == 0){
|
if(t.length_W == 0){
|
||||||
printf_P(PSTR("DBG: XXX <%S %s %d>\n"), PSTR(__FILE__), __func__, __LINE__);
|
printf_P(PSTR("DBG: XXX <%S %s %d>\n"), PSTR(__FILE__), __func__, __LINE__);
|
||||||
return 2;
|
return 2;
|
||||||
|
|
|
@ -46,6 +46,12 @@ uint8_t nist_curve_p192_p_w[] = {
|
||||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint8_t nist_curve_p192_n_w[] = {
|
||||||
|
0x31, 0x28, 0xd2, 0xb4, 0xb1, 0xc9, 0x6b, 0x14,
|
||||||
|
0x36, 0xf8, 0xde, 0x99, 0xff, 0xff, 0xff, 0xff,
|
||||||
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||||
|
};
|
||||||
|
|
||||||
uint8_t nist_curve_p192_b_w[] = {
|
uint8_t nist_curve_p192_b_w[] = {
|
||||||
0xb1, 0xb9, 0x46, 0xc1, 0xec, 0xde, 0xb8, 0xfe,
|
0xb1, 0xb9, 0x46, 0xc1, 0xec, 0xde, 0xb8, 0xfe,
|
||||||
0x49, 0x30, 0x24, 0x72, 0xab, 0xe9, 0xa7, 0x0f,
|
0x49, 0x30, 0x24, 0x72, 0xab, 0xe9, 0xa7, 0x0f,
|
||||||
|
@ -85,6 +91,13 @@ bigint_t nist_curve_p192_p = {
|
||||||
.info = 7
|
.info = 7
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
bigint_t nist_curve_p192_n = {
|
||||||
|
.length_W = 192 / BIGINT_WORD_SIZE,
|
||||||
|
.wordv = nist_curve_p192_n_w,
|
||||||
|
.info = 7
|
||||||
|
};
|
||||||
|
|
||||||
bigint_t nist_curve_p192_b = {
|
bigint_t nist_curve_p192_b = {
|
||||||
.length_W = 192 / BIGINT_WORD_SIZE,
|
.length_W = 192 / BIGINT_WORD_SIZE,
|
||||||
.wordv = nist_curve_p192_b_w,
|
.wordv = nist_curve_p192_b_w,
|
||||||
|
@ -124,6 +137,7 @@ ecc_combi_point_t nist_curve_p192_basepoint = {
|
||||||
ecc_curve_sp_t nist_curve_p192 = {
|
ecc_curve_sp_t nist_curve_p192 = {
|
||||||
.b = &nist_curve_p192_b,
|
.b = &nist_curve_p192_b,
|
||||||
.p = &nist_curve_p192_p,
|
.p = &nist_curve_p192_p,
|
||||||
|
.n = &nist_curve_p192_n,
|
||||||
.reduce_p = bigint_reduce_p192
|
.reduce_p = bigint_reduce_p192
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue