summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cms
diff options
context:
space:
mode:
authorjsing <>2014-10-22 13:02:04 +0000
committerjsing <>2014-10-22 13:02:04 +0000
commita2960bc2e14b4c5f7d8f78d2a69ebb537ca4afa8 (patch)
tree32d920c77e1ecf12be5fad632b9ae71343194a7c /src/lib/libcrypto/cms
parent5a6d7fd5a10b0ad084948463b25822d91091b325 (diff)
downloadopenbsd-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/cms')
-rw-r--r--src/lib/libcrypto/cms/cms_enc.c8
-rw-r--r--src/lib/libcrypto/cms/cms_ess.c9
-rw-r--r--src/lib/libcrypto/cms/cms_pwri.c10
3 files changed, 13 insertions, 14 deletions
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);