From f008350afd2b5977d5924764617312f7dc6f0fee Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 14 Jun 2017 15:45:34 -0700 Subject: [PATCH] Added QAT DRBG support. --- wolfcrypt/src/random.c | 14 ++++++++++---- wolfssl/wolfcrypt/random.h | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 1940bff1c..783376eb7 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -530,14 +530,13 @@ int wc_InitRng_ex(WC_RNG* rng, void* heap, int devId) #endif /* configure async RNG source if available */ -#if defined(WOLFSSL_ASYNC_CRYPT) && defined(HAVE_CAVIUM) +#ifdef WOLFSSL_ASYNC_CRYPT ret = wolfAsync_DevCtxInit(&rng->asyncDev, WOLFSSL_ASYNC_MARKER_RNG, rng->heap, rng->devId); if (ret != 0) return ret; #endif - #ifdef HAVE_INTEL_RDRAND /* if CPU supports RDRAND, use it directly and by-pass DRBG init */ if (IS_INTEL_RDRAND) @@ -610,9 +609,16 @@ int wc_RNG_GenerateBlock(WC_RNG* rng, byte* output, word32 sz) return wc_GenerateRand_IntelRD(NULL, output, sz); #endif -#if defined(WOLFSSL_ASYNC_CRYPT) && defined(HAVE_CAVIUM) +#if defined(WOLFSSL_ASYNC_CRYPT) if (rng->asyncDev.marker == WOLFSSL_ASYNC_MARKER_RNG) { + /* these are blocking */ + #ifdef HAVE_CAVIUM return NitroxRngGenerateBlock(rng, output, sz); + #elif defined(HAVE_INTEL_QA) + return IntelQaDrbg(&rng->asyncDev, output, sz); + #else + /* simulator not supported */ + #endif } #endif @@ -685,7 +691,7 @@ int wc_FreeRng(WC_RNG* rng) if (rng == NULL) return BAD_FUNC_ARG; -#if defined(WOLFSSL_ASYNC_CRYPT) && defined(HAVE_CAVIUM) +#if defined(WOLFSSL_ASYNC_CRYPT) wolfAsync_DevCtxFree(&rng->asyncDev, WOLFSSL_ASYNC_MARKER_RNG); #endif diff --git a/wolfssl/wolfcrypt/random.h b/wolfssl/wolfcrypt/random.h index 6a6f104e5..1e72eb16e 100644 --- a/wolfssl/wolfcrypt/random.h +++ b/wolfssl/wolfcrypt/random.h @@ -37,7 +37,11 @@ /* Maximum generate block length */ #ifndef RNG_MAX_BLOCK_LEN - #define RNG_MAX_BLOCK_LEN (0x10000) + #ifdef HAVE_INTEL_QA + #define RNG_MAX_BLOCK_LEN (0xFFFF) + #else + #define RNG_MAX_BLOCK_LEN (0x10000) + #endif #endif /* Size of the BRBG seed */