diff options
-rw-r--r-- | ecdsa.c | 10 | ||||
-rw-r--r-- | tests/test-ecdsa.c | 2 |
2 files changed, 7 insertions, 5 deletions
@@ -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) |