]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Corrected bug in DSA signature generation.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 18 May 2010 21:41:22 +0000 (23:41 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 3 Jun 2010 17:42:03 +0000 (19:42 +0200)
lib/x509/sign.c

index 31c7c4f57994fea572fa3ac33c6e5f418517989f..7d0373b086d5a94cb7a4d027e5e06a2baaa4ced2 100644 (file)
@@ -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