Skip to content

Commit 2c4b751

Browse files
authored
Merge pull request #16 from wolfSSL/nitroxv
Added Nitrox V ECC, AES-GCM, HMAC (SHA-224/384/512 and SHA-3)
2 parents 2034ba4 + 5ffdea5 commit 2c4b751

6 files changed

Lines changed: 971 additions & 351 deletions

File tree

wolfcrypt/src/async.c

Lines changed: 84 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <wolfssl/wolfcrypt/settings.h>
2727

2828
#ifdef WOLFSSL_ASYNC_CRYPT
29+
2930
#include <wolfssl/internal.h>
3031
#include <wolfssl/error-ssl.h>
3132
#include <wolfssl/wolfcrypt/error-crypt.h>
@@ -304,7 +305,7 @@ int wolfAsync_DevOpenThread(int *pDevId, void* threadId)
304305
int devId = INVALID_DEVID;
305306

306307
#ifdef HAVE_CAVIUM
307-
ret = NitroxOpenDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
308+
ret = NitroxOpenDeviceDefault();
308309
if (ret >= 0)
309310
devId = ret;
310311
else
@@ -468,6 +469,40 @@ int wolfAsync_EventQueuePush(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event)
468469
return wolfEventQueue_Push(queue, event);
469470
}
470471

472+
#ifdef HAVE_CAVIUM
473+
static int wolfAsync_NitroxCheckReq(WC_ASYNC_DEV* asyncDev, WOLF_EVENT* event)
474+
{
475+
int ret;
476+
477+
/* populate event requestId */
478+
event->reqId = asyncDev->nitrox.reqId;
479+
if (event->reqId == 0)
480+
return WC_INIT_E;
481+
482+
/* poll specific request */
483+
ret = NitroxCheckRequest(asyncDev, event);
484+
485+
#ifdef WOLFSSL_NITROX_DEBUG
486+
if (event->ret == WC_PENDING_E)
487+
event->pendCount++;
488+
else
489+
printf("NitroxCheckRequest: ret %x, req %lx, count %d\n",
490+
ret,
491+
event->reqId,
492+
event->pendCount);
493+
#else
494+
(void)ret;
495+
#endif
496+
497+
/* if not pending then clear requestId */
498+
if (event->ret != WC_PENDING_E) {
499+
event->reqId = 0;
500+
}
501+
502+
return 0;
503+
}
504+
#endif /* HAVE_CAVIUM */
505+
471506
int wolfAsync_EventPoll(WOLF_EVENT* event, WOLF_EVENT_FLAG flags)
472507
{
473508
int ret = 0;
@@ -479,14 +514,15 @@ int wolfAsync_EventPoll(WOLF_EVENT* event, WOLF_EVENT_FLAG flags)
479514
return BAD_FUNC_ARG;
480515
}
481516
asyncDev = event->dev.async;
482-
483-
/* Note: event queue mutex is locked here, so make sure
484-
hardware doesn't try and lock event_queue */
517+
if (asyncDev == NULL) {
518+
return WC_INIT_E;
519+
}
485520

