[svn] gcry - r1302 - in trunk: cipher mpi random src

svn author wk cvs at cvs.gnupg.org
Wed Aug 20 19:59:45 CEST 2008


Author: wk
Date: 2008-08-20 19:59:42 +0200 (Wed, 20 Aug 2008)
New Revision: 1302

Modified:
   trunk/cipher/ac.c
   trunk/cipher/dsa.c
   trunk/cipher/ecc.c
   trunk/cipher/md.c
   trunk/cipher/primegen.c
   trunk/cipher/pubkey.c
   trunk/cipher/rijndael.c
   trunk/cipher/whirlpool.c
   trunk/mpi/ec.c
   trunk/mpi/mpi-bit.c
   trunk/mpi/mpi-mod.c
   trunk/mpi/mpi-mpow.c
   trunk/mpi/mpi-pow.c
   trunk/mpi/mpicoder.c
   trunk/mpi/mpiutil.c
   trunk/random/random-csprng.c
   trunk/random/random.c
   trunk/random/rndhw.c
   trunk/random/rndw32.c
   trunk/src/ChangeLog
   trunk/src/ath.c
   trunk/src/fips.c
   trunk/src/g10lib.h
   trunk/src/global.c
   trunk/src/misc.c
Log:
Replace assert calls by a new gcry_assert at most places.


[The diff below has been truncated]

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/src/ChangeLog	2008-08-20 17:59:42 UTC (rev 1302)
@@ -1,3 +1,10 @@
+2008-08-20  Werner Koch  <wk at g10code.com>
+
+	* g10lib.h (gcry_assert): New.  use this at almost all places
+	where we used a plain assert.
+	* misc.c (_gcry_assert_failed): New.
+	(_gcry_bug): Also use func variant for ISO-C99.
+
 2008-08-19  Werner Koch  <wk at g10code.com>
 
 	* visibility.c, visibility.h (gcry_mpi_lshift): New.

Modified: trunk/cipher/ac.c
===================================================================
--- trunk/cipher/ac.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/cipher/ac.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -24,7 +24,6 @@
 #include <string.h>
 #include <stdio.h>
 #include <stddef.h>
-#include <assert.h>
 
 #include "g10lib.h"
 #include "cipher.h"
@@ -886,8 +885,8 @@
   if (fips_mode ())
     return;
 
-  assert ((mode == GCRY_AC_IO_READABLE) || (mode == GCRY_AC_IO_WRITABLE));
-  assert ((type == GCRY_AC_IO_STRING) || (type == GCRY_AC_IO_STRING));
+  gcry_assert ((mode == GCRY_AC_IO_READABLE) || (mode == GCRY_AC_IO_WRITABLE));
+  gcry_assert ((type == GCRY_AC_IO_STRING) || (type == GCRY_AC_IO_STRING));
 
   ac_io->mode = mode;
   ac_io->type = type;
