xref: /freebsd/sys/dev/random/random_harvestq.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
177de2c3fSMark Murray /*-
2150890b0SMark Murray  * Copyright (c) 2013-2015, 2017 Mark R V Murray
377de2c3fSMark Murray  * All rights reserved.
477de2c3fSMark Murray  *
577de2c3fSMark Murray  * Redistribution and use in source and binary forms, with or without
677de2c3fSMark Murray  * modification, are permitted provided that the following conditions
777de2c3fSMark Murray  * are met:
877de2c3fSMark Murray  * 1. Redistributions of source code must retain the above copyright
977de2c3fSMark Murray  *    notice, this list of conditions and the following disclaimer
1077de2c3fSMark Murray  *    in this position and unchanged.
1177de2c3fSMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
1277de2c3fSMark Murray  *    notice, this list of conditions and the following disclaimer in the
1377de2c3fSMark Murray  *    documentation and/or other materials provided with the distribution.
1477de2c3fSMark Murray  *
1577de2c3fSMark Murray  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1677de2c3fSMark Murray  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1777de2c3fSMark Murray  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1877de2c3fSMark Murray  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1977de2c3fSMark Murray  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2077de2c3fSMark Murray  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2177de2c3fSMark Murray  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2277de2c3fSMark Murray  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2377de2c3fSMark Murray  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2477de2c3fSMark Murray  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2577de2c3fSMark Murray  */
2677de2c3fSMark Murray 
273e8957eaSDag-Erling Smørgrav #ifndef SYS_DEV_RANDOM_RANDOM_HARVESTQ_H_INCLUDED
283e8957eaSDag-Erling Smørgrav #define	SYS_DEV_RANDOM_RANDOM_HARVESTQ_H_INCLUDED
2977de2c3fSMark Murray 
30d1b06863SMark Murray #define	HARVESTSIZE	2	/* Max length in words of each harvested entropy unit */
3177de2c3fSMark Murray 
3210cb2424SMark Murray /* These are used to queue harvested packets of entropy. The entropy
3310cb2424SMark Murray  * buffer size is pretty arbitrary.
3410cb2424SMark Murray  */
3510cb2424SMark Murray struct harvest_event {
36d1b06863SMark Murray 	uint32_t	he_somecounter;		/* fast counter for clock jitter */
37d1b06863SMark Murray 	uint32_t	he_entropy[HARVESTSIZE];/* some harvested entropy */
38d1b06863SMark Murray 	uint8_t		he_size;		/* harvested entropy byte count */
39d1b06863SMark Murray 	uint8_t		he_destination;		/* destination pool of this entropy */
40d1b06863SMark Murray 	uint8_t		he_source;		/* origin of the entropy */
41*19fa89e9SMark Murray };
4210cb2424SMark Murray 
43d1b06863SMark Murray #define	RANDOM_HARVEST_INIT_LOCK(x)	mtx_init(&harvest_context.hc_mtx, "entropy harvest mutex", NULL, MTX_SPIN)
44d1b06863SMark Murray #define	RANDOM_HARVEST_LOCK(x)		mtx_lock_spin(&harvest_context.hc_mtx)
45d1b06863SMark Murray #define	RANDOM_HARVEST_UNLOCK(x)	mtx_unlock_spin(&harvest_context.hc_mtx)
4677de2c3fSMark Murray 
473e8957eaSDag-Erling Smørgrav #endif /* SYS_DEV_RANDOM_RANDOM_HARVESTQ_H_INCLUDED */
48