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 /src/lib/libcrypto/pem | |
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@
Diffstat (limited to 'src/lib/libcrypto/pem')
-rw-r--r-- | src/lib/libcrypto/pem/pem_lib.c | 7 | ||||
-rw-r--r-- | src/lib/libcrypto/pem/pvkfmt.c | 7 |
2 files changed, 6 insertions, 8 deletions
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 | } |