Skip to content

Commit fef8dae

Browse files
authored
Merge pull request #33 from dgarske/docs
Updates to documentation for async
2 parents fdfd3b4 + 3d24295 commit fef8dae

File tree

4 files changed

+429
-359
lines changed

4 files changed

+429
-359
lines changed

README-async.md

Lines changed: 88 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ void wolfAsync_DevClose(int *devId)
6464

6565
Closes the async device.
6666

67+
### ```wolfAsync_DevCopy```
68+
69+
```
70+
int wolfAsync_DevCopy(WC_ASYNC_DEV* src, WC_ASYNC_DEV* dst);
71+
```
72+
73+
Copy async device memory safe (not pointers to old device).
74+
6775
### ```wolfAsync_DevCtxInit```
6876
```
6977
int wolfAsync_DevCtxInit(WC_ASYNC_DEV* asyncDev, word32 marker, void* heap, int devId);
@@ -156,74 +164,60 @@ Stops hardware if internal `--start_count == 0`.
156164

157165
### TLS Server Example
158166

159-
```
160-
#ifdef WOLFSSL_ASYNC_CRYPT
161-
static int devId = INVALID_DEVID;
162-
163-
ret = wolfAsync_DevOpen(&devId);
164-
if (ret != 0) {
165-
err_sys("Async device open failed");
167+
```c
168+
int devId = INVALID_DEVID;
169+
170+
ret = wolfAsync_DevOpen(&devId);
171+
if (ret != 0) {
172+
err_sys("Async device open failed");
173+
}
174+
wolfSSL_CTX_SetDevId(ctx, devId);
175+
176+
do {
177+
err = 0; /* reset error */
178+
ret = wolfSSL_accept(ssl, msg, msgSz, &msgSz);
179+
if (ret <= 0) {
180+
err = wolfSSL_get_error(ssl, 0);
181+
if (err == WC_PENDING_E) {
182+
ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
183+
if (ret < 0) break;
184+
}
166185
}
167-
wolfSSL_CTX_UseAsync(ctx, devId);
168-
#endif /* WOLFSSL_ASYNC_CRYPT */
169-
170-
err = 0;
171-
do {
172-
#ifdef WOLFSSL_ASYNC_CRYPT
173-
if (err == WC_PENDING_E) {
174-
ret = wolfSSL_AsyncPoll(ssl);
175-
if (ret < 0) { break; } else if (ret == 0) { continue; }
176-
}
177-
#endif
178-
179-
ret = wolfSSL_accept(ssl);
180-
if (ret != SSL_SUCCESS) {
181-
err = wolfSSL_get_error(ssl, 0);
182-
}
183-
} while (ret != SSL_SUCCESS && err == WC_PENDING_E);
186+
} while (err == WC_PENDING_E);
187+
if (ret != WOLFSSL_SUCCESS) {
188+
err_sys("SSL_connect failed");
189+
}
184190

185-
#ifdef WOLFSSL_ASYNC_CRYPT
186-
wolfAsync_DevClose(&devId);
187-
#endif
191+
wolfAsync_DevClose(&devId);
188192
```
189193
190194
### wolfCrypt RSA Example
191195
192-
```
193-
#ifdef WOLFSSL_ASYNC_CRYPT
194-
static int devId = INVALID_DEVID;
195-
196-
ret = wolfAsync_DevOpen(&devId);
197-
if (ret != 0) {
198-
err_sys("Async device open failed");
199-
}
200-
#endif /* WOLFSSL_ASYNC_CRYPT */
196+
```c
197+
static int devId = INVALID_DEVID;
198+
RsaKey key;
201199
202-
RsaKey key;
203-
ret = wc_InitRsaKey_ex(&key, HEAP_HINT, devId);
200+
ret = wolfAsync_DevOpen(&devId);
201+
if (ret != 0)
202+
err_sys("Async device open failed");
204203
205-
ret = wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes);
206-
207-
do {
208-
#if defined(WOLFSSL_ASYNC_CRYPT)
204+
wc_InitRsaKey_ex(&key, HEAP_HINT, devId);
205+
if (ret == 0) {
206+
ret = wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes);
207+
do {
209208
ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
210-
#endif
211-
if (ret >= 0) {
209+
if (ret >= 0)
212210
ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, &key, &rng);
213-
}
214211
} while (ret == WC_PENDING_E);
215-
if (ret < 0) {
216-
err_sys("RsaPublicEncrypt operation failed");
217-
}
212+
wc_FreeRsaKey(&key);
213+
}
218214
219-
#ifdef WOLFSSL_ASYNC_CRYPT
220-
wolfAsync_DevClose(&devId);
221-
#endif
215+
wolfAsync_DevClose(&devId);
222216
```
223217

224218
## Build Options
225219

226-
1. Async mult-threading can be disabled by defining `WC_NO_ASYNC_THREADING`.
220+
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.
227221
2. Software benchmarks can be disabled by defining `NO_SW_BENCH`.
228222
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.
229223
4. Use `WOLFSSL_DEBUG_MEMORY` and `WOLFSSL_TRACK_MEMORY` to help debug memory issues. QAT also supports `WOLFSSL_DEBUG_MEMORY_PRINT`.
@@ -239,31 +233,53 @@ We have a full TLS client/server async examples here:
239233

240234
* [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)
241235

242-
#### Usage
236+
#### TLS Threaded epoll Example Building
243237

244-
```
238+
```sh
245239
git clone [email protected]:wolfSSL/wolfssl-examples.git
246240
cd wolfssl-examples
247241
cd tls
242+
# For QuickAssist: Uncomment QAT lines at top of Makefile
248243
make
249-
sudo ./server-tls-epoll-perf
250-
sudo ./client-tls-perf
251-
```
252-
253-
```
254-
Waiting for a connection...
255-
SSL cipher suite is TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
256-
wolfSSL Client Benchmark 16384 bytes
257-
Num Conns : 100
258-
Total : 777.080 ms
259-
Total Avg : 7.771 ms
260-
t/s : 128.687
261-
Accept : 590.556 ms
262-
Accept Avg : 5.906 ms
263-
Total Read bytes : 1638400 bytes
264-
Total Write bytes : 1638400 bytes
265-
Read : 73.360 ms ( 21.299 MBps)
266-
Write : 74.535 ms ( 20.963 MBps)
244+
```
245+
246+
#### TLS Threaded epoll Example Usage
247+
248+
```sh
249+
$ ./client-tls-perf -?
250+
perf 4.5.0 (NOTE: All files relative to wolfSSL home dir)
251+
-? Help, print this usage
252+
-p <num> Port to listen on, not 0, default 11111
253+
-v <num> SSL version [0-3], SSLv3(0) - TLS1.2(3)), default 3
254+
-l <str> Cipher suite list (: delimited)
255+
-c <file> Certificate file, default ../certs/client-cert.pem
256+
-k <file> Key file, default ../certs/client-key.pem
257+
-A <file> Certificate Authority file, default ../certs/ca-cert.pem
258+
-r Resume session
259+
-n <num> Benchmark <num> connections
260+
-N <num> <num> concurrent connections
261+
-R <num> <num> bytes read from client
262+
-W <num> <num> bytes written to client
263+
-B <num> Benchmark <num> written bytes
264+
```
265+
266+
#### TLS Threaded epoll Example Output
267+
268+
```sh
269+
$ sudo ./server-tls-epoll-threaded -n 10000
270+
$ sudo ./client-tls-perf -n 10000
271+
272+
wolfSSL Server Benchmark 16384 bytes
273+
Num Conns : 10000
274+
Total : 18575.800 ms
275+
Total Avg : 1.858 ms
276+
t/s : 538.335
277+
Accept : 35848.428 ms
278+
Accept Avg : 3.585 ms
279+
Total Read bytes : 163840000 bytes
280+
Total Write bytes : 163840000 bytes
281+
Read : 402.212 ms ( 388.476 MBps)
282+
Write : 591.469 ms ( 264.173 MBps)
267283
```
268284

