summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--lib/gnutls_mem.h4
-rw-r--r--lib/includes/gnutls/gnutls.h.in1
-rw-r--r--lib/safe-memset.c25
4 files changed, 22 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index 74c4ec633f..6f37897850 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ create a full chain. This addresses points from https://savannah.gnu.org/support
** API and ABI modifications:
dane_verify_crt_raw2: Added
+gnutls_memset: Added
* Version 3.3.2 (released 2014-05-06)
diff --git a/lib/gnutls_mem.h b/lib/gnutls_mem.h
index 6505f6d950..418a7b724f 100644
--- a/lib/gnutls_mem.h
+++ b/lib/gnutls_mem.h
@@ -36,9 +36,7 @@ char *_gnutls_strdup(const char *);
_gnutls_mpi_release(mpi); \
}
-void _gnutls_safe_memset(void *data, int c, size_t size);
-
-#define zeroize_key(x, size) _gnutls_safe_memset(x, 0, size)
+#define zeroize_key(x, size) gnutls_memset(x, 0, size)
#define zeroize_temp_key zeroize_key
#define zrelease_temp_mpi_key zrelease_mpi_key
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index 48c6d4783e..49f4bd2f9c 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -1470,6 +1470,7 @@ extern gnutls_alloc_function gnutls_malloc;
extern gnutls_realloc_function gnutls_realloc;
extern gnutls_calloc_function gnutls_calloc;
extern gnutls_free_function gnutls_free;
+void gnutls_memset(void *data, int c, size_t size);
extern char *(*gnutls_strdup) (const char *);
diff --git a/lib/safe-memset.c b/lib/safe-memset.c
index 2cf2cb8cd6..69a5ea2d12 100644
--- a/lib/safe-memset.c
+++ b/lib/safe-memset.c
@@ -24,15 +24,28 @@
# include <gnutls_int.h>
#endif
-/* This is based on a nice trick for safe memset,
- * sent by David Jacobson in the openssl-dev mailing list.
- */
-
-void _gnutls_safe_memset(void *data, int c, size_t size)
+/**
+ * gnutls_memset:
+ * @data: the memory to set
+ * @c: the constant byte to fill the memory with
+ * @n: the size of memory
+ *
+ * This function will operate similarly to memset(), but will
+ * not be optimized out by the compiler.
+ *
+ * Returns: void.
+ *
+ * Since: 3.3.3
+ **/
+void gnutls_memset(void *data, int c, size_t size)
{
volatile unsigned volatile_zero = 0;
volatile char *vdata = (volatile char*)data;
+ /* This is based on a nice trick for safe memset,
+ * sent by David Jacobson in the openssl-dev mailing list.
+ */
+
do {
memset(data, c, size);
} while(vdata[volatile_zero] != c);
@@ -43,7 +56,7 @@ int main()
{
char x[64];
- safe_memset(x, 0, sizeof(x));
+ gnutls_memset(x, 0, sizeof(x));
return 0;