aboutsummaryrefslogtreecommitdiffstats
path: root/src/wipe.c
blob: ca67eb168738ac5294cea6559dd1c0b238846b81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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