269285
## Change Log

wolfcrypt/src/port/cavium/README.md

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,51 @@ Tested using `CNN55XX-Driver-Linux-KVM-XEN-PF-SDK-1.4.14.tar`
1111

1212
### Installation
1313

14+
```sh
15+
$ cd CN55XX-SDK
16+
$ make clean
17+
$ make
18+
$ cd bin
19+
$ sudo perl ./init_nitrox.pl
20+
21+
NITROX-V devices found: 1
22+
NITROX-V driver(nitrox_drv.ko) load: SUCCESS
23+
NITROX-V Device-0 part: CNN5560-900BG676-C45-G
24+
25+
Reading config file: ../microcode/ssl.conf
26+
Device count: 1 Config file device count: 2
27+
28+
NITROX Model: 0x1200 [ CNN55XX PASS 1.0 ]
29+
30+
Microcode Details:
31+
Version : CNN5x-MC-AE-MAIN-0001
32+
Core Count : 80
33+
Code length : 9514
34+
Block number: 0
35+
36+
Microcode Details:
37+
Version : CNN5x-MC-SE-SSL-0004
38+
Core Count : 64
39+
Code length : 23738
40+
Block number: 1
41+
42+
Microcode Load Succeed on device: 0
43+
44+
[ AE ] Microcode: CNN5x-MC-AE-MAIN-0001
45+
Group : 0
46+
Core Mask [Hi Low]: ffff ffffffffffffffff [ 80 ]
47+
48+
[ SE ] Microcode: CNN5x-MC-SE-SSL-0004
49+
Group : 0
50+
Core Mask : ffffffffffffffff [ 64 ]
51+
52+
Microcode Load success
1453
```
15-
cd CN55XX-SDK
16-
make clean
17-
make
18-
cd bin
19-
sudo perl ./init_nitrox.pl
54+
55+
```sh
56+
$ lspci | grep Cavium
57+
09:00.0 Network and computing encryption device: Cavium, Inc. Nitrox XL NPX (rev 01)
58+
81:00.0 Network and computing encryption device: Cavium, Inc. Device 0012
2059
```
2160

