aboutsummaryrefslogtreecommitdiffstats
path: root/src/wipe.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-12-05 11:13:46 +0100
committerMattias Andrée <maandree@operamail.com>2015-12-05 11:13:46 +0100
commit8fb6e77a618ce1a8151fab27445e0c3cc0241134 (patch)
tree73608a9d6880fa65c8046a09b3e6a055d9608ed4 /src/wipe.c
parentaccept flags (diff)
downloadlibpassphrase-8fb6e77a618ce1a8151fab27445e0c3cc0241134.tar.gz
libpassphrase-8fb6e77a618ce1a8151fab27445e0c3cc0241134.tar.bz2
libpassphrase-8fb6e77a618ce1a8151fab27445e0c3cc0241134.tar.xz
beginning of issue #2 on github
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/wipe.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/wipe.c b/src/wipe.c
new file mode 100644
index 0000000..ca67eb1
--- /dev/null
+++ b/src/wipe.c
@@ -0,0 +1,75 @@
+/**
+ * libpassphrase – Personalisable library for TTY passphrase reading
+ *
+ * Copyright © 2013, 2014, 2015 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <string.h>
+
+#define PASSPHRASE_USE_DEPRECATED
+#include "passphrase.h"
+#include "passphrase_helper.h"
+
+
+
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+#endif
+/* Must positively absolutely not be flagged as possible to optimise away as it depends on configurations,
+ and programs that uses this library must not be forced to be recompiled if the library is reconfigured. */
+
+
+/**
+ * `memset`, except calls to it cannot be removed by the compiler.
+ */
+void* (*volatile passphrase_explicit_memset________________)(void*, int, size_t) = memset;
+
+
+/**
+ * Forcefully write NUL characters to a passphrase
+ *
+ * @param ptr The password to wipe
+ * @param n The number of characters to wipe
+ */
+#ifdef __GNUC__
+__attribute__((optimize("-O0")))
+#endif
+void passphrase_wipe(char* ptr, size_t n)
+{
+
+ passphrase_explicit_memset________________(ptr, 0, n);
+}
+
+/**
+ * Forcefully write NUL characters to a passphrase
+ *
+ * @param ptr The password to wipe
+ */
+#ifdef __GNUC__
+__attribute__((optimize("-O0")))
+#endif
+void passphrase_wipe1(char* ptr)
+{
+
+ passphrase_explicit_memset________________(ptr, 0, strlen(ptr));
+}
+
+
+#ifdef __GNUC__
+# pragma GCC diagnostic pop
+#endif
+