Merge pull request #5085 from douzzer/20220426-multi-test

20220426 multi-test fixups
This commit is contained in:
David Garske
2022-04-26 11:15:59 -07:00
committed by GitHub
4 changed files with 55 additions and 107 deletions

View File

@ -26454,7 +26454,7 @@ WOLFSSL_DH* wolfSSL_DH_new(void)
WOLFSSL_DH* wolSSL_DH_new_by_nid(int nid)
{
WOLFSSL_DH* dh;
WOLFSSL_DH* dh = NULL;
int err = 0;
#if defined(HAVE_PUBLIC_FFDHE) || (defined(HAVE_FIPS) && FIPS_VERSION_EQ(2,0))
const DhParams* params = NULL;
@ -26473,40 +26473,39 @@ WOLFSSL_DH* wolSSL_DH_new_by_nid(int nid)
WOLFSSL_ENTER("wolfSSL_DH_new_by_nid");
dh = wolfSSL_DH_new();
if (dh == NULL) {
WOLFSSL_MSG("Failed to create WOLFSSL_DH.");
err = 1;
}
/* HAVE_PUBLIC_FFDHE not required to expose wc_Dh_ffdhe* functions in FIPS v2
* module */
#if defined(HAVE_PUBLIC_FFDHE) || (defined(HAVE_FIPS) && FIPS_VERSION_EQ(2,0))
if (err == 0) {
switch (nid) {
switch (nid) {
#ifdef HAVE_FFDHE_2048
case NID_ffdhe2048:
params = wc_Dh_ffdhe2048_Get();
break;
case NID_ffdhe2048:
params = wc_Dh_ffdhe2048_Get();
break;
#endif /* HAVE_FFDHE_2048 */
#ifdef HAVE_FFDHE_3072
case NID_ffdhe3072:
params = wc_Dh_ffdhe3072_Get();
break;
case NID_ffdhe3072:
params = wc_Dh_ffdhe3072_Get();
break;
#endif /* HAVE_FFDHE_3072 */
#ifdef HAVE_FFDHE_4096
case NID_ffdhe4096:
params = wc_Dh_ffdhe4096_Get();
break;
case NID_ffdhe4096:
params = wc_Dh_ffdhe4096_Get();
break;
#endif /* HAVE_FFDHE_4096 */
default:
break;
}
default:
break;
}
if (err == 0 && params == NULL) {
if (params == NULL) {
WOLFSSL_MSG("Unable to find DH params for nid.");
err = 1;
}
if (err == 0) {
dh = wolfSSL_DH_new();
if (dh == NULL) {
WOLFSSL_MSG("Failed to create WOLFSSL_DH.");
err = 1;
}
}
if (err == 0) {
pBn = wolfSSL_BN_bin2bn(params->p, params->p_len, NULL);
if (pBn == NULL) {
@ -26537,12 +26536,14 @@ WOLFSSL_DH* wolSSL_DH_new_by_nid(int nid)
err = 1;
}
#else
dh->p = pBn;
dh->q = qBn;
dh->g = gBn;
if (err == 0 && SetDhInternal(dh) != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("Failed to set internal DH params.");
err = 1;
if (err == 0) {
dh->p = pBn;
dh->q = qBn;
dh->g = gBn;
if (SetDhInternal(dh) != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("Failed to set internal DH params.");
err = 1;
}
}
#endif /* OPENSSL_ALL || OPENSSL_VERSION_NUMBER >= 0x10100000L */
@ -26554,27 +26555,32 @@ WOLFSSL_DH* wolSSL_DH_new_by_nid(int nid)
/* FIPS v2 and lower doesn't support wc_DhSetNamedKey. */
#elif !defined(HAVE_PUBLIC_FFDHE) && (!defined(HAVE_FIPS) || \
FIPS_VERSION_GT(2,0))
if (err == 0) {
switch (nid) {
switch (nid) {
#ifdef HAVE_FFDHE_2048
case NID_ffdhe2048:
name = WC_FFDHE_2048;
break;
case NID_ffdhe2048:
name = WC_FFDHE_2048;
break;
#endif /* HAVE_FFDHE_2048 */
#ifdef HAVE_FFDHE_3072
case NID_ffdhe3072:
name = WC_FFDHE_3072;
break;
case NID_ffdhe3072:
name = WC_FFDHE_3072;
break;
#endif /* HAVE_FFDHE_3072 */
#ifdef HAVE_FFDHE_4096
case NID_ffdhe4096:
name = WC_FFDHE_4096;
break;
case NID_ffdhe4096:
name = WC_FFDHE_4096;
break;
#endif /* HAVE_FFDHE_4096 */
default:
err = 1;
WOLFSSL_MSG("Unable to find DH params for nid.");
break;
default:
err = 1;
WOLFSSL_MSG("Unable to find DH params for nid.");
break;
}
if (err == 0) {
dh = wolfSSL_DH_new();
if (dh == NULL) {
WOLFSSL_MSG("Failed to create WOLFSSL_DH.");
err = 1;
}
}
if (err == 0 && wc_DhSetNamedKey((DhKey*)dh->internal, name) != 0) {
@ -26595,6 +26601,8 @@ WOLFSSL_DH* wolSSL_DH_new_by_nid(int nid)
dh = NULL;
}
WOLFSSL_LEAVE("wolfSSL_DH_new_by_nid", err);
return dh;
}

View File

@ -52837,7 +52837,7 @@ static void test_wolfSSL_DH(void)
#else
AssertNull((dh = DH_new_by_nid(NID_ffdhe2048)));
#endif /* (HAVE_PUBLIC_FFDHE || (HAVE_FIPS && HAVE_FIPS_VERSION == 2)) ||
* (!HAVE_PUBLIC_FFDHE && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2))*/
* (!HAVE_PUBLIC_FFDHE && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2))*/
printf(resultFmt, passed);
#endif /* OPENSSL_EXTRA && !NO_DH */
}

View File

@ -1379,7 +1379,7 @@ typedef enum bench_stat_type {
pthread_mutex_unlock(&bench_lock);
}
#else
#else /* !WC_ENABLE_BENCH_THREADING */
typedef struct bench_stats {
const char* algo;
@ -1403,29 +1403,8 @@ typedef enum bench_stat_type {
if (gStatsCount >= MAX_BENCH_STATS)
return bstat;
#ifdef WC_ENABLE_BENCH_THREADING
/* protect bench_stats_head and bench_stats_tail access */
pthread_mutex_lock(&bench_lock);
#endif
bstat = &gStats[gStatsCount++];
bstat->algo = algo;
#ifdef WC_ENABLE_BENCH_THREADING
pthread_mutex_lock(&bench_lock);
if (g_threadCount > 1) {
int algoLen = (int)(XSTRLEN(algo) + 1);
bstat->algo = (const char* )XMALLOC(algoLen, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER);
if (bstat->algo == NULL) {
bstat->algo = "UNKNOWN";
type = BENCH_STAT_IGNORE;
}
else {
XSTRNCPY((char* )bstat->algo, algo, algoLen);
}
}
pthread_mutex_unlock(&bench_lock);
#endif
bstat->desc = desc;
bstat->perfsec = perfsec;
bstat->perftype = perftype;
@ -1435,10 +1414,6 @@ typedef enum bench_stat_type {
(void)useDeviceID;
#ifdef WC_ENABLE_BENCH_THREADING
pthread_mutex_unlock(&bench_lock);
#endif
return bstat;
}
@ -1447,35 +1422,6 @@ typedef enum bench_stat_type {
int i;
bench_stats_t* bstat;
#ifdef WC_ENABLE_BENCH_THREADING
pthread_mutex_lock(&bench_lock);
if (g_threadCount > 1) {
int j;
bench_stats_t* bstat2;
/* Merge results and mark duplicates with type ignore. */
for (i=0; i<gStatsCount; i++) {
bstat = &gStats[i];
if (bstat->type == BENCH_STAT_IGNORE)
continue;
for (j=i+1; j<gStatsCount; j++) {
bstat2 = &gStats[j];
if (bstat2->type == BENCH_STAT_IGNORE)
continue;
if ((XSTRNCMP(bstat->algo, bstat2->algo,
XSTRLEN(bstat->algo)) == 0) &&
(XSTRNCMP(bstat->desc, bstat2->desc,
XSTRLEN(bstat->desc)) == 0)) {
bstat2->type = BENCH_STAT_IGNORE;
bstat->perfsec += bstat2->perfsec;
}
}
}
}
pthread_mutex_unlock(&bench_lock);
#endif
for (i=0; i<gStatsCount; i++) {
bstat = &gStats[i];
if (bstat->type == BENCH_STAT_SYM) {
@ -1486,16 +1432,9 @@ typedef enum bench_stat_type {
printf("%-5s %4d %-9s %.3f ops/sec\n",
bstat->algo, bstat->strength, bstat->desc, bstat->perfsec);
}
#ifdef WC_ENABLE_BENCH_THREADING
pthread_mutex_lock(&bench_lock);
if (g_threadCount > 1) {
free((void*)bstat->algo);
}
pthread_mutex_unlock(&bench_lock);
#endif
}
}
#endif /* WOLFSSL_ASYNC_CRYPT && !WC_NO_ASYNC_THREADING */
#endif /* WC_ENABLE_BENCH_THREADING */
static WC_INLINE void bench_stats_init(void)
{

View File

@ -8608,6 +8608,7 @@ void wolfSSL_EVP_PKEY_free(WOLFSSL_EVP_PKEY* key)
key->hkdfSaltSz = 0;
key->hkdfKeySz = 0;
key->hkdfInfoSz = 0;
break;
#endif /* HAVE_HKDF */
default: