Sun Apr 12 07:16:09 2020 UTC ()
Don't inline cprng_strong{32,64}(), so they can be called from asm.


(maxv)
diff -r1.34 -r1.35 src/sys/kern/subr_cprng.c
diff -r1.15 -r1.16 src/sys/sys/cprng.h

cvs diff -r1.34 -r1.35 src/sys/kern/subr_cprng.c (expand / switch to unified diff)

--- src/sys/kern/subr_cprng.c 2019/12/04 05:36:34 1.34
+++ src/sys/kern/subr_cprng.c 2020/04/12 07:16:09 1.35
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: subr_cprng.c,v 1.34 2019/12/04 05:36:34 riastradh Exp $ */ 1/* $NetBSD: subr_cprng.c,v 1.35 2020/04/12 07:16:09 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011-2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2011-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 Thor Lancelot Simon and Taylor R. Campbell. 8 * by Thor Lancelot Simon and Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.34 2019/12/04 05:36:34 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.35 2020/04/12 07:16:09 maxv Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/condvar.h> 37#include <sys/condvar.h>
38#include <sys/cprng.h> 38#include <sys/cprng.h>
39#include <sys/errno.h> 39#include <sys/errno.h>
40#include <sys/event.h> /* XXX struct knote */ 40#include <sys/event.h> /* XXX struct knote */
41#include <sys/fcntl.h> /* XXX FNONBLOCK */ 41#include <sys/fcntl.h> /* XXX FNONBLOCK */
42#include <sys/kernel.h> 42#include <sys/kernel.h>
43#include <sys/kmem.h> 43#include <sys/kmem.h>
44#include <sys/lwp.h> 44#include <sys/lwp.h>
45#include <sys/once.h> 45#include <sys/once.h>
46#include <sys/percpu.h> 46#include <sys/percpu.h>
@@ -241,26 +241,42 @@ cprng_strong(struct cprng_strong *cprng, @@ -241,26 +241,42 @@ cprng_strong(struct cprng_strong *cprng,
241 KASSERT(bytes <= NIST_HASH_DRBG_MIN_SEEDLEN_BYTES); 241 KASSERT(bytes <= NIST_HASH_DRBG_MIN_SEEDLEN_BYTES);
242 KASSERT(0 < cprng->cs_remaining); 242 KASSERT(0 < cprng->cs_remaining);
243 KASSERT(cprng->cs_remaining <= 243 KASSERT(cprng->cs_remaining <=
244 NIST_HASH_DRBG_MIN_SEEDLEN_BYTES); 244 NIST_HASH_DRBG_MIN_SEEDLEN_BYTES);
245 } 245 }
246 246
247 cprng_strong_generate(cprng, buffer, bytes); 247 cprng_strong_generate(cprng, buffer, bytes);
248 result = bytes; 248 result = bytes;
249 249
250out: mutex_exit(&cprng->cs_lock); 250out: mutex_exit(&cprng->cs_lock);
251 return result; 251 return result;
252} 252}
253 253
 254uint32_t
 255cprng_strong32(void)
 256{
 257 uint32_t r;
 258 cprng_strong(kern_cprng, &r, sizeof(r), 0);
 259 return r;
 260}
 261
 262uint64_t
 263cprng_strong64(void)
 264{
 265 uint64_t r;
 266 cprng_strong(kern_cprng, &r, sizeof(r), 0);
 267 return r;
 268}
 269
254static void 270static void
255filt_cprng_detach(struct knote *kn) 271filt_cprng_detach(struct knote *kn)
256{ 272{
257 struct cprng_strong *const cprng = kn->kn_hook; 273 struct cprng_strong *const cprng = kn->kn_hook;
258 274
259 mutex_enter(&cprng->cs_lock); 275 mutex_enter(&cprng->cs_lock);
260 SLIST_REMOVE(&cprng->cs_selq.sel_klist, kn, knote, kn_selnext); 276 SLIST_REMOVE(&cprng->cs_selq.sel_klist, kn, knote, kn_selnext);
261 mutex_exit(&cprng->cs_lock); 277 mutex_exit(&cprng->cs_lock);
262} 278}
263 279
264static int 280static int
265filt_cprng_read_event(struct knote *kn, long hint) 281filt_cprng_read_event(struct knote *kn, long hint)
266{ 282{

cvs diff -r1.15 -r1.16 src/sys/sys/cprng.h (expand / switch to unified diff)

--- src/sys/sys/cprng.h 2019/09/02 20:09:30 1.15
+++ src/sys/sys/cprng.h 2020/04/12 07:16:09 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cprng.h,v 1.15 2019/09/02 20:09:30 riastradh Exp $ */ 1/* $NetBSD: cprng.h,v 1.16 2020/04/12 07:16:09 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011-2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2011-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 Thor Lancelot Simon and Taylor R. Campbell. 8 * by Thor Lancelot Simon and Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -61,30 +61,17 @@ b\2USE_CV\0\ @@ -61,30 +61,17 @@ b\2USE_CV\0\
61b\3HARD\0" 61b\3HARD\0"
62 62
63cprng_strong_t * 63cprng_strong_t *
64 cprng_strong_create(const char *, int, int); 64 cprng_strong_create(const char *, int, int);
65void cprng_strong_destroy(cprng_strong_t *); 65void cprng_strong_destroy(cprng_strong_t *);
66size_t cprng_strong(cprng_strong_t *, void *, size_t, int); 66size_t cprng_strong(cprng_strong_t *, void *, size_t, int);
67 67
68struct knote; /* XXX temp, for /dev/random */ 68struct knote; /* XXX temp, for /dev/random */
69int cprng_strong_kqfilter(cprng_strong_t *, struct knote *); /* XXX " */ 69int cprng_strong_kqfilter(cprng_strong_t *, struct knote *); /* XXX " */
70int cprng_strong_poll(cprng_strong_t *, int); /* XXX " */ 70int cprng_strong_poll(cprng_strong_t *, int); /* XXX " */
71 71
72extern cprng_strong_t *kern_cprng; 72extern cprng_strong_t *kern_cprng;
73 73
74static __inline uint32_t 74uint32_t cprng_strong32(void);
75cprng_strong32(void) 75uint64_t cprng_strong64(void);
76{ 
77 uint32_t r; 
78 cprng_strong(kern_cprng, &r, sizeof(r), 0); 
79 return r; 
80} 
81 
82static __inline uint64_t 
83cprng_strong64(void) 
84{ 
85 uint64_t r; 
86 cprng_strong(kern_cprng, &r, sizeof(r), 0); 
87 return r; 
88} 
89 76
90#endif /* _CPRNG_H */ 77#endif /* _CPRNG_H */