[git] GCRYPT - branch, master, updated. libgcrypt-1.6.0-107-gf850add

by Werner Koch cvs at cvs.gnupg.org
Thu Aug 21 12:27:12 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU crypto library".

The branch, master has been updated
       via  f850add813d783f31ca6a60459dea25ef71bce7e (commit)
       via  18056ace7f466cb8c1eaf08e5dc0400516d83b4c (commit)
      from  34bb55ee36df3aca3ebca88f8b61c786cd0c0701 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f850add813d783f31ca6a60459dea25ef71bce7e
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Aug 21 11:47:16 2014 +0200

    cipher: Fix a segv in case of calling with wrong parameters.
    
    * cipher/md.c (_gcry_md_info): Fix arg testing.
    --
    
    GnuPG-bug-id: 1697

diff --git a/cipher/md.c b/cipher/md.c
index a1e5859..df8b027 100644
--- a/cipher/md.c
+++ b/cipher/md.c
@@ -1181,7 +1181,7 @@ _gcry_md_info (gcry_md_hd_t h, int cmd, void *buffer, size_t *nbytes)
 	GcryDigestEntry *r;
 	int algo;
 
-	if ( !buffer || (nbytes && (*nbytes != sizeof (int))))
+	if ( !buffer || !nbytes || *nbytes != sizeof (int))
 	  rc = GPG_ERR_INV_ARG;
 	else
 	  {

commit 18056ace7f466cb8c1eaf08e5dc0400516d83b4c
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Aug 21 11:39:17 2014 +0200

    cipher: Fix possible NULL deref in call to prime generator.
    
    * cipher/primegen.c (_gcry_generate_elg_prime): Change to return an
    error code.
    * cipher/dsa.c (generate): Take care of new return code.
    * cipher/elgamal.c (generate): Change to return an error code.  Take
    care of _gcry_generate_elg_prime return code.
    (generate_using_x): Take care of _gcry_generate_elg_prime return code.
    (elg_generate): Propagate return code from generate.
    --
    
    GnuPG-bug-id: 1699, 1700
    Reported-by: S.K. Gupta
    
    Note that the NULL deref may have only happened on malloc failure.

diff --git a/cipher/dsa.c b/cipher/dsa.c
index 1707d8c..09cd969 100644
--- a/cipher/dsa.c
+++ b/cipher/dsa.c
@@ -196,6 +196,7 @@ static gpg_err_code_t
 generate (DSA_secret_key *sk, unsigned int nbits, unsigned int qbits,
           int transient_key, dsa_domain_t *domain, gcry_mpi_t **ret_factors )
 {
+  gpg_err_code_t rc;
   gcry_mpi_t p;    /* the prime */
   gcry_mpi_t q;    /* the 160 bit prime factor */
   gcry_mpi_t g;    /* the generator */
@@ -247,7 +248,10 @@ generate (DSA_secret_key *sk, unsigned int nbits, unsigned int qbits,
   else
     {
       /* Generate new domain parameters.  */
-      p = _gcry_generate_elg_prime (1, nbits, qbits, NULL, ret_factors);
+      rc = _gcry_generate_elg_prime (1, nbits, qbits, NULL, &p, ret_factors);
+      if (rc)
+        return rc;
+
       /* Get q out of factors.  */
       q = mpi_copy ((*ret_factors)[0]);
       gcry_assert (mpi_get_nbits (q) == qbits);
diff --git a/cipher/elgamal.c b/cipher/elgamal.c
index a71a9bc..cb3ca43 100644
--- a/cipher/elgamal.c
+++ b/cipher/elgamal.c
@@ -61,7 +61,8 @@ static const char *elg_names[] =
 
 static int test_keys (ELG_secret_key *sk, unsigned int nbits, int nodie);
 static gcry_mpi_t gen_k (gcry_mpi_t p, int small_k);
-static void generate (ELG_secret_key *sk, unsigned nbits, gcry_mpi_t **factors);
+static gcry_err_code_t generate (ELG_secret_key *sk, unsigned nbits,
+                                 gcry_mpi_t **factors);
 static int  check_secret_key (ELG_secret_key *sk);
 static void do_encrypt (gcry_mpi_t a, gcry_mpi_t b, gcry_mpi_t input,
                         ELG_public_key *pkey);
@@ -268,9 +269,10 @@ gen_k( gcry_mpi_t p, int small_k )
  * Returns: 2 structures filled with all needed values
  *	    and an array with n-1 factors of (p-1)
  */
-static void
+static gcry_err_code_t
 generate ( ELG_secret_key *sk, unsigned int nbits, gcry_mpi_t **ret_factors )
 {
+  gcry_err_code_t rc;
   gcry_mpi_t p;    /* the prime */
   gcry_mpi_t p_min1;
   gcry_mpi_t g;
@@ -285,7 +287,13 @@ generate ( ELG_secret_key *sk, unsigned int nbits, gcry_mpi_t **ret_factors )
   if( qbits & 1 ) /* better have a even one */
     qbits++;
   g = mpi_alloc(1);
-  p = _gcry_generate_elg_prime( 0, nbits, qbits, g, ret_factors );
+  rc = _gcry_generate_elg_prime (0, nbits, qbits, g, &p, ret_factors);
+  if (rc)
+    {
+      mpi_free (p_min1);
+      mpi_free (g);
+      return rc;
+    }
   mpi_sub_ui(p_min1, p, 1);
 
 
@@ -359,6 +367,8 @@ generate ( ELG_secret_key *sk, unsigned int nbits, gcry_mpi_t **ret_factors )
 
   /* Now we can test our keys (this should never fail!) */
   test_keys ( sk, nbits - 64, 0 );
+
+  return 0;
 }
 
 
@@ -373,6 +383,7 @@ static gcry_err_code_t
 generate_using_x (ELG_secret_key *sk, unsigned int nbits, gcry_mpi_t x,
                   gcry_mpi_t **ret_factors )
 {
+  gcry_err_code_t rc;
   gcry_mpi_t p;      /* The prime.  */
   gcry_mpi_t p_min1; /* The prime minus 1.  */
   gcry_mpi_t g;      /* The generator.  */
@@ -395,7 +406,13 @@ generate_using_x (ELG_secret_key *sk, unsigned int nbits, gcry_mpi_t x,
   if ( (qbits & 1) ) /* Better have an even one.  */
     qbits++;
   g = mpi_alloc (1);
-  p = _gcry_generate_elg_prime ( 0, nbits, qbits, g, ret_factors );
+  rc = _gcry_generate_elg_prime (0, nbits, qbits, g, &p, ret_factors );
+  if (rc)
+    {
+      mpi_free (p_min1);
+      mpi_free (g);
+      return rc;
+    }
   mpi_sub_ui (p_min1, p, 1);
 
   if (DBG_CIPHER)
@@ -662,8 +679,7 @@ elg_generate (const gcry_sexp_t genparms, gcry_sexp_t *r_skey)
     }
   else
     {
-      generate (&sk, nbits, &factors);
-      rc = 0;
+      rc = generate (&sk, nbits, &factors);
     }
   if (rc)
     goto leave;
diff --git a/cipher/primegen.c b/cipher/primegen.c
index 9f6ec70..14a5ccf 100644
--- a/cipher/primegen.c
+++ b/cipher/primegen.c
@@ -726,19 +726,22 @@ prime_generate_internal (int need_q_factor,
 
 
 /* Generate a prime used for discrete logarithm algorithms; i.e. this
-   prime will be public and no strong random is required.  */
-gcry_mpi_t
+   prime will be public and no strong random is required.  On success
+   R_PRIME receives a new MPI with the prime.  On error R_PRIME is set
+   to NULL and an error code is returned.  If RET_FACTORS is not NULL
+   it is set to an allocated array of factors on success or to NULL on
+   error.  */
+gcry_err_code_t
 _gcry_generate_elg_prime (int mode, unsigned pbits, unsigned qbits,
-			  gcry_mpi_t g, gcry_mpi_t **ret_factors)
+			  gcry_mpi_t g,
+                          gcry_mpi_t *r_prime, gcry_mpi_t **ret_factors)
 {
-  gcry_mpi_t prime = NULL;
-
-  if (prime_generate_internal ((mode == 1), &prime, pbits, qbits, g,
-                               ret_factors, GCRY_WEAK_RANDOM, 0, 0,
-                               NULL, NULL))
-    prime = NULL; /* (Should be NULL in the error case anyway.)  */
-
-  return prime;
+  *r_prime = NULL;
+  if (ret_factors)
+    *ret_factors = NULL;
+  return prime_generate_internal ((mode == 1), r_prime, pbits, qbits, g,
+                                  ret_factors, GCRY_WEAK_RANDOM, 0, 0,
+                                  NULL, NULL);
 }
 
 
diff --git a/src/g10lib.h b/src/g10lib.h
index 43dc011..238871d 100644
--- a/src/g10lib.h
+++ b/src/g10lib.h
@@ -236,9 +236,12 @@ gcry_mpi_t _gcry_generate_public_prime (unsigned int nbits,
                                  gcry_random_level_t random_level,
                                  int (*extra_check)(void*, gcry_mpi_t),
                                  void *extra_check_arg);
-gcry_mpi_t _gcry_generate_elg_prime (int mode,
-                                     unsigned int pbits, unsigned int qbits,
-                                     gcry_mpi_t g, gcry_mpi_t **factors);
+gcry_err_code_t _gcry_generate_elg_prime (int mode,
+                                          unsigned int pbits,
+                                          unsigned int qbits,
+                                          gcry_mpi_t g,
+                                          gcry_mpi_t *r_prime,
+                                          gcry_mpi_t **factors);
 gcry_mpi_t _gcry_derive_x931_prime (const gcry_mpi_t xp,
                                     const gcry_mpi_t xp1, const gcry_mpi_t xp2,
                                     const gcry_mpi_t e,

-----------------------------------------------------------------------

Summary of changes:
 cipher/dsa.c      |    6 +++++-
 cipher/elgamal.c  |   28 ++++++++++++++++++++++------
 cipher/md.c       |    2 +-
 cipher/primegen.c |   25 ++++++++++++++-----------
 src/g10lib.h      |    9 ++++++---
 5 files changed, 48 insertions(+), 22 deletions(-)


hooks/post-receive
-- 
The GNU crypto library
http://git.gnupg.org


_______________________________________________
Gnupg-commits mailing list
Gnupg-commits at gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-commits




More information about the Gcrypt-devel mailing list