xref: /dflybsd-src/lib/libc/gen/arc4random-compat.c (revision 22cd51fe15e7d8e951102064ba0d7e07839d6394)
1*22cd51feSMatthew Dillon /*-
2*22cd51feSMatthew Dillon  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*22cd51feSMatthew Dillon  *
4*22cd51feSMatthew Dillon  * Copyright (c) 2018 Google LLC
5*22cd51feSMatthew Dillon  * All rights reserved.
6*22cd51feSMatthew Dillon  *
7*22cd51feSMatthew Dillon  * Redistribution and use in source and binary forms, with or without
8*22cd51feSMatthew Dillon  * modification, are permitted provided that the following conditions
9*22cd51feSMatthew Dillon  * are met:
10*22cd51feSMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
11*22cd51feSMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
12*22cd51feSMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
13*22cd51feSMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
14*22cd51feSMatthew Dillon  *    documentation and/or other materials provided with the distribution.
15*22cd51feSMatthew Dillon  *
16*22cd51feSMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*22cd51feSMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*22cd51feSMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*22cd51feSMatthew Dillon  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*22cd51feSMatthew Dillon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*22cd51feSMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*22cd51feSMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*22cd51feSMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*22cd51feSMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*22cd51feSMatthew Dillon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*22cd51feSMatthew Dillon  * SUCH DAMAGE.
27*22cd51feSMatthew Dillon  *
28*22cd51feSMatthew Dillon  * $FreeBSD$
29*22cd51feSMatthew Dillon  */
30*22cd51feSMatthew Dillon 
31*22cd51feSMatthew Dillon #include <sys/cdefs.h>
32*22cd51feSMatthew Dillon #include <sys/types.h>
33*22cd51feSMatthew Dillon #include <stdbool.h>
34*22cd51feSMatthew Dillon #include <syslog.h>
35*22cd51feSMatthew Dillon 
36*22cd51feSMatthew Dillon /*
37*22cd51feSMatthew Dillon  * The following functions were removed from OpenBSD for good reasons:
38*22cd51feSMatthew Dillon  *
39*22cd51feSMatthew Dillon  *  - arc4random_stir()
40*22cd51feSMatthew Dillon  *  - arc4random_addrandom()
41*22cd51feSMatthew Dillon  *
42*22cd51feSMatthew Dillon  * On FreeBSD, for backward ABI compatibility, we provide two wrapper which
43*22cd51feSMatthew Dillon  * logs this event and returns.
44*22cd51feSMatthew Dillon  */
45*22cd51feSMatthew Dillon 
46*22cd51feSMatthew Dillon void __arc4random_stir(void);
47*22cd51feSMatthew Dillon void __arc4random_addrandom(u_char *, int);
48*22cd51feSMatthew Dillon 
49*22cd51feSMatthew Dillon void
__arc4random_stir(void)50*22cd51feSMatthew Dillon __arc4random_stir(void)
51*22cd51feSMatthew Dillon {
52*22cd51feSMatthew Dillon 	static bool warned = false;
53*22cd51feSMatthew Dillon 
54*22cd51feSMatthew Dillon 	if (!warned)
55*22cd51feSMatthew Dillon 		syslog(LOG_DEBUG, "Deprecated function arc4random_stir() called");
56*22cd51feSMatthew Dillon 	warned = true;
57*22cd51feSMatthew Dillon }
58*22cd51feSMatthew Dillon 
59*22cd51feSMatthew Dillon void
__arc4random_addrandom(u_char * dummy1 __unused,int dummy2 __unused)60*22cd51feSMatthew Dillon __arc4random_addrandom(u_char * dummy1 __unused, int dummy2 __unused)
61*22cd51feSMatthew Dillon {
62*22cd51feSMatthew Dillon 	static bool warned = false;
63*22cd51feSMatthew Dillon 
64*22cd51feSMatthew Dillon 	if (!warned)
65*22cd51feSMatthew Dillon 		syslog(LOG_DEBUG, "Deprecated function arc4random_addrandom() called");
66*22cd51feSMatthew Dillon 	warned = true;
67*22cd51feSMatthew Dillon }
68*22cd51feSMatthew Dillon 
69*22cd51feSMatthew Dillon __weak_reference(__arc4random_stir, arc4random_stir);
70*22cd51feSMatthew Dillon __weak_reference(__arc4random_stir, _arc4random_stir);
71*22cd51feSMatthew Dillon __weak_reference(__arc4random_addrandom, arc4random_addrandom);
72*22cd51feSMatthew Dillon __weak_reference(__arc4random_addrandom, _arc4random_addrandom);
73