Fixing some play-nice between sync QAT and sync Octeon.

This commit is contained in:
John Safranek
2019-10-04 15:35:39 -07:00
parent 989c964a95
commit 67b11b8ece
7 changed files with 50 additions and 23 deletions

View File

@ -61,6 +61,9 @@
#ifdef HAVE_INTEL_QA_SYNC #ifdef HAVE_INTEL_QA_SYNC
#include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h> #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
#endif #endif
#ifdef HAVE_CAVIUM_OCTEON_SYNC
#include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
#endif
#endif #endif
@ -508,16 +511,28 @@ void ssl_InitSniffer(void)
int rc; int rc;
CryptoDeviceId = IntelQaInit(NULL); CryptoDeviceId = IntelQaInit(NULL);
if (CryptoDeviceId == INVALID_DEVID) { if (CryptoDeviceId == INVALID_DEVID) {
WOLFSSL_MSG("Couldn't init the Intel QA"); printf("Couldn't init the Intel QA\n");
} }
rc = IntelQaOpen(&CryptoDevice, CryptoDeviceId); rc = IntelQaOpen(&CryptoDevice, CryptoDeviceId);
if (rc != 0) { if (rc != 0) {
WOLFSSL_MSG("Couldn't open the device"); printf("Couldn't open the device\n");
} }
rc = wc_CryptoCb_RegisterDevice(CryptoDeviceId, rc = wc_CryptoCb_RegisterDevice(CryptoDeviceId,
IntelQaSymSync_CryptoDevCb, &CryptoDevice); IntelQaSymSync_CryptoDevCb, &CryptoDevice);
if (rc != 0) { if (rc != 0) {
WOLFSSL_MSG("Couldn't register the device"); printf("Couldn't register the device\n");
}
}
#endif
#ifdef HAVE_CAVIUM_OCTEON_SYNC
{
CryptoDeviceId = wc_CryptoCb_GetDevIdOcteon();
if (CryptoDeviceId == INVALID_DEVID) {
printf("Couldn't get the Octeon device ID\n");
}
if (wc_CryptoCb_InitOcteon() != 0) {
printf("Couldn't init the Cavium Octeon\n");
CryptoDeviceId = INVALID_DEVID;
} }
} }
#endif #endif
@ -656,6 +671,9 @@ void ssl_FreeSniffer(void)
IntelQaClose(&CryptoDevice); IntelQaClose(&CryptoDevice);
IntelQaDeInit(CryptoDeviceId); IntelQaDeInit(CryptoDeviceId);
#endif #endif
#ifdef HAVE_CAVIUM_OCTEON_SYNC
wc_CryptoCb_CleanupOcteon();
#endif
#endif #endif
if (TraceFile) { if (TraceFile) {

View File

@ -174,6 +174,9 @@
#ifdef WOLF_CRYPTO_CB #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptocb.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#ifdef HAVE_INTEL_QA_SYNC
#include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
#endif
#ifdef HAVE_CAVIUM_OCTEON_SYNC #ifdef HAVE_CAVIUM_OCTEON_SYNC
#include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h> #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
#endif #endif
@ -1305,16 +1308,16 @@ static void* benchmarks_do(void* args)
int rc; int rc;
devId = IntelQaInit(NULL); devId = IntelQaInit(NULL);
if (devId == INVALID_DEVID) { if (devId == INVALID_DEVID) {
WOLFSSL_MSG("Couldn't init the Intel QA"); printf("Couldn't init the Intel QA\n");
} }
rc = IntelQaOpen(&devQat, devId); rc = IntelQaOpen(&devQat, devId);
if (rc != 0) { if (rc != 0) {
WOLFSSL_MSG("Couldn't open the device"); printf("Couldn't open the device\n");
} }
rc = wc_CryptoCb_RegisterDevice(devId, rc = wc_CryptoCb_RegisterDevice(devId,
IntelQaSymSync_CryptoDevCb, &devQat); IntelQaSymSync_CryptoDevCb, &devQat);
if (rc != 0) { if (rc != 0) {
WOLFSSL_MSG("Couldn't register the device"); printf("Couldn't register the device\n");
} }
} }
#endif #endif
@ -1372,7 +1375,7 @@ static void* benchmarks_do(void* args)
XMEMSET(bench_plain, 0, (size_t)bench_buf_size); XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
XMEMSET(bench_cipher, 0, (size_t)bench_buf_size); XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
#ifdef WOLFSSL_ASYNC_CRYPT #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
bench_key = (byte*)XMALLOC(sizeof(bench_key_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); 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); bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
if (bench_key == NULL || bench_iv == NULL) { if (bench_key == NULL || bench_iv == NULL) {
@ -1824,9 +1827,9 @@ exit:
#ifdef WOLF_CRYPTO_CB #ifdef WOLF_CRYPTO_CB
#ifdef HAVE_INTEL_QA_SYNC #ifdef HAVE_INTEL_QA_SYNC
wc_CryptoCb_UnRegisterDevice(CryptoDeviceId); wc_CryptoCb_UnRegisterDevice(devId);
IntelQaClose(&CryptoDevice); IntelQaClose(&devQat);
IntelQaDeInit(CryptoDeviceId); IntelQaDeInit(devId);
#endif #endif
#ifdef HAVE_CAVIUM_OCTEON_SYNC #ifdef HAVE_CAVIUM_OCTEON_SYNC
wc_CryptoCb_CleanupOcteon(); wc_CryptoCb_CleanupOcteon();

View File

@ -3629,6 +3629,12 @@ int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len)
wc_AesGcmSetKey_ex(aes, key, len, 0); wc_AesGcmSetKey_ex(aes, key, len, 0);
#endif #endif
#ifdef WOLF_CRYPTO_CB
if (aes->devId != INVALID_DEVID) {
XMEMCPY(aes->devKey, key, len);
}
#endif
#ifdef WOLFSSL_IMX6_CAAM_BLOB #ifdef WOLFSSL_IMX6_CAAM_BLOB
ForceZero(local, sizeof(local)); ForceZero(local, sizeof(local));
#endif #endif

View File

@ -503,7 +503,7 @@ static int Octeon_AesGcm_SetKey(Aes* aes)
ret = BAD_FUNC_ARG; ret = BAD_FUNC_ARG;
if (ret != 0) { if (ret != 0) {
word32* key = (word32*)aes->devKey; uint64_t* key = (uint64_t*)aes->devKey;
CVMX_MT_AES_KEY(key[0], 0); CVMX_MT_AES_KEY(key[0], 0);
CVMX_MT_AES_KEY(key[1], 1); CVMX_MT_AES_KEY(key[1], 1);

View File

@ -76,6 +76,7 @@
#ifdef HAVE_INTEL_QA_SYNC #ifdef HAVE_INTEL_QA_SYNC
#include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h> #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
#endif
#ifdef HAVE_CAVIUM_OCTEON_SYNC #ifdef HAVE_CAVIUM_OCTEON_SYNC
#include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h> #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>

View File

@ -109,7 +109,6 @@ struct Des3 {
#ifdef WOLF_CRYPTO_CB #ifdef WOLF_CRYPTO_CB
int devId; int devId;
void* devCtx; void* devCtx;
word32 devKey[DES3_KEY_SIZE/sizeof(word32)]; /* raw key */
#endif #endif
void* heap; void* heap;
}; };

View File

@ -155,16 +155,16 @@ typedef struct IntelQaDev {
/* Interface */ /* Interface */
WOLFSSL_LOCAL int IntelQaHardwareStart(const char*, int); WOLFSSL_API int IntelQaHardwareStart(const char*, int);
WOLFSSL_LOCAL void IntelQaHardwareStop(void); WOLFSSL_API void IntelQaHardwareStop(void);
WOLFSSL_LOCAL int IntelQaInit(void*); WOLFSSL_API int IntelQaInit(void*);
WOLFSSL_LOCAL void IntelQaDeInit(int); WOLFSSL_API void IntelQaDeInit(int);
WOLFSSL_LOCAL int IntelQaNumInstances(void); WOLFSSL_API int IntelQaNumInstances(void);
WOLFSSL_LOCAL int IntelQaOpen(IntelQaDev*, int); WOLFSSL_API int IntelQaOpen(IntelQaDev*, int);
WOLFSSL_LOCAL void IntelQaClose(IntelQaDev*); WOLFSSL_API void IntelQaClose(IntelQaDev*);
WOLFSSL_LOCAL int IntelQaDevCopy(IntelQaDev*, IntelQaDev*); WOLFSSL_API int IntelQaDevCopy(IntelQaDev*, IntelQaDev*);
WOLFSSL_LOCAL int IntelQaPoll(IntelQaDev*); WOLFSSL_API int IntelQaPoll(IntelQaDev*);
WOLFSSL_LOCAL int IntelQaGetCyInstanceCount(void); WOLFSSL_API int IntelQaGetCyInstanceCount(void);
#ifndef NO_AES #ifndef NO_AES
#ifdef HAVE_AES_CBC #ifdef HAVE_AES_CBC
@ -196,7 +196,7 @@ WOLFSSL_LOCAL int IntelQaGetCyInstanceCount(void);
#endif /*! NO_DES3 */ #endif /*! NO_DES3 */
#ifdef WOLF_CRYPTO_CB #ifdef WOLF_CRYPTO_CB
WOLFSSL_LOCAL int IntelQaSymSync_CryptoDevCb(int, struct wc_CryptoInfo*, WOLFSSL_API int IntelQaSymSync_CryptoDevCb(int, struct wc_CryptoInfo*,
void*); void*);
#endif /* WOLF_CRYPTO_CB */ #endif /* WOLF_CRYPTO_CB */