aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-08-25 23:18:14 -0400
committerRob Austein <sra@hactrn.net>2015-08-25 23:18:14 -0400
commit821f7d6bf05601811cf9b4e9a5513374e3261d0b (patch)
treea62850ca9503e73a0540ccd6c3211a8b21dd31f5
parentdd313d41739740c4bb9e631e48c9a6f61f7b876e (diff)
More ASN.1 fixes.
-rw-r--r--ecdsa.c10
-rw-r--r--tests/test-ecdsa.c2
2 files changed, 7 insertions, 5 deletions
diff --git a/ecdsa.c b/ecdsa.c
index 91a6c25..ca3b1b5 100644
--- a/ecdsa.c
+++ b/ecdsa.c
@@ -991,14 +991,14 @@ hal_error_t hal_ecdsa_key_to_der(const hal_ecdsa_key_t * const key,
if ((err = hal_asn1_encode_header(ASN1_EXPLICIT_1, hlen_bit + (q_len + 1) * 2, d, &hlen, der + der_max - d)) != HAL_OK)
return err;
d += hlen;
- if ((err = hal_asn1_encode_header(ASN1_EXPLICIT_1, (q_len + 1) * 2, d, &hlen, der + der_max - d)) != HAL_OK)
+ if ((err = hal_asn1_encode_header(ASN1_BIT_STRING, (q_len + 1) * 2, d, &hlen, der + der_max - d)) != HAL_OK)
return err;
d += hlen;
*d++ = 0x00;
*d++ = 0x04;
- fp_to_unsigned_bin(unconst_fp_int(key->d), d + q_len - Qx_len);
+ fp_to_unsigned_bin(unconst_fp_int(key->Q->x), d + q_len - Qx_len);
d += q_len;
- fp_to_unsigned_bin(unconst_fp_int(key->d), d + q_len - Qy_len);
+ fp_to_unsigned_bin(unconst_fp_int(key->Q->y), d + q_len - Qy_len);
d += q_len;
assert(d == der + der_max);
@@ -1079,12 +1079,14 @@ hal_error_t hal_ecdsa_key_from_der(hal_ecdsa_key_t **key_,
vlen = vlen/2 - 1;
fp_read_unsigned_bin(key->Q->x, unconst_uint8_t(d), vlen);
d += vlen;
- fp_read_unsigned_bin(key->Q->x, unconst_uint8_t(d), vlen);
+ fp_read_unsigned_bin(key->Q->y, unconst_uint8_t(d), vlen);
d += vlen;
+ fp_set(key->Q->z, 1);
if (d != der_end)
lose(HAL_ERROR_ASN1_PARSE_FAILED);
+ *key_ = key;
return HAL_OK;
fail:
diff --git a/tests/test-ecdsa.c b/tests/test-ecdsa.c
index 816c80e..2cf2277 100644
--- a/tests/test-ecdsa.c
+++ b/tests/test-ecdsa.c
@@ -157,7 +157,7 @@ static int test_against_static_vectors(const ecdsa_tc_t * const tc)
set_next_random(tc->k, tc->k_len);
- uint8_t sig[tc->sig_len];
+ uint8_t sig[tc->sig_len + 4];
size_t sig_len;
if ((err = hal_ecdsa_sign(key1, tc->H, tc->H_len, sig, &sig_len, sizeof(sig))) != HAL_OK)