xref: /freebsd/sys/dev/random/other_algorithm.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1646041a8SMark Murray /*-
2646041a8SMark Murray  * Copyright (c) 2015 Mark R V Murray
3646041a8SMark Murray  * All rights reserved.
4646041a8SMark Murray  *
5646041a8SMark Murray  * Redistribution and use in source and binary forms, with or without
6646041a8SMark Murray  * modification, are permitted provided that the following conditions
7646041a8SMark Murray  * are met:
8646041a8SMark Murray  * 1. Redistributions of source code must retain the above copyright
9646041a8SMark Murray  *    notice, this list of conditions and the following disclaimer
10646041a8SMark Murray  *    in this position and unchanged.
11646041a8SMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
12646041a8SMark Murray  *    notice, this list of conditions and the following disclaimer in the
13646041a8SMark Murray  *    documentation and/or other materials provided with the distribution.
14646041a8SMark Murray  *
15646041a8SMark Murray  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16646041a8SMark Murray  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17646041a8SMark Murray  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18646041a8SMark Murray  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19646041a8SMark Murray  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20646041a8SMark Murray  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21646041a8SMark Murray  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22646041a8SMark Murray  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23646041a8SMark Murray  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24646041a8SMark Murray  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25646041a8SMark Murray  */
26646041a8SMark Murray 
27646041a8SMark Murray /*-
28646041a8SMark Murray  * This is a skeleton for folks who wish to build a loadable module
29646041a8SMark Murray  * containing an alternative entropy-processing algorithm for random(4).
30646041a8SMark Murray  *
31646041a8SMark Murray  * The functions below should be completed with the appropriate code,
32*19fa89e9SMark Murray  * and the nearby fortuna.c may be consulted for examples of working code.
33646041a8SMark Murray  *
34646041a8SMark Murray  * The author is willing to provide reasonable help to those wishing to
35646041a8SMark Murray  * write such a module for themselves. Please use the markm@ FreeBSD
36646041a8SMark Murray  * email address, and ensure that you are developing this on a suitably
37*19fa89e9SMark Murray  * supported branch (This is currently 12-CURRENT, and may be no
38*19fa89e9SMark Murray  * older than 12-STABLE in the future).
39646041a8SMark Murray  */
40646041a8SMark Murray 
41646041a8SMark Murray #ifndef SYS_DEV_RANDOM_OTHER_H_INCLUDED
42646041a8SMark Murray #define	SYS_DEV_RANDOM_OTHER_H_INCLUDED
43646041a8SMark Murray 
44646041a8SMark Murray #ifdef _KERNEL
45646041a8SMark Murray typedef struct mtx mtx_t;
46646041a8SMark Murray #define	RANDOM_RESEED_INIT_LOCK(x)		mtx_init(&other_mtx, "reseed mutex", NULL, MTX_DEF)
47646041a8SMark Murray #define	RANDOM_RESEED_DEINIT_LOCK(x)		mtx_destroy(&other_mtx)
48646041a8SMark Murray #define	RANDOM_RESEED_LOCK(x)			mtx_lock(&other_mtx)
49646041a8SMark Murray #define	RANDOM_RESEED_UNLOCK(x)			mtx_unlock(&other_mtx)
50646041a8SMark Murray #define	RANDOM_RESEED_ASSERT_LOCK_OWNED(x)	mtx_assert(&other_mtx, MA_OWNED)
51646041a8SMark Murray #else
52646041a8SMark Murray #define	RANDOM_RESEED_INIT_LOCK(x)		mtx_init(&other_mtx, mtx_plain)
53646041a8SMark Murray #define	RANDOM_RESEED_DEINIT_LOCK(x)		mtx_destroy(&other_mtx)
54646041a8SMark Murray #define	RANDOM_RESEED_LOCK(x)			mtx_lock(&other_mtx)
55646041a8SMark Murray #define	RANDOM_RESEED_UNLOCK(x)			mtx_unlock(&other_mtx)
56646041a8SMark Murray #define	RANDOM_RESEED_ASSERT_LOCK_OWNED(x)
57646041a8SMark Murray #endif
58646041a8SMark Murray 
59646041a8SMark Murray #endif /* SYS_DEV_RANDOM_OTHER_H_INCLUDED */
60