Skip to content

Commit f9e87b9

Browse files
author
jinghe-INTC
authored
update patched rand_lib.c, based on 3.0.12 version (#178)
Signed-off-by: Jing He <[email protected]>
1 parent f7f7e76 commit f9e87b9

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

openssl_source/rand_lib.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
2+
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
33
*
44
* Licensed under the Apache License 2.0 (the "License"). You may not use
55
* this file except in compliance with the License. You can obtain a copy
@@ -96,6 +96,7 @@ void ossl_rand_cleanup_int(void)
9696
CRYPTO_THREAD_lock_free(rand_meth_lock);
9797
rand_meth_lock = NULL;
9898
# endif
99+
ossl_release_default_drbg_ctx();
99100
rand_inited = 0;
100101
}
101102

@@ -119,6 +120,8 @@ void RAND_keep_random_devices_open(int keep)
119120
*/
120121
int RAND_poll(void)
121122
{
123+
static const char salt[] = "polling";
124+
122125
# ifndef OPENSSL_NO_DEPRECATED_3_0
123126
const RAND_METHOD *meth = RAND_get_rand_method();
124127
int ret = meth == RAND_OpenSSL();
@@ -147,14 +150,12 @@ int RAND_poll(void)
147150
ret = 1;
148151
err:
149152
ossl_rand_pool_free(pool);
153+
return ret;
150154
}
151-
return ret;
152-
# else
153-
static const char salt[] = "polling";
155+
# endif
154156

155157
RAND_seed(salt, sizeof(salt));
156158
return 1;
157-
# endif
158159
}
159160

160161
# ifndef OPENSSL_NO_DEPRECATED_3_0
@@ -540,6 +541,8 @@ static EVP_RAND_CTX *rand_new_seed(OSSL_LIB_CTX *libctx)
540541
EVP_RAND_CTX *ctx;
541542
char *name;
542543

544+
if (dgbl == NULL)
545+
return NULL;
543546
name = dgbl->seed_name != NULL ? dgbl->seed_name : "SEED-SRC";
544547
rand = EVP_RAND_fetch(libctx, name, dgbl->seed_propq);
545548
if (rand == NULL) {
@@ -571,6 +574,8 @@ static EVP_RAND_CTX *rand_new_drbg(OSSL_LIB_CTX *libctx, EVP_RAND_CTX *parent,
571574
OSSL_PARAM params[7], *p = params;
572575
char *name, *cipher;
573576

577+
if (dgbl == NULL)
578+
return NULL;
574579
name = dgbl->rng_name != NULL ? dgbl->rng_name : "CTR-DRBG";
575580
rand = EVP_RAND_fetch(libctx, name, dgbl->rng_propq);
576581
if (rand == NULL) {
@@ -770,24 +775,27 @@ static int random_conf_init(CONF_IMODULE *md, const CONF *cnf)
770775
return 0;
771776
}
772777

778+
if (dgbl == NULL)
779+
return 0;
780+
773781
for (i = 0; i < sk_CONF_VALUE_num(elist); i++) {
774782
cval = sk_CONF_VALUE_value(elist, i);
775-
if (strcasecmp(cval->name, "random") == 0) {
783+
if (OPENSSL_strcasecmp(cval->name, "random") == 0) {
776784
if (!random_set_string(&dgbl->rng_name, cval->value))
777785
return 0;
778-
} else if (strcasecmp(cval->name, "cipher") == 0) {
786+
} else if (OPENSSL_strcasecmp(cval->name, "cipher") == 0) {
779787
if (!random_set_string(&dgbl->rng_cipher, cval->value))
780788
return 0;
781-
} else if (strcasecmp(cval->name, "digest") == 0) {
789+
} else if (OPENSSL_strcasecmp(cval->name, "digest") == 0) {
782790
if (!random_set_string(&dgbl->rng_digest, cval->value))
783791
return 0;
784-
} else if (strcasecmp(cval->name, "properties") == 0) {
792+
} else if (OPENSSL_strcasecmp(cval->name, "properties") == 0) {
785793
if (!random_set_string(&dgbl->rng_propq, cval->value))
786794
return 0;
787-
} else if (strcasecmp(cval->name, "seed") == 0) {
795+
} else if (OPENSSL_strcasecmp(cval->name, "seed") == 0) {
788796
if (!random_set_string(&dgbl->seed_name, cval->value))
789797
return 0;
790-
} else if (strcasecmp(cval->name, "seed_properties") == 0) {
798+
} else if (OPENSSL_strcasecmp(cval->name, "seed_properties") == 0) {
791799
if (!random_set_string(&dgbl->seed_propq, cval->value))
792800
return 0;
793801
} else {

0 commit comments

Comments
 (0)