From: Nikos Mavrogiannopoulos Date: Tue, 18 May 2010 21:41:22 +0000 (+0200) Subject: Corrected bug in DSA signature generation. X-Git-Tag: gnutls_2_11_3~289 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2b3dc5053c3a04fdb69f642195190c466d4a539e;p=thirdparty%2Fgnutls.git Corrected bug in DSA signature generation. --- diff --git a/lib/x509/sign.c b/lib/x509/sign.c index 31c7c4f579..7d0373b086 100644 --- a/lib/x509/sign.c +++ b/lib/x509/sign.c @@ -49,7 +49,7 @@ */ static int encode_ber_digest_info (gnutls_digest_algorithm_t hash, - const gnutls_datum_t * digest, gnutls_datum_t * info) + const gnutls_datum_t * digest, gnutls_datum_t * output) { ASN1_TYPE dinfo = ASN1_TYPE_EMPTY; int result; @@ -101,18 +101,18 @@ encode_ber_digest_info (gnutls_digest_algorithm_t hash, return _gnutls_asn2err (result); } - info->size = 0; - asn1_der_coding (dinfo, "", NULL, &info->size, NULL); + output->size = 0; + asn1_der_coding (dinfo, "", NULL, &output->size, NULL); - info->data = gnutls_malloc (info->size); - if (info->data == NULL) + output->data = gnutls_malloc (output->size); + if (output->data == NULL) { gnutls_assert (); asn1_delete_structure (&dinfo); return GNUTLS_E_MEMORY_ERROR; } - result = asn1_der_coding (dinfo, "", info->data, &info->size, NULL); + result = asn1_der_coding (dinfo, "", output->data, &output->size, NULL); if (result != ASN1_SUCCESS) { gnutls_assert (); @@ -166,33 +166,37 @@ int pk_dsa_hash (const gnutls_datum_t * text, gnutls_datum_t * hash) { int ret; - opaque _digest[MAX_HASH_SIZE]; digest_hd_st hd; gnutls_datum_t digest; + opaque _digest[MAX_HASH_SIZE]; gnutls_digest_algorithm_t hash = _gnutls_dsa_q_to_hash(params[1]); + hash->size = _gnutls_hash_get_algo_len(hash); + hash->data = gnutls_malloc( hash->size); + if (hash->data == NULL) + { + gnutls_assert(); + return GNUTLS_E_MEMORY_ERROR; + } + ret = _gnutls_hash_init (&hd, hash); + if (ret < 0) { gnutls_assert (); - return ret; + goto fail; } _gnutls_hash (&hd, text->data, text->size); - _gnutls_hash_deinit (&hd, _digest); - digest.data = _digest; - digest.size = _gnutls_hash_get_algo_len(hash); - - if ((ret = - _gnutls_sign (GNUTLS_PK_DSA, params, params_len, &digest, - signature)) < 0) - { - gnutls_assert (); - return ret; - } + _gnutls_hash_deinit (&hd, hash->data); return 0; + +fail: + gnutls_free(hash->data); + + return ret; } /* This is the same as the _gnutls_x509_sign, but this one will decode