Assorted changeds
authorWerner Koch <wk@gnupg.org>
Thu, 8 Dec 2005 15:34:16 +0000 (15:34 +0000)
committerWerner Koch <wk@gnupg.org>
Thu, 8 Dec 2005 15:34:16 +0000 (15:34 +0000)
ChangeLog
THANKS
cipher/ChangeLog
cipher/dsa.c
configure.ac
doc/gcrypt.texi
tests/ChangeLog
tests/benchmark.c
tests/keygen.c

index d8dc774..46aecf7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-12-08  Werner Koch  <wk@g10code.com>
+
+       * configure.ac: Changed the random device names for netbsd.  From
+       Christian Biere.
+
 2005-11-02  Moritz Schulte  <moritz@g10code.com>
 
        * NEWS: Documented minor API changes.
diff --git a/THANKS b/THANKS
index 2441d05..d4948e5 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -14,6 +14,7 @@ Bryan Fullerton          bryanf@samurai.com
 Caskey L. Dickson         caskey@technocage.com
 Cees van de Griend        cees-list@griend.xs4all.nl
 Charles Levert            charles@comm.polymtl.ca
+Christian Biere            christianbiere@gmx.de
 Christian Grothoff         grothoff@cs.purdue.edu
 Christian von Roques      roques@pond.sub.org
 Christopher Oliver        oliver@fritz.traverse.net
index 57cbeed..c70ebca 100644 (file)
@@ -9,6 +9,12 @@
        * pubkey.c (gcry_pk_algo_info): Don't forget to break after switch
        case.
 
+2005-09-19  Werner Koch  <wk@g10code.com>
+
+       * dsa.c (generate): Add preliminary support for 2 and 4 keys.
+       Return an error code if the key size is not supported.
+       (_gcry_dsa_generate): Return an error.
+
 2005-08-22  Werner Koch  <wk@g10code.com>
 
        * primegen.c (check_prime): New arg RM_ROUNDS.
index c3b4c82..5faf97b 100644 (file)
@@ -50,8 +50,8 @@ typedef struct
 static gcry_mpi_t gen_k (gcry_mpi_t 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,
-                      gcry_mpi_t **ret_factors);
+static gpg_err_code_t generate (DSA_secret_key *sk, unsigned nbits,
+                                gcry_mpi_t **ret_factors);
 static void sign (gcry_mpi_t r, gcry_mpi_t s, gcry_mpi_t input,
                   DSA_secret_key *skey);
 static int verify (gcry_mpi_t r, gcry_mpi_t s, gcry_mpi_t input,
@@ -172,7 +172,7 @@ test_keys( DSA_secret_key *sk, unsigned qbits )
    Returns: 2 structures filled with all needed values
            and an array with the n-1 factors of (p-1)
  */
-static void
+static gpg_err_code_t
 generate( DSA_secret_key *sk, unsigned nbits, gcry_mpi_t **ret_factors )
 {
   gcry_mpi_t p;    /* the prime */
@@ -182,11 +182,21 @@ generate( DSA_secret_key *sk, unsigned nbits, gcry_mpi_t **ret_factors )
   gcry_mpi_t x;    /* the secret exponent */
   gcry_mpi_t h, e;  /* helper */
   unsigned qbits;
-  byte *rndbuf;
-
-  assert( nbits >= 512 && nbits <= 1024 );
+  unsigned char *rndbuf;
+
+  if ( nbits >= 512 && nbits <= 1024 )
+    qbits = 160;
+  else if ( nbits == 2048 )
+    qbits = 224;
+  else if ( nbits == 3072 )
+    qbits = 256;
+/*   else if ( nbits == 7680 ) */
+/*     qbits = 384; */
+/*   else if ( nbits == 15360 ) */
+/*     qbits = 512; */
+  else
+    return GPG_ERR_INV_VALUE;
 
-  qbits = 160;
   p = _gcry_generate_elg_prime( 1, nbits, qbits, NULL, ret_factors );
   /* get q out of factors */
   q = mpi_copy((*ret_factors)[0]);
@@ -263,6 +273,7 @@ generate( DSA_secret_key *sk, unsigned nbits, gcry_mpi_t **ret_factors )
 
   /* Now we can test our keys (this should never fail!). */
   test_keys( sk, qbits );
+  return 0;
 }
 
 
@@ -374,16 +385,20 @@ gcry_err_code_t
 _gcry_dsa_generate (int algo, unsigned nbits, unsigned long dummy,
                     gcry_mpi_t *skey, gcry_mpi_t **retfactors)
 {
+  gpg_err_code_t err;
   DSA_secret_key sk;
 
-  generate (&sk, nbits, retfactors);
-  skey[0] = sk.p;
-  skey[1] = sk.q;
-  skey[2] = sk.g;
-  skey[3] = sk.y;
-  skey[4] = sk.x;
+  err = generate (&sk, nbits, retfactors);
+  if (!err)
+    {
+      skey[0] = sk.p;
+      skey[1] = sk.q;
+      skey[2] = sk.g;
+      skey[3] = sk.y;
+      skey[4] = sk.x;
+    }
 
-  return GPG_ERR_NO_ERROR;
+  return err;
 }
 
 
index aafca6b..f90ec84 100644 (file)
@@ -210,14 +210,14 @@ esac
 
 
 case "${target}" in
-    *-openbsd* | *-netbsd*)
+    *-openbsd*)
         # FIXME: Are these the best flags for OpenBSD?
         NAME_OF_DEV_RANDOM="/dev/srandom"
         NAME_OF_DEV_URANDOM="/dev/urandom"
 #       DYNLINK_MOD_CFLAGS="-shared -rdynamic $CFLAGS_PIC -Wl,-Bshareable -Wl,-x"
         ;;
 
