From c927e4315a328d3c0402fb7f5d06d8548a38897c Mon Sep 17 00:00:00 2001 From: Karel Miko Date: Tue, 29 Aug 2017 23:25:05 +0200 Subject: [PATCH] dsa_verify_hash: fix wycheproof - appending unused 0's --- src/pk/dsa/dsa_verify_hash.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/pk/dsa/dsa_verify_hash.c b/src/pk/dsa/dsa_verify_hash.c index b13caf9..baac9ee 100644 --- a/src/pk/dsa/dsa_verify_hash.c +++ b/src/pk/dsa/dsa_verify_hash.c @@ -98,16 +98,23 @@ int dsa_verify_hash(const unsigned char *sig, unsigned long siglen, { int err; void *r, *s; + ltc_asn1_list sig_seq[2]; + unsigned long reallen = 0; if ((err = mp_init_multi(&r, &s, NULL)) != CRYPT_OK) { return err; } - /* decode the sequence */ - if ((err = der_decode_sequence_multi(sig, siglen, - LTC_ASN1_INTEGER, 1UL, r, - LTC_ASN1_INTEGER, 1UL, s, - LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { + LTC_SET_ASN1(sig_seq, 0, LTC_ASN1_INTEGER, r, 1UL); + LTC_SET_ASN1(sig_seq, 1, LTC_ASN1_INTEGER, s, 1UL); + + err = der_decode_sequence(sig, siglen, sig_seq, 2); + if (err != CRYPT_OK) { + goto LBL_ERR; + } + + err = der_length_sequence(sig_seq, 2, &reallen); + if (err != CRYPT_OK || reallen != siglen) { goto LBL_ERR; }