@@ -947,7 +946,7 @@
 {
   gcry_error_t err;
 
-  assert (ac_io->mode == GCRY_AC_IO_WRITABLE);
+  gcry_assert (ac_io->mode == GCRY_AC_IO_WRITABLE);
   err = 0;
 
   switch (ac_io->type)
@@ -1007,7 +1006,7 @@
 {
   gcry_error_t err;
   
-  assert (ac_io->mode == GCRY_AC_IO_READABLE);
+  gcry_assert (ac_io->mode == GCRY_AC_IO_READABLE);
   err = 0;
 
   switch (ac_io->type)

Modified: trunk/cipher/dsa.c
===================================================================
--- trunk/cipher/dsa.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/cipher/dsa.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -23,7 +23,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 #include "g10lib.h"
 #include "mpi.h"
@@ -237,7 +236,7 @@
    * is the secret part. */
   if( DBG_CIPHER )
     log_debug("choosing a random x ");
-  assert( qbits >= 160 );
+  gcry_assert( qbits >= 160 );
   x = mpi_alloc_secure( mpi_get_nlimbs(q) );
   mpi_sub_ui( h, q, 1 );  /* put q-1 into h */
   rndbuf = NULL;

Modified: trunk/cipher/ecc.c
===================================================================
--- trunk/cipher/ecc.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/cipher/ecc.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -54,7 +54,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 #include "g10lib.h"
 #include "mpi.h"

Modified: trunk/cipher/md.c
===================================================================
--- trunk/cipher/md.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/cipher/md.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -23,7 +23,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <assert.h>
 
 #include "g10lib.h"
 #include "cipher.h"
@@ -627,10 +626,10 @@
     {
       bhd->ctx = b = (struct gcry_md_context *) ((char *) bhd + n);
       /* No need to copy the buffer due to the write above. */
-      assert (ahd->bufsize == (n - sizeof (struct gcry_md_handle) + 1));
+      gcry_assert (ahd->bufsize == (n - sizeof (struct gcry_md_handle) + 1));
       bhd->bufsize = ahd->bufsize;
       bhd->bufpos = 0;
-      assert (! ahd->bufpos);
+      gcry_assert (! ahd->bufpos);
       memcpy (b, a, sizeof *a);
       b->list = NULL;
       b->debug = NULL;
@@ -843,7 +842,7 @@
       gcry_md_hash_buffer ( algo, helpkey, key, keylen );
       key = helpkey;
       keylen = md_digest_length( algo );
-      assert ( keylen <= 64 );
+      gcry_assert ( keylen <= 64 );
     }
 
   memset ( hd->ctx->macpads, 0, 2*(hd->ctx->macpads_Bsize) );

Modified: trunk/cipher/primegen.c
===================================================================
--- trunk/cipher/primegen.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/cipher/primegen.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -24,7 +24,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 #include <errno.h>
 
 #include "g10lib.h"
@@ -208,7 +207,7 @@
       {
         gcry_mpi_t prime = item->prime;
         item->prime = NULL;
-        assert (nbits == mpi_get_nbits (prime));
+        gcry_assert (nbits == mpi_get_nbits (prime));
         return prime;
       }
   return NULL;
@@ -950,7 +949,7 @@
               mpi_set_highbit( x, nbits-2 );
               mpi_clear_bit( x, nbits-2 );
             }
-          assert ( mpi_cmp( x, nminus1 ) < 0 && mpi_cmp_ui( x, 1 ) > 0 );
+          gcry_assert (mpi_cmp (x, nminus1) < 0 && mpi_cmp_ui (x, 1) > 0);
 	}
       gcry_mpi_powm ( y, x, q, n);
       if ( mpi_cmp_ui(y, 1) && mpi_cmp( y, nminus1 ) )

Modified: trunk/cipher/pubkey.c
===================================================================
--- trunk/cipher/pubkey.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/cipher/pubkey.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -23,7 +23,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <assert.h>
 
 #include "g10lib.h"
 #include "mpi.h"
@@ -860,7 +859,7 @@
   /* Clear the array for easir error cleanup. */
   for (name = element_names, idx = 0; *name; name++, idx++)
     elements[idx] = NULL;
-  assert (idx >= 6); /* We know that ECC has at least 6 elements.  */
+  gcry_assert (idx >= 6); /* We know that ECC has at least 6 elements.  */
 
   /* Init the array with the available curve parameters. */
   for (name = element_names, idx = 0; *name && !err; name++, idx++)
@@ -1391,7 +1390,7 @@
           frame[n++] = 0;
           frame[n++] = 2; /* block type */
           i = nframe - 3 - valuelen;
-          assert (i > 0);
+          gcry_assert (i > 0);
           p = gcry_random_bytes_secure (i, GCRY_STRONG_RANDOM);
           /* Replace zero bytes by new values. */
           for (;;)
@@ -1426,7 +1425,7 @@
           frame[n++] = 0;
           memcpy (frame+n, value, valuelen);
           n += valuelen;
-          assert (n == nframe);
+          gcry_assert (n == nframe);
 
 	  /* FIXME, error checking?  */
           gcry_mpi_scan (ret_mpi, GCRYMPI_FMT_USG, frame, n, &nframe);
@@ -1527,7 +1526,7 @@
               frame[n++] = 0;
               frame[n++] = 1; /* block type */
               i = nframe - valuelen - asnlen - 3 ;
-              assert (i > 1);
+              gcry_assert (i > 1);
               memset (frame+n, 0xff, i );
               n += i;
               frame[n++] = 0;
@@ -1535,7 +1534,7 @@
               n += asnlen;
               memcpy (frame+n, value, valuelen );
               n += valuelen;
-              assert (n == nframe);
+              gcry_assert (n == nframe);
       
               /* Convert it into an MPI.  FIXME: error checking?  */
               gcry_mpi_scan (ret_mpi, GCRYMPI_FMT_USG, frame, n, &nframe);
