[svn] GnuPG - r4182 - trunk/g10

svn author dshaw cvs at cvs.gnupg.org
Wed Jun 28 19:54:37 CEST 2006


Author: dshaw
Date: 2006-06-28 19:54:35 +0200 (Wed, 28 Jun 2006)
New Revision: 4182

Modified:
   trunk/g10/ChangeLog
   trunk/g10/keydb.h
   trunk/g10/pkclist.c
   trunk/g10/sign.c
Log:
* keydb.h, pkclist.c (select_algo_from_prefs, algo_available): Pass a
union for preference hints rather than doing void * games.

* sign.c (sign_file): Use it here.


Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog	2006-06-28 17:12:55 UTC (rev 4181)
+++ trunk/g10/ChangeLog	2006-06-28 17:54:35 UTC (rev 4182)
@@ -1,5 +1,10 @@
 2006-06-28  David Shaw  <dshaw at jabberwocky.com>
 
+	* keydb.h, pkclist.c (select_algo_from_prefs, algo_available):
+	Pass a union for preference hints rather than doing void * games.
+
+	* sign.c (sign_file): Use it here.
+
 	* sign.c (sign_file): When signing with multiple DSA keys, one
 	being DSA1 and one being DSA2 and encrypting at the same time, if
 	the recipient preferences give a hash that can work with the DSA2

Modified: trunk/g10/keydb.h
===================================================================
--- trunk/g10/keydb.h	2006-06-28 17:12:55 UTC (rev 4181)
+++ trunk/g10/keydb.h	2006-06-28 17:54:35 UTC (rev 4182)
@@ -177,9 +177,14 @@
 int  check_signatures_trust( PKT_signature *sig );
 void release_pk_list( PK_LIST pk_list );
 int  build_pk_list( STRLIST rcpts, PK_LIST *ret_pk_list, unsigned use );
-int  algo_available( preftype_t preftype, int algo, void *hint );
+union pref_hint
+{
+  int digest_length;
+};
+int  algo_available( preftype_t preftype, int algo,
+		     const union pref_hint *hint );
 int  select_algo_from_prefs( PK_LIST pk_list, int preftype,
-			     int request, void *hint );
+			     int request, const union pref_hint *hint );
 int  select_mdc_from_pklist (PK_LIST pk_list);
 
 /*-- skclist.c --*/

Modified: trunk/g10/pkclist.c
===================================================================
--- trunk/g10/pkclist.c	2006-06-28 17:12:55 UTC (rev 4181)
+++ trunk/g10/pkclist.c	2006-06-28 17:54:35 UTC (rev 4182)
@@ -1186,7 +1186,7 @@
    preference list, so I'm including it. -dms */
 
 int
-algo_available( preftype_t preftype, int algo, void *hint )
+algo_available( preftype_t preftype, int algo, const union pref_hint *hint )
 {
   if( preftype == PREFTYPE_SYM )
     {
@@ -1210,18 +1210,18 @@
     }
   else if( preftype == PREFTYPE_HASH )
     {
-      if(hint)
+      if(hint && hint->digest_length)
 	{
-	  if((*(int *)hint)!=20 || opt.flags.dsa2)
+	  if(hint->digest_length!=20 || opt.flags.dsa2)
 	    {
 	      /* If --enable-dsa2 is set or the hash isn't 160 bits
 		 (which implies DSA2), then we'll accept a hash that
 		 is larger than we need.  Otherwise we won't accept
 		 any hash that isn't exactly the right size. */
-	      if((*(int *)hint) > md_digest_length(algo))
+	      if(hint->digest_length > md_digest_length(algo))
 		return 0;
 	    }
-	  else if(((*(int *)hint) != md_digest_length(algo)))
+	  else if(hint->digest_length != md_digest_length(algo))
 	    return 0;
 	}
 
@@ -1259,7 +1259,8 @@
  * Return -1 if we could not find an algorithm.
  */
 int
-select_algo_from_prefs(PK_LIST pk_list, int preftype, int request, void *hint)
+select_algo_from_prefs(PK_LIST pk_list, int preftype,
+		       int request, const union pref_hint *hint)
 {
     PK_LIST pkr;
     u32 bits[8];

Modified: trunk/g10/sign.c
===================================================================
--- trunk/g10/sign.c	2006-06-28 17:12:55 UTC (rev 4181)
+++ trunk/g10/sign.c	2006-06-28 17:54:35 UTC (rev 4182)
@@ -866,8 +866,11 @@
 	  }
 	else
 	  {
-	    int hashlen=0,algo,smartcard=0;
+	    union pref_hint hint;
+	    int algo,smartcard=0;
 
+	    hint.digest_length=0;
+
 	    /* Of course, if the recipient asks for something
 	       unreasonable (like the wrong hash for a DSA key) then
 	       don't do it.  Check all sk's - if any are DSA or live
@@ -894,8 +897,8 @@
 		    /* Pick a hash that is large enough for our
 		       largest q */
 
-		    if(hashlen<temp_hashlen)
-		      hashlen=temp_hashlen;
+		    if(hint.digest_length<temp_hashlen)
+		      hint.digest_length=temp_hashlen;
 		  }
 		else if(sk_rover->sk->is_protected
 			&& sk_rover->sk->protect.s2k.mode==1002)
@@ -909,10 +912,9 @@
 	       single hash for all signatures.  All this may well have
 	       to change as the cards add algorithms. */
 
-	    if(!smartcard || (smartcard && hashlen==20))
+	    if(!smartcard || (smartcard && hint.digest_length==20))
 	      if((algo=
-		  select_algo_from_prefs(pk_list,PREFTYPE_HASH,-1,
-					 hashlen?&hashlen:NULL))>0)
+		  select_algo_from_prefs(pk_list,PREFTYPE_HASH,-1,&hint))>0)
 		recipient_digest_algo=algo;
 	  }
       }




More information about the Gnupg-commits mailing list