-    *-solaris* | *-irix* | *-dec-osf* )
+    *-solaris* | *-irix* | *-dec-osf* | *-netbsd* )
         NAME_OF_DEV_RANDOM="/dev/random"
         NAME_OF_DEV_URANDOM="/dev/random"
 #       DYNLINK_MOD_CFLAGS="-shared $CFLAGS_PIC"
index 856e2ad..e194bd4 100644 (file)
@@ -1763,7 +1763,7 @@ this is the hashed data is highly confidential.
 Turn the algorithm into a HMAC message authentication algorithm.  This
 does only work if just one algorithm is enabled for the handle and
 SHA-384 and SHA512 is not used.  Note that the function
-@code{gcry_md_setkey} must be used set the MAC key.  If you want CBC
+@code{gcry_md_setkey} must be used to set the MAC key.  If you want CBC
 message authentication codes based on a cipher, see @xref{Working with
 cipher handles}.
 
index a5eb712..bd86b5f 100644 (file)
@@ -7,6 +7,10 @@
        * Makefile.am (TESTS): Added keygrip.
        * keygrip.c: New.
 
+2005-09-19  Werner Koch  <wk@g10code.com>
+
+       * benchmark.c (dsa_bench): New.
+
 2005-08-19  Werner Koch  <wk@g10code.com>
 
        * hmac.c (main): Added all FIPS tests.
index 9516e82..04cfedc 100644 (file)
 #include <gcrypt.h>
 
 #define PGM "benchmark"
