Blame SOURCES/scrub-2.6.1-use-libgcrypt.patch

aaccc6
diff -up scrub-2.6.1/configure.ac.libgcrypt scrub-2.6.1/configure.ac
aaccc6
--- scrub-2.6.1/configure.ac.libgcrypt	2014-08-26 14:15:12.000000000 -0400
aaccc6
+++ scrub-2.6.1/configure.ac	2021-02-22 13:42:48.489217200 -0500
aaccc6
@@ -70,6 +70,25 @@ AC_CHECK_FUNCS( \
aaccc6
 X_AC_CHECK_PTHREADS
aaccc6
 
aaccc6
 ##
aaccc6
+# gcrypt library
aaccc6
+##
aaccc6
+have_libgcrypt=no
aaccc6
+AC_ARG_WITH(libgcrypt, AS_HELP_STRING([--without-libgcrypt], [build without libgcrypt;
aaccc6
+                                         fallback to custom AES implementation]))
aaccc6
+AS_IF([test "x$with_libgcrypt" != "xno"],
aaccc6
+  [AM_PATH_LIBGCRYPT([1.5.0],
aaccc6
+    [AC_DEFINE([HAVE_LIBGCRYPT], [1], [libgcrypt API available])
aaccc6
+      gcrypt_CFLAGS="$LIBGCRYPT_CFLAGS"
aaccc6
+      gcrypt_LIBS="$LIBGCRYPT_LIBS"
aaccc6
+      have_libgcrypt=yes
aaccc6
+    ]
aaccc6
+  )]
aaccc6
+)
aaccc6
+AM_CONDITIONAL([LIBGCRYPT], [test "$have_libgcrypt" = "yes"])
aaccc6
+AC_SUBST([gcrypt_CFLAGS])
aaccc6
+AC_SUBST([gcrypt_LIBS])
aaccc6
+
aaccc6
+##
aaccc6
 # Arrange for large file support
aaccc6
 ## 
aaccc6
 AC_SYS_LARGEFILE
aaccc6
diff -up scrub-2.6.1/src/genrand.c.libgcrypt scrub-2.6.1/src/genrand.c
aaccc6
--- scrub-2.6.1/src/genrand.c.libgcrypt	2014-08-20 17:33:43.000000000 -0400
aaccc6
+++ scrub-2.6.1/src/genrand.c	2021-02-22 13:42:48.490217204 -0500
aaccc6
@@ -37,21 +37,27 @@
aaccc6
 #include <assert.h>
aaccc6
 #include <libgen.h>
aaccc6
 
aaccc6
-#include "aes.h"
aaccc6
 #include "util.h"
aaccc6
 #include "genrand.h"
aaccc6
 #include "hwrand.h"
aaccc6
 
aaccc6
-#define PATH_URANDOM    "/dev/urandom"
aaccc6
-
aaccc6
-#define PAYLOAD_SZ  16
aaccc6
-#define KEY_SZ      16
aaccc6
+#ifdef HAVE_LIBGCRYPT
aaccc6
+#include <gcrypt.h>
aaccc6
+#else
aaccc6
+#include "aes.h"
aaccc6
+#endif /* HAVE_LIBGCRYPT. */
aaccc6
 
aaccc6
 extern char *prog;
aaccc6
 
aaccc6
 static bool no_hwrand = false;
aaccc6
 static hwrand_t gen_hwrand;
aaccc6
 
aaccc6
+#ifndef HAVE_LIBGCRYPT
aaccc6
+#define PATH_URANDOM    "/dev/urandom"
aaccc6
+
aaccc6
+#define PAYLOAD_SZ  16
aaccc6
+#define KEY_SZ      16
aaccc6
+
aaccc6
 static aes_context  ctx;
aaccc6
 static unsigned char ctr[PAYLOAD_SZ];
aaccc6
 
aaccc6
@@ -140,17 +146,26 @@ churnrand(void)
aaccc6
 error:
aaccc6
     return -1;
aaccc6
 }
aaccc6
+#endif /* HAVE_LIBGCRYPT. */
aaccc6
 
aaccc6
 /* Initialize the module.
aaccc6
  */
aaccc6
 int
aaccc6
 initrand(void)
