31807d
diff -up ./include/md.h.crypto ./include/md.h
31807d
--- ./include/md.h.crypto	2016-07-25 22:56:55.000000000 +0200
31807d
+++ ./include/md.h	2018-08-29 15:00:30.827491299 +0200
31807d
@@ -149,6 +149,7 @@ int init_md(struct md_container*);
31807d
 int update_md(struct md_container*,void*,ssize_t);
31807d
 int close_md(struct md_container*);
31807d
 void md2line(struct md_container*,struct db_line*);
31807d
+DB_ATTR_TYPE get_available_crypto();
31807d
 
31807d
 
31807d
 #endif /*_MD_H_INCLUDED*/
31807d
diff -up ./src/aide.c.crypto ./src/aide.c
31807d
--- ./src/aide.c.crypto	2018-08-29 15:00:30.825491309 +0200
31807d
+++ ./src/aide.c	2018-08-29 15:00:30.827491299 +0200
31807d
@@ -349,7 +349,7 @@ static void setdefaults_before_config()
31807d
 
31807d
   conf->db_attrs = 0;
31807d
 #if defined(WITH_MHASH) || defined(WITH_GCRYPT)
31807d
-  conf->db_attrs |= DB_MD5|DB_TIGER|DB_HAVAL|DB_CRC32|DB_SHA1|DB_RMD160|DB_SHA256|DB_SHA512;
31807d
+  conf->db_attrs |= get_available_crypto();
31807d
 #ifdef WITH_MHASH
31807d
   conf->db_attrs |= DB_GOST;
31807d
 #ifdef HAVE_MHASH_WHIRLPOOL
31807d
diff -up ./src/md.c.crypto ./src/md.c
31807d
--- ./src/md.c.crypto	2018-08-29 15:00:30.823491319 +0200
31807d
+++ ./src/md.c	2018-08-29 15:02:28.013903479 +0200
31807d
@@ -78,6 +78,49 @@ DB_ATTR_TYPE hash_gcrypt2attr(int i) {
31807d
   return r;
31807d
 }
31807d
 
31807d
+const char * hash_gcrypt2str(int i) {
31807d
+  char * r = "?";
31807d
+#ifdef WITH_GCRYPT
31807d
+  switch (i) {
31807d
+  case GCRY_MD_MD5: {
31807d
+    r = "MD5";
31807d
+    break;
31807d
+  }
31807d
+  case GCRY_MD_SHA1: {
31807d
+    r = "SHA1";
31807d
+    break;
31807d
+  }
31807d
+  case GCRY_MD_RMD160: {
31807d
+    r = "RMD160";
31807d
+    break;
31807d
+  }
31807d
+  case GCRY_MD_TIGER: {
31807d
+    r = "TIGER";
31807d
+    break;
31807d
+  }
31807d
+  case GCRY_MD_HAVAL: {
31807d
+    r = "HAVAL";
31807d
+    break;
31807d
+  }
31807d
+  case GCRY_MD_SHA256: {
31807d
+    r = "SHA256";
31807d
+    break;
31807d
+  }
31807d
+  case GCRY_MD_SHA512: {
31807d
+    r = "SHA512";
31807d
+    break;
31807d
+  }
31807d
+  case GCRY_MD_CRC32: {
31807d
+    r = "CRC32";
31807d
+    break;
31807d
+  }
31807d
+  default:
31807d
+    break;
31807d
+  }
31807d
+#endif
31807d
+  return r;
31807d
+}
31807d
+
31807d
 DB_ATTR_TYPE hash_mhash2attr(int i) {
31807d
   DB_ATTR_TYPE r=0;
31807d
 #ifdef WITH_MHASH
31807d
@@ -163,6 +206,44 @@ DB_ATTR_TYPE hash_mhash2attr(int i) {
31807d
   Initialise md_container according it's todo_attr field
31807d
  */
31807d
 
31807d
+DB_ATTR_TYPE get_available_crypto() {
31807d
+  
31807d
+  DB_ATTR_TYPE ret = 0;
31807d
+
31807d
+/*
31807d
+ * This function is usually called before config processing
31807d
+ * and default verbose level is 5
31807d
+ */
31807d
+#define lvl 255
31807d
+
31807d
+  error(lvl, "get_available_crypto called\n");
31807d
+
31807d
+#ifdef WITH_GCRYPT
31807d
+
31807d
+  /*
31807d
+ * some initialization for FIPS
31807d
+ */
31807d
+  gcry_check_version(NULL);
31807d
+  error(lvl, "Found algos:");
31807d
+
31807d
+  for(int i=0;i<=HASH_GCRYPT_COUNT;i++) {
31807d
+
31807d
+    if ( (hash_gcrypt2attr(i) & HASH_USE_GCRYPT) == 0 )
31807d
+      continue;
31807d
+  
31807d
+    if (gcry_md_algo_info(i, GCRYCTL_TEST_ALGO, NULL, NULL) == 0) {
31807d
+      ret |= hash_gcrypt2attr(i);
31807d
+      error(lvl, " %s", hash_gcrypt2str(i));
31807d
+    }
31807d
+  }
31807d
+  error(lvl, "\n");
31807d
+
31807d
+#endif
31807d
+
31807d
+  error(lvl, "get_available_crypto_returned with %lld\n", ret);
31807d
+  return ret;
31807d
+}
31807d
+
31807d
 int init_md(struct md_container* md) {
31807d
   
31807d
   int i;
31807d
@@ -201,18 +282,27 @@ int init_md(struct md_container* md) {
31807d
   }
31807d
 #endif 
31807d
 #ifdef WITH_GCRYPT
31807d
-        if(gcry_md_open(&md->mdh,0,GCRY_MD_FLAG_SECURE)!=GPG_ERR_NO_ERROR){
31807d
+  if(gcry_md_open(&md->mdh,0,GCRY_MD_FLAG_SECURE)!=GPG_ERR_NO_ERROR){
31807d
 		error(0,"gcrypt_md_open failed\n");
31807d
 		exit(IO_ERROR);
31807d
 	}
31807d
   for(i=0;i<=HASH_GCRYPT_COUNT;i++) {
31807d
+
31807d
+
31807d
     if (((hash_gcrypt2attr(i)&HASH_USE_GCRYPT)&md->todo_attr)!=0) {
31807d
-      DB_ATTR_TYPE h=hash_gcrypt2attr(i);
31807d
-      error(255,"inserting %llu\n",h);
31807d
+
31807d
+        DB_ATTR_TYPE h=hash_gcrypt2attr(i);
31807d
+
31807d
+        if (gcry_md_algo_info(i, GCRYCTL_TEST_ALGO, NULL, NULL) != 0) {
31807d
+            error(0,"Algo %s is not available\n", hash_gcrypt2str(i));
31807d
+            exit(-1);
31807d
+        }
31807d
+
31807d
+        error(255,"inserting %llu\n",h);
31807d
 			if(gcry_md_enable(md->mdh,i)==GPG_ERR_NO_ERROR){
31807d
 				md->calc_attr|=h;
31807d
 			} else {
31807d
-				error(0,"gcry_md_enable %i failed",i);
31807d
+				error(0,"gcry_md_enable %i failed\n",i);
31807d
 				md->todo_attr&=~h;
31807d
 			}
31807d
 		}