+
+static const char sample_private_dsa_key_1024[] =
+"(private-key\n"
+"  (dsa\n"
+"   (p #00A126202D592214C5A8F6016E2C3F4256052ACB1CB17D88E64B1293FAF08F5E4685"
+       "03E6F68366B326A56284370EB2103E92D8346A163E44A08FDC422AC8E9E44268557A"
+       "853539A6AF39353A59CE5E78FD98B57D0F3E3A7EBC8A256AC9A775BA59689F3004BF"
+       "C3035730C4C0C51626C5D7F5852637EC589BB29DAB46C161572E4B#)\n"
+"   (q #00DEB5A296421887179ECA1762884DE2AF8185AFC5#)\n"
+"   (g #3958B34AE7747194ECBD312F8FEE8CBE3918E94DF9FD11E2912E56318F33BDC38622"
+       "B18DDFF393074BCA8BAACF50DF27AEE529F3E8AEECE55C398DAB3A5E04C2EA142312"
+       "FACA2FE7F0A88884F8DAC3979EE67598F9A383B2A2325F035C796F352A5C3CDF2CB3"
+       "85AD24EC52A6E55247E1BB37D260F79E617D2A4446415B6AD79A#)\n"
+"   (y #519E9FE9AB0545A6724E74603B7B04E48DC1437E0284A11EA605A7BA8AB1CF354FD4"
+       "ECC93880AC293391C69B558AD84E7AAFA88F11D028CF3A378F241D6B056A90C588F6"
+       "66F68D27262B4DA84657D15057D371BCEC1F6504032507D5B881E45FC93A1B973155"
+       "D91C57219D090C3ACD75E7C2B9F1176A208AC03D6C12AC28A271#)\n"
+"   (x #4186F8A58C5DF46C5BCFC7006BEEBF05E93C0CA7#)\n"
+"))\n";
+
+static const char sample_public_dsa_key_1024[] =
+"(public-key\n"
+"  (dsa\n"
+"   (p #00A126202D592214C5A8F6016E2C3F4256052ACB1CB17D88E64B1293FAF08F5E4685"
+       "03E6F68366B326A56284370EB2103E92D8346A163E44A08FDC422AC8E9E44268557A"
+       "853539A6AF39353A59CE5E78FD98B57D0F3E3A7EBC8A256AC9A775BA59689F3004BF"
+       "C3035730C4C0C51626C5D7F5852637EC589BB29DAB46C161572E4B#)\n"
+"   (q #00DEB5A296421887179ECA1762884DE2AF8185AFC5#)\n"
+"   (g #3958B34AE7747194ECBD312F8FEE8CBE3918E94DF9FD11E2912E56318F33BDC38622"
+       "B18DDFF393074BCA8BAACF50DF27AEE529F3E8AEECE55C398DAB3A5E04C2EA142312"
+       "FACA2FE7F0A88884F8DAC3979EE67598F9A383B2A2325F035C796F352A5C3CDF2CB3"
+       "85AD24EC52A6E55247E1BB37D260F79E617D2A4446415B6AD79A#)\n"
+"   (y #519E9FE9AB0545A6724E74603B7B04E48DC1437E0284A11EA605A7BA8AB1CF354FD4"
+       "ECC93880AC293391C69B558AD84E7AAFA88F11D028CF3A378F241D6B056A90C588F6"
+       "66F68D27262B4DA84657D15057D371BCEC1F6504032507D5B881E45FC93A1B973155"
+       "D91C57219D090C3ACD75E7C2B9F1176A208AC03D6C12AC28A271#)\n"
+"))\n";
+
+
+static const char sample_private_dsa_key_2048[] =
+"(private-key\n"
+"  (dsa\n"
+"   (p #00B54636673962B64F7DC23C71ACEF6E7331796F607560B194DFCC0CA370E858A365"
+       "A413152FB6EB8C664BD171AC316FE5B381CD084D07377571599880A068EF1382D85C"
+       "308B4E9DEAC12D66DE5C4A826EBEB5ED94A62E7301E18927E890589A2F230272A150"
+       "C118BC3DC2965AE0D05BE4F65C6137B2BA7EDABB192C3070D202C10AA3F534574970"
+       "71454DB8A73DDB6511A5BA98EF1450FD90DE5BAAFC9FD3AC22EBEA612DD075BB7405"
+       "D56866D125E33982C046808F7CEBA8E5C0B9F19A6FE451461660A1CBA9EF68891179"
+       "0256A573D3B8F35A5C7A0C6C31F2DB90E25A26845252AD9E485EF2D339E7B5890CD4"
+       "2F9C9F315ED409171EC35CA04CC06B275577B3#)\n"
+"   (q #00DA67989167FDAC4AE3DF9247A716859A30C0CF9C5A6DBA01EABA3481#)\n"
+"   (g #48E35DA584A089D05142AA63603FDB00D131B07A0781E2D5A8F9614D2B33D3E40A78"
+       "98A9E10CDBB612CF093F95A3E10D09566726F2C12823836B2D9CD974BB695665F3B3"
+       "5D219A9724B87F380BD5207EDA0AE38C79E8F18122C3F76E4CEB0ABED3250914987F"
+       "B30D4B9E19C04C28A5D4F45560AF586F6A1B41751EAD90AE7F044F4E2A4A50C1F508"
+       "4FC202463F478F678B9A19392F0D2961C5391C546EF365368BB46410C9C1CEE96E9F"
+       "0C953570C2ED06328B11C90E86E57CAA7FA5ABAA278E22A4C8C08E16EE59F484EC44"
+       "2CF55535BAA2C6BEA8833A555372BEFE1E665D3C7DAEF58061D5136331EF4EB61BC3"
+       "6EE4425A553AF8885FEA15A88135BE133520#)\n"
+"   (y #66E0D1A69D663466F8FEF2B7C0878DAC93C36A2FB2C05E0306A53B926021D4B92A1C"
+       "2FA6860061E88E78CBBBA49B0E12700F07DBF86F72CEB2927EDAC0C7E3969C3A47BB"
+       "4E0AE93D8BB3313E93CC7A72DFEEE442EFBC81B3B2AEC9D8DCBE21220FB760201D79"
+       "328C41C773866587A44B6954767D022A88072900E964089D9B17133603056C985C4F"
+       "8A0B648F297F8D2C3CB43E4371DC6002B5B12CCC085BDB2CFC5074A0587566187EE3"
+       "E11A2A459BD94726248BB8D6CC62938E11E284C2C183576FBB51749EB238C4360923"
+       "79C08CE1C8CD77EB57404CE9B4744395ACF721487450BADE3220576F2F816248B0A7"
+       "14A264330AECCB24DE2A1107847B23490897#)\n"
+"   (x #477BD14676E22563C5ABA68025CEBA2A48D485F5B2D4AD4C0EBBD6D0#)\n"
+"))\n";
+
+
+static const char sample_public_dsa_key_2048[] =
+"(public-key\n"
+"  (dsa\n"
+"   (p #00B54636673962B64F7DC23C71ACEF6E7331796F607560B194DFCC0CA370E858A365"
+       "A413152FB6EB8C664BD171AC316FE5B381CD084D07377571599880A068EF1382D85C"
+       "308B4E9DEAC12D66DE5C4A826EBEB5ED94A62E7301E18927E890589A2F230272A150"
+       "C118BC3DC2965AE0D05BE4F65C6137B2BA7EDABB192C3070D202C10AA3F534574970"
+       "71454DB8A73DDB6511A5BA98EF1450FD90DE5BAAFC9FD3AC22EBEA612DD075BB7405"
+       "D56866D125E33982C046808F7CEBA8E5C0B9F19A6FE451461660A1CBA9EF68891179"
+       "0256A573D3B8F35A5C7A0C6C31F2DB90E25A26845252AD9E485EF2D339E7B5890CD4"
+       "2F9C9F315ED409171EC35CA04CC06B275577B3#)\n"
+"   (q #00DA67989167FDAC4AE3DF9247A716859A30C0CF9C5A6DBA01EABA3481#)\n"
+"   (g #48E35DA584A089D05142AA63603FDB00D131B07A0781E2D5A8F9614D2B33D3E40A78"
+       "98A9E10CDBB612CF093F95A3E10D09566726F2C12823836B2D9CD974BB695665F3B3"
+       "5D219A9724B87F380BD5207EDA0AE38C79E8F18122C3F76E4CEB0ABED3250914987F"
+       "B30D4B9E19C04C28A5D4F45560AF586F6A1B41751EAD90AE7F044F4E2A4A50C1F508"
+       "4FC202463F478F678B9A19392F0D2961C5391C546EF365368BB46410C9C1CEE96E9F"
+       "0C953570C2ED06328B11C90E86E57CAA7FA5ABAA278E22A4C8C08E16EE59F484EC44"
+       "2CF55535BAA2C6BEA8833A555372BEFE1E665D3C7DAEF58061D5136331EF4EB61BC3"
+       "6EE4425A553AF8885FEA15A88135BE133520#)\n"
+"   (y #66E0D1A69D663466F8FEF2B7C0878DAC93C36A2FB2C05E0306A53B926021D4B92A1C"
+       "2FA6860061E88E78CBBBA49B0E12700F07DBF86F72CEB2927EDAC0C7E3969C3A47BB"
+       "4E0AE93D8BB3313E93CC7A72DFEEE442EFBC81B3B2AEC9D8DCBE21220FB760201D79"
+       "328C41C773866587A44B6954767D022A88072900E964089D9B17133603056C985C4F"
+       "8A0B648F297F8D2C3CB43E4371DC6002B5B12CCC085BDB2CFC5074A0587566187EE3"
+       "E11A2A459BD94726248BB8D6CC62938E11E284C2C183576FBB51749EB238C4360923"
+       "79C08CE1C8CD77EB57404CE9B4744395ACF721487450BADE3220576F2F816248B0A7"
+       "14A264330AECCB24DE2A1107847B23490897#)\n"
+"))\n";
+
+
+static const char sample_private_dsa_key_3072[] =
+"(private-key\n"
+"  (dsa\n"
+"   (p #00BA73E148AEA5E8B64878AF5BE712B8302B9671C5F3EEB7722A9D0D9868D048C938"
+       "877C91C335C7819292E69C7D34264F1578E32EC2DA8408DF75D0EB76E0D3030B84B5"
+       "62D8EF93AB53BAB6B8A5DE464F5CA87AEA43BDCF0FB0B7815AA3114CFC84FD916A83"
+       "B3D5FD78390189332232E9D037D215313FD002FF46C048B66703F87FAE092AAA0988"
+       "AC745336EBE672A01DEDBD52395783579B67CF3AE1D6F1602CCCB12154FA0E00AE46"
+       "0D9B289CF709194625BCB919B11038DEFC50ADBBA20C3F320078E4E9529B4F6848E2"
+       "AB5E6278DB961FE226F2EEBD201E071C48C5BEF98B4D9BEE42C1C7102D893EBF8902"
+       "D7A91266340AFD6CE1D09E52282FFF5B97EAFA3886A3FCF84FF76D1E06538D0D8E60"
+       "B3332145785E07D29A5965382DE3470D1D888447FA9C00A2373378FC3FA7B9F7D17E"
+       "95A6A5AE1397BE46D976EF2C96E89913AC4A09351CA661BF6F67E30407DA846946C7"
+       "62D9BAA6B77825097D3E7B886456BB32E3E74516BF3FD93D71B257AA8F723E01CE33"
+       "8015353D3778B02B892AF7#)\n"
+"   (q #00BFF3F3CC18FA018A5B8155A8695E1E4939660D5E4759322C39D50F3B93E5F68B#)\n"
+"   (g #6CCFD8219F5FCE8EF2BEF3262929787140847E38674B1EF8DB20255E212CB6330EC4"
+       "DFE8A26AB7ECC5760DEB9BBF59A2B2821D510F1868172222867558B8D204E889C474"
+       "7CA30FBF9D8CF41AE5D5BD845174641101593849FF333E6C93A6550931B2B9D56B98"
+       "9CAB01729D9D736FA6D24A74D2DDE1E9E648D141473E443DD6BBF0B3CAB64F9FE4FC"
+       "134B2EB57437789F75C744DF1FA67FA8A64603E5441BC7ECE29E00BDF262BDC81E8C"
+       "7330A18A412DE38E7546D342B89A0AF675A89E6BEF00540EB107A2FE74EA402B0D89"
+       "F5C02918DEEEAF8B8737AC866B09B50810AB8D8668834A1B9E1E53866E2B0A926FAB"
+       "120A0CDE5B3715FFFE6ACD1AB73588DCC1EC4CE9392FE57F8D1D35811200CB07A0E6"
+       "374E2C4B0AEB7E3D077B8545C0E438DCC0F1AE81E186930E99EBC5B91B77E92803E0"
+       "21602887851A4FFDB3A7896AC655A0901218C121C5CBB0931E7D5EAC243F37711B5F"
+       "D5A62B1B38A83F03D8F6703D8B98DF367FC8A76990335F62173A5391836F0F2413EC"
+       "4997AF9EB55C6660B01A#)\n"
+"   (y #2320B22434C5DB832B4EC267CC52E78DD5CCFA911E8F0804E7E7F32B186B2D4167AE"
+       "4AA6869822E76400492D6A193B0535322C72B0B7AA4A87E33044FDC84BE24C64A053"
+       "A37655EE9EABDCDC1FDF63F3F1C677CEB41595DF7DEFE9178D85A3D621B4E4775492"
+       "8C0A58D2458D06F9562E4DE2FE6129A64063A99E88E54485B97484A28188C4D33F15"
+       "DDC903B6CEA0135E3E3D27B4EA39319696305CE93D7BA7BE00367DBE3AAF43491E71"
+       "CBF254744A5567F5D70090D6139E0C990239627B3A1C5B20B6F9F6374B8D8D8A8997"
+       "437265BE1E3B4810D4B09254400DE287A0DFFBAEF339E48D422B1D41A37E642BC026"
+       "73314701C8FA9792845C129351A87A945A03E6C895860E51D6FB8B7340A94D1A8A7B"
+       "FA85AC83B4B14E73AB86CB96C236C8BFB0978B61B2367A7FE4F7891070F56C78D5DD"
+       "F5576BFE5BE4F333A4E2664E79528B3294907AADD63F4F2E7AA8147B928D8CD69765"
+       "3DB98C4297CB678046ED55C0DBE60BF7142C594603E4D705DC3D17270F9F086EC561"
+       "2703D518D8D49FF0EBE6#)\n"
+"   (x #00A9FFFC88E67D6F7B810E291C050BAFEA7FC4A75E8D2F16CFED3416FD77607232#)\n"
+"))\n";
+
+static const char sample_public_dsa_key_3072[] =
+"(public-key\n"
+"  (dsa\n"
+"   (p #00BA73E148AEA5E8B64878AF5BE712B8302B9671C5F3EEB7722A9D0D9868D048C938"
+       "877C91C335C7819292E69C7D34264F1578E32EC2DA8408DF75D0EB76E0D3030B84B5"
+       "62D8EF93AB53BAB6B8A5DE464F5CA87AEA43BDCF0FB0B7815AA3114CFC84FD916A83"
+       "B3D5FD78390189332232E9D037D215313FD002FF46C048B66703F87FAE092AAA0988"
+       "AC745336EBE672A01DEDBD52395783579B67CF3AE1D6F1602CCCB12154FA0E00AE46"
+       "0D9B289CF709194625BCB919B11038DEFC50ADBBA20C3F320078E4E9529B4F6848E2"
+       "AB5E6278DB961FE226F2EEBD201E071C48C5BEF98B4D9BEE42C1C7102D893EBF8902"
+       "D7A91266340AFD6CE1D09E52282FFF5B97EAFA3886A3FCF84FF76D1E06538D0D8E60"
+       "B3332145785E07D29A5965382DE3470D1D888447FA9C00A2373378FC3FA7B9F7D17E"
+       "95A6A5AE1397BE46D976EF2C96E89913AC4A09351CA661BF6F67E30407DA846946C7"
+       "62D9BAA6B77825097D3E7B886456BB32E3E74516BF3FD93D71B257AA8F723E01CE33"
+       "8015353D3778B02B892AF7#)\n"
+"   (q #00BFF3F3CC18FA018A5B8155A8695E1E4939660D5E4759322C39D50F3B93E5F68B#)\n"
+"   (g #6CCFD8219F5FCE8EF2BEF3262929787140847E38674B1EF8DB20255E212CB6330EC4"
+       "DFE8A26AB7ECC5760DEB9BBF59A2B2821D510F1868172222867558B8D204E889C474"
+       "7CA30FBF9D8CF41AE5D5BD845174641101593849FF333E6C93A6550931B2B9D56B98"
+       "9CAB01729D9D736FA6D24A74D2DDE1E9E648D141473E443DD6BBF0B3CAB64F9FE4FC"
+       "134B2EB57437789F75C744DF1FA67FA8A64603E5441BC7ECE29E00BDF262BDC81E8C"
+       "7330A18A412DE38E7546D342B89A0AF675A89E6BEF00540EB107A2FE74EA402B0D89"
+       "F5C02918DEEEAF8B8737AC866B09B50810AB8D8668834A1B9E1E53866E2B0A926FAB"
+       "120A0CDE5B3715FFFE6ACD1AB73588DCC1EC4CE9392FE57F8D1D35811200CB07A0E6"
+       "374E2C4B0AEB7E3D077B8545C0E438DCC0F1AE81E186930E99EBC5B91B77E92803E0"
+       "21602887851A4FFDB3A7896AC655A0901218C121C5CBB0931E7D5EAC243F37711B5F"
+       "D5A62B1B38A83F03D8F6703D8B98DF367FC8A76990335F62173A5391836F0F2413EC"
+       "4997AF9EB55C6660B01A#)\n"
+"   (y #2320B22434C5DB832B4EC267CC52E78DD5CCFA911E8F0804E7E7F32B186B2D4167AE"
+       "4AA6869822E76400492D6A193B0535322C72B0B7AA4A87E33044FDC84BE24C64A053"
+       "A37655EE9EABDCDC1FDF63F3F1C677CEB41595DF7DEFE9178D85A3D621B4E4775492"
+       "8C0A58D2458D06F9562E4DE2FE6129A64063A99E88E54485B97484A28188C4D33F15"
+       "DDC903B6CEA0135E3E3D27B4EA39319696305CE93D7BA7BE00367DBE3AAF43491E71"
+       "CBF254744A5567F5D70090D6139E0C990239627B3A1C5B20B6F9F6374B8D8D8A8997"
+       "437265BE1E3B4810D4B09254400DE287A0DFFBAEF339E48D422B1D41A37E642BC026"
+       "73314701C8FA9792845C129351A87A945A03E6C895860E51D6FB8B7340A94D1A8A7B"
+       "FA85AC83B4B14E73AB86CB96C236C8BFB0978B61B2367A7FE4F7891070F56C78D5DD"
+       "F5576BFE5BE4F333A4E2664E79528B3294907AADD63F4F2E7AA8147B928D8CD69765"
+       "3DB98C4297CB678046ED55C0DBE60BF7142C594603E4D705DC3D17270F9F086EC561"
+       "2703D518D8D49FF0EBE6#)\n"
+"))\n";
+
+
+#define DIM(v)              (sizeof(v)/sizeof((v)[0]))
+#define DIMof(type,member)   DIM(((type *)0)->member)
 #define BUG() do {fprintf ( stderr, "Ooops at %s:%d\n", __FILE__ , __LINE__ );\
                  exit(2);} while(0)
 
