Blame SOURCES/libgcrypt-1.5.3-fips-ctor.patch

241384
diff -up libgcrypt-1.5.3/cipher/md.c.fips-ctor libgcrypt-1.5.3/cipher/md.c
241384
--- libgcrypt-1.5.3/cipher/md.c.fips-ctor	2013-07-25 11:10:03.000000000 +0200
241384
+++ libgcrypt-1.5.3/cipher/md.c	2014-12-12 15:32:35.464515238 +0100
241384
@@ -570,11 +570,8 @@ md_enable (gcry_md_hd_t hd, int algorith
241384
 
241384
   if (!err && algorithm == GCRY_MD_MD5 && fips_mode ())
241384
     {
241384
-      _gcry_inactivate_fips_mode ("MD5 used");
241384
       if (_gcry_enforced_fips_mode () )
241384
         {
241384
-          /* We should never get to here because we do not register
241384
-             MD5 in enforced fips mode. But better throw an error.  */
241384
           err = GPG_ERR_DIGEST_ALGO;
241384
         }
241384
     }
241384
diff -up libgcrypt-1.5.3/src/global.c.fips-ctor libgcrypt-1.5.3/src/global.c
241384
--- libgcrypt-1.5.3/src/global.c.fips-ctor	2014-12-12 15:32:35.463515215 +0100
241384
+++ libgcrypt-1.5.3/src/global.c	2014-12-12 16:46:33.424883301 +0100
241384
@@ -140,6 +140,34 @@ global_init (void)
241384
 }
241384
 
241384
 
241384
+#ifndef FIPS_MODULE_PATH
241384
+#define FIPS_MODULE_PATH "/etc/system-fips"
241384
+#endif
241384
+
241384
+void __attribute__ ((constructor)) _gcry_global_constructor (void)
241384
+{
241384
+  int rv;
241384
+
241384
+  rv = access (FIPS_MODULE_PATH, F_OK);
241384
+  if (rv < 0 && errno != ENOENT)
241384
+    rv = 0;
241384
+
241384
+  if (!rv)
241384
+    {
241384
+      int no_secmem_save;
241384
+
241384
+      /* it should be always 0 at this point but let's keep on the safe side */
241384
+      no_secmem_save = no_secure_memory;
241384
+      no_secure_memory = 1;
241384
+      /* force selftests */
241384
+      global_init ();
241384
+      if (fips_mode ())
241384
+         _gcry_random_initialize (1);
241384
+      _gcry_fips_run_selftests (0);
241384
+      no_secure_memory = no_secmem_save;
241384
+    }
241384
+}
241384
+
241384
 /* This function is called by the macro fips_is_operational and makes
241384
    sure that the minimal initialization has been done.  This is far
241384
    from a perfect solution and hides problems with an improper
241384
@@ -500,8 +528,7 @@ _gcry_vcontrol (enum gcry_ctl_cmds cmd,
241384
 
241384
     case GCRYCTL_FIPS_MODE_P:
241384
       if (fips_mode ()
241384
-          && !_gcry_is_fips_mode_inactive ()
241384
-          && !no_secure_memory)
241384
+          && !_gcry_is_fips_mode_inactive ())
241384
 	err = GPG_ERR_GENERAL; /* Used as TRUE value */
241384
       break;
241384
 
241384
@@ -600,7 +627,7 @@ _gcry_vcontrol (enum gcry_ctl_cmds cmd,
241384
       break;
241384
 
241384
     case GCRYCTL_SET_ENFORCED_FIPS_FLAG:
241384
-      if (!any_init_done)
241384
+      if (fips_mode ())
241384
         {
241384
           /* Not yet intialized at all.  Set the enforced fips mode flag */
241384
           _gcry_set_enforced_fips_mode ();