[svn] gcry - r1307 - in trunk: cipher src tests

svn author wk cvs at cvs.gnupg.org
Wed Aug 27 12:10:48 CEST 2008


Author: wk
Date: 2008-08-27 12:10:47 +0200 (Wed, 27 Aug 2008)
New Revision: 1307

Modified:
   trunk/cipher/md.c
   trunk/src/ChangeLog
   trunk/src/Makefile.am
   trunk/src/fips.c
   trunk/src/g10lib.h
   trunk/src/global.c
   trunk/tests/ChangeLog
   trunk/tests/basic.c
Log:
Allow getting out of the FIPS error state by running a self-test.


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2008-08-26 11:13:57 UTC (rev 1306)
+++ trunk/src/ChangeLog	2008-08-27 10:10:47 UTC (rev 1307)
@@ -1,3 +1,11 @@
+2008-08-27  Werner Koch  <wk at g10code.com>
+
+	* global.c (_gcry_vcontrol): Allow running selftests from error
+	state.
+	* fips.c (_gcry_fips_test_error_or_operational): New.
+	(fips_new_state): Allow transtion from error into selftest.
+	Disallow error to init.
+
 2008-08-26  Werner Koch  <wk at g10code.com>
 
 	* fips.c (fips_new_state): Print state transitions only at

Modified: trunk/tests/ChangeLog
===================================================================
--- trunk/tests/ChangeLog	2008-08-26 11:13:57 UTC (rev 1306)
+++ trunk/tests/ChangeLog	2008-08-27 10:10:47 UTC (rev 1307)
@@ -1,3 +1,7 @@
+2008-08-27  Werner Koch  <wk at g10code.com>
+
+	* basic.c (main): Extended FIPS self-test test.
+
 2008-08-26  Werner Koch  <wk at g10code.com>
 
 	* basic.c (get_keys_new): Use transient-key flag. 

Modified: trunk/cipher/md.c
===================================================================
--- trunk/cipher/md.c	2008-08-26 11:13:57 UTC (rev 1306)
+++ trunk/cipher/md.c	2008-08-27 10:10:47 UTC (rev 1307)
@@ -1011,7 +1011,7 @@
   if (r && r->next)
     {
       fips_signal_error ("possible usage error");
-      log_error ("WARNING: more than algorithm in md_get_algo()\n");
+      log_error ("WARNING: more than one algorithm in md_get_algo()\n");
     }
   return r ? r->module->mod_id : 0;
 }

Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	2008-08-26 11:13:57 UTC (rev 1306)
+++ trunk/src/Makefile.am	2008-08-27 10:10:47 UTC (rev 1307)
@@ -122,9 +122,9 @@
 
 uninstall-local: uninstall-def-file
 
-# FIXME: We ned to figure out how to gte the actual name (parsing
+# FIXME: We need to figure out how to get the actual name (parsing
 # libgcrypt.la?) and how to create the hmac file already at link time
-# so that it can be used without first installing.
+# so that it can be used without installing libgcrypt first.
 #install-exec-hook:
 #	./hmac256 --binary "What am I, a doctor or a moonshuttle conductor?" \
 #           $(DESTDIR)$(libdir)/libgcrypt.so.11.5.0 \

Modified: trunk/src/fips.c
===================================================================
--- trunk/src/fips.c	2008-08-26 11:13:57 UTC (rev 1306)
+++ trunk/src/fips.c	2008-08-27 10:10:47 UTC (rev 1307)
@@ -289,6 +289,26 @@
 }
 
 
