[svn] gcry - r1105 - trunk/tests

svn author mo cvs at cvs.gnupg.org
Thu Sep 15 18:24:48 CEST 2005


Author: mo
Date: 2005-09-15 18:24:48 +0200 (Thu, 15 Sep 2005)
New Revision: 1105

Added:
   trunk/tests/keygrip.c
Modified:
   trunk/tests/ChangeLog
   trunk/tests/Makefile.am
   trunk/tests/basic.c
Log:
2005-09-15  Moritz Schulte  <moritz at g10code.com>

	* Makefile.am (TESTS): Added keygrip.
	* keygrip.c: New.


Modified: trunk/tests/ChangeLog
===================================================================
--- trunk/tests/ChangeLog	2005-09-14 18:56:36 UTC (rev 1104)
+++ trunk/tests/ChangeLog	2005-09-15 16:24:48 UTC (rev 1105)
@@ -1,3 +1,8 @@
+2005-09-15  Moritz Schulte  <moritz at g10code.com>
+
+	* Makefile.am (TESTS): Added keygrip.
+	* keygrip.c: New.
+
 2005-08-19  Werner Koch  <wk at g10code.com>
 
 	* hmac.c (main): Added all FIPS tests.

Modified: trunk/tests/Makefile.am
===================================================================
--- trunk/tests/Makefile.am	2005-09-14 18:56:36 UTC (rev 1104)
+++ trunk/tests/Makefile.am	2005-09-15 16:24:48 UTC (rev 1105)
@@ -19,7 +19,7 @@
 ## Process this file with automake to produce Makefile.in
 
 TESTS = prime register ac ac-schemes ac-data basic \
-        tsexp keygen pubkey benchmark pkbench hmac
+        tsexp keygen pubkey benchmark pkbench hmac keygrip
 
 INCLUDES = -I$(top_srcdir)/src
 LDADD = ../src/libgcrypt.la

Modified: trunk/tests/basic.c
===================================================================
--- trunk/tests/basic.c	2005-09-14 18:56:36 UTC (rev 1104)
+++ trunk/tests/basic.c	2005-09-15 16:24:48 UTC (rev 1105)
@@ -850,6 +850,8 @@
 	GPG_ERR_DIGEST_ALGO },
       {	"(data\n (flags )\n" " (value #11223344556677889900AA#))\n",
 	0 },
