| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_rndq.c,v 1.50 2015/04/14 12:28:12 riastradh Exp $ */ | | 1 | /* $NetBSD: kern_rndq.c,v 1.51 2015/04/14 12:33:53 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1997-2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997-2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Michael Graff <explorer@flame.org> and Thor Lancelot Simon. | | 8 | * by Michael Graff <explorer@flame.org> and Thor Lancelot Simon. |
9 | * This code uses ideas and algorithms from the Linux driver written by | | 9 | * This code uses ideas and algorithms from the Linux driver written by |
10 | * Ted Ts'o. | | 10 | * Ted Ts'o. |
11 | * | | 11 | * |
12 | * Redistribution and use in source and binary forms, with or without | | 12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | | 13 | * modification, are permitted provided that the following conditions |
14 | * are met: | | 14 | * are met: |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
31 | * POSSIBILITY OF SUCH DAMAGE. | | 31 | * POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #include <sys/cdefs.h> | | 34 | #include <sys/cdefs.h> |
35 | __KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.50 2015/04/14 12:28:12 riastradh Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.51 2015/04/14 12:33:53 riastradh Exp $"); |
36 | | | 36 | |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | #include <sys/atomic.h> | | 38 | #include <sys/atomic.h> |
39 | #include <sys/ioctl.h> | | 39 | #include <sys/ioctl.h> |
40 | #include <sys/fcntl.h> | | 40 | #include <sys/fcntl.h> |
41 | #include <sys/select.h> | | 41 | #include <sys/select.h> |
42 | #include <sys/poll.h> | | 42 | #include <sys/poll.h> |
43 | #include <sys/kmem.h> | | 43 | #include <sys/kmem.h> |
44 | #include <sys/mutex.h> | | 44 | #include <sys/mutex.h> |
45 | #include <sys/proc.h> | | 45 | #include <sys/proc.h> |
46 | #include <sys/kernel.h> | | 46 | #include <sys/kernel.h> |
47 | #include <sys/conf.h> | | 47 | #include <sys/conf.h> |
48 | #include <sys/systm.h> | | 48 | #include <sys/systm.h> |
| @@ -1010,27 +1010,27 @@ rnd_hwrng_test(rnd_sample_t *sample) | | | @@ -1010,27 +1010,27 @@ rnd_hwrng_test(rnd_sample_t *sample) |
1010 | return 0; | | 1010 | return 0; |
1011 | } | | 1011 | } |
1012 | | | 1012 | |
1013 | /* | | 1013 | /* |
1014 | * Process the events in the ring buffer. Called by rnd_timeout or | | 1014 | * Process the events in the ring buffer. Called by rnd_timeout or |
1015 | * by the add routines directly if the callout has never fired (that | | 1015 | * by the add routines directly if the callout has never fired (that |
1016 | * is, if we are "cold" -- just booted). | | 1016 | * is, if we are "cold" -- just booted). |
1017 | * | | 1017 | * |
1018 | */ | | 1018 | */ |
1019 | static void | | 1019 | static void |
1020 | rnd_process_events(void) | | 1020 | rnd_process_events(void) |
1021 | { | | 1021 | { |
1022 | rnd_sample_t *sample = NULL; | | 1022 | rnd_sample_t *sample = NULL; |
1023 | krndsource_t *source, *badsource = NULL; | | 1023 | krndsource_t *source; |
1024 | static krndsource_t *last_source; | | 1024 | static krndsource_t *last_source; |
1025 | uint32_t entropy; | | 1025 | uint32_t entropy; |
1026 | size_t pool_entropy; | | 1026 | size_t pool_entropy; |
1027 | int found = 0, wake = 0; | | 1027 | int found = 0, wake = 0; |
1028 | struct rnd_sampleq dq_samples = SIMPLEQ_HEAD_INITIALIZER(dq_samples); | | 1028 | struct rnd_sampleq dq_samples = SIMPLEQ_HEAD_INITIALIZER(dq_samples); |
1029 | struct rnd_sampleq df_samples = SIMPLEQ_HEAD_INITIALIZER(df_samples); | | 1029 | struct rnd_sampleq df_samples = SIMPLEQ_HEAD_INITIALIZER(df_samples); |
1030 | | | 1030 | |
1031 | /* | | 1031 | /* |
1032 | * Drain to the on-stack queue and drop the lock. | | 1032 | * Drain to the on-stack queue and drop the lock. |
1033 | */ | | 1033 | */ |
1034 | mutex_spin_enter(&rnd_samples.lock); | | 1034 | mutex_spin_enter(&rnd_samples.lock); |
1035 | while ((sample = SIMPLEQ_FIRST(&rnd_samples.q))) { | | 1035 | while ((sample = SIMPLEQ_FIRST(&rnd_samples.q))) { |
1036 | found++; | | 1036 | found++; |
| @@ -1080,27 +1080,27 @@ rnd_process_events(void) | | | @@ -1080,27 +1080,27 @@ rnd_process_events(void) |
1080 | */ | | 1080 | */ |
1081 | if (source->flags & RND_FLAG_NO_COLLECT) | | 1081 | if (source->flags & RND_FLAG_NO_COLLECT) |
1082 | goto skip; | | 1082 | goto skip; |
1083 | | | 1083 | |
1084 | /* | | 1084 | /* |
1085 | * Hardware generators are great but sometimes they | | 1085 | * Hardware generators are great but sometimes they |
1086 | * have...hardware issues. Don't use any data from | | 1086 | * have...hardware issues. Don't use any data from |
1087 | * them unless it passes some tests. | | 1087 | * them unless it passes some tests. |
1088 | */ | | 1088 | */ |
1089 | if (source->type == RND_TYPE_RNG) { | | 1089 | if (source->type == RND_TYPE_RNG) { |
1090 | if (__predict_false(rnd_hwrng_test(sample))) { | | 1090 | if (__predict_false(rnd_hwrng_test(sample))) { |
1091 | source->flags |= RND_FLAG_NO_COLLECT; | | 1091 | source->flags |= RND_FLAG_NO_COLLECT; |
1092 | rnd_printf("rnd: disabling source \"%s\".", | | 1092 | rnd_printf("rnd: disabling source \"%s\".", |
1093 | badsource->name); | | 1093 | source->name); |
1094 | goto skip; | | 1094 | goto skip; |
1095 | } | | 1095 | } |
1096 | } | | 1096 | } |
1097 | | | 1097 | |
1098 | if (source->flags & RND_FLAG_COLLECT_VALUE) { | | 1098 | if (source->flags & RND_FLAG_COLLECT_VALUE) { |
1099 | rndpool_add_data(&rnd_pool, sample->values, | | 1099 | rndpool_add_data(&rnd_pool, sample->values, |
1100 | sample_count * | | 1100 | sample_count * |
1101 | sizeof(sample->values[1]), | | 1101 | sizeof(sample->values[1]), |
1102 | 0); | | 1102 | 0); |
1103 | } | | 1103 | } |
1104 | if (source->flags & RND_FLAG_COLLECT_TIME) { | | 1104 | if (source->flags & RND_FLAG_COLLECT_TIME) { |
1105 | rndpool_add_data(&rnd_pool, sample->ts, | | 1105 | rndpool_add_data(&rnd_pool, sample->ts, |
1106 | sample_count * | | 1106 | sample_count * |