2261
#### Issues
@@ -25,7 +64,7 @@ sudo perl ./init_nitrox.pl
2564

2665
a. Modify `include/vf_defs.h:120` -> `vf_config_mode_str()` function to:
2766

28-
```
67+
```c
2968
static inline const char *vf_config_mode_str(vf_config_type_t vf_mode)
3069
{
3170
const char *vf_mode_str;
@@ -38,14 +77,14 @@ c. In `include/linux/sysdep.h:46` rename `__BYTED_ORDER` to `__BYTE_ORDER`.
3877
3978
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`.
4079
41-
```
80+
```sh
4281
NITROX Model: 0x1200 [ CNN55XX PASS 1.0 ]
4382
Invalid microcode
4483
ucode_dload: failed to initialize
4584
```
4685

4786
Resolve Links:
48-
```
87+
```sh
4988
cd microcode
5089
rm main_asym.out
5190
ln -s ./build/main_ae.out ./main_asym.out
@@ -58,7 +97,7 @@ ls -s ./build/main_ssl.out ./main_ssl.out
5897

5998
## Building wolfSSL
6099

61-
```
100+
```sh
62101
./configure --with-cavium-v=../CNN55XX-SDK --enable-asynccrypt --enable-aesni --enable-intelasm
63102
make
64103
sudo make install
@@ -82,7 +121,7 @@ Include the libnitrox static library:
82121
`LDFLAGS+= ../CNN55XX-SDK/lib/libnitrox.a`
83122

84123

85-
### Issues
124+
### wolfSSL Build Issues
86125

87126
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`.
88127

@@ -97,9 +136,9 @@ sudo ./wolfcrypt/test/testwolfcrypt
97136
```
98137

99138

100-
## TLS Code Tempalte
139+
## TLS Code Template
101140

102-
```
141+
```c
103142
/* GLOBAL DEVICE IDENTIFIER */
104143
#ifdef WOLFSSL_ASYNC_CRYPT
105144
static int devId = INVALID_DEVID;
@@ -115,7 +154,6 @@ sudo ./wolfcrypt/test/testwolfcrypt
115154
wolfSSL_CTX_UseAsync(ctx, devId);
116155
#endif
117156

118-
119157
/* DONE IN YOUR WORKER LOOP IN WC_PENDING_E CASES AGAINST YOUR WOLFSSL_CTX */
120158
#ifdef WOLFSSL_ASYNC_CRYPT
121159
int ret;
@@ -135,7 +173,6 @@ sudo ./wolfcrypt/test/testwolfcrypt
135173
}
136174
#endif
137175

138-
139176
/* DONE AT CLEANUP */
140177
#ifdef WOLFSSL_ASYNC_CRYPT
141178
wolfAsync_DevClose(&devId);
@@ -150,7 +187,7 @@ CentOS: Kernel 3.10.0-514.16.1.el7.x86_64
150187
Single Thread
151188

152189
```
153-
./configure --with-cavium-v=../CNN55XX-SDK --enable-asynccrypt --enable-aesni --enable-intelasm CFLAGS="-DWC_NO_ASYNC_THREADING" && make
190+
./configure --with-cavium-v=../CNN55XX-SDK --enable-asynccrypt --enable-aesni --enable-intelasm --enable-sp --enable-sp-asm CFLAGS="-DWC_NO_ASYNC_THREADING" && make
154191
155192
sudo ./wolfcrypt/benchmark/benchmark
156193

0 commit comments

Comments
 (0)