forked from wolfSSL/wolfssl
Merge pull request #1154 from dgarske/fix_async
Fixes for building with async
This commit is contained in:
@ -407,8 +407,8 @@ static THREAD_LS_T int devId = INVALID_DEVID;
|
||||
#define BENCH_SIZE bench_size
|
||||
|
||||
/* globals for cipher tests */
|
||||
static byte* bench_plain = NULL;
|
||||
static byte* bench_cipher = NULL;
|
||||
static THREAD_LS_T byte* bench_plain = NULL;
|
||||
static THREAD_LS_T byte* bench_cipher = NULL;
|
||||
|
||||
static const XGEN_ALIGN byte bench_key_buf[] =
|
||||
{
|
||||
@ -424,8 +424,8 @@ static const XGEN_ALIGN byte bench_iv_buf[] =
|
||||
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
|
||||
0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
|
||||
};
|
||||
static byte* bench_key = (byte*)bench_key_buf;
|
||||
static byte* bench_iv = (byte*)bench_iv_buf;
|
||||
static THREAD_LS_T byte* bench_key = NULL;
|
||||
static THREAD_LS_T byte* bench_iv = NULL;
|
||||
|
||||
#ifdef WOLFSSL_STATIC_MEMORY
|
||||
#ifdef BENCH_EMBEDDED
|
||||
@ -662,6 +662,8 @@ static INLINE void bench_stats_free(void)
|
||||
|
||||
static void* benchmarks_do(void* args)
|
||||
{
|
||||
int bench_buf_size;
|
||||
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
#ifndef WC_NO_ASYNC_THREADING
|
||||
ThreadData* threadData = (ThreadData*)args;
|
||||
@ -694,10 +696,48 @@ static void* benchmarks_do(void* args)
|
||||
#endif
|
||||
if (rngRet < 0) {
|
||||
printf("InitRNG failed\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* setup bench plain, cipher, key and iv globals */
|
||||
/* make sure bench buffer is multiple of 16 (AES block size) */
|
||||
bench_buf_size = bench_size + BENCH_CIPHER_ADD;
|
||||
if (bench_buf_size % 16)
|
||||
bench_buf_size += 16 - (bench_buf_size % 16);
|
||||
|
||||
bench_plain = (byte*)XMALLOC(bench_buf_size, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
bench_cipher = (byte*)XMALLOC(bench_buf_size, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
if (bench_plain == NULL || bench_cipher == NULL) {
|
||||
XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
bench_plain = bench_cipher = NULL;
|
||||
|
||||
printf("Benchmark block buffer alloc failed!\n");
|
||||
goto exit;
|
||||
}
|
||||
XMEMSET(bench_plain, 0, bench_buf_size);
|
||||
XMEMSET(bench_cipher, 0, bench_buf_size);
|
||||
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
bench_key = (byte*)XMALLOC(sizeof(bench_key_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
if (bench_key == NULL || bench_iv == NULL) {
|
||||
XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
bench_key = bench_iv = NULL;
|
||||
|
||||
printf("Benchmark cipher buffer alloc failed!\n");
|
||||
goto exit;
|
||||
}
|
||||
XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
|
||||
XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
|
||||
#else
|
||||
bench_key = (byte*)bench_key_buf;
|
||||
bench_iv = (byte*)bench_iv_buf;
|
||||
#endif
|
||||
|
||||
#ifndef WC_NO_RNG
|
||||
bench_rng();
|
||||
#endif /* WC_NO_RNG */
|
||||
@ -930,6 +970,15 @@ static void* benchmarks_do(void* args)
|
||||
bench_ed25519KeySign();
|
||||
#endif
|
||||
|
||||
exit:
|
||||
/* free benchmark buffers */
|
||||
XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
/* free event queue */
|
||||
wolfEventQueue_Free(&eventQueue);
|
||||
@ -949,7 +998,6 @@ static void* benchmarks_do(void* args)
|
||||
int benchmark_init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int block_size;
|
||||
|
||||
#ifdef WOLFSSL_STATIC_MEMORY
|
||||
ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory, sizeof(gBenchMemory),
|
||||
@ -980,40 +1028,6 @@ int benchmark_init(void)
|
||||
}
|
||||
#endif /* HAVE_WNR */
|
||||
|
||||
/* make sure bench buffer is multiple of 16 (AES block size) */
|
||||
block_size = bench_size + BENCH_CIPHER_ADD;
|
||||
if (block_size % 16)
|
||||
block_size += 16 - (block_size % 16);
|
||||
|
||||
/* setup bench plain, cipher, key and iv globals */
|
||||
bench_plain = (byte*)XMALLOC(block_size, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
bench_cipher = (byte*)XMALLOC(block_size, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
if (bench_plain == NULL || bench_cipher == NULL) {
|
||||
XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
|
||||
printf("Benchmark block buffer alloc failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
XMEMSET(bench_plain, 0, block_size);
|
||||
XMEMSET(bench_cipher, 0, block_size);
|
||||
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
bench_key = (byte*)XMALLOC(sizeof(bench_key_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
if (bench_key == NULL || bench_iv == NULL) {
|
||||
XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
|
||||
printf("Benchmark cipher buffer alloc failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
|
||||
XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
|
||||
#endif
|
||||
(void)bench_key;
|
||||
(void)bench_iv;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1021,13 +1035,6 @@ int benchmark_free(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WNR
|
||||
ret = wc_FreeNetRandom();
|
||||
if (ret < 0) {
|
||||
@ -2549,7 +2556,7 @@ void bench_rsaKeyGen(int doAsync)
|
||||
{
|
||||
RsaKey genKey[BENCH_MAX_PENDING];
|
||||
double start;
|
||||
int ret, i, count = 0, times, pending = 0;
|
||||
int ret = 0, i, count = 0, times, pending = 0;
|
||||
int k, keySz;
|
||||
const int keySizes[2] = {1024, 2048};
|
||||
const long rsa_e_val = 65537;
|
||||
|
@ -4271,7 +4271,7 @@ static int aes_xts_128_test(void)
|
||||
return -4000;
|
||||
ret = wc_AesXtsEncrypt(&aes, buf, p2, sizeof(p2), i2, sizeof(i2));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4001;
|
||||
@ -4284,7 +4284,7 @@ static int aes_xts_128_test(void)
|
||||
return -4003;
|
||||
ret = wc_AesXtsEncrypt(&aes, buf, p1, sizeof(p1), i1, sizeof(i1));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4004;
|
||||
@ -4295,7 +4295,7 @@ static int aes_xts_128_test(void)
|
||||
XMEMSET(cipher, 0, sizeof(cipher));
|
||||
ret = wc_AesXtsEncrypt(&aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4006;
|
||||
@ -4308,7 +4308,7 @@ static int aes_xts_128_test(void)
|
||||
return -4007;
|
||||
ret = wc_AesXtsDecrypt(&aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4008;
|
||||
@ -4319,7 +4319,7 @@ static int aes_xts_128_test(void)
|
||||
XMEMSET(buf, 0, sizeof(buf));
|
||||
ret = wc_AesXtsDecrypt(&aes, buf, c1, sizeof(c1), i1, sizeof(i1));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4010;
|
||||
@ -4330,7 +4330,7 @@ static int aes_xts_128_test(void)
|
||||
XMEMSET(buf, 0, sizeof(buf));
|
||||
ret = wc_AesXtsDecrypt(&aes, buf, c2, sizeof(c2), i2, sizeof(i2));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4012;
|
||||
@ -4344,7 +4344,7 @@ static int aes_xts_128_test(void)
|
||||
return -4014;
|
||||
ret = wc_AesXtsDecrypt(&aes, buf, c2, sizeof(c2), i2, sizeof(i2));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4015;
|
||||
@ -4441,7 +4441,7 @@ static int aes_xts_256_test(void)
|
||||
return -4017;
|
||||
ret = wc_AesXtsEncrypt(&aes, buf, p2, sizeof(p2), i2, sizeof(i2));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4018;
|
||||
@ -4454,7 +4454,7 @@ static int aes_xts_256_test(void)
|
||||
return -4020;
|
||||
ret = wc_AesXtsEncrypt(&aes, buf, p1, sizeof(p1), i1, sizeof(i1));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4021;
|
||||
@ -4465,7 +4465,7 @@ static int aes_xts_256_test(void)
|
||||
XMEMSET(cipher, 0, sizeof(cipher));
|
||||
ret = wc_AesXtsEncrypt(&aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4023;
|
||||
@ -4478,7 +4478,7 @@ static int aes_xts_256_test(void)
|
||||
return -4024;
|
||||
ret = wc_AesXtsDecrypt(&aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4025;
|
||||
@ -4489,7 +4489,7 @@ static int aes_xts_256_test(void)
|
||||
XMEMSET(buf, 0, sizeof(buf));
|
||||
ret = wc_AesXtsDecrypt(&aes, buf, c1, sizeof(c1), i1, sizeof(i1));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4027;
|
||||
@ -4502,7 +4502,7 @@ static int aes_xts_256_test(void)
|
||||
return -4029;
|
||||
ret = wc_AesXtsDecrypt(&aes, buf, c2, sizeof(c2), i2, sizeof(i2));
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4030;
|
||||
@ -4573,7 +4573,7 @@ static int aes_xts_sector_test(void)
|
||||
return -4032;
|
||||
ret = wc_AesXtsEncryptSector(&aes, buf, p1, sizeof(p1), s1);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4033;
|
||||
@ -4587,7 +4587,7 @@ static int aes_xts_sector_test(void)
|
||||
return -4035;
|
||||
ret = wc_AesXtsDecryptSector(&aes, buf, c1, sizeof(c1), s1);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4036;
|
||||
@ -4602,7 +4602,7 @@ static int aes_xts_sector_test(void)
|
||||
return -4038;
|
||||
ret = wc_AesXtsEncryptSector(&aes, buf, p2, sizeof(p2), s2);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4039;
|
||||
@ -4616,7 +4616,7 @@ static int aes_xts_sector_test(void)
|
||||
return -4041;
|
||||
ret = wc_AesXtsDecryptSector(&aes, buf, c2, sizeof(c2), s2);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
return -4042;
|
||||
@ -4667,14 +4667,14 @@ static int aes_xts_args_test(void)
|
||||
return -4046;
|
||||
ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret == 0)
|
||||
return -4047;
|
||||
|
||||
ret = wc_AesXtsEncryptSector(&aes, NULL, p1, sizeof(p1), s1);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret == 0)
|
||||
return -4048;
|
||||
@ -4686,14 +4686,14 @@ static int aes_xts_args_test(void)
|
||||
return -4046;
|
||||
ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret == 0)
|
||||
return -4049;
|
||||
|
||||
ret = wc_AesXtsDecryptSector(&aes, NULL, c1, sizeof(c1), s1);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
ret = wc_AsyncWait(ret, &aes.aes.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret == 0)
|
||||
return -4050;
|
||||
|
Reference in New Issue
Block a user