1 /*@ S-nail - a mail user agent derived from Berkeley Mail. 2 *@ Random string creation. 3 * 4 * Copyright (c) 2015 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>. 5 * SPDX-License-Identifier: ISC 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 #ifndef mx_RANDOM_H 20 #define mx_RANDOM_H 21 22 #include <mx/nail.h> 23 24 #define mx_HEADER 25 #include <su/code-in.h> 26 27 /* mx_HAVE_RANDOM: supported (external) PRG implementations */ 28 #define mx_RANDOM_IMPL_BUILTIN 0 29 #define mx_RANDOM_IMPL_ARC4 1 30 #define mx_RANDOM_IMPL_TLS 2 31 #define mx_RANDOM_IMPL_GETENTROPY 3 32 #define mx_RANDOM_IMPL_GETRANDOM 4 /* (both, syscall + library) */ 33 #define mx_RANDOM_IMPL_URANDOM 5 34 35 /* Get a (pseudo) random string of *len* bytes, _not_ counting the NUL 36 * terminator, the second returns an n_autorec_alloc()ed buffer. 37 * If su_STATE_REPRODUCIBLE and reprocnt_or_nil not NIL then we produce 38 * a reproducible string by using and managing that counter instead */ 39 EXPORT char *mx_random_create_buf(char *dat, uz len, u32 *reprocnt_or_nil); 40 EXPORT char *mx_random_create_cp(uz len, u32 *reprocnt_or_nil); 41 42 #include <su/code-ou.h> 43 #endif /* mx_RANDOM_H */ 44 /* s-it-mode */ 45