| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_rndq.c,v 1.7 2013/01/16 06:45:24 msaitoh Exp $ */ | | 1 | /* $NetBSD: kern_rndq.c,v 1.8 2013/01/24 14:23:45 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997-2011 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.7 2013/01/16 06:45:24 msaitoh Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.8 2013/01/24 14:23:45 riastradh Exp $"); |
36 | | | 36 | |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | #include <sys/ioctl.h> | | 38 | #include <sys/ioctl.h> |
39 | #include <sys/fcntl.h> | | 39 | #include <sys/fcntl.h> |
40 | #include <sys/select.h> | | 40 | #include <sys/select.h> |
41 | #include <sys/poll.h> | | 41 | #include <sys/poll.h> |
42 | #include <sys/kmem.h> | | 42 | #include <sys/kmem.h> |
43 | #include <sys/mutex.h> | | 43 | #include <sys/mutex.h> |
44 | #include <sys/proc.h> | | 44 | #include <sys/proc.h> |
45 | #include <sys/kernel.h> | | 45 | #include <sys/kernel.h> |
46 | #include <sys/conf.h> | | 46 | #include <sys/conf.h> |
47 | #include <sys/systm.h> | | 47 | #include <sys/systm.h> |
48 | #include <sys/callout.h> | | 48 | #include <sys/callout.h> |
| @@ -749,27 +749,27 @@ rnd_add_data_ts(krndsource_t *rs, const | | | @@ -749,27 +749,27 @@ rnd_add_data_ts(krndsource_t *rs, const |
749 | return; | | 749 | return; |
750 | } | | 750 | } |
751 | mutex_spin_exit(&rnd_mtx); | | 751 | mutex_spin_exit(&rnd_mtx); |
752 | } | | 752 | } |
753 | | | 753 | |
754 | static int | | 754 | static int |
755 | rnd_hwrng_test(rnd_sample_t *sample) | | 755 | rnd_hwrng_test(rnd_sample_t *sample) |
756 | { | | 756 | { |
757 | krndsource_t *source = sample->source; | | 757 | krndsource_t *source = sample->source; |
758 | size_t cmplen; | | 758 | size_t cmplen; |
759 | uint8_t *v1, *v2; | | 759 | uint8_t *v1, *v2; |
760 | size_t resid, totest; | | 760 | size_t resid, totest; |
761 | | | 761 | |
762 | KASSERT(source->type = RND_TYPE_RNG); | | 762 | KASSERT(source->type == RND_TYPE_RNG); |
763 | | | 763 | |
764 | /* | | 764 | /* |
765 | * Continuous-output test: compare two halves of the | | 765 | * Continuous-output test: compare two halves of the |
766 | * sample buffer to each other. The sample buffer (64 ints, | | 766 | * sample buffer to each other. The sample buffer (64 ints, |
767 | * so either 256 or 512 bytes on any modern machine) should be | | 767 | * so either 256 or 512 bytes on any modern machine) should be |
768 | * much larger than a typical hardware RNG output, so this seems | | 768 | * much larger than a typical hardware RNG output, so this seems |
769 | * a reasonable way to do it without retaining extra data. | | 769 | * a reasonable way to do it without retaining extra data. |
770 | */ | | 770 | */ |
771 | cmplen = sizeof(sample->values) / 2; | | 771 | cmplen = sizeof(sample->values) / 2; |
772 | v1 = (uint8_t *)sample->values; | | 772 | v1 = (uint8_t *)sample->values; |
773 | v2 = (uint8_t *)sample->values + cmplen; | | 773 | v2 = (uint8_t *)sample->values + cmplen; |
774 | | | 774 | |
775 | if (__predict_false(!memcmp(v1, v2, cmplen))) { | | 775 | if (__predict_false(!memcmp(v1, v2, cmplen))) { |