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