[svn] GnuPG - r4118 - in trunk: cipher include
svn author dshaw
cvs at cvs.gnupg.org
Thu Apr 20 20:40:39 CEST 2006
Author: dshaw
Date: 2006-04-20 20:40:37 +0200 (Thu, 20 Apr 2006)
New Revision: 4118
Modified:
trunk/cipher/ChangeLog
trunk/cipher/dsa.c
trunk/include/ChangeLog
trunk/include/cipher.h
Log:
The plumbing necessary to create DSA keys with variable sized q.
Not yet used (q==160).
Modified: trunk/cipher/ChangeLog
===================================================================
--- trunk/cipher/ChangeLog 2006-04-20 02:36:05 UTC (rev 4117)
+++ trunk/cipher/ChangeLog 2006-04-20 18:40:37 UTC (rev 4118)
@@ -1,3 +1,8 @@
+2006-04-20 David Shaw <dshaw at jabberwocky.com>
+
+ * dsa.c (dsa2_generate): New function to generate a DSA key with a
+ variable sized q.
+
2006-04-19 David Shaw <dshaw at jabberwocky.com>
* sha256.c (sha224_get_info, sha224_init): New init functions for
Modified: trunk/cipher/dsa.c
===================================================================
--- trunk/cipher/dsa.c 2006-04-20 02:36:05 UTC (rev 4117)
+++ trunk/cipher/dsa.c 2006-04-20 18:40:37 UTC (rev 4118)
@@ -1,5 +1,5 @@
/* dsa.c - DSA signature algorithm
- * Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2003, 2006 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -49,7 +49,8 @@
static MPI gen_k( MPI q );
static void test_keys( DSA_secret_key *sk, unsigned qbits );
static int check_secret_key( DSA_secret_key *sk );
-static void generate( DSA_secret_key *sk, unsigned nbits, MPI **ret_factors );
+static void generate( DSA_secret_key *sk, unsigned nbits, unsigned qbits,
+ MPI **ret_factors );
static void sign(MPI r, MPI s, MPI input, DSA_secret_key *skey);
static int verify(MPI r, MPI s, MPI input, DSA_public_key *pkey);
@@ -168,20 +169,20 @@
* and an array with the n-1 factors of (p-1)
*/
static void
-generate( DSA_secret_key *sk, unsigned nbits, MPI **ret_factors )
+generate( DSA_secret_key *sk, unsigned nbits, unsigned qbits,
+ MPI **ret_factors )
{
MPI p; /* the prime */
- MPI q; /* the 160 bit prime factor */
+ MPI q; /* the prime factor */
MPI g; /* the generator */
MPI y; /* g^x mod p */
MPI x; /* the secret exponent */
MPI h, e; /* helper */
- unsigned qbits;
byte *rndbuf;
assert( nbits >= 512 && nbits <= 1024 );
+ assert( qbits >= 160 );
- qbits = 160;
p = generate_elg_prime( 1, nbits, qbits, NULL, ret_factors );
/* get q out of factors */
q = mpi_copy((*ret_factors)[0]);
@@ -207,7 +208,6 @@
* is the secret part. */
if( DBG_CIPHER )
log_debug("choosing a random x ");
- assert( qbits >= 160 );
x = mpi_alloc_secure( mpi_get_nlimbs(q) );
mpi_sub_ui( h, q, 1 ); /* put q-1 into h */
rndbuf = NULL;
@@ -364,15 +364,22 @@
************** interface ******************
*********************************************/
+/* DSA2 has a variable-sized q, which adds an extra parameter to the
+ pubkey generation. I'm doing this as a different function as it is
+ only called from one place and is thus cleaner than revamping the
+ pubkey_generate interface to carry an extra parameter which would
+ be meaningless for all algorithms other than DSA. */
+
int
-dsa_generate( int algo, unsigned nbits, MPI *skey, MPI **retfactors )
+dsa2_generate( int algo, unsigned nbits, unsigned qbits,
+ MPI *skey, MPI **retfactors )
{
DSA_secret_key sk;
if( algo != PUBKEY_ALGO_DSA )
return G10ERR_PUBKEY_ALGO;
- generate( &sk, nbits, retfactors );
+ generate( &sk, nbits, qbits, retfactors );
skey[0] = sk.p;
skey[1] = sk.q;
skey[2] = sk.g;
@@ -383,6 +390,13 @@
int
+dsa_generate( int algo, unsigned nbits, MPI *skey, MPI **retfactors )
+{
+ return dsa2_generate(algo,nbits,160,skey,retfactors);
+}
+
+
+int
dsa_check_secret_key( int algo, MPI *skey )
{
DSA_secret_key sk;
Modified: trunk/include/ChangeLog
===================================================================
--- trunk/include/ChangeLog 2006-04-20 02:36:05 UTC (rev 4117)
+++ trunk/include/ChangeLog 2006-04-20 18:40:37 UTC (rev 4118)
@@ -1,3 +1,7 @@
+2006-04-20 David Shaw <dshaw at jabberwocky.com>
+
+ * cipher.h: Add dsa2_generate();
+
2006-04-19 David Shaw <dshaw at jabberwocky.com>
* cipher.h: Add SHA-224.
Modified: trunk/include/cipher.h
===================================================================
--- trunk/include/cipher.h 2006-04-20 02:36:05 UTC (rev 4117)
+++ trunk/include/cipher.h 2006-04-20 18:40:37 UTC (rev 4118)
@@ -184,6 +184,8 @@
int pubkey_get_nenc( int algo );
unsigned pubkey_nbits( int algo, MPI *pkey );
int pubkey_generate( int algo, unsigned nbits, MPI *skey, MPI **retfactors );
+int dsa2_generate( int algo, unsigned nbits, unsigned qbits,
+ MPI *skey, MPI **retfactors );
int pubkey_check_secret_key( int algo, MPI *skey );
int pubkey_encrypt( int algo, MPI *resarr, MPI data, MPI *pkey );
int pubkey_decrypt( int algo, MPI *result, MPI *data, MPI *skey );
More information about the Gnupg-commits
mailing list