Migrate wolfAsyncCrypt repo into wolfSSL proper

This commit is contained in:
David Garske
2025-11-14 09:43:59 -08:00
parent 50c5028c5a
commit a071426bc8
21 changed files with 11352 additions and 161 deletions

View File

@@ -33,7 +33,7 @@ jobs:
- name: Test wolfSSL async
run: |
./async-check.sh install
./autogen.sh
./configure ${{ matrix.config }}
make check

10
.gitignore vendored
View File

@@ -50,16 +50,6 @@ wolfcrypt_first.c
wolfcrypt_last.c
selftest.c
fipsv2.c
src/async.c
wolfssl/async.h
wolfcrypt/src/async.c
wolfssl/wolfcrypt/async.h
wolfcrypt/src/port/intel/quickassist.c
wolfcrypt/src/port/intel/quickassist_mem.c
wolfcrypt/src/port/cavium/cavium_nitrox.c
wolfssl/wolfcrypt/port/intel/quickassist.h
wolfssl/wolfcrypt/port/intel/quickassist_mem.h
wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h
ctaocrypt/benchmark/benchmark
ctaocrypt/test/testctaocrypt
wolfcrypt/benchmark/benchmark

View File

@@ -180,6 +180,7 @@ CONFIG_WOLFTPM_EXAMPLE_NAME_ESPRESSIF
CONFIG_X86
CONV_WITH_DIV
CPA_CY_API_VERSION_NUM_MAJOR
CPA_CY_API_VERSION_NUM_MINOR
CPU_MIMXRT1176DVMAA_cm7
CPU_MK82FN256VLL15
CRLDP_VALIDATE_DATA
@@ -412,6 +413,7 @@ NO_PKCS7_STREAM
NO_POLY1305_ASM
NO_PUBLIC_CCM_SET_NONCE
NO_PUBLIC_GCM_SET_IV
NO_QAT_RNG
NO_RESUME_SUITE_CHECK
NO_RNG
NO_RNG_MUTEX
@@ -475,6 +477,7 @@ RTC_ALARMSUBSECONDMASK_ALL
RTE_CMSIS_RTOS_RTX
RTOS_MODULE_NET_AVAIL
RTPLATFORM
SAL_IOMMU_CODE
SA_INTERRUPT
SCEKEY_INSTALLED
SHA256_MANY_REGISTERS
@@ -565,8 +568,10 @@ USE_CONTESTMUTEX
USE_ECDSA_KEYSZ_HASH_ALGO
USE_FULL_ASSERT
USE_HAL_DRIVER
USE_LAC_SESSION_FOR_STRUCT_OFFSET
USE_NXP_LTC
USE_NXP_MMCAU
USE_QAE_STATIC_MEM
USE_QAE_THREAD_LS
USE_SECRET_CALLBACK
USE_STSAFE_RNG_SEED
@@ -580,24 +585,26 @@ WC_AES_BS_WORD_SIZE
WC_AES_GCM_DEC_AUTH_EARLY
WC_ASN_HASH_SHA256
WC_ASN_RUNTIME_DATE_CHECK_CONTROL
WC_ASYNC_ENABLE_3DES
WC_ASYNC_ENABLE_AES
WC_ASYNC_ENABLE_ARC4
WC_ASYNC_ENABLE_DH
WC_ASYNC_ENABLE_ECC
WC_ASYNC_ENABLE_ECC_KEYGEN
WC_ASYNC_ENABLE_HMAC
WC_ASYNC_ENABLE_MD5
WC_ASYNC_ENABLE_RSA
WC_ASYNC_ENABLE_RSA_KEYGEN
WC_ASYNC_ENABLE_SHA
WC_ASYNC_ENABLE_SHA224
WC_ASYNC_ENABLE_SHA256
WC_ASYNC_ENABLE_SHA3
WC_ASYNC_ENABLE_SHA384
WC_ASYNC_ENABLE_SHA512
WC_ASYNC_NO_3DES
WC_ASYNC_NO_AES
WC_ASYNC_NO_ARC4
WC_ASYNC_NO_CRYPT
WC_ASYNC_NO_HASH
WC_ASYNC_NO_DH
WC_ASYNC_NO_ECC
WC_ASYNC_NO_HMAC
WC_ASYNC_NO_MD5
WC_ASYNC_NO_PKI
WC_ASYNC_NO_RNG
WC_ASYNC_NO_RSA
WC_ASYNC_NO_RSA_KEYGEN
WC_ASYNC_NO_SHA
WC_ASYNC_NO_SHA224
WC_ASYNC_NO_SHA256
WC_ASYNC_NO_SHA3
WC_ASYNC_NO_SHA384
WC_ASYNC_NO_SHA512
WC_ASYNC_THREAD_BIND
WC_CACHE_RESISTANT_BASE64_TABLE
WC_DILITHIUM_CACHE_PRIV_VECTORS
WC_DILITHIUM_CACHE_PUB_VECTORS
@@ -607,6 +614,7 @@ WC_ECC_NONBLOCK_ONLY
WC_FLAG_DONT_USE_AESNI
WC_FORCE_LINUXKM_FORTIFY_SOURCE
WC_LMS_FULL_HASH
WC_NO_ASYNC_SLEEP
WC_NO_RNG_SIMPLE
WC_NO_STATIC_ASSERT
WC_PKCS11_FIND_WITH_ID_ONLY
@@ -977,6 +985,7 @@ __BCPLUSPLUS__
__BIG_ENDIAN__
__BORLANDC__
__CCRX__
__CC_ARM
__COMPILER_VER__
__COUNTER__
__CYGWIN__

View File

@@ -148,6 +148,7 @@ EXTRA_DIST+= valgrind-bash.supp
EXTRA_DIST+= fips-hash.sh
EXTRA_DIST+= gencertbuf.pl
EXTRA_DIST+= README.md
EXTRA_DIST+= README-async.md
EXTRA_DIST+= README
EXTRA_DIST+= ChangeLog.md
EXTRA_DIST+= LICENSING

558
README-async.md Normal file
View File

