Commit d91f4568 authored by Kurt Roeckx's avatar Kurt Roeckx
Browse files

Tell the ciphers which DRBG to use for generating random bytes.



Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
GH: #4672
parent b3f9064c
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "internal/evp_int.h"
#include "modes_lcl.h"
#include <openssl/rand.h>
#include <internal/rand.h>
#include "evp_locl.h"

typedef struct {
@@ -1404,8 +1405,14 @@ 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 && RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0)
        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) {
                return 0;
            }
        }

        gctx->iv_gen = 1;
        return 1;
@@ -2632,9 +2639,14 @@ 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)
            && RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0)
        if (EVP_CIPHER_CTX_encrypting(c)) {
            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) {
                return 0;
            }
        }
        gctx->iv_gen = 1;
        return 1;

+12 −3
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@
#include <openssl/aes.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <internal/rand.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;
@@ -154,7 +156,8 @@ 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)
                                         size_t inp_len, int n4x,
                                         RAND_DRBG *drbg)
{                               /* n4x is 1 or 2 */
    HASH_DESC hash_d[8], edges[8];
    CIPH_DESC ciph_d[8];
@@ -174,8 +177,13 @@ static size_t tls1_1_multi_block_encrypt(EVP_AES_HMAC_SHA1 *key,
#  endif

    /* ask for IVs in bulk */
    if (RAND_bytes((IVs = blocks[0].c), 16 * x4) <= 0)
    IVs = blocks[0].c;
    if (drbg != NULL) {
        if (RAND_DRBG_bytes(drbg, IVs, 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 */

@@ -893,7 +901,8 @@ 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);
                                                   param->interleave / 4,
                                                   ctx->drbg);
        }
    case EVP_CTRL_TLS1_1_MULTIBLOCK_DECRYPT:
# endif
+12 −3
Original line number Diff line number Diff line
@@ -18,9 +18,11 @@
#include <openssl/aes.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <internal/rand.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;
@@ -150,7 +152,8 @@ 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)
                                         size_t inp_len, int n4x,
                                         RAND_DRBG *drbg)
{                               /* n4x is 1 or 2 */
    HASH_DESC hash_d[8], edges[8];
    CIPH_DESC ciph_d[8];
@@ -170,8 +173,13 @@ static size_t tls1_1_multi_block_encrypt(EVP_AES_HMAC_SHA256 *key,
#  endif

    /* ask for IVs in bulk */
    if (RAND_bytes((IVs = blocks[0].c), 16 * x4) <= 0)
    IVs = blocks[0].c;
    if (drbg != NULL) {
        if (RAND_DRBG_bytes(drbg, IVs, 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));
@@ -877,7 +885,8 @@ 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);
                                                   param->interleave / 4,
                                                   ctx->drbg);
        }
    case EVP_CTRL_TLS1_1_MULTIBLOCK_DECRYPT:
# endif
+9 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
# include <openssl/rand.h>
# include "internal/aria.h"
# include "internal/evp_int.h"
# include "internal/rand.h"
# include "modes_lcl.h"
# include "evp_locl.h"

@@ -301,9 +302,14 @@ 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)
            && RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0)
        if (EVP_CIPHER_CTX_encrypting(c)) {
            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) {
                return 0;
            }
        }
        gctx->iv_gen = 1;
        return 1;

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

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

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

Loading