1*0c6274a8SJohn Baldwin /* 2*0c6274a8SJohn Baldwin * ISC License 3*0c6274a8SJohn Baldwin * 4*0c6274a8SJohn Baldwin * Copyright (c) 2013-2018 5*0c6274a8SJohn Baldwin * Frank Denis <j at pureftpd dot org> 6*0c6274a8SJohn Baldwin * 7*0c6274a8SJohn Baldwin * Permission to use, copy, modify, and/or distribute this software for any 8*0c6274a8SJohn Baldwin * purpose with or without fee is hereby granted, provided that the above 9*0c6274a8SJohn Baldwin * copyright notice and this permission notice appear in all copies. 10*0c6274a8SJohn Baldwin * 11*0c6274a8SJohn Baldwin * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12*0c6274a8SJohn Baldwin * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13*0c6274a8SJohn Baldwin * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14*0c6274a8SJohn Baldwin * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15*0c6274a8SJohn Baldwin * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16*0c6274a8SJohn Baldwin * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17*0c6274a8SJohn Baldwin * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18*0c6274a8SJohn Baldwin */ 19f36e41e2SConrad Meyer 20f36e41e2SConrad Meyer #include <sys/cdefs.h> 21f36e41e2SConrad Meyer __FBSDID("$FreeBSD$"); 22f36e41e2SConrad Meyer #include <sys/types.h> 23f36e41e2SConrad Meyer #include <sys/systm.h> 24f36e41e2SConrad Meyer 25f36e41e2SConrad Meyer #include <sodium/utils.h> 26f36e41e2SConrad Meyer 27f36e41e2SConrad Meyer void 28f36e41e2SConrad Meyer sodium_memzero(void *b, size_t n) 29f36e41e2SConrad Meyer { 30f36e41e2SConrad Meyer explicit_bzero(b, n); 31f36e41e2SConrad Meyer } 32*0c6274a8SJohn Baldwin 33*0c6274a8SJohn Baldwin int 34*0c6274a8SJohn Baldwin sodium_is_zero(const unsigned char *n, const size_t nlen) 35*0c6274a8SJohn Baldwin { 36*0c6274a8SJohn Baldwin size_t i; 37*0c6274a8SJohn Baldwin volatile unsigned char d = 0U; 38*0c6274a8SJohn Baldwin 39*0c6274a8SJohn Baldwin for (i = 0U; i < nlen; i++) { 40*0c6274a8SJohn Baldwin d |= n[i]; 41*0c6274a8SJohn Baldwin } 42*0c6274a8SJohn Baldwin return 1 & ((d - 1) >> 8); 43*0c6274a8SJohn Baldwin } 44