@@ -0,0 +1,558 @@
# wolfSSL / wolfCrypt Asynchronous Support
The asynchronous code was previously maintained at https://github.com/wolfSSL/wolfAsyncCrypt but was integrated into wolfSSL proper starting with release v5.8.4.
This feature is enabled using:
`./configure --enable-asynccrypt` or `#define WOLFSSL_ASYNC_CRYPT`.
If async crypto is enabled but no hardware backend is enabled or if `WOLFSSL_ASYNC_CRYPT_SW` is defined, a software backend using wolfCrypt is used instead. This software backend can simulate periodic hardware delays using the macro `WOLF_ASYNC_SW_SKIP_MOD`, which is on by default if `DEBUG_WOLFSSL` is defined.
## Design
Each crypto algorithm has its own `WC_ASYNC_DEV` structure, which contains a `WOLF_EVENT`, local crypto context and local hardware context.
For SSL/TLS the `WOLF_EVENT` context is the `WOLFSSL*` and the type is `WOLF_EVENT_TYPE_ASYNC_WOLFSSL`. For wolfCrypt operations the `WOLF_EVENT` context is the `WC_ASYNC_DEV*` and the type is `WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT`.
A generic event system has been created using a `WOLF_EVENT` structure when `HAVE_WOLF_EVENT` is defined. The event structure resides in the `WC_ASYNC_DEV`.
The asynchronous crypto system is modeled after epoll. The implementation uses `wolfSSL_AsyncPoll` or `wolfSSL_CTX_AsyncPoll` to check if any async operations are complete.
## Hardware Backends
Supported hardware backends:
* Intel QuickAssist with QAT 1.6 or QAT 1.7 driver. See README.md in `wolfcrypt/src/port/intel/README.md`.
* Cavium Nitrox III and V. See README.md in `wolfcrypt/src/port/cavium/README.md`.
## wolfCrypt Backend
The wolfCrypt backend uses the same API as the hardware backends do. Once an asynchronous operation is initiated with the software backend, subsequent calls to `wolfSSL_AsyncPoll` will call into wolfCrypt to complete the operation. If non-blocking is enabled, for example, for ECC (via `WC_ECC_NONBLOCK`), each `wolfSSL_AsyncPoll` will do a chunk of work for the operation and return, to minimize blocking time.
## API's
### ```wolfSSL_AsyncPoll```
```
int wolfSSL_AsyncPoll(WOLFSSL* ssl, WOLF_EVENT_FLAG flags);
```
Polls the provided WOLFSSL object's reference to the WOLFSSL_CTX's event queue to see if any operations outstanding for the WOLFSSL object are done. Return the completed event count on success.
### ```wolfSSL_CTX_AsyncPoll```
```
int wolfSSL_CTX_AsyncPoll(WOLFSSL_CTX* ctx, WOLF_EVENT** events, int maxEvents, WOLF_EVENT_FLAG flags, int* eventCount)
```
Polls the provided WOLFSSL_CTX context event queue to see if any pending events are done. If the `events` argument is provided then a pointer to the `WOLF_EVENT` will be returned up to `maxEvents`. If `eventCount` is provided then the number of events populated will be returned. The `flags` allows for `WOLF_POLL_FLAG_CHECK_HW` to indicate if the crypto backend (i.e. hardware or wolfCrypt, if the software implementation is being used) should be polled again or just return more events.
### ```wolfAsync_DevOpen```
```
int wolfAsync_DevOpen(int *devId);
```
Open the async device and returns an `int` device id for it.
### ```wolfAsync_DevOpenThread```
```
int wolfAsync_DevOpenThread(int *devId, void* threadId);
```
Opens the async device for a specific thread. A crypto instance is assigned and thread affinity set.
### ```wolfAsync_DevClose```
```
void wolfAsync_DevClose(int *devId)
```
Closes the async device.
### ```wolfAsync_DevCopy```
```
int wolfAsync_DevCopy(WC_ASYNC_DEV* src, WC_ASYNC_DEV* dst);
```
Copy async device memory safe (not pointers to old device).
### ```wolfAsync_DevCtxInit```
```
int wolfAsync_DevCtxInit(WC_ASYNC_DEV* asyncDev, word32 marker, void* heap, int devId);
```
Initialize the device context and open the device hardware using the provided `WC_ASYNC_DEV ` pointer, marker and device id (from wolfAsync_DevOpen).
### ```wolfAsync_DevCtxFree```
```
void wolfAsync_DevCtxFree(WC_ASYNC_DEV* asyncDev);
```
Closes and free's the device context.
### ```wolfAsync_EventInit```
```
int wolfAsync_EventInit(WOLF_EVENT* event, enum WOLF_EVENT_TYPE type, void* context, word32 flags);
```
Initialize an event structure with provided type and context. Sets the pending flag and the status code to `WC_PENDING_E`. Current flag options are `WC_ASYNC_FLAG_NONE` and `WC_ASYNC_FLAG_CALL_AGAIN` (indicates crypto needs called again after WC_PENDING_E).
### ```wolfAsync_EventWait ```
```
int wolfAsync_EventWait(WOLF_EVENT* event);
```
Waits for the provided event to complete.
### ```wolfAsync_EventPoll```
```
int wolfAsync_EventPoll(WOLF_EVENT* event, WOLF_EVENT_FLAG event_flags);
```
Polls the provided event to determine if its done.
### ```wolfAsync_EventPop ```
```
int wolfAsync_EventPop(WOLF_EVENT* event, enum WOLF_EVENT_TYPE event_type);
```
This will check the event to see if the event type matches and the event is complete. If it is then the async return code is returned. If not then `WC_NOT_PENDING_E` is returned.
### ```wolfAsync_EventQueuePush```
```
int wolfAsync_EventQueuePush(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
```
Pushes an event to the provided event queue and assigns the provided event.
### ```wolfAsync_EventQueuePoll```
```
int wolfAsync_EventQueuePoll(WOLF_EVENT_QUEUE* queue, void* context_filter,
WOLF_EVENT** events, int maxEvents, WOLF_EVENT_FLAG event_flags, int* eventCount);
```
Polls all events in the provided event queue. Optionally filters by context. Will return pointers to the done events.
### ```wc_AsyncHandle```
```
int wc_AsyncHandle(WC_ASYNC_DEV* asyncDev, WOLF_EVENT_QUEUE* queue, word32 flags);
```
This will push the event inside asyncDev into the provided queue.
### ```wc_AsyncWait```
```
int wc_AsyncWait(int ret, WC_ASYNC_DEV* asyncDev, word32 flags);
```
This will wait until the provided asyncDev is done (or error).
### ```wolfAsync_HardwareStart```
```
int wolfAsync_HardwareStart(void);
```
If using multiple threads this allows a way to start the hardware before using `wolfAsync_DevOpen` to ensure the memory system is setup. Ensure that `wolfAsync_HardwareStop` is called on exit. Internally there is a start/stop counter, so this can be called multiple times, but stop must also be called the same number of times to shutdown the hardware.
### ```wolfAsync_HardwareStop```
```
void wolfAsync_HardwareStop(void);
```
Stops hardware if internal `--start_count == 0`.
## Examples
### TLS Server Example
```c
int devId = INVALID_DEVID;
ret = wolfAsync_DevOpen(&devId);
if (ret != 0) {
err_sys("Async device open failed");
}
wolfSSL_CTX_SetDevId(ctx, devId);
do {
err = 0; /* reset error */
ret = wolfSSL_accept(ssl, msg, msgSz, &msgSz);
if (ret <= 0) {
err = wolfSSL_get_error(ssl, 0);
if (err == WC_PENDING_E) {
ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
if (ret < 0) break;
}
}
} while (err == WC_PENDING_E);
if (ret != WOLFSSL_SUCCESS) {
err_sys("SSL_connect failed");
}
wolfAsync_DevClose(&devId);
```
### wolfCrypt RSA Example
```c
static int devId = INVALID_DEVID;
RsaKey key;
ret = wolfAsync_DevOpen(&devId);
if (ret != 0)
err_sys("Async device open failed");
wc_InitRsaKey_ex(&key, HEAP_HINT, devId);
if (ret == 0) {
ret = wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes);
do {
ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
if (ret >= 0)
ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, &key, &rng);
} while (ret == WC_PENDING_E);
wc_FreeRsaKey(&key);
}
wolfAsync_DevClose(&devId);
```
## Build Options
1. Async multi-threading can be disabled by defining `WC_NO_ASYNC_THREADING`. This only disables internal async threading functions. You are free to use other threading APIs or paradigms in your application.
2. Software benchmarks can be disabled by defining `NO_SW_BENCH`.
3. The `WC_ASYNC_THRESH_NONE` define can be used to disable the cipher thresholds, which are tunable values to determine at what size hardware should be used vs. software.
4. Use `WOLFSSL_DEBUG_MEMORY` and `WOLFSSL_TRACK_MEMORY` to help debug memory issues. QAT also supports `WOLFSSL_DEBUG_MEMORY_PRINT`.
## References
### TLS Client/Server Async Example
We have a full TLS client/server async examples here:
* [https://github.com/wolfSSL/wolfssl-examples/blob/master/tls/server-tls-epoll-perf.c](https://github.com/wolfSSL/wolfssl-examples/blob/master/tls/server-tls-epoll-perf.c)
* [https://github.com/wolfSSL/wolfssl-examples/blob/master/tls/client-tls-perf.c](https://github.com/wolfSSL/wolfssl-examples/blob/master/tls/client-tls-perf.c)
#### TLS Threaded epoll Example Building
```sh
git clone git@github.com:wolfSSL/wolfssl-examples.git
cd wolfssl-examples
cd tls
# For QuickAssist: Uncomment QAT lines at top of Makefile
make
```
#### TLS Threaded epoll Example Usage
```sh
$ ./client-tls-perf -?
perf 4.5.0 (NOTE: All files relative to wolfSSL home dir)
-? Help, print this usage
-p <num> Port to listen on, not 0, default 11111
-v <num> SSL version [0-3], SSLv3(0) - TLS1.2(3)), default 3
-l <str> Cipher suite list (: delimited)
-c <file> Certificate file, default ../certs/client-cert.pem
-k <file> Key file, default ../certs/client-key.pem
-A <file> Certificate Authority file, default ../certs/ca-cert.pem
-r Resume session
-n <num> Benchmark <num> connections
-N <num> <num> concurrent connections
-R <num> <num> bytes read from client
-W <num> <num> bytes written to client
-B <num> Benchmark <num> written bytes
```
#### TLS Threaded epoll Example Output
```sh
$ sudo ./server-tls-epoll-threaded -n 10000
$ sudo ./client-tls-perf -n 10000
wolfSSL Server Benchmark 16384 bytes
Num Conns : 10000
Total : 18575.800 ms
Total Avg : 1.858 ms
t/s : 538.335
Accept : 35848.428 ms
Accept Avg : 3.585 ms
Total Read bytes : 163840000 bytes
Total Write bytes : 163840000 bytes
Read : 402.212 ms ( 388.476 MBps)
Write : 591.469 ms ( 264.173 MBps)
```
## Change Log
### wolfSSL Async Release v5.8.0 (May 01, 2025)
* Includes all wolfSSL v5.8.0 fixes. See ChangeLog.md here: https://github.com/wolfSSL/wolfssl/blob/master/ChangeLog.md#wolfssl-release-580-apr-24-2025
* Update for libwolfssl_sources.h refactor. (https://github.com/wolfSSL/wolfAsyncCrypt/pull/77)
### wolfSSL Async Release v5.7.4 (Oct 29, 2024)
* Includes all wolfSSL v5.7.4 fixes. See ChangeLog.md here: https://github.com/wolfSSL/wolfssl/blob/master/ChangeLog.md#wolfssl-release-574-oct-24-2024
- Plus fixes for asynchronous release - SHA3/HMAC devId (https://github.com/wolfSSL/wolfssl/pull/8119)
* Fix for Intel QuickAssist RSA Key generation exponent result. (https://github.com/wolfSSL/wolfAsyncCrypt/pull/75)
### wolfSSL Async Release v5.7.0 (Mar 21, 2023)
* Includes all wolfSSL v5.7.0 fixes. See ChangeLog.md here: https://github.com/wolfSSL/wolfssl/blob/master/ChangeLog.md#wolfssl-release-570-mar-20-2024
### wolfSSL Async Release v5.6.6 (Dec 20, 2023)
* Includes all wolfSSL v5.6.6 fixes. See ChangeLog.md here: https://github.com/wolfSSL/wolfssl/blob/master/ChangeLog.md#wolfssl-release-566-dec-19-2023
- Plus wolfSSL PR 7085 fix for invalid `dh_ffdhe_test` for even P when using Intel QuickAssist. https://github.com/wolfSSL/wolfssl/pull/7085
* Fix for missing `IntelQaFreeFlatBuffer` with DH enabled and no keygen. (broken in PR #71)
* Add return code checking for wc_AsyncThreadCreate_ex in exit_fail section for pthread_attr_destroy. (PR #72)
### wolfSSL Async Release v5.6.4 (Oct 30, 2023)
* Fixes for support async with crypto or pk callbacks.
* Rename `WC_NOT_PENDING_E` -> `WC_NO_PENDING_E`
### wolfSSL Async Release v5.6.3 (June 16, 2023)
* Includes all wolfSSL v5.6.3 fixes. See ChangeLog.md here: https://github.com/wolfSSL/wolfssl/blob/master/ChangeLog.md#wolfssl-release-563-jun-16-2023
* Add sanity check of index devId before accessing array
* Use the blocking call from the async test
### wolfSSL Async Release v5.6.0 (Mar 29, 2023)
* Includes all wolfSSL v5.6.0 fixes. See ChangeLog.md here: https://github.com/wolfSSL/wolfssl/blob/master/ChangeLog.md#wolfssl-release-560-mar-24-2023
* wolfAsyncCrypt github repository became public.
### wolfSSL Async Release v5.5.4 (Dec 22, 2022)
* Includes all wolfSSL v5.5.4 fixes. See ChangeLog.md here: https://github.com/wolfSSL/wolfssl/blob/master/ChangeLog.md#wolfssl-release-554-dec-21-2022
* Use the `wc_ecc_shared_secret_ex` version for async test. Requires https://github.com/wolfSSL/wolfssl/pull/5868
### wolfSSL Async Release v5.5.3 (Nov 8, 2022)
* Includes all wolfSSL v5.5.1-v5.5.3 fixes. See ChangeLog.md here: https://github.com/wolfSSL/wolfssl/blob/master/ChangeLog.md#wolfssl-release-553-nov-2-2022
* Fix for Intel QAT handling of sign R when cofactor is not 1. https://github.com/wolfSSL/wolfssl/pull/5737 and https://github.com/wolfSSL/wolfAsyncCrypt/pull/54
* Fix check scalar bits for ECC cofactor. https://github.com/wolfSSL/wolfssl/pull/5737
* Fixes for async sniffer: https://github.com/wolfSSL/wolfssl/pull/5734
- Handling of packets with multiple TLS messages.
- Multiple back to back sessions.
- Ensure all pending queued packets are finished before ending pcap processing.
* Fix for various tests that do not properly handle `WC_PENDING_E`. https://github.com/wolfSSL/wolfssl/pull/5773
* Revert "Fix for sniffer to decode out of order packets". https://github.com/wolfSSL/wolfssl/pull/5771
### wolfSSL Async Release v5.5.0 (Sep 2, 2022)
* Includes all wolfSSL v5.5.0 fixes. See ChangeLog.md here: https://github.com/wolfSSL/wolfssl/blob/master/ChangeLog.md#wolfssl-release-550-aug-30-2022
* Fix for handling return codes from `pthread_attr_destroy`.
* Fix for async session tickets. https://github.com/wolfSSL/wolfssl/pull/5534
* Fix for async with OCSP non-blocking in ProcessPeerCerts. https://github.com/wolfSSL/wolfssl/pull/5539
### wolfSSL Async Release v5.4.0 (July 11, 2022)
* Fix for DH trim of leading zeros to use memmove.
* Fix to print errors to stderr.
* Fix to consistently return the status of failed pthreads funcs.
* Move async device pointer (https://github.com/wolfSSL/wolfssl/pull/5149)
### wolfSSL Async Release v5.3.0 (May 5, 2022)
* Added Intel QuickAssist ECC Key Generation acceleration. Specifically point multiplication similar to our `wc_ecc_mulmod_ex2`.
* Fix for building Intel QAT with SP math all
* Fix for `error: unused function 'IntelQaFreeFlatBuffer'`.
* Fix for handling the Koblitz curve param "a", which is all zeros.
* Fixes for scan-build warnings.
* Includes wolfSSL PR https://github.com/wolfSSL/wolfssl/pull/5101
### wolfSSL Async Release v5.2.0 (Feb 21, 2022)
* Adds `WC_NO_ASYNC_SLEEP` option to hide wc_AsyncSleep for platforms that do not need it.
* Fix for async test anonymous union on some platforms (`#pragma anon_unions` and `HAVE_ANONYMOUS_INLINE_AGGREGATES`)
* Fixes for invalidPrintfArgType_sint (cppcheck) and readability-redundant-preprocessor (clang-tidy).
### wolfSSL Async Release v5.1.0 (Jan 3rd, 2022)
### wolfSSL Async Release v5.0.0 (11/01/2021)
* Fix for issue with QAT AES GCM input buffer already NUMA and not aligned.
### wolfSSL Async Release v4.8.0 (07/14/2021)
* Fix for new QAT 1.7 hash types warning.
* Updated Intel QAT 1.7 build instructions.
* Includes possible HAVE_WOLF_BIGINT leaks in PR https://github.com/wolfSSL/wolfssl/pull/4208
### wolfSSL Async Release v4.7.0 (02/20/2021)
* Fix for ARC4 macro typo
### wolfSSL Async Release v4.6.0 (12/21/2020)
* Documentation updates.
* Fixes for Cavium Nitrox and Intel Quick Assist (wolfSSL/wolfssl#3577) with TLS v1.3
### wolfSSL Async Release v4.4.0 (04/24/2020)
* Fix for uninitialized `supSha3` warning.
* Fix for use of incorrect devId for wolfSSL_SHA3_256_Init.
* Fix for QAT with Shake256.
* Fix for QAT example `./build.sh`.
### wolfSSL Async Release v4.3.0 (12/20/2019)
* Fix for async date override callback issue.
* Updates to Octeon README.
### wolfSSL Async Release v4.2.0 (10/22/2019)
* Fix for QuickAssist DH Agree issue with leading zero bytes.
* Fix for QuickAssist AES CBC issue with previous IV on back-to-back operations.
* Updates to QuickAssist README.md for latest QAT v1.7 driver.
* Instructions for Octeon III (CN7300) use.
### wolfSSL Async Release v4.0.0 (03/25/2019)
* Fix for building with QuickAssist v1.7 driver (4.4.0-00023) (was missing usdm_drv during configure with check).
* Fix for building async with file system disabled.
* Fix for SHA-3 runtime detection for not supported in hardware.
### wolfSSL Async Release v3.15.8 (03/01/2019) - Intermediate release
* Performance improvements for QuickAssist.
* Added new build option `QAT_POLL_RESP_QUOTA` to indicate maximum number of callbacks to service per poll. The default is 0 (all), was previously 8.
* Added useful QAT_DEBUG logging for ECC and DH operations.
* Cleanup whitespace in quickassist.c.
* Enhanced the Cavium macros for `CAVIUM_MAX_PENDING` and `CAVIUM_MAX_POLL` over-ridable.
* Added build-time override for benchmark thread count `WC_ASYNC_BENCH_THREAD_COUNT`.
* Fixes for wolfCrypt test with asynchronous support enabled and `--enable-nginx`.
* Fix to use QAT for ECC sign and verify when SP is enabled and key was initialized with devId.
* Fixes issues with wolfCrypt test and QAT not properly calling "again" for the ECC sign, verify and shared secret.
* Correct the output for multi-threaded benchmark using `-base10` option.
* Fixes to QAT HMAC enables in benchmark tool.
* Adds new `NO_HW_BENCH` to support using multi-threaded software only benchmarks.
### wolfSSL Async Release v3.15.7 (12/27/2018)
* Fixes for various analysis warnings (https://github.com/wolfSSL/wolfssl/pull/2003).
* Added QAT v1.7 driver support.
* Added QAT SHA-3 support.
* Added QAT RSA Key Generation support.
* Added support for new usdm memory driver.
* Added support for detecting QAT version and features.
* Added `QAT_ENABLE_RNG` option to disable QAT TRNG/DRBG.
* Added alternate hashing method to cache all updates (avoids using partial updates).
### wolfSSL Async Release v3.15.5 (11/09/2018)
* Fixes for various analysis warnings (https://github.com/wolfSSL/wolfssl/pull/1918).
* Fix for QAT possible double free case where `ctx->symCtx` is not trapped.
* Improved QAT debug messages when using `QAT_DEBUG`.
* Fix for QAT RNG to allow zero length. This resolves PSS case where `wc_RNG_GenerateBlock` is called for saltLen == 0.
### wolfSSL Async Release v3.15.3 (06/20/2018)
* Fixes for fsantize tests with Cavium Nitrox V.
* Removed typedef for `CspHandle`, since its already defined.
* Fixes for a couple of fsanitize warnings.
* Fix for possible leak with large request to `IntelQaDrbg`.
### wolfSSL Async Release v3.14.4 (04/13/2018)
* Added Nitrox V ECC.
* Added Nitrox V SHA-224 and SHA-3
* Added Nitrox V AES GCM
* Added Nitrox III SHA2 384/512 support for HMAC.
* Added error code handling for signature check failure.
* Added error translate for `ERR_PKCS_DECRYPT_INCORRECT`
* Added useful `WOLFSSL_NITROX_DEBUG` and show count for pending checks.
* Cleanup of Nitrox symmetric processing to use single while loops.
* Cleanup to only include some headers in cavium_nitrox.c port.
* Fixes for building against Nitrox III and V SDK.
* Updates to README.md with required CFLAGS/LDFLAGS when building without ./configure.
* Fix for Intel QuickAssist HMAC to use software for unsupported hash algorithms.
### wolfSSL Async Release v3.12.2 (10/22/2017)
* Fix for HMAC QAT when block size aligned. The QAT HMAC final without any buffers will fail incorrectly (bug in QAT 1.6).
* Nitrox fix for rename of `ContextType` to `context_type_t`. Updates to Nitrox README.md.
* Workaround for `USE_QAE_THREAD_LS` issue with realloc from a different thread.
* Fix for hashing to allow zero length. This resolves issue with new empty hash tests.
* Fix bug with blocking async where operation was being free'd before completion. Set freeFunc prior to performing operation and check ret code in poll.
* Fix leak with cipher symmetric context close.
* Fix QAT_DEBUG partialState offset.
* Fixes for symmetric context caching.
* Refactored async event initialization so its done prior to making possible async calls.
* Fix to resolve issue with QAT callbacks and multi-threading.
* The cleanup is now handled in polling function and the event is only marked done from the polling thread that matches the originating thread.
* Fix possible mem leak with multiple threads `g_qatEcdhY` and `g_qatEcdhCofactor1`.
* Fix the block polling to use `ret` instead of `status`.
* Change order of `IntelQaDevClear` and setting `event->ret`.
* Fixes to better handle threading with async.
* Refactor of async event state.
* Refactor to initialize event prior to operation (in case it finishes before adding to queue).
* Fixes issues with AES GCM decrypt that can corrupt up to authTag bytes at end of output buffer provided.
* Optimize the Hmac struct to replace keyRaw with ipad.
* Enhancement to allow reuse of the symmetric context for ciphers.
* Fixes for QuickAssist (QAT) multi-threading. Fix to not set return code until after callback cleanup.
* Disable thread binding to specific CPU by default (enabled now with `WC_ASYNC_THREAD_BIND`).
* Added optional define `QAT_USE_POLLING_CHECK ` to have only one thread polling at a time (not required and doesn't improve performance).
* Reduced default QAT_MAX_PENDING for benchmark to 15 (120/num_threads).
* Fix for IntelQaDrbg to handle buffer over 0xFFFF in length.
* Added working DRBG and TRNG implementations for QAT.
* Fix to set callback status after ret and output have been set. Cleanup of the symmetric context.
* Updates to support refactored dynamic types.
* Fix for QAT symmetric to allow NULL authTag.
* Fix GCC 7 build warning with braces.
* Cleanup formatting.
### wolfSSL Async Release v3.11.0 (05/05/2017)
* Fixes for Cavium Nitrox III/V.
- Fix with possible crash when using a request Id that is already complete, due to partial submissions not marking event done.
- Improvements to max buffer lengths.
- Fixes to handle various return code patterns with CNN55XX-SDK.
- All Nitrox V tests and benchmarks pass. Bench: RSA 2048-bit public 336,674 ops/sec and private (CRT) 66,524 ops/sec.
* Intel QuickAssist support and various async fixes/improvements:
- Added support for Intel QuickAssist v1.6 driver with QuickAssist 8950 hardware
- Added QAE memory option to use static memory list instead of dynamic list using `USE_QAE_STATIC_MEM`.
- Added tracking of deallocs and made the values signed long.
- Improved code for wolf header check and expanded to 16-byte alignment for performance improvement with TLS.
- Added ability to override limit dev access parameters and all configurable QAT fields.
- Added async simulator tests for DH, DES3 CBC and AES CBC/GCM.
- Rename AsyncCryptDev to WC_ASYNC_DEV.
- Refactor to move WOLF_EVENT into WC_ASYNC_DEV.
- Refactor the async struct/enum names to use WC_ naming.
- Refactor of the async event->context to use WOLF_EVENT_TYPE_ASYNC_WOLFSSL or WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT to indicate the type of context pointer.
- Added flag to WOLF_EVENT which is used to determine if the async complete should call into operation again or goto next `WC_ASYNC_FLAG_CALL_AGAIN`.
- Cleanup of the "wolfAsync_DevCtxInit" calls to make sure asyncDev is always cleared if invalid device id is used.
- Eliminated WOLFSSL_ASYNC_CRYPT_STATE.
- Removed async event type WOLF_EVENT_TYPE_ASYNC_ANY.
- Enable the random extra delay option by default for simulator as it helps catch bugs.
- Cleanup for async free to also check marker.
- Refactor of the async wait and handle to reduce duplicate code.
- Added async simulator test for RSA make key.
- Added WC_ASYNC_THRESH_NONE to allow bypass of threshold for testing
- Added static numbers for the async sim test types, for easier debugging of the “testDev->type” value.
- Populate heap hint into asyncDev struct.
- Enhancement to cache the asyncDev to improve poll performance.
- Added async threading helpers and new wolfAsync_DevOpenThread.
- Added WC_NO_ASYNC_THREADING to prevent async threading.
- Added new API “wc_AsyncGetNumberOfCpus” for getting number of CPUs.
- Added new “wc_AsyncThreadYield” API.
- Added WOLF_ASYNC_MAX_THREADS.
- Added new API for wolfAsync_DevCopy.
- Fix to make sure an async init failure sets the deviceId to INVALID_DEVID.
- Fix for building with async threading support on Mac.
- Fix for using simulator so it supports multiple threads.
* Moved Intel QuickAssist and Cavium Nitrox III/V code into async repo.
* Added new WC_ASYNC_NO_* options to allow disabling of individual async algorithms.
- New defines are: WC_ASYNC_NO_CRYPT, WC_ASYNC_NO_PKI and WC_ASYNC_NO_HASH.
- Additionally each algorithm has a WC_ASYNC_NO_[ALGO] define.
### wolfSSL Async Release v3.9.8 (07/25/2016)
* Asynchronous wolfCrypt and Cavium Nitrox V support.
### wolfSSL Async Release v3.9.0 (03/04/2016)
* Initial version with async simulator and README.md.
## Support
For questions email wolfSSL support at support@wolfssl.com

View File

@@ -11,8 +11,6 @@ fips-hash.sh - updates the verifyCore hash in fips_test.c
fips-check.sh - checks if current wolfSSL version works against FIPS wolfCrypt
comment out last line to leave working directory
async-check.sh - internal script for validating wolfSSL Async using the simulator.
gencertbuf.pl - creates certs_test.h, our certs / keys C array for easy non
filesystem testing

View File

@@ -1,104 +0,0 @@
#!/usr/bin/env bash
# This script creates symbolic links to the required asynchronous
# file for using the asynchronous simulator and make check
# Fail on any error in script
set -e
ASYNC_REPO=https://github.com/wolfSSL/wolfAsyncCrypt.git
ASYNC_DIR=${ASYNC_DIR:-wolfAsyncCrypt}
function Usage() {
printf "Usage: $0 [install|uninstall|test|remove]\n"
printf "\tinstall - get and set up links to wolfAsyncCrypt files\n"
printf "\tuninstall - remove the links to wolfAsyncCrypt\n"
printf "\ttest - install and run 'make check'\n"
printf "\tremove - uninstall and remove wolfAsyncCrypt\n"
}
function UnlinkFiles() {
unlink ./wolfcrypt/src/async.c
unlink ./wolfssl/wolfcrypt/async.h
unlink ./wolfcrypt/src/port/intel/quickassist.c
unlink ./wolfcrypt/src/port/intel/quickassist_mem.c
unlink ./wolfcrypt/src/port/intel/README.md
unlink ./wolfssl/wolfcrypt/port/intel/quickassist.h
unlink ./wolfssl/wolfcrypt/port/intel/quickassist_mem.h
unlink ./wolfcrypt/src/port/cavium/cavium_nitrox.c
unlink ./wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h
unlink ./wolfcrypt/src/port/cavium/README.md
# restore original README.md files
git checkout -- wolfcrypt/src/port/cavium/README.md
git checkout -- wolfcrypt/src/port/intel/README.md
}
function LinkFiles() {
# link files
ln -s -f ../../${ASYNC_DIR}/wolfcrypt/src/async.c ./wolfcrypt/src/async.c
ln -s -f ../../${ASYNC_DIR}/wolfssl/wolfcrypt/async.h ./wolfssl/wolfcrypt/async.h
ln -s -f ../../../../${ASYNC_DIR}/wolfcrypt/src/port/intel/quickassist.c ./wolfcrypt/src/port/intel/quickassist.c
ln -s -f ../../../../${ASYNC_DIR}/wolfcrypt/src/port/intel/quickassist_mem.c ./wolfcrypt/src/port/intel/quickassist_mem.c
ln -s -f ../../../../${ASYNC_DIR}/wolfcrypt/src/port/intel/README.md ./wolfcrypt/src/port/intel/README.md
ln -s -f ../../../../${ASYNC_DIR}/wolfssl/wolfcrypt/port/intel/quickassist.h ./wolfssl/wolfcrypt/port/intel/quickassist.h
ln -s -f ../../../../${ASYNC_DIR}/wolfssl/wolfcrypt/port/intel/quickassist_mem.h ./wolfssl/wolfcrypt/port/intel/quickassist_mem.h
ln -s -f ../../../../${ASYNC_DIR}/wolfcrypt/src/port/cavium/cavium_nitrox.c ./wolfcrypt/src/port/cavium/cavium_nitrox.c
ln -s -f ../../../../${ASYNC_DIR}/wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h ./wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h
ln -s -f ../../../../${ASYNC_DIR}/wolfcrypt/src/port/cavium/README.md ./wolfcrypt/src/port/cavium/README.md
}
function Install() {
if [ -d $ASYNC_DIR ];
then
echo "Using existing async repo"
else
# make a clone of the wolfAsyncCrypt repository
git clone --depth 1 $ASYNC_REPO $ASYNC_DIR
fi
# setup auto-conf
./autogen.sh
LinkFiles
}
function Uninstall() {
UnlinkFiles
}
function Test() {
Install
./configure --enable-asynccrypt --enable-all
make check
}
function Remove() {
UnlinkFiles
rm -rf ${ASYNC_DIR}
}
if [ "$#" -gt 1 ]; then
Usage
exit 1
fi
case "x$1" in
"xinstall")
Install
;;
"xuninstall")
Uninstall
;;
"xremove")
Remove
;;
"xtest")
Test
;;
*)
Usage
exit 1
;;
esac

View File

@@ -17,7 +17,7 @@ if [ -n "$WSL_DISTRO_NAME" ]; then
fi
# if and as needed, create empty dummy versions of various files, mostly
# associated with fips/self-test and asynccrypt:
# associated with fips/self-test:
for dir in \
./wolfssl/wolfcrypt/port/intel \
@@ -35,15 +35,7 @@ for file in \
./wolfcrypt/src/wolfcrypt_first.c \
./wolfcrypt/src/wolfcrypt_last.c \
./wolfssl/wolfcrypt/fips.h \
./wolfcrypt/src/selftest.c \
./wolfcrypt/src/async.c \
./wolfssl/wolfcrypt/async.h \
./wolfcrypt/src/port/intel/quickassist.c \
./wolfcrypt/src/port/intel/quickassist_mem.c \
./wolfcrypt/src/port/cavium/cavium_nitrox.c \
./wolfssl/wolfcrypt/port/intel/quickassist.h \
./wolfssl/wolfcrypt/port/intel/quickassist_mem.h \
./wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h
./wolfcrypt/src/selftest.c
do
if [ ! -e "$file" ]; then
> "$file" || exit $?

View File

@@ -9535,10 +9535,6 @@ fi
if test "$ENABLED_ASYNCCRYPT" = "yes"
then
AC_MSG_NOTICE([Enabling asynchronous support])
if ! test -f ${srcdir}/wolfcrypt/src/async.c || ! test -f ${srcdir}/wolfssl/wolfcrypt/async.h
then
AC_MSG_ERROR([--enable-asynccrypt requested, but WOLFSSL_ASYNC_CRYPT source files are missing.])
fi
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ASYNC_CRYPT -DHAVE_WOLF_EVENT -DHAVE_WOLF_BIGINT -DWOLFSSL_NO_HASH_RAW"
@@ -11623,11 +11619,6 @@ fi # $silent != yes
# Show warnings at bottom so they are noticed
################################################################################
if test "$ENABLED_ASYNCCRYPT" = "yes" && ! test -s $srcdir/wolfcrypt/src/async.c
then
AC_MSG_WARN([Make sure real async files are loaded. See async-check.sh or the wolfssl/wolfAsyncCrypt GitHub repo.])
fi
# MinGW static vs shared library
# Reference URL from libtool for MinGW is located at
# http://www.gnu.org/software/libtool/manual/libtool.html#Cygwin-to-MinGW-Cross

View File

@@ -6,9 +6,6 @@ Supported with:
* Crypto Callbacks (`--enable-cryptocb`)
* PK Callbacks (`--enable-pkcallbacks`)
Requires files from https://github.com/wolfSSL/wolfAsyncCrypt
See `async-check.sh` for how to setup.
Tested with:
* `./configure --enable-asynccrypt --enable-rsa --disable-ecc`
* `./configure --enable-asynccrypt --disable-rsa --enable-ecc`
@@ -25,7 +22,7 @@ make
## Asynchronous Cryptography Design
When a cryptogaphic call is handed off to hardware it return `WC_PENDING_E` up to caller. Then it can keep calling until the operation completes. For some platforms it is required to call `wolfSSL_AsyncPoll`. At the TLS layer a "devId" (Device ID) must be set using `wolfSSL_CTX_SetDevId` to indicate desire to offload cryptography.
When a cryptographic call is handed off to hardware it return `WC_PENDING_E` up to caller. Then it can keep calling until the operation completes. For some platforms it is required to call `wolfSSL_AsyncPoll`. At the TLS layer a "devId" (Device ID) must be set using `wolfSSL_CTX_SetDevId` to indicate desire to offload cryptography.
For further design details please see: https://github.com/wolfSSL/wolfAsyncCrypt#design

1158
wolfcrypt/src/async.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,264 @@
# Cavium Nitrox III/V Support
# Cavium Nitrox V Support
Please contact wolfSSL at info@wolfssl.com to request an evaluation.
## Directory Structure:
`/`
`/CNN55XX-SDK`
`/wolfssl`
## Building Cavium Driver
Tested using `CNN55XX-Driver-Linux-KVM-XEN-PF-SDK-1.4.14.tar`
### Installation
```sh
$ cd CN55XX-SDK
$ make clean
$ make
$ cd bin
$ sudo perl ./init_nitrox.pl
NITROX-V devices found: 1
NITROX-V driver(nitrox_drv.ko) load: SUCCESS
NITROX-V Device-0 part: CNN5560-900BG676-C45-G
Reading config file: ../microcode/ssl.conf
Device count: 1 Config file device count: 2
NITROX Model: 0x1200 [ CNN55XX PASS 1.0 ]
Microcode Details:
Version : CNN5x-MC-AE-MAIN-0001
Core Count : 80
Code length : 9514
Block number: 0
Microcode Details:
Version : CNN5x-MC-SE-SSL-0004
Core Count : 64
Code length : 23738
Block number: 1
Microcode Load Succeed on device: 0
[ AE ] Microcode: CNN5x-MC-AE-MAIN-0001
Group : 0
Core Mask [Hi Low]: ffff ffffffffffffffff [ 80 ]
[ SE ] Microcode: CNN5x-MC-SE-SSL-0004
Group : 0
Core Mask : ffffffffffffffff [ 64 ]
Microcode Load success
```
```sh
$ lspci | grep Cavium
09:00.0 Network and computing encryption device: Cavium, Inc. Nitrox XL NPX (rev 01)
81:00.0 Network and computing encryption device: Cavium, Inc. Device 0012
```
#### Issues
1. Fixes to Nitrox Driver for includes into wolfSSL
a. Modify `include/vf_defs.h:120` -> `vf_config_mode_str()` function to:
```c
static inline const char *vf_config_mode_str(vf_config_type_t vf_mode)
{
const char *vf_mode_str;
```
b. Add `case PF:` to `include/vf_defs.h:82` above `default:` in `vf_config_mode_to_num_vfs()`.
c. In `include/linux/sysdep.h:46` rename `__BYTED_ORDER` to `__BYTE_ORDER`.
2. If the CNN55XX driver is not extracted on the Linux box it can cause issues with the symbolic links in the microcode folder. Fix was to resolve the symbolic links in `./microcode`.
```sh
NITROX Model: 0x1200 [ CNN55XX PASS 1.0 ]
Invalid microcode
ucode_dload: failed to initialize
```
Resolve Links:
```sh
cd microcode
rm main_asym.out
ln -s ./build/main_ae.out ./main_asym.out
rm main_ipsec.out
ln -s ./build/main_ipsec.out ./main_ipsec.out
rm main_ssl.out
ls -s ./build/main_ssl.out ./main_ssl.out
```
## Building wolfSSL
```sh
./configure --with-cavium-v=../CNN55XX-SDK --enable-asynccrypt --enable-aesni --enable-intelasm
make
sudo make install
```
### CFLAGS
`CFLAGS+= -DHAVE_CAVIUM -DHAVE_CAVIUM_V -DWOLFSSL_ASYNC_CRYPT -DHAVE_WOLF_EVENT -DHAVE_WOLF_BIGINT`
`CFLAGS+= -I../CNN55XX-SDK/include -lrt -lcrypto`
* `HAVE_CAVIUM`: The Cavium define
* `HAVE_CAVIUM_V`: Nitrox V
* `WOLFSSL_ASYNC_CRYPT`: Enable asynchronous wolfCrypt.
* `HAVE_WOLF_EVENT`: Enable wolf event support (required for async)
* `HAVE_WOLF_BIGINT`: Enable wolf big integer support (required for async)
### LDFLAGS
Include the libnitrox static library:
`LDFLAGS+= ../CNN55XX-SDK/lib/libnitrox.a`
### wolfSSL Build Issues
a. If building with debug `-g` and using an older binutils LD version 2.23 or less you may see a linker crash. Example of error: `BFD (GNU Binutils) 2.23.2 internal error, aborting at merge.c line 873 in _bfd_merged_section_offset`. Resolution is to use this in the CFLAGS `-g -fno-merge-debug-strings -fdebug-types-section`.
## Usage
Note: Must run applications with `sudo` to access device.
```
sudo ./wolfcrypt/benchmark/benchmark
sudo ./wolfcrypt/test/testwolfcrypt
```
## TLS Code Template
```c
/* GLOBAL DEVICE IDENTIFIER */
#ifdef WOLFSSL_ASYNC_CRYPT
static int devId = INVALID_DEVID;
#endif
/* DONE AT INIT */
#ifdef WOLFSSL_ASYNC_CRYPT
if (wolfAsync_DevOpen(&devId) != 0) {
fprintf(stderr, "Async device open failed\nRunning without async\n");
}
wolfSSL_CTX_UseAsync(ctx, devId);
#endif
/* DONE IN YOUR WORKER LOOP IN WC_PENDING_E CASES AGAINST YOUR WOLFSSL_CTX */
#ifdef WOLFSSL_ASYNC_CRYPT
int ret;
WOLF_EVENT* wolfEvents[MAX_WOLF_EVENTS];
int eventCount, i;
/* get list of events that are done (not pending) */
ret = wolfSSL_CTX_AsyncPoll(ctx, wolfEvents, MAX_WOLF_EVENTS, WOLF_POLL_FLAG_CHECK_HW, &eventCount);
if (ret != 0)
goto error;
for (i = 0; i < eventCount; i++) {
WOLFSSL* ssl = (WOLFSSL*)wolfEvents[i]->context;
if (ssl) {
/* your SSL object is ready to be called again */
}
}
#endif
/* DONE AT CLEANUP */
#ifdef WOLFSSL_ASYNC_CRYPT
wolfAsync_DevClose(&devId);
#endif
```
## Benchmarks
Nitrox V: CNN5560-900-C45
Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
CentOS: Kernel 3.10.0-514.16.1.el7.x86_64
Single Thread
```
./configure --with-cavium-v=../CNN55XX-SDK --enable-asynccrypt --enable-aesni --enable-intelasm --enable-sp --enable-sp-asm CFLAGS="-DWC_NO_ASYNC_THREADING" && make
sudo ./wolfcrypt/benchmark/benchmark
wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each)
RNG SW 135 MB took 1.012 seconds, 133.356 MB/s Cycles per byte = 25.69
RNG HW 85 MB took 1.049 seconds, 81.039 MB/s Cycles per byte = 42.27
AES-128-CBC-enc SW 845 MB took 1.001 seconds, 844.293 MB/s Cycles per byte = 4.06
AES-128-CBC-dec SW 6060 MB took 1.001 seconds, 6055.102 MB/s Cycles per byte = 0.57
AES-192-CBC-enc SW 710 MB took 1.004 seconds, 707.248 MB/s Cycles per byte = 4.84
AES-192-CBC-dec SW 5055 MB took 1.001 seconds, 5050.086 MB/s Cycles per byte = 0.68
AES-256-CBC-enc SW 610 MB took 1.003 seconds, 608.296 MB/s Cycles per byte = 5.63
AES-256-CBC-dec SW 4330 MB took 1.001 seconds, 4326.604 MB/s Cycles per byte = 0.79
AES-128-CBC-enc HW 240 MB took 1.018 seconds, 235.801 MB/s Cycles per byte = 14.53
AES-128-CBC-dec HW 240 MB took 1.011 seconds, 237.312 MB/s Cycles per byte = 14.43
AES-192-CBC-enc HW 220 MB took 1.021 seconds, 215.411 MB/s Cycles per byte = 15.90
AES-192-CBC-dec HW 215 MB took 1.002 seconds, 214.516 MB/s Cycles per byte = 15.97
AES-256-CBC-enc HW 200 MB took 1.016 seconds, 196.910 MB/s Cycles per byte = 17.40
AES-256-CBC-dec HW 200 MB took 1.016 seconds, 196.758 MB/s Cycles per byte = 17.41
AES-128-GCM-enc SW 3095 MB took 1.000 seconds, 3093.571 MB/s Cycles per byte = 1.11
AES-128-GCM-dec SW 3090 MB took 1.001 seconds, 3087.702 MB/s Cycles per byte = 1.11
AES-192-GCM-enc SW 2825 MB took 1.002 seconds, 2820.654 MB/s Cycles per byte = 1.21
AES-192-GCM-dec SW 2815 MB took 1.000 seconds, 2814.153 MB/s Cycles per byte = 1.22
AES-256-GCM-enc SW 2550 MB took 1.001 seconds, 2548.379 MB/s Cycles per byte = 1.34
AES-256-GCM-dec SW 2555 MB took 1.002 seconds, 2550.183 MB/s Cycles per byte = 1.34
AES-128-GCM-enc HW 135 MB took 1.018 seconds, 132.618 MB/s Cycles per byte = 25.83
AES-128-GCM-dec HW 130 MB took 1.022 seconds, 127.202 MB/s Cycles per byte = 26.93
AES-192-GCM-enc HW 135 MB took 1.019 seconds, 132.435 MB/s Cycles per byte = 25.86
AES-192-GCM-dec HW 130 MB took 1.025 seconds, 126.789 MB/s Cycles per byte = 27.02
AES-256-GCM-enc HW 135 MB took 1.019 seconds, 132.418 MB/s Cycles per byte = 25.87
AES-256-GCM-dec HW 130 MB took 1.023 seconds, 127.071 MB/s Cycles per byte = 26.96
CHACHA SW 3245 MB took 1.001 seconds, 3241.680 MB/s Cycles per byte = 1.06
CHA-POLY SW 1930 MB took 1.000 seconds, 1929.817 MB/s Cycles per byte = 1.77
MD5 SW 710 MB took 1.005 seconds, 706.678 MB/s Cycles per byte = 4.85
POLY1305 SW 4850 MB took 1.000 seconds, 4849.127 MB/s Cycles per byte = 0.71
SHA SW 560 MB took 1.008 seconds, 555.558 MB/s Cycles per byte = 6.17
SHA-224 SW 460 MB took 1.002 seconds, 459.021 MB/s Cycles per byte = 7.46
SHA-256 SW 460 MB took 1.002 seconds, 459.013 MB/s Cycles per byte = 7.46
SHA-384 SW 690 MB took 1.002 seconds, 688.368 MB/s Cycles per byte = 4.98
SHA-512 SW 690 MB took 1.002 seconds, 688.414 MB/s Cycles per byte = 4.98
SHA3-224 SW 330 MB took 1.007 seconds, 327.713 MB/s Cycles per byte = 10.45
SHA3-256 SW 310 MB took 1.000 seconds, 309.909 MB/s Cycles per byte = 11.05
SHA3-384 SW 235 MB took 1.007 seconds, 233.355 MB/s Cycles per byte = 14.68
SHA3-512 SW 170 MB took 1.027 seconds, 165.547 MB/s Cycles per byte = 20.69
HMAC-MD5 SW 705 MB took 1.002 seconds, 703.344 MB/s Cycles per byte = 4.87
HMAC-MD5 HW 62670 MB took 1.000 seconds,62666.115 MB/s Cycles per byte = 0.05
HMAC-SHA SW 555 MB took 1.000 seconds, 554.964 MB/s Cycles per byte = 6.17
HMAC-SHA HW 62745 MB took 1.000 seconds,62744.312 MB/s Cycles per byte = 0.05
HMAC-SHA224 SW 475 MB took 1.005 seconds, 472.870 MB/s Cycles per byte = 7.24
HMAC-SHA224 HW 62415 MB took 1.000 seconds,62412.262 MB/s Cycles per byte = 0.05
HMAC-SHA256 SW 475 MB took 1.005 seconds, 472.710 MB/s Cycles per byte = 7.25
HMAC-SHA256 HW 63185 MB took 1.000 seconds,63180.255 MB/s Cycles per byte = 0.05
HMAC-SHA384 SW 690 MB took 1.005 seconds, 686.794 MB/s Cycles per byte = 4.99
HMAC-SHA384 HW 62575 MB took 1.000 seconds,62573.195 MB/s Cycles per byte = 0.05
HMAC-SHA512 SW 690 MB took 1.004 seconds, 687.563 MB/s Cycles per byte = 4.98
HMAC-SHA512 HW 62430 MB took 1.000 seconds,62428.497 MB/s Cycles per byte = 0.05
RSA 2048 public SW 3900 ops took 1.026 sec, avg 0.263 ms, 3801.211 ops/sec
RSA 2048 private SW 300 ops took 1.035 sec, avg 3.452 ms, 289.722 ops/sec
RSA 2048 public HW 140900 ops took 1.001 sec, avg 0.007 ms, 140825.228 ops/sec
RSA 2048 private HW 8300 ops took 1.004 sec, avg 0.121 ms, 8267.789 ops/sec
DH 2048 key gen SW 1010 ops took 1.004 sec, avg 0.994 ms, 1005.939 ops/sec
DH 2048 agree SW 1000 ops took 1.005 sec, avg 1.005 ms, 995.404 ops/sec
ECC 256 key gen SW 1090 ops took 1.001 sec, avg 0.918 ms, 1089.153 ops/sec
ECDHE 256 agree SW 1400 ops took 1.038 sec, avg 0.742 ms, 1348.211 ops/sec
ECDSA 256 sign SW 1400 ops took 1.076 sec, avg 0.769 ms, 1300.595 ops/sec
ECDSA 256 verify SW 1900 ops took 1.016 sec, avg 0.535 ms, 1870.353 ops/sec
ECDHE 256 agree HW 10500 ops took 1.001 sec, avg 0.095 ms, 10485.383 ops/sec
ECDSA 256 sign HW 22200 ops took 1.001 sec, avg 0.045 ms, 22169.233 ops/sec
ECDSA 256 verify HW 7500 ops took 1.012 sec, avg 0.135 ms, 7408.213 ops/sec
```
## Support
For questions or issues email us at support@wolfssl.com.

View File

@@ -1,3 +1,235 @@
# Cavium Octeon III CN7300
# Octeon III
Please contact wolfSSL at info@wolfssl.com to request an evaluation.
Guide for setting up wolfSSL on the Octeon III CN7300
## Octeon SDK
```sh
sudo yum install libuuid-devel
sudo yum install perl-Env
sudo rpm -i OCTEON-SDK-5.1.0-609.x86_64.rpm
```
The OCTEON-SDK package has been successfully installed under the
/usr/local/Cavium_Networks directory.
The installation requires the OCTEON_MODEL environment variable
to be set. To set this environment variable, cd to the
/usr/local/Cavium_Networks/OCTEON-SDK directory, and invoke
source env-setup <OCTEON_MODEL>
script. Valid OCTEON_MODELs are listed in octeon-models.txt file
under OCTEON-SDK directory.
You may want to copy the OCTEON-SDK package to your home directory to allow
modification without root privileges.
For more information please refer to the online SDK documentation:
file:///usr/local/Cavium_Networks/OCTEON-SDK/docs/html/index.html
```sh
sudo rpm -i OCTEON-CRYPTO-CORE-5.1.0-01.x86_64.rpm
```
The OCTEON-CRYPTO-CORE is installed under
/usr/local/Cavium_Networks/OCTEON-SDK/components/crypto-api/core directory.
This package installs the following sources.
* Crypto-Core API Sources
* Sample Crypto-Core Test Applications
Please refer to following documentation under
/usr/local/Cavium_Networks/OCTEON-SDK/components/crypto-api/core directory
* README.txt - contains build instructions and other details
* Release_Notes.txt - contains change history
```sh
sudo rpm -i OCTEON-LINUX-5.1.0-609.x86_64.rpm
```
The Linux Kernel has been successfully installed under the directory
/usr/local/Cavium_Networks/OCTEON-SDK/linux
Please refer to file:///usr/local/Cavium_Networks/OCTEON-SDK/docs/html/linux.html
on how to use Linux on the OCTEON.
Final Setup:
```sh
cp -r /usr/local/Cavium_Networks/OCTEON-SDK/ ~
cd OCTEON-SDK
source env-setup OCTEON_CN73XX
cd examples
make
```
Setup for CN73XX board EVB7304
```sh
setenv qlm2_mode pcie
setenv pcie2_mode ep
setenv pcie2_gen 2
setenv pcie2_lanes 4
setenv qlm2_mode sgmii
setenv qlm4_mode sata
#setenv ethact octeth0
#setenv ethprime octeth0
dhcp
saveenv
```
## Building bootloader
```sh
# On Host
cd OCTEON-SDK/bootloader/u-boot
make distclean
make octeon_ebb7304
make
cp *.bin /mnt/cf1
# On Target
fatls mmc 1
fatload mmc 1 $(loadaddr) u-boot-octeon_ebb7304.bin
bootloadervalidate
bootloaderupdate
```
Note: You must run `source env-setup OCTEON_CN73XX` anytime a new shell is opened to setup the build environment.
## Building Linux Kernel (Busybox)
```sh
# On Host
su root
cd OCTEON-SDK
source env-setup OCTEON_CN73XX
cd linux
make clean
cd embedded_rootfs
make menuconfig
cd ..
make kernel
make strip
cp ./kernel/linux/vmlinux.64 /mnt/cf1
```
```sh
# On Target
telnet 192.168.0.114 9761
fatls mmc 1
fatload mmc 1 $(loadaddr) vmlinux.64
bootoctlinux $(loadaddr) coremask=0xffff root=/dev/sda2 mem=0
```
Shortcut macro from U-Boot:
```sh
# On Target
setenv linux_mmc 'fatload mmc 1 $(loadaddr) vmlinux.64;bootoctlinux $(loadaddr) coremask=0xffff root=/dev/sda2 mem=0'
run linux_mmc
saveenv
```
## Building Linux Debian
```sh
su root
cd OCTEON-SDK
source env-setup OCTEON_CN73XX
cd linux
make kernel-deb
# Identify external /dev/sd*
fdisk -l
# Edit /etc/fstab. Replace "sda" with the device name determined from above.
/dev/sdb1 /mnt/cf1 auto noauto,noatime,user 0 0
/dev/sdb2 /mnt/cf2 ext3 noauto,noatime,user 0 0
mkdir -p /mnt/cf1
mkdir -p /mnt/cf2
cd debian
make DISK=/dev/sdb compact-flash
cd ..
make kernel-deb flash
usb start
fatls usb 0
fatload usb 0 $(loadaddr) vmlinux.64
fatls mmc 0
fatload mmc 0 $(loadaddr) vmlinux.64
bootoctlinux $(loadaddr) coremask=0xffff root=/dev/mmcblk0p2 mem=0 rootdelay=5
```
### Setting up default boot
```sh
setenv bootcmd 'fatload mmc 0 $(loadaddr) vmlinux.64; bootoctlinux $(loadaddr) coremask=0xffff root=/dev/mmcblk0p2 mem=0 rootdelay=5'
saveenv
reset
```
### Debian Packages
```sh
vi /etc/sources.list
deb http://archive.debian.org/debian/ jessie main contrib non-free
deb-src http://archive.debian.org/debian/ jessie main contrib non-free
#deb-src http://archive.debian.org/ jessie/updates main contrib non-free
#deb http://archive.debian.org/ jessie/updates main contrib non-free
```
## wolfSSL Building for Octeon
```sh
cd examples
ln -s ../../wolfssl wolfssl
cd wolfssl
./autogen.sh
./configure --host=mips64 CC="mips64-octeon-linux-gnu-gcc -mabi=64" \
--with-octeon-sync=../OCTEON-SDK OCTEON_OBJ=obj-octeon3 \
--enable-cryptocb --enable-des3 CPPFLAGS="-DWOLFSSL_AES_DIRECT" \
CFLAGS="-Wno-error=redundant-decls"
make
```
Installing to USB media for use on Octeon Board:
```sh
cp -r src /run/media/dgarske/OCTEON/
cp -r wolfcrypt/ /run/media/dgarske/OCTEON/
cp -r wolfssl /run/media/dgarske/OCTEON/
cp -r certs /run/media/dgarske/OCTEON/
```
## Remote Access
### UART and Telnet
EBB7304_DEFAULT D8-80-39-7D-6D-0B
telnet 192.168.0.114 9760
telnet 192.168.0.114 9761
date 070216502019
## Support
For questions please email wolfSSL at support@wolfssl.com

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,411 @@
# Intel QuickAssist Adapter Asynchronous Support
Please contact wolfSSL at info@wolfssl.com to request an evaluation.
The wolfSSL / wolfCrypt libraries support hardware crypto acceleration using the Intel QuickAssist adapter. This software has been tested using the Intel DH8970 and DH8950 QuickAssist adapters.
## Overview
Support has been added for wolfCrypt for RSA public/private (CRT/non-CRT), AES CBC/GCM, ECDH/ECDSA, DH, DES3, SHA, SHA224, SHA256, SHA384, SHA512, MD5 and HMAC. RSA padding is done via software. The wolfCrypt tests and benchmarks have asynchronous support. The wolfCrypt benchmark tool support multi-threading. The wolfSSL SSL/TLS async support has been extended to include all PKI, Encryption/Decryption and hashing/HMAC. An async hardware simulator has been added to test the asynchronous support without hardware.
The Intel QuickAssist port files are located in `wolfcrypt/src/port/intel/quickassist.c` and `wolfssl/wolfcrypt/port/intel/quickassist.h`. The QuickAssist memory handling for NUMA and normal malloc is in `wolfcrypt/src/port/intel/quickassist_mem.c`.
The asynchronous crypto files are located at `wolfcrypt/src/async.c` and `wolfssl/wolfcrypt/async.h`. These files are not in the public repository. Please contact info@wolfssl.com if interested in our asynchronous support to request an evaluation.
## Building
1. Download Driver: The latest driver for QAT can be found here: https://www.intel.com/content/www/us/en/download/19734
2. Notes:
* If you have the older driver installed you may need to remove it or unload the module and reboot.
* If you are using the QAT hardware hashing, you may need to disable the params checking, which doesn't support a last partial with 0 length source input. Code runs and works, but parameter checking will fail.
Use `./configure --disable-param-check && sudo make install`
* If you want to use legacy algorithms like RSA 1024 bit then Use `./configure --enable-legacy-algorithms`
* Recommend not using `make -j` due to synchronization issues on dependencies.
3. Setup `QAT` and `wolfssl` next to each other in the same folder.
4. Build QAT Driver
Prerequisites Ubuntu:
`sudo apt-get install libudev-dev pciutils-dev g++ pkg-config libssl-dev`
OR
Prerequisites CentOS:
`sudo yum install pciutils libudev-devel kernel-devel-$(uname -r) gcc openssl-devel`
```sh
mkdir QAT
cd QAT
tar -zxof QAT.L.4.23.0-00001.tar.gz
./configure
sudo make install
...
There is 3 QAT acceleration device(s) in the system:
qat_dev0 - type: c6xx, inst_id: 0, node_id: 1, bsf: 0000:84:00.0, #accel: 5 #engines: 10 state: up
qat_dev1 - type: c6xx, inst_id: 1, node_id: 1, bsf: 0000:85:00.0, #accel: 5 #engines: 10 state: up
qat_dev2 - type: c6xx, inst_id: 2, node_id: 1, bsf: 0000:86:00.0, #accel: 5 #engines: 10 state: up
```
```sh
$ lspci -d 8086: | grep QuickAssist
84:00.0 Co-processor: Intel Corporation C62x Chipset QuickAssist Technology (rev 04)
85:00.0 Co-processor: Intel Corporation C62x Chipset QuickAssist Technology (rev 04)
86:00.0 Co-processor: Intel Corporation C62x Chipset QuickAssist Technology (rev 04)
```
5. Build wolfSSL:
```sh
cd ../wolfssl
./configure --with-intelqa=../QAT --enable-asynccrypt
make
```
## Usage
Running wolfCrypt test and benchmark must be done with `sudo` to allow hardware access. By default the QuickAssist code uses the "SSL" process name via `QAT_PROCESS_NAME` in quickassist.h to match up to the hardware configuration.
Note: `sudo make check` will fail since default QAT configuration doesn't allow multiple concurrent processes to use hardware. You can run each of the make check scripts individually with sudo. The hardware configuration can be customized by editing the `QAT/build/dh895xcc_qa_dev0.conf` file to allow multiple processes.
Here are some build options for tuning your use:
1. `QAT_USE_POLLING_CHECK`: Enables polling check to ensure only one poll per crypto instance.
2. `WC_ASYNC_THREAD_BIND`: Enables binding of thread to crypto hardware instance.
3. `WOLFSSL_DEBUG_MEMORY_PRINT`: Enables verbose malloc/free printing. This option is used along with `WOLFSSL_DEBUG_MEMORY` and `WOLFSSL_TRACK_MEMORY`.
4. `WC_ASYNC_THRESH_NONE`: Disables the default thresholds for determining if software AES/DES3 is used. Otherwise you can define `WC_ASYNC_THRESH_AES_CBC`, `WC_ASYNC_THRESH_AES_GCM` and `WC_ASYNC_THRESH_DES3_CBC` with your own values. The defaults are AES CBC: 1024, AES GCM 128, DES3 1024. If the symmetric operation is over this size it will use QAT hardware. Otherwise software.
5. `WC_ASYNC_NO_CRYPT`: When defined with disable QAT use for AES/DES3.
6. `WC_ASYNC_NO_HASH`: When defined disables the QAT for hashing (MD5,SHA,SHA256,SHA512).
7. `WC_ASYNC_NO_RNG`: When defined disables the QAT DRBG (default for QAT v1.7)
8. `WC_NO_ASYNC_THREADING`: Disables the thread affinity code for optionally linking a thread to a specific QAT instance. To use this feature you must also define `WC_ASYNC_THREAD_BIND`.
9. `WC_ASYNC_BENCH_THREAD_COUNT`: Use specific number of threads for benchmarking.
10. `QAT_HASH_ENABLE_PARTIAL`: Enables partial hashing support, which allows sending blocks to hardware prior to final. Otherwise all hash updates are cached.
The QuickAssist v1.6 driver uses its own memory management system in `quickassist_mem.c`. This can be tuned using the following defines:
1. `USE_QAE_STATIC_MEM`: Uses a global pool for the list of allocations. This improves performance, but consumes extra up front memory. The pre-allocation size can be tuned using `QAE_USER_MEM_MAX_COUNT`.
2. `USE_QAE_THREAD_LS` : Uses thread-local-storage and removes the mutex. Can improve performance in multi-threaded environment, but does use extra memory.
For QuickAssist v1.7 or later the newer usdm memory driver is used directly.
### Recommended wolfSSL Build Options
```sh
$ ./configure --with-intelqa=../QAT --enable-asynccrypt \
--enable-aesni --enable-intelasm \
--enable-sp --enable-sp-asm \
CFLAGS="-DWC_ASYNC_NO_HASH"
```
* `--with-intelqa=../QAT`: Enables the Intel QuickAssist mode.
* `--enable-asynccrypt`: Enables asynchronous cryptography mode.
* `--enable-aesni`: Enables the Intel AES-NI assembly speedups.
* `--enable-intelasm`: Enables the Intel ASM (AVX/AVX2) speedups.
* `--enable-sp`: Enable Single Precision math to speedup standard key sizes and curves.
* `--enable-sp-asm`: Enable Single Precision assembly speedups.
* `WC_ASYNC_NO_HASH`: Disable the QAT hashing and use Intel AVX accelerated software hashing. Overhead for using QAT hashing is not yet well tuned.
### wolfCrypt Test with QAT
```
sudo ./wolfcrypt/test/testwolfcrypt
IntelQA: Instances 2
...
RSA test passed!
```
### wolfCrypt Benchmark with QAT 8970 (multi-threaded)
Multiple concurrent threads will be started based on the number of CPU's available. If you want to exclude the software benchmarks use `./configure CFLAGS="-DNO_SW_BENCH"`.
```
Intel QuickAssist DH8950 on Intel(R) Xeon(R) CPU E5-2678 v3 @ 2.50GHz:
Recommended wolfSSL build options when benchmarking.
$ ./configure --enable-sp --enable-sp-asm --enable-aesni --enable-intelasm --enable-intelrand --enable-keygen --enable-sha3 --enable-asynccrypt --with-intelqa=../QAT CFLAGS="-DWC_ASYNC_THRESH_NONE -DQAT_MAX_PENDING=40 -DWC_ASYNC_BENCH_THREAD_COUNT=2"
$ make
$ sudo ./wolfcrypt/benchmark/benchmark -rsa_sign -base10 -threads 2 -print
------------------------------------------------------------------------------
wolfSSL version 4.5.0
------------------------------------------------------------------------------
IntelQA: Instances 18
wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each)
CPUs: 2
RNG SW 79 mB took 1.030 seconds, 76.388 mB/s Cycles per byte = 32.65
RNG SW 79 mB took 1.042 seconds, 75.456 mB/s Cycles per byte = 33.05
AES-128-CBC-enc SW 729 mB took 1.006 seconds, 724.266 mB/s Cycles per byte = 3.44
AES-128-CBC-enc SW 729 mB took 1.007 seconds, 723.825 mB/s Cycles per byte = 3.45
AES-128-CBC-dec SW 5185 mB took 1.000 seconds, 5184.260 mB/s Cycles per byte = 0.48
AES-128-CBC-dec SW 5190 mB took 1.000 seconds, 5189.351 mB/s Cycles per byte = 0.48
AES-192-CBC-enc SW 608 mB took 1.003 seconds, 606.175 mB/s Cycles per byte = 4.11
AES-192-CBC-enc SW 608 mB took 1.004 seconds, 605.855 mB/s Cycles per byte = 4.12
AES-192-CBC-dec SW 4325 mB took 1.000 seconds, 4325.333 mB/s Cycles per byte = 0.58
AES-192-CBC-dec SW 4331 mB took 1.001 seconds, 4325.809 mB/s Cycles per byte = 0.58
AES-256-CBC-enc SW 524 mB took 1.005 seconds, 521.465 mB/s Cycles per byte = 4.78
AES-256-CBC-enc SW 524 mB took 1.006 seconds, 521.190 mB/s Cycles per byte = 4.79
AES-256-CBC-dec SW 3707 mB took 1.000 seconds, 3705.767 mB/s Cycles per byte = 0.67
AES-256-CBC-dec SW 3707 mB took 1.001 seconds, 3703.024 mB/s Cycles per byte = 0.67
AES-128-CBC-enc HW 2443 mB took 1.000 seconds, 2442.819 mB/s Cycles per byte = 1.02
AES-128-CBC-enc HW 2443 mB took 1.000 seconds, 2442.770 mB/s Cycles per byte = 1.02
AES-128-CBC-dec HW 2380 mB took 1.001 seconds, 2378.716 mB/s Cycles per byte = 1.05
AES-128-CBC-dec HW 2380 mB took 1.001 seconds, 2378.657 mB/s Cycles per byte = 1.05
AES-192-CBC-enc HW 2365 mB took 1.002 seconds, 2359.520 mB/s Cycles per byte = 1.06
AES-192-CBC-enc HW 2365 mB took 1.002 seconds, 2359.471 mB/s Cycles per byte = 1.06
AES-192-CBC-dec HW 2417 mB took 1.002 seconds, 2411.874 mB/s Cycles per byte = 1.03
AES-192-CBC-dec HW 2417 mB took 1.002 seconds, 2411.831 mB/s Cycles per byte = 1.03
AES-256-CBC-enc HW 2223 mB took 1.001 seconds, 2221.082 mB/s Cycles per byte = 1.12
AES-256-CBC-enc HW 2218 mB took 1.001 seconds, 2215.793 mB/s Cycles per byte = 1.13
AES-256-CBC-dec HW 2113 mB took 1.002 seconds, 2108.506 mB/s Cycles per byte = 1.18
AES-256-CBC-dec HW 2113 mB took 1.002 seconds, 2108.354 mB/s Cycles per byte = 1.18
AES-128-GCM-enc SW 1919 mB took 1.001 seconds, 1916.366 mB/s Cycles per byte = 1.30
AES-128-GCM-enc SW 2595 mB took 1.001 seconds, 2591.465 mB/s Cycles per byte = 0.96
AES-128-GCM-dec SW 2611 mB took 1.000 seconds, 2610.093 mB/s Cycles per byte = 0.96
AES-128-GCM-dec SW 2218 mB took 1.002 seconds, 2213.073 mB/s Cycles per byte = 1.13
AES-192-GCM-enc SW 2317 mB took 1.001 seconds, 2315.896 mB/s Cycles per byte = 1.08
AES-192-GCM-enc SW 2286 mB took 1.002 seconds, 2281.953 mB/s Cycles per byte = 1.09
AES-192-GCM-dec SW 2207 mB took 1.001 seconds, 2206.098 mB/s Cycles per byte = 1.13
AES-192-GCM-dec SW 1589 mB took 1.002 seconds, 1586.020 mB/s Cycles per byte = 1.57
AES-256-GCM-enc SW 2071 mB took 1.001 seconds, 2069.342 mB/s Cycles per byte = 1.21
AES-256-GCM-enc SW 2108 mB took 1.002 seconds, 2103.268 mB/s Cycles per byte = 1.19
AES-256-GCM-dec SW 2108 mB took 1.001 seconds, 2105.715 mB/s Cycles per byte = 1.18
AES-256-GCM-dec SW 2108 mB took 1.002 seconds, 2103.563 mB/s Cycles per byte = 1.19
AES-128-GCM-enc HW 2427 mB took 1.002 seconds, 2422.522 mB/s Cycles per byte = 1.03
AES-128-GCM-enc HW 2433 mB took 1.002 seconds, 2427.722 mB/s Cycles per byte = 1.03
AES-128-GCM-dec HW 1861 mB took 1.001 seconds, 1860.039 mB/s Cycles per byte = 1.34
AES-128-GCM-dec HW 1861 mB took 1.001 seconds, 1860.019 mB/s Cycles per byte = 1.34
AES-192-GCM-enc HW 2380 mB took 1.000 seconds, 2379.218 mB/s Cycles per byte = 1.05
AES-192-GCM-enc HW 2386 mB took 1.000 seconds, 2384.418 mB/s Cycles per byte = 1.05
AES-192-GCM-dec HW 1971 mB took 1.002 seconds, 1966.480 mB/s Cycles per byte = 1.27
AES-192-GCM-dec HW 1971 mB took 1.002 seconds, 1966.458 mB/s Cycles per byte = 1.27
AES-256-GCM-enc HW 2254 mB took 1.002 seconds, 2249.535 mB/s Cycles per byte = 1.11
AES-256-GCM-enc HW 2254 mB took 1.002 seconds, 2249.487 mB/s Cycles per byte = 1.11
AES-256-GCM-dec HW 1746 mB took 1.001 seconds, 1744.049 mB/s Cycles per byte = 1.43
AES-256-GCM-dec HW 1746 mB took 1.001 seconds, 1744.018 mB/s Cycles per byte = 1.43
CHACHA SW 1478 mB took 1.000 seconds, 1478.220 mB/s Cycles per byte = 1.69
CHACHA SW 1347 mB took 1.003 seconds, 1342.833 mB/s Cycles per byte = 1.86
CHA-POLY SW 949 mB took 1.002 seconds, 946.915 mB/s Cycles per byte = 2.63
CHA-POLY SW 949 mB took 1.005 seconds, 944.670 mB/s Cycles per byte = 2.64
MD5 SW 603 mB took 1.003 seconds, 601.383 mB/s Cycles per byte = 4.15
MD5 SW 613 mB took 1.005 seconds, 610.413 mB/s Cycles per byte = 4.09
MD5 HW 409 mB took 1.002 seconds, 408.088 mB/s Cycles per byte = 6.11
MD5 HW 409 mB took 1.003 seconds, 407.845 mB/s Cycles per byte = 6.12
POLY1305 SW 2621 mB took 1.000 seconds, 2620.709 mB/s Cycles per byte = 0.95
POLY1305 SW 2616 mB took 1.001 seconds, 2613.824 mB/s Cycles per byte = 0.95
SHA SW 377 mB took 1.003 seconds, 376.342 mB/s Cycles per byte = 6.63
SHA SW 383 mB took 1.011 seconds, 378.592 mB/s Cycles per byte = 6.59
SHA HW 535 mB took 1.005 seconds, 531.941 mB/s Cycles per byte = 4.69
SHA HW 535 mB took 1.006 seconds, 531.644 mB/s Cycles per byte = 4.69
SHA-224 SW 351 mB took 1.010 seconds, 347.715 mB/s Cycles per byte = 7.17
SHA-224 SW 351 mB took 1.014 seconds, 346.285 mB/s Cycles per byte = 7.20
SHA-224 HW 414 mB took 1.012 seconds, 409.434 mB/s Cycles per byte = 6.09
SHA-224 HW 419 mB took 1.012 seconds, 414.387 mB/s Cycles per byte = 6.02
SHA-256 SW 351 mB took 1.011 seconds, 347.292 mB/s Cycles per byte = 7.18
SHA-256 SW 315 mB took 1.013 seconds, 310.424 mB/s Cycles per byte = 8.03
SHA-256 HW 419 mB took 1.004 seconds, 417.688 mB/s Cycles per byte = 5.97
SHA-256 HW 419 mB took 1.005 seconds, 417.427 mB/s Cycles per byte = 5.98
SHA-384 SW 530 mB took 1.001 seconds, 529.040 mB/s Cycles per byte = 4.71
SHA-384 SW 530 mB took 1.003 seconds, 528.139 mB/s Cycles per byte = 4.72
SHA-384 HW 357 mB took 1.001 seconds, 356.156 mB/s Cycles per byte = 7.00
SHA-384 HW 367 mB took 1.010 seconds, 363.498 mB/s Cycles per byte = 6.86
SHA-512 SW 530 mB took 1.002 seconds, 528.589 mB/s Cycles per byte = 4.72
SHA-512 SW 446 mB took 1.009 seconds, 441.540 mB/s Cycles per byte = 5.65
SHA-512 HW 367 mB took 1.004 seconds, 365.434 mB/s Cycles per byte = 6.83
SHA-512 HW 367 mB took 1.005 seconds, 365.224 mB/s Cycles per byte = 6.83
SHA3-224 SW 236 mB took 1.014 seconds, 232.784 mB/s Cycles per byte = 10.71
SHA3-224 SW 236 mB took 1.018 seconds, 231.794 mB/s Cycles per byte = 10.76
SHA3-224 HW 220 mB took 1.006 seconds, 218.860 mB/s Cycles per byte = 11.40
SHA3-224 HW 236 mB took 1.015 seconds, 232.538 mB/s Cycles per byte = 10.73
SHA3-256 SW 163 mB took 1.000 seconds, 162.463 mB/s Cycles per byte = 15.35
SHA3-256 SW 225 mB took 1.023 seconds, 220.278 mB/s Cycles per byte = 11.32
SHA3-256 HW 692 mB took 1.004 seconds, 689.291 mB/s Cycles per byte = 3.62
SHA3-256 HW 692 mB took 1.007 seconds, 687.092 mB/s Cycles per byte = 3.63
SHA3-384 SW 173 mB took 1.022 seconds, 169.214 mB/s Cycles per byte = 14.74
SHA3-384 SW 173 mB took 1.024 seconds, 168.878 mB/s Cycles per byte = 14.77
SHA3-384 HW 173 mB took 1.023 seconds, 169.202 mB/s Cycles per byte = 14.74
SHA3-384 HW 173 mB took 1.024 seconds, 168.948 mB/s Cycles per byte = 14.76
SHA3-512 SW 121 mB took 1.026 seconds, 117.548 mB/s Cycles per byte = 21.22
SHA3-512 SW 121 mB took 1.027 seconds, 117.375 mB/s Cycles per byte = 21.25
SHA3-512 HW 121 mB took 1.026 seconds, 117.585 mB/s Cycles per byte = 21.21
SHA3-512 HW 121 mB took 1.028 seconds, 117.335 mB/s Cycles per byte = 21.26
HMAC-MD5 SW 608 mB took 1.000 seconds, 608.096 mB/s Cycles per byte = 4.10
HMAC-MD5 SW 613 mB took 1.004 seconds, 611.102 mB/s Cycles per byte = 4.08
HMAC-MD5 HW 414 mB took 1.001 seconds, 413.762 mB/s Cycles per byte = 6.03
HMAC-MD5 HW 414 mB took 1.004 seconds, 412.554 mB/s Cycles per byte = 6.05
HMAC-SHA SW 383 mB took 1.011 seconds, 378.446 mB/s Cycles per byte = 6.59
HMAC-SHA SW 383 mB took 1.013 seconds, 377.729 mB/s Cycles per byte = 6.60
HMAC-SHA HW 535 mB took 1.008 seconds, 530.760 mB/s Cycles per byte = 4.70
HMAC-SHA HW 514 mB took 1.009 seconds, 509.292 mB/s Cycles per byte = 4.90
HMAC-SHA224 SW 267 mB took 1.008 seconds, 265.316 mB/s Cycles per byte = 9.40
HMAC-SHA224 SW 351 mB took 1.012 seconds, 346.982 mB/s Cycles per byte = 7.19
HMAC-SHA224 HW 404 mB took 1.003 seconds, 402.579 mB/s Cycles per byte = 6.20
HMAC-SHA224 HW 393 mB took 1.011 seconds, 388.951 mB/s Cycles per byte = 6.41
HMAC-SHA256 SW 294 mB took 1.007 seconds, 291.426 mB/s Cycles per byte = 8.56
HMAC-SHA256 SW 351 mB took 1.012 seconds, 347.205 mB/s Cycles per byte = 7.18
HMAC-SHA256 HW 419 mB took 1.004 seconds, 417.677 mB/s Cycles per byte = 5.97
HMAC-SHA256 HW 419 mB took 1.009 seconds, 415.514 mB/s Cycles per byte = 6.00
HMAC-SHA384 SW 530 mB took 1.002 seconds, 528.479 mB/s Cycles per byte = 4.72
HMAC-SHA384 SW 530 mB took 1.007 seconds, 526.093 mB/s Cycles per byte = 4.74
HMAC-SHA384 HW 367 mB took 1.004 seconds, 365.498 mB/s Cycles per byte = 6.82
HMAC-SHA384 HW 367 mB took 1.006 seconds, 364.878 mB/s Cycles per byte = 6.84
HMAC-SHA512 SW 530 mB took 1.002 seconds, 528.616 mB/s Cycles per byte = 4.72
HMAC-SHA512 SW 530 mB took 1.006 seconds, 526.513 mB/s Cycles per byte = 4.74
HMAC-SHA512 HW 367 mB took 1.003 seconds, 365.816 mB/s Cycles per byte = 6.82
HMAC-SHA512 HW 367 mB took 1.007 seconds, 364.560 mB/s Cycles per byte = 6.84
RSA 1024 key gen SW 40 ops took 1.191 sec, avg 29.780 ms, 33.580 ops/sec
RSA 1024 key gen SW 40 ops took 1.428 sec, avg 35.694 ms, 28.016 ops/sec
RSA 2048 key gen SW 40 ops took 4.154 sec, avg 103.853 ms, 9.629 ops/sec
RSA 2048 key gen SW 40 ops took 5.687 sec, avg 142.172 ms, 7.034 ops/sec
RSA 1024 key gen HW 120 ops took 1.064 sec, avg 8.866 ms, 112.790 ops/sec
RSA 1024 key gen HW 120 ops took 1.072 sec, avg 8.932 ms, 111.953 ops/sec
RSA 2048 key gen HW 40 ops took 1.389 sec, avg 34.717 ms, 28.804 ops/sec
RSA 2048 key gen HW 40 ops took 1.437 sec, avg 35.935 ms, 27.828 ops/sec
RSA 2048 sign SW 1000 ops took 1.046 sec, avg 1.046 ms, 956.197 ops/sec
RSA 2048 sign SW 1000 ops took 1.052 sec, avg 1.052 ms, 950.320 ops/sec
RSA 2048 verify SW 32300 ops took 1.001 sec, avg 0.031 ms, 32271.670 ops/sec
RSA 2048 verify SW 32200 ops took 1.003 sec, avg 0.031 ms, 32117.110 ops/sec
RSA 2048 sign HW 12300 ops took 1.001 sec, avg 0.081 ms, 12288.056 ops/sec
RSA 2048 sign HW 19600 ops took 1.003 sec, avg 0.051 ms, 19537.967 ops/sec
RSA 2048 verify HW 116000 ops took 1.000 sec, avg 0.009 ms, 115971.935 ops/sec
RSA 2048 verify HW 118000 ops took 1.000 sec, avg 0.008 ms, 117962.707 ops/sec
DH 2048 key gen SW 2080 ops took 1.000 sec, avg 0.481 ms, 2079.830 ops/sec
DH 2048 key gen SW 2120 ops took 1.016 sec, avg 0.479 ms, 2086.548 ops/sec
DH 2048 agree SW 2100 ops took 1.023 sec, avg 0.487 ms, 2053.478 ops/sec
DH 2048 agree SW 2100 ops took 1.026 sec, avg 0.489 ms, 2046.644 ops/sec
DH 2048 key gen HW 43720 ops took 1.000 sec, avg 0.023 ms, 43712.257 ops/sec
DH 2048 key gen HW 43320 ops took 1.000 sec, avg 0.023 ms, 43299.560 ops/sec
DH 2048 agree HW 32500 ops took 1.001 sec, avg 0.031 ms, 32471.874 ops/sec
DH 2048 agree HW 39400 ops took 1.001 sec, avg 0.025 ms, 39351.757 ops/sec
ECC 256 key gen SW 41320 ops took 1.001 sec, avg 0.024 ms, 41298.692 ops/sec
ECC 256 key gen SW 41280 ops took 1.001 sec, avg 0.024 ms, 41258.674 ops/sec
ECC 256 key gen HW 41320 ops took 1.000 sec, avg 0.024 ms, 41309.127 ops/sec
ECC 256 key gen HW 41280 ops took 1.001 sec, avg 0.024 ms, 41244.118 ops/sec
ECDHE 256 agree SW 13400 ops took 1.005 sec, avg 0.075 ms, 13328.731 ops/sec
ECDHE 256 agree SW 13300 ops took 1.006 sec, avg 0.076 ms, 13221.465 ops/sec
ECDSA 256 sign SW 29900 ops took 1.002 sec, avg 0.034 ms, 29841.744 ops/sec
ECDSA 256 sign SW 30000 ops took 1.003 sec, avg 0.033 ms, 29910.091 ops/sec
ECDSA 256 verify SW 10700 ops took 1.006 sec, avg 0.094 ms, 10641.471 ops/sec
ECDSA 256 verify SW 10700 ops took 1.009 sec, avg 0.094 ms, 10604.105 ops/sec
ECDHE 256 agree HW 26600 ops took 1.000 sec, avg 0.038 ms, 26594.522 ops/sec
ECDHE 256 agree HW 19000 ops took 1.002 sec, avg 0.053 ms, 18964.479 ops/sec
ECDSA 256 sign HW 22300 ops took 1.001 sec, avg 0.045 ms, 22286.137 ops/sec
ECDSA 256 sign HW 22000 ops took 1.002 sec, avg 0.046 ms, 21963.146 ops/sec
ECDSA 256 verify HW 12600 ops took 1.002 sec, avg 0.080 ms, 12569.531 ops/sec
ECDSA 256 verify HW 12600 ops took 1.005 sec, avg 0.080 ms, 12542.829 ops/sec
Benchmark complete
RNG SW 151.844 mB/s
AES-128-CBC-enc SW 1448.090 mB/s
AES-128-CBC-dec SW 10373.612 mB/s
AES-192-CBC-enc SW 1212.030 mB/s
AES-192-CBC-dec SW 8651.141 mB/s
AES-256-CBC-enc SW 1042.655 mB/s
AES-256-CBC-dec SW 7408.791 mB/s
AES-128-CBC-enc HW 4885.588 mB/s
AES-128-CBC-dec HW 4757.373 mB/s
AES-192-CBC-enc HW 4718.991 mB/s
AES-192-CBC-dec HW 4823.705 mB/s
AES-256-CBC-enc HW 4436.875 mB/s
AES-256-CBC-dec HW 4216.860 mB/s
AES-128-GCM-enc SW 4507.831 mB/s
AES-128-GCM-dec SW 4823.166 mB/s
AES-192-GCM-enc SW 4597.849 mB/s
AES-192-GCM-dec SW 3792.119 mB/s
AES-256-GCM-enc SW 4172.610 mB/s
AES-256-GCM-dec SW 4209.278 mB/s
AES-128-GCM-enc HW 4850.244 mB/s
AES-128-GCM-dec HW 3720.058 mB/s
AES-192-GCM-enc HW 4763.636 mB/s
AES-192-GCM-dec HW 3932.937 mB/s
AES-256-GCM-enc HW 4499.022 mB/s
AES-256-GCM-dec HW 3488.068 mB/s
CHACHA SW 2821.053 mB/s
CHA-POLY SW 1891.585 mB/s
MD5 SW 1211.796 mB/s
MD5 HW 815.933 mB/s
POLY1305 SW 5234.533 mB/s
SHA SW 754.934 mB/s
SHA HW 1063.586 mB/s
SHA-224 SW 694.001 mB/s
SHA-224 HW 823.821 mB/s
SHA-256 SW 657.716 mB/s
SHA-256 HW 835.115 mB/s
SHA-384 SW 1057.178 mB/s
SHA-384 HW 719.655 mB/s
SHA-512 SW 970.129 mB/s
SHA-512 HW 730.657 mB/s
SHA3-224 SW 464.579 mB/s
SHA3-224 HW 451.398 mB/s
SHA3-256 SW 382.741 mB/s
SHA3-256 HW 1376.382 mB/s
SHA3-384 SW 338.092 mB/s
SHA3-384 HW 338.150 mB/s
SHA3-512 SW 234.923 mB/s
SHA3-512 HW 234.921 mB/s
HMAC-MD5 SW 1219.198 mB/s
HMAC-MD5 HW 826.316 mB/s
HMAC-SHA SW 756.175 mB/s
HMAC-SHA HW 1040.052 mB/s
HMAC-SHA224 SW 612.297 mB/s
HMAC-SHA224 HW 791.530 mB/s
HMAC-SHA256 SW 638.631 mB/s
HMAC-SHA256 HW 833.191 mB/s
HMAC-SHA384 SW 1054.571 mB/s
HMAC-SHA384 HW 730.376 mB/s
HMAC-SHA512 SW 1055.130 mB/s
HMAC-SHA512 HW 730.377 mB/s
RSA 1024 key gen SW 61.596 ops/sec
RSA 2048 key gen SW 16.663 ops/sec
RSA 1024 key gen HW 224.743 ops/sec
RSA 2048 key gen HW 56.632 ops/sec
RSA 2048 sign SW 1906.517 ops/sec
RSA 2048 verify SW 64388.780 ops/sec
RSA 2048 sign HW 31826.022 ops/sec
RSA 2048 verify HW 233934.642 ops/sec
DH 2048 key gen SW 4166.378 ops/sec
DH 2048 agree SW 4100.122 ops/sec
DH 2048 key gen HW 87011.816 ops/sec
DH 2048 agree HW 71823.630 ops/sec
ECC 256 key gen SW 82557.366 ops/sec
ECC 256 key gen HW 82553.245 ops/sec
ECDHE 256 agree SW 26550.196 ops/sec
ECDSA 256 sign SW 59751.835 ops/sec
ECDSA 256 verify SW 21245.576 ops/sec
ECDHE 256 agree HW 45559.001 ops/sec
ECDSA 256 sign HW 44249.283 ops/sec
ECDSA 256 verify HW 25112.360 ops/sec
IntelQA: Stop
```
### wolfCrypt Benchmark with QAT (single-threaded)
To use the benchmark tool against hardware in single threaded mode build the library with `CFLAGS="-DWC_NO_ASYNC_THREADING"`.
```
sudo ./wolfcrypt/benchmark/benchmark -rsa_sign -dh -ecc
IntelQA: Instances 2
wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each)
RSA 2048 public HW 161000 ops took 1.000 sec, avg 0.006 ms, 160989.829 ops/sec
RSA 2048 private HW 18600 ops took 1.002 sec, avg 0.054 ms, 18566.416 ops/sec
DH 2048 key gen HW 48945 ops took 1.000 sec, avg 0.020 ms, 48931.782 ops/sec
DH 2048 agree HW 43300 ops took 1.001 sec, avg 0.023 ms, 43248.876 ops/sec
ECDHE 256 agree HW 26400 ops took 1.001 sec, avg 0.038 ms, 26382.639 ops/sec
ECDSA 256 sign HW 23900 ops took 1.004 sec, avg 0.042 ms, 23810.849 ops/sec
ECDSA 256 verify HW 13800 ops took 1.000 sec, avg 0.072 ms, 13799.878 ops/sec
IntelQA: Stop
```
### wolfSSL Asynchronous Test Mode
Enable asynccrypt alone to use async simulator.
`./configure --enable-asynccrypt`
## Debugging
To enable debug messages:
`./configure --enable-asynccrypt --with-intelqa=../QAT --enable-debug --disable-shared CFLAGS="-DQAT_DEBUG" && make`
## Support
For questions or issues email us at support@wolfssl.com.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

442
wolfssl/wolfcrypt/async.h Normal file
View File

@@ -0,0 +1,442 @@
/* async.h
*
* Copyright (C) 2006-2023 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WOLFSSL_ASYNC_H
#define WOLFSSL_ASYNC_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WOLFSSL_ASYNC_CRYPT
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/wolfevent.h>
#ifdef HAVE_CAVIUM
#include <wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h>
#elif defined(HAVE_INTEL_QA)
#include <wolfssl/wolfcrypt/port/intel/quickassist.h>
#endif
struct WC_ASYNC_DEV;
/* Asynchronous crypto using software */
#ifdef WOLFSSL_ASYNC_CRYPT_SW
enum WC_ASYNC_SW_TYPE {
ASYNC_SW_NONE = 0,
#ifdef HAVE_ECC
ASYNC_SW_ECC_MAKE = 1,
#ifdef HAVE_ECC_SIGN
ASYNC_SW_ECC_SIGN = 2,
#endif
#ifdef HAVE_ECC_VERIFY
ASYNC_SW_ECC_VERIFY = 3,
#endif
#ifdef HAVE_ECC_DHE
ASYNC_SW_ECC_SHARED_SEC = 4,
#endif
#endif /* HAVE_ECC */
#ifndef NO_RSA
#ifdef WOLFSSL_KEY_GEN
ASYNC_SW_RSA_MAKE = 5,
#endif
ASYNC_SW_RSA_FUNC = 6,
#endif /* !NO_RSA */
#ifndef NO_DH
ASYNC_SW_DH_AGREE = 7,
ASYNC_SW_DH_GEN = 8,
#endif /* !NO_DH */
#ifndef NO_AES
ASYNC_SW_AES_CBC_ENCRYPT = 9,
#ifdef HAVE_AES_DECRYPT
ASYNC_SW_AES_CBC_DECRYPT = 10,
#endif
#ifdef HAVE_AESGCM
ASYNC_SW_AES_GCM_ENCRYPT = 11,
#ifdef HAVE_AES_DECRYPT
ASYNC_SW_AES_GCM_DECRYPT = 12,
#endif
#endif /* HAVE_AESGCM */
#endif /* !NO_AES */
#ifndef NO_DES3
ASYNC_SW_DES3_CBC_ENCRYPT = 13,
ASYNC_SW_DES3_CBC_DECRYPT = 14,
#endif /* !NO_DES3 */
};
#ifdef HAVE_ECC
struct AsyncCryptSwEccMake {
void* rng; /* WC_RNG */
void* key; /* ecc_key */
int curve_id;
int size;
};
struct AsyncCryptSwEccSign {
const byte* in;
word32 inSz;
void* rng; /* WC_RNG */
void* key; /* ecc_key */
void* r; /* mp_int */
void* s; /* mp_int */
};
struct AsyncCryptSwEccVerify {
void* r; /* mp_int */
void* s; /* mp_int */
const byte* hash;
word32 hashlen;
int* stat;
void* key; /* ecc_key */
};
struct AsyncCryptSwEccSharedSec {
void* private_key; /* ecc_key */
void* public_point; /* ecc_point */
byte* out;
word32* outLen;
};
#endif /* HAVE_ECC */
#ifndef NO_RSA
#ifdef WOLFSSL_KEY_GEN
struct AsyncCryptSwRsaMake {
void* key; /* RsaKey */
void* rng;
long e;
int size;
};
#endif
struct AsyncCryptSwRsaFunc {
const byte* in;
word32 inSz;
byte* out;
word32* outSz;
int type;
void* key; /* RsaKey */
void* rng;
};
#endif /* !NO_RSA */
#ifndef NO_DH
struct AsyncCryptSwDhAgree {
void* key; /* DhKey */
byte* agree;
word32* agreeSz;
const byte* priv;
word32 privSz;
const byte* otherPub;
word32 pubSz;
};
struct AsyncCryptSwDhGen {
void* key; /* DhKey */
void* rng; /* WC_RNG */
byte* priv;
word32* privSz;
byte* pub;
word32* pubSz;
};
#endif /* !NO_DH */
#ifndef NO_AES
struct AsyncCryptSwAes {
void* aes; /* Aes */
byte* out;
const byte* in;
word32 sz;
#ifdef HAVE_AESGCM
const byte* iv;
word32 ivSz;
byte* authTag;
word32 authTagSz;
const byte* authIn;
word32 authInSz;
#endif
};
#endif /* !NO_AES */
#ifndef NO_DES3
struct AsyncCryptSwDes {
void* des; /* Des */
byte* out;
const byte* in;
word32 sz;
};
#endif /* !NO_DES3 */
#ifdef __CC_ARM
#pragma push
#pragma anon_unions
#endif
typedef struct WC_ASYNC_SW {
void* ctx;
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
union {
#endif
#ifdef HAVE_ECC
struct AsyncCryptSwEccMake eccMake;
struct AsyncCryptSwEccSign eccSign;
struct AsyncCryptSwEccVerify eccVerify;
struct AsyncCryptSwEccSharedSec eccSharedSec;
#endif /* HAVE_ECC */
#ifndef NO_RSA
#ifdef WOLFSSL_KEY_GEN
struct AsyncCryptSwRsaMake rsaMake;
#endif
struct AsyncCryptSwRsaFunc rsaFunc;
#endif /* !NO_RSA */
#ifndef NO_DH
struct AsyncCryptSwDhAgree dhAgree;
struct AsyncCryptSwDhGen dhGen;
#endif /* !NO_DH */
#ifndef NO_AES
struct AsyncCryptSwAes aes;
#endif /* !NO_AES */
#ifndef NO_DES3
struct AsyncCryptSwDes des;
#endif /* !NO_DES3 */
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
}; /* union */
#endif
byte type; /* enum WC_ASYNC_SW_TYPE */
} WC_ASYNC_SW;
#ifdef __CC_ARM
#pragma pop
#endif
#endif /* WOLFSSL_ASYNC_CRYPT_SW */
/* Performance tuning options */
/* determine maximum async pending requests */
#ifdef HAVE_CAVIUM
#define WOLF_ASYNC_MAX_PENDING CAVIUM_MAX_PENDING
#elif defined(HAVE_INTEL_QA)
#define WOLF_ASYNC_MAX_PENDING QAT_MAX_PENDING
#else
#define WOLF_ASYNC_MAX_PENDING 8
#ifdef DEBUG_WOLFSSL
/* Use this to introduce extra delay in simulator at interval */
#ifndef WOLF_ASYNC_SW_SKIP_MOD
#define WOLF_ASYNC_SW_SKIP_MOD (WOLF_ASYNC_MAX_PENDING / 2)
#endif
#endif
#endif
/* async thresholds - defaults */
#ifdef WC_ASYNC_THRESH_NONE
#undef WC_ASYNC_THRESH_AES_CBC
#define WC_ASYNC_THRESH_AES_CBC 1
#undef WC_ASYNC_THRESH_AES_GCM
#define WC_ASYNC_THRESH_AES_GCM 1
#undef WC_ASYNC_THRESH_DES3_CBC
#define WC_ASYNC_THRESH_DES3_CBC 1
#else
#ifndef WC_ASYNC_THRESH_AES_CBC
#define WC_ASYNC_THRESH_AES_CBC 1024
#endif
#ifndef WC_ASYNC_THRESH_AES_GCM
#define WC_ASYNC_THRESH_AES_GCM 128
#endif
#ifndef WC_ASYNC_THRESH_DES3_CBC
#define WC_ASYNC_THRESH_DES3_CBC 1024
#endif
#endif /* WC_ASYNC_THRESH_NONE */
/* Overrides to allow disabling async support per algorithm */
#ifndef WC_ASYNC_NO_CRYPT
#ifndef WC_ASYNC_NO_ARC4
#define WC_ASYNC_ENABLE_ARC4
#endif
#ifndef WC_ASYNC_NO_AES
#define WC_ASYNC_ENABLE_AES
#endif
#ifndef WC_ASYNC_NO_3DES
#define WC_ASYNC_ENABLE_3DES
#endif
#endif /* WC_ASYNC_NO_CRYPT */
#ifndef WC_ASYNC_NO_PKI
#ifndef WC_ASYNC_NO_RSA_KEYGEN
#define WC_ASYNC_ENABLE_RSA_KEYGEN
#endif
#ifndef WC_ASYNC_NO_RSA
#define WC_ASYNC_ENABLE_RSA
#endif
#ifndef WC_ASYNC_NO_ECC
#define WC_ASYNC_ENABLE_ECC
#endif
#ifndef WC_ASYNC_NO_DH
#define WC_ASYNC_ENABLE_DH
#endif
#endif /* WC_ASYNC_NO_PKI */
#ifndef WC_ASYNC_NO_HASH
#ifndef WC_ASYNC_NO_SHA512
#define WC_ASYNC_ENABLE_SHA512
#endif
#ifndef WC_ASYNC_NO_SHA384
#define WC_ASYNC_ENABLE_SHA384
#endif
#ifndef WC_ASYNC_NO_SHA256
#define WC_ASYNC_ENABLE_SHA256
#endif
#ifndef WC_ASYNC_NO_SHA224
#define WC_ASYNC_ENABLE_SHA224
#endif
#ifndef WC_ASYNC_NO_SHA
#define WC_ASYNC_ENABLE_SHA
#endif
#ifndef WC_ASYNC_NO_MD5
#define WC_ASYNC_ENABLE_MD5
#endif
#ifndef WC_ASYNC_NO_HMAC
#define WC_ASYNC_ENABLE_HMAC
#endif
#ifndef WC_ASYNC_NO_SHA3
#define WC_ASYNC_ENABLE_SHA3
#endif
#endif /* WC_ASYNC_NO_HASH */
#ifndef WC_ASYNC_NO_RNG
#define WC_ASYNC_ENABLE_RNG
#endif
/* async marker values */
#define WOLFSSL_ASYNC_MARKER_INVALID 0x0
#define WOLFSSL_ASYNC_MARKER_ARC4 0xBEEF0001
#define WOLFSSL_ASYNC_MARKER_AES 0xBEEF0002
#define WOLFSSL_ASYNC_MARKER_3DES 0xBEEF0003
#define WOLFSSL_ASYNC_MARKER_RNG 0xBEEF0004
#define WOLFSSL_ASYNC_MARKER_HMAC 0xBEEF0005
#define WOLFSSL_ASYNC_MARKER_RSA 0xBEEF0006
#define WOLFSSL_ASYNC_MARKER_ECC 0xBEEF0007
#define WOLFSSL_ASYNC_MARKER_SHA512 0xBEEF0008
#define WOLFSSL_ASYNC_MARKER_SHA384 0xBEEF0009
#define WOLFSSL_ASYNC_MARKER_SHA256 0xBEEF000A
#define WOLFSSL_ASYNC_MARKER_SHA224 0xBEEF000B
#define WOLFSSL_ASYNC_MARKER_SHA 0xBEEF000C
#define WOLFSSL_ASYNC_MARKER_MD5 0xBEEF000D
#define WOLFSSL_ASYNC_MARKER_DH 0xBEEF000E
#define WOLFSSL_ASYNC_MARKER_SHA3 0xBEEF000F
/* event flags (bit mask) */
enum WC_ASYNC_FLAGS {
WC_ASYNC_FLAG_NONE = 0x00000000,
/* crypto needs called again after WC_PENDING_E */
WC_ASYNC_FLAG_CALL_AGAIN = 0x00000001,
};
/* async device */
typedef struct WC_ASYNC_DEV {
word32 marker; /* async marker */
void* heap;
/* event */
WOLF_EVENT event;
/* context for driver */
#ifdef HAVE_CAVIUM
CaviumNitroxDev nitrox;
#elif defined(HAVE_INTEL_QA)
IntelQaDev qat;
#elif defined(WOLFSSL_ASYNC_CRYPT_SW)
WC_ASYNC_SW sw;
#endif
} WC_ASYNC_DEV;
/* Interfaces */
WOLFSSL_API int wolfAsync_HardwareStart(void);
WOLFSSL_API void wolfAsync_HardwareStop(void);
WOLFSSL_API int wolfAsync_DevOpen(int *devId);
WOLFSSL_API int wolfAsync_DevOpenThread(int *devId, void* threadId);
WOLFSSL_API int wolfAsync_DevCtxInit(WC_ASYNC_DEV* asyncDev, word32 marker,
void* heap, int devId);
WOLFSSL_API void wolfAsync_DevCtxFree(WC_ASYNC_DEV* asyncDev, word32 marker);
WOLFSSL_API void wolfAsync_DevClose(int *devId);
WOLFSSL_API int wolfAsync_DevCopy(WC_ASYNC_DEV* src, WC_ASYNC_DEV* dst);
WOLFSSL_API int wolfAsync_EventInit(WOLF_EVENT* event,
enum WOLF_EVENT_TYPE type, void* context, word32 flags);
WOLFSSL_API int wolfAsync_EventWait(WOLF_EVENT* event);
WOLFSSL_API int wolfAsync_EventPoll(WOLF_EVENT* event,
WOLF_EVENT_FLAG event_flags);
WOLFSSL_API int wolfAsync_EventPop(WOLF_EVENT* event,
enum WOLF_EVENT_TYPE event_type);
WOLFSSL_API int wolfAsync_EventQueuePush(WOLF_EVENT_QUEUE* queue,
WOLF_EVENT* event);
WOLFSSL_API int wolfAsync_EventQueuePoll(WOLF_EVENT_QUEUE* queue,
void* context_filter, WOLF_EVENT** events, int maxEvents,
WOLF_EVENT_FLAG event_flags, int* eventCount);
WOLFSSL_API int wc_AsyncHandle(WC_ASYNC_DEV* asyncDev,
WOLF_EVENT_QUEUE* queue, word32 flags);
WOLFSSL_API int wc_AsyncWait(int ret, WC_ASYNC_DEV* asyncDev,
word32 flags);
WOLFSSL_API int wc_AsyncSleep(word32 ms);
#ifdef WOLFSSL_ASYNC_CRYPT_SW
WOLFSSL_API int wc_AsyncSwInit(WC_ASYNC_DEV* dev, int type);
#endif
/* Pthread Helpers */
#ifndef WC_NO_ASYNC_THREADING
#include <stdio.h>
#include <pthread.h>
#include <errno.h>
#include <sched.h>
#include <unistd.h>
typedef void* (*AsyncThreadFunc_t) (void *);
#define THREAD_DEFAULT_PRIORITY (0)
#define THREAD_DEFAULT_POLICY SCHED_OTHER
WOLFSSL_API int wc_AsyncGetNumberOfCpus(void);
WOLFSSL_API int wc_AsyncThreadCreate(pthread_t *thread,
AsyncThreadFunc_t function, void* params);
WOLFSSL_API int wc_AsyncThreadCreate_ex(pthread_t *thread,
word32 priority, int policy,
AsyncThreadFunc_t function, void* params);
WOLFSSL_API int wc_AsyncThreadBind(pthread_t *thread, word32 logicalCore);
WOLFSSL_API int wc_AsyncThreadStart(pthread_t *thread);
WOLFSSL_API void wc_AsyncThreadExit(void *retval);
WOLFSSL_API int wc_AsyncThreadKill(pthread_t *thread);
WOLFSSL_API int wc_AsyncThreadPrioritySet(pthread_t *thread, word32 priority);
WOLFSSL_API int wc_AsyncThreadSetPolicyAndPriority(pthread_t *thread,
word32 policy, word32 priority);
WOLFSSL_API int wc_AsyncThreadJoin(pthread_t *thread);
WOLFSSL_API void wc_AsyncThreadYield(void);
WOLFSSL_API pthread_t wc_AsyncThreadId(void);
#endif /* WC_NO_ASYNC_THREADING */
#endif /* WOLFSSL_ASYNC_CRYPT */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* WOLFSSL_ASYNC_H */

View File

@@ -0,0 +1,217 @@
/* cavium_nitrox.h
*
* Copyright (C) 2006-2023 wolfSSL Inc.
*
* This file is part of wolfSSL. (formerly known as CyaSSL)
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef _CAVIUM_NITROX_H_
#define _CAVIUM_NITROX_H_
#ifdef HAVE_CAVIUM
#ifndef HAVE_CAVIUM_V
#include "cavium_sysdep.h"
#endif
#include "cavium_common.h"
#define CAVIUM_SSL_GRP 0
#define CAVIUM_DPORT 256
/* Compatibility with older Cavium SDK's */
#ifndef HAVE_CAVIUM_V
typedef int CspHandle;
typedef word32 CavReqId;
#define AES_128 AES_128_BIT
#define AES_192 AES_192_BIT
#define AES_256 AES_256_BIT
#define MAX_TO_POLL 30
typedef int context_type_t;
struct CspMultiRequestStatusBuffer {
int count;
CspRequestStatusBuffer req[MAX_TO_POLL];
};
#define AES_CBC 0x3
#define AES_GCM 0x7
#else
typedef word64 CavReqId;
#define CAVIUM_DEV_ID 0
#define CAVIUM_BLOCKING BLOCKING
#define CAVIUM_NON_BLOCKING NON_BLOCKING
#define CAVIUM_DIRECT DMA_DIRECT_DIRECT
#endif
typedef struct CspMultiRequestStatusBuffer CspMultiRequestStatusBuffer;
#ifdef WOLFSSL_ASYNC_CRYPT
#define CAVIUM_REQ_MODE CAVIUM_NON_BLOCKING
#else
#define CAVIUM_REQ_MODE CAVIUM_BLOCKING
#endif
#ifdef WOLFSSL_ASYNC_CRYPT
#ifndef CAVIUM_MAX_PENDING
#define CAVIUM_MAX_PENDING 10 /* 90 */
#endif
#ifndef CAVIUM_MAX_POLL
#define CAVIUM_MAX_POLL MAX_TO_POLL
#endif
#endif
typedef struct CaviumNitroxDev {
CspHandle devId; /* nitrox device id */
context_type_t type; /* Typically CONTEXT_SSL, but also ECC types*/
word64 contextHandle; /* nitrox context memory handle */
CavReqId reqId; /* Current requestId */
} CaviumNitroxDev;
struct WOLF_EVENT;
struct WC_ASYNC_DEV;
struct WC_BIGINT;
/* Wrapper API's */
WOLFSSL_LOCAL int NitroxTranslateResponseCode(int ret);
WOLFSSL_LOCAL CspHandle NitroxGetDeviceHandle(void);
WOLFSSL_LOCAL CspHandle NitroxOpenDeviceDefault(void);
WOLFSSL_LOCAL CspHandle NitroxOpenDevice(int dma_mode, int dev_id);
WOLFSSL_LOCAL int NitroxAllocContext(struct WC_ASYNC_DEV* dev, CspHandle devId,
context_type_t type);
WOLFSSL_LOCAL void NitroxFreeContext(struct WC_ASYNC_DEV* dev);
WOLFSSL_LOCAL void NitroxCloseDevice(CspHandle devId);
#if defined(WOLFSSL_ASYNC_CRYPT)
WOLFSSL_LOCAL int NitroxCheckRequest(struct WC_ASYNC_DEV* dev,
struct WOLF_EVENT* event);
WOLFSSL_LOCAL int NitroxCheckRequests(struct WC_ASYNC_DEV* dev,
CspMultiRequestStatusBuffer* req_stat_buf);
#endif /* WOLFSSL_ASYNC_CRYPT */
/* Crypto wrappers */
#ifndef NO_RSA
struct RsaKey;
WOLFSSL_LOCAL int NitroxRsaExptMod(
const byte* in, word32 inLen,
byte* exponent, word32 expLen,
byte* modulus, word32 modLen,
byte* out, word32* outLen, struct RsaKey* key);
WOLFSSL_LOCAL int NitroxRsaPublicEncrypt(const byte* in, word32 inLen,
byte* out, word32 outLen, struct RsaKey* key);
WOLFSSL_LOCAL int NitroxRsaPrivateDecrypt(const byte* in, word32 inLen,
byte* out, word32* outLen, struct RsaKey* key);
WOLFSSL_LOCAL int NitroxRsaSSL_Sign(const byte* in, word32 inLen,
byte* out, word32 outLen, struct RsaKey* key);
WOLFSSL_LOCAL int NitroxRsaSSL_Verify(const byte* in, word32 inLen,
byte* out, word32 *outLen, struct RsaKey* key);
#endif /* !NO_RSA */
#if defined(HAVE_ECC) && defined(HAVE_CAVIUM_V)
struct ecc_key;
WOLFSSL_LOCAL int NitroxEccGetSize(struct ecc_key* key);
WOLFSSL_LOCAL int NitroxEccRsSplit(struct ecc_key* key,
struct WC_BIGINT* r, struct WC_BIGINT* s);
WOLFSSL_LOCAL int NitroxEccIsCurveSupported(struct ecc_key* key);
WOLFSSL_LOCAL int NitroxEccPad(struct WC_BIGINT* bi, word32 padTo);
#ifdef HAVE_ECC_DHE
WOLFSSL_LOCAL int NitroxEcdh(struct ecc_key* key,
struct WC_BIGINT* k, struct WC_BIGINT* xG, struct WC_BIGINT* yG,
byte* out, word32* outlen, struct WC_BIGINT* q);
#endif /* HAVE_ECC_DHE */
#ifdef HAVE_ECC_SIGN
WOLFSSL_LOCAL int NitroxEcdsaSign(struct ecc_key* key,
struct WC_BIGINT* m, struct WC_BIGINT* d,
struct WC_BIGINT* k,
struct WC_BIGINT* r, struct WC_BIGINT* s,
struct WC_BIGINT* q, struct WC_BIGINT* n);
#endif /* HAVE_ECC_SIGN */
#ifdef HAVE_ECC_VERIFY
WOLFSSL_LOCAL int NitroxEcdsaVerify(struct ecc_key* key,
struct WC_BIGINT* m, struct WC_BIGINT* xp,
struct WC_BIGINT* yp, struct WC_BIGINT* r,
struct WC_BIGINT* s, struct WC_BIGINT* q,
struct WC_BIGINT* n, int* stat);
#endif /* HAVE_ECC_VERIFY */
#endif /* HAVE_ECC */
#ifndef NO_AES
struct Aes;
#ifdef HAVE_AES_CBC
WOLFSSL_LOCAL int NitroxAesCbcEncrypt(struct Aes* aes, byte* out,
const byte* in, word32 length);
#ifdef HAVE_AES_DECRYPT
WOLFSSL_LOCAL int NitroxAesCbcDecrypt(struct Aes* aes, byte* out,
const byte* in, word32 length);
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AES_CBC */
#ifdef HAVE_AESGCM
WOLFSSL_LOCAL int NitroxAesGcmEncrypt(struct Aes* aes,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
const byte* iv, word32 ivSz,
byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz);
#ifdef HAVE_AES_DECRYPT
WOLFSSL_LOCAL int NitroxAesGcmDecrypt(struct Aes* aes,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
const byte* iv, word32 ivSz,
const byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz);
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AESGCM */
#endif /* !NO_AES */
#ifndef NO_RC4
struct Arc4;
WOLFSSL_LOCAL int NitroxArc4SetKey(struct Arc4* arc4, const byte* key,
word32 length);
WOLFSSL_LOCAL int NitroxArc4Process(struct Arc4* arc4, byte* out,
const byte* in, word32 length);
#endif /* !NO_RC4 */
#ifndef NO_DES3
struct Des3;
WOLFSSL_LOCAL int NitroxDes3SetKey(struct Des3* des3, const byte* key,
const byte* iv);
WOLFSSL_LOCAL int NitroxDes3CbcEncrypt(struct Des3* des3, byte* out,
const byte* in, word32 length);
WOLFSSL_LOCAL int NitroxDes3CbcDecrypt(struct Des3* des3, byte* out,
const byte* in, word32 length);
#endif /* !NO_DES3 */
#ifndef NO_HMAC
struct Hmac;
WOLFSSL_LOCAL int NitroxHmacUpdate(struct Hmac* hmac, const byte* msg,
word32 length);
WOLFSSL_LOCAL int NitroxHmacFinal(struct Hmac* hmac, byte* hash,
word16 hashLen);
#endif /* NO_HMAC */
struct WC_RNG;
WOLFSSL_API int NitroxRngGenerateBlock(struct WC_RNG* rng, byte* output,
word32 sz);
#endif /* HAVE_CAVIUM */
#endif /* _CAVIUM_NITROX_H_ */

View File

@@ -0,0 +1,520 @@
/* quickassist.h
*
* Copyright (C) 2006-2023 wolfSSL Inc.
*
* This file is part of wolfSSL. (formerly known as CyaSSL)
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef _INTEL_QUICKASSIST_H_
#define _INTEL_QUICKASSIST_H_
#ifdef HAVE_INTEL_QA
#include "cpa.h"
#include "cpa_cy_im.h"
#include "cpa_cy_sym.h"
#include "cpa_cy_rsa.h"
#include "cpa_cy_ln.h"
#include "cpa_cy_ecdh.h"
#include "cpa_cy_ecdsa.h"
#include "cpa_cy_dh.h"
#include "cpa_cy_drbg.h"
#include "cpa_cy_nrbg.h"
#include "cpa_cy_prime.h"
/* User space utils */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#if 0
/* Optional feature for partial QAT hashing support */
/* This will process updates through hardware instead of caching them */
#define QAT_HASH_ENABLE_PARTIAL
#endif
#ifdef QAT_HASH_ENABLE_PARTIAL
#define MAX_QAT_HASH_BUFFERS 2
#endif
/* Detect QAT driver version */
#if defined(CPA_CY_API_VERSION_NUM_MAJOR) && CPA_CY_API_VERSION_NUM_MAJOR > 1
#define QAT_V2
#if CPA_CY_API_VERSION_NUM_MAJOR > 2 || ( \
CPA_CY_API_VERSION_NUM_MAJOR == 2 && ( \
defined(CPA_CY_API_VERSION_NUM_MINOR) && \
CPA_CY_API_VERSION_NUM_MINOR >= 4 \
) \
)
#define QAT_V2_4_PLUS
#endif
#endif
#ifdef QAT_V2
/* quickassist/utilities/libusdm_drv/qae_mem.h */
/* Provides user-space API's for accessing NUMA allocated memory
* through usdm_drv */
#include "qae_mem.h"
#endif
#ifdef QAT_USE_POLLING_THREAD
#include <pthread.h>
#endif
#ifdef QA_DEMO_MAIN
#include <semaphore.h>
#endif
/* Tunable parameters */
#ifndef QAT_PROCESS_NAME
#define QAT_PROCESS_NAME "SSL"
#endif
#ifndef QAT_LIMIT_DEV_ACCESS
#define QAT_LIMIT_DEV_ACCESS CPA_FALSE
#endif
#ifndef QAT_MAX_DEVICES
#define QAT_MAX_DEVICES (1) /* maximum number of QAT cards */
#endif
#ifndef QAT_MAX_PENDING
/* max num of concurrent ops */
#ifdef WC_NO_ASYNC_THREADING
#define QAT_MAX_PENDING (40)
#elif defined(WC_ASYNC_BENCH_THREAD_COUNT)
#define QAT_MAX_PENDING ((40/WC_ASYNC_BENCH_THREAD_COUNT)*2)
#else
#define QAT_MAX_PENDING (15)
#endif
#endif
#ifndef QAT_RETRY_LIMIT
#define QAT_RETRY_LIMIT (100)
#endif
#ifndef QAT_POLL_RESP_QUOTA
#define QAT_POLL_RESP_QUOTA (0) /* all pending */
#endif
/* TODO: Tune this value to get best performance */
#ifndef WC_ASYNC_THRESH_AES_CBC
#define WC_ASYNC_THRESH_AES_CBC 128
#endif
#ifndef WC_ASYNC_THRESH_AES_GCM
#define WC_ASYNC_THRESH_AES_GCM 128
#endif
#ifndef WC_ASYNC_THRESH_DES3_CBC
#define WC_ASYNC_THRESH_DES3_CBC 128
#endif
/* Macros */
#define INVALID_STATUS -256
#if !defined(NO_SHA256) || defined(WOLFSSL_SHA512) || \
defined(WOLFSSL_SHA384) || !defined(NO_HMAC) || !defined(NO_MD5) || \
defined(WOLFSSL_SHA224)
#define QAT_ENABLE_HASH
#endif
#if !defined(NO_AES) || !defined(NO_DES3)
#define QAT_ENABLE_CRYPTO
#endif
#if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DH)
#define QAT_ENABLE_PKI
#endif
/* QAT 1.7 does not support NRBG or DRBG */
#if !defined(QAT_V2) && !defined(NO_QAT_RNG)
#define QAT_ENABLE_RNG
#endif
/* Pre-declarations */
struct WC_ASYNC_DEV;
struct WC_BIGINT;
struct IntelQaDev;
struct WC_RNG;
#if defined(QAT_ENABLE_HASH) || defined(QAT_ENABLE_CRYPTO)
/* symmetric context */
typedef struct IntelQaSymCtx {
CpaCySymOpData opData;
CpaCySymSessionCtx symCtxSrc;
CpaCySymSessionCtx symCtx;
word32 symCtxSize;
/* flags */
word32 isOpen:1;
word32 isCopy:1;
} IntelQaSymCtx;
#endif
typedef void (*IntelQaFreeFunc)(struct WC_ASYNC_DEV*);
#if defined(QAT_ENABLE_PKI) && !defined(NO_RSA) && defined (WOLFSSL_KEY_GEN)
#ifndef QAT_PRIME_GEN_TRIES
/* number of times to try generating a prime candidates
based on generated miller rabbin */
#define QAT_PRIME_GEN_TRIES 100
#endif
#ifndef QAT_PRIME_GEN_RETRIES
/* number of times to try new prime candidates */
#define QAT_PRIME_GEN_RETRIES 1000
#endif
#ifndef QAT_PRIME_GEN_MR_ROUNDS
/* Miller Rabbin Rounds */
#define QAT_PRIME_GEN_MR_ROUNDS 2
#endif
enum {
QAT_PRIME_CHK_STATUS_INIT = 0,
QAT_PRIME_CHK_STATUS_FAILED,
QAT_PRIME_CHK_STATUS_PASSED,
QAT_PRIME_CHK_STATUS_ERROR,
};
#endif
#if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
struct sp_int;
#define MATH_INT_T struct sp_int
#elif defined(USE_FAST_MATH)
struct fp_int;
#define MATH_INT_T struct fp_int
#else
struct mp_int;
#define MATH_INT_T struct mp_int
#endif
/* QuickAssist device */
typedef struct IntelQaDev {
CpaInstanceHandle handle;
int devId;
/* callback return info */
int ret;
byte* out;
union {
word32* outLenPtr;
word32 outLen;
};
/* operations */
IntelQaFreeFunc freeFunc;
union {
#if defined(QAT_ENABLE_PKI) && !defined(NO_RSA)
#ifdef WOLFSSL_KEY_GEN
struct {
CpaCyPrimeTestOpData* opData;
CpaFlatBuffer* primeCandidates;
byte* pMillerRabinData;
byte testStatus[QAT_PRIME_GEN_TRIES];
} prime_gen;
struct {
CpaCyRsaKeyGenOpData opData;
CpaCyRsaPrivateKey privateKey;
CpaCyRsaPublicKey publicKey;
struct RsaKey* rsakey;
} rsa_keygen;
#endif /* WOLFSSL_KEY_GEN */
struct {
CpaCyRsaDecryptOpData opData;
CpaCyRsaPrivateKey privateKey;
CpaFlatBuffer outBuf;
} rsa_priv;
struct {
CpaCyRsaEncryptOpData opData;
CpaCyRsaPublicKey publicKey;
CpaFlatBuffer outBuf;
} rsa_pub;
struct {
CpaCyLnModExpOpData opData;
CpaFlatBuffer target;
} rsa_modexp;
#endif
#ifdef QAT_ENABLE_CRYPTO
struct {
IntelQaSymCtx ctx;
CpaBufferList bufferList;
CpaFlatBuffer flatBuffer;
byte* authTag;
word32 authTagSz;
byte* iv;
word32 ivSz;
} cipher;
#endif
#if defined(QAT_ENABLE_PKI) && defined(HAVE_ECC)
struct {
CpaCyEcPointMultiplyOpData opData;
CpaFlatBuffer pXk;
CpaFlatBuffer pYk;
CpaBoolean multiplyStatus;
/* output pub */
MATH_INT_T* pubX;
MATH_INT_T* pubY;
MATH_INT_T* pubZ;
} ecc_mul;
#ifdef HAVE_ECC_DHE
struct {
CpaCyEcdhPointMultiplyOpData opData;
CpaFlatBuffer pXk;
CpaFlatBuffer pYk;
CpaBoolean multiplyStatus;
} ecc_ecdh;
#endif
#ifdef HAVE_ECC_SIGN
struct {
CpaCyEcdsaSignRSOpData opData;
CpaFlatBuffer R;
CpaFlatBuffer S;
CpaBoolean signStatus;
struct WC_BIGINT* pR;
struct WC_BIGINT* pS;
} ecc_sign;
#endif
#ifdef HAVE_ECC_VERIFY
struct {
CpaCyEcdsaVerifyOpData opData;
CpaBoolean verifyStatus;
int* stat;
} ecc_verify;
#endif
#endif /* HAVE_ECC */
#ifdef QAT_ENABLE_HASH
struct {
IntelQaSymCtx ctx;
CpaBufferList* srcList;
/* tmp buffer to hold anything pending less than block size */
byte* tmpIn;
word32 tmpInSz;
word32 tmpInBufSz;
#ifdef QAT_HASH_ENABLE_PARTIAL
int bufferCount;
byte* buffers[MAX_QAT_HASH_BUFFERS];
word32 buffersSz[MAX_QAT_HASH_BUFFERS];
#endif
} hash;
#endif
#if defined(QAT_ENABLE_PKI) && !defined(NO_DH)
struct {
CpaCyDhPhase1KeyGenOpData opData;
CpaFlatBuffer pOut;
} dh_gen;
struct {
CpaCyDhPhase2SecretKeyGenOpData opData;
CpaFlatBuffer pOut;
} dh_agree;
#endif
#ifdef QAT_ENABLE_RNG
struct {
CpaCyDrbgGenOpData opData;
CpaCyDrbgSessionHandle handle;
CpaFlatBuffer pOut;
} drbg;
#endif
} op;
#ifdef QAT_USE_POLLING_THREAD
pthread_t pollingThread;
byte pollingCy;
#endif
} IntelQaDev;
/* Interface */
WOLFSSL_LOCAL int IntelQaHardwareStart(const char* process_name,
int limitDevAccess);
WOLFSSL_LOCAL void IntelQaHardwareStop(void);
WOLFSSL_LOCAL int IntelQaInit(void* threadId);
WOLFSSL_LOCAL void IntelQaDeInit(int);
WOLFSSL_LOCAL int IntelQaNumInstances(void);
WOLFSSL_LOCAL int IntelQaOpen(struct WC_ASYNC_DEV* dev, int devId);
WOLFSSL_LOCAL void IntelQaClose(struct WC_ASYNC_DEV* dev);
WOLFSSL_LOCAL int IntelQaDevCopy(struct WC_ASYNC_DEV* src,
struct WC_ASYNC_DEV* dst);
WOLFSSL_LOCAL int IntelQaPoll(struct WC_ASYNC_DEV* dev);
WOLFSSL_LOCAL int IntelQaGetCyInstanceCount(void);
#ifndef NO_RSA
#ifdef WOLFSSL_KEY_GEN
WOLFSSL_LOCAL int IntelQaGenPrime(struct WC_ASYNC_DEV* dev,
struct WC_RNG* rng, byte* primeBuf, word32 primeSz);
WOLFSSL_LOCAL int IntelQaRsaKeyGen(struct WC_ASYNC_DEV* dev,
struct RsaKey* key, int keyBits, long e,
struct WC_RNG* rng);
#endif
WOLFSSL_LOCAL int IntelQaRsaPrivate(struct WC_ASYNC_DEV* dev,
const byte* in, word32 inLen,
struct WC_BIGINT* d, struct WC_BIGINT* n,
byte* out, word32* outLen);
WOLFSSL_LOCAL int IntelQaRsaCrtPrivate(struct WC_ASYNC_DEV* dev,
const byte* in, word32 inLen,
struct WC_BIGINT* p, struct WC_BIGINT* q,
struct WC_BIGINT* dP, struct WC_BIGINT* dQ,
struct WC_BIGINT* qInv,
byte* out, word32* outLen);
WOLFSSL_LOCAL int IntelQaRsaPublic(struct WC_ASYNC_DEV* dev,
const byte* in, word32 inLen,
struct WC_BIGINT* e, struct WC_BIGINT* n,
byte* out, word32* outLen);
WOLFSSL_LOCAL int IntelQaRsaExptMod(struct WC_ASYNC_DEV* dev,
const byte* in, word32 inLen,
struct WC_BIGINT* e, struct WC_BIGINT* n,
byte* out, word32* outLen);
#endif /* !NO_RSA */
#ifndef NO_AES
#ifdef HAVE_AES_CBC
WOLFSSL_LOCAL int IntelQaSymAesCbcEncrypt(struct WC_ASYNC_DEV* dev,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
byte* iv, word32 ivSz);
#ifdef HAVE_AES_DECRYPT
WOLFSSL_LOCAL int IntelQaSymAesCbcDecrypt(struct WC_ASYNC_DEV* dev,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
byte* iv, word32 ivSz);
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AES_CBC */
#ifdef HAVE_AESGCM
WOLFSSL_LOCAL int IntelQaSymAesGcmEncrypt(struct WC_ASYNC_DEV* dev,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
const byte* iv, word32 ivSz,
byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz);
#ifdef HAVE_AES_DECRYPT
WOLFSSL_LOCAL int IntelQaSymAesGcmDecrypt(struct WC_ASYNC_DEV* dev,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
const byte* iv, word32 ivSz,
const byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz);
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AESGCM */
#endif /* !NO_AES */
#ifndef NO_DES3
WOLFSSL_LOCAL int IntelQaSymDes3CbcEncrypt(struct WC_ASYNC_DEV* dev,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
byte* iv, word32 ivSz);
WOLFSSL_LOCAL int IntelQaSymDes3CbcDecrypt(struct WC_ASYNC_DEV* dev,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
byte* iv, word32 ivSz);
#endif /*! NO_DES3 */
#ifdef WOLFSSL_SHA512
WOLFSSL_LOCAL int IntelQaSymSha512(struct WC_ASYNC_DEV* dev, byte* out,
const byte* in, word32 sz);
#ifdef WOLFSSL_SHA384
WOLFSSL_LOCAL int IntelQaSymSha384(struct WC_ASYNC_DEV* dev,
byte* out, const byte* in, word32 sz);
#endif
#endif
#ifndef NO_SHA256
WOLFSSL_LOCAL int IntelQaSymSha256(struct WC_ASYNC_DEV* dev, byte* out,
const byte* in, word32 sz);
#ifdef WOLFSSL_SHA224
WOLFSSL_LOCAL int IntelQaSymSha224(struct WC_ASYNC_DEV* dev, byte* out,
const byte* in, word32 sz);
#endif
#endif /* !NO_SHA256 */
#ifndef NO_SHA
WOLFSSL_LOCAL int IntelQaSymSha(struct WC_ASYNC_DEV* dev, byte* out,
const byte* in, word32 sz);
#endif /* !NO_SHA */
#ifndef NO_MD5
WOLFSSL_LOCAL int IntelQaSymMd5(struct WC_ASYNC_DEV* dev, byte* out,
const byte* in, word32 sz);
#endif /* !NO_MD5 */
#if defined(WOLFSSL_SHA3) && defined(QAT_V2)
WOLFSSL_LOCAL int IntelQaSymSha3(struct WC_ASYNC_DEV* dev, byte* out,
const byte* in, word32 sz);
#endif
#ifdef HAVE_ECC
#ifdef HAVE_ECC_DHE
WOLFSSL_LOCAL int IntelQaEccPointMul(struct WC_ASYNC_DEV* dev,
struct WC_BIGINT* k, MATH_INT_T* pubX, MATH_INT_T* pubY,
MATH_INT_T* pubZ,
struct WC_BIGINT* xG, struct WC_BIGINT* yG,
struct WC_BIGINT* a, struct WC_BIGINT* b,
struct WC_BIGINT* q, word32 cofactor);
WOLFSSL_LOCAL int IntelQaEcdh(struct WC_ASYNC_DEV* dev,
struct WC_BIGINT* k, struct WC_BIGINT* xG,
struct WC_BIGINT* yG, byte* out, word32* outlen,
struct WC_BIGINT* a, struct WC_BIGINT* b,
struct WC_BIGINT* q, word32 cofactor);
#endif /* HAVE_ECC_DHE */
#ifdef HAVE_ECC_SIGN
WOLFSSL_LOCAL int IntelQaEcdsaSign(struct WC_ASYNC_DEV* dev,
struct WC_BIGINT* m, struct WC_BIGINT* d,
struct WC_BIGINT* k,
struct WC_BIGINT* r, struct WC_BIGINT* s,
struct WC_BIGINT* a, struct WC_BIGINT* b,
struct WC_BIGINT* q, struct WC_BIGINT* n,
struct WC_BIGINT* xg, struct WC_BIGINT* yg);
#endif /* HAVE_ECC_SIGN */
#ifdef HAVE_ECC_VERIFY
WOLFSSL_LOCAL int IntelQaEcdsaVerify(struct WC_ASYNC_DEV* dev,
struct WC_BIGINT* m, struct WC_BIGINT* xp,
struct WC_BIGINT* yp, struct WC_BIGINT* r,
struct WC_BIGINT* s, struct WC_BIGINT* a,
struct WC_BIGINT* b, struct WC_BIGINT* q,
struct WC_BIGINT* n, struct WC_BIGINT* xg,
struct WC_BIGINT* yg, int* stat);
#endif /* HAVE_ECC_VERIFY */
#endif /* HAVE_ECC */
#ifndef NO_DH
WOLFSSL_LOCAL int IntelQaDhKeyGen(struct WC_ASYNC_DEV* dev,
struct WC_BIGINT* p, struct WC_BIGINT* g, struct WC_BIGINT* x,
byte* pub, word32* pubSz);
WOLFSSL_LOCAL int IntelQaDhAgree(struct WC_ASYNC_DEV* dev,
struct WC_BIGINT* p,
byte* agree, word32* agreeSz,
const byte* priv, word32 privSz,
const byte* otherPub, word32 pubSz);
#endif /* !NO_DH */
#ifndef NO_HMAC
WOLFSSL_LOCAL int IntelQaHmacGetType(int macType, word32* hashAlgorithm);
WOLFSSL_LOCAL int IntelQaHmac(struct WC_ASYNC_DEV* dev,
int macType, byte* keyRaw, word16 keyLen,
byte* out, const byte* in, word32 sz);
#endif /* !NO_HMAC */
WOLFSSL_LOCAL int IntelQaDrbg(struct WC_ASYNC_DEV* dev, byte* rngBuf,
word32 rngSz);
WOLFSSL_LOCAL int IntelQaNrbg(CpaFlatBuffer* pBuffer, Cpa32U length);
#endif /* HAVE_INTEL_QA */
#endif /* _INTEL_QUICKASSIST_H_ */

View File

@@ -0,0 +1,64 @@
/* quickassist_mem.h
*
* Copyright (C) 2006-2023 wolfSSL Inc.
*
* This file is part of wolfSSL. (formerly known as CyaSSL)
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef _QUICKASSIST_MEM_H_
#define _QUICKASSIST_MEM_H_
#ifdef HAVE_INTEL_QA
#include <wolfssl/wolfcrypt/port/intel/quickassist.h>
CpaStatus qaeMemInit(void);
void qaeMemDestroy(void);
#ifndef QAT_V2
#define QAE_PHYS_ADDR CpaPhysicalAddr
WOLFSSL_LOCAL QAE_PHYS_ADDR qaeVirtToPhysNUMA(void* pVirtAddress);
#endif
#ifdef WOLFSSL_TRACK_MEMORY
WOLFSSL_API int InitMemoryTracker(void);
WOLFSSL_API void ShowMemoryTracker(void);
#endif
WOLFSSL_API void* IntelQaMalloc(size_t size, void* heap, int type
#ifdef WOLFSSL_DEBUG_MEMORY
, const char* func, unsigned int line
#endif
);
WOLFSSL_API void IntelQaFree(void *ptr, void* heap, int type
#ifdef WOLFSSL_DEBUG_MEMORY
, const char* func, unsigned int line
#endif
);
WOLFSSL_API void* IntelQaRealloc(void *ptr, size_t size, void* heap, int type
#ifdef WOLFSSL_DEBUG_MEMORY
, const char* func, unsigned int line
#endif
);
#endif /* HAVE_INTEL_QA */
#endif /* _QUICKASSIST_MEM_H_ */