forked from wolfSSL/wolfssl
Fixes to better handle threading with async. Fix wc_CamelliaCbcEncrypt
return code checking. Fix to ensure cycles per byte shows on same line. Refactor of async event state. Refactor to initalize event prior to operation (in case it finishes before adding to queue). Add HAVE_AES_DECRYPT
to --enable-all option. Cleanup benchmark error display.
This commit is contained in:
@@ -213,6 +213,8 @@ then
|
||||
enable_aeskeywrap=yes
|
||||
enable_x963kdf=yes
|
||||
enable_scrypt=yes
|
||||
|
||||
AM_CFLAGS="-DHAVE_AES_DECRYPT $AM_CFLAGS"
|
||||
fi
|
||||
AM_CONDITIONAL([BUILD_ALL], [test "x$ENABLED_ALL" = "xyes"])
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -2822,9 +2822,8 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
||||
(const byte*)aes->asyncKey, aes->keylen,
|
||||
(const byte*)aes->asyncIv, AES_BLOCK_SIZE);
|
||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||
WC_ASYNC_TEST* testDev = &aes->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_AES_CBC_ENCRYPT;
|
||||
if (wc_AsyncTestInit(&aes->asyncDev, ASYNC_TEST_AES_CBC_ENCRYPT)) {
|
||||
WC_ASYNC_TEST* testDev = &aes->asyncDev.test;
|
||||
testDev->aes.aes = aes;
|
||||
testDev->aes.out = out;
|
||||
testDev->aes.in = in;
|
||||
@@ -2913,9 +2912,8 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
||||
(const byte*)aes->asyncKey, aes->keylen,
|
||||
(const byte*)aes->asyncIv, AES_BLOCK_SIZE);
|
||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||
WC_ASYNC_TEST* testDev = &aes->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_AES_CBC_DECRYPT;
|
||||
if (wc_AsyncTestInit(&aes->asyncDev, ASYNC_TEST_AES_CBC_DECRYPT)) {
|
||||
WC_ASYNC_TEST* testDev = &aes->asyncDev.test;
|
||||
testDev->aes.aes = aes;
|
||||
testDev->aes.out = out;
|
||||
testDev->aes.in = in;
|
||||
@@ -3165,7 +3163,7 @@ int wc_AesEcbDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
||||
byte out_block[AES_BLOCK_SIZE];
|
||||
int odd, even, blocks;
|
||||
byte *tmp;
|
||||
|
||||
|
||||
if (aes == NULL || out == NULL || in == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
@@ -5494,7 +5492,7 @@ static int AES_GCM_decrypt(const unsigned char *in, unsigned char *out,
|
||||
for (; i < nbytes/16/8; i++) {
|
||||
r0 = _mm_setzero_si128();
|
||||
r1 = _mm_setzero_si128();
|
||||
|
||||
|
||||
tmp1 = _mm_shuffle_epi8(ctr1, BSWAP_EPI64);
|
||||
tmp2 = _mm_add_epi32(ctr1, ONE);
|
||||
tmp2 = _mm_shuffle_epi8(tmp2, BSWAP_EPI64);
|
||||
@@ -7078,9 +7076,8 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
||||
(const byte*)aes->asyncKey, aes->keylen, iv, ivSz,
|
||||
authTag, authTagSz, authIn, authInSz);
|
||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||
WC_ASYNC_TEST* testDev = &aes->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_AES_GCM_ENCRYPT;
|
||||
if (wc_AsyncTestInit(&aes->asyncDev, ASYNC_TEST_AES_GCM_ENCRYPT)) {
|
||||
WC_ASYNC_TEST* testDev = &aes->asyncDev.test;
|
||||
testDev->aes.aes = aes;
|
||||
testDev->aes.out = out;
|
||||
testDev->aes.in = in;
|
||||
@@ -7091,6 +7088,7 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
||||
testDev->aes.authTagSz = authTagSz;
|
||||
testDev->aes.authIn = authIn;
|
||||
testDev->aes.authInSz = authInSz;
|
||||
return WC_PENDING_E;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -7340,9 +7338,8 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
||||
(const byte*)aes->asyncKey, aes->keylen, iv, ivSz,
|
||||
authTag, authTagSz, authIn, authInSz);
|
||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||
WC_ASYNC_TEST* testDev = &aes->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_AES_GCM_DECRYPT;
|
||||
if (wc_AsyncTestInit(&aes->asyncDev, ASYNC_TEST_AES_GCM_DECRYPT)) {
|
||||
WC_ASYNC_TEST* testDev = &aes->asyncDev.test;
|
||||
testDev->aes.aes = aes;
|
||||
testDev->aes.out = out;
|
||||
testDev->aes.in = in;
|
||||
|
@@ -1582,9 +1582,8 @@
|
||||
return IntelQaSymDes3CbcEncrypt(&des->asyncDev, out, in, sz,
|
||||
des->key_raw, DES3_KEYLEN, (byte*)des->iv_raw, DES3_IVLEN);
|
||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||
WC_ASYNC_TEST* testDev = &des->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_DES3_CBC_ENCRYPT;
|
||||
if (wc_AsyncTestInit(&des->asyncDev, ASYNC_TEST_DES3_CBC_ENCRYPT)) {
|
||||
WC_ASYNC_TEST* testDev = &des->asyncDev.test;
|
||||
testDev->des.des = des;
|
||||
testDev->des.out = out;
|
||||
testDev->des.in = in;
|
||||
@@ -1625,9 +1624,8 @@
|
||||
return IntelQaSymDes3CbcDecrypt(&des->asyncDev, out, in, sz,
|
||||
des->key_raw, DES3_KEYLEN, (byte*)des->iv_raw, DES3_IVLEN);
|
||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||
WC_ASYNC_TEST* testDev = &des->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_DES3_CBC_DECRYPT;
|
||||
if (wc_AsyncTestInit(&des->asyncDev, ASYNC_TEST_DES3_CBC_DECRYPT)) {
|
||||
WC_ASYNC_TEST* testDev = &des->asyncDev.test;
|
||||
testDev->des.des = des;
|
||||
testDev->des.out = out;
|
||||
testDev->des.in = in;
|
||||
|
@@ -687,9 +687,8 @@ static int wc_DhGenerateKeyPair_Async(DhKey* key, WC_RNG* rng,
|
||||
/* TODO: Not implemented - use software for now */
|
||||
|
||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_DH_GEN;
|
||||
if (wc_AsyncTestInit(&key->asyncDev, ASYNC_TEST_DH_GEN)) {
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
testDev->dhGen.key = key;
|
||||
testDev->dhGen.rng = rng;
|
||||
testDev->dhGen.priv = priv;
|
||||
@@ -836,9 +835,8 @@ static int wc_DhAgree_Async(DhKey* key, byte* agree, word32* agreeSz,
|
||||
ret = IntelQaDhAgree(&key->asyncDev, &key->p.raw,
|
||||
agree, agreeSz, priv, privSz, otherPub, pubSz);
|
||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_DH_AGREE;
|
||||
if (wc_AsyncTestInit(&key->asyncDev, ASYNC_TEST_DH_AGREE)) {
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
testDev->dhAgree.key = key;
|
||||
testDev->dhAgree.agree = agree;
|
||||
testDev->dhAgree.agreeSz = agreeSz;
|
||||
|
@@ -2803,9 +2803,8 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
|
||||
&curve->Af->raw, &curve->Bf->raw, &curve->prime->raw,
|
||||
private_key->dp->cofactor);
|
||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||
WC_ASYNC_TEST* testDev = &private_key->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_ECC_SHARED_SEC;
|
||||
if (wc_AsyncTestInit(&private_key->asyncDev, ASYNC_TEST_ECC_SHARED_SEC)) {
|
||||
WC_ASYNC_TEST* testDev = &private_key->asyncDev.test;
|
||||
testDev->eccSharedSec.private_key = private_key;
|
||||
testDev->eccSharedSec.public_point = point;
|
||||
testDev->eccSharedSec.out = out;
|
||||
@@ -3017,9 +3016,8 @@ int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id)
|
||||
#elif defined(HAVE_INTEL_QA)
|
||||
/* TODO: Not implemented */
|
||||
#else
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_ECC_MAKE;
|
||||
if (wc_AsyncTestInit(&key->asyncDev, ASYNC_TEST_ECC_MAKE)) {
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
testDev->eccMake.rng = rng;
|
||||
testDev->eccMake.key = key;
|
||||
testDev->eccMake.size = keysize;
|
||||
@@ -3465,9 +3463,8 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \
|
||||
defined(WOLFSSL_ASYNC_CRYPT_TEST)
|
||||
if (key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ECC) {
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_ECC_SIGN;
|
||||
if (wc_AsyncTestInit(&key->asyncDev, ASYNC_TEST_ECC_SIGN)) {
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
testDev->eccSign.in = in;
|
||||
testDev->eccSign.inSz = inlen;
|
||||
testDev->eccSign.rng = rng;
|
||||
@@ -4011,9 +4008,8 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \
|
||||
defined(WOLFSSL_ASYNC_CRYPT_TEST)
|
||||
if (key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ECC) {
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_ECC_VERIFY;
|
||||
if (wc_AsyncTestInit(&key->asyncDev, ASYNC_TEST_ECC_VERIFY)) {
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
testDev->eccVerify.r = r;
|
||||
testDev->eccVerify.s = s;
|
||||
testDev->eccVerify.hash = hash;
|
||||
|
@@ -1289,9 +1289,8 @@ static int wc_RsaFunctionAsync(const byte* in, word32 inLen, byte* out,
|
||||
(void)rng;
|
||||
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT_TEST
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_RSA_FUNC;
|
||||
if (wc_AsyncTestInit(&key->asyncDev, ASYNC_TEST_RSA_FUNC)) {
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
testDev->rsaFunc.in = in;
|
||||
testDev->rsaFunc.inSz = inLen;
|
||||
testDev->rsaFunc.out = out;
|
||||
@@ -1870,9 +1869,8 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
|
||||
#elif defined(HAVE_INTEL_QA)
|
||||
/* TODO: Not implemented */
|
||||
#else
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
if (testDev->type == ASYNC_TEST_NONE) {
|
||||
testDev->type = ASYNC_TEST_RSA_MAKE;
|
||||
if (wc_AsyncTestInit(&key->asyncDev, ASYNC_TEST_RSA_MAKE)) {
|
||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||
testDev->rsaMake.rng = rng;
|
||||
testDev->rsaMake.key = key;
|
||||
testDev->rsaMake.size = size;
|
||||
|
@@ -41,8 +41,8 @@ int wolfEvent_Init(WOLF_EVENT* event, WOLF_EVENT_TYPE type, void* context)
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (event->pending) {
|
||||
WOLFSSL_MSG("event already pending!");
|
||||
if (event->state == WOLF_EVENT_STATE_PENDING) {
|
||||
WOLFSSL_MSG("Event already pending!");
|
||||
return BAD_COND_E;
|
||||
}
|
||||
|
||||
@@ -99,10 +99,6 @@ int wolfEventQueue_Push(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Setup event */
|
||||
event->next = NULL;
|
||||
event->pending = 1;
|
||||
|
||||
ret = wolfEventQueue_Add(queue, event);
|
||||
|
||||
#ifndef SINGLE_THREADED
|
||||
@@ -145,6 +141,8 @@ int wolfEventQueue_Add(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event)
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
event->next = NULL; /* added to end */
|
||||
event->prev = NULL;
|
||||
if (queue->tail == NULL) {
|
||||
queue->head = event;
|
||||
}
|
||||
@@ -218,7 +216,7 @@ int wolfEventQueue_Poll(WOLF_EVENT_QUEUE* queue, void* context_filter,
|
||||
if (ret < 0) break; /* exit for */
|
||||
|
||||
/* If event is done then process */
|
||||
if (event->done) {
|
||||
if (event->state == WOLF_EVENT_STATE_DONE) {
|
||||
/* remove from queue */
|
||||
ret = wolfEventQueue_Remove(queue, event);
|
||||
if (ret < 0) break; /* exit for */
|
||||
|
@@ -55,6 +55,12 @@ typedef enum WOLF_EVENT_TYPE {
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||
} WOLF_EVENT_TYPE;
|
||||
|
||||
typedef enum WOLF_EVENT_STATE {
|
||||
WOLF_EVENT_STATE_READY,
|
||||
WOLF_EVENT_STATE_PENDING,
|
||||
WOLF_EVENT_STATE_DONE,
|
||||
} WOLF_EVENT_STATE;
|
||||
|
||||
struct WOLF_EVENT {
|
||||
/* double linked list */
|
||||
WOLF_EVENT* next;
|
||||
@@ -73,11 +79,7 @@ struct WOLF_EVENT {
|
||||
int ret; /* Async return code */
|
||||
unsigned int flags;
|
||||
WOLF_EVENT_TYPE type;
|
||||
|
||||
/* event flags */
|
||||
WOLF_EVENT_FLAG pending:1;
|
||||
WOLF_EVENT_FLAG done:1;
|
||||
/* Future event flags can go here */
|
||||
WOLF_EVENT_STATE state;
|
||||
};
|
||||
|
||||
enum WOLF_POLL_FLAGS {
|
||||
|
Reference in New Issue
Block a user