Skip to content

Commit

Permalink
Merge pull request P-H-C#267 from maciejsszmigiero/use-explicit_bzero…
Browse files Browse the repository at this point in the history
…-glibc

use explicit_bzero() on recent glibc versions
  • Loading branch information
sneves authored Mar 10, 2019
2 parents 6b4420f + fea3943 commit 80dca85
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#endif
#define VC_GE_2005(version) (version >= 1400)

/* for explicit_bzero() on glibc */
#define _DEFAULT_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -120,12 +123,20 @@ void free_memory(const argon2_context *context, uint8_t *memory,
}
}

#if defined(__OpenBSD__)
#define HAVE_EXPLICIT_BZERO 1
#elif defined(__GLIBC__) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2,25)
#define HAVE_EXPLICIT_BZERO 1
#endif
#endif

void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
#if defined(_MSC_VER) && VC_GE_2005(_MSC_VER)
SecureZeroMemory(v, n);
#elif defined memset_s
memset_s(v, n, 0, n);
#elif defined(__OpenBSD__)
#elif defined(HAVE_EXPLICIT_BZERO)
explicit_bzero(v, n);
#else
static void *(*const volatile memset_sec)(void *, int, size_t) = &memset;
Expand Down

0 comments on commit 80dca85

Please sign in to comment.