@@ -1599,7 +1598,7 @@
   if (rc)
     goto leave;
 
-  assert (module);
+  gcry_assert (module);
   pubkey = (gcry_pk_spec_t *) module->spec;
 
   /* If aliases for the algorithm name exists, take the first one
@@ -1838,7 +1837,7 @@
   if (rc)
     goto leave;
 
-  assert (module);
+  gcry_assert (module);
   pubkey = (gcry_pk_spec_t *) module->spec;
   algo_name = pubkey->aliases? *pubkey->aliases : NULL;
   if (!algo_name || !*algo_name)
@@ -2291,7 +2290,7 @@
         p = stpcpy (p, "))");
       }
     strcpy (p, ")");
-    assert (p - string < needed);
+    gcry_assert (p - string < needed);
 
     while (nelem < DIM (mpis))
       mpis[nelem++] = NULL;
@@ -2315,9 +2314,9 @@
       free (arg_list);
       if (rc)
 	BUG ();
-      assert (DIM (mpis) == 30); /* Reminder to make sure that the
-                                    array gets increased if new
-                                    parameters are added. */
+      gcry_assert (DIM (mpis) == 30); /* Reminder to make sure that
+                                         the array gets increased if
+                                         new parameters are added. */
     }
     gcry_free (string);
   }

Modified: trunk/cipher/rijndael.c
===================================================================
--- trunk/cipher/rijndael.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/cipher/rijndael.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h> /* for memcmp() */
-#include <assert.h>
 
 #include "types.h"  /* for byte and u32 typedefs */
 #include "g10lib.h"
@@ -995,8 +994,8 @@
     return a;                    \
   } while (0)
 
-  assert (sizeof tv[0].data[0].input == sizeof scratch);
-  assert (sizeof tv[0].data[0].output == sizeof scratch);
+  gcry_assert (sizeof tv[0].data[0].input == sizeof scratch);
+  gcry_assert (sizeof tv[0].data[0].output == sizeof scratch);
 
   for (tvi=0; tvi < DIM (tv); tvi++)
     if (tv[tvi].mode == requested_mode)

Modified: trunk/cipher/whirlpool.c
===================================================================
--- trunk/cipher/whirlpool.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/cipher/whirlpool.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -33,7 +33,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 #include "types.h"
 #include "g10lib.h"
@@ -1350,7 +1349,7 @@
       buffer_size >>= 8;
       carry >>= 8;
     }
-  assert (! (buffer_size || carry));
+  gcry_assert (! (buffer_size || carry));
 }
 
 static void

Modified: trunk/mpi/ec.c
===================================================================
--- trunk/mpi/ec.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/mpi/ec.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -22,7 +22,6 @@
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <assert.h>
 
 #include "mpi-internal.h"
 #include "longlong.h"

Modified: trunk/mpi/mpi-bit.c
===================================================================
--- trunk/mpi/mpi-bit.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/mpi/mpi-bit.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -21,7 +21,6 @@
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <assert.h>
 #include "mpi-internal.h"
 #include "longlong.h"
 

Modified: trunk/mpi/mpi-mod.c
===================================================================
--- trunk/mpi/mpi-mod.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/mpi/mpi-mod.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -23,7 +23,6 @@
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <assert.h>
 
 #include "mpi-internal.h"
 #include "longlong.h"

Modified: trunk/mpi/mpi-mpow.c
===================================================================
--- trunk/mpi/mpi-mpow.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/mpi/mpi-mpow.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -21,10 +21,10 @@
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
+
 #include "mpi-internal.h"
 #include "longlong.h"
 #include "g10lib.h"
-#include <assert.h>
 
 
 /* Barrett is slower than the classical way.  It can be tweaked by
@@ -77,7 +77,7 @@
 
     for(k=0; basearray[k]; k++ )
 	;
-    assert(k);
+    gcry_assert(k);
     for(t=0, i=0; (tmp=exparray[i]); i++ ) {
 	/*log_mpidump("exp: ", tmp );*/
 	j = mpi_get_nbits(tmp);
@@ -85,9 +85,9 @@
 	    t = j;
     }
     /*log_mpidump("mod: ", m );*/
-    assert(i==k);
-    assert(t);
-    assert( k < 10 );
+    gcry_assert (i==k);
+    gcry_assert (t);
+    gcry_assert (k < 10);
 
     G = gcry_xcalloc( (1<<k) , sizeof *G );
 #ifdef USE_BARRETT
