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/types.h>
21f36e41e2SConrad Meyer #include <sys/systm.h>
22f36e41e2SConrad Meyer
23f36e41e2SConrad Meyer #include <sodium/utils.h>
24f36e41e2SConrad Meyer
25f36e41e2SConrad Meyer void
sodium_memzero(void * b,size_t n)26f36e41e2SConrad Meyer sodium_memzero(void *b, size_t n)
27f36e41e2SConrad Meyer {
28f36e41e2SConrad Meyer explicit_bzero(b, n);
29f36e41e2SConrad Meyer }
30*0c6274a8SJohn Baldwin
31*0c6274a8SJohn Baldwin int
sodium_is_zero(const unsigned char * n,const size_t nlen)32*0c6274a8SJohn Baldwin sodium_is_zero(const unsigned char *n, const size_t nlen)
33*0c6274a8SJohn Baldwin {
34*0c6274a8SJohn Baldwin size_t i;
35*0c6274a8SJohn Baldwin volatile unsigned char d = 0U;
36*0c6274a8SJohn Baldwin
37*0c6274a8SJohn Baldwin for (i = 0U; i < nlen; i++) {
38*0c6274a8SJohn Baldwin d |= n[i];
39*0c6274a8SJohn Baldwin }
40*0c6274a8SJohn Baldwin return 1 & ((d - 1) >> 8);
41*0c6274a8SJohn Baldwin }
42