From 55ca2c2da7ec1f4b5998f85a07a9c7f6249a8480 Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 21 Feb 2019 10:45:09 -0800 Subject: [PATCH 1/5] Added build-time override for benchmark thread count `WC_ASYNC_BENCH_THREAD_COUNT`. --- wolfcrypt/benchmark/benchmark.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 9fb97c9b2..98dad2691 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -1701,8 +1701,13 @@ int benchmark_test(void *args) #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING) { - int i; - int numCpus = wc_AsyncGetNumberOfCpus(); + int i, numCpus; + +#ifdef WC_ASYNC_BENCH_THREAD_COUNT + numCpus = WC_ASYNC_BENCH_THREAD_COUNT; +#else + numCpus = wc_AsyncGetNumberOfCpus(); +#endif printf("CPUs: %d\n", numCpus); From 9ff976a6e1414664a4c410065d3695a0f6077581 Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 22 Feb 2019 13:47:34 -0800 Subject: [PATCH 2/5] Fixes for wolfCrypt test with asynchronous support enabled and `--enable-nginx`. --- wolfcrypt/test/test.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 122c08112..2fa901fa1 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -15693,6 +15693,9 @@ static int ecc_test_make_pub(WC_RNG* rng) x = FOURK_BUF; ret = wc_ecc_shared_secret(&key, &pub, exportBuf, &x); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &pub.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); +#endif wc_ecc_free(&pub); if (ret != 0) { ERROR_OUT(-8332, done); @@ -16601,6 +16604,9 @@ static int ecc_ssh_test(ecc_key* key) /* Use API. */ ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); +#endif if (ret != 0) return -8448; return 0; From b45241f6f8db5b4c1e353ba70e3cd1dc7710e8a9 Mon Sep 17 00:00:00 2001 From: David Garske Date: Mon, 25 Feb 2019 14:51:15 -0800 Subject: [PATCH 3/5] Fix to use QAT for ECC sign and verify when SP is enabled and key was initialized with devId. Fixes issues with wolfCrypt test and QAT not properly calling "again" for the ECC sign, verify and shared secret. --- wolfcrypt/src/ecc.c | 52 +++++++++---------- wolfcrypt/test/test.c | 115 ++++++++++++++++++++++++++++++------------ 2 files changed, 109 insertions(+), 58 deletions(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 8e5bf8ef0..0bdf8c42c 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -3322,7 +3322,7 @@ int wc_ecc_get_curve_id_from_oid(const byte* oid, word32 len) } -#ifdef WOLFSSL_ASYNC_CRYPT +#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) static WC_INLINE int wc_ecc_alloc_mpint(ecc_key* key, mp_int** mp) { if (key == NULL || mp == NULL) @@ -3362,7 +3362,7 @@ static void wc_ecc_free_async(ecc_key* key) wc_ecc_free_mpint(key, &key->signK); #endif /* HAVE_CAVIUM_V */ } -#endif /* WOLFSSL_ASYNC_CRYPT */ +#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */ #ifdef HAVE_ECC_DHE @@ -3576,7 +3576,7 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key, return err; } -#endif /* WOLFSSL_ASYNC_CRYPT */ +#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */ int wc_ecc_shared_secret_gen(ecc_key* private_key, ecc_point* point, byte* out, word32 *outlen) @@ -3685,7 +3685,7 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point, } /* cleanup */ -#ifdef WOLFSSL_ASYNC_CRYPT +#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) wc_ecc_free_async(private_key); #endif private_key->state = ECC_STATE_NONE; @@ -4308,7 +4308,8 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, { int err; mp_int *r = NULL, *s = NULL; -#if !defined(WOLFSSL_ASYNC_CRYPT) && !defined(WOLFSSL_SMALL_STACK) +#if (!defined(WOLFSSL_ASYNC_CRYPT) || !defined(WC_ASYNC_ENABLE_ECC)) && \ + !defined(WOLFSSL_SMALL_STACK) mp_int r_lcl, s_lcl; #endif @@ -4325,7 +4326,7 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, } #endif -#ifdef WOLFSSL_ASYNC_CRYPT +#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) err = wc_ecc_alloc_async(key); if (err != 0) return err; @@ -4343,7 +4344,7 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, XFREE(r, key->heap, DYNAMIC_TYPE_ECC); return MEMORY_E; } -#endif +#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */ switch(key->state) { case ECC_STATE_NONE: @@ -4415,7 +4416,7 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, } /* cleanup */ -#ifdef WOLFSSL_ASYNC_CRYPT +#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) wc_ecc_free_async(key); #endif key->state = ECC_STATE_NONE; @@ -4467,8 +4468,7 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng, return WC_KEY_SIZE_E; #else #ifdef WOLFSSL_HAVE_SP_ECC - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \ - defined(WOLFSSL_ASYNC_CRYPT_TEST) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) if (key->asyncDev.marker != WOLFSSL_ASYNC_MARKER_ECC) #endif { @@ -4624,7 +4624,7 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng, } #endif /* HAVE_CAVIUM_V || HAVE_INTEL_QA */ } - #endif /* WOLFSSL_ASYNC_CRYPT */ + #endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */ #ifdef WOLFSSL_SMALL_STACK pubkey = (ecc_key*)XMALLOC(sizeof(ecc_key), key->heap, DYNAMIC_TYPE_ECC); @@ -4795,7 +4795,7 @@ int wc_ecc_free(ecc_key* key) return 0; } -#ifdef WOLFSSL_ASYNC_CRYPT +#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) #ifdef WC_ASYNC_ENABLE_ECC wolfAsync_DevCtxFree(&key->asyncDev, WOLFSSL_ASYNC_MARKER_ECC); #endif @@ -5155,8 +5155,9 @@ int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, { int err; mp_int *r = NULL, *s = NULL; -#if !defined(WOLFSSL_ASYNC_CRYPT) && !defined(WOLFSSL_SMALL_STACK) - mp_int r_lcl[1], s_lcl[1]; +#if (!defined(WOLFSSL_ASYNC_CRYPT) || !defined(WC_ASYNC_ENABLE_ECC)) && \ + !defined(WOLFSSL_SMALL_STACK) + mp_int r_lcl, s_lcl; #endif if (sig == NULL || hash == NULL || res == NULL || key == NULL) { @@ -5171,7 +5172,7 @@ int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, } #endif -#ifdef WOLFSSL_ASYNC_CRYPT +#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) err = wc_ecc_alloc_async(key); if (err != 0) return err; @@ -5179,8 +5180,8 @@ int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, s = key->s; #else #ifndef WOLFSSL_SMALL_STACK - r = r_lcl; - s = s_lcl; + r = &r_lcl; + s = &s_lcl; #else r = (mp_int*)XMALLOC(sizeof(mp_int), key->heap, DYNAMIC_TYPE_ECC); if (r == NULL) @@ -5252,7 +5253,7 @@ int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, } /* cleanup */ -#ifdef WOLFSSL_ASYNC_CRYPT +#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) wc_ecc_free_async(key); #elif defined(WOLFSSL_SMALL_STACK) XFREE(s, key->heap, DYNAMIC_TYPE_ECC); @@ -5376,8 +5377,7 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash, #else #ifdef WOLFSSL_HAVE_SP_ECC #ifndef WOLFSSL_SP_NO_256 - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \ - defined(WOLFSSL_ASYNC_CRYPT_TEST) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) if (key->asyncDev.marker != WOLFSSL_ASYNC_MARKER_ECC) #endif { @@ -5406,7 +5406,7 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash, } #endif e = e_lcl; -#endif +#endif /* WOLFSSL_ASYNC_CRYPT && HAVE_CAVIUM_V */ err = mp_init(e); if (err != MP_OKAY) @@ -5474,7 +5474,7 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash, } #endif /* HAVE_CAVIUM_V || HAVE_INTEL_QA */ } -#endif /* WOLFSSL_ASYNC_CRYPT */ +#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */ #ifdef WOLFSSL_SMALL_STACK if (err == MP_OKAY) { @@ -8856,7 +8856,7 @@ int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, #endif do { - #if defined(WOLFSSL_ASYNC_CRYPT) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) ret = wc_AsyncWait(ret, &privKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); if (ret != 0) break; @@ -8892,7 +8892,7 @@ int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, AES_ENCRYPTION); if (ret == 0) { ret = wc_AesCbcEncrypt(&aes, out, msg, msgSz); - #if defined(WOLFSSL_ASYNC_CRYPT) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) ret = wc_AsyncWait(ret, &aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -9025,7 +9025,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, #endif do { - #if defined(WOLFSSL_ASYNC_CRYPT) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) ret = wc_AsyncWait(ret, &privKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); if (ret != 0) break; @@ -9093,7 +9093,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, if (ret != 0) break; ret = wc_AesCbcDecrypt(&aes, out, msg, msgSz-digestSz); - #if defined(WOLFSSL_ASYNC_CRYPT) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) ret = wc_AsyncWait(ret, &aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 2fa901fa1..6402fc39e 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -15192,12 +15192,10 @@ static int ecc_test_vector_item(const eccVector* vector) #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); #endif - if (ret >= 0) { + if (ret == 0) ret = wc_ecc_verify_hash(sig, sigSz, (byte*)vector->msg, vector->msgLen, &verify, &userA); - } } while (ret == WC_PENDING_E); - if (ret != 0) goto done; @@ -15495,7 +15493,13 @@ static int ecc_test_cdh_vectors(void) /* compute ECC Cofactor shared secret */ x = sizeof(sharedA); - ret = wc_ecc_shared_secret(&priv_key, &pub_key, sharedA, &x); + do { + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &priv_key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + #endif + if (ret == 0) + ret = wc_ecc_shared_secret(&priv_key, &pub_key, sharedA, &x); + } while (ret == WC_PENDING_E); if (ret != 0) { goto done; } @@ -15631,14 +15635,28 @@ static int ecc_test_make_pub(WC_RNG* rng) #ifdef HAVE_ECC_SIGN tmpSz = FOURK_BUF; - ret = wc_ecc_sign_hash(msg, sizeof(msg), tmp, &tmpSz, rng, &key); + ret = 0; + do { + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + #endif + if (ret == 0) + ret = wc_ecc_sign_hash(msg, sizeof(msg), tmp, &tmpSz, rng, &key); + } while (ret == WC_PENDING_E); if (ret != 0) { ERROR_OUT(-8324, done); } #ifdef HAVE_ECC_VERIFY /* try verify with private only key */ - ret = wc_ecc_verify_hash(tmp, tmpSz, msg, sizeof(msg), &verify, &key); + ret = 0; + do { + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + #endif + if (ret == 0) + ret = wc_ecc_verify_hash(tmp, tmpSz, msg, sizeof(msg), &verify, &key); + } while (ret == WC_PENDING_E); if (ret != 0) { ERROR_OUT(-8325, done); } @@ -15685,17 +15703,21 @@ static int ecc_test_make_pub(WC_RNG* rng) wc_ecc_init_ex(&pub, HEAP_HINT, devId); ret = wc_ecc_make_key(rng, 32, &pub); #if defined(WOLFSSL_ASYNC_CRYPT) - ret = wc_AsyncWait(ret, &pub.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + ret = wc_AsyncWait(ret, &pub.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) { ERROR_OUT(-8331, done); } x = FOURK_BUF; - ret = wc_ecc_shared_secret(&key, &pub, exportBuf, &x); -#if defined(WOLFSSL_ASYNC_CRYPT) - ret = wc_AsyncWait(ret, &pub.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); -#endif + do { + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + #endif + if (ret == 0) { + ret = wc_ecc_shared_secret(&key, &pub, exportBuf, &x); + } + } while (ret == WC_PENDING_E); wc_ecc_free(&pub); if (ret != 0) { ERROR_OUT(-8332, done); @@ -15743,7 +15765,7 @@ static int ecc_test_key_gen(WC_RNG* rng, int keySize) ret = wc_ecc_make_key(rng, keySize, &userA); #if defined(WOLFSSL_ASYNC_CRYPT) - ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) goto done; @@ -15856,7 +15878,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_make_key_ex(rng, keySize, &userA, curve_id); #if defined(WOLFSSL_ASYNC_CRYPT) - ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) goto done; @@ -15875,7 +15897,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_make_key_ex(rng, keySize, &userB, curve_id); #if defined(WOLFSSL_ASYNC_CRYPT) - ret = wc_AsyncWait(ret, &userB.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + ret = wc_AsyncWait(ret, &userB.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) goto done; @@ -15893,7 +15915,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); #endif - if (ret >= 0) + if (ret == 0) ret = wc_ecc_shared_secret(&userA, &userB, sharedA, &x); } while (ret == WC_PENDING_E); if (ret != 0) { @@ -15905,7 +15927,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userB.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); #endif - if (ret >= 0) + if (ret == 0) ret = wc_ecc_shared_secret(&userB, &userA, sharedB, &y); } while (ret == WC_PENDING_E); if (ret != 0) @@ -15924,13 +15946,25 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, wc_ecc_set_flags(&userB, WC_ECC_FLAG_COFACTOR); x = sizeof(sharedA); - ret = wc_ecc_shared_secret(&userA, &userB, sharedA, &x); + do { + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + #endif + if (ret == 0) + ret = wc_ecc_shared_secret(&userA, &userB, sharedA, &x); + } while (ret == WC_PENDING_E); if (ret != 0) { goto done; } y = sizeof(sharedB); - ret = wc_ecc_shared_secret(&userB, &userA, sharedB, &y); + do { + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &userB.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + #endif + if (ret == 0) + ret = wc_ecc_shared_secret(&userB, &userA, sharedB, &y); + } while (ret == WC_PENDING_E); if (ret != 0) goto done; @@ -15968,7 +16002,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userB.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); #endif - if (ret >= 0) + if (ret == 0) ret = wc_ecc_shared_secret(&userB, &pubKey, sharedB, &y); } while (ret == WC_PENDING_E); if (ret != 0) @@ -16005,7 +16039,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userB.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); #endif - if (ret >= 0) + if (ret == 0) ret = wc_ecc_shared_secret(&userB, &pubKey, sharedB, &y); } while (ret == WC_PENDING_E); if (ret != 0) @@ -16033,7 +16067,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); #endif - if (ret >= 0) + if (ret == 0) ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, &userA); } while (ret == WC_PENDING_E); @@ -16047,7 +16081,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); #endif - if (ret >= 0) + if (ret == 0) ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, &userA); } while (ret == WC_PENDING_E); @@ -16069,7 +16103,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); #endif - if (ret >= 0) + if (ret == 0) ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, &userA); } while (ret == WC_PENDING_E); @@ -16083,7 +16117,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); #endif - if (ret >= 0) + if (ret == 0) ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, &userA); } while (ret == WC_PENDING_E); @@ -16603,10 +16637,14 @@ static int ecc_ssh_test(ecc_key* key) return -8447; /* Use API. */ - ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen); -#if defined(WOLFSSL_ASYNC_CRYPT) - ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); -#endif + ret = 0; + do { + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + #endif + if (ret == 0) + ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen); + } while (ret == WC_PENDING_E); if (ret != 0) return -8448; return 0; @@ -16634,7 +16672,7 @@ static int ecc_def_curve_test(WC_RNG *rng) ret = wc_ecc_make_key(rng, 32, &key); #if defined(WOLFSSL_ASYNC_CRYPT) - ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) { ret = -8451; @@ -17000,7 +17038,7 @@ static int ecc_test_cert_gen(WC_RNG* rng) ret = wc_ecc_make_key(rng, 32, &certPubKey); #if defined(WOLFSSL_ASYNC_CRYPT) - ret = wc_AsyncWait(ret, &certPubKey.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + ret = wc_AsyncWait(ret, &certPubKey.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) { ERROR_OUT(-8524, exit); @@ -17477,13 +17515,26 @@ int ecc_test_buffers(void) { x = sizeof(out); - ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, &cliKey); + do { + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &cliKey.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + #endif + if (ret == 0) + ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, &cliKey); + } while (ret == WC_PENDING_E); if (ret < 0) return -8717; XMEMSET(plain, 0, sizeof(plain)); - ret = wc_ecc_verify_hash(out, x, plain, sizeof(plain), &verify, &cliKey); + do { + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &cliKey.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); + #endif + if (ret == 0) + ret = wc_ecc_verify_hash(out, x, plain, sizeof(plain), &verify, + &cliKey); + } while (ret == WC_PENDING_E); if (ret < 0) return -8718; From 1512f4da907fc6770d3ec83276d04abbe5caf668 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 26 Feb 2019 13:38:33 -0800 Subject: [PATCH 4/5] Correct the output for multi-threaded benchmark usign `-base10` option. --- wolfcrypt/benchmark/benchmark.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 98dad2691..38d98b856 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -934,8 +934,9 @@ static THREAD_LS_T byte* bench_iv = NULL; /* print final stat */ if (isLast) { if (bstat->type == BENCH_STAT_SYM) { - printf("%-12s%s %8.3f MB/s\n", bstat->desc, - BENCH_ASYNC_GET_NAME(bstat->doAsync), bstat->perfsec); + printf("%-16s%s %8.3f %s/s\n", bstat->desc, + BENCH_ASYNC_GET_NAME(bstat->doAsync), bstat->perfsec, + base2 ? "MB" : "mB"); } else { printf("%-5s %4d %-9s %s %.3f ops/sec\n", From 77ffeccb0b315b7f555d968e4e6cbb3f02264795 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 26 Feb 2019 14:34:03 -0800 Subject: [PATCH 5/5] Fixes to QAT enables for benchmark for HMAC. Adds new `NO_HW_BENCH` to support using multi-threaded software only benchmarks. --- wolfcrypt/benchmark/benchmark.c | 86 +++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 38d98b856..b240154d4 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -1204,7 +1204,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_aescbc(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) && \ + !defined(NO_HW_BENCH) bench_aescbc(1); #endif } @@ -1214,7 +1215,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_aesgcm(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) && \ + !defined(NO_HW_BENCH) bench_aesgcm(1); #endif } @@ -1224,7 +1226,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_aesecb(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) && \ + !defined(NO_HW_BENCH) bench_aesecb(1); #endif } @@ -1256,7 +1259,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_arc4(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ARC4) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ARC4) && \ + !defined(NO_HW_BENCH) bench_arc4(1); #endif } @@ -1282,7 +1286,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_des(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES) && \ + !defined(NO_HW_BENCH) bench_des(1); #endif } @@ -1297,7 +1302,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_md5(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_MD5) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_MD5) && \ + !defined(NO_HW_BENCH) bench_md5(1); #endif } @@ -1311,7 +1317,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_sha(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA) && \ + !defined(NO_HW_BENCH) bench_sha(1); #endif } @@ -1321,7 +1328,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_sha224(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224) && \ + !defined(NO_HW_BENCH) bench_sha224(1); #endif } @@ -1331,7 +1339,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_sha256(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA256) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA256) && \ + !defined(NO_HW_BENCH) bench_sha256(1); #endif } @@ -1341,7 +1350,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_sha384(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384) && \ + !defined(NO_HW_BENCH) bench_sha384(1); #endif } @@ -1351,7 +1361,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_sha512(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512) && \ + !defined(NO_HW_BENCH) bench_sha512(1); #endif } @@ -1362,7 +1373,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_sha3_224(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA3) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA3) && \ + !defined(NO_HW_BENCH) bench_sha3_224(1); #endif } @@ -1372,7 +1384,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_sha3_256(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA3) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA3) && \ + !defined(NO_HW_BENCH) bench_sha3_256(1); #endif } @@ -1382,7 +1395,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_sha3_384(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA3) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA3) && \ + !defined(NO_HW_BENCH) bench_sha3_384(1); #endif } @@ -1392,7 +1406,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_sha3_512(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA3) && \ + !defined(NO_HW_BENCH) bench_sha3_512(1); #endif } @@ -1417,7 +1432,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_hmac_md5(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC) && \ + defined(WC_ASYNC_ENABLE_MD5) && !defined(NO_HW_BENCH) bench_hmac_md5(1); #endif } @@ -1427,7 +1443,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_hmac_sha(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC) && \ + defined(WC_ASYNC_ENABLE_SHA) && !defined(NO_HW_BENCH) bench_hmac_sha(1); #endif } @@ -1437,7 +1454,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_hmac_sha224(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC) && \ + defined(WC_ASYNC_ENABLE_SHA224) && !defined(NO_HW_BENCH) bench_hmac_sha224(1); #endif } @@ -1447,7 +1465,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_hmac_sha256(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA256) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC) && \ + defined(WC_ASYNC_ENABLE_SHA256) && !defined(NO_HW_BENCH) bench_hmac_sha256(1); #endif } @@ -1457,7 +1476,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_hmac_sha384(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC) && \ + defined(WC_ASYNC_ENABLE_SHA384) && !defined(NO_HW_BENCH) bench_hmac_sha384(1); #endif } @@ -1467,7 +1487,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_hmac_sha512(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC) && \ + defined(WC_ASYNC_ENABLE_SHA512) && !defined(NO_HW_BENCH) bench_hmac_sha512(1); #endif } @@ -1490,7 +1511,8 @@ static void* benchmarks_do(void* args) bench_rsaKeyGen(0); } #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_RSA_KEYGEN) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_RSA_KEYGEN) \ + && !defined(NO_HW_BENCH) if (bench_asym_algs & BENCH_RSA_SZ) { bench_rsaKeyGen_size(1, bench_size); } @@ -1504,7 +1526,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_rsa(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_RSA) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_RSA) && \ + !defined(NO_HW_BENCH) bench_rsa(1); #endif } @@ -1514,7 +1537,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_rsa_key(0, bench_size); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_RSA) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_RSA) && \ + !defined(NO_HW_BENCH) bench_rsa_key(1, bench_size); #endif } @@ -1526,7 +1550,8 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_dh(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_DH) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_DH) && \ + !defined(NO_HW_BENCH) bench_dh(1); #endif } @@ -1544,18 +1569,17 @@ static void* benchmarks_do(void* args) #ifndef NO_SW_BENCH bench_eccMakeKey(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) - /* async supported in simulator only */ - #ifdef WOLFSSL_ASYNC_CRYPT_TEST - bench_eccMakeKey(1); - #endif + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \ + !defined(NO_HW_BENCH) + bench_eccMakeKey(1); #endif } if (bench_all || (bench_asym_algs & BENCH_ECC)) { #ifndef NO_SW_BENCH bench_ecc(0); #endif - #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \ + !defined(NO_HW_BENCH) bench_ecc(1); #endif }