+/* This is a test on whether the library is in the error or
+   operational state. */
+int
+_gcry_fips_test_error_or_operational (void)
+{
+  int result;
+
+  if (!fips_mode ())
+    result = 1;
+  else
+    {
+      lock_fsm ();
+      result = (current_state == STATE_OPERATIONAL
+                || current_state == STATE_ERROR);
+      unlock_fsm ();
+    }
+  return result;
+}
+
+
 static void
 reporter (const char *domain, int algo, const char *what, const char *errtxt)
 {
@@ -604,7 +624,7 @@
     case STATE_ERROR:
       if (new_state == STATE_SHUTDOWN
           || new_state == STATE_FATALERROR
-          || new_state == STATE_INIT)
+          || new_state == STATE_SELFTEST)
         ok = 1;
       break;
       

Modified: trunk/src/g10lib.h
===================================================================
--- trunk/src/g10lib.h	2008-08-26 11:13:57 UTC (rev 1306)
+++ trunk/src/g10lib.h	2008-08-27 10:10:47 UTC (rev 1307)
@@ -314,6 +314,7 @@
 #define fips_not_operational()  (GCRY_GPG_ERR_NOT_OPERATIONAL)
 
 int _gcry_fips_test_operational (void);
+int _gcry_fips_test_error_or_operational (void);
 
 void _gcry_fips_run_selftests (void);
 

Modified: trunk/src/global.c
===================================================================
--- trunk/src/global.c	2008-08-26 11:13:57 UTC (rev 1306)
+++ trunk/src/global.c	2008-08-27 10:10:47 UTC (rev 1307)
@@ -469,7 +469,7 @@
           /* Already initialized.  If we are already operational we
              run a selftest.  If not we use the is_operational call to
              force us into operational state if possible.  */
-          if (_gcry_fips_test_operational ())
+          if (_gcry_fips_test_error_or_operational ())
             _gcry_fips_run_selftests ();
           if (_gcry_fips_is_operational ())
             err = GPG_ERR_GENERAL; /* Used as TRUE value */

Modified: trunk/tests/basic.c
===================================================================
--- trunk/tests/basic.c	2008-08-26 11:13:57 UTC (rev 1306)
+++ trunk/tests/basic.c	2008-08-27 10:10:47 UTC (rev 1307)
@@ -2042,6 +2042,7 @@
 int
 main (int argc, char **argv)
 { 
+  gpg_error_t err;
   int last_argc = -1;
   int debug = 0;
   int use_fips = 0;
@@ -2105,10 +2106,50 @@
   check_hmac ();
   check_pubkey ();
 
-  /* If we are in fips mode, trigger a selftest.  */
+  /* If we are in fips mode do some more tests. */
   if (in_fips_mode)
-    gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
+    {
+      gcry_md_hd_t md;
 
+      /* First trigger a self-test.  */
+      gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
+      if (!gcry_control (GCRYCTL_OPERATIONAL_P, 0))
+        fail ("not in operational state after self-test\n");
+      
+      /* Get us into the error state.  */
+      err = gcry_md_open (&md, GCRY_MD_SHA1, 0);
+      if (err)
+        fail ("failed to open SHA-1 hash context: %s\n", gpg_strerror (err));
+      else
+        {
+          err = gcry_md_enable (md, GCRY_MD_SHA256);
+          if (err)
+            fail ("failed to add SHA-256 hash context: %s\n",
+                  gpg_strerror (err));
+          else
+            {
+              /* gcry_md_get_algo is only defined for a context with
+                 just one digest algorithm.  With our setup it should
+                 put the oibrary intoerror state.  */
+              gcry_md_get_algo (md);
+              gcry_md_close (md);
+              if (gcry_control (GCRYCTL_OPERATIONAL_P, 0))
+                fail ("expected error state but still in operational state\n");
+              else
+                {
+                  /* Now run a self-test and to get back into
+                     operational state.  */
+                  gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
+                  if (!gcry_control (GCRYCTL_OPERATIONAL_P, 0))
+                    fail ("did not reach operational after error "
+                          "and self-test\n");
+                }
+            }
+        }
+      
+    }
+  
+
   if (verbose)
     fprintf (stderr, "\nAll tests completed. Errors: %i\n", error_count);
 




More information about the Gnupg-commits mailing list