[Cryptech-Commits] [sw/libhal] 03/04: More ASN.1 fixes.

git at cryptech.is git at cryptech.is
Wed Aug 26 12:42:22 UTC 2015


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch ecdsa
in repository sw/libhal.

commit 821f7d6bf05601811cf9b4e9a5513374e3261d0b
Author: Rob Austein <sra at hactrn.net>
Date:   Tue Aug 25 23:18:14 2015 -0400

    More ASN.1 fixes.
---
 ecdsa.c            | 10 ++++++----
 tests/test-ecdsa.c |  2 +-
 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)



More information about the Commits mailing list