summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2014-10-22 13:54:03 +0000
committerjsing <>2014-10-22 13:54:03 +0000
commit85b016137f0bd9cf3b15129668f9d794a71c6d34 (patch)
tree5182be1e2bb99eb4ec60a5c42f2f953b4c1cadf1
parente931cb809e30a11ec87c1f47536227dc2f58dbdb (diff)
downloadopenbsd-85b016137f0bd9cf3b15129668f9d794a71c6d34.tar.gz
openbsd-85b016137f0bd9cf3b15129668f9d794a71c6d34.tar.bz2
openbsd-85b016137f0bd9cf3b15129668f9d794a71c6d34.zip
Use arc4random_buf() instead of RAND(_pseudo)?_bytes().
ok bcook@
-rw-r--r--src/usr.bin/openssl/enc.c8
-rw-r--r--src/usr.bin/openssl/openssl.c4
-rw-r--r--src/usr.bin/openssl/passwd.c9
-rw-r--r--src/usr.bin/openssl/rand.c7
-rw-r--r--src/usr.bin/openssl/s_cb.c9
-rw-r--r--src/usr.bin/openssl/s_server.c5
-rw-r--r--src/usr.bin/openssl/speed.c7
-rw-r--r--src/usr.bin/openssl/ts.c6
8 files changed, 19 insertions, 36 deletions
diff --git a/src/usr.bin/openssl/enc.c b/src/usr.bin/openssl/enc.c
index 1a3b8f21b3..b5aaab9842 100644
--- a/src/usr.bin/openssl/enc.c
+++ b/src/usr.bin/openssl/enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: enc.c,v 1.2 2014/09/01 20:54:37 doug Exp $ */ 1/* $OpenBSD: enc.c,v 1.3 2014/10/22 13:54:03 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -69,7 +69,6 @@
69#include <openssl/evp.h> 69#include <openssl/evp.h>
70#include <openssl/objects.h> 70#include <openssl/objects.h>
71#include <openssl/pem.h> 71#include <openssl/pem.h>
72#include <openssl/rand.h>
73#include <openssl/x509.h> 72#include <openssl/x509.h>
74 73
75int set_hex(char *in, unsigned char *out, int size); 74int set_hex(char *in, unsigned char *out, int size);
@@ -461,8 +460,9 @@ enc_main(int argc, char **argv)
461 "invalid hex salt value\n"); 460 "invalid hex salt value\n");
462 goto end; 461 goto end;
463 } 462 }
464 } else if (RAND_pseudo_bytes(salt, sizeof salt) < 0) 463 } else
465 goto end; 464 arc4random_buf(salt,
465 sizeof(salt));
466 /* 466 /*
467 * If -P option then don't bother 467 * If -P option then don't bother
468 * writing 468 * writing
diff --git a/src/usr.bin/openssl/openssl.c b/src/usr.bin/openssl/openssl.c
index bcb9b56b74..76e1644f59 100644
--- a/src/usr.bin/openssl/openssl.c
+++ b/src/usr.bin/openssl/openssl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: openssl.c,v 1.1 2014/08/26 17:47:25 jsing Exp $ */ 1/* $OpenBSD: openssl.c,v 1.2 2014/10/22 13:54:03 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -123,7 +123,6 @@
123#include <openssl/err.h> 123#include <openssl/err.h>
124#include <openssl/lhash.h> 124#include <openssl/lhash.h>
125#include <openssl/pem.h> 125#include <openssl/pem.h>
126#include <openssl/rand.h>
127#include <openssl/ssl.h> 126#include <openssl/ssl.h>
128#include <openssl/x509.h> 127#include <openssl/x509.h>
129 128
@@ -233,7 +232,6 @@ openssl_shutdown(void)
233 232
234 CRYPTO_cleanup_all_ex_data(); 233 CRYPTO_cleanup_all_ex_data();
235 ERR_remove_thread_state(NULL); 234 ERR_remove_thread_state(NULL);
236 RAND_cleanup();
237 ERR_free_strings(); 235 ERR_free_strings();
238} 236}
239 237
diff --git a/src/usr.bin/openssl/passwd.c b/src/usr.bin/openssl/passwd.c
index fd5d062f57..c29cccf6cf 100644
--- a/src/usr.bin/openssl/passwd.c
+++ b/src/usr.bin/openssl/passwd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: passwd.c,v 1.1 2014/08/26 17:47:25 jsing Exp $ */ 1/* $OpenBSD: passwd.c,v 1.2 2014/10/22 13:54:03 jsing Exp $ */
2 2
3#if defined OPENSSL_NO_MD5 3#if defined OPENSSL_NO_MD5
4#define NO_MD5CRYPT_1 4#define NO_MD5CRYPT_1
@@ -14,7 +14,6 @@
14#include <openssl/bio.h> 14#include <openssl/bio.h>
15#include <openssl/err.h> 15#include <openssl/err.h>
16#include <openssl/evp.h> 16#include <openssl/evp.h>
17#include <openssl/rand.h>
18 17
19#ifndef OPENSSL_NO_DES 18#ifndef OPENSSL_NO_DES
20#include <openssl/des.h> 19#include <openssl/des.h>
@@ -384,8 +383,7 @@ do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
384 if (*salt_malloc_p == NULL) 383 if (*salt_malloc_p == NULL)
385 goto err; 384 goto err;
386 } 385 }
387 if (RAND_pseudo_bytes((unsigned char *) *salt_p, 2) < 0) 386 arc4random_buf(*salt_p, 2);
388 goto err;
389 (*salt_p)[0] = cov_2char[(*salt_p)[0] & 0x3f]; /* 6 bits */ 387 (*salt_p)[0] = cov_2char[(*salt_p)[0] & 0x3f]; /* 6 bits */
390 (*salt_p)[1] = cov_2char[(*salt_p)[1] & 0x3f]; /* 6 bits */ 388 (*salt_p)[1] = cov_2char[(*salt_p)[1] & 0x3f]; /* 6 bits */
391 (*salt_p)[2] = 0; 389 (*salt_p)[2] = 0;
@@ -401,8 +399,7 @@ do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
401 if (*salt_malloc_p == NULL) 399 if (*salt_malloc_p == NULL)
402 goto err; 400 goto err;
403 } 401 }
404 if (RAND_pseudo_bytes((unsigned char *) *salt_p, 8) < 0) 402 arc4random_buf(*salt_p, 8);
405 goto err;
406 403
407 for (i = 0; i < 8; i++) 404 for (i = 0; i < 8; i++)
408 (*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f]; /* 6 bits */ 405 (*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f]; /* 6 bits */
diff --git a/src/usr.bin/openssl/rand.c b/src/usr.bin/openssl/rand.c
index dcc99e7392..6de2208b42 100644
--- a/src/usr.bin/openssl/rand.c
+++ b/src/usr.bin/openssl/rand.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rand.c,v 1.4 2014/10/13 02:46:14 bcook Exp $ */ 1/* $OpenBSD: rand.c,v 1.5 2014/10/22 13:54:03 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -61,7 +61,6 @@
61 61
62#include <openssl/bio.h> 62#include <openssl/bio.h>
63#include <openssl/err.h> 63#include <openssl/err.h>
64#include <openssl/rand.h>
65 64
66struct { 65struct {
67 int base64; 66 int base64;
@@ -171,9 +170,7 @@ rand_main(int argc, char **argv)
171 chunk = num; 170 chunk = num;
172 if (chunk > (int) sizeof(buf)) 171 if (chunk > (int) sizeof(buf))
173 chunk = sizeof(buf); 172 chunk = sizeof(buf);
174 r = RAND_bytes(buf, chunk); 173 arc4random_buf(buf, chunk);
175 if (r <= 0)
176 goto err;
177 if (rand_config.hex) { 174 if (rand_config.hex) {
178 for (i = 0; i < chunk; i++) 175 for (i = 0; i < chunk; i++)
179 BIO_printf(out, "%02x", buf[i]); 176 BIO_printf(out, "%02x", buf[i]);
diff --git a/src/usr.bin/openssl/s_cb.c b/src/usr.bin/openssl/s_cb.c
index 2e00abe7f1..f7d8a323a6 100644
--- a/src/usr.bin/openssl/s_cb.c
+++ b/src/usr.bin/openssl/s_cb.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s_cb.c,v 1.1 2014/08/26 17:47:25 jsing Exp $ */ 1/* $OpenBSD: s_cb.c,v 1.2 2014/10/22 13:54:03 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -121,7 +121,6 @@
121#include "apps.h" 121#include "apps.h"
122 122
123#include <openssl/err.h> 123#include <openssl/err.h>
124#include <openssl/rand.h>
125#include <openssl/ssl.h> 124#include <openssl/ssl.h>
126#include <openssl/x509.h> 125#include <openssl/x509.h>
127 126
@@ -728,11 +727,7 @@ generate_cookie_callback(SSL * ssl, unsigned char *cookie,
728 727
729 /* Initialize a random secret */ 728 /* Initialize a random secret */
730 if (!cookie_initialized) { 729 if (!cookie_initialized) {
731 if (!RAND_bytes(cookie_secret, COOKIE_SECRET_LENGTH)) { 730 arc4random_buf(cookie_secret, COOKIE_SECRET_LENGTH);
732 BIO_printf(bio_err,
733 "error setting random cookie secret\n");
734 return 0;
735 }
736 cookie_initialized = 1; 731 cookie_initialized = 1;
737 } 732 }
738 /* Read peer information */ 733 /* Read peer information */
diff --git a/src/usr.bin/openssl/s_server.c b/src/usr.bin/openssl/s_server.c
index 9ca13dd335..6f87819d1e 100644
--- a/src/usr.bin/openssl/s_server.c
+++ b/src/usr.bin/openssl/s_server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s_server.c,v 1.2 2014/10/13 02:39:09 bcook Exp $ */ 1/* $OpenBSD: s_server.c,v 1.3 2014/10/22 13:54:03 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -166,7 +166,6 @@
166#include <openssl/lhash.h> 166#include <openssl/lhash.h>
167#include <openssl/ocsp.h> 167#include <openssl/ocsp.h>
168#include <openssl/pem.h> 168#include <openssl/pem.h>
169#include <openssl/rand.h>
170#include <openssl/ssl.h> 169#include <openssl/ssl.h>
171#include <openssl/x509.h> 170#include <openssl/x509.h>
172 171
@@ -2130,7 +2129,7 @@ generate_session_id(const SSL * ssl, unsigned char *id,
2130{ 2129{
2131 unsigned int count = 0; 2130 unsigned int count = 0;
2132 do { 2131 do {
2133 RAND_pseudo_bytes(id, *id_len); 2132 arc4random_buf(id, *id_len);
2134 /* 2133 /*
2135 * Prefix the session_id with the required prefix. NB: If our 2134 * Prefix the session_id with the required prefix. NB: If our
2136 * prefix is too long, clip it - but there will be worse 2135 * prefix is too long, clip it - but there will be worse
diff --git a/src/usr.bin/openssl/speed.c b/src/usr.bin/openssl/speed.c
index 82a0f90f05..ccaef15f68 100644
--- a/src/usr.bin/openssl/speed.c
+++ b/src/usr.bin/openssl/speed.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: speed.c,v 1.1 2014/08/26 17:47:25 jsing Exp $ */ 1/* $OpenBSD: speed.c,v 1.2 2014/10/22 13:54:03 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -98,7 +98,6 @@
98#include <openssl/evp.h> 98#include <openssl/evp.h>
99#include <openssl/modes.h> 99#include <openssl/modes.h>
100#include <openssl/objects.h> 100#include <openssl/objects.h>
101#include <openssl/rand.h>
102#include <openssl/x509.h> 101#include <openssl/x509.h>
103 102
104#ifndef OPENSSL_NO_AES 103#ifndef OPENSSL_NO_AES
@@ -1471,7 +1470,7 @@ speed_main(int argc, char **argv)
1471 print_result(D_EVP, j, count, d); 1470 print_result(D_EVP, j, count, d);
1472 } 1471 }
1473 } 1472 }
1474 RAND_pseudo_bytes(buf, 36); 1473 arc4random_buf(buf, 36);
1475 for (j = 0; j < RSA_NUM; j++) { 1474 for (j = 0; j < RSA_NUM; j++) {
1476 int ret; 1475 int ret;
1477 if (!rsa_doit[j]) 1476 if (!rsa_doit[j])
@@ -1543,7 +1542,7 @@ speed_main(int argc, char **argv)
1543 } 1542 }
1544 } 1543 }
1545 1544
1546 RAND_pseudo_bytes(buf, 20); 1545 arc4random_buf(buf, 20);
1547 for (j = 0; j < DSA_NUM; j++) { 1546 for (j = 0; j < DSA_NUM; j++) {
1548 unsigned int kk; 1547 unsigned int kk;
1549 int ret; 1548 int ret;
diff --git a/src/usr.bin/openssl/ts.c b/src/usr.bin/openssl/ts.c
index c765465c45..cd7d9cc81e 100644
--- a/src/usr.bin/openssl/ts.c
+++ b/src/usr.bin/openssl/ts.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts.c,v 1.2 2014/08/28 14:23:52 jsing Exp $ */ 1/* $OpenBSD: ts.c,v 1.3 2014/10/22 13:54:03 jsing Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -66,7 +66,6 @@
66#include <openssl/bn.h> 66#include <openssl/bn.h>
67#include <openssl/err.h> 67#include <openssl/err.h>
68#include <openssl/pem.h> 68#include <openssl/pem.h>
69#include <openssl/rand.h>
70#include <openssl/ts.h> 69#include <openssl/ts.h>
71 70
72/* Length of the nonce of the request in bits (must be a multiple of 8). */ 71/* Length of the nonce of the request in bits (must be a multiple of 8). */
@@ -593,8 +592,7 @@ create_nonce(int bits)
593 /* Generating random byte sequence. */ 592 /* Generating random byte sequence. */
594 if (len > (int) sizeof(buf)) 593 if (len > (int) sizeof(buf))
595 goto err; 594 goto err;
596 if (RAND_bytes(buf, len) <= 0) 595 arc4random_buf(buf, len);
597 goto err;
598 596
599 /* Find the first non-zero byte and creating ASN1_INTEGER object. */ 597 /* Find the first non-zero byte and creating ASN1_INTEGER object. */
600 for (i = 0; i < len && !buf[i]; ++i) 598 for (i = 0; i < len && !buf[i]; ++i)