[110762] in cryptography@c2.net mail archive
Re: More on in-memory zeroisation
daemon@ATHENA.MIT.EDU (Werner Koch)
Fri Dec 14 17:43:12 2007
From: Werner Koch <wk@gnupg.org>
To: Alan Barrett <apb@cequrux.com>
Cc: cryptography@metzdowd.com
Date: Fri, 14 Dec 2007 17:14:34 +0100
In-Reply-To: <20071213201148.GB1429@apb-laptoy.apb.alt.za> (Alan Barrett's
message of "Thu, 13 Dec 2007 22:11:48 +0200")
On Thu, 13 Dec 2007 21:11, apb@cequrux.com said:
> volatile char buf[SIZE];
> /* ... do stuff with buf ... */
> memset(buf, 0, sizeof(buf));
This has the little disadvantage that you need to check the attributes
of BUF first and that you can't immediately see what the memset is used
for. For a long time we use the macros below to document the intention
and to make sure that the compiler does not do any harm:
/* To avoid that a compiler optimizes certain memset calls away, these
macros may be used instead. */
#define wipememory2(_ptr,_set,_len) do { \
volatile char *_vptr=(volatile char *)(_ptr); \
size_t _vlen=(_len); \
while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \
} while(0)
#define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
Shalom-Salam,
Werner
--
Die Gedanken sind frei. Auschnahme regelt ein Bundeschgesetz.
---------------------------------------------------------------------
The Cryptography Mailing List
Unsubscribe by sending "unsubscribe cryptography" to majordomo@metzdowd.com