From 8fb6e77a618ce1a8151fab27445e0c3cc0241134 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 5 Dec 2015 11:13:46 +0100 Subject: beginning of issue #2 on github MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/wipe.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/wipe.c (limited to 'src/wipe.c') 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 . + */ +#include + +#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 + -- cgit v1.2.3-70-g09d2