aaccc6
 {
aaccc6
+#ifndef HAVE_LIBGCRYPT
aaccc6
     struct timeval tv;
aaccc6
+#else
aaccc6
+    if (!gcry_check_version(GCRYPT_VERSION)) {
aaccc6
+        goto error;
aaccc6
+    }
aaccc6
+    gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
aaccc6
+#endif /* HAVE_LIBGCRYPT */
aaccc6
 
aaccc6
     if (!no_hwrand)
aaccc6
         gen_hwrand = init_hwrand();
aaccc6
 
aaccc6
+#ifndef HAVE_LIBGCRYPT
aaccc6
     /* Always initialize the software random number generator as backup */
aaccc6
 
aaccc6
     if (gettimeofday(&tv, NULL) < 0)
aaccc6
@@ -163,6 +178,7 @@ initrand(void)
aaccc6
 #endif
aaccc6
     if (churnrand() < 0)
aaccc6
         goto error;
aaccc6
+#endif /* HAVE_LIBGCRYPT. */
aaccc6
     return 0;
aaccc6
 error:
aaccc6
     return -1;
aaccc6
@@ -173,9 +189,11 @@ error:
aaccc6
 void 
aaccc6
 genrand(unsigned char *buf, int buflen)
aaccc6
 {
aaccc6
+#ifndef HAVE_LIBGCRYPT
aaccc6
     int i;
aaccc6
     unsigned char out[PAYLOAD_SZ];
aaccc6
     int cpylen = PAYLOAD_SZ;
aaccc6
+#endif /* HAVE_LIBGCRYPT. */
aaccc6
 
aaccc6
     if (gen_hwrand) {
aaccc6
         bool hwok = gen_hwrand(buf, buflen);
aaccc6
@@ -183,6 +201,7 @@ genrand(unsigned char *buf, int buflen)
aaccc6
             return;
aaccc6
     }
aaccc6
 
aaccc6
+#ifndef HAVE_LIBGCRYPT
aaccc6
     for (i = 0; i < buflen; i += cpylen) {
aaccc6
         aes_encrypt(&ctx, ctr, out);
aaccc6
         incr128(ctr);
aaccc6
@@ -191,6 +210,9 @@ genrand(unsigned char *buf, int buflen)
aaccc6
         memcpy(&buf[i], out, cpylen);
aaccc6
     }
aaccc6
     assert(i == buflen);
aaccc6
+#else
aaccc6
+    gcry_randomize(buf, buflen, GCRY_STRONG_RANDOM);
aaccc6
+#endif /* HAVE_LIBGCRYPT. */
aaccc6
 }
aaccc6
 
aaccc6
 /*
aaccc6
diff -up scrub-2.6.1/src/genrand.h.libgcrypt scrub-2.6.1/src/genrand.h
aaccc6
--- scrub-2.6.1/src/genrand.h.libgcrypt	2014-08-20 17:33:43.000000000 -0400
aaccc6
+++ scrub-2.6.1/src/genrand.h	2021-02-22 13:42:48.490217204 -0500
aaccc6
@@ -1,8 +1,14 @@
aaccc6
+#include "config.h"
aaccc6
+
aaccc6
 void disable_hwrand(void);
aaccc6
 int initrand(void);
aaccc6
-int churnrand(void);
aaccc6
 void genrand(unsigned char *buf, int buflen);
aaccc6
 
aaccc6
+#ifndef HAVE_LIBGCRYPT
aaccc6
+int churnrand(void);
aaccc6
+#endif /* HAVE_LIBGCRYPT. */
aaccc6
+
aaccc6
+
aaccc6
 /*
aaccc6
  * vi:tabstop=4 shiftwidth=4 expandtab
aaccc6
  */
aaccc6
diff -up scrub-2.6.1/src/Makefile.am.libgcrypt scrub-2.6.1/src/Makefile.am
aaccc6
--- scrub-2.6.1/src/Makefile.am.libgcrypt	2014-08-20 17:33:43.000000000 -0400
aaccc6
+++ scrub-2.6.1/src/Makefile.am	2021-02-22 13:43:47.008492696 -0500
aaccc6
@@ -1,8 +1,6 @@
aaccc6
 bin_PROGRAMS = scrub
aaccc6
 
aaccc6
 scrub_SOURCES = \
aaccc6
-	aes.c \
aaccc6
-	aes.h \
aaccc6
 	filldentry.c \
aaccc6
 	filldentry.h \
aaccc6
 	fillfile.c \
aaccc6
@@ -24,3 +22,9 @@ scrub_SOURCES = \
aaccc6
 	util.h
aaccc6
 
aaccc6
 scrub_LDADD = $(LIBPTHREAD)
aaccc6
+
aaccc6
+if LIBGCRYPT
aaccc6
+scrub_LDADD += $(gcrypt_LIBS)
aaccc6
+else
aaccc6
+scrub_SOURCES += aes.c aes.h
aaccc6
+endif
aaccc6
diff -up scrub-2.6.1/src/scrub.c.libgcrypt scrub-2.6.1/src/scrub.c
aaccc6
--- scrub-2.6.1/src/scrub.c.libgcrypt	2021-02-22 13:42:48.488217195 -0500
aaccc6
+++ scrub-2.6.1/src/scrub.c	2021-02-22 13:42:48.490217204 -0500
aaccc6
@@ -459,11 +459,13 @@ scrub(char *path, off_t size, const sequ
aaccc6
             case PAT_RANDOM:
aaccc6
                 printf("%s: %-8s", prog, "random");
aaccc6
                 progress_create(&p, pcol);
aaccc6
+#ifndef HAVE_LIBGCRYPT
aaccc6
                 if (churnrand() < 0) {
aaccc6
                     fprintf(stderr, "%s: churnrand: %s\n", prog,
aaccc6
                              strerror(errno));
aaccc6
                     exit(1);
aaccc6
                 }
aaccc6
+#endif /* HAVE_LIBGCRYPT. */
aaccc6
                 written = fillfile(path, size, buf, bufsize, 
aaccc6
                                    (progress_t)progress_update, p, 
aaccc6
                                    (refill_t)genrand, sparse, enospc);
aaccc6
diff -up scrub-2.6.1/test/Makefile.am.libgcrypt scrub-2.6.1/test/Makefile.am
aaccc6
--- scrub-2.6.1/test/Makefile.am.libgcrypt	2014-08-26 14:11:14.000000000 -0400
aaccc6
+++ scrub-2.6.1/test/Makefile.am	2021-02-22 13:44:59.301833042 -0500
aaccc6
@@ -1,8 +1,8 @@
aaccc6
-check_PROGRAMS = pad trand aestest tprogress tgetsize tsig tsize pat
aaccc6
+check_PROGRAMS = pad trand tprogress tgetsize tsig tsize pat
aaccc6
 
aaccc6
 TESTS_ENVIRONMENT = env 
aaccc6
 TESTS_ENVIRONMENT += "PATH_SCRUB=$(top_builddir)/src/scrub"
aaccc6
-TESTS = t00 t01 t02 t03 t04 t05 t06 t07 t08 t09 t10 t11 t12 t13 t14 t15 t16 \
aaccc6
+TESTS = t01 t02 t03 t04 t05 t06 t07 t08 t09 t10 t11 t12 t13 t14 t15 t16 \
aaccc6
 	t17 t18 t19 t20 t21 t22
aaccc6
 
aaccc6
 CLEANFILES = *.out *.diff testfile
aaccc6
@@ -13,17 +13,24 @@ common_sources = \
aaccc6
 	$(top_srcdir)/src/getsize.c \
aaccc6
 	$(top_srcdir)/src/genrand.c \
aaccc6
 	$(top_srcdir)/src/hwrand.c \
aaccc6
-	$(top_srcdir)/src/aes.c \
aaccc6
 	$(top_srcdir)/src/util.c \
aaccc6
 	$(top_srcdir)/src/progress.c \
aaccc6
 	$(top_srcdir)/src/sig.c
aaccc6
 
aaccc6
 pad_SOURCES = pad.c $(common_sources)
aaccc6
 trand_SOURCES = trand.c $(common_sources)
aaccc6
-aestest_SOURCES = aestest.c $(common_sources)
aaccc6
 tprogress_SOURCES = tprogress.c $(common_sources)
aaccc6
 tgetsize_SOURCES = tgetsize.c $(common_sources)
aaccc6
 tsig_SOURCES = tsig.c $(common_sources)
aaccc6
 pat_SOURCES = pat.c $(common_sources)
aaccc6
 
aaccc6
+if LIBGCRYPT
aaccc6
+AM_LDFLAGS = $(gcrypt_LIBS)
aaccc6
+else
aaccc6
+check_PROGRAMS += aestest
aaccc6
+TESTS += t00
aaccc6
+common_sources += $(top_srcdir)/src/aes.c
aaccc6
+aestest_SOURCES = aestest.c $(common_sources)
aaccc6
+endif
aaccc6
+
aaccc6
 EXTRA_DIST = $(TESTS) $(TESTS:%=%.exp)