diff options
author | jsing <> | 2014-10-22 13:02:04 +0000 |
---|---|---|
committer | jsing <> | 2014-10-22 13:02:04 +0000 |
commit | a2960bc2e14b4c5f7d8f78d2a69ebb537ca4afa8 (patch) | |
tree | 32d920c77e1ecf12be5fad632b9ae71343194a7c | |
parent | 5a6d7fd5a10b0ad084948463b25822d91091b325 (diff) | |
download | openbsd-a2960bc2e14b4c5f7d8f78d2a69ebb537ca4afa8.tar.gz openbsd-a2960bc2e14b4c5f7d8f78d2a69ebb537ca4afa8.tar.bz2 openbsd-a2960bc2e14b4c5f7d8f78d2a69ebb537ca4afa8.zip |
Use arc4random_buf() instead of RAND_bytes() or RAND_pseudo_bytes().
arc4random_buf() is guaranteed to always succeed - it is worth noting
that a number of the replaced function calls were already missing return
value checks.
ok deraadt@
54 files changed, 202 insertions, 260 deletions
diff --git a/src/lib/libcrypto/asn1/asn_mime.c b/src/lib/libcrypto/asn1/asn_mime.c index c153deca1e..afa0abd696 100644 --- a/src/lib/libcrypto/asn1/asn_mime.c +++ b/src/lib/libcrypto/asn1/asn_mime.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn_mime.c,v 1.22 2014/07/13 16:03:09 beck Exp $ */ | 1 | /* $OpenBSD: asn_mime.c,v 1.23 2014/10/22 13:02:03 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -54,12 +54,12 @@ | |||
54 | 54 | ||
55 | #include <ctype.h> | 55 | #include <ctype.h> |
56 | #include <stdio.h> | 56 | #include <stdio.h> |
57 | #include <stdlib.h> | ||
57 | #include <string.h> | 58 | #include <string.h> |
58 | 59 | ||
59 | #include <openssl/asn1.h> | 60 | #include <openssl/asn1.h> |
60 | #include <openssl/asn1t.h> | 61 | #include <openssl/asn1t.h> |
61 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
62 | #include <openssl/rand.h> | ||
63 | #include <openssl/x509.h> | 63 | #include <openssl/x509.h> |
64 | 64 | ||
65 | #include "asn1_locl.h" | 65 | #include "asn1_locl.h" |
@@ -298,7 +298,7 @@ SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | |||
298 | if ((flags & SMIME_DETACHED) && data) { | 298 | if ((flags & SMIME_DETACHED) && data) { |
299 | /* We want multipart/signed */ | 299 | /* We want multipart/signed */ |
300 | /* Generate a random boundary */ | 300 | /* Generate a random boundary */ |
301 | RAND_pseudo_bytes((unsigned char *)bound, 32); | 301 | arc4random_buf(bound, 32); |
302 | for (i = 0; i < 32; i++) { | 302 | for (i = 0; i < 32; i++) { |
303 | c = bound[i] & 0xf; | 303 | c = bound[i] & 0xf; |
304 | if (c < 10) | 304 | if (c < 10) |
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c index ba892b185c..44fbb648be 100644 --- a/src/lib/libcrypto/asn1/p5_pbe.c +++ b/src/lib/libcrypto/asn1/p5_pbe.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p5_pbe.c,v 1.16 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: p5_pbe.c,v 1.17 2014/10/22 13:02:03 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 1999. | 3 | * project 1999. |
4 | */ | 4 | */ |
@@ -57,11 +57,11 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/asn1t.h> | 63 | #include <openssl/asn1t.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/rand.h> | ||
65 | #include <openssl/x509.h> | 65 | #include <openssl/x509.h> |
66 | 66 | ||
67 | /* PKCS#5 password based encryption structure */ | 67 | /* PKCS#5 password based encryption structure */ |
@@ -104,8 +104,8 @@ PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, | |||
104 | sstr = ASN1_STRING_data(pbe->salt); | 104 | sstr = ASN1_STRING_data(pbe->salt); |
105 | if (salt) | 105 | if (salt) |
106 | memcpy(sstr, salt, saltlen); | 106 | memcpy(sstr, salt, saltlen); |
107 | else if (RAND_pseudo_bytes(sstr, saltlen) < 0) | 107 | else |
108 | goto err; | 108 | arc4random_buf(sstr, saltlen); |
109 | 109 | ||
110 | if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) { | 110 | if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) { |
111 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); | 111 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); |
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c index 8085aba453..0947965219 100644 --- a/src/lib/libcrypto/asn1/p5_pbev2.c +++ b/src/lib/libcrypto/asn1/p5_pbev2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p5_pbev2.c,v 1.17 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: p5_pbev2.c,v 1.18 2014/10/22 13:02:03 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 1999-2004. | 3 | * project 1999-2004. |
4 | */ | 4 | */ |
@@ -57,11 +57,11 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/asn1t.h> | 63 | #include <openssl/asn1t.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/rand.h> | ||
65 | #include <openssl/x509.h> | 65 | #include <openssl/x509.h> |
66 | 66 | ||
67 | /* PKCS#5 v2.0 password based encryption structures */ | 67 | /* PKCS#5 v2.0 password based encryption structures */ |
@@ -121,9 +121,8 @@ PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt, | |||
121 | if (EVP_CIPHER_iv_length(cipher)) { | 121 | if (EVP_CIPHER_iv_length(cipher)) { |
122 | if (aiv) | 122 | if (aiv) |
123 | memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher)); | 123 | memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher)); |
124 | else if (RAND_pseudo_bytes(iv, | 124 | else |
125 | EVP_CIPHER_iv_length(cipher)) < 0) | 125 | arc4random_buf(iv, EVP_CIPHER_iv_length(cipher)); |
126 | goto err; | ||
127 | } | 126 | } |
128 | 127 | ||
129 | EVP_CIPHER_CTX_init(&ctx); | 128 | EVP_CIPHER_CTX_init(&ctx); |
@@ -227,8 +226,8 @@ PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, int prf_nid, | |||
227 | 226 | ||
228 | if (salt) | 227 | if (salt) |
229 | memcpy (osalt->data, salt, saltlen); | 228 | memcpy (osalt->data, salt, saltlen); |
230 | else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) | 229 | else |
231 | goto merr; | 230 | arc4random_buf(osalt->data, saltlen); |
232 | 231 | ||
233 | if (iter <= 0) | 232 | if (iter <= 0) |
234 | iter = PKCS5_DEFAULT_ITER; | 233 | iter = PKCS5_DEFAULT_ITER; |
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c index 86a13a8bc8..a86feb49c2 100644 --- a/src/lib/libcrypto/bio/bf_nbio.c +++ b/src/lib/libcrypto/bio/bf_nbio.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bf_nbio.c,v 1.17 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: bf_nbio.c,v 1.18 2014/10/22 13:02: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 | * |
@@ -58,9 +58,9 @@ | |||
58 | 58 | ||
59 | #include <errno.h> | 59 | #include <errno.h> |
60 | #include <stdio.h> | 60 | #include <stdio.h> |
61 | #include <stdlib.h> | ||
61 | 62 | ||
62 | #include <openssl/bio.h> | 63 | #include <openssl/bio.h> |
63 | #include <openssl/rand.h> | ||
64 | 64 | ||
65 | /* BIO_put and BIO_get both add to the digest, | 65 | /* BIO_put and BIO_get both add to the digest, |
66 | * BIO_gets returns the digest */ | 66 | * BIO_gets returns the digest */ |
@@ -142,7 +142,7 @@ nbiof_read(BIO *b, char *out, int outl) | |||
142 | 142 | ||
143 | BIO_clear_retry_flags(b); | 143 | BIO_clear_retry_flags(b); |
144 | #if 1 | 144 | #if 1 |
145 | RAND_pseudo_bytes(&n, 1); | 145 | arc4random_buf(&n, 1); |
146 | num = (n & 0x07); | 146 | num = (n & 0x07); |
147 | 147 | ||
148 | if (outl > num) | 148 | if (outl > num) |
@@ -182,7 +182,7 @@ nbiof_write(BIO *b, const char *in, int inl) | |||
182 | num = nt->lwn; | 182 | num = nt->lwn; |
183 | nt->lwn = 0; | 183 | nt->lwn = 0; |
184 | } else { | 184 | } else { |
185 | RAND_pseudo_bytes(&n, 1); | 185 | arc4random_buf(&n, 1); |
186 | num = (n&7); | 186 | num = (n&7); |
187 | } | 187 | } |
188 | 188 | ||
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h index 155adf4fe0..10414dc339 100644 --- a/src/lib/libcrypto/bn/bn.h +++ b/src/lib/libcrypto/bn/bn.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn.h,v 1.24 2014/06/27 06:07:35 deraadt Exp $ */ | 1 | /* $OpenBSD: bn.h,v 1.25 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -125,9 +125,11 @@ | |||
125 | #ifndef HEADER_BN_H | 125 | #ifndef HEADER_BN_H |
126 | #define HEADER_BN_H | 126 | #define HEADER_BN_H |
127 | 127 | ||
128 | #include <stdio.h> | ||
129 | #include <stdlib.h> | ||
130 | |||
128 | #include <openssl/opensslconf.h> | 131 | #include <openssl/opensslconf.h> |
129 | 132 | ||
130 | #include <stdio.h> /* FILE */ | ||
131 | #include <openssl/ossl_typ.h> | 133 | #include <openssl/ossl_typ.h> |
132 | #include <openssl/crypto.h> | 134 | #include <openssl/crypto.h> |
133 | 135 | ||
@@ -673,11 +675,6 @@ BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */ | |||
673 | #include <assert.h> | 675 | #include <assert.h> |
674 | 676 | ||
675 | #ifdef BN_DEBUG_RAND | 677 | #ifdef BN_DEBUG_RAND |
676 | /* To avoid "make update" cvs wars due to BN_DEBUG, use some tricks */ | ||
677 | #ifndef RAND_pseudo_bytes | ||
678 | int RAND_pseudo_bytes(unsigned char *buf, int num); | ||
679 | #define BN_DEBUG_TRIX | ||
680 | #endif | ||
681 | #define bn_pollute(a) \ | 678 | #define bn_pollute(a) \ |
682 | do { \ | 679 | do { \ |
683 | const BIGNUM *_bnum1 = (a); \ | 680 | const BIGNUM *_bnum1 = (a); \ |
@@ -688,17 +685,15 @@ int RAND_pseudo_bytes(unsigned char *buf, int num); | |||
688 | * wouldn't be constructed with top!=dmax. */ \ | 685 | * wouldn't be constructed with top!=dmax. */ \ |
689 | BN_ULONG *_not_const; \ | 686 | BN_ULONG *_not_const; \ |
690 | memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \ | 687 | memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \ |
691 | RAND_pseudo_bytes(&_tmp_char, 1); \ | 688 | arc4random_buf(&_tmp_char, 1); \ |
692 | memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \ | 689 | memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \ |
693 | (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \ | 690 | (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \ |
694 | } \ | 691 | } \ |
695 | } while(0) | 692 | } while(0) |
696 | #ifdef BN_DEBUG_TRIX | ||
697 | #undef RAND_pseudo_bytes | ||
698 | #endif | ||
699 | #else | 693 | #else |
700 | #define bn_pollute(a) | 694 | #define bn_pollute(a) |
701 | #endif | 695 | #endif |
696 | |||
702 | #define bn_check_top(a) \ | 697 | #define bn_check_top(a) \ |
703 | do { \ | 698 | do { \ |
704 | const BIGNUM *_bnum2 = (a); \ | 699 | const BIGNUM *_bnum2 = (a); \ |
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c index acb17882ef..334c65dd57 100644 --- a/src/lib/libcrypto/bn/bn_rand.c +++ b/src/lib/libcrypto/bn/bn_rand.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_rand.c,v 1.15 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: bn_rand.c,v 1.16 2014/10/22 13:02:04 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 | * |
@@ -110,10 +110,10 @@ | |||
110 | */ | 110 | */ |
111 | 111 | ||
112 | #include <stdio.h> | 112 | #include <stdio.h> |
113 | #include <stdlib.h> | ||
113 | #include <time.h> | 114 | #include <time.h> |
114 | 115 | ||
115 | #include <openssl/err.h> | 116 | #include <openssl/err.h> |
116 | #include <openssl/rand.h> | ||
117 | 117 | ||
118 | #include "bn_lcl.h" | 118 | #include "bn_lcl.h" |
119 | 119 | ||
@@ -139,14 +139,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom) | |||
139 | } | 139 | } |
140 | 140 | ||
141 | /* make a random number and set the top and bottom bits */ | 141 | /* make a random number and set the top and bottom bits */ |
142 | 142 | arc4random_buf(buf, bytes); | |
143 | if (pseudorand) { | ||
144 | if (RAND_pseudo_bytes(buf, bytes) == -1) | ||
145 | goto err; | ||
146 | } else { | ||
147 | if (RAND_bytes(buf, bytes) <= 0) | ||
148 | goto err; | ||
149 | } | ||
150 | 143 | ||
151 | #if 1 | 144 | #if 1 |
152 | if (pseudorand == 2) { | 145 | if (pseudorand == 2) { |
@@ -156,7 +149,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom) | |||
156 | unsigned char c; | 149 | unsigned char c; |
157 | 150 | ||
158 | for (i = 0; i < bytes; i++) { | 151 | for (i = 0; i < bytes; i++) { |
159 | RAND_pseudo_bytes(&c, 1); | 152 | arc4random_buf(&c, 1); |
160 | if (c >= 128 && i > 0) | 153 | if (c >= 128 && i > 0) |
161 | buf[i] = buf[i - 1]; | 154 | buf[i] = buf[i - 1]; |
162 | else if (c < 42) | 155 | else if (c < 42) |
diff --git a/src/lib/libcrypto/cms/cms_enc.c b/src/lib/libcrypto/cms/cms_enc.c index efe19a3131..f97e4d5f34 100644 --- a/src/lib/libcrypto/cms/cms_enc.c +++ b/src/lib/libcrypto/cms/cms_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_enc.c,v 1.5 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: cms_enc.c,v 1.6 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -51,11 +51,12 @@ | |||
51 | * ==================================================================== | 51 | * ==================================================================== |
52 | */ | 52 | */ |
53 | 53 | ||
54 | #include <stdlib.h> | ||
55 | |||
54 | #include <openssl/asn1t.h> | 56 | #include <openssl/asn1t.h> |
55 | #include <openssl/cms.h> | 57 | #include <openssl/cms.h> |
56 | #include <openssl/err.h> | 58 | #include <openssl/err.h> |
57 | #include <openssl/pem.h> | 59 | #include <openssl/pem.h> |
58 | #include <openssl/rand.h> | ||
59 | #include <openssl/x509v3.h> | 60 | #include <openssl/x509v3.h> |
60 | 61 | ||
61 | #include "cms_lcl.h" | 62 | #include "cms_lcl.h" |
@@ -119,8 +120,7 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) | |||
119 | /* Generate a random IV if we need one */ | 120 | /* Generate a random IV if we need one */ |
120 | ivlen = EVP_CIPHER_CTX_iv_length(ctx); | 121 | ivlen = EVP_CIPHER_CTX_iv_length(ctx); |
121 | if (ivlen > 0) { | 122 | if (ivlen > 0) { |
122 | if (RAND_pseudo_bytes(iv, ivlen) <= 0) | 123 | arc4random_buf(iv, ivlen); |
123 | goto err; | ||
124 | piv = iv; | 124 | piv = iv; |
125 | } | 125 | } |
126 | } else if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0) { | 126 | } else if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0) { |
diff --git a/src/lib/libcrypto/cms/cms_ess.c b/src/lib/libcrypto/cms/cms_ess.c index e3b7e7da4c..fca62e0627 100644 --- a/src/lib/libcrypto/cms/cms_ess.c +++ b/src/lib/libcrypto/cms/cms_ess.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_ess.c,v 1.6 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: cms_ess.c,v 1.7 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -51,11 +51,12 @@ | |||
51 | * ==================================================================== | 51 | * ==================================================================== |
52 | */ | 52 | */ |
53 | 53 | ||
54 | #include <stdlib.h> | ||
55 | |||
54 | #include <openssl/asn1t.h> | 56 | #include <openssl/asn1t.h> |
55 | #include <openssl/cms.h> | 57 | #include <openssl/cms.h> |
56 | #include <openssl/err.h> | 58 | #include <openssl/err.h> |
57 | #include <openssl/pem.h> | 59 | #include <openssl/pem.h> |
58 | #include <openssl/rand.h> | ||
59 | #include <openssl/x509v3.h> | 60 | #include <openssl/x509v3.h> |
60 | 61 | ||
61 | #include "cms_lcl.h" | 62 | #include "cms_lcl.h" |
@@ -105,9 +106,7 @@ CMS_ReceiptRequest_create0(unsigned char *id, int idlen, int allorfirst, | |||
105 | else { | 106 | else { |
106 | if (!ASN1_STRING_set(rr->signedContentIdentifier, NULL, 32)) | 107 | if (!ASN1_STRING_set(rr->signedContentIdentifier, NULL, 32)) |
107 | goto merr; | 108 | goto merr; |
108 | if (RAND_pseudo_bytes(rr->signedContentIdentifier->data, 32) | 109 | arc4random_buf(rr->signedContentIdentifier->data, 32); |
109 | <= 0) | ||
110 | goto err; | ||
111 | } | 110 | } |
112 | 111 | ||
113 | sk_GENERAL_NAMES_pop_free(rr->receiptsTo, GENERAL_NAMES_free); | 112 | sk_GENERAL_NAMES_pop_free(rr->receiptsTo, GENERAL_NAMES_free); |
diff --git a/src/lib/libcrypto/cms/cms_pwri.c b/src/lib/libcrypto/cms/cms_pwri.c index b7c3038027..89f7925938 100644 --- a/src/lib/libcrypto/cms/cms_pwri.c +++ b/src/lib/libcrypto/cms/cms_pwri.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_pwri.c,v 1.7 2014/07/11 15:42:34 miod Exp $ */ | 1 | /* $OpenBSD: cms_pwri.c,v 1.8 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -51,12 +51,13 @@ | |||
51 | * ==================================================================== | 51 | * ==================================================================== |
52 | */ | 52 | */ |
53 | 53 | ||
54 | #include <stdlib.h> | ||
55 | |||
54 | #include <openssl/aes.h> | 56 | #include <openssl/aes.h> |
55 | #include <openssl/asn1t.h> | 57 | #include <openssl/asn1t.h> |
56 | #include <openssl/cms.h> | 58 | #include <openssl/cms.h> |
57 | #include <openssl/err.h> | 59 | #include <openssl/err.h> |
58 | #include <openssl/pem.h> | 60 | #include <openssl/pem.h> |
59 | #include <openssl/rand.h> | ||
60 | #include <openssl/x509v3.h> | 61 | #include <openssl/x509v3.h> |
61 | 62 | ||
62 | #include "asn1_locl.h" | 63 | #include "asn1_locl.h" |
@@ -130,8 +131,7 @@ CMS_add0_recipient_password(CMS_ContentInfo *cms, int iter, int wrap_nid, | |||
130 | ivlen = EVP_CIPHER_CTX_iv_length(&ctx); | 131 | ivlen = EVP_CIPHER_CTX_iv_length(&ctx); |
131 | 132 | ||
132 | if (ivlen > 0) { | 133 | if (ivlen > 0) { |
133 | if (RAND_pseudo_bytes(iv, ivlen) <= 0) | 134 | arc4random_buf(iv, ivlen); |
134 | goto err; | ||
135 | if (EVP_EncryptInit_ex(&ctx, NULL, NULL, NULL, iv) <= 0) { | 135 | if (EVP_EncryptInit_ex(&ctx, NULL, NULL, NULL, iv) <= 0) { |
136 | CMSerr(CMS_F_CMS_ADD0_RECIPIENT_PASSWORD, | 136 | CMSerr(CMS_F_CMS_ADD0_RECIPIENT_PASSWORD, |
137 | ERR_R_EVP_LIB); | 137 | ERR_R_EVP_LIB); |
@@ -297,7 +297,7 @@ kek_wrap_key(unsigned char *out, size_t *outlen, const unsigned char *in, | |||
297 | memcpy(out + 4, in, inlen); | 297 | memcpy(out + 4, in, inlen); |
298 | /* Add random padding to end */ | 298 | /* Add random padding to end */ |
299 | if (olen > inlen + 4) | 299 | if (olen > inlen + 4) |
300 | RAND_pseudo_bytes(out + 4 + inlen, olen - 4 - inlen); | 300 | arc4random_buf(out + 4 + inlen, olen - 4 - inlen); |
301 | /* Encrypt twice */ | 301 | /* Encrypt twice */ |
302 | EVP_EncryptUpdate(ctx, out, &dummy, out, olen); | 302 | EVP_EncryptUpdate(ctx, out, &dummy, out, olen); |
303 | EVP_EncryptUpdate(ctx, out, &dummy, out, olen); | 303 | EVP_EncryptUpdate(ctx, out, &dummy, out, olen); |
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c index a7049ff44e..0130c2c6d9 100644 --- a/src/lib/libcrypto/des/enc_writ.c +++ b/src/lib/libcrypto/des/enc_writ.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: enc_writ.c,v 1.12 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: enc_writ.c,v 1.13 2014/10/22 13:02:04 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 | * |
@@ -58,12 +58,11 @@ | |||
58 | 58 | ||
59 | #include <errno.h> | 59 | #include <errno.h> |
60 | #include <stdio.h> | 60 | #include <stdio.h> |
61 | #include <stdlib.h> | ||
61 | #include <time.h> | 62 | #include <time.h> |
62 | 63 | ||
63 | #include <openssl/opensslconf.h> | 64 | #include <openssl/opensslconf.h> |
64 | 65 | ||
65 | #include <openssl/rand.h> | ||
66 | |||
67 | #include "des_locl.h" | 66 | #include "des_locl.h" |
68 | 67 | ||
69 | /* | 68 | /* |
@@ -136,7 +135,7 @@ int DES_enc_write(int fd, const void *_buf, int len, | |||
136 | { | 135 | { |
137 | cp=shortbuf; | 136 | cp=shortbuf; |
138 | memcpy(shortbuf,buf,len); | 137 | memcpy(shortbuf,buf,len); |
139 | RAND_pseudo_bytes(shortbuf+len, 8-len); | 138 | arc4random_buf(shortbuf+len, 8-len); |
140 | rnum=8; | 139 | rnum=8; |
141 | } | 140 | } |
142 | else | 141 | else |
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c index 727d36f488..7abb811df4 100644 --- a/src/lib/libcrypto/des/rand_key.c +++ b/src/lib/libcrypto/des/rand_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rand_key.c,v 1.7 2014/07/22 18:09:20 miod Exp $ */ | 1 | /* $OpenBSD: rand_key.c,v 1.8 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -53,15 +53,15 @@ | |||
53 | * | 53 | * |
54 | */ | 54 | */ |
55 | 55 | ||
56 | #include <stdlib.h> | ||
57 | |||
56 | #include <openssl/des.h> | 58 | #include <openssl/des.h> |
57 | #include <openssl/rand.h> | ||
58 | 59 | ||
59 | int | 60 | int |
60 | DES_random_key(DES_cblock *ret) | 61 | DES_random_key(DES_cblock *ret) |
61 | { | 62 | { |
62 | do { | 63 | do { |
63 | if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1) | 64 | arc4random_buf(ret, sizeof(DES_cblock)); |
64 | return (0); | ||
65 | DES_set_odd_parity(ret); | 65 | DES_set_odd_parity(ret); |
66 | } while (DES_is_weak_key(ret)); | 66 | } while (DES_is_weak_key(ret)); |
67 | return (1); | 67 | return (1); |
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c index a3d07b901a..296a544c31 100644 --- a/src/lib/libcrypto/dsa/dsa_gen.c +++ b/src/lib/libcrypto/dsa/dsa_gen.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dsa_gen.c,v 1.16 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: dsa_gen.c,v 1.17 2014/10/22 13:02:04 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 | * |
@@ -61,11 +61,11 @@ | |||
61 | #ifndef OPENSSL_NO_SHA | 61 | #ifndef OPENSSL_NO_SHA |
62 | 62 | ||
63 | #include <stdio.h> | 63 | #include <stdio.h> |
64 | #include <stdlib.h> | ||
64 | #include <string.h> | 65 | #include <string.h> |
65 | 66 | ||
66 | #include <openssl/bn.h> | 67 | #include <openssl/bn.h> |
67 | #include <openssl/evp.h> | 68 | #include <openssl/evp.h> |
68 | #include <openssl/rand.h> | ||
69 | #include <openssl/sha.h> | 69 | #include <openssl/sha.h> |
70 | 70 | ||
71 | #include "dsa_locl.h" | 71 | #include "dsa_locl.h" |
@@ -169,7 +169,7 @@ dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, const EVP_MD *evpmd, | |||
169 | goto err; | 169 | goto err; |
170 | 170 | ||
171 | if (!seed_len) { | 171 | if (!seed_len) { |
172 | RAND_pseudo_bytes(seed, qsize); | 172 | arc4random_buf(seed, qsize); |
173 | seed_is_random = 1; | 173 | seed_is_random = 1; |
174 | } else { | 174 | } else { |
175 | seed_is_random = 0; | 175 | seed_is_random = 0; |
diff --git a/src/lib/libcrypto/engine/eng_lib.c b/src/lib/libcrypto/engine/eng_lib.c index 118fa6cb9c..b3b9213d87 100644 --- a/src/lib/libcrypto/engine/eng_lib.c +++ b/src/lib/libcrypto/engine/eng_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: eng_lib.c,v 1.9 2014/07/10 13:58:22 jsing Exp $ */ | 1 | /* $OpenBSD: eng_lib.c,v 1.10 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -58,9 +58,10 @@ | |||
58 | 58 | ||
59 | #include <string.h> | 59 | #include <string.h> |
60 | 60 | ||
61 | #include "eng_int.h" | ||
62 | #include <openssl/rand.h> | 61 | #include <openssl/rand.h> |
63 | 62 | ||
63 | #include "eng_int.h" | ||
64 | |||
64 | /* The "new"/"free" stuff first */ | 65 | /* The "new"/"free" stuff first */ |
65 | 66 | ||
66 | ENGINE * | 67 | ENGINE * |
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c index f96a15f19c..bb3b420a3b 100644 --- a/src/lib/libcrypto/evp/e_aes.c +++ b/src/lib/libcrypto/evp/e_aes.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_aes.c,v 1.25 2014/07/12 19:31:03 miod Exp $ */ | 1 | /* $OpenBSD: e_aes.c,v 1.26 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -50,6 +50,7 @@ | |||
50 | */ | 50 | */ |
51 | 51 | ||
52 | #include <assert.h> | 52 | #include <assert.h> |
53 | #include <stdlib.h> | ||
53 | #include <string.h> | 54 | #include <string.h> |
54 | 55 | ||
55 | #include <openssl/opensslconf.h> | 56 | #include <openssl/opensslconf.h> |
@@ -58,7 +59,6 @@ | |||
58 | #include <openssl/aes.h> | 59 | #include <openssl/aes.h> |
59 | #include <openssl/err.h> | 60 | #include <openssl/err.h> |
60 | #include <openssl/evp.h> | 61 | #include <openssl/evp.h> |
61 | #include <openssl/rand.h> | ||
62 | 62 | ||
63 | #include "evp_locl.h" | 63 | #include "evp_locl.h" |
64 | #include "modes_lcl.h" | 64 | #include "modes_lcl.h" |
@@ -769,9 +769,8 @@ aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | |||
769 | return 0; | 769 | return 0; |
770 | if (arg) | 770 | if (arg) |
771 | memcpy(gctx->iv, ptr, arg); | 771 | memcpy(gctx->iv, ptr, arg); |
772 | if (c->encrypt && | 772 | if (c->encrypt) |
773 | RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0) | 773 | arc4random_buf(gctx->iv + arg, gctx->ivlen - arg); |
774 | return 0; | ||
775 | gctx->iv_gen = 1; | 774 | gctx->iv_gen = 1; |
776 | return 1; | 775 | return 1; |
777 | 776 | ||
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index 4333e4dff8..49ceacefad 100644 --- a/src/lib/libcrypto/evp/evp_enc.c +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_enc.c,v 1.24 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: evp_enc.c,v 1.25 2014/10/22 13:02:04 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 | * |
@@ -57,13 +57,13 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/opensslconf.h> | 63 | #include <openssl/opensslconf.h> |
63 | 64 | ||
64 | #include <openssl/err.h> | 65 | #include <openssl/err.h> |
65 | #include <openssl/evp.h> | 66 | #include <openssl/evp.h> |
66 | #include <openssl/rand.h> | ||
67 | 67 | ||
68 | #ifndef OPENSSL_NO_ENGINE | 68 | #ifndef OPENSSL_NO_ENGINE |
69 | #include <openssl/engine.h> | 69 | #include <openssl/engine.h> |
@@ -613,8 +613,7 @@ EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key) | |||
613 | { | 613 | { |
614 | if (ctx->cipher->flags & EVP_CIPH_RAND_KEY) | 614 | if (ctx->cipher->flags & EVP_CIPH_RAND_KEY) |
615 | return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key); | 615 | return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key); |
616 | if (RAND_bytes(key, ctx->key_len) <= 0) | 616 | arc4random_buf(key, ctx->key_len); |
617 | return 0; | ||
618 | return 1; | 617 | return 1; |
619 | } | 618 | } |
620 | 619 | ||
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c index 4f8417ae64..8b9740fbcd 100644 --- a/src/lib/libcrypto/evp/p_seal.c +++ b/src/lib/libcrypto/evp/p_seal.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p_seal.c,v 1.13 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: p_seal.c,v 1.14 2014/10/22 13:02:04 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 | * |
@@ -57,12 +57,12 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | 61 | ||
61 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
62 | 63 | ||
63 | #include <openssl/evp.h> | 64 | #include <openssl/evp.h> |
64 | #include <openssl/objects.h> | 65 | #include <openssl/objects.h> |
65 | #include <openssl/rand.h> | ||
66 | #include <openssl/x509.h> | 66 | #include <openssl/x509.h> |
67 | 67 | ||
68 | #ifndef OPENSSL_NO_RSA | 68 | #ifndef OPENSSL_NO_RSA |
@@ -86,7 +86,7 @@ EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek, | |||
86 | if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) | 86 | if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) |
87 | return 0; | 87 | return 0; |
88 | if (EVP_CIPHER_CTX_iv_length(ctx)) | 88 | if (EVP_CIPHER_CTX_iv_length(ctx)) |
89 | RAND_pseudo_bytes(iv, EVP_CIPHER_CTX_iv_length(ctx)); | 89 | arc4random_buf(iv, EVP_CIPHER_CTX_iv_length(ctx)); |
90 | 90 | ||
91 | if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) | 91 | if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) |
92 | return 0; | 92 | return 0; |
diff --git a/src/lib/libcrypto/ocsp/ocsp_ext.c b/src/lib/libcrypto/ocsp/ocsp_ext.c index c7b9d817ac..6318e1718b 100644 --- a/src/lib/libcrypto/ocsp/ocsp_ext.c +++ b/src/lib/libcrypto/ocsp/ocsp_ext.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ocsp_ext.c,v 1.11 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: ocsp_ext.c,v 1.12 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL | 2 | /* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL |
3 | * project. */ | 3 | * project. */ |
4 | 4 | ||
@@ -62,11 +62,11 @@ | |||
62 | */ | 62 | */ |
63 | 63 | ||
64 | #include <stdio.h> | 64 | #include <stdio.h> |
65 | #include <stdlib.h> | ||
65 | #include <string.h> | 66 | #include <string.h> |
66 | 67 | ||
67 | #include <openssl/objects.h> | 68 | #include <openssl/objects.h> |
68 | #include <openssl/ocsp.h> | 69 | #include <openssl/ocsp.h> |
69 | #include <openssl/rand.h> | ||
70 | #include <openssl/x509.h> | 70 | #include <openssl/x509.h> |
71 | #include <openssl/x509v3.h> | 71 | #include <openssl/x509v3.h> |
72 | 72 | ||
@@ -389,7 +389,7 @@ ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len) | |||
389 | if (val) | 389 | if (val) |
390 | memcpy(tmpval, val, len); | 390 | memcpy(tmpval, val, len); |
391 | else | 391 | else |
392 | RAND_pseudo_bytes(tmpval, len); | 392 | arc4random_buf(tmpval, len); |
393 | if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce, &os, 0, | 393 | if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce, &os, 0, |
394 | X509V3_ADD_REPLACE)) | 394 | X509V3_ADD_REPLACE)) |
395 | goto err; | 395 | goto err; |
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c index 26b1876f36..1ebae53e74 100644 --- a/src/lib/libcrypto/pem/pem_lib.c +++ b/src/lib/libcrypto/pem/pem_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pem_lib.c,v 1.34 2014/07/23 20:43:56 miod Exp $ */ | 1 | /* $OpenBSD: pem_lib.c,v 1.35 2014/10/22 13:02:04 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 | * |
@@ -58,6 +58,7 @@ | |||
58 | 58 | ||
59 | #include <ctype.h> | 59 | #include <ctype.h> |
60 | #include <stdio.h> | 60 | #include <stdio.h> |
61 | #include <stdlib.h> | ||
61 | #include <string.h> | 62 | #include <string.h> |
62 | 63 | ||
63 | #include <openssl/opensslconf.h> | 64 | #include <openssl/opensslconf.h> |
@@ -67,7 +68,6 @@ | |||
67 | #include <openssl/objects.h> | 68 | #include <openssl/objects.h> |
68 | #include <openssl/pem.h> | 69 | #include <openssl/pem.h> |
69 | #include <openssl/pkcs12.h> | 70 | #include <openssl/pkcs12.h> |
70 | #include <openssl/rand.h> | ||
71 | #include <openssl/x509.h> | 71 | #include <openssl/x509.h> |
72 | 72 | ||
73 | #ifndef OPENSSL_NO_DES | 73 | #ifndef OPENSSL_NO_DES |
@@ -390,8 +390,7 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, | |||
390 | kstr = (unsigned char *)buf; | 390 | kstr = (unsigned char *)buf; |
391 | } | 391 | } |
392 | OPENSSL_assert(enc->iv_len <= (int)sizeof(iv)); | 392 | OPENSSL_assert(enc->iv_len <= (int)sizeof(iv)); |
393 | if (RAND_pseudo_bytes(iv, enc->iv_len) < 0) /* Generate a salt */ | 393 | arc4random_buf(iv, enc->iv_len); /* Generate a salt */ |
394 | goto err; | ||
395 | /* The 'iv' is used as the iv and as a salt. It is | 394 | /* The 'iv' is used as the iv and as a salt. It is |
396 | * NOT taken from the BytesToKey function */ | 395 | * NOT taken from the BytesToKey function */ |
397 | if (!EVP_BytesToKey(enc, EVP_md5(), iv, kstr, klen, 1, | 396 | if (!EVP_BytesToKey(enc, EVP_md5(), iv, kstr, klen, 1, |
diff --git a/src/lib/libcrypto/pem/pvkfmt.c b/src/lib/libcrypto/pem/pvkfmt.c index ca7e908c29..2009c9db80 100644 --- a/src/lib/libcrypto/pem/pvkfmt.c +++ b/src/lib/libcrypto/pem/pvkfmt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pvkfmt.c,v 1.11 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: pvkfmt.c,v 1.12 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2005. | 3 | * project 2005. |
4 | */ | 4 | */ |
@@ -60,6 +60,7 @@ | |||
60 | * and PRIVATEKEYBLOB). | 60 | * and PRIVATEKEYBLOB). |
61 | */ | 61 | */ |
62 | 62 | ||
63 | #include <stdlib.h> | ||
63 | #include <string.h> | 64 | #include <string.h> |
64 | 65 | ||
65 | #include <openssl/opensslconf.h> | 66 | #include <openssl/opensslconf.h> |
@@ -67,7 +68,6 @@ | |||
67 | #include <openssl/bn.h> | 68 | #include <openssl/bn.h> |
68 | #include <openssl/err.h> | 69 | #include <openssl/err.h> |
69 | #include <openssl/pem.h> | 70 | #include <openssl/pem.h> |
70 | #include <openssl/rand.h> | ||
71 | 71 | ||
72 | #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) | 72 | #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) |
73 | #include <openssl/dsa.h> | 73 | #include <openssl/dsa.h> |
@@ -869,8 +869,7 @@ i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, pem_password_cb *cb, | |||
869 | write_ledword(&p, enclevel ? PVK_SALTLEN : 0); | 869 | write_ledword(&p, enclevel ? PVK_SALTLEN : 0); |
870 | write_ledword(&p, pklen); | 870 | write_ledword(&p, pklen); |
871 | if (enclevel) { | 871 | if (enclevel) { |
872 | if (RAND_bytes(p, PVK_SALTLEN) <= 0) | 872 | arc4random_buf(p, PVK_SALTLEN); |
873 | goto error; | ||
874 | salt = p; | 873 | salt = p; |
875 | p += PVK_SALTLEN; | 874 | p += PVK_SALTLEN; |
876 | } | 875 | } |
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c index 453d30d65f..0c49bf96fd 100644 --- a/src/lib/libcrypto/pkcs12/p12_mutl.c +++ b/src/lib/libcrypto/pkcs12/p12_mutl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p12_mutl.c,v 1.17 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: p12_mutl.c,v 1.18 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 1999. | 3 | * project 1999. |
4 | */ | 4 | */ |
@@ -57,6 +57,7 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/opensslconf.h> | 63 | #include <openssl/opensslconf.h> |
@@ -66,7 +67,6 @@ | |||
66 | #include <openssl/err.h> | 67 | #include <openssl/err.h> |
67 | #include <openssl/hmac.h> | 68 | #include <openssl/hmac.h> |
68 | #include <openssl/pkcs12.h> | 69 | #include <openssl/pkcs12.h> |
69 | #include <openssl/rand.h> | ||
70 | 70 | ||
71 | /* Generate a MAC */ | 71 | /* Generate a MAC */ |
72 | int | 72 | int |
@@ -193,10 +193,9 @@ PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen, | |||
193 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); | 193 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); |
194 | return 0; | 194 | return 0; |
195 | } | 195 | } |
196 | if (!salt) { | 196 | if (!salt) |
197 | if (RAND_pseudo_bytes (p12->mac->salt->data, saltlen) < 0) | 197 | arc4random_buf(p12->mac->salt->data, saltlen); |
198 | return 0; | 198 | else |
199 | } else | ||
200 | memcpy (p12->mac->salt->data, salt, saltlen); | 199 | memcpy (p12->mac->salt->data, salt, saltlen); |
201 | p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); | 200 | p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); |
202 | if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { | 201 | if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { |
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c index 8f1e393635..d69aff8f41 100644 --- a/src/lib/libcrypto/pkcs7/pk7_doit.c +++ b/src/lib/libcrypto/pkcs7/pk7_doit.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pk7_doit.c,v 1.29 2014/07/25 06:05:32 doug Exp $ */ | 1 | /* $OpenBSD: pk7_doit.c,v 1.30 2014/10/22 13:02:04 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 | * |
@@ -57,11 +57,11 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/err.h> | 63 | #include <openssl/err.h> |
63 | #include <openssl/objects.h> | 64 | #include <openssl/objects.h> |
64 | #include <openssl/rand.h> | ||
65 | #include <openssl/x509.h> | 65 | #include <openssl/x509.h> |
66 | #include <openssl/x509v3.h> | 66 | #include <openssl/x509v3.h> |
67 | 67 | ||
@@ -324,8 +324,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio) | |||
324 | ivlen = EVP_CIPHER_iv_length(evp_cipher); | 324 | ivlen = EVP_CIPHER_iv_length(evp_cipher); |
325 | xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher)); | 325 | xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher)); |
326 | if (ivlen > 0) | 326 | if (ivlen > 0) |
327 | if (RAND_pseudo_bytes(iv, ivlen) <= 0) | 327 | arc4random_buf(iv, ivlen); |
328 | goto err; | ||
329 | if (EVP_CipherInit_ex(ctx, evp_cipher, NULL, NULL, | 328 | if (EVP_CipherInit_ex(ctx, evp_cipher, NULL, NULL, |
330 | NULL, 1) <= 0) | 329 | NULL, 1) <= 0) |
331 | goto err; | 330 | goto err; |
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c index 2b2c827740..8342a55f05 100644 --- a/src/lib/libcrypto/rand/rand_lib.c +++ b/src/lib/libcrypto/rand/rand_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rand_lib.c,v 1.19 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: rand_lib.c,v 1.20 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | 3 | * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> |
4 | * | 4 | * |
@@ -15,12 +15,12 @@ | |||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <stdlib.h> | ||
19 | |||
18 | #include <openssl/opensslconf.h> | 20 | #include <openssl/opensslconf.h> |
19 | 21 | ||
20 | #include <openssl/rand.h> | 22 | #include <openssl/rand.h> |
21 | 23 | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* | 24 | /* |
25 | * The useful functions in this file are at the bottom. | 25 | * The useful functions in this file are at the bottom. |
26 | */ | 26 | */ |
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index dca49b10aa..e54a009420 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: randfile.c,v 1.39 2014/07/14 00:01:39 deraadt Exp $ */ | 1 | /* $OpenBSD: randfile.c,v 1.40 2014/10/22 13:02:04 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 | * |
@@ -118,8 +118,7 @@ RAND_write_file(const char *file) | |||
118 | for (;;) { | 118 | for (;;) { |
119 | i = (n > BUFSIZE) ? BUFSIZE : n; | 119 | i = (n > BUFSIZE) ? BUFSIZE : n; |
120 | n -= BUFSIZE; | 120 | n -= BUFSIZE; |
121 | if (RAND_bytes(buf, i) <= 0) | 121 | arc4random_buf(buf, i); |
122 | rand_err = 1; | ||
123 | i = fwrite(buf, 1, i, out); | 122 | i = fwrite(buf, 1, i, out); |
124 | if (i <= 0) { | 123 | if (i <= 0) { |
125 | ret = 0; | 124 | ret = 0; |
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c index 9be0f9be31..8585d7c3aa 100644 --- a/src/lib/libcrypto/rsa/rsa_oaep.c +++ b/src/lib/libcrypto/rsa/rsa_oaep.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_oaep.c,v 1.23 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: rsa_oaep.c,v 1.24 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Ulf Moeller. This software is distributed on an "AS IS" | 2 | /* Written by Ulf Moeller. This software is distributed on an "AS IS" |
3 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ | 3 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ |
4 | 4 | ||
@@ -19,6 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | ||
22 | #include <string.h> | 23 | #include <string.h> |
23 | 24 | ||
24 | #include <openssl/opensslconf.h> | 25 | #include <openssl/opensslconf.h> |
@@ -28,7 +29,6 @@ | |||
28 | #include <openssl/bn.h> | 29 | #include <openssl/bn.h> |
29 | #include <openssl/err.h> | 30 | #include <openssl/err.h> |
30 | #include <openssl/evp.h> | 31 | #include <openssl/evp.h> |
31 | #include <openssl/rand.h> | ||
32 | #include <openssl/rsa.h> | 32 | #include <openssl/rsa.h> |
33 | #include <openssl/sha.h> | 33 | #include <openssl/sha.h> |
34 | 34 | ||
@@ -65,8 +65,7 @@ RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, | |||
65 | emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); | 65 | emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); |
66 | db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01; | 66 | db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01; |
67 | memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, flen); | 67 | memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, flen); |
68 | if (RAND_bytes(seed, SHA_DIGEST_LENGTH) <= 0) | 68 | arc4random_buf(seed, SHA_DIGEST_LENGTH); |
69 | return 0; | ||
70 | 69 | ||
71 | dbmask = malloc(emlen - SHA_DIGEST_LENGTH); | 70 | dbmask = malloc(emlen - SHA_DIGEST_LENGTH); |
72 | if (dbmask == NULL) { | 71 | if (dbmask == NULL) { |
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c index 4f82bf6768..6c3e7fb846 100644 --- a/src/lib/libcrypto/rsa/rsa_pk1.c +++ b/src/lib/libcrypto/rsa/rsa_pk1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_pk1.c,v 1.13 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: rsa_pk1.c,v 1.14 2014/10/22 13:02:04 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 | * |
@@ -57,12 +57,12 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/rsa.h> | 65 | #include <openssl/rsa.h> |
65 | #include <openssl/rand.h> | ||
66 | 66 | ||
67 | int | 67 | int |
68 | RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, | 68 | RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, |
@@ -167,13 +167,10 @@ RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, | |||
167 | /* pad out with non-zero random data */ | 167 | /* pad out with non-zero random data */ |
168 | j = tlen - 3 - flen; | 168 | j = tlen - 3 - flen; |
169 | 169 | ||
170 | if (RAND_bytes(p, j) <= 0) | 170 | arc4random_buf(p, j); |
171 | return 0; | ||
172 | for (i = 0; i < j; i++) { | 171 | for (i = 0; i < j; i++) { |
173 | while (*p == '\0') { | 172 | while (*p == '\0') |
174 | if (RAND_bytes(p, 1) <= 0) | 173 | arc4random_buf(p, 1); |
175 | return 0; | ||
176 | } | ||
177 | p++; | 174 | p++; |
178 | } | 175 | } |
179 | 176 | ||
diff --git a/src/lib/libcrypto/rsa/rsa_pss.c b/src/lib/libcrypto/rsa/rsa_pss.c index f841b2f8a3..5e137a3090 100644 --- a/src/lib/libcrypto/rsa/rsa_pss.c +++ b/src/lib/libcrypto/rsa/rsa_pss.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_pss.c,v 1.10 2014/07/13 12:53:46 miod Exp $ */ | 1 | /* $OpenBSD: rsa_pss.c,v 1.11 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2005. | 3 | * project 2005. |
4 | */ | 4 | */ |
@@ -57,12 +57,12 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/evp.h> | 65 | #include <openssl/evp.h> |
65 | #include <openssl/rand.h> | ||
66 | #include <openssl/rsa.h> | 66 | #include <openssl/rsa.h> |
67 | #include <openssl/sha.h> | 67 | #include <openssl/sha.h> |
68 | 68 | ||
@@ -243,8 +243,7 @@ RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, | |||
243 | ERR_R_MALLOC_FAILURE); | 243 | ERR_R_MALLOC_FAILURE); |
244 | goto err; | 244 | goto err; |
245 | } | 245 | } |
246 | if (RAND_bytes(salt, sLen) <= 0) | 246 | arc4random_buf(salt, sLen); |
247 | goto err; | ||
248 | } | 247 | } |
249 | maskedDBLen = emLen - hLen - 1; | 248 | maskedDBLen = emLen - hLen - 1; |
250 | H = EM + maskedDBLen; | 249 | H = EM + maskedDBLen; |
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c index a5fe5004b1..73262f29c1 100644 --- a/src/lib/libcrypto/rsa/rsa_ssl.c +++ b/src/lib/libcrypto/rsa/rsa_ssl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_ssl.c,v 1.13 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: rsa_ssl.c,v 1.14 2014/10/22 13:02:04 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 | * |
@@ -57,11 +57,11 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/rand.h> | ||
65 | #include <openssl/rsa.h> | 65 | #include <openssl/rsa.h> |
66 | 66 | ||
67 | int | 67 | int |
@@ -85,13 +85,10 @@ RSA_padding_add_SSLv23(unsigned char *to, int tlen, const unsigned char *from, | |||
85 | /* pad out with non-zero random data */ | 85 | /* pad out with non-zero random data */ |
86 | j = tlen - 3 - 8 - flen; | 86 | j = tlen - 3 - 8 - flen; |
87 | 87 | ||
88 | if (RAND_bytes(p, j) <= 0) | 88 | arc4random_buf(p, j); |
89 | return 0; | ||
90 | for (i = 0; i < j; i++) { | 89 | for (i = 0; i < j; i++) { |
91 | while (*p == '\0') { | 90 | while (*p == '\0') |
92 | if (RAND_bytes(p, 1) <= 0) | 91 | arc4random_buf(p, 1); |
93 | return 0; | ||
94 | } | ||
95 | p++; | 92 | p++; |
96 | } | 93 | } |
97 | 94 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/asn_mime.c b/src/lib/libssl/src/crypto/asn1/asn_mime.c index c153deca1e..afa0abd696 100644 --- a/src/lib/libssl/src/crypto/asn1/asn_mime.c +++ b/src/lib/libssl/src/crypto/asn1/asn_mime.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn_mime.c,v 1.22 2014/07/13 16:03:09 beck Exp $ */ | 1 | /* $OpenBSD: asn_mime.c,v 1.23 2014/10/22 13:02:03 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -54,12 +54,12 @@ | |||
54 | 54 | ||
55 | #include <ctype.h> | 55 | #include <ctype.h> |
56 | #include <stdio.h> | 56 | #include <stdio.h> |
57 | #include <stdlib.h> | ||
57 | #include <string.h> | 58 | #include <string.h> |
58 | 59 | ||
59 | #include <openssl/asn1.h> | 60 | #include <openssl/asn1.h> |
60 | #include <openssl/asn1t.h> | 61 | #include <openssl/asn1t.h> |
61 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
62 | #include <openssl/rand.h> | ||
63 | #include <openssl/x509.h> | 63 | #include <openssl/x509.h> |
64 | 64 | ||
65 | #include "asn1_locl.h" | 65 | #include "asn1_locl.h" |
@@ -298,7 +298,7 @@ SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | |||
298 | if ((flags & SMIME_DETACHED) && data) { | 298 | if ((flags & SMIME_DETACHED) && data) { |
299 | /* We want multipart/signed */ | 299 | /* We want multipart/signed */ |
300 | /* Generate a random boundary */ | 300 | /* Generate a random boundary */ |
301 | RAND_pseudo_bytes((unsigned char *)bound, 32); | 301 | arc4random_buf(bound, 32); |
302 | for (i = 0; i < 32; i++) { | 302 | for (i = 0; i < 32; i++) { |
303 | c = bound[i] & 0xf; | 303 | c = bound[i] & 0xf; |
304 | if (c < 10) | 304 | if (c < 10) |
diff --git a/src/lib/libssl/src/crypto/asn1/p5_pbe.c b/src/lib/libssl/src/crypto/asn1/p5_pbe.c index ba892b185c..44fbb648be 100644 --- a/src/lib/libssl/src/crypto/asn1/p5_pbe.c +++ b/src/lib/libssl/src/crypto/asn1/p5_pbe.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p5_pbe.c,v 1.16 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: p5_pbe.c,v 1.17 2014/10/22 13:02:03 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 1999. | 3 | * project 1999. |
4 | */ | 4 | */ |
@@ -57,11 +57,11 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/asn1t.h> | 63 | #include <openssl/asn1t.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/rand.h> | ||
65 | #include <openssl/x509.h> | 65 | #include <openssl/x509.h> |
66 | 66 | ||
67 | /* PKCS#5 password based encryption structure */ | 67 | /* PKCS#5 password based encryption structure */ |
@@ -104,8 +104,8 @@ PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, | |||
104 | sstr = ASN1_STRING_data(pbe->salt); | 104 | sstr = ASN1_STRING_data(pbe->salt); |
105 | if (salt) | 105 | if (salt) |
106 | memcpy(sstr, salt, saltlen); | 106 | memcpy(sstr, salt, saltlen); |
107 | else if (RAND_pseudo_bytes(sstr, saltlen) < 0) | 107 | else |
108 | goto err; | 108 | arc4random_buf(sstr, saltlen); |
109 | 109 | ||
110 | if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) { | 110 | if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) { |
111 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); | 111 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); |
diff --git a/src/lib/libssl/src/crypto/asn1/p5_pbev2.c b/src/lib/libssl/src/crypto/asn1/p5_pbev2.c index 8085aba453..0947965219 100644 --- a/src/lib/libssl/src/crypto/asn1/p5_pbev2.c +++ b/src/lib/libssl/src/crypto/asn1/p5_pbev2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p5_pbev2.c,v 1.17 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: p5_pbev2.c,v 1.18 2014/10/22 13:02:03 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 1999-2004. | 3 | * project 1999-2004. |
4 | */ | 4 | */ |
@@ -57,11 +57,11 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/asn1t.h> | 63 | #include <openssl/asn1t.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/rand.h> | ||
65 | #include <openssl/x509.h> | 65 | #include <openssl/x509.h> |
66 | 66 | ||
67 | /* PKCS#5 v2.0 password based encryption structures */ | 67 | /* PKCS#5 v2.0 password based encryption structures */ |
@@ -121,9 +121,8 @@ PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt, | |||
121 | if (EVP_CIPHER_iv_length(cipher)) { | 121 | if (EVP_CIPHER_iv_length(cipher)) { |
122 | if (aiv) | 122 | if (aiv) |
123 | memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher)); | 123 | memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher)); |
124 | else if (RAND_pseudo_bytes(iv, | 124 | else |
125 | EVP_CIPHER_iv_length(cipher)) < 0) | 125 | arc4random_buf(iv, EVP_CIPHER_iv_length(cipher)); |
126 | goto err; | ||
127 | } | 126 | } |
128 | 127 | ||
129 | EVP_CIPHER_CTX_init(&ctx); | 128 | EVP_CIPHER_CTX_init(&ctx); |
@@ -227,8 +226,8 @@ PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, int prf_nid, | |||
227 | 226 | ||
228 | if (salt) | 227 | if (salt) |
229 | memcpy (osalt->data, salt, saltlen); | 228 | memcpy (osalt->data, salt, saltlen); |
230 | else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) | 229 | else |
231 | goto merr; | 230 | arc4random_buf(osalt->data, saltlen); |
232 | 231 | ||
233 | if (iter <= 0) | 232 | if (iter <= 0) |
234 | iter = PKCS5_DEFAULT_ITER; | 233 | iter = PKCS5_DEFAULT_ITER; |
diff --git a/src/lib/libssl/src/crypto/bio/bf_nbio.c b/src/lib/libssl/src/crypto/bio/bf_nbio.c index 86a13a8bc8..a86feb49c2 100644 --- a/src/lib/libssl/src/crypto/bio/bf_nbio.c +++ b/src/lib/libssl/src/crypto/bio/bf_nbio.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bf_nbio.c,v 1.17 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: bf_nbio.c,v 1.18 2014/10/22 13:02: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 | * |
@@ -58,9 +58,9 @@ | |||
58 | 58 | ||
59 | #include <errno.h> | 59 | #include <errno.h> |
60 | #include <stdio.h> | 60 | #include <stdio.h> |
61 | #include <stdlib.h> | ||
61 | 62 | ||
62 | #include <openssl/bio.h> | 63 | #include <openssl/bio.h> |
63 | #include <openssl/rand.h> | ||
64 | 64 | ||
65 | /* BIO_put and BIO_get both add to the digest, | 65 | /* BIO_put and BIO_get both add to the digest, |
66 | * BIO_gets returns the digest */ | 66 | * BIO_gets returns the digest */ |
@@ -142,7 +142,7 @@ nbiof_read(BIO *b, char *out, int outl) | |||
142 | 142 | ||
143 | BIO_clear_retry_flags(b); | 143 | BIO_clear_retry_flags(b); |
144 | #if 1 | 144 | #if 1 |
145 | RAND_pseudo_bytes(&n, 1); | 145 | arc4random_buf(&n, 1); |
146 | num = (n & 0x07); | 146 | num = (n & 0x07); |
147 | 147 | ||
148 | if (outl > num) | 148 | if (outl > num) |
@@ -182,7 +182,7 @@ nbiof_write(BIO *b, const char *in, int inl) | |||
182 | num = nt->lwn; | 182 | num = nt->lwn; |
183 | nt->lwn = 0; | 183 | nt->lwn = 0; |
184 | } else { | 184 | } else { |
185 | RAND_pseudo_bytes(&n, 1); | 185 | arc4random_buf(&n, 1); |
186 | num = (n&7); | 186 | num = (n&7); |
187 | } | 187 | } |
188 | 188 | ||
diff --git a/src/lib/libssl/src/crypto/bn/bn.h b/src/lib/libssl/src/crypto/bn/bn.h index 155adf4fe0..10414dc339 100644 --- a/src/lib/libssl/src/crypto/bn/bn.h +++ b/src/lib/libssl/src/crypto/bn/bn.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn.h,v 1.24 2014/06/27 06:07:35 deraadt Exp $ */ | 1 | /* $OpenBSD: bn.h,v 1.25 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -125,9 +125,11 @@ | |||
125 | #ifndef HEADER_BN_H | 125 | #ifndef HEADER_BN_H |
126 | #define HEADER_BN_H | 126 | #define HEADER_BN_H |
127 | 127 | ||
128 | #include <stdio.h> | ||
129 | #include <stdlib.h> | ||
130 | |||
128 | #include <openssl/opensslconf.h> | 131 | #include <openssl/opensslconf.h> |
129 | 132 | ||
130 | #include <stdio.h> /* FILE */ | ||
131 | #include <openssl/ossl_typ.h> | 133 | #include <openssl/ossl_typ.h> |
132 | #include <openssl/crypto.h> | 134 | #include <openssl/crypto.h> |
133 | 135 | ||
@@ -673,11 +675,6 @@ BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */ | |||
673 | #include <assert.h> | 675 | #include <assert.h> |
674 | 676 | ||
675 | #ifdef BN_DEBUG_RAND | 677 | #ifdef BN_DEBUG_RAND |
676 | /* To avoid "make update" cvs wars due to BN_DEBUG, use some tricks */ | ||
677 | #ifndef RAND_pseudo_bytes | ||
678 | int RAND_pseudo_bytes(unsigned char *buf, int num); | ||
679 | #define BN_DEBUG_TRIX | ||
680 | #endif | ||
681 | #define bn_pollute(a) \ | 678 | #define bn_pollute(a) \ |
682 | do { \ | 679 | do { \ |
683 | const BIGNUM *_bnum1 = (a); \ | 680 | const BIGNUM *_bnum1 = (a); \ |
@@ -688,17 +685,15 @@ int RAND_pseudo_bytes(unsigned char *buf, int num); | |||
688 | * wouldn't be constructed with top!=dmax. */ \ | 685 | * wouldn't be constructed with top!=dmax. */ \ |
689 | BN_ULONG *_not_const; \ | 686 | BN_ULONG *_not_const; \ |
690 | memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \ | 687 | memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \ |
691 | RAND_pseudo_bytes(&_tmp_char, 1); \ | 688 | arc4random_buf(&_tmp_char, 1); \ |
692 | memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \ | 689 | memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \ |
693 | (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \ | 690 | (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \ |
694 | } \ | 691 | } \ |
695 | } while(0) | 692 | } while(0) |
696 | #ifdef BN_DEBUG_TRIX | ||
697 | #undef RAND_pseudo_bytes | ||
698 | #endif | ||
699 | #else | 693 | #else |
700 | #define bn_pollute(a) | 694 | #define bn_pollute(a) |
701 | #endif | 695 | #endif |
696 | |||
702 | #define bn_check_top(a) \ | 697 | #define bn_check_top(a) \ |
703 | do { \ | 698 | do { \ |
704 | const BIGNUM *_bnum2 = (a); \ | 699 | const BIGNUM *_bnum2 = (a); \ |
diff --git a/src/lib/libssl/src/crypto/bn/bn_rand.c b/src/lib/libssl/src/crypto/bn/bn_rand.c index acb17882ef..334c65dd57 100644 --- a/src/lib/libssl/src/crypto/bn/bn_rand.c +++ b/src/lib/libssl/src/crypto/bn/bn_rand.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_rand.c,v 1.15 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: bn_rand.c,v 1.16 2014/10/22 13:02:04 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 | * |
@@ -110,10 +110,10 @@ | |||
110 | */ | 110 | */ |
111 | 111 | ||
112 | #include <stdio.h> | 112 | #include <stdio.h> |
113 | #include <stdlib.h> | ||
113 | #include <time.h> | 114 | #include <time.h> |
114 | 115 | ||
115 | #include <openssl/err.h> | 116 | #include <openssl/err.h> |
116 | #include <openssl/rand.h> | ||
117 | 117 | ||
118 | #include "bn_lcl.h" | 118 | #include "bn_lcl.h" |
119 | 119 | ||
@@ -139,14 +139,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom) | |||
139 | } | 139 | } |
140 | 140 | ||
141 | /* make a random number and set the top and bottom bits */ | 141 | /* make a random number and set the top and bottom bits */ |
142 | 142 | arc4random_buf(buf, bytes); | |
143 | if (pseudorand) { | ||
144 | if (RAND_pseudo_bytes(buf, bytes) == -1) | ||
145 | goto err; | ||
146 | } else { | ||
147 | if (RAND_bytes(buf, bytes) <= 0) | ||
148 | goto err; | ||
149 | } | ||
150 | 143 | ||
151 | #if 1 | 144 | #if 1 |
152 | if (pseudorand == 2) { | 145 | if (pseudorand == 2) { |
@@ -156,7 +149,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom) | |||
156 | unsigned char c; | 149 | unsigned char c; |
157 | 150 | ||
158 | for (i = 0; i < bytes; i++) { | 151 | for (i = 0; i < bytes; i++) { |
159 | RAND_pseudo_bytes(&c, 1); | 152 | arc4random_buf(&c, 1); |
160 | if (c >= 128 && i > 0) | 153 | if (c >= 128 && i > 0) |
161 | buf[i] = buf[i - 1]; | 154 | buf[i] = buf[i - 1]; |
162 | else if (c < 42) | 155 | else if (c < 42) |
diff --git a/src/lib/libssl/src/crypto/cms/cms_enc.c b/src/lib/libssl/src/crypto/cms/cms_enc.c index efe19a3131..f97e4d5f34 100644 --- a/src/lib/libssl/src/crypto/cms/cms_enc.c +++ b/src/lib/libssl/src/crypto/cms/cms_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_enc.c,v 1.5 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: cms_enc.c,v 1.6 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -51,11 +51,12 @@ | |||
51 | * ==================================================================== | 51 | * ==================================================================== |
52 | */ | 52 | */ |
53 | 53 | ||
54 | #include <stdlib.h> | ||
55 | |||
54 | #include <openssl/asn1t.h> | 56 | #include <openssl/asn1t.h> |
55 | #include <openssl/cms.h> | 57 | #include <openssl/cms.h> |
56 | #include <openssl/err.h> | 58 | #include <openssl/err.h> |
57 | #include <openssl/pem.h> | 59 | #include <openssl/pem.h> |
58 | #include <openssl/rand.h> | ||
59 | #include <openssl/x509v3.h> | 60 | #include <openssl/x509v3.h> |
60 | 61 | ||
61 | #include "cms_lcl.h" | 62 | #include "cms_lcl.h" |
@@ -119,8 +120,7 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) | |||
119 | /* Generate a random IV if we need one */ | 120 | /* Generate a random IV if we need one */ |
120 | ivlen = EVP_CIPHER_CTX_iv_length(ctx); | 121 | ivlen = EVP_CIPHER_CTX_iv_length(ctx); |
121 | if (ivlen > 0) { | 122 | if (ivlen > 0) { |
122 | if (RAND_pseudo_bytes(iv, ivlen) <= 0) | 123 | arc4random_buf(iv, ivlen); |
123 | goto err; | ||
124 | piv = iv; | 124 | piv = iv; |
125 | } | 125 | } |
126 | } else if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0) { | 126 | } else if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0) { |
diff --git a/src/lib/libssl/src/crypto/cms/cms_ess.c b/src/lib/libssl/src/crypto/cms/cms_ess.c index e3b7e7da4c..fca62e0627 100644 --- a/src/lib/libssl/src/crypto/cms/cms_ess.c +++ b/src/lib/libssl/src/crypto/cms/cms_ess.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_ess.c,v 1.6 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: cms_ess.c,v 1.7 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -51,11 +51,12 @@ | |||
51 | * ==================================================================== | 51 | * ==================================================================== |
52 | */ | 52 | */ |
53 | 53 | ||
54 | #include <stdlib.h> | ||
55 | |||
54 | #include <openssl/asn1t.h> | 56 | #include <openssl/asn1t.h> |
55 | #include <openssl/cms.h> | 57 | #include <openssl/cms.h> |
56 | #include <openssl/err.h> | 58 | #include <openssl/err.h> |
57 | #include <openssl/pem.h> | 59 | #include <openssl/pem.h> |
58 | #include <openssl/rand.h> | ||
59 | #include <openssl/x509v3.h> | 60 | #include <openssl/x509v3.h> |
60 | 61 | ||
61 | #include "cms_lcl.h" | 62 | #include "cms_lcl.h" |
@@ -105,9 +106,7 @@ CMS_ReceiptRequest_create0(unsigned char *id, int idlen, int allorfirst, | |||
105 | else { | 106 | else { |
106 | if (!ASN1_STRING_set(rr->signedContentIdentifier, NULL, 32)) | 107 | if (!ASN1_STRING_set(rr->signedContentIdentifier, NULL, 32)) |
107 | goto merr; | 108 | goto merr; |
108 | if (RAND_pseudo_bytes(rr->signedContentIdentifier->data, 32) | 109 | arc4random_buf(rr->signedContentIdentifier->data, 32); |
109 | <= 0) | ||
110 | goto err; | ||
111 | } | 110 | } |
112 | 111 | ||
113 | sk_GENERAL_NAMES_pop_free(rr->receiptsTo, GENERAL_NAMES_free); | 112 | sk_GENERAL_NAMES_pop_free(rr->receiptsTo, GENERAL_NAMES_free); |
diff --git a/src/lib/libssl/src/crypto/cms/cms_pwri.c b/src/lib/libssl/src/crypto/cms/cms_pwri.c index b7c3038027..89f7925938 100644 --- a/src/lib/libssl/src/crypto/cms/cms_pwri.c +++ b/src/lib/libssl/src/crypto/cms/cms_pwri.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_pwri.c,v 1.7 2014/07/11 15:42:34 miod Exp $ */ | 1 | /* $OpenBSD: cms_pwri.c,v 1.8 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -51,12 +51,13 @@ | |||
51 | * ==================================================================== | 51 | * ==================================================================== |
52 | */ | 52 | */ |
53 | 53 | ||
54 | #include <stdlib.h> | ||
55 | |||
54 | #include <openssl/aes.h> | 56 | #include <openssl/aes.h> |
55 | #include <openssl/asn1t.h> | 57 | #include <openssl/asn1t.h> |
56 | #include <openssl/cms.h> | 58 | #include <openssl/cms.h> |
57 | #include <openssl/err.h> | 59 | #include <openssl/err.h> |
58 | #include <openssl/pem.h> | 60 | #include <openssl/pem.h> |
59 | #include <openssl/rand.h> | ||
60 | #include <openssl/x509v3.h> | 61 | #include <openssl/x509v3.h> |
61 | 62 | ||
62 | #include "asn1_locl.h" | 63 | #include "asn1_locl.h" |
@@ -130,8 +131,7 @@ CMS_add0_recipient_password(CMS_ContentInfo *cms, int iter, int wrap_nid, | |||
130 | ivlen = EVP_CIPHER_CTX_iv_length(&ctx); | 131 | ivlen = EVP_CIPHER_CTX_iv_length(&ctx); |
131 | 132 | ||
132 | if (ivlen > 0) { | 133 | if (ivlen > 0) { |
133 | if (RAND_pseudo_bytes(iv, ivlen) <= 0) | 134 | arc4random_buf(iv, ivlen); |
134 | goto err; | ||
135 | if (EVP_EncryptInit_ex(&ctx, NULL, NULL, NULL, iv) <= 0) { | 135 | if (EVP_EncryptInit_ex(&ctx, NULL, NULL, NULL, iv) <= 0) { |
136 | CMSerr(CMS_F_CMS_ADD0_RECIPIENT_PASSWORD, | 136 | CMSerr(CMS_F_CMS_ADD0_RECIPIENT_PASSWORD, |
137 | ERR_R_EVP_LIB); | 137 | ERR_R_EVP_LIB); |
@@ -297,7 +297,7 @@ kek_wrap_key(unsigned char *out, size_t *outlen, const unsigned char *in, | |||
297 | memcpy(out + 4, in, inlen); | 297 | memcpy(out + 4, in, inlen); |
298 | /* Add random padding to end */ | 298 | /* Add random padding to end */ |
299 | if (olen > inlen + 4) | 299 | if (olen > inlen + 4) |
300 | RAND_pseudo_bytes(out + 4 + inlen, olen - 4 - inlen); | 300 | arc4random_buf(out + 4 + inlen, olen - 4 - inlen); |
301 | /* Encrypt twice */ | 301 | /* Encrypt twice */ |
302 | EVP_EncryptUpdate(ctx, out, &dummy, out, olen); | 302 | EVP_EncryptUpdate(ctx, out, &dummy, out, olen); |
303 | EVP_EncryptUpdate(ctx, out, &dummy, out, olen); | 303 | EVP_EncryptUpdate(ctx, out, &dummy, out, olen); |
diff --git a/src/lib/libssl/src/crypto/des/enc_writ.c b/src/lib/libssl/src/crypto/des/enc_writ.c index a7049ff44e..0130c2c6d9 100644 --- a/src/lib/libssl/src/crypto/des/enc_writ.c +++ b/src/lib/libssl/src/crypto/des/enc_writ.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: enc_writ.c,v 1.12 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: enc_writ.c,v 1.13 2014/10/22 13:02:04 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 | * |
@@ -58,12 +58,11 @@ | |||
58 | 58 | ||
59 | #include <errno.h> | 59 | #include <errno.h> |
60 | #include <stdio.h> | 60 | #include <stdio.h> |
61 | #include <stdlib.h> | ||
61 | #include <time.h> | 62 | #include <time.h> |
62 | 63 | ||
63 | #include <openssl/opensslconf.h> | 64 | #include <openssl/opensslconf.h> |
64 | 65 | ||
65 | #include <openssl/rand.h> | ||
66 | |||
67 | #include "des_locl.h" | 66 | #include "des_locl.h" |
68 | 67 | ||
69 | /* | 68 | /* |
@@ -136,7 +135,7 @@ int DES_enc_write(int fd, const void *_buf, int len, | |||
136 | { | 135 | { |
137 | cp=shortbuf; | 136 | cp=shortbuf; |
138 | memcpy(shortbuf,buf,len); | 137 | memcpy(shortbuf,buf,len); |
139 | RAND_pseudo_bytes(shortbuf+len, 8-len); | 138 | arc4random_buf(shortbuf+len, 8-len); |
140 | rnum=8; | 139 | rnum=8; |
141 | } | 140 | } |
142 | else | 141 | else |
diff --git a/src/lib/libssl/src/crypto/des/rand_key.c b/src/lib/libssl/src/crypto/des/rand_key.c index 727d36f488..7abb811df4 100644 --- a/src/lib/libssl/src/crypto/des/rand_key.c +++ b/src/lib/libssl/src/crypto/des/rand_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rand_key.c,v 1.7 2014/07/22 18:09:20 miod Exp $ */ | 1 | /* $OpenBSD: rand_key.c,v 1.8 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -53,15 +53,15 @@ | |||
53 | * | 53 | * |
54 | */ | 54 | */ |
55 | 55 | ||
56 | #include <stdlib.h> | ||
57 | |||
56 | #include <openssl/des.h> | 58 | #include <openssl/des.h> |
57 | #include <openssl/rand.h> | ||
58 | 59 | ||
59 | int | 60 | int |
60 | DES_random_key(DES_cblock *ret) | 61 | DES_random_key(DES_cblock *ret) |
61 | { | 62 | { |
62 | do { | 63 | do { |
63 | if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1) | 64 | arc4random_buf(ret, sizeof(DES_cblock)); |
64 | return (0); | ||
65 | DES_set_odd_parity(ret); | 65 | DES_set_odd_parity(ret); |
66 | } while (DES_is_weak_key(ret)); | 66 | } while (DES_is_weak_key(ret)); |
67 | return (1); | 67 | return (1); |
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_gen.c b/src/lib/libssl/src/crypto/dsa/dsa_gen.c index a3d07b901a..296a544c31 100644 --- a/src/lib/libssl/src/crypto/dsa/dsa_gen.c +++ b/src/lib/libssl/src/crypto/dsa/dsa_gen.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dsa_gen.c,v 1.16 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: dsa_gen.c,v 1.17 2014/10/22 13:02:04 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 | * |
@@ -61,11 +61,11 @@ | |||
61 | #ifndef OPENSSL_NO_SHA | 61 | #ifndef OPENSSL_NO_SHA |
62 | 62 | ||
63 | #include <stdio.h> | 63 | #include <stdio.h> |
64 | #include <stdlib.h> | ||
64 | #include <string.h> | 65 | #include <string.h> |
65 | 66 | ||
66 | #include <openssl/bn.h> | 67 | #include <openssl/bn.h> |
67 | #include <openssl/evp.h> | 68 | #include <openssl/evp.h> |
68 | #include <openssl/rand.h> | ||
69 | #include <openssl/sha.h> | 69 | #include <openssl/sha.h> |
70 | 70 | ||
71 | #include "dsa_locl.h" | 71 | #include "dsa_locl.h" |
@@ -169,7 +169,7 @@ dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, const EVP_MD *evpmd, | |||
169 | goto err; | 169 | goto err; |
170 | 170 | ||
171 | if (!seed_len) { | 171 | if (!seed_len) { |
172 | RAND_pseudo_bytes(seed, qsize); | 172 | arc4random_buf(seed, qsize); |
173 | seed_is_random = 1; | 173 | seed_is_random = 1; |
174 | } else { | 174 | } else { |
175 | seed_is_random = 0; | 175 | seed_is_random = 0; |
diff --git a/src/lib/libssl/src/crypto/engine/eng_lib.c b/src/lib/libssl/src/crypto/engine/eng_lib.c index 118fa6cb9c..b3b9213d87 100644 --- a/src/lib/libssl/src/crypto/engine/eng_lib.c +++ b/src/lib/libssl/src/crypto/engine/eng_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: eng_lib.c,v 1.9 2014/07/10 13:58:22 jsing Exp $ */ | 1 | /* $OpenBSD: eng_lib.c,v 1.10 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -58,9 +58,10 @@ | |||
58 | 58 | ||
59 | #include <string.h> | 59 | #include <string.h> |
60 | 60 | ||
61 | #include "eng_int.h" | ||
62 | #include <openssl/rand.h> | 61 | #include <openssl/rand.h> |
63 | 62 | ||
63 | #include "eng_int.h" | ||
64 | |||
64 | /* The "new"/"free" stuff first */ | 65 | /* The "new"/"free" stuff first */ |
65 | 66 | ||
66 | ENGINE * | 67 | ENGINE * |
diff --git a/src/lib/libssl/src/crypto/evp/e_aes.c b/src/lib/libssl/src/crypto/evp/e_aes.c index f96a15f19c..bb3b420a3b 100644 --- a/src/lib/libssl/src/crypto/evp/e_aes.c +++ b/src/lib/libssl/src/crypto/evp/e_aes.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_aes.c,v 1.25 2014/07/12 19:31:03 miod Exp $ */ | 1 | /* $OpenBSD: e_aes.c,v 1.26 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -50,6 +50,7 @@ | |||
50 | */ | 50 | */ |
51 | 51 | ||
52 | #include <assert.h> | 52 | #include <assert.h> |
53 | #include <stdlib.h> | ||
53 | #include <string.h> | 54 | #include <string.h> |
54 | 55 | ||
55 | #include <openssl/opensslconf.h> | 56 | #include <openssl/opensslconf.h> |
@@ -58,7 +59,6 @@ | |||
58 | #include <openssl/aes.h> | 59 | #include <openssl/aes.h> |
59 | #include <openssl/err.h> | 60 | #include <openssl/err.h> |
60 | #include <openssl/evp.h> | 61 | #include <openssl/evp.h> |
61 | #include <openssl/rand.h> | ||
62 | 62 | ||
63 | #include "evp_locl.h" | 63 | #include "evp_locl.h" |
64 | #include "modes_lcl.h" | 64 | #include "modes_lcl.h" |
@@ -769,9 +769,8 @@ aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | |||
769 | return 0; | 769 | return 0; |
770 | if (arg) | 770 | if (arg) |
771 | memcpy(gctx->iv, ptr, arg); | 771 | memcpy(gctx->iv, ptr, arg); |
772 | if (c->encrypt && | 772 | if (c->encrypt) |
773 | RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0) | 773 | arc4random_buf(gctx->iv + arg, gctx->ivlen - arg); |
774 | return 0; | ||
775 | gctx->iv_gen = 1; | 774 | gctx->iv_gen = 1; |
776 | return 1; | 775 | return 1; |
777 | 776 | ||
diff --git a/src/lib/libssl/src/crypto/evp/evp_enc.c b/src/lib/libssl/src/crypto/evp/evp_enc.c index 4333e4dff8..49ceacefad 100644 --- a/src/lib/libssl/src/crypto/evp/evp_enc.c +++ b/src/lib/libssl/src/crypto/evp/evp_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_enc.c,v 1.24 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: evp_enc.c,v 1.25 2014/10/22 13:02:04 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 | * |
@@ -57,13 +57,13 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/opensslconf.h> | 63 | #include <openssl/opensslconf.h> |
63 | 64 | ||
64 | #include <openssl/err.h> | 65 | #include <openssl/err.h> |
65 | #include <openssl/evp.h> | 66 | #include <openssl/evp.h> |
66 | #include <openssl/rand.h> | ||
67 | 67 | ||
68 | #ifndef OPENSSL_NO_ENGINE | 68 | #ifndef OPENSSL_NO_ENGINE |
69 | #include <openssl/engine.h> | 69 | #include <openssl/engine.h> |
@@ -613,8 +613,7 @@ EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key) | |||
613 | { | 613 | { |
614 | if (ctx->cipher->flags & EVP_CIPH_RAND_KEY) | 614 | if (ctx->cipher->flags & EVP_CIPH_RAND_KEY) |
615 | return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key); | 615 | return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key); |
616 | if (RAND_bytes(key, ctx->key_len) <= 0) | 616 | arc4random_buf(key, ctx->key_len); |
617 | return 0; | ||
618 | return 1; | 617 | return 1; |
619 | } | 618 | } |
620 | 619 | ||
diff --git a/src/lib/libssl/src/crypto/evp/p_seal.c b/src/lib/libssl/src/crypto/evp/p_seal.c index 4f8417ae64..8b9740fbcd 100644 --- a/src/lib/libssl/src/crypto/evp/p_seal.c +++ b/src/lib/libssl/src/crypto/evp/p_seal.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p_seal.c,v 1.13 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: p_seal.c,v 1.14 2014/10/22 13:02:04 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 | * |
@@ -57,12 +57,12 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | 61 | ||
61 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
62 | 63 | ||
63 | #include <openssl/evp.h> | 64 | #include <openssl/evp.h> |
64 | #include <openssl/objects.h> | 65 | #include <openssl/objects.h> |
65 | #include <openssl/rand.h> | ||
66 | #include <openssl/x509.h> | 66 | #include <openssl/x509.h> |
67 | 67 | ||
68 | #ifndef OPENSSL_NO_RSA | 68 | #ifndef OPENSSL_NO_RSA |
@@ -86,7 +86,7 @@ EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek, | |||
86 | if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) | 86 | if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) |
87 | return 0; | 87 | return 0; |
88 | if (EVP_CIPHER_CTX_iv_length(ctx)) | 88 | if (EVP_CIPHER_CTX_iv_length(ctx)) |
89 | RAND_pseudo_bytes(iv, EVP_CIPHER_CTX_iv_length(ctx)); | 89 | arc4random_buf(iv, EVP_CIPHER_CTX_iv_length(ctx)); |
90 | 90 | ||
91 | if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) | 91 | if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) |
92 | return 0; | 92 | return 0; |
diff --git a/src/lib/libssl/src/crypto/ocsp/ocsp_ext.c b/src/lib/libssl/src/crypto/ocsp/ocsp_ext.c index c7b9d817ac..6318e1718b 100644 --- a/src/lib/libssl/src/crypto/ocsp/ocsp_ext.c +++ b/src/lib/libssl/src/crypto/ocsp/ocsp_ext.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ocsp_ext.c,v 1.11 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: ocsp_ext.c,v 1.12 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL | 2 | /* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL |
3 | * project. */ | 3 | * project. */ |
4 | 4 | ||
@@ -62,11 +62,11 @@ | |||
62 | */ | 62 | */ |
63 | 63 | ||
64 | #include <stdio.h> | 64 | #include <stdio.h> |
65 | #include <stdlib.h> | ||
65 | #include <string.h> | 66 | #include <string.h> |
66 | 67 | ||
67 | #include <openssl/objects.h> | 68 | #include <openssl/objects.h> |
68 | #include <openssl/ocsp.h> | 69 | #include <openssl/ocsp.h> |
69 | #include <openssl/rand.h> | ||
70 | #include <openssl/x509.h> | 70 | #include <openssl/x509.h> |
71 | #include <openssl/x509v3.h> | 71 | #include <openssl/x509v3.h> |
72 | 72 | ||
@@ -389,7 +389,7 @@ ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len) | |||
389 | if (val) | 389 | if (val) |
390 | memcpy(tmpval, val, len); | 390 | memcpy(tmpval, val, len); |
391 | else | 391 | else |
392 | RAND_pseudo_bytes(tmpval, len); | 392 | arc4random_buf(tmpval, len); |
393 | if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce, &os, 0, | 393 | if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce, &os, 0, |
394 | X509V3_ADD_REPLACE)) | 394 | X509V3_ADD_REPLACE)) |
395 | goto err; | 395 | goto err; |
diff --git a/src/lib/libssl/src/crypto/pem/pem_lib.c b/src/lib/libssl/src/crypto/pem/pem_lib.c index 26b1876f36..1ebae53e74 100644 --- a/src/lib/libssl/src/crypto/pem/pem_lib.c +++ b/src/lib/libssl/src/crypto/pem/pem_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pem_lib.c,v 1.34 2014/07/23 20:43:56 miod Exp $ */ | 1 | /* $OpenBSD: pem_lib.c,v 1.35 2014/10/22 13:02:04 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 | * |
@@ -58,6 +58,7 @@ | |||
58 | 58 | ||
59 | #include <ctype.h> | 59 | #include <ctype.h> |
60 | #include <stdio.h> | 60 | #include <stdio.h> |
61 | #include <stdlib.h> | ||
61 | #include <string.h> | 62 | #include <string.h> |
62 | 63 | ||
63 | #include <openssl/opensslconf.h> | 64 | #include <openssl/opensslconf.h> |
@@ -67,7 +68,6 @@ | |||
67 | #include <openssl/objects.h> | 68 | #include <openssl/objects.h> |
68 | #include <openssl/pem.h> | 69 | #include <openssl/pem.h> |
69 | #include <openssl/pkcs12.h> | 70 | #include <openssl/pkcs12.h> |
70 | #include <openssl/rand.h> | ||
71 | #include <openssl/x509.h> | 71 | #include <openssl/x509.h> |
72 | 72 | ||
73 | #ifndef OPENSSL_NO_DES | 73 | #ifndef OPENSSL_NO_DES |
@@ -390,8 +390,7 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, | |||
390 | kstr = (unsigned char *)buf; | 390 | kstr = (unsigned char *)buf; |
391 | } | 391 | } |
392 | OPENSSL_assert(enc->iv_len <= (int)sizeof(iv)); | 392 | OPENSSL_assert(enc->iv_len <= (int)sizeof(iv)); |
393 | if (RAND_pseudo_bytes(iv, enc->iv_len) < 0) /* Generate a salt */ | 393 | arc4random_buf(iv, enc->iv_len); /* Generate a salt */ |
394 | goto err; | ||
395 | /* The 'iv' is used as the iv and as a salt. It is | 394 | /* The 'iv' is used as the iv and as a salt. It is |
396 | * NOT taken from the BytesToKey function */ | 395 | * NOT taken from the BytesToKey function */ |
397 | if (!EVP_BytesToKey(enc, EVP_md5(), iv, kstr, klen, 1, | 396 | if (!EVP_BytesToKey(enc, EVP_md5(), iv, kstr, klen, 1, |
diff --git a/src/lib/libssl/src/crypto/pem/pvkfmt.c b/src/lib/libssl/src/crypto/pem/pvkfmt.c index ca7e908c29..2009c9db80 100644 --- a/src/lib/libssl/src/crypto/pem/pvkfmt.c +++ b/src/lib/libssl/src/crypto/pem/pvkfmt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pvkfmt.c,v 1.11 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: pvkfmt.c,v 1.12 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2005. | 3 | * project 2005. |
4 | */ | 4 | */ |
@@ -60,6 +60,7 @@ | |||
60 | * and PRIVATEKEYBLOB). | 60 | * and PRIVATEKEYBLOB). |
61 | */ | 61 | */ |
62 | 62 | ||
63 | #include <stdlib.h> | ||
63 | #include <string.h> | 64 | #include <string.h> |
64 | 65 | ||
65 | #include <openssl/opensslconf.h> | 66 | #include <openssl/opensslconf.h> |
@@ -67,7 +68,6 @@ | |||
67 | #include <openssl/bn.h> | 68 | #include <openssl/bn.h> |
68 | #include <openssl/err.h> | 69 | #include <openssl/err.h> |
69 | #include <openssl/pem.h> | 70 | #include <openssl/pem.h> |
70 | #include <openssl/rand.h> | ||
71 | 71 | ||
72 | #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) | 72 | #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) |
73 | #include <openssl/dsa.h> | 73 | #include <openssl/dsa.h> |
@@ -869,8 +869,7 @@ i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, pem_password_cb *cb, | |||
869 | write_ledword(&p, enclevel ? PVK_SALTLEN : 0); | 869 | write_ledword(&p, enclevel ? PVK_SALTLEN : 0); |
870 | write_ledword(&p, pklen); | 870 | write_ledword(&p, pklen); |
871 | if (enclevel) { | 871 | if (enclevel) { |
872 | if (RAND_bytes(p, PVK_SALTLEN) <= 0) | 872 | arc4random_buf(p, PVK_SALTLEN); |
873 | goto error; | ||
874 | salt = p; | 873 | salt = p; |
875 | p += PVK_SALTLEN; | 874 | p += PVK_SALTLEN; |
876 | } | 875 | } |
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_mutl.c b/src/lib/libssl/src/crypto/pkcs12/p12_mutl.c index 453d30d65f..0c49bf96fd 100644 --- a/src/lib/libssl/src/crypto/pkcs12/p12_mutl.c +++ b/src/lib/libssl/src/crypto/pkcs12/p12_mutl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p12_mutl.c,v 1.17 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: p12_mutl.c,v 1.18 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 1999. | 3 | * project 1999. |
4 | */ | 4 | */ |
@@ -57,6 +57,7 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/opensslconf.h> | 63 | #include <openssl/opensslconf.h> |
@@ -66,7 +67,6 @@ | |||
66 | #include <openssl/err.h> | 67 | #include <openssl/err.h> |
67 | #include <openssl/hmac.h> | 68 | #include <openssl/hmac.h> |
68 | #include <openssl/pkcs12.h> | 69 | #include <openssl/pkcs12.h> |
69 | #include <openssl/rand.h> | ||
70 | 70 | ||
71 | /* Generate a MAC */ | 71 | /* Generate a MAC */ |
72 | int | 72 | int |
@@ -193,10 +193,9 @@ PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen, | |||
193 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); | 193 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); |
194 | return 0; | 194 | return 0; |
195 | } | 195 | } |
196 | if (!salt) { | 196 | if (!salt) |
197 | if (RAND_pseudo_bytes (p12->mac->salt->data, saltlen) < 0) | 197 | arc4random_buf(p12->mac->salt->data, saltlen); |
198 | return 0; | 198 | else |
199 | } else | ||
200 | memcpy (p12->mac->salt->data, salt, saltlen); | 199 | memcpy (p12->mac->salt->data, salt, saltlen); |
201 | p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); | 200 | p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); |
202 | if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { | 201 | if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { |
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c index 8f1e393635..d69aff8f41 100644 --- a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c +++ b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pk7_doit.c,v 1.29 2014/07/25 06:05:32 doug Exp $ */ | 1 | /* $OpenBSD: pk7_doit.c,v 1.30 2014/10/22 13:02:04 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 | * |
@@ -57,11 +57,11 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/err.h> | 63 | #include <openssl/err.h> |
63 | #include <openssl/objects.h> | 64 | #include <openssl/objects.h> |
64 | #include <openssl/rand.h> | ||
65 | #include <openssl/x509.h> | 65 | #include <openssl/x509.h> |
66 | #include <openssl/x509v3.h> | 66 | #include <openssl/x509v3.h> |
67 | 67 | ||
@@ -324,8 +324,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio) | |||
324 | ivlen = EVP_CIPHER_iv_length(evp_cipher); | 324 | ivlen = EVP_CIPHER_iv_length(evp_cipher); |
325 | xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher)); | 325 | xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher)); |
326 | if (ivlen > 0) | 326 | if (ivlen > 0) |
327 | if (RAND_pseudo_bytes(iv, ivlen) <= 0) | 327 | arc4random_buf(iv, ivlen); |
328 | goto err; | ||
329 | if (EVP_CipherInit_ex(ctx, evp_cipher, NULL, NULL, | 328 | if (EVP_CipherInit_ex(ctx, evp_cipher, NULL, NULL, |
330 | NULL, 1) <= 0) | 329 | NULL, 1) <= 0) |
331 | goto err; | 330 | goto err; |
diff --git a/src/lib/libssl/src/crypto/rand/rand_lib.c b/src/lib/libssl/src/crypto/rand/rand_lib.c index 2b2c827740..8342a55f05 100644 --- a/src/lib/libssl/src/crypto/rand/rand_lib.c +++ b/src/lib/libssl/src/crypto/rand/rand_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rand_lib.c,v 1.19 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: rand_lib.c,v 1.20 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | 3 | * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> |
4 | * | 4 | * |
@@ -15,12 +15,12 @@ | |||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <stdlib.h> | ||
19 | |||
18 | #include <openssl/opensslconf.h> | 20 | #include <openssl/opensslconf.h> |
19 | 21 | ||
20 | #include <openssl/rand.h> | 22 | #include <openssl/rand.h> |
21 | 23 | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* | 24 | /* |
25 | * The useful functions in this file are at the bottom. | 25 | * The useful functions in this file are at the bottom. |
26 | */ | 26 | */ |
diff --git a/src/lib/libssl/src/crypto/rand/randfile.c b/src/lib/libssl/src/crypto/rand/randfile.c index dca49b10aa..e54a009420 100644 --- a/src/lib/libssl/src/crypto/rand/randfile.c +++ b/src/lib/libssl/src/crypto/rand/randfile.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: randfile.c,v 1.39 2014/07/14 00:01:39 deraadt Exp $ */ | 1 | /* $OpenBSD: randfile.c,v 1.40 2014/10/22 13:02:04 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 | * |
@@ -118,8 +118,7 @@ RAND_write_file(const char *file) | |||
118 | for (;;) { | 118 | for (;;) { |
119 | i = (n > BUFSIZE) ? BUFSIZE : n; | 119 | i = (n > BUFSIZE) ? BUFSIZE : n; |
120 | n -= BUFSIZE; | 120 | n -= BUFSIZE; |
121 | if (RAND_bytes(buf, i) <= 0) | 121 | arc4random_buf(buf, i); |
122 | rand_err = 1; | ||
123 | i = fwrite(buf, 1, i, out); | 122 | i = fwrite(buf, 1, i, out); |
124 | if (i <= 0) { | 123 | if (i <= 0) { |
125 | ret = 0; | 124 | ret = 0; |
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_oaep.c b/src/lib/libssl/src/crypto/rsa/rsa_oaep.c index 9be0f9be31..8585d7c3aa 100644 --- a/src/lib/libssl/src/crypto/rsa/rsa_oaep.c +++ b/src/lib/libssl/src/crypto/rsa/rsa_oaep.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_oaep.c,v 1.23 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: rsa_oaep.c,v 1.24 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Ulf Moeller. This software is distributed on an "AS IS" | 2 | /* Written by Ulf Moeller. This software is distributed on an "AS IS" |
3 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ | 3 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ |
4 | 4 | ||
@@ -19,6 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | ||
22 | #include <string.h> | 23 | #include <string.h> |
23 | 24 | ||
24 | #include <openssl/opensslconf.h> | 25 | #include <openssl/opensslconf.h> |
@@ -28,7 +29,6 @@ | |||
28 | #include <openssl/bn.h> | 29 | #include <openssl/bn.h> |
29 | #include <openssl/err.h> | 30 | #include <openssl/err.h> |
30 | #include <openssl/evp.h> | 31 | #include <openssl/evp.h> |
31 | #include <openssl/rand.h> | ||
32 | #include <openssl/rsa.h> | 32 | #include <openssl/rsa.h> |
33 | #include <openssl/sha.h> | 33 | #include <openssl/sha.h> |
34 | 34 | ||
@@ -65,8 +65,7 @@ RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, | |||
65 | emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); | 65 | emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); |
66 | db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01; | 66 | db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01; |
67 | memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, flen); | 67 | memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, flen); |
68 | if (RAND_bytes(seed, SHA_DIGEST_LENGTH) <= 0) | 68 | arc4random_buf(seed, SHA_DIGEST_LENGTH); |
69 | return 0; | ||
70 | 69 | ||
71 | dbmask = malloc(emlen - SHA_DIGEST_LENGTH); | 70 | dbmask = malloc(emlen - SHA_DIGEST_LENGTH); |
72 | if (dbmask == NULL) { | 71 | if (dbmask == NULL) { |
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_pk1.c b/src/lib/libssl/src/crypto/rsa/rsa_pk1.c index 4f82bf6768..6c3e7fb846 100644 --- a/src/lib/libssl/src/crypto/rsa/rsa_pk1.c +++ b/src/lib/libssl/src/crypto/rsa/rsa_pk1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_pk1.c,v 1.13 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: rsa_pk1.c,v 1.14 2014/10/22 13:02:04 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 | * |
@@ -57,12 +57,12 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/rsa.h> | 65 | #include <openssl/rsa.h> |
65 | #include <openssl/rand.h> | ||
66 | 66 | ||
67 | int | 67 | int |
68 | RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, | 68 | RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, |
@@ -167,13 +167,10 @@ RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, | |||
167 | /* pad out with non-zero random data */ | 167 | /* pad out with non-zero random data */ |
168 | j = tlen - 3 - flen; | 168 | j = tlen - 3 - flen; |
169 | 169 | ||
170 | if (RAND_bytes(p, j) <= 0) | 170 | arc4random_buf(p, j); |
171 | return 0; | ||
172 | for (i = 0; i < j; i++) { | 171 | for (i = 0; i < j; i++) { |
173 | while (*p == '\0') { | 172 | while (*p == '\0') |
174 | if (RAND_bytes(p, 1) <= 0) | 173 | arc4random_buf(p, 1); |
175 | return 0; | ||
176 | } | ||
177 | p++; | 174 | p++; |
178 | } | 175 | } |
179 | 176 | ||
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_pss.c b/src/lib/libssl/src/crypto/rsa/rsa_pss.c index f841b2f8a3..5e137a3090 100644 --- a/src/lib/libssl/src/crypto/rsa/rsa_pss.c +++ b/src/lib/libssl/src/crypto/rsa/rsa_pss.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_pss.c,v 1.10 2014/07/13 12:53:46 miod Exp $ */ | 1 | /* $OpenBSD: rsa_pss.c,v 1.11 2014/10/22 13:02:04 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2005. | 3 | * project 2005. |
4 | */ | 4 | */ |
@@ -57,12 +57,12 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/evp.h> | 65 | #include <openssl/evp.h> |
65 | #include <openssl/rand.h> | ||
66 | #include <openssl/rsa.h> | 66 | #include <openssl/rsa.h> |
67 | #include <openssl/sha.h> | 67 | #include <openssl/sha.h> |
68 | 68 | ||
@@ -243,8 +243,7 @@ RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, | |||
243 | ERR_R_MALLOC_FAILURE); | 243 | ERR_R_MALLOC_FAILURE); |
244 | goto err; | 244 | goto err; |
245 | } | 245 | } |
246 | if (RAND_bytes(salt, sLen) <= 0) | 246 | arc4random_buf(salt, sLen); |
247 | goto err; | ||
248 | } | 247 | } |
249 | maskedDBLen = emLen - hLen - 1; | 248 | maskedDBLen = emLen - hLen - 1; |
250 | H = EM + maskedDBLen; | 249 | H = EM + maskedDBLen; |
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_ssl.c b/src/lib/libssl/src/crypto/rsa/rsa_ssl.c index a5fe5004b1..73262f29c1 100644 --- a/src/lib/libssl/src/crypto/rsa/rsa_ssl.c +++ b/src/lib/libssl/src/crypto/rsa/rsa_ssl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_ssl.c,v 1.13 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: rsa_ssl.c,v 1.14 2014/10/22 13:02:04 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 | * |
@@ -57,11 +57,11 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | ||
60 | #include <string.h> | 61 | #include <string.h> |
61 | 62 | ||
62 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
63 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
64 | #include <openssl/rand.h> | ||
65 | #include <openssl/rsa.h> | 65 | #include <openssl/rsa.h> |
66 | 66 | ||
67 | int | 67 | int |
@@ -85,13 +85,10 @@ RSA_padding_add_SSLv23(unsigned char *to, int tlen, const unsigned char *from, | |||
85 | /* pad out with non-zero random data */ | 85 | /* pad out with non-zero random data */ |
86 | j = tlen - 3 - 8 - flen; | 86 | j = tlen - 3 - 8 - flen; |
87 | 87 | ||
88 | if (RAND_bytes(p, j) <= 0) | 88 | arc4random_buf(p, j); |
89 | return 0; | ||
90 | for (i = 0; i < j; i++) { | 89 | for (i = 0; i < j; i++) { |
91 | while (*p == '\0') { | 90 | while (*p == '\0') |
92 | if (RAND_bytes(p, 1) <= 0) | 91 | arc4random_buf(p, 1); |
93 | return 0; | ||
94 | } | ||
95 | p++; | 92 | p++; |
96 | } | 93 | } |
97 | 94 | ||