summaryrefslogtreecommitdiffstats
path: root/sys/lib/libkern/explicit_bzero.c
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2011-01-10 23:23:56 +0000
committertedu <tedu@openbsd.org>2011-01-10 23:23:56 +0000
commitf5d2eefeb6c492f8ab3e752fb0b086496271977f (patch)
tree989efedd9da100c040b61831f0aff4f054bbe05b /sys/lib/libkern/explicit_bzero.c
parenttweak previous; ok millert (diff)
downloadwireguard-openbsd-f5d2eefeb6c492f8ab3e752fb0b086496271977f.tar.xz
wireguard-openbsd-f5d2eefeb6c492f8ab3e752fb0b086496271977f.zip
add a new function, explicit_bzero, to be used for erasing "secret" stuff.
unlike normal bzero, we guarantee that the compiler will not optimize out calls to this function for otherwise dead variables. to be adjusted as needed when compilers and linkers get smarter. ok deraadt miod
Diffstat (limited to 'sys/lib/libkern/explicit_bzero.c')
-rw-r--r--sys/lib/libkern/explicit_bzero.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/sys/lib/libkern/explicit_bzero.c b/sys/lib/libkern/explicit_bzero.c
new file mode 100644
index 00000000000..7550a2f0c8d
--- /dev/null
+++ b/sys/lib/libkern/explicit_bzero.c
@@ -0,0 +1,20 @@
+/* $OpenBSD: explicit_bzero.c,v 1.1 2011/01/10 23:23:56 tedu Exp $ */
+/*
+ * Public domain.
+ * Written by Ted Unangst
+ */
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <string.h>
+#else
+#include <lib/libkern/libkern.h>
+#endif
+
+/*
+ * explicit_bzero - don't let the compiler optimize away bzero
+ */
+void
+explicit_bzero(void *p, size_t n)
+{
+ bzero(p, n);
+}