xref: /freebsd/contrib/unbound/compat/explicit_bzero.c (revision ff8258499cd4a5a2a522c985cd7592a7904d973f)
1*ff825849SDag-Erling Smørgrav /*	$OpenBSD: explicit_bzero.c,v 1.3 2014/06/21 02:34:26 matthew Exp $ */
2*ff825849SDag-Erling Smørgrav /*
3*ff825849SDag-Erling Smørgrav  * Public domain.
4*ff825849SDag-Erling Smørgrav  * Written by Matthew Dempsky.
5*ff825849SDag-Erling Smørgrav  */
6*ff825849SDag-Erling Smørgrav #include "config.h"
7*ff825849SDag-Erling Smørgrav #include <string.h>
8*ff825849SDag-Erling Smørgrav 
9*ff825849SDag-Erling Smørgrav __attribute__((weak)) void
10*ff825849SDag-Erling Smørgrav __explicit_bzero_hook(void *ATTR_UNUSED(buf), size_t ATTR_UNUSED(len))
11*ff825849SDag-Erling Smørgrav {
12*ff825849SDag-Erling Smørgrav }
13*ff825849SDag-Erling Smørgrav 
14*ff825849SDag-Erling Smørgrav void
15*ff825849SDag-Erling Smørgrav explicit_bzero(void *buf, size_t len)
16*ff825849SDag-Erling Smørgrav {
17*ff825849SDag-Erling Smørgrav #ifdef UB_ON_WINDOWS
18*ff825849SDag-Erling Smørgrav 	SecureZeroMemory(buf, len);
19*ff825849SDag-Erling Smørgrav #endif
20*ff825849SDag-Erling Smørgrav 	memset(buf, 0, len);
21*ff825849SDag-Erling Smørgrav 	__explicit_bzero_hook(buf, len);
22*ff825849SDag-Erling Smørgrav }
23