486521
if (flags & WOLF_POLL_FLAG_CHECK_HW) {
487522
#if defined(HAVE_CAVIUM)
488-
event->ret = NitroxCheckRequest(asyncDev, event);
523+
ret = wolfAsync_NitroxCheckReq(asyncDev, event);
489524
#elif defined(HAVE_INTEL_QA)
525+
/* poll QAT hardware, callback returns data, IntelQaPoll sets event */
490526
ret = IntelQaPoll(asyncDev);
491527
#elif defined(WOLFSSL_ASYNC_CRYPT_TEST)
492528
event->ret = wolfAsync_crypt_test(asyncDev);
@@ -503,9 +539,9 @@ int wolfAsync_EventPoll(WOLF_EVENT* event, WOLF_EVENT_FLAG flags)
503539

504540

505541
#ifdef HAVE_CAVIUM
506-
static int wolfAsync_CheckMultiReqBuf(WC_ASYNC_DEV* asyncDev,
542+
static int wolfAsync_NitroxCheckMultiReqBuf(WC_ASYNC_DEV* asyncDev,
507543
WOLF_EVENT_QUEUE* queue, void* context_filter,
508-
struct CspMultiRequestStatusBuffer* multi_req)
544+
CspMultiRequestStatusBuffer* multi_req, int req_count)
509545
{
510546
WOLF_EVENT* event;
511547
int ret = 0, i;
@@ -520,17 +556,29 @@ static int wolfAsync_CheckMultiReqBuf(WC_ASYNC_DEV* asyncDev,
520556
return ret;
521557
}
522558

523-
/* Itterate event queue */
559+
/* Iterate event queue */
524560
for (event = queue->head; event != NULL; event = event->next) {
525561
if (event->type >= WOLF_EVENT_TYPE_ASYNC_FIRST &&
526562
event->type <= WOLF_EVENT_TYPE_ASYNC_LAST)
527563
{
528564
/* optional filter based on context */
529565
if (context_filter == NULL || event->context == context_filter) {
530566
/* find request */
531-
for (i = 0; i < multi_req->count; i++) {
532-
if (event->reqId > 0 && event->reqId == multi_req->req[i].request_id) {
533-
event->ret = NitroxTranslateResponseCode(multi_req->req[i].status);
567+
for (i = 0; i < req_count; i++) {
568+
if (event->reqId == multi_req->req[i].request_id) {
569+
570+
event->ret = NitroxTranslateResponseCode(
571+
multi_req->req[i].status);
572+
573+
#ifdef WOLFSSL_NITROX_DEBUG
574+
if (event->ret == WC_PENDING_E)
575+
event->pendCount++;
576+
else
577+
printf("NitroxCheckRequests: ret %x, req %lx, count %d\n",
578+
multi_req->req[i].status,
579+
multi_req->req[i].request_id,
580+
event->pendCount);
581+
#endif
534582

535583
/* If not pending then mark as done */
536584
if (event->ret != WC_PENDING_E) {
@@ -545,21 +593,26 @@ static int wolfAsync_CheckMultiReqBuf(WC_ASYNC_DEV* asyncDev,
545593
}
546594

547595
/* reset multi request buffer */
548-
XMEMSET(multi_req, 0, sizeof(struct CspMultiRequestStatusBuffer));
596+
XMEMSET(multi_req, 0, sizeof(CspMultiRequestStatusBuffer));
597+
multi_req->count = CAVIUM_MAX_POLL;
549598

550599
return ret;
551600
}
552-
#endif
601+
#endif /* HAVE_CAVIUM */
553602

554603
int wolfAsync_EventQueuePoll(WOLF_EVENT_QUEUE* queue, void* context_filter,
555604
WOLF_EVENT** events, int maxEvents, WOLF_EVENT_FLAG flags, int* eventCount)
556605
{
557606
WOLF_EVENT* event;
558607
int ret = 0, count = 0;
559608
WC_ASYNC_DEV* asyncDev = NULL;
560-
#ifdef HAVE_CAVIUM
561-
struct CspMultiRequestStatusBuffer multi_req;
562-
XMEMSET(&multi_req, 0, sizeof(multi_req));
609+
#if defined(HAVE_CAVIUM)
610+
CspMultiRequestStatusBuffer multi_req;
611+
int req_count = 0;
612+
613+
/* reset multi request buffer */
614+
XMEMSET(&multi_req, 0, sizeof(CspMultiRequestStatusBuffer));
615+
multi_req.count = CAVIUM_MAX_POLL;
563616
#endif
564617

565618
/* possible un-used variable */
@@ -579,7 +632,6 @@ int wolfAsync_EventQueuePoll(WOLF_EVENT_QUEUE* queue, void* context_filter,
579632
/* if check hardware flag is set */
580633
if (flags & WOLF_POLL_FLAG_CHECK_HW) {
581634
/* check event queue */
582-
count = 0;
583635
for (event = queue->head; event != NULL; event = event->next) {
584636
if (event->type >= WOLF_EVENT_TYPE_ASYNC_FIRST &&
585637
event->type <= WOLF_EVENT_TYPE_ASYNC_LAST)
@@ -596,22 +648,24 @@ int wolfAsync_EventQueuePoll(WOLF_EVENT_QUEUE* queue, void* context_filter,
596648
count++;
597649

598650
#if defined(HAVE_CAVIUM)
599-
/* Add entry to multi-request buffer */
651+
/* populate event requestId */
652+
event->reqId = asyncDev->nitrox.reqId;
653+
654+
/* add entry to multi-request buffer for polling */
600655
if (event->reqId > 0) {
601-
multi_req.req[multi_req.count].request_id = event->reqId;
602-
multi_req.count++;
656+
multi_req.req[req_count++].request_id = event->reqId;
603657
}
604-
/* Submit filled multi-request query */
605-
if (multi_req.count >= CAVIUM_MAX_POLL) {
606-
ret = wolfAsync_CheckMultiReqBuf(asyncDev,
607-
queue, context_filter, &multi_req);
658+
/* submit filled multi-request query */
659+
if (req_count == CAVIUM_MAX_POLL) {
660+
ret = wolfAsync_NitroxCheckMultiReqBuf(asyncDev,
661+
queue, context_filter, &multi_req, req_count);
608662
if (ret != 0) {
609663
break;
610664
}
611665
}
612666
#else
613667
#if defined(HAVE_INTEL_QA)
614-
/* poll QAT hardware, callback returns data, this thread poll sets event */
668+
/* poll QAT hardware, callback returns data, IntelQaPoll sets event */
615669
ret = IntelQaPoll(asyncDev);
616670
if (ret != 0) {
617671
break;
@@ -642,10 +696,10 @@ int wolfAsync_EventQueuePoll(WOLF_EVENT_QUEUE* queue, void* context_filter,
642696
} /* for */
643697

644698
#if defined(HAVE_CAVIUM)
645-
/* Submit partial multi-request query (if no prev errors) */
646-
if (ret == 0 && multi_req.count > 0) {
647-
ret = wolfAsync_CheckMultiReqBuf(asyncDev,
648-
queue, context_filter, &multi_req);
699+
/* submit partial multi-request query (if no prev errors) */
700+
if (ret == 0 && req_count > 0) {
701+
ret = wolfAsync_NitroxCheckMultiReqBuf(asyncDev,
702+
queue, context_filter, &multi_req, req_count);
649703
}
650704
#endif
651705
} /* flag WOLF_POLL_FLAG_CHECK_HW */
@@ -713,7 +767,7 @@ int wolfAsync_EventInit(WOLF_EVENT* event, WOLF_EVENT_TYPE type, void* context,
713767
event->dev.async = asyncDev;
714768
event->flags = flags;
715769
#ifdef HAVE_CAVIUM
716-
event->reqId = asyncDev->nitrox.reqId;
770+
event->reqId = 0;
717771
#endif
718772

719773
return ret;

0 commit comments

Comments
 (0)