Commit 16cfc2c9 authored by Kurt Roeckx's avatar Kurt Roeckx Committed by Dr. Matthias St. Pierre
Browse files

Don't use a ssl specific DRBG anymore



Since the public and private DRBG are per thread we don't need one
per ssl object anymore. It could also try to get entropy from a DRBG
that's really from an other thread because the SSL object moved to an
other thread.

Reviewed-by: default avatarTim Hudson <tjh@openssl.org>
Reviewed-by: default avatarPaul Dale <paul.dale@oracle.com>
Reviewed-by: default avatarMatthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/5547)
parent 7caf122e
Loading
Loading
Loading
Loading
+5 −17
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#include "internal/evp_int.h"
#include "modes_lcl.h"
#include <openssl/rand.h>
#include <openssl/rand_drbg.h>
#include "evp_locl.h"

typedef struct {
@@ -1405,14 +1404,8 @@ static int s390x_aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
            memcpy(gctx->iv, ptr, arg);

        enc = EVP_CIPHER_CTX_encrypting(c);
        if (enc) {
            if (c->drbg != NULL) {
                if (RAND_DRBG_bytes(c->drbg, gctx->iv + arg, gctx->ivlen - arg) == 0)
                    return 0;
            } else if (RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0) {
        if (enc && RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0)
            return 0;
            }
        }

        gctx->iv_gen = 1;
        return 1;
@@ -2639,14 +2632,9 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
            return 0;
        if (arg)
            memcpy(gctx->iv, ptr, arg);
        if (EVP_CIPHER_CTX_encrypting(c)) {
            if (c->drbg != NULL) {
                if (RAND_DRBG_bytes(c->drbg, gctx->iv + arg, gctx->ivlen - arg) == 0)
        if (EVP_CIPHER_CTX_encrypting(c)
            && RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0)
            return 0;
            } else if (RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0) {
                return 0;
            }
        }
        gctx->iv_gen = 1;
        return 1;

+3 −12
Original line number Diff line number Diff line
@@ -17,11 +17,9 @@
#include <openssl/aes.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <openssl/rand_drbg.h>
#include "modes_lcl.h"
#include "internal/evp_int.h"
#include "internal/constant_time_locl.h"
#include "evp_locl.h"

typedef struct {
    AES_KEY ks;
@@ -156,8 +154,7 @@ void aesni_multi_cbc_encrypt(CIPH_DESC *, void *, int);
static size_t tls1_1_multi_block_encrypt(EVP_AES_HMAC_SHA1 *key,
                                         unsigned char *out,
                                         const unsigned char *inp,
                                         size_t inp_len, int n4x,
                                         RAND_DRBG *drbg)
                                         size_t inp_len, int n4x)
{                               /* n4x is 1 or 2 */
    HASH_DESC hash_d[8], edges[8];
    CIPH_DESC ciph_d[8];
@@ -177,13 +174,8 @@ static size_t tls1_1_multi_block_encrypt(EVP_AES_HMAC_SHA1 *key,
#  endif

    /* ask for IVs in bulk */
    IVs = blocks[0].c;
    if (drbg != NULL) {
        if (RAND_DRBG_bytes(drbg, IVs, 16 * x4) == 0)
    if (RAND_bytes((IVs = blocks[0].c), 16 * x4) <= 0)
        return 0;
    } else if (RAND_bytes(IVs, 16 * x4) <= 0) {
        return 0;
    }

    ctx = (SHA1_MB_CTX *) (storage + 32 - ((size_t)storage % 32)); /* align */

@@ -901,8 +893,7 @@ static int aesni_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,

            return (int)tls1_1_multi_block_encrypt(key, param->out,
                                                   param->inp, param->len,
                                                   param->interleave / 4,
                                                   ctx->drbg);
                                                   param->interleave / 4);
        }
    case EVP_CTRL_TLS1_1_MULTIBLOCK_DECRYPT:
# endif
+3 −12
Original line number Diff line number Diff line
@@ -18,11 +18,9 @@
#include <openssl/aes.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <openssl/rand_drbg.h>
#include "modes_lcl.h"
#include "internal/constant_time_locl.h"
#include "internal/evp_int.h"
#include "evp_locl.h"

typedef struct {
    AES_KEY ks;
@@ -152,8 +150,7 @@ void aesni_multi_cbc_encrypt(CIPH_DESC *, void *, int);
static size_t tls1_1_multi_block_encrypt(EVP_AES_HMAC_SHA256 *key,
                                         unsigned char *out,
                                         const unsigned char *inp,
                                         size_t inp_len, int n4x,
                                         RAND_DRBG *drbg)
                                         size_t inp_len, int n4x)
{                               /* n4x is 1 or 2 */
    HASH_DESC hash_d[8], edges[8];
    CIPH_DESC ciph_d[8];
@@ -173,13 +170,8 @@ static size_t tls1_1_multi_block_encrypt(EVP_AES_HMAC_SHA256 *key,
#  endif

    /* ask for IVs in bulk */
    IVs = blocks[0].c;
    if (drbg != NULL) {
        if (RAND_DRBG_bytes(drbg, IVs, 16 * x4) == 0)
    if (RAND_bytes((IVs = blocks[0].c), 16 * x4) <= 0)
        return 0;
    } else if (RAND_bytes(IVs, 16 * x4) <= 0) {
        return 0;
    }

    /* align */
    ctx = (SHA256_MB_CTX *) (storage + 32 - ((size_t)storage % 32));
@@ -885,8 +877,7 @@ static int aesni_cbc_hmac_sha256_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,

            return (int)tls1_1_multi_block_encrypt(key, param->out,
                                                   param->inp, param->len,
                                                   param->interleave / 4,
                                                   ctx->drbg);
                                                   param->interleave / 4);
        }
    case EVP_CTRL_TLS1_1_MULTIBLOCK_DECRYPT:
# endif
+3 −8
Original line number Diff line number Diff line
@@ -302,14 +302,9 @@ static int aria_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
            return 0;
        if (arg)
            memcpy(gctx->iv, ptr, arg);
        if (EVP_CIPHER_CTX_encrypting(c)) {
            if (c->drbg != NULL) {
                if (RAND_DRBG_bytes(c->drbg, gctx->iv + arg, gctx->ivlen - arg) == 0)
        if (EVP_CIPHER_CTX_encrypting(c)
            && RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0)
            return 0;
            } else if (RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0) {
                return 0;
            }
        }
        gctx->iv_gen = 1;
        return 1;

+1 −7
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
# include "internal/evp_int.h"
# include <openssl/des.h>
# include <openssl/rand.h>
# include <openssl/rand_drbg.h>
# include "evp_locl.h"

typedef struct {
    union {
@@ -231,12 +229,8 @@ static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)

    switch (type) {
    case EVP_CTRL_RAND_KEY:
        if (c->drbg != NULL) {
            if (RAND_DRBG_bytes(c->drbg, ptr, 8) == 0)
        if (RAND_bytes(ptr, 8) <= 0)
            return 0;
        } else if (RAND_bytes(ptr, 8) <= 0) {
            return 0;
        }
        DES_set_odd_parity((DES_cblock *)ptr);
        return 1;

Loading