Blame SOURCES/argon2-Use-explicit_bzero-on-recent-glibc-versions.patch

d560a5
From fea3943adadf6527d1e839a2953e9591896e628d Mon Sep 17 00:00:00 2001
d560a5
From: "Maciej S. Szmigiero" <mail@maciej.szmigiero.name>
d560a5
Date: Tue, 5 Mar 2019 14:30:22 +0100
d560a5
Subject: [PATCH] Use explicit_bzero() on recent glibc versions
d560a5
d560a5
glibc 2.25+ has explicit_bzero(), so we can use it to securely wipe memory
d560a5
instead of hacking our own memset-based replacement, just like we already
d560a5
do on OpenBSD.
d560a5
---
d560a5
 src/core.c | 13 ++++++++++++-
d560a5
 1 file changed, 12 insertions(+), 1 deletion(-)
d560a5
d560a5
diff --git a/src/core.c b/src/core.c
d560a5
index 8781852..8361175 100644
d560a5
--- a/src/core.c
d560a5
+++ b/src/core.c
d560a5
@@ -25,6 +25,9 @@
d560a5
 #endif
d560a5
 #define VC_GE_2005(version) (version >= 1400)
d560a5
 
d560a5
+/* for explicit_bzero() on glibc */
d560a5
+#define _DEFAULT_SOURCE
d560a5
+
d560a5
 #include <stdio.h>
d560a5
 #include <stdlib.h>
d560a5
 #include <string.h>
d560a5
@@ -120,12 +123,20 @@ void free_memory(const argon2_context *context, uint8_t *memory,
d560a5
     }
d560a5
 }
d560a5
 
d560a5
+#if defined(__OpenBSD__)
d560a5
+#define HAVE_EXPLICIT_BZERO 1
d560a5
+#elif defined(__GLIBC__) && defined(__GLIBC_PREREQ)
d560a5
+#if __GLIBC_PREREQ(2,25)
d560a5
+#define HAVE_EXPLICIT_BZERO 1
d560a5
+#endif
d560a5
+#endif
d560a5
+
d560a5
 void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
d560a5
 #if defined(_MSC_VER) && VC_GE_2005(_MSC_VER)
d560a5
     SecureZeroMemory(v, n);
d560a5
 #elif defined memset_s
d560a5
     memset_s(v, n, 0, n);
d560a5
-#elif defined(__OpenBSD__)
d560a5
+#elif defined(HAVE_EXPLICIT_BZERO)
d560a5
     explicit_bzero(v, n);
d560a5
 #else
d560a5
     static void *(*const volatile memset_sec)(void *, int, size_t) = &memset;
d560a5
-- 
d560a5
2.20.1
d560a5