+      {	"(data\n (flags )\n" " (value #0090223344556677889900AA#))\n",
+	0 },
       { "(data\n (flags raw)\n" " (value #11223344556677889900AA#))\n",
 	0 },
       {	"(data\n (flags pkcs1)\n"

Added: trunk/tests/keygrip.c
===================================================================
--- trunk/tests/keygrip.c	2005-09-14 18:56:36 UTC (rev 1104)
+++ trunk/tests/keygrip.c	2005-09-15 16:24:48 UTC (rev 1105)
@@ -0,0 +1,139 @@
+/* keygrip.c - verifies that keygrips are calculated as expected
+ *	Copyright (C) 2005 Free Software Foundation, Inc.
+ *
+ * This file is part of Libgcrypt.
+ *
+ * Libgcrypt is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * Libgcrypt is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <assert.h>
+
+#include "../src/gcrypt.h"
+
+static int verbose;
+
+
+
+static void
+die (const char *format, ...)
+{
+  va_list arg_ptr;
+
+  va_start (arg_ptr, format);
+  vfprintf (stderr, format, arg_ptr);
+  va_end (arg_ptr);
+  exit (1);
+}
+
+
+
+static struct
+{
+  const char *key;
+  const unsigned char grip[20];
+} key_grips[] =
+  {
+    {
+      "(private-key"
+      " (rsa"
+      "  (n #00B6B509596A9ECABC939212F891E656A626BA07DA8521A9CAD4C08E640C04052FBB87F424EF1A0275A48A9299AC9DB69ABE3D0124E6C756B1F7DFB9B842D6251AEA6EE85390495CADA73D671537FCE5850A932F32BAB60AB1AC1F852C1F83C625E7A7D70CDA9EF16D5C8E47739D77DF59261ABE8454807FF441E143FBD37F8545#)"
+      "  (e #010001#)"
+      "  (d #077AD3DE284245F4806A1B82B79E616FBDE821C82D691A65665E57B5FAD3F34E67F401E7BD2E28699E89D9C496CF821945AE83AC7A1231176A196BA6027E77D85789055D50404A7A2A95B1512F91F190BBAEF730ED550D227D512F89C0CDB31AC06FA9A19503DDF6B66D0B42B9691BFD6140EC1720FFC48AE00C34796DC899E5#)"
+      "  (p #00D586C78E5F1B4BF2E7CD7A04CA091911706F19788B93E44EE20AAF462E8363E98A72253ED845CCBF2481BB351E8557C85BCFFF0DABDBFF8E26A79A0938096F27#)"
+      "  (q #00DB0CDF60F26F2A296C88D6BF9F8E5BE45C0DDD713C96CC73EBCB48B061740943F21D2A93D6E42A7211E7F02A95DCED6C390A67AD21ECF739AE8A0CA46FF2EBB3#)"
+      "  (u #33149195F16912DB20A48D020DBC3B9E3881B39D722BF79378F6340F43148A6E9FC5F53E2853B7387BA4443BA53A52FCA8173DE6E85B42F9783D4A7817D0680B#)))",
+      "\x32\xCF\xFA\x85\xB1\x79\x1F\xBB\x26\x14\xE9\x1A\xFD\xF3\xAF\xE3\x32\x08\x2E\x25"
+    },
+    {
+      " (public-key"
+      " (dsa"
+      "  (p #0084E4C626E16005770BD9509ABF7354492E85B8C0060EFAAAEC617F725B592FAA59DF5460575F41022776A9718CE62EDD542AB73C7720869EBDBC834D174ADCD7136827DF51E2613545A25CA573BC502A61B809000B6E35F5EB7FD6F18C35678C23EA1C3638FB9CFDBA2800EE1B62F41A4479DE824F2834666FBF8DC5B53C2617#)"
+      "  (q #00B0E6F710051002A9F425D98A677B18E0E5B038AB#)"
+      "  (g #44370CEE0FE8609994183DBFEBA7EEA97D466838BCF65EFF506E35616DA93FA4E572A2F08886B74977BC00CA8CD3DBEA7AEB7DB8CBB180E6975E0D2CA76E023E6DE9F8CCD8826EBA2F72B8516532F6001DEFFAE76AA5E59E0FA33DBA3999B4E92D1703098CDEDCC416CF008801964084CDE1980132B2B78CB4CE9C15A559528B#)"
+      "  (y #3D5DD14AFA2BF24A791E285B90232213D0E3BA74AB1109E768AED19639A322F84BB7D959E2BA92EF73DE4C7F381AA9F4053CFA3CD4527EF9043E304E5B95ED0A3A5A9D590AA641C13DB2B6E32B9B964A6A2C730DD3EA7C8E13F7A140AFF1A91CE375E9B9B960384779DC4EA180FA1F827C52288F366C0770A220F50D6D8FD6F6#)))",
+      "\x04\xA3\x4F\xA0\x2B\x03\x94\xD7\x32\xAD\xD5\x9B\x50\xAF\xDB\x5D\x57\x22\xA6\x10"
+      
+    },
+    {
+      "(private-key"
+      " (dsa"
+      "  (p #0084E4C626E16005770BD9509ABF7354492E85B8C0060EFAAAEC617F725B592FAA59DF5460575F41022776A9718CE62EDD542AB73C7720869EBDBC834D174ADCD7136827DF51E2613545A25CA573BC502A61B809000B6E35F5EB7FD6F18C35678C23EA1C3638FB9CFDBA2800EE1B62F41A4479DE824F2834666FBF8DC5B53C2617#)"
+      "  (q #00B0E6F710051002A9F425D98A677B18E0E5B038AB#)"
+      "  (g #44370CEE0FE8609994183DBFEBA7EEA97D466838BCF65EFF506E35616DA93FA4E572A2F08886B74977BC00CA8CD3DBEA7AEB7DB8CBB180E6975E0D2CA76E023E6DE9F8CCD8826EBA2F72B8516532F6001DEFFAE76AA5E59E0FA33DBA3999B4E92D1703098CDEDCC416CF008801964084CDE1980132B2B78CB4CE9C15A559528B#)"
+      "  (y #3D5DD14AFA2BF24A791E285B90232213D0E3BA74AB1109E768AED19639A322F84BB7D959E2BA92EF73DE4C7F381AA9F4053CFA3CD4527EF9043E304E5B95ED0A3A5A9D590AA641C13DB2B6E32B9B964A6A2C730DD3EA7C8E13F7A140AFF1A91CE375E9B9B960384779DC4EA180FA1F827C52288F366C0770A220F50D6D8FD6F6#)"
+      "  (x #0087F9E91BFBCC1163DE71ED86D557708E32F8ADDE#)))",
+      "\x04\xA3\x4F\xA0\x2B\x03\x94\xD7\x32\xAD\xD5\x9B\x50\xAF\xDB\x5D\x57\x22\xA6\x10"
+    }
+  };
+
+static void
+check (void)
+{
+  unsigned char buf[20];
+  unsigned char *ret;
+  gcry_error_t err;
+  gcry_sexp_t sexp;
+  unsigned int i;
+
+  for (i = 0; i < (sizeof (key_grips) / sizeof (*key_grips)); i++)
+    {
+      err = gcry_sexp_sscan (&sexp, NULL, key_grips[i].key,
+			     strlen (key_grips[i].key));
+      assert (! err);
+      ret = gcry_pk_get_keygrip (sexp, buf);
+      assert (ret);
+      assert (! memcmp (key_grips[i].grip, buf, sizeof (buf)));
+      gcry_sexp_release (sexp);
+    }
+}
+
+
+
+static void
+progress_handler (void *cb_data, const char *what, int printchar,
+		  int current, int total)
+{
+  putchar (printchar);
+}
+
+int
+main (int argc, char **argv)
+{
+  int debug = 0;
+
+  if (argc > 1 && !strcmp (argv[1], "--verbose"))
+    verbose = 1;
+  else if (argc > 1 && !strcmp (argv[1], "--debug"))
+    verbose = debug = 1;
+
+  if (!gcry_check_version (GCRYPT_VERSION))
+    die ("version mismatch\n");
+
+  gcry_set_progress_handler (progress_handler, NULL);
+  
+  gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
+
+  check ();
+
+  return 0;
+}




More information about the Gnupg-commits mailing list