Skip to content

Commit c69273a

Browse files
authored
Merge pull request #2 from pieterlexis/explicit_bzero
Use `explicit_bzero` when `HAVE_EXPLICIT_BZERO` is defined
2 parents 1811d35 + e7e3b18 commit c69273a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Alternatively, you can build `ipcrypt2` as a static library. This is useful when
7070
- Manage dependencies more cleanly in larger codebases
7171
- Integrate with build systems that prefer library dependencies
7272

73+
To use `explicit_bzero` to zero-out secrets on de-initialization, define `HAVE_EXPLICIT_BZERO` in your build system.
74+
7375
## Building as a Static Library with Make
7476

7577
Set the appropriate `CFLAGS` if necessary and type:

src/ipcrypt2.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,9 @@ ipcrypt_init(IPCrypt *ipcrypt, const uint8_t key[IPCRYPT_KEYBYTES])
862862
void
863863
ipcrypt_deinit(IPCrypt *ipcrypt)
864864
{
865-
#ifdef _MSC_VER
865+
#ifdef HAVE_EXPLICIT_BZERO
866+
explicit_bzero(ipcrypt, sizeof *ipcrypt);
867+
#elif defined (_MSC_VER)
866868
SecureZeroMemory(ipcrypt, sizeof *ipcrypt);
867869
#elif defined(__STDC_LIB_EXT1__)
868870
memset_s(ipcrypt, sizeof *ipcrypt, 0, sizeof *ipcrypt);
@@ -897,7 +899,9 @@ ipcrypt_pfx_init(IPCryptPFX *ipcrypt, const uint8_t key[IPCRYPT_PFX_KEYBYTES])
897899
void
898900
ipcrypt_pfx_deinit(IPCryptPFX *ipcrypt)
899901
{
900-
#ifdef _MSC_VER
902+
#ifdef HAVE_EXPLICIT_BZERO
903+
explicit_bzero(ipcrypt, sizeof *ipcrypt);
904+
#elif defined (_MSC_VER)
901905
SecureZeroMemory(ipcrypt, sizeof *ipcrypt);
902906
#elif defined(__STDC_LIB_EXT1__)
903907
memset_s(ipcrypt, sizeof *ipcrypt, 0, sizeof *ipcrypt);
@@ -1202,7 +1206,9 @@ ipcrypt_ndx_init(IPCryptNDX *ipcrypt, const uint8_t key[IPCRYPT_NDX_KEYBYTES])
12021206
void
12031207
ipcrypt_ndx_deinit(IPCryptNDX *ipcrypt)
12041208
{
1205-
#ifdef _MSC_VER
1209+
#ifdef HAVE_EXPLICIT_BZERO
1210+
explicit_bzero(ipcrypt, sizeof *ipcrypt);
1211+
#elif defined (_MSC_VER)
12061212
SecureZeroMemory(ipcrypt, sizeof *ipcrypt);
12071213
#elif defined(__STDC_LIB_EXT1__)
12081214
memset_s(ipcrypt, sizeof *ipcrypt, 0, sizeof *ipcrypt);

0 commit comments

Comments
 (0)