@@ -313,6 +503,105 @@ cipher_bench ( const char *algoname )
 }
 
 
+
+static void
+dsa_bench (void)
+{
+  gpg_error_t err;
+  gcry_sexp_t pub_key[3], sec_key[3];
+  int p_sizes[3] = { 1024, 2048, 3072 };
+  int q_sizes[3] = { 160, 224, 256 };
+  gcry_sexp_t data;
+  gcry_sexp_t sig;
+  int i, j;
+
+  err = gcry_sexp_sscan (pub_key+0, NULL, sample_public_dsa_key_1024,
+                         strlen (sample_public_dsa_key_1024));
+  if (!err)
+    err = gcry_sexp_sscan (sec_key+0, NULL, sample_private_dsa_key_1024,
+                           strlen (sample_private_dsa_key_1024));
+  if (!err)
+    err = gcry_sexp_sscan (pub_key+1, NULL, sample_public_dsa_key_2048,
+                           strlen (sample_public_dsa_key_2048));
+  if (!err)
+    err = gcry_sexp_sscan (sec_key+1, NULL, sample_private_dsa_key_2048,
+                           strlen (sample_private_dsa_key_2048));
+  if (!err)
+    err = gcry_sexp_sscan (pub_key+2, NULL, sample_public_dsa_key_3072,
+                           strlen (sample_public_dsa_key_3072));
+  if (!err)
+    err = gcry_sexp_sscan (sec_key+2, NULL, sample_private_dsa_key_3072,
+                           strlen (sample_private_dsa_key_3072));
+  if (err)
+    {
+      fprintf (stderr, PGM ": converting sample keys failed: %s\n",
+               gcry_strerror (err));
+      exit (1);
+    }
+
+
+  fputs ("DSA 100 times    sign  verify\n"
+         "-----------------------------\n", stdout);
+  for (i=0; i < DIM (q_sizes); i++)
+    {
+      gcry_mpi_t x;
+
+      x = gcry_mpi_new (q_sizes[i]);
+      gcry_mpi_randomize (x, q_sizes[i], GCRY_WEAK_RANDOM);
+      err = gcry_sexp_build (&data, NULL, "(data (flags raw) (value %m))", x);
+      gcry_mpi_release (x);
+      if (err)
+        {
+          fprintf (stderr, PGM ": converting data failed: %s\n",
+                   gcry_strerror (err));
+          exit (1);
+        }
+
+      printf ("DSA %d/%d ", p_sizes[i], q_sizes[i]);
+      start_timer ();
+      for (j=0; j < 100; j++)
+        {
+          err = gcry_pk_sign (&sig, data, sec_key[i]);
+          if (err)
+            {
+              putchar ('\n');
+              fprintf (stderr, PGM ": signing failed: %s\n",
+                       gpg_strerror (err));
+              exit (1);
+            }
+        }
+      stop_timer ();
+      printf (" %s", elapsed_time ());
+
+      start_timer ();
+      for (j=0; j < 100; j++)
+        {
+          err = gcry_pk_verify (sig, data, pub_key[i]);
+          if (err)
+            {
+              putchar ('\n');
+              fprintf (stderr, PGM ": verify failed: %s\n",
+                       gpg_strerror (err));
+              exit (1);
+            }
+        }
+      stop_timer ();
+      printf (" %s\n", elapsed_time ());
+
+      gcry_sexp_release (sig);
+      gcry_sexp_release (data);
+    }
+
+
+  for (i=0; i < DIM (q_sizes); i++)
+    {
+      gcry_sexp_release (sec_key[i]);
+      gcry_sexp_release (pub_key[i]);
+    }
+}
+
+
+
 static void
 do_powm ( const char *n_str, const char *e_str, const char *m_str)
 {
@@ -382,6 +671,14 @@ main( int argc, char **argv )
   if (argc)
     { argc--; argv++; }
 
+  gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
+  if (!gcry_check_version (GCRYPT_VERSION))
+    {
+      fprintf (stderr, PGM ": version mismatch\n");
+      exit (1);
+    }
+  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
+
   if ( !argc )
     {
       md_bench (NULL);
@@ -393,7 +690,8 @@ main( int argc, char **argv )
       random_bench ();
     }
   else if ( !strcmp (*argv, "--help"))
-     fputs ("usage: benchmark [md|cipher|random|mpi [algonames]]\n", stdout);
+     fputs ("usage: benchmark [md|cipher|random|mpi|dsa [algonames]]\n",
+            stdout);
   else if ( !strcmp (*argv, "random"))
     {
       random_bench ();
@@ -418,6 +716,10 @@ main( int argc, char **argv )
     {
         mpi_bench ();
     }
+  else if ( !strcmp (*argv, "dsa"))
+    {
+        dsa_bench ();
+    }
   else
     {
       fprintf (stderr, PGM ": bad arguments\n");
index 6a4e015..d1d01fd 100644 (file)
@@ -124,6 +124,28 @@ check_rsa_keys (void)
   int rc;
 
   if (verbose)
+    fprintf (stderr, "creating 2048 bit DSA key using old interface\n");
+  rc = gcry_sexp_new (&keyparm, 
+                      "(genkey\n"
+                      " (dsa\n"
+                      "  (nbits 4:2048)\n"
+                      " ))", 0, 1);
+  if (rc)
+    die ("error creating S-expression: %s\n", gpg_strerror (rc));
+  rc = gcry_pk_genkey (&key, keyparm);
+  gcry_sexp_release (keyparm);
+  if (rc)
+    die ("error generating DSA key: %s\n", gpg_strerror (rc));
+  {
+    char buffer[20000];
+    gcry_sexp_sprint (key, GCRYSEXP_FMT_ADVANCED, buffer, sizeof buffer);
+    printf ("=============================\n%s\n"
+            "=============================\n", buffer);
+  }
+  gcry_sexp_release (key);
+  exit (0);
+
+  if (verbose)
     fprintf (stderr, "creating 1024 bit RSA key using old interface\n");
   rc = gcry_sexp_new (&keyparm, 
                       "(genkey\n"
@@ -140,6 +162,7 @@ check_rsa_keys (void)
   check_generated_rsa_key (key, 65537);
   gcry_sexp_release (key);
 
+
   if (verbose)
     fprintf (stderr, "creating 512 bit RSA key with e=257\n");
   rc = gcry_sexp_new (&keyparm,