@@ -100,7 +100,7 @@
 	barrett_mulm(tmp, res, res, m, barrett_y, barrett_k,
 				       barrett_r1, barrett_r2 );
 	idx = build_index( exparray, k, i, t );
-	assert( idx >= 0 && idx < (1<<k) );
+	gcry_assert (idx >= 0 && idx < (1<<k));
 	if( !G[idx] ) {
 	    if( !idx )
 		 G[0] = mpi_alloc_set_ui( 1 );

Modified: trunk/mpi/mpi-pow.c
===================================================================
--- trunk/mpi/mpi-pow.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/mpi/mpi-pow.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -28,9 +28,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "mpi-internal.h"
 #include "longlong.h"
-#include <assert.h>
 
 
 /****************
@@ -133,7 +133,7 @@
     else { /* Make BASE, EXPO and MOD not overlap with RES.  */
 	if( rp == bp ) {
 	    /* RES and BASE are identical.  Allocate temp. space for BASE.  */
-	    assert( !bp_marker );
+	    gcry_assert (!bp_marker);
             bp_nlimbs = bsec? bsize:0;
 	    bp = bp_marker = mpi_alloc_limb_space( bsize, bsec );
 	    MPN_COPY(bp, rp, bsize);
@@ -146,7 +146,7 @@
 	}
 	if( rp == mp ) {
 	    /* RES and MOD are identical.  Allocate temporary space for MOD.*/
-	    assert( !mp_marker );
+	    gcry_assert (!mp_marker);
             mp_nlimbs = msec?msize:0;
 	    mp = mp_marker = mpi_alloc_limb_space( msize, msec );
 	    MPN_COPY(mp, rp, msize);

Modified: trunk/mpi/mpicoder.c
===================================================================
--- trunk/mpi/mpicoder.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/mpi/mpicoder.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -23,7 +23,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <assert.h>
 
 #include "mpi-internal.h"
 #include "g10lib.h"
@@ -123,9 +122,9 @@
 	    }
 	    else
 		c1 = *str++;
-	    assert(c1);
+	    gcry_assert (c1);
 	    c2 = *str++;
-	    assert(c2);
+	    gcry_assert (c2);
 	    if( c1 >= '0' && c1 <= '9' )
 		c = c1 - '0';
 	    else if( c1 >= 'a' && c1 <= 'f' )
@@ -328,7 +327,7 @@
 	a->d[i++] = alimb;
     }
     a->nlimbs = i;
-    assert( i == nlimbs );
+    gcry_assert (i == nlimbs);
 }
 
 

Modified: trunk/mpi/mpiutil.c
===================================================================
--- trunk/mpi/mpiutil.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/mpi/mpiutil.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -22,7 +22,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 #include "g10lib.h"
 #include "mpi-internal.h"
@@ -196,7 +195,7 @@
   ap = a->d;
   if (!a->nlimbs)
     {
-      assert(!ap);
+      gcry_assert (!ap);
       return;
     }
   bp = mpi_alloc_limb_space (a->nlimbs, 1);

Modified: trunk/random/random-csprng.c
===================================================================
--- trunk/random/random-csprng.c	2008-08-20 14:10:11 UTC (rev 1301)
+++ trunk/random/random-csprng.c	2008-08-20 17:59:42 UTC (rev 1302)
@@ -29,7 +29,6 @@
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <assert.h>
 #include <errno.h>
 #include <string.h>
 #include <sys/time.h>
@@ -278,9 +277,9 @@
 
       /* Make sure that we are still using the values we have
          traditionally used for the random levels.  */
-      assert ( GCRY_WEAK_RANDOM == 0 
-               && GCRY_STRONG_RANDOM == 1
-               && GCRY_VERY_STRONG_RANDOM == 2);
+      gcry_assert (GCRY_WEAK_RANDOM == 0 
+                   && GCRY_STRONG_RANDOM == 1
+                   && GCRY_VERY_STRONG_RANDOM == 2);
     }
 }
 
@@ -603,7 +602,7 @@
 #error must have a digest length of 20 for ripe-md-160
 #endif
 
-  assert (pool_is_locked);
+  gcry_assert (pool_is_locked);
   _gcry_rmd160_init( &md );
 
   /* Loop over the pool.  */
@@ -728,7 +727,7 @@
   unsigned char buffer[POOLSIZE];




More information about the Gnupg-commits mailing list