xref: /freebsd/sys/dev/random/fortuna.h (revision 32fce09268ddd97efb4412529ba57293554c5985)
110cb2424SMark Murray /*-
2d1b06863SMark Murray  * Copyright (c) 2013-2015 Mark R V Murray
310cb2424SMark Murray  * All rights reserved.
410cb2424SMark Murray  *
510cb2424SMark Murray  * Redistribution and use in source and binary forms, with or without
610cb2424SMark Murray  * modification, are permitted provided that the following conditions
710cb2424SMark Murray  * are met:
810cb2424SMark Murray  * 1. Redistributions of source code must retain the above copyright
910cb2424SMark Murray  *    notice, this list of conditions and the following disclaimer
1010cb2424SMark Murray  *    in this position and unchanged.
1110cb2424SMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
1210cb2424SMark Murray  *    notice, this list of conditions and the following disclaimer in the
1310cb2424SMark Murray  *    documentation and/or other materials provided with the distribution.
1410cb2424SMark Murray  *
1510cb2424SMark Murray  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1610cb2424SMark Murray  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1710cb2424SMark Murray  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1810cb2424SMark Murray  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1910cb2424SMark Murray  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2010cb2424SMark Murray  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2110cb2424SMark Murray  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2210cb2424SMark Murray  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2310cb2424SMark Murray  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2410cb2424SMark Murray  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2510cb2424SMark Murray  */
2610cb2424SMark Murray 
2710cb2424SMark Murray #ifndef SYS_DEV_RANDOM_FORTUNA_H_INCLUDED
2810cb2424SMark Murray #define	SYS_DEV_RANDOM_FORTUNA_H_INCLUDED
2910cb2424SMark Murray 
30*32fce092SColin Percival /* Defined in FS&K */
31*32fce092SColin Percival #define	RANDOM_FORTUNA_NPOOLS 32		/* The number of accumulation pools */
32*32fce092SColin Percival #define	RANDOM_FORTUNA_DEFPOOLSIZE 64		/* The default pool size/length for a (re)seed */
33*32fce092SColin Percival 
3410cb2424SMark Murray #ifdef _KERNEL
3510cb2424SMark Murray typedef struct mtx mtx_t;
36d1b06863SMark Murray #define	RANDOM_RESEED_INIT_LOCK(x)		mtx_init(&fortuna_state.fs_mtx, "reseed mutex", NULL, MTX_DEF)
37d1b06863SMark Murray #define	RANDOM_RESEED_DEINIT_LOCK(x)		mtx_destroy(&fortuna_state.fs_mtx)
38d1b06863SMark Murray #define	RANDOM_RESEED_LOCK(x)			mtx_lock(&fortuna_state.fs_mtx)
39d1b06863SMark Murray #define	RANDOM_RESEED_UNLOCK(x)			mtx_unlock(&fortuna_state.fs_mtx)
40d1b06863SMark Murray #define	RANDOM_RESEED_ASSERT_LOCK_OWNED(x)	mtx_assert(&fortuna_state.fs_mtx, MA_OWNED)
41179f6280SConrad Meyer #define	RANDOM_RESEED_ASSERT_LOCK_NOT_OWNED()	mtx_assert(&fortuna_state.fs_mtx, MA_NOTOWNED)
42d1b06863SMark Murray #else
43d1b06863SMark Murray #define	RANDOM_RESEED_INIT_LOCK(x)		mtx_init(&fortuna_state.fs_mtx, mtx_plain)
44d1b06863SMark Murray #define	RANDOM_RESEED_DEINIT_LOCK(x)		mtx_destroy(&fortuna_state.fs_mtx)
45d1b06863SMark Murray #define	RANDOM_RESEED_LOCK(x)			mtx_lock(&fortuna_state.fs_mtx)
46d1b06863SMark Murray #define	RANDOM_RESEED_UNLOCK(x)			mtx_unlock(&fortuna_state.fs_mtx)
47d1b06863SMark Murray #define	RANDOM_RESEED_ASSERT_LOCK_OWNED(x)
48179f6280SConrad Meyer #define	RANDOM_RESEED_ASSERT_LOCK_NOT_OWNED()
4910cb2424SMark Murray #endif
5010cb2424SMark Murray 
51d1b06863SMark Murray #endif /* SYS_DEV_RANDOM_FORTUNA_H_INCLUDED */
52