1 /* $NetBSD: rndsource.h,v 1.9 2023/07/16 10:36:11 riastradh Exp $ */ 2 3 /*- 4 * Copyright (c) 2019 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Taylor R. Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _SYS_RNDSOURCE_H 33 #define _SYS_RNDSOURCE_H 34 35 #ifndef _KERNEL /* XXX */ 36 #error <sys/rndsource.h> is meant for kernel consumers only. 37 #endif 38 39 #include <sys/types.h> 40 #include <sys/queue.h> 41 #include <sys/rndio.h> 42 #include <sys/rngtest.h> 43 44 struct percpu; 45 46 /* 47 * struct rnd_delta_estimator 48 * 49 * State for the time-delta entropy estimation model. 50 */ 51 typedef struct rnd_delta_estimator { 52 uint64_t x; 53 uint64_t dx; 54 uint64_t d2x; 55 uint64_t insamples; 56 uint64_t outbits; 57 } rnd_delta_t; 58 59 /* 60 * struct krndsource 61 * 62 * State for an entropy source. To be allocated by a driver for a 63 * hardware entropy source, and treated as opaque. 64 * 65 * There are a number of unused fields in order to preserve ABI 66 * compatibility with the old implementation. 67 */ 68 struct krndsource { 69 LIST_ENTRY(krndsource) list; /* the linked list */ 70 char name[16]; /* device name */ 71 rnd_delta_t time_delta; /* time samples added while cold */ 72 rnd_delta_t value_delta; /* value samples added whiel cold */ 73 uint32_t total; /* number of bits added while cold */ 74 uint32_t type; /* type, RND_TYPE_* */ 75 uint32_t flags; /* flags, RND_FLAG_* */ 76 void *state; /* percpu (struct rndsource_cpu *) */ 77 size_t test_cnt; /* unused */ 78 void (*get)(size_t, void *); /* pool wants N bytes (badly) */ 79 void *getarg; /* argument to get-function */ 80 void (*enable)(struct krndsource *, bool); /* unused */ 81 rngtest_t *test; /* unused */ 82 unsigned refcnt; /* unused */ 83 }; 84 85 typedef struct krndsource krndsource_t; 86 87 void rndsource_setcb(struct krndsource *, void (*)(size_t, void *), void *); 88 void rnd_attach_source(struct krndsource *, const char *, uint32_t, 89 uint32_t); 90 void rnd_detach_source(struct krndsource *); 91 92 void _rnd_add_uint32(struct krndsource *, uint32_t); /* legacy */ 93 void _rnd_add_uint64(struct krndsource *, uint64_t); /* legacy */ 94 95 void rnd_add_uint32(struct krndsource *, uint32_t); 96 void rnd_add_data(struct krndsource *, const void *, uint32_t, uint32_t); 97 void rnd_add_data_sync(struct krndsource *, const void *, uint32_t, 98 uint32_t); 99 100 #endif /* _SYS_RNDSOURCE_H */ 101