summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rand/rc4_rand.c
diff options
context:
space:
mode:
authormiod <>2014-04-15 16:52:50 +0000
committermiod <>2014-04-15 16:52:50 +0000
commit7a19a50981d49325d35ae058d54f915cbfa1a027 (patch)
treecd099da9298b8ab84a5dbbead9a6560737057c97 /src/lib/libcrypto/rand/rc4_rand.c
parent2d3ffc156e48e292feaa28edc341e694571d2b00 (diff)
downloadopenbsd-7a19a50981d49325d35ae058d54f915cbfa1a027.tar.gz
openbsd-7a19a50981d49325d35ae058d54f915cbfa1a027.tar.bz2
openbsd-7a19a50981d49325d35ae058d54f915cbfa1a027.zip
Replace the old OpenSSL PRNG by direct use of arc4random_buf(), keeping the
existing RAND interfaces unchanged. All interfaces allowing external feed or seed of the RNG (either from a file or a local entropy gathering daemon) are kept for ABI compatibility, but are no longer do anything. While the OpenSSL PRNG was required 15+ years ago when many systems lacked proper entropy collection, things have evolved and one can reasonably assume it is better to use the kernel (system global) entropy pool rather than trying to build one's own and having to compensate for thread scheduling... <RANT> Whoever thought that RAND_screen(), feeding the PRNG with the contents of the local workstation's display, under Win32, was a smart idea, ought to be banned from security programming. </RANT> ok beck@ deraadt@ tedu@
Diffstat (limited to 'src/lib/libcrypto/rand/rc4_rand.c')
-rw-r--r--src/lib/libcrypto/rand/rc4_rand.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/libcrypto/rand/rc4_rand.c b/src/lib/libcrypto/rand/rc4_rand.c
new file mode 100644
index 0000000000..ebfb241d53
--- /dev/null
+++ b/src/lib/libcrypto/rand/rc4_rand.c
@@ -0,0 +1,44 @@
1/* $OpenBSD: rc4_rand.c,v 1.1 2014/04/15 16:52:50 miod Exp $ */
2
3/*
4 * Copyright (c) 2014 Miodrag Vallat.
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <stdlib.h>
20
21#include <openssl/rand.h>
22
23static int
24arc4_rand_bytes(unsigned char *buf, int num)
25{
26 if (num > 0)
27 arc4random_buf(buf, (size_t)num);
28
29 return 1;
30}
31
32static RAND_METHOD rand_arc4_meth = {
33 .seed = NULL, /* no external seed allowed */
34 .bytes = arc4_rand_bytes,
35 .cleanup = NULL, /* no cleanup necessary */
36 .add = NULL, /* no external feed allowed */
37 .pseudorand = arc4_rand_bytes,
38 .status = NULL /* no possible error condition */
39};
40
41RAND_METHOD *RAND_SSLeay(void)
42{
43 return &rand_arc4_meth;
44}