mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-03 04:34:41 +02:00
@@ -1084,6 +1084,12 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
err_sys("unable to get ctx");
|
err_sys("unable to get ctx");
|
||||||
|
|
||||||
|
#ifdef SINGLE_THREADED
|
||||||
|
if (wolfSSL_CTX_new_rng(ctx) != SSL_SUCCESS) {
|
||||||
|
err_sys("Single Threaded new rng at CTX failed");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (cipherList) {
|
if (cipherList) {
|
||||||
if (wolfSSL_CTX_set_cipher_list(ctx, cipherList) != SSL_SUCCESS)
|
if (wolfSSL_CTX_set_cipher_list(ctx, cipherList) != SSL_SUCCESS)
|
||||||
err_sys("client can't set cipher list 1");
|
err_sys("client can't set cipher list 1");
|
||||||
|
@@ -1449,6 +1449,13 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx)
|
|||||||
XFREE(ctx->serverDH_P.buffer, ctx->heap, DYNAMIC_TYPE_DH);
|
XFREE(ctx->serverDH_P.buffer, ctx->heap, DYNAMIC_TYPE_DH);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SINGLE_THREADED
|
||||||
|
if (ctx->rng) {
|
||||||
|
wc_FreeRng(ctx->rng);
|
||||||
|
XFREE(ctx->rng, ctx->heap, DYNAMIC_TYPE_RNG);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef NO_CERTS
|
#ifndef NO_CERTS
|
||||||
FreeDer(&ctx->privateKey);
|
FreeDer(&ctx->privateKey);
|
||||||
FreeDer(&ctx->certificate);
|
FreeDer(&ctx->certificate);
|
||||||
@@ -3475,12 +3482,18 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SINGLE_THREADED
|
||||||
|
ssl->rng = ctx->rng; /* CTX may have one, if so use it */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (ssl->rng == NULL) {
|
||||||
/* RNG */
|
/* RNG */
|
||||||
ssl->rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), ssl->heap,DYNAMIC_TYPE_RNG);
|
ssl->rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), ssl->heap,DYNAMIC_TYPE_RNG);
|
||||||
if (ssl->rng == NULL) {
|
if (ssl->rng == NULL) {
|
||||||
WOLFSSL_MSG("RNG Memory error");
|
WOLFSSL_MSG("RNG Memory error");
|
||||||
return MEMORY_E;
|
return MEMORY_E;
|
||||||
}
|
}
|
||||||
|
ssl->options.weOwnRng = 1;
|
||||||
|
|
||||||
/* FIPS RNG API does not accept a heap hint */
|
/* FIPS RNG API does not accept a heap hint */
|
||||||
#ifndef HAVE_FIPS
|
#ifndef HAVE_FIPS
|
||||||
@@ -3494,6 +3507,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_SERVER)
|
#if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_SERVER)
|
||||||
if (ssl->options.dtls && ssl->options.side == WOLFSSL_SERVER_END) {
|
if (ssl->options.dtls && ssl->options.side == WOLFSSL_SERVER_END) {
|
||||||
@@ -3591,8 +3605,10 @@ void SSL_ResourceFree(WOLFSSL* ssl)
|
|||||||
FreeCiphers(ssl);
|
FreeCiphers(ssl);
|
||||||
FreeArrays(ssl, 0);
|
FreeArrays(ssl, 0);
|
||||||
FreeKeyExchange(ssl);
|
FreeKeyExchange(ssl);
|
||||||
|
if (ssl->options.weOwnRng) {
|
||||||
wc_FreeRng(ssl->rng);
|
wc_FreeRng(ssl->rng);
|
||||||
XFREE(ssl->rng, ssl->heap, DYNAMIC_TYPE_RNG);
|
XFREE(ssl->rng, ssl->heap, DYNAMIC_TYPE_RNG);
|
||||||
|
}
|
||||||
XFREE(ssl->suites, ssl->heap, DYNAMIC_TYPE_SUITES);
|
XFREE(ssl->suites, ssl->heap, DYNAMIC_TYPE_SUITES);
|
||||||
XFREE(ssl->hsHashes, ssl->heap, DYNAMIC_TYPE_HASHES);
|
XFREE(ssl->hsHashes, ssl->heap, DYNAMIC_TYPE_HASHES);
|
||||||
XFREE(ssl->buffers.domainName.buffer, ssl->heap, DYNAMIC_TYPE_DOMAIN);
|
XFREE(ssl->buffers.domainName.buffer, ssl->heap, DYNAMIC_TYPE_DOMAIN);
|
||||||
@@ -3783,9 +3799,12 @@ void FreeHandshakeResources(WOLFSSL* ssl)
|
|||||||
|
|
||||||
/* RNG */
|
/* RNG */
|
||||||
if (ssl->specs.cipher_type == stream || ssl->options.tls1_1 == 0) {
|
if (ssl->specs.cipher_type == stream || ssl->options.tls1_1 == 0) {
|
||||||
|
if (ssl->options.weOwnRng) {
|
||||||
wc_FreeRng(ssl->rng);
|
wc_FreeRng(ssl->rng);
|
||||||
XFREE(ssl->rng, ssl->heap, DYNAMIC_TYPE_RNG);
|
XFREE(ssl->rng, ssl->heap, DYNAMIC_TYPE_RNG);
|
||||||
ssl->rng = NULL;
|
ssl->rng = NULL;
|
||||||
|
ssl->options.weOwnRng = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WOLFSSL_DTLS
|
#ifdef WOLFSSL_DTLS
|
||||||
|
33
src/ssl.c
33
src/ssl.c
@@ -2323,6 +2323,39 @@ int wolfSSL_CertManagerUnloadCAs(WOLFSSL_CERT_MANAGER* cm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SINGLE_THREADED
|
||||||
|
/* no locking in single threaded mode, allow a CTX level rng to be shared with
|
||||||
|
* WOLFSSL objects, SSL_SUCCESS on ok */
|
||||||
|
int wolfSSL_CTX_new_rng(WOLFSSL_CTX* ctx)
|
||||||
|
{
|
||||||
|
WC_RNG* rng;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (ctx == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
rng = XMALLOC(sizeof(WC_RNG), ctx->heap, DYNAMIC_TYPE_RNG);
|
||||||
|
if (rng == NULL) {
|
||||||
|
return MEMORY_E;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS
|
||||||
|
ret = wc_InitRng_ex(rng, ctx->heap);
|
||||||
|
#else
|
||||||
|
ret = wc_InitRng(rng);
|
||||||
|
#endif
|
||||||
|
if (ret != 0) {
|
||||||
|
XFREE(rng, ctx->heap, DYNAMIC_TYPE_RNG);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->rng = rng;
|
||||||
|
return SSL_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_TRUST_PEER_CERT
|
#ifdef WOLFSSL_TRUST_PEER_CERT
|
||||||
int wolfSSL_CertManagerUnload_trust_peers(WOLFSSL_CERT_MANAGER* cm)
|
int wolfSSL_CertManagerUnload_trust_peers(WOLFSSL_CERT_MANAGER* cm)
|
||||||
{
|
{
|
||||||
|
@@ -1029,29 +1029,28 @@ static int wc_InitRng_IntelRD()
|
|||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INTELRD_RETRY 10
|
#define INTELRD_RETRY 32
|
||||||
|
|
||||||
#if defined(HAVE_HASHDRBG) || defined(NO_RC4)
|
#if defined(HAVE_HASHDRBG) || defined(NO_RC4)
|
||||||
|
|
||||||
/* return 0 on success */
|
/* return 0 on success */
|
||||||
static INLINE int IntelRDseed32(unsigned int *seed)
|
static INLINE int IntelRDseed64(word64* seed)
|
||||||
{
|
{
|
||||||
int rdseed; unsigned char ok ;
|
unsigned char ok;
|
||||||
|
|
||||||
__asm__ volatile("rdseed %0; setc %1":"=r"(rdseed), "=qm"(ok));
|
__asm__ volatile("rdseed %0; setc %1":"=r"(*seed), "=qm"(ok));
|
||||||
if(ok){
|
if(ok){
|
||||||
*seed = rdseed ;
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
} else
|
} else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return 0 on success */
|
/* return 0 on success */
|
||||||
static INLINE int IntelRDseed32_r(unsigned int *rnd)
|
static INLINE int IntelRDseed64_r(word64* rnd)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<INTELRD_RETRY;i++) {
|
for(i=0; i<INTELRD_RETRY;i++) {
|
||||||
if(IntelRDseed32(rnd) == 0) return 0 ;
|
if(IntelRDseed64(rnd) == 0) return 0 ;
|
||||||
}
|
}
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
@@ -1061,17 +1060,17 @@ static int wc_GenerateSeed_IntelRD(OS_Seed* os, byte* output, word32 sz)
|
|||||||
{
|
{
|
||||||
(void) os ;
|
(void) os ;
|
||||||
int ret ;
|
int ret ;
|
||||||
unsigned int rndTmp ;
|
word64 rndTmp ;
|
||||||
|
|
||||||
for( ; sz/4 > 0; sz-=4, output+=4) {
|
for( ; sz/8 > 0; sz-=8, output+=8) {
|
||||||
if(IS_INTEL_RDSEED)ret = IntelRDseed32_r((word32 *)output) ;
|
if(IS_INTEL_RDSEED)ret = IntelRDseed64_r((word64*)output);
|
||||||
else return 1 ;
|
else return 1 ;
|
||||||
if(ret)
|
if(ret)
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
if(sz == 0)return 0 ;
|
if(sz == 0)return 0 ;
|
||||||
|
|
||||||
if(IS_INTEL_RDSEED)ret = IntelRDseed32_r(&rndTmp) ;
|
if(IS_INTEL_RDSEED)ret = IntelRDseed64_r(&rndTmp) ;
|
||||||
else return 1 ;
|
else return 1 ;
|
||||||
if(ret)
|
if(ret)
|
||||||
return 1 ;
|
return 1 ;
|
||||||
@@ -1621,8 +1620,21 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
|||||||
|
|
||||||
#if defined(HAVE_INTEL_RDGEN) && (defined(HAVE_HASHDRBG) || defined(NO_RC4))
|
#if defined(HAVE_INTEL_RDGEN) && (defined(HAVE_HASHDRBG) || defined(NO_RC4))
|
||||||
wc_InitRng_IntelRD() ; /* set cpuid_flags if not yet */
|
wc_InitRng_IntelRD() ; /* set cpuid_flags if not yet */
|
||||||
if(IS_INTEL_RDSEED)
|
if(IS_INTEL_RDSEED) {
|
||||||
return wc_GenerateSeed_IntelRD(NULL, output, sz) ;
|
ret = wc_GenerateSeed_IntelRD(NULL, output, sz);
|
||||||
|
if (ret == 0) {
|
||||||
|
/* success, we're done */
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#ifdef FORCE_FAILURE_RDSEED
|
||||||
|
/* don't fallback to /dev/urandom */
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
|
/* fallback to /dev/urandom attempt */
|
||||||
|
ret = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
os->fd = open("/dev/urandom",O_RDONLY);
|
os->fd = open("/dev/urandom",O_RDONLY);
|
||||||
|
@@ -1902,6 +1902,9 @@ WOLFSSL_LOCAL int TLSX_ValidateQSHScheme(TLSX** extensions, word16 name);
|
|||||||
/* wolfSSL context type */
|
/* wolfSSL context type */
|
||||||
struct WOLFSSL_CTX {
|
struct WOLFSSL_CTX {
|
||||||
WOLFSSL_METHOD* method;
|
WOLFSSL_METHOD* method;
|
||||||
|
#ifdef SINGLE_THREADED
|
||||||
|
WC_RNG* rng; /* to be shared with WOLFSSL w/o locking */
|
||||||
|
#endif
|
||||||
wolfSSL_Mutex countMutex; /* reference count mutex */
|
wolfSSL_Mutex countMutex; /* reference count mutex */
|
||||||
int refCount; /* reference count */
|
int refCount; /* reference count */
|
||||||
int err; /* error code in case of mutex not created */
|
int err; /* error code in case of mutex not created */
|
||||||
@@ -2396,6 +2399,7 @@ typedef struct Options {
|
|||||||
word16 usingNonblock:1; /* are we using nonblocking socket */
|
word16 usingNonblock:1; /* are we using nonblocking socket */
|
||||||
word16 saveArrays:1; /* save array Memory for user get keys
|
word16 saveArrays:1; /* save array Memory for user get keys
|
||||||
or psk */
|
or psk */
|
||||||
|
word16 weOwnRng:1; /* will be true unless CTX owns */
|
||||||
#ifdef HAVE_POLY1305
|
#ifdef HAVE_POLY1305
|
||||||
word16 oldPoly:1; /* set when to use old rfc way of poly*/
|
word16 oldPoly:1; /* set when to use old rfc way of poly*/
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1418,6 +1418,11 @@ WOLFSSL_API void* wolfSSL_GetRsaDecCtx(WOLFSSL* ssl);
|
|||||||
WOLFSSL_API int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX*);
|
WOLFSSL_API int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX*);
|
||||||
#endif /* !NO_CERTS */
|
#endif /* !NO_CERTS */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SINGLE_THREADED
|
||||||
|
WOLFSSL_API int wolfSSL_CTX_new_rng(WOLFSSL_CTX*);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* end of handshake frees temporary arrays, if user needs for get_keys or
|
/* end of handshake frees temporary arrays, if user needs for get_keys or
|
||||||
psk hints, call KeepArrays before handshake and then FreeArrays when done
|
psk hints, call KeepArrays before handshake and then FreeArrays when done
|
||||||
if don't want to wait for object free */
|
if don't want to wait for object free */
|
||||||
|
Reference in New Issue
Block a user