13#include <wolfssl/wolfcrypt/mem_track.h>
14#if defined(SHOW_CERTS) && \
15 (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
24#ifdef HAVE_PK_CALLBACKS
38 #ifdef HAVE_CURVE25519
45 #include <wolfssl/wolfcrypt/curve448.h>
56 #define SOCKET_T SOCKET
57 #define SNPRINTF _snprintf
58#elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
62 typedef int socklen_t ;
63 #define inet_addr wolfSSL_inet_addr
64 static unsigned long wolfSSL_inet_addr(
const char *cp)
66 unsigned int a[4] ;
unsigned long ret ;
67 sscanf(cp,
"%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]) ;
68 ret = ((a[3]<<24) + (a[2]<<16) + (a[1]<<8) + a[0]) ;
71 #if defined(HAVE_KEIL_RTX)
72 #define sleep(t) os_dly_wait(t/1000+1);
73 #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
74 #define sleep(t) osDelay(t/1000+1);
76#elif defined(WOLFSSL_TIRTOS)
79 #include <sys/types.h>
80 #include <arpa/inet.h>
81 #include <sys/socket.h>
82 #include <ti/sysbios/knl/Task.h>
91#elif defined(WOLFSSL_VXWORKS)
94 #include <arpa/inet.h>
96 #include <selectLib.h>
97 #include <sys/types.h>
98 #include <netinet/in.h>
100 #include <sys/time.h>
104#elif defined(WOLFSSL_ZEPHYR)
106 #include <sys/types.h>
107 #include <net/socket.h>
110 #define SO_REUSEADDR 201
111 #define WOLFSSL_USE_GETADDRINFO
113 static unsigned long inet_addr(
const char *cp)
115 unsigned int a[4];
unsigned long ret;
117 for (i=0, j=0; i<4; i++) {
119 while (cp[j] !=
'.' && cp[j] !=
'\0') {
125 ret = ((a[3]<<24) + (a[2]<<16) + (a[1]<<8) + a[0]) ;
130 #include <sys/types.h>
131#ifndef WOLFSSL_LEANPSK
134 #include <netinet/in.h>
135 #include <netinet/tcp.h>
136 #include <arpa/inet.h>
137 #include <sys/ioctl.h>
138 #include <sys/time.h>
139 #include <sys/socket.h>
150 #define SNPRINTF snprintf
153#ifdef WOLFSSL_ASYNC_CRYPT
154 #include <wolfssl/wolfcrypt/async.h>
157 #include <wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h>
162 #pragma warning(disable:4244 4996)
165#ifndef WOLFSSL_CIPHER_LIST_MAX_SIZE
166 #define WOLFSSL_CIPHER_LIST_MAX_SIZE 4096
169#ifndef TEST_BUFFER_SIZE
170 #define TEST_BUFFER_SIZE 16384
173#ifndef WOLFSSL_HAVE_MIN
174 #define WOLFSSL_HAVE_MIN
175 static WC_INLINE word32 min(word32 a, word32 b)
177 return a > b ? b : a;
182#ifndef WOLFSSL_SOCKET_INVALID
183#ifdef USE_WINDOWS_API
184 #define WOLFSSL_SOCKET_INVALID ((SOCKET_T)INVALID_SOCKET)
185#elif defined(WOLFSSL_TIRTOS)
186 #define WOLFSSL_SOCKET_INVALID ((SOCKET_T)-1)
188 #define WOLFSSL_SOCKET_INVALID (SOCKET_T)(0)
192#ifndef WOLFSSL_SOCKET_IS_INVALID
193#if defined(USE_WINDOWS_API) || defined(WOLFSSL_TIRTOS)
194 #define WOLFSSL_SOCKET_IS_INVALID(s) ((SOCKET_T)(s) == WOLFSSL_SOCKET_INVALID)
196 #define WOLFSSL_SOCKET_IS_INVALID(s) ((SOCKET_T)(s) < WOLFSSL_SOCKET_INVALID)
200#if defined(__MACH__) || defined(USE_WINDOWS_API)
202 typedef int socklen_t;
209#if !defined(__hpux__) && !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_IAR_ARM)\
210 && !defined(WOLFSSL_ROWLEY_ARM) && !defined(WOLFSSL_KEIL_TCP_NET)
211 typedef socklen_t* ACCEPT_THIRD_T;
213 #if defined _XOPEN_SOURCE_EXTENDED
214 typedef socklen_t* ACCEPT_THIRD_T;
216 typedef int* ACCEPT_THIRD_T;
222#ifdef SINGLE_THREADED
223 typedef unsigned int THREAD_RETURN;
224 typedef void* THREAD_TYPE;
225 #define WOLFSSL_THREAD
227 #if defined(_POSIX_THREADS) && !defined(__MINGW32__)
228 typedef void* THREAD_RETURN;
229 typedef pthread_t THREAD_TYPE;
230 #define WOLFSSL_THREAD
232 #define WAIT_OBJECT_0 0L
233 #elif defined(WOLFSSL_MDK_ARM)|| defined(WOLFSSL_KEIL_TCP_NET)
234 typedef unsigned int THREAD_RETURN;
235 typedef int THREAD_TYPE;
236 #define WOLFSSL_THREAD
237 #elif defined(WOLFSSL_TIRTOS)
238 typedef void THREAD_RETURN;
239 typedef Task_Handle THREAD_TYPE;
240 #define WOLFSSL_THREAD
241 #elif defined(WOLFSSL_ZEPHYR)
242 typedef void THREAD_RETURN;
243 typedef struct k_thread THREAD_TYPE;
244 #define WOLFSSL_THREAD
246 typedef unsigned int THREAD_RETURN;
247 typedef intptr_t THREAD_TYPE;
248 #define WOLFSSL_THREAD __stdcall
254 typedef struct sockaddr_in6 SOCKADDR_IN_T;
255 #define AF_INET_V AF_INET6
257 typedef struct sockaddr_in SOCKADDR_IN_T;
258 #define AF_INET_V AF_INET
262#ifndef WOLFSSL_NO_TLS12
263#define SERVER_DEFAULT_VERSION 3
265#define SERVER_DEFAULT_VERSION 4
267#define SERVER_DTLS_DEFAULT_VERSION (-2)
268#define SERVER_INVALID_VERSION (-99)
269#define SERVER_DOWNGRADE_VERSION (-98)
270#ifndef WOLFSSL_NO_TLS12
271#define CLIENT_DEFAULT_VERSION 3
273#define CLIENT_DEFAULT_VERSION 4
275#define CLIENT_DTLS_DEFAULT_VERSION (-2)
276#define CLIENT_INVALID_VERSION (-99)
277#define CLIENT_DOWNGRADE_VERSION (-98)
278#define EITHER_DOWNGRADE_VERSION (-97)
279#if !defined(NO_FILESYSTEM) && defined(WOLFSSL_MAX_STRENGTH)
280 #define DEFAULT_MIN_DHKEY_BITS 2048
281 #define DEFAULT_MAX_DHKEY_BITS 3072
283 #define DEFAULT_MIN_DHKEY_BITS 1024
284 #define DEFAULT_MAX_DHKEY_BITS 2048
286#if !defined(NO_FILESYSTEM) && defined(WOLFSSL_MAX_STRENGTH)
287 #define DEFAULT_MIN_RSAKEY_BITS 2048
289 #define DEFAULT_MIN_RSAKEY_BITS 1024
291#if !defined(NO_FILESYSTEM) && defined(WOLFSSL_MAX_STRENGTH)
292 #define DEFAULT_MIN_ECCKEY_BITS 256
294 #define DEFAULT_MIN_ECCKEY_BITS 224
298#if defined(WOLFSSL_NO_CURRDIR) || defined(WOLFSSL_MDK_SHELL)
299#define caCertFile "certs/ca-cert.pem"
300#define eccCertFile "certs/server-ecc.pem"
301#define eccKeyFile "certs/ecc-key.pem"
302#define eccRsaCertFile "certs/server-ecc-rsa.pem"
303#define svrCertFile "certs/server-cert.pem"
304#define svrKeyFile "certs/server-key.pem"
305#define cliCertFile "certs/client-cert.pem"
306#define cliCertDerFile "certs/client-cert.der"
307#define cliCertFileExt "certs/client-cert-ext.pem"
308#define cliCertDerFileExt "certs/client-cert-ext.der"
309#define cliKeyFile "certs/client-key.pem"
310#define ntruCertFile "certs/ntru-cert.pem"
311#define ntruKeyFile "certs/ntru-key.raw"
312#define dhParamFile "certs/dh2048.pem"
313#define cliEccKeyFile "certs/ecc-client-key.pem"
314#define cliEccCertFile "certs/client-ecc-cert.pem"
315#define caEccCertFile "certs/ca-ecc-cert.pem"
316#define crlPemDir "certs/crl"
317#define edCertFile "certs/ed25519/server-ed25519-cert.pem"
318#define edKeyFile "certs/ed25519/server-ed25519-priv.pem"
319#define cliEdCertFile "certs/ed25519/client-ed25519.pem"
320#define cliEdKeyFile "certs/ed25519/client-ed25519-priv.pem"
321#define caEdCertFile "certs/ed25519/ca-ed25519.pem"
322#define ed448CertFile "certs/ed448/server-ed448-cert.pem"
323#define ed448KeyFile "certs/ed448/server-ed448-priv.pem"
324#define cliEd448CertFile "certs/ed448/client-ed448.pem"
325#define cliEd448KeyFile "certs/ed448/client-ed448-priv.pem"
326#define caEd448CertFile "certs/ed448/ca-ed448.pem"
329 #define wnrConfig "wnr-example.conf"
332#define caCertFile "./certs/ca-cert.pem"
333#define eccCertFile "./certs/server-ecc.pem"
334#define eccKeyFile "./certs/ecc-key.pem"
335#define eccRsaCertFile "./certs/server-ecc-rsa.pem"
336#define svrCertFile "./certs/server-cert.pem"
337#define svrKeyFile "./certs/server-key.pem"
338#define cliCertFile "./certs/client-cert.pem"
339#define cliCertDerFile "./certs/client-cert.der"
340#define cliCertFileExt "./certs/client-cert-ext.pem"
341#define cliCertDerFileExt "./certs/client-cert-ext.der"
342#define cliKeyFile "./certs/client-key.pem"
343#define ntruCertFile "./certs/ntru-cert.pem"
344#define ntruKeyFile "./certs/ntru-key.raw"
345#define dhParamFile "./certs/dh2048.pem"
346#define cliEccKeyFile "./certs/ecc-client-key.pem"
347#define cliEccCertFile "./certs/client-ecc-cert.pem"
348#define caEccCertFile "./certs/ca-ecc-cert.pem"
349#define crlPemDir "./certs/crl"
350#define edCertFile "./certs/ed25519/server-ed25519-cert.pem"
351#define edKeyFile "./certs/ed25519/server-ed25519-priv.pem"
352#define cliEdCertFile "./certs/ed25519/client-ed25519.pem"
353#define cliEdKeyFile "./certs/ed25519/client-ed25519-priv.pem"
354#define caEdCertFile "./certs/ed25519/ca-ed25519.pem"
355#define ed448CertFile "./certs/ed448/server-ed448-cert.pem"
356#define ed448KeyFile "./certs/ed448/server-ed448-priv.pem"
357#define cliEd448CertFile "./certs/ed448/client-ed448.pem"
358#define cliEd448KeyFile "./certs/ed448/client-ed448-priv.pem"
359#define caEd448CertFile "./certs/ed448/ca-ed448.pem"
362 #define wnrConfig "./wnr-example.conf"
370#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
371 pthread_mutex_t mutex;
377static WC_INLINE
void InitTcpReady(
tcp_ready* ready)
381 ready->srfName = NULL;
382#ifdef SINGLE_THREADED
383#elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
384 pthread_mutex_init(&ready->mutex, 0);
385 pthread_cond_init(&ready->cond, 0);
390static WC_INLINE
void FreeTcpReady(
tcp_ready* ready)
392#ifdef SINGLE_THREADED
394#elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
395 pthread_mutex_destroy(&ready->mutex);
396 pthread_cond_destroy(&ready->cond);
404typedef void (*ssl_callback)(
WOLFSSL* ssl);
407 method_provider method;
408 ctx_callback ctx_ready;
409 ssl_callback ssl_ready;
410 ssl_callback on_result;
414typedef struct func_args {
425void wait_tcp_ready(func_args*);
428typedef void THREAD_FUNC(
void*,
void*,
void*);
430typedef THREAD_RETURN WOLFSSL_THREAD THREAD_FUNC(
void*);
433void start_thread(THREAD_FUNC, func_args*, THREAD_TYPE*);
434void join_thread(THREAD_TYPE);
438 static const char*
const wolfSSLIP =
"127.0.0.1";
440 static const char*
const wolfSSLIP =
"::1";
442static const word16 wolfSSLPort = 11111;
451#define EXIT_FAILURE 1
454#if defined(WOLFSSL_FORCE_MALLOC_FAIL_TEST) || defined(WOLFSSL_ZEPHYR)
456 #define EXIT_SUCCESS 0
458 #define XEXIT(rc) return rc
459 #define XEXIT_T(rc) return (THREAD_RETURN)rc
461 #define XEXIT(rc) exit((int)(rc))
462 #define XEXIT_T(rc) exit((int)(rc))
467#if defined(WOLFSSL_FORCE_MALLOC_FAIL_TEST) || defined(WOLFSSL_ZEPHYR)
472err_sys(
const char* msg)
474 printf(
"wolfSSL error: %s\n", msg);
476#if !defined(__GNUC__)
486 XEXIT_T(EXIT_FAILURE);
492extern char* myoptarg;
494static WC_INLINE
int mygetopt(
int argc,
char** argv,
const char* optstring)
496 static char* next = NULL;
511 if (next == NULL || *next ==
'\0') {
515 if (myoptind >= argc || argv[myoptind] == NULL ||
516 argv[myoptind][0] !=
'-' || argv[myoptind][1] ==
'\0') {
519 myoptarg = argv[myoptind];
524 if (strcmp(argv[myoptind],
"--") == 0) {
529 myoptarg = argv[myoptind];
534 next = argv[myoptind];
541 cp = (
char*)strchr(optstring, c);
543 if (cp == NULL || c ==
':')
553 else if (myoptind < argc) {
554 myoptarg = argv[myoptind];
565#ifdef WOLFSSL_ENCRYPTED_KEYS
567static WC_INLINE
int PasswordCallBack(
char* passwd,
int sz,
int rw,
void* userdata)
571 if (userdata != NULL) {
572 strncpy(passwd, (
char*)userdata, sz);
573 return (
int)XSTRLEN((
char*)userdata);
576 strncpy(passwd,
"yassl123", sz);
583static const char* client_showpeer_msg[][8] = {
587 "SSL cipher suite is",
590 "SSL reused session",
591 "Alternate cert chain used",
595#ifndef NO_MULTIBYTE_PRINT
610#if defined(KEEP_PEER_CERT) || defined(KEEP_OUR_CERT) || defined(SESSION_CERTS)
611static const char* client_showx509_msg[][5] = {
620#ifndef NO_MULTIBYTE_PRINT
634static WC_INLINE
void ShowX509Ex(
WOLFSSL_X509* x509,
const char* hdr,
642 int sz =
sizeof(serial);
643 const char** words = client_showx509_msg[lng_index];
646 printf(
"%s No Cert\n", hdr);
655 printf(
"%s\n %s : %s\n %s: %s\n", hdr, words[0], issuer, words[1], subject);
658 printf(
" %s = %s\n", words[2], altName);
661 if (ret == WOLFSSL_SUCCESS) {
668 strLen = sprintf(serialMsg,
" %s", words[3]);
669 for (i = 0; i < sz; i++)
670 sprintf(serialMsg + strLen + (i*3),
":%02x ", serial[i]);
671 printf(
"%s\n", serialMsg);
674 XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
675 XFREE(issuer, 0, DYNAMIC_TYPE_OPENSSL);
677#if defined(SHOW_CERTS) && defined(OPENSSL_EXTRA)
688 printf(
"Domain Component = %s\n", buf);
691 bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
694 wolfSSL_X509_print(bio, x509);
695 wolfSSL_BIO_free(bio);
701static WC_INLINE
void ShowX509(
WOLFSSL_X509* x509,
const char* hdr)
703 ShowX509Ex(x509, hdr, 0);
708#if defined(SHOW_CERTS) && defined(SESSION_CERTS) && \
709 (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
715 unsigned char buffer[3072];
718 for (i = 0; i < count; i++) {
721 printf(
"\n%s: %d has length %d data = \n%s\n", hdr, i, length, buffer);
725 ShowX509(chainX509, hdr);
727 printf(
"get_chain_X509 failed\n");
728 wolfSSL_FreeX509(chainX509);
735static WC_INLINE
void showPeerEx(
WOLFSSL* ssl,
int lng_index)
738 const char** words = client_showpeer_msg[lng_index];
740#if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448) || \
750 ShowX509Ex(peer, words[6], lng_index);
752 printf(
"peer has no cert!\n");
753 wolfSSL_FreeX509(peer);
755#if defined(SHOW_CERTS) && defined(KEEP_OUR_CERT) && \
756 (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
757 ShowX509(wolfSSL_get_certificate(ssl),
"our cert info:");
764 printf(
"%s %s%s\n", words[1], (
wolfSSL_isQSH(ssl))?
"QSH:":
"",
769#if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448) || \
771 if ((name = wolfSSL_get_curve_name(ssl)) != NULL)
772 printf(
"%s %s\n", words[2], name);
776 printf(
"%s %d bits\n", words[3], bits);
779 printf(
"%s\n", words[4]);
780#ifdef WOLFSSL_ALT_CERT_CHAINS
781 if (wolfSSL_is_peer_alt_cert_chain(ssl))
782 printf(
"%s\n", words[5]);
785#if defined(SHOW_CERTS) && defined(SESSION_CERTS) && \
786 (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
793 #ifdef WOLFSSL_ALT_CERT_CHAINS
794 if (wolfSSL_is_peer_alt_cert_chain(ssl)) {
795 chain = wolfSSL_get_peer_alt_chain(ssl);
804static WC_INLINE
void showPeer(
WOLFSSL* ssl)
809static WC_INLINE
void build_addr(SOCKADDR_IN_T* addr,
const char* peer,
810 word16 port,
int udp,
int sctp)
818 err_sys(
"invalid argument to build_addr, addr is NULL");
820 XMEMSET(addr, 0,
sizeof(SOCKADDR_IN_T));
824 if ( ((
size_t)peer != INADDR_ANY) && isalpha((
int)peer[0])) {
825 #ifndef WOLFSSL_USE_GETADDRINFO
826 #if defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
828 struct hostent* entry = gethostbyname(peer, &err);
829 #elif defined(WOLFSSL_TIRTOS)
830 struct hostent* entry = DNSGetHostByName(peer);
831 #elif defined(WOLFSSL_VXWORKS)
832 struct hostent* entry = (
struct hostent*)hostGetByName((
char*)peer);
834 struct hostent* entry = gethostbyname(peer);
838 XMEMCPY(&addr->sin_addr.s_addr, entry->h_addr_list[0],
843 struct zsock_addrinfo hints, *addrInfo;
845 XSNPRINTF(portStr,
sizeof(portStr),
"%d", port);
846 memset(&hints, 0,
sizeof(hints));
847 hints.ai_family = AF_UNSPEC;
848 hints.ai_socktype = udp ? SOCK_DGRAM : SOCK_STREAM;
849 hints.ai_protocol = udp ? IPPROTO_UDP : IPPROTO_TCP;
850 if (getaddrinfo((
char*)peer, portStr, &hints, &addrInfo) == 0) {
851 XMEMCPY(addr, addrInfo->ai_addr,
sizeof(*addr));
856 err_sys(
"no entry for host");
862 #if defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
863 addr->sin_family = PF_INET;
865 addr->sin_family = AF_INET_V;
867 addr->sin_port = XHTONS(port);
868 if ((
size_t)peer == INADDR_ANY)
869 addr->sin_addr.s_addr = INADDR_ANY;
872 addr->sin_addr.s_addr = inet_addr(peer);
875 addr->sin6_family = AF_INET_V;
876 addr->sin6_port = XHTONS(port);
877 if ((
size_t)peer == INADDR_ANY) {
878 addr->sin6_addr = in6addr_any;
881 #if defined(HAVE_GETADDRINFO) || defined(WOLF_C99)
882 struct addrinfo hints;
883 struct addrinfo* answer = NULL;
887 XMEMSET(&hints, 0,
sizeof(hints));
889 hints.ai_family = AF_INET_V;
891 hints.ai_socktype = SOCK_DGRAM;
892 hints.ai_protocol = IPPROTO_UDP;
896 hints.ai_socktype = SOCK_STREAM;
897 hints.ai_protocol = IPPROTO_SCTP;
901 hints.ai_socktype = SOCK_STREAM;
902 hints.ai_protocol = IPPROTO_TCP;
905 SNPRINTF(strPort,
sizeof(strPort),
"%d", port);
908 ret = getaddrinfo(peer, strPort, &hints, &answer);
909 if (ret < 0 || answer == NULL)
910 err_sys(
"getaddrinfo failed");
912 XMEMCPY(addr, answer->ai_addr, answer->ai_addrlen);
913 freeaddrinfo(answer);
915 printf(
"no ipv6 getaddrinfo, loopback only tests/examples\n");
916 addr->sin6_addr = in6addr_loopback;
923static WC_INLINE
void tcp_socket(SOCKET_T* sockfd,
int udp,
int sctp)
928 *sockfd = socket(AF_INET_V, SOCK_DGRAM, IPPROTO_UDP);
931 *sockfd = socket(AF_INET_V, SOCK_STREAM, IPPROTO_SCTP);
934 *sockfd = socket(AF_INET_V, SOCK_STREAM, IPPROTO_TCP);
936 if(WOLFSSL_SOCKET_IS_INVALID(*sockfd)) {
937 err_sys(
"socket failed\n");
940#ifndef USE_WINDOWS_API
944 socklen_t len =
sizeof(on);
945 int res = setsockopt(*sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on, len);
947 err_sys(
"setsockopt SO_NOSIGPIPE failed\n");
949#elif defined(WOLFSSL_MDK_ARM) || defined (WOLFSSL_TIRTOS) ||\
950 defined(WOLFSSL_KEIL_TCP_NET) || defined(WOLFSSL_ZEPHYR)
953 signal(SIGPIPE, SIG_IGN);
956#if defined(TCP_NODELAY)
960 socklen_t len =
sizeof(on);
961 int res = setsockopt(*sockfd, IPPROTO_TCP, TCP_NODELAY, &on, len);
963 err_sys(
"setsockopt TCP_NODELAY failed\n");
969static WC_INLINE
void tcp_connect(SOCKET_T* sockfd,
const char* ip, word16 port,
970 int udp,
int sctp,
WOLFSSL* ssl)
973 build_addr(&addr, ip, port, udp, sctp);
975 wolfSSL_dtls_set_peer(ssl, &addr,
sizeof(addr));
977 tcp_socket(sockfd, udp, sctp);
980 if (connect(*sockfd, (
const struct sockaddr*)&addr,
sizeof(addr)) != 0)
981 err_sys(
"tcp connect failed");
986static WC_INLINE
void udp_connect(SOCKET_T* sockfd,
void* addr,
int addrSz)
988 if (connect(*sockfd, (
const struct sockaddr*)addr, addrSz) != 0)
989 err_sys(
"tcp connect failed");
1002#if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_TCP_NET) && \
1003 !defined(WOLFSSL_TIRTOS)
1004static WC_INLINE
int tcp_select_ex(SOCKET_T socketfd,
int to_sec,
int rx)
1009 SOCKET_T nfds = socketfd + 1;
1010#if !defined(__INTEGRITY)
1011 struct timeval timeout = {(to_sec > 0) ? to_sec : 0, 0};
1018 FD_SET(socketfd, &fds);
1020 FD_SET(socketfd, &errfds);
1027#if defined(__INTEGRITY)
1028 timeout.tv_sec = (
long long)(to_sec > 0) ? to_sec : 0, 0;
1030 result = select(nfds, recvfds, sendfds, &errfds, &timeout);
1033 return TEST_TIMEOUT;
1034 else if (result > 0) {
1035 if (FD_ISSET(socketfd, &fds)) {
1037 return TEST_RECV_READY;
1039 return TEST_SEND_READY;
1041 else if(FD_ISSET(socketfd, &errfds))
1042 return TEST_ERROR_READY;
1045 return TEST_SELECT_FAIL;
1048static WC_INLINE
int tcp_select(SOCKET_T socketfd,
int to_sec)
1050 return tcp_select_ex(socketfd, to_sec, 1);
1053static WC_INLINE
int tcp_select_tx(SOCKET_T socketfd,
int to_sec)
1055 return tcp_select_ex(socketfd, to_sec, 0);
1058#elif defined(WOLFSSL_TIRTOS) || defined(WOLFSSL_KEIL_TCP_NET)
1059static WC_INLINE
int tcp_select(SOCKET_T socketfd,
int to_sec)
1061 return TEST_RECV_READY;
1063static WC_INLINE
int tcp_select_tx(SOCKET_T socketfd,
int to_sec)
1065 return TEST_SEND_READY;
1070static WC_INLINE
void tcp_listen(SOCKET_T* sockfd, word16* port,
int useAnyAddr,
1077 build_addr(&addr, (useAnyAddr ? INADDR_ANY : wolfSSLIP), *port, udp, sctp);
1078 tcp_socket(sockfd, udp, sctp);
1080#if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_MDK_ARM)\
1081 && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_ZEPHYR)
1084 socklen_t len =
sizeof(on);
1085 res = setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR, &on, len);
1087 err_sys(
"setsockopt SO_REUSEADDR failed\n");
1091 if (bind(*sockfd, (
const struct sockaddr*)&addr,
sizeof(addr)) != 0)
1092 err_sys(
"tcp bind failed");
1094 #ifdef WOLFSSL_KEIL_TCP_NET
1095 #define SOCK_LISTEN_MAX_QUEUE 1
1097 #define SOCK_LISTEN_MAX_QUEUE 5
1099 if (listen(*sockfd, SOCK_LISTEN_MAX_QUEUE) != 0)
1100 err_sys(
"tcp listen failed");
1102 #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS) \
1103 && !defined(WOLFSSL_ZEPHYR)
1105 socklen_t len =
sizeof(addr);
1106 if (getsockname(*sockfd, (
struct sockaddr*)&addr, &len) == 0) {
1108 *port = XNTOHS(addr.sin_port);
1110 *port = XNTOHS(addr.sin6_port);
1119static WC_INLINE
int udp_read_connect(SOCKET_T sockfd)
1121 SOCKADDR_IN_T cliaddr;
1124 socklen_t len =
sizeof(cliaddr);
1126 n = (int)recvfrom(sockfd, (
char*)b,
sizeof(b), MSG_PEEK,
1127 (
struct sockaddr*)&cliaddr, &len);
1129 if (connect(sockfd, (
const struct sockaddr*)&cliaddr,
1130 sizeof(cliaddr)) != 0)
1131 err_sys(
"udp connect failed");
1134 err_sys(
"recvfrom failed");
1140static WC_INLINE
void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
1141 int useAnyAddr, word16 port, func_args* args)
1146 build_addr(&addr, (useAnyAddr ? INADDR_ANY : wolfSSLIP), port, 1, 0);
1147 tcp_socket(sockfd, 1, 0);
1150#if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_MDK_ARM) \
1151 && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_ZEPHYR)
1154 socklen_t len =
sizeof(on);
1155 res = setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR, &on, len);
1157 err_sys(
"setsockopt SO_REUSEADDR failed\n");
1161 if (bind(*sockfd, (
const struct sockaddr*)&addr,
sizeof(addr)) != 0)
1162 err_sys(
"tcp bind failed");
1164 #if (defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API)) && !defined(WOLFSSL_TIRTOS)
1166 socklen_t len =
sizeof(addr);
1167 if (getsockname(*sockfd, (
struct sockaddr*)&addr, &len) == 0) {
1169 port = XNTOHS(addr.sin_port);
1171 port = XNTOHS(addr.sin6_port);
1177#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && !defined(__MINGW32__)
1181 pthread_mutex_lock(&ready->mutex);
1184 pthread_cond_signal(&ready->cond);
1185 pthread_mutex_unlock(&ready->mutex);
1187#elif defined (WOLFSSL_TIRTOS)
1196 *clientfd = *sockfd;
1199static WC_INLINE
void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
1200 func_args* args, word16 port,
int useAnyAddr,
1201 int udp,
int sctp,
int ready_file,
int do_listen)
1203 SOCKADDR_IN_T client;
1204 socklen_t client_len =
sizeof(client);
1210 udp_accept(sockfd, clientfd, useAnyAddr, port, args);
1215 tcp_listen(sockfd, &port, useAnyAddr, udp, sctp);
1217 #if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && !defined(__MINGW32__)
1220 ready = args->signal;
1222 pthread_mutex_lock(&ready->mutex);
1225 pthread_cond_signal(&ready->cond);
1226 pthread_mutex_unlock(&ready->mutex);
1228 #elif defined (WOLFSSL_TIRTOS)
1231 ready = args->signal;
1239 #if !defined(NO_FILESYSTEM) || defined(FORCE_BUFFER_TEST)
1242 ready = args->signal;
1245 srf = XFOPEN(ready->srfName,
"w");
1253 fprintf(srf,
"%d\n", (
int)port);
1261 *clientfd = accept(*sockfd, (
struct sockaddr*)&client,
1262 (ACCEPT_THIRD_T)&client_len);
1263 if(WOLFSSL_SOCKET_IS_INVALID(*clientfd)) {
1264 err_sys(
"tcp accept failed");
1269static WC_INLINE
void tcp_set_nonblocking(SOCKET_T* sockfd)
1271 #ifdef USE_WINDOWS_API
1272 unsigned long blocking = 1;
1273 int ret = ioctlsocket(*sockfd, FIONBIO, &blocking);
1274 if (ret == SOCKET_ERROR)
1275 err_sys(
"ioctlsocket failed");
1276 #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) \
1277 || defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \
1278 || defined(WOLFSSL_ZEPHYR)
1281 int flags = fcntl(*sockfd, F_GETFL, 0);
1283 err_sys(
"fcntl get failed");
1284 flags = fcntl(*sockfd, F_SETFL, flags | O_NONBLOCK);
1286 err_sys(
"fcntl set failed");
1294static const char* kIdentityStr =
"Client_identity";
1296static WC_INLINE
unsigned int my_psk_client_cb(
WOLFSSL* ssl,
const char* hint,
1297 char* identity,
unsigned int id_max_len,
unsigned char* key,
1298 unsigned int key_max_len)
1305 strncpy(identity, kIdentityStr, id_max_len);
1307 if (wolfSSL_GetVersion(ssl) < WOLFSSL_TLSV1_3) {
1321 for (i = 0; i < 32; i++, b += 0x22) {
1332static WC_INLINE
unsigned int my_psk_server_cb(
WOLFSSL* ssl,
const char* identity,
1333 unsigned char* key,
unsigned int key_max_len)
1339 if (strncmp(identity, kIdentityStr, strlen(kIdentityStr)) != 0)
1342 if (wolfSSL_GetVersion(ssl) < WOLFSSL_TLSV1_3) {
1356 for (i = 0; i < 32; i++, b += 0x22) {
1367static WC_INLINE
unsigned int my_psk_client_tls13_cb(
WOLFSSL* ssl,
1368 const char* hint,
char* identity,
unsigned int id_max_len,
1369 unsigned char* key,
unsigned int key_max_len,
const char** ciphersuite)
1379 strncpy(identity, kIdentityStr, id_max_len);
1381 for (i = 0; i < 32; i++, b += 0x22) {
1387 *ciphersuite =
"TLS13-AES128-GCM-SHA256";
1393static WC_INLINE
unsigned int my_psk_server_tls13_cb(
WOLFSSL* ssl,
1394 const char* identity,
unsigned char* key,
unsigned int key_max_len,
1395 const char** ciphersuite)
1404 if (strncmp(identity, kIdentityStr, strlen(kIdentityStr)) != 0)
1407 for (i = 0; i < 32; i++, b += 0x22) {
1413 *ciphersuite =
"TLS13-AES128-GCM-SHA256";
1421#if defined(WOLFSSL_USER_CURRTIME)
1422 extern double current_time(
int reset);
1424#elif defined(USE_WINDOWS_API)
1426 #define WIN32_LEAN_AND_MEAN
1427 #include <windows.h>
1429 static WC_INLINE
double current_time(
int reset)
1431 static int init = 0;
1432 static LARGE_INTEGER freq;
1434 LARGE_INTEGER count;
1437 QueryPerformanceFrequency(&freq);
1441 QueryPerformanceCounter(&count);
1444 return (
double)count.QuadPart / freq.QuadPart;
1447#elif defined(WOLFSSL_TIRTOS)
1448 extern double current_time();
1449#elif defined(WOLFSSL_ZEPHYR)
1450 extern double current_time();
1453#if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_CHIBIOS)
1454 #include <sys/time.h>
1456 static WC_INLINE
double current_time(
int reset)
1459 gettimeofday(&tv, 0);
1462 return (
double)tv.tv_sec + (double)tv.tv_usec / 1000000;
1465 extern double current_time(
int reset);
1470#if defined(HAVE_OCSP) && defined(WOLFSSL_NONBLOCK_OCSP)
1471static WC_INLINE
int OCSPIOCb(
void* ioCtx,
const char* url,
int urlSz,
1472 unsigned char* request,
int requestSz,
unsigned char** response)
1474#ifdef TEST_NONBLOCK_CERTS
1475 static int ioCbCnt = 0;
1485#ifdef TEST_NONBLOCK_CERTS
1488 return EmbedOcspLookup(ioCtx, url, urlSz, request, requestSz, response);
1492 return WOLFSSL_CBIO_ERR_WANT_READ;
1495 return EmbedOcspLookup(ioCtx, url, urlSz, request, requestSz, response);
1499static WC_INLINE
void OCSPRespFreeCb(
void* ioCtx,
unsigned char* response)
1506#if !defined(NO_CERTS)
1507 #if !defined(NO_FILESYSTEM) || \
1508 (defined(NO_FILESYSTEM) && defined(FORCE_BUFFER_TEST))
1511 static WC_INLINE
int load_file(
const char* fname,
byte** buf,
size_t* bufLen)
1517 if (fname == NULL || buf == NULL || bufLen == NULL)
1518 return BAD_FUNC_ARG;
1525 file = XFOPEN(fname,
"rb");
1527 printf(
"Error loading %s\n", fname);
1528 return BAD_PATH_ERROR;
1531 fseek(file, 0, SEEK_END);
1532 fileSz = (int)ftell(file);
1535 *bufLen = (size_t)fileSz;
1536 *buf = (
byte*)malloc(*bufLen);
1539 printf(
"Error allocating %lu bytes\n", (
unsigned long)*bufLen);
1542 size_t readLen = fread(*buf, *bufLen, 1, file);
1545 ret = (readLen > 0) ? 0 : -1;
1560 WOLFSSL_CERT_CHAIN = 4,
1563 static WC_INLINE
void load_buffer(
WOLFSSL_CTX* ctx,
const char* fname,
int type)
1565 int format = WOLFSSL_FILETYPE_PEM;
1569 if (load_file(fname, &buff, &sz) != 0) {
1570 err_sys(
"can't open file for buffer load "
1571 "Please run from wolfSSL home directory if not");
1575 if (strstr(fname,
".der"))
1576 format = WOLFSSL_FILETYPE_ASN1;
1578 if (type == WOLFSSL_CA) {
1581 err_sys(
"can't load buffer ca file");
1583 else if (type == WOLFSSL_CERT) {
1585 format) != WOLFSSL_SUCCESS)
1586 err_sys(
"can't load buffer cert file");
1588 else if (type == WOLFSSL_KEY) {
1590 format) != WOLFSSL_SUCCESS)
1591 err_sys(
"can't load buffer key file");
1593 else if (type == WOLFSSL_CERT_CHAIN) {
1594 if (wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, buff,
1595 (
long)sz, format) != WOLFSSL_SUCCESS)
1596 err_sys(
"can't load cert chain buffer");
1603 static WC_INLINE
void load_ssl_buffer(
WOLFSSL* ssl,
const char* fname,
int type)
1605 int format = WOLFSSL_FILETYPE_PEM;
1609 if (load_file(fname, &buff, &sz) != 0) {
1610 err_sys(
"can't open file for buffer load "
1611 "Please run from wolfSSL home directory if not");
1615 if (strstr(fname,
".der"))
1616 format = WOLFSSL_FILETYPE_ASN1;
1618 if (type == WOLFSSL_CA) {
1623 err_sys(
"can't load buffer ca file");
1625 else if (type == WOLFSSL_CERT) {
1627 format) != WOLFSSL_SUCCESS)
1628 err_sys(
"can't load buffer cert file");
1630 else if (type == WOLFSSL_KEY) {
1632 format) != WOLFSSL_SUCCESS)
1633 err_sys(
"can't load buffer key file");
1635 else if (type == WOLFSSL_CERT_CHAIN) {
1636 if (wolfSSL_use_certificate_chain_buffer_format(ssl, buff,
1637 (
long)sz, format) != WOLFSSL_SUCCESS)
1638 err_sys(
"can't load cert chain buffer");
1645 #ifdef TEST_PK_PRIVKEY
1646 static WC_INLINE
int load_key_file(
const char* fname,
byte** derBuf, word32* derLen)
1652 ret = load_file(fname, &buf, &bufLen);
1656 *derBuf = (
byte*)malloc(bufLen);
1657 if (*derBuf == NULL) {
1662 ret =
wc_KeyPemToDer(buf, (word32)bufLen, *derBuf, (word32)bufLen, NULL);
1678static int myVerifyFail = 0;
1689 char buffer[WOLFSSL_MAX_ERROR_SZ];
1690#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
1692#if defined(SHOW_CERTS) && !defined(NO_FILESYSTEM)
1716 printf(
"In verification callback, error = %d, %s\n", store->error,
1718#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
1719 peer = store->current_cert;
1725 printf(
"\tPeer's cert info:\n issuer : %s\n subject: %s\n", issuer,
1727 XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
1728 XFREE(issuer, 0, DYNAMIC_TYPE_OPENSSL);
1729#if defined(SHOW_CERTS) && !defined(NO_FILESYSTEM)
1731 if (store->depth == 1) {
1733 sk = wolfSSL_X509_STORE_GetCerts(store);
1735 for (i = 0; i < wolfSSL_sk_X509_num(sk); i++) {
1736 x509 = wolfSSL_sk_X509_value(sk, i);
1737 bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
1740 wolfSSL_X509_print(bio, x509);
1741 wolfSSL_BIO_free(bio);
1744 wolfSSL_sk_X509_free(sk);
1749 printf(
"\tPeer has no cert!\n");
1751 printf(
"\tPeer certs: %d\n", store->totalCerts);
1754 for (i=0; i<store->totalCerts; i++) {
1756 printf(
"\t\tCert %d: Ptr %p, Len %u\n", i, cert->buffer, cert->length);
1762 printf(
"\tSubject's domain name at %d is %s\n", store->error_depth, store->domain);
1770 if (store->error != 0) {
1771 printf(
"\tAllowing failed certificate check, testing only "
1772 "(shouldn't do this in production)\n");
1782 char buffer[WOLFSSL_MAX_ERROR_SZ];
1785 printf(
"In verification callback, error = %d, %s\n", store->error,
1787 printf(
"Subject's domain name is %s\n", store->domain);
1789 if (store->error == ASN_BEFORE_DATE_E || store->error == ASN_AFTER_DATE_E) {
1790 printf(
"Overriding cert date error as example for bad clock testing\n");
1793 printf(
"Cert error is not date error, not overriding\n");
1799#ifdef HAVE_EXT_CACHE
1802 int id_len,
int* copy)
1835static WC_INLINE
void CRL_CallBack(
const char* url)
1837 printf(
"CRL callback url = %s\n", url);
1843static WC_INLINE
void SetDH(
WOLFSSL* ssl)
1846 static const unsigned char p[] =
1848 0xE6, 0x96, 0x9D, 0x3D, 0x49, 0x5B, 0xE3, 0x2C, 0x7C, 0xF1, 0x80, 0xC3,
1849 0xBD, 0xD4, 0x79, 0x8E, 0x91, 0xB7, 0x81, 0x82, 0x51, 0xBB, 0x05, 0x5E,
1850 0x2A, 0x20, 0x64, 0x90, 0x4A, 0x79, 0xA7, 0x70, 0xFA, 0x15, 0xA2, 0x59,
1851 0xCB, 0xD5, 0x23, 0xA6, 0xA6, 0xEF, 0x09, 0xC4, 0x30, 0x48, 0xD5, 0xA2,
1852 0x2F, 0x97, 0x1F, 0x3C, 0x20, 0x12, 0x9B, 0x48, 0x00, 0x0E, 0x6E, 0xDD,
1853 0x06, 0x1C, 0xBC, 0x05, 0x3E, 0x37, 0x1D, 0x79, 0x4E, 0x53, 0x27, 0xDF,
1854 0x61, 0x1E, 0xBB, 0xBE, 0x1B, 0xAC, 0x9B, 0x5C, 0x60, 0x44, 0xCF, 0x02,
1855 0x3D, 0x76, 0xE0, 0x5E, 0xEA, 0x9B, 0xAD, 0x99, 0x1B, 0x13, 0xA6, 0x3C,
1856 0x97, 0x4E, 0x9E, 0xF1, 0x83, 0x9E, 0xB5, 0xDB, 0x12, 0x51, 0x36, 0xF7,
1857 0x26, 0x2E, 0x56, 0xA8, 0x87, 0x15, 0x38, 0xDF, 0xD8, 0x23, 0xC6, 0x50,
1858 0x50, 0x85, 0xE2, 0x1F, 0x0D, 0xD5, 0xC8, 0x6B,
1862 static const unsigned char g[] =
1873 static const unsigned char p[] =
1875 0xE6, 0x96, 0x9D, 0x3D, 0x49, 0x5B, 0xE3, 0x2C, 0x7C, 0xF1, 0x80, 0xC3,
1876 0xBD, 0xD4, 0x79, 0x8E, 0x91, 0xB7, 0x81, 0x82, 0x51, 0xBB, 0x05, 0x5E,
1877 0x2A, 0x20, 0x64, 0x90, 0x4A, 0x79, 0xA7, 0x70, 0xFA, 0x15, 0xA2, 0x59,
1878 0xCB, 0xD5, 0x23, 0xA6, 0xA6, 0xEF, 0x09, 0xC4, 0x30, 0x48, 0xD5, 0xA2,
1879 0x2F, 0x97, 0x1F, 0x3C, 0x20, 0x12, 0x9B, 0x48, 0x00, 0x0E, 0x6E, 0xDD,
1880 0x06, 0x1C, 0xBC, 0x05, 0x3E, 0x37, 0x1D, 0x79, 0x4E, 0x53, 0x27, 0xDF,
1881 0x61, 0x1E, 0xBB, 0xBE, 0x1B, 0xAC, 0x9B, 0x5C, 0x60, 0x44, 0xCF, 0x02,
1882 0x3D, 0x76, 0xE0, 0x5E, 0xEA, 0x9B, 0xAD, 0x99, 0x1B, 0x13, 0xA6, 0x3C,
1883 0x97, 0x4E, 0x9E, 0xF1, 0x83, 0x9E, 0xB5, 0xDB, 0x12, 0x51, 0x36, 0xF7,
1884 0x26, 0x2E, 0x56, 0xA8, 0x87, 0x15, 0x38, 0xDF, 0xD8, 0x23, 0xC6, 0x50,
1885 0x50, 0x85, 0xE2, 0x1F, 0x0D, 0xD5, 0xC8, 0x6B,
1889 static const unsigned char g[] =
1900static WC_INLINE
void CaCb(
unsigned char* der,
int sz,
int type)
1903 printf(
"Got CA cache add callback, derSz = %d, type = %d\n", sz, type);
1911#if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_FS) && !defined(WOLFSSL_TIRTOS)
1913 #define MAX_WOLF_ROOT_DEPTH 5
1915 static WC_INLINE
int ChangeToWolfRoot(
void)
1917 #if !defined(NO_FILESYSTEM) || defined(FORCE_BUFFER_TEST)
1920 for(depth = 0; depth <= MAX_WOLF_ROOT_DEPTH; depth++) {
1921 file = XFOPEN(ntruKeyFile,
"rb");
1926 #ifdef USE_WINDOWS_API
1927 res = SetCurrentDirectoryA(
"..\\");
1932 printf(
"chdir to ../ failed!\n");
1937 err_sys(
"wolf root not found");
1945#ifdef HAVE_STACK_SIZE
1947typedef THREAD_RETURN WOLFSSL_THREAD (*thread_func)(
void* args);
1948#define STACK_CHECK_VAL 0x01
1950static WC_INLINE
int StackSizeCheck(func_args* args, thread_func tf)
1954 unsigned char* myStack = NULL;
1955 int stackSize = 1024*152;
1956 pthread_attr_t myAttr;
1959#ifdef PTHREAD_STACK_MIN
1960 if (stackSize < PTHREAD_STACK_MIN)
1961 stackSize = PTHREAD_STACK_MIN;
1964 ret = posix_memalign((
void**)&myStack, sysconf(_SC_PAGESIZE), stackSize);
1965 if (ret != 0 || myStack == NULL)
1966 err_sys(
"posix_memalign failed\n");
1968 XMEMSET(myStack, STACK_CHECK_VAL, stackSize);
1970 ret = pthread_attr_init(&myAttr);
1972 err_sys(
"attr_init failed");
1974 ret = pthread_attr_setstack(&myAttr, myStack, stackSize);
1976 err_sys(
"attr_setstackaddr failed");
1978 ret = pthread_create(&threadId, &myAttr, tf, args);
1980 perror(
"pthread_create failed");
1984 ret = pthread_join(threadId, &status);
1986 err_sys(
"pthread_join failed");
1988 for (i = 0; i < stackSize; i++) {
1989 if (myStack[i] != STACK_CHECK_VAL) {
1996 used = stackSize - i;
1997 printf(
"stack used = %d\n", used);
1999 return (
int)((size_t)status);
2013#ifdef HAVE_STACK_SIZE
2016 #error "can't use STACK_TRAP with STACK_SIZE, setrlimit will fail"
2019static WC_INLINE
void StackTrap(
void)
2022 if (getrlimit(RLIMIT_STACK, &rl) != 0)
2023 err_sys(
"getrlimit failed");
2024 printf(
"rlim_cur = %llu\n", rl.rlim_cur);
2025 rl.rlim_cur = 1024*21;
2026 if (setrlimit(RLIMIT_STACK, &rl) != 0) {
2027 perror(
"setrlimit");
2028 err_sys(
"setrlimit failed");
2034static WC_INLINE
void StackTrap(
void)
2041#if defined(ATOMIC_USER) && !defined(WOLFSSL_AEAD_ONLY)
2057static WC_INLINE
int myMacEncryptCb(
WOLFSSL* ssl,
unsigned char* macOut,
2058 const unsigned char* macIn,
unsigned int macInSz,
int macContent,
2059 int macVerify,
unsigned char* encOut,
const unsigned char* encIn,
2060 unsigned int encSz,
void* ctx)
2064 byte myInner[WOLFSSL_TLS_HMAC_INNER_SZ];
2066 const char* tlsStr =
"TLS";
2069 if (wolfSSL_GetBulkCipher(ssl) != wolfssl_aes) {
2070 printf(
"myMacEncryptCb not using AES\n");
2075 printf(
"myMacEncryptCb not using (D)TLS\n");
2080 wolfSSL_SetTlsHmacInner(ssl, myInner, macInSz, macContent, macVerify);
2082 ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
2086 wolfSSL_GetMacSecret(ssl, macVerify), wolfSSL_GetHmacSize(ssl));
2101 if (encCtx->keySetup == 0) {
2102 int keyLen = wolfSSL_GetKeySize(ssl);
2106 if (wolfSSL_GetSide(ssl) == WOLFSSL_CLIENT_END) {
2107 key = wolfSSL_GetClientWriteKey(ssl);
2108 iv = wolfSSL_GetClientWriteIV(ssl);
2111 key = wolfSSL_GetServerWriteKey(ssl);
2112 iv = wolfSSL_GetServerWriteIV(ssl);
2115 ret =
wc_AesSetKey(&encCtx->aes, key, keyLen, iv, AES_ENCRYPTION);
2117 printf(
"AesSetKey failed in myMacEncryptCb\n");
2120 encCtx->keySetup = 1;
2128static WC_INLINE
int myDecryptVerifyCb(
WOLFSSL* ssl,
2129 unsigned char* decOut,
const unsigned char* decIn,
2130 unsigned int decSz,
int macContent,
int macVerify,
2131 unsigned int* padSz,
void* ctx)
2137 int digestSz = wolfSSL_GetHmacSize(ssl);
2138 unsigned int pad = 0;
2139 unsigned int padByte = 0;
2141 byte myInner[WOLFSSL_TLS_HMAC_INNER_SZ];
2142 byte verify[WC_MAX_DIGEST_SIZE];
2143 const char* tlsStr =
"TLS";
2146 if (wolfSSL_GetBulkCipher(ssl) != wolfssl_aes) {
2147 printf(
"myMacEncryptCb not using AES\n");
2152 printf(
"myMacEncryptCb not using (D)TLS\n");
2157 if (decCtx->keySetup == 0) {
2158 int keyLen = wolfSSL_GetKeySize(ssl);
2163 if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
2164 key = wolfSSL_GetClientWriteKey(ssl);
2165 iv = wolfSSL_GetClientWriteIV(ssl);
2168 key = wolfSSL_GetServerWriteKey(ssl);
2169 iv = wolfSSL_GetServerWriteIV(ssl);
2172 ret =
wc_AesSetKey(&decCtx->aes, key, keyLen, iv, AES_DECRYPTION);
2174 printf(
"AesSetKey failed in myDecryptVerifyCb\n");
2177 decCtx->keySetup = 1;
2185 if (wolfSSL_GetCipherType(ssl) == WOLFSSL_AEAD_TYPE) {
2186 *padSz = wolfSSL_GetAeadMacSize(ssl);
2190 if (wolfSSL_GetCipherType(ssl) == WOLFSSL_BLOCK_TYPE) {
2191 pad = *(decOut + decSz - 1);
2193 if (wolfSSL_IsTLSv1_1(ssl))
2194 ivExtra = wolfSSL_GetCipherBlockSize(ssl);
2197 *padSz = wolfSSL_GetHmacSize(ssl) + pad + padByte;
2198 macInSz = decSz - ivExtra - digestSz - pad - padByte;
2200 wolfSSL_SetTlsHmacInner(ssl, myInner, macInSz, macContent, macVerify);
2202 ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
2206 wolfSSL_GetMacSecret(ssl, macVerify), digestSz);
2219 if (XMEMCMP(verify, decOut + decSz - digestSz - pad - padByte,
2221 printf(
"myDecryptVerify verify failed\n");
2228#if defined(HAVE_ENCRYPT_THEN_MAC)
2230static WC_INLINE
int myEncryptMacCb(
WOLFSSL* ssl,
unsigned char* macOut,
2231 int content,
int macVerify,
unsigned char* encOut,
2232 const unsigned char* encIn,
unsigned int encSz,
void* ctx)
2237 byte myInner[WOLFSSL_TLS_HMAC_INNER_SZ];
2238 const char* tlsStr =
"TLS";
2241 if (wolfSSL_GetBulkCipher(ssl) != wolfssl_aes) {
2242 printf(
"myMacEncryptCb not using AES\n");
2247 printf(
"myMacEncryptCb not using (D)TLS\n");
2252 if (encCtx->keySetup == 0) {
2253 int keyLen = wolfSSL_GetKeySize(ssl);
2257 if (wolfSSL_GetSide(ssl) == WOLFSSL_CLIENT_END) {
2258 key = wolfSSL_GetClientWriteKey(ssl);
2259 iv = wolfSSL_GetClientWriteIV(ssl);
2262 key = wolfSSL_GetServerWriteKey(ssl);
2263 iv = wolfSSL_GetServerWriteIV(ssl);
2266 ret =
wc_AesSetKey(&encCtx->aes, key, keyLen, iv, AES_ENCRYPTION);
2268 printf(
"AesSetKey failed in myMacEncryptCb\n");
2271 encCtx->keySetup = 1;
2280 wolfSSL_SetTlsHmacInner(ssl, myInner, encSz, content, macVerify);
2282 ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
2286 wolfSSL_GetMacSecret(ssl, macVerify), wolfSSL_GetHmacSize(ssl));
2299static WC_INLINE
int myVerifyDecryptCb(
WOLFSSL* ssl,
2300 unsigned char* decOut,
const unsigned char* decIn,
2301 unsigned int decSz,
int content,
int macVerify,
2302 unsigned int* padSz,
void* ctx)
2306 int digestSz = wolfSSL_GetHmacSize(ssl);
2308 byte myInner[WOLFSSL_TLS_HMAC_INNER_SZ];
2309 byte verify[WC_MAX_DIGEST_SIZE];
2310 const char* tlsStr =
"TLS";
2313 if (wolfSSL_GetBulkCipher(ssl) != wolfssl_aes) {
2314 printf(
"myMacEncryptCb not using AES\n");
2319 printf(
"myMacEncryptCb not using (D)TLS\n");
2324 wolfSSL_SetTlsHmacInner(ssl, myInner, decSz, content, macVerify);
2326 ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
2330 wolfSSL_GetMacSecret(ssl, macVerify), digestSz);
2343 if (XMEMCMP(verify, decOut + decSz, digestSz) != 0) {
2344 printf(
"myDecryptVerify verify failed\n");
2349 if (decCtx->keySetup == 0) {
2350 int keyLen = wolfSSL_GetKeySize(ssl);
2355 if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
2356 key = wolfSSL_GetClientWriteKey(ssl);
2357 iv = wolfSSL_GetClientWriteIV(ssl);
2360 key = wolfSSL_GetServerWriteKey(ssl);
2361 iv = wolfSSL_GetServerWriteIV(ssl);
2364 ret =
wc_AesSetKey(&decCtx->aes, key, keyLen, iv, AES_DECRYPTION);
2366 printf(
"AesSetKey failed in myDecryptVerifyCb\n");
2369 decCtx->keySetup = 1;
2377 *padSz = *(decOut + decSz - 1) + 1;
2392 err_sys(
"AtomicEncCtx malloc failed");
2396 if (decCtx == NULL) {
2398 err_sys(
"AtomicDecCtx malloc failed");
2402 wolfSSL_CTX_SetMacEncryptCb(ctx, myMacEncryptCb);
2403 wolfSSL_SetMacEncryptCtx(ssl, encCtx);
2405 wolfSSL_CTX_SetDecryptVerifyCb(ctx, myDecryptVerifyCb);
2406 wolfSSL_SetDecryptVerifyCtx(ssl, decCtx);
2408#if defined(HAVE_ENCRYPT_THEN_MAC)
2409 wolfSSL_CTX_SetEncryptMacCb(ctx, myEncryptMacCb);
2410 wolfSSL_SetEncryptMacCtx(ssl, encCtx);
2412 wolfSSL_CTX_SetVerifyDecryptCb(ctx, myVerifyDecryptCb);
2413 wolfSSL_SetVerifyDecryptCtx(ssl, decCtx);
2418static WC_INLINE
void FreeAtomicUser(
WOLFSSL* ssl)
2431#ifdef WOLFSSL_STATIC_MEMORY
2436 if (stats == NULL) {
2441 fprintf(stderr,
"Total mallocs = %d\n", stats->totalAlloc);
2442 fprintf(stderr,
"Total frees = %d\n", stats->totalFr);
2443 fprintf(stderr,
"Current mallocs = %d\n", stats->curAlloc);
2444 fprintf(stderr,
"Available IO = %d\n", stats->avaIO);
2445 fprintf(stderr,
"Max con. handshakes = %d\n", stats->maxHa);
2446 fprintf(stderr,
"Max con. IO = %d\n", stats->maxIO);
2447 fprintf(stderr,
"State of memory blocks: size : available \n");
2448 for (i = 0; i < WOLFMEM_MAX_BUCKETS; i++) {
2449 fprintf(stderr,
" : %d\t : %d\n", stats->blockSz[i],
2450 stats->avaBlock[i]);
2457#ifdef HAVE_PK_CALLBACKS
2461#ifdef TEST_PK_PRIVKEY
2466 #ifdef HAVE_CURVE25519
2469 #ifdef HAVE_CURVE448
2476#if defined(DEBUG_PK_CB) || defined(TEST_PK_PRIVKEY)
2477 #define WOLFSSL_PKMSG(_f_, ...) printf(_f_, ##__VA_ARGS__)
2479 #define WOLFSSL_PKMSG(_f_, ...)
2484static WC_INLINE
int myEccKeyGen(
WOLFSSL* ssl,
ecc_key* key, word32 keySz,
2485 int ecc_curve,
void* ctx)
2491#ifdef TEST_PK_PRIVKEY
2492 byte qx[MAX_ECC_BYTES], qy[MAX_ECC_BYTES];
2493 word32 qxLen =
sizeof(qx), qyLen =
sizeof(qy);
2495 new_key = &cbInfo->keyGen.ecc;
2503 WOLFSSL_PKMSG(
"PK ECC KeyGen: keySz %d, Curve ID %d\n", keySz, ecc_curve);
2514 #ifdef TEST_PK_PRIVKEY
2517 ret = wc_ecc_export_public_raw(new_key, qx, &qxLen, qy, &qyLen);
2520 ret = wc_ecc_import_unsigned(key, qx, qy, NULL, ecc_curve);
2528 WOLFSSL_PKMSG(
"PK ECC KeyGen: ret %d\n", ret);
2535static WC_INLINE
int myEccSign(
WOLFSSL* ssl,
const byte* in, word32 inSz,
2536 byte* out, word32* outSz,
const byte* key, word32 keySz,
void* ctx)
2542 byte* keyBuf = (
byte*)key;
2548 WOLFSSL_PKMSG(
"PK ECC Sign: inSz %d, keySz %d\n", inSz, keySz);
2550#ifdef TEST_PK_PRIVKEY
2551 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
2564 WOLFSSL_PKMSG(
"PK ECC Sign: Curve ID %d\n", myKey.dp->id);
2571#ifdef TEST_PK_PRIVKEY
2575 WOLFSSL_PKMSG(
"PK ECC Sign: ret %d outSz %d\n", ret, *outSz);
2581static WC_INLINE
int myEccVerify(
WOLFSSL* ssl,
const byte* sig, word32 sigSz,
2582 const byte* hash, word32 hashSz,
const byte* key, word32 keySz,
2583 int* result,
void* ctx)
2593 WOLFSSL_PKMSG(
"PK ECC Verify: sigSz %d, hashSz %d, keySz %d\n", sigSz, hashSz, keySz);
2603 WOLFSSL_PKMSG(
"PK ECC Verify: ret %d, result %d\n", ret, *result);
2608static WC_INLINE
int myEccSharedSecret(
WOLFSSL* ssl,
ecc_key* otherKey,
2609 unsigned char* pubKeyDer,
unsigned int* pubKeySz,
2610 unsigned char* out,
unsigned int* outlen,
2611 int side,
void* ctx)
2622 WOLFSSL_PKMSG(
"PK ECC PMS: Side %s, Peer Curve %d\n",
2623 side == WOLFSSL_CLIENT_END ?
"client" :
"server", otherKey->dp->id);
2631 if (side == WOLFSSL_CLIENT_END) {
2640 #ifdef WOLFSSL_ASYNC_CRYPT
2641 if (ret == WC_PENDING_E) {
2642 ret = wc_AsyncWait(ret, &privKey->asyncDev, WC_ASYNC_FLAG_NONE);
2652 else if (side == WOLFSSL_SERVER_END) {
2653 #ifdef TEST_PK_PRIVKEY
2654 privKey = &cbInfo->keyGen.ecc;
2660 ret = wc_ecc_import_x963_ex(pubKeyDer, *pubKeySz, pubKey,
2671 #ifdef WOLFSSL_ASYNC_CRYPT
2672 if (ret == WC_PENDING_E) {
2673 ret = wc_AsyncWait(ret, &privKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
2678#ifdef TEST_PK_PRIVKEY
2679 if (side == WOLFSSL_SERVER_END) {
2686 WOLFSSL_PKMSG(
"PK ECC PMS: ret %d, PubKeySz %d, OutLen %d\n", ret, *pubKeySz, *outlen);
2692static WC_INLINE
int myEd25519Sign(
WOLFSSL* ssl,
const byte* in, word32 inSz,
2693 byte* out, word32* outSz,
const byte* key, word32 keySz,
void* ctx)
2698 byte* keyBuf = (
byte*)key;
2704 WOLFSSL_PKMSG(
"PK 25519 Sign: inSz %d, keySz %d\n", inSz, keySz);
2706#ifdef TEST_PK_PRIVKEY
2707 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
2714 ret = wc_Ed25519PrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
2720#ifdef TEST_PK_PRIVKEY
2724 WOLFSSL_PKMSG(
"PK 25519 Sign: ret %d, outSz %d\n", ret, *outSz);
2730static WC_INLINE
int myEd25519Verify(
WOLFSSL* ssl,
const byte* sig, word32 sigSz,
2731 const byte* msg, word32 msgSz,
const byte* key, word32 keySz,
2732 int* result,
void* ctx)
2741 WOLFSSL_PKMSG(
"PK 25519 Verify: sigSz %d, msgSz %d, keySz %d\n", sigSz, msgSz, keySz);
2752 WOLFSSL_PKMSG(
"PK 25519 Verify: ret %d, result %d\n", ret, *result);
2758#ifdef HAVE_CURVE25519
2760 unsigned int keySz,
void* ctx)
2769 WOLFSSL_PKMSG(
"PK 25519 KeyGen: keySz %d\n", keySz);
2779 WOLFSSL_PKMSG(
"PK 25519 KeyGen: ret %d\n", ret);
2785 unsigned char* pubKeyDer,
unsigned int* pubKeySz,
2786 unsigned char* out,
unsigned int* outlen,
2787 int side,
void* ctx)
2798 WOLFSSL_PKMSG(
"PK 25519 PMS: side %s\n",
2799 side == WOLFSSL_CLIENT_END ?
"client" :
"server");
2807 if (side == WOLFSSL_CLIENT_END) {
2818 pubKeySz, EC25519_LITTLE_ENDIAN);
2825 else if (side == WOLFSSL_SERVER_END) {
2830 EC25519_LITTLE_ENDIAN);
2839 EC25519_LITTLE_ENDIAN);
2844 WOLFSSL_PKMSG(
"PK 25519 PMS: ret %d, pubKeySz %d, outLen %d\n",
2845 ret, *pubKeySz, *outlen);
2852static WC_INLINE
int myEd448Sign(
WOLFSSL* ssl,
const byte* in, word32 inSz,
2853 byte* out, word32* outSz,
const byte* key, word32 keySz,
void* ctx)
2858 byte* keyBuf = (
byte*)key;
2864 WOLFSSL_PKMSG(
"PK 448 Sign: inSz %d, keySz %d\n", inSz, keySz);
2866#ifdef TEST_PK_PRIVKEY
2867 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
2872 ret = wc_ed448_init(&myKey);
2874 ret = wc_Ed448PrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
2876 ret = wc_ed448_sign_msg(in, inSz, out, outSz, &myKey);
2877 wc_ed448_free(&myKey);
2880#ifdef TEST_PK_PRIVKEY
2884 WOLFSSL_PKMSG(
"PK 448 Sign: ret %d, outSz %d\n", ret, *outSz);
2890static WC_INLINE
int myEd448Verify(
WOLFSSL* ssl,
const byte* sig, word32 sigSz,
2891 const byte* msg, word32 msgSz,
const byte* key, word32 keySz,
2892 int* result,
void* ctx)
2901 WOLFSSL_PKMSG(
"PK 448 Verify: sigSz %d, msgSz %d, keySz %d\n", sigSz, msgSz,
2904 ret = wc_ed448_init(&myKey);
2906 ret = wc_ed448_import_public(key, keySz, &myKey);
2908 ret = wc_ed448_verify_msg(sig, sigSz, msg, msgSz, result, &myKey);
2910 wc_ed448_free(&myKey);
2913 WOLFSSL_PKMSG(
"PK 448 Verify: ret %d, result %d\n", ret, *result);
2920static WC_INLINE
int myX448KeyGen(
WOLFSSL* ssl, curve448_key* key,
2921 unsigned int keySz,
void* ctx)
2930 WOLFSSL_PKMSG(
"PK 448 KeyGen: keySz %d\n", keySz);
2936 ret = wc_curve448_make_key(&rng, keySz, key);
2940 WOLFSSL_PKMSG(
"PK 448 KeyGen: ret %d\n", ret);
2945static WC_INLINE
int myX448SharedSecret(
WOLFSSL* ssl, curve448_key* otherKey,
2946 unsigned char* pubKeyDer,
unsigned int* pubKeySz,
2947 unsigned char* out,
unsigned int* outlen,
2948 int side,
void* ctx)
2951 curve448_key* privKey = NULL;
2952 curve448_key* pubKey = NULL;
2953 curve448_key tmpKey;
2959 WOLFSSL_PKMSG(
"PK 448 PMS: side %s\n",
2960 side == WOLFSSL_CLIENT_END ?
"client" :
"server");
2962 ret = wc_curve448_init(&tmpKey);
2968 if (side == WOLFSSL_CLIENT_END) {
2976 ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, privKey);
2978 ret = wc_curve448_export_public_ex(privKey, pubKeyDer,
2979 pubKeySz, EC448_LITTLE_ENDIAN);
2986 else if (side == WOLFSSL_SERVER_END) {
2990 ret = wc_curve448_import_public_ex(pubKeyDer, *pubKeySz, pubKey,
2991 EC448_LITTLE_ENDIAN);
2999 ret = wc_curve448_shared_secret_ex(privKey, pubKey, out, outlen,
3000 EC448_LITTLE_ENDIAN);
3003 wc_curve448_free(&tmpKey);
3005 WOLFSSL_PKMSG(
"PK 448 PMS: ret %d, pubKeySz %d, outLen %d\n",
3006 ret, *pubKeySz, *outlen);
3015static WC_INLINE
int myDhCallback(
WOLFSSL* ssl,
struct DhKey* key,
3016 const unsigned char* priv,
unsigned int privSz,
3017 const unsigned char* pubKeyDer,
unsigned int pubKeySz,
3018 unsigned char* out,
unsigned int* outlen,
3028 ret =
wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz);
3030 WOLFSSL_PKMSG(
"PK ED Agree: ret %d, privSz %d, pubKeySz %d, outlen %d\n",
3031 ret, privSz, pubKeySz, *outlen);
3040static WC_INLINE
int myRsaSign(
WOLFSSL* ssl,
const byte* in, word32 inSz,
3041 byte* out, word32* outSz,
const byte* key, word32 keySz,
void* ctx)
3047 byte* keyBuf = (
byte*)key;
3053 WOLFSSL_PKMSG(
"PK RSA Sign: inSz %d, keySz %d\n", inSz, keySz);
3055#ifdef TEST_PK_PRIVKEY
3056 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3078#ifdef TEST_PK_PRIVKEY
3082 WOLFSSL_PKMSG(
"PK RSA Sign: ret %d, outSz %d\n", ret, *outSz);
3088static WC_INLINE
int myRsaVerify(
WOLFSSL* ssl,
byte* sig, word32 sigSz,
3089 byte** out,
const byte* key, word32 keySz,
void* ctx)
3099 WOLFSSL_PKMSG(
"PK RSA Verify: sigSz %d, keySz %d\n", sigSz, keySz);
3109 WOLFSSL_PKMSG(
"PK RSA Verify: ret %d\n", ret);
3114static WC_INLINE
int myRsaSignCheck(
WOLFSSL* ssl,
byte* sig, word32 sigSz,
3115 byte** out,
const byte* key, word32 keySz,
void* ctx)
3120 byte* keyBuf = (
byte*)key;
3126 WOLFSSL_PKMSG(
"PK RSA SignCheck: sigSz %d, keySz %d\n", sigSz, keySz);
3128#ifdef TEST_PK_PRIVKEY
3129 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3141#ifdef TEST_PK_PRIVKEY
3145 WOLFSSL_PKMSG(
"PK RSA SignCheck: ret %d\n", ret);
3151static WC_INLINE
int myRsaPssSign(
WOLFSSL* ssl,
const byte* in, word32 inSz,
3152 byte* out, word32* outSz,
int hash,
int mgf,
const byte* key,
3153 word32 keySz,
void* ctx)
3155 enum wc_HashType hashType = WC_HASH_TYPE_NONE;
3160 byte* keyBuf = (
byte*)key;
3166 WOLFSSL_PKMSG(
"PK RSA PSS Sign: inSz %d, hash %d, mgf %d, keySz %d\n",
3167 inSz, hash, mgf, keySz);
3169#ifdef TEST_PK_PRIVKEY
3170 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3178 hashType = WC_HASH_TYPE_SHA256;
3181#ifdef WOLFSSL_SHA384
3183 hashType = WC_HASH_TYPE_SHA384;
3186#ifdef WOLFSSL_SHA512
3188 hashType = WC_HASH_TYPE_SHA512;
3201 ret = wc_RsaPSS_Sign(in, inSz, out, *outSz, hashType, mgf, &myKey,
3212#ifdef TEST_PK_PRIVKEY
3216 WOLFSSL_PKMSG(
"PK RSA PSS Sign: ret %d, outSz %d\n", ret, *outSz);
3222static WC_INLINE
int myRsaPssVerify(
WOLFSSL* ssl,
byte* sig, word32 sigSz,
3223 byte** out,
int hash,
int mgf,
const byte* key, word32 keySz,
void* ctx)
3229 enum wc_HashType hashType = WC_HASH_TYPE_NONE;
3234 WOLFSSL_PKMSG(
"PK RSA PSS Verify: sigSz %d, hash %d, mgf %d, keySz %d\n",
3235 sigSz, hash, mgf, keySz);
3240 hashType = WC_HASH_TYPE_SHA256;
3243#ifdef WOLFSSL_SHA384
3245 hashType = WC_HASH_TYPE_SHA384;
3248#ifdef WOLFSSL_SHA512
3250 hashType = WC_HASH_TYPE_SHA512;
3259 ret = wc_RsaPSS_VerifyInline(sig, sigSz, out, hashType, mgf,
3265 WOLFSSL_PKMSG(
"PK RSA PSS Verify: ret %d\n", ret);
3270static WC_INLINE
int myRsaPssSignCheck(
WOLFSSL* ssl,
byte* sig, word32 sigSz,
3271 byte** out,
int hash,
int mgf,
const byte* key, word32 keySz,
void* ctx)
3276 byte* keyBuf = (
byte*)key;
3278 enum wc_HashType hashType = WC_HASH_TYPE_NONE;
3283 WOLFSSL_PKMSG(
"PK RSA PSS SignCheck: sigSz %d, hash %d, mgf %d, keySz %d\n",
3284 sigSz, hash, mgf, keySz);
3286#ifdef TEST_PK_PRIVKEY
3287 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3295 hashType = WC_HASH_TYPE_SHA256;
3298#ifdef WOLFSSL_SHA384
3300 hashType = WC_HASH_TYPE_SHA384;
3303#ifdef WOLFSSL_SHA512
3305 hashType = WC_HASH_TYPE_SHA512;
3314 ret = wc_RsaPSS_VerifyInline(sig, sigSz, out, hashType, mgf,
3320#ifdef TEST_PK_PRIVKEY
3324 WOLFSSL_PKMSG(
"PK RSA PSS SignCheck: ret %d\n", ret);
3331static WC_INLINE
int myRsaEnc(
WOLFSSL* ssl,
const byte* in, word32 inSz,
3332 byte* out, word32* outSz,
const byte* key,
3333 word32 keySz,
void* ctx)
3344 WOLFSSL_PKMSG(
"PK RSA Enc: inSz %d, keySz %d\n", inSz, keySz);
3364 WOLFSSL_PKMSG(
"PK RSA Enc: ret %d, outSz %d\n", ret, *outSz);
3369static WC_INLINE
int myRsaDec(
WOLFSSL* ssl,
byte* in, word32 inSz,
3371 const byte* key, word32 keySz,
void* ctx)
3376 byte* keyBuf = (
byte*)key;
3382 WOLFSSL_PKMSG(
"PK RSA Dec: inSz %d, keySz %d\n", inSz, keySz);
3384#ifdef TEST_PK_PRIVKEY
3385 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3394 #ifdef WC_RSA_BLINDING
3395 ret = wc_RsaSetRNG(&myKey, wolfSSL_GetRNG(ssl));
3406#ifdef TEST_PK_PRIVKEY
3410 WOLFSSL_PKMSG(
"PK RSA Dec: ret %d\n", ret);
3417static WC_INLINE
void SetupPkCallbacks(
WOLFSSL_CTX* ctx)
3422 wolfSSL_CTX_SetEccKeyGenCb(ctx, myEccKeyGen);
3423 wolfSSL_CTX_SetEccSignCb(ctx, myEccSign);
3424 wolfSSL_CTX_SetEccVerifyCb(ctx, myEccVerify);
3425 wolfSSL_CTX_SetEccSharedSecretCb(ctx, myEccSharedSecret);
3428 wolfSSL_CTX_SetDhAgreeCb(ctx, myDhCallback);
3431 wolfSSL_CTX_SetEd25519SignCb(ctx, myEd25519Sign);
3432 wolfSSL_CTX_SetEd25519VerifyCb(ctx, myEd25519Verify);
3434 #ifdef HAVE_CURVE25519
3435 wolfSSL_CTX_SetX25519KeyGenCb(ctx, myX25519KeyGen);
3436 wolfSSL_CTX_SetX25519SharedSecretCb(ctx, myX25519SharedSecret);
3439 wolfSSL_CTX_SetEd448SignCb(ctx, myEd448Sign);
3440 wolfSSL_CTX_SetEd448VerifyCb(ctx, myEd448Verify);
3442 #ifdef HAVE_CURVE448
3443 wolfSSL_CTX_SetX448KeyGenCb(ctx, myX448KeyGen);
3444 wolfSSL_CTX_SetX448SharedSecretCb(ctx, myX448SharedSecret);
3447 wolfSSL_CTX_SetRsaSignCb(ctx, myRsaSign);
3448 wolfSSL_CTX_SetRsaVerifyCb(ctx, myRsaVerify);
3449 wolfSSL_CTX_SetRsaSignCheckCb(ctx, myRsaSignCheck);
3451 wolfSSL_CTX_SetRsaPssSignCb(ctx, myRsaPssSign);
3452 wolfSSL_CTX_SetRsaPssVerifyCb(ctx, myRsaPssVerify);
3453 wolfSSL_CTX_SetRsaPssSignCheckCb(ctx, myRsaPssSignCheck);
3455 wolfSSL_CTX_SetRsaEncCb(ctx, myRsaEnc);
3456 wolfSSL_CTX_SetRsaDecCb(ctx, myRsaDec);
3460static WC_INLINE
void SetupPkCallbackContexts(
WOLFSSL* ssl,
void* myCtx)
3463 wolfSSL_SetEccKeyGenCtx(ssl, myCtx);
3464 wolfSSL_SetEccSignCtx(ssl, myCtx);
3465 wolfSSL_SetEccVerifyCtx(ssl, myCtx);
3466 wolfSSL_SetEccSharedSecretCtx(ssl, myCtx);
3469 wolfSSL_SetDhAgreeCtx(ssl, myCtx);
3472 wolfSSL_SetEd25519SignCtx(ssl, myCtx);
3473 wolfSSL_SetEd25519VerifyCtx(ssl, myCtx);
3475 #ifdef HAVE_CURVE25519
3476 wolfSSL_SetX25519KeyGenCtx(ssl, myCtx);
3477 wolfSSL_SetX25519SharedSecretCtx(ssl, myCtx);
3480 wolfSSL_SetEd448SignCtx(ssl, myCtx);
3481 wolfSSL_SetEd448VerifyCtx(ssl, myCtx);
3483 #ifdef HAVE_CURVE448
3484 wolfSSL_SetX448KeyGenCtx(ssl, myCtx);
3485 wolfSSL_SetX448SharedSecretCtx(ssl, myCtx);
3488 wolfSSL_SetRsaSignCtx(ssl, myCtx);
3489 wolfSSL_SetRsaVerifyCtx(ssl, myCtx);
3491 wolfSSL_SetRsaPssSignCtx(ssl, myCtx);
3492 wolfSSL_SetRsaPssVerifyCtx(ssl, myCtx);
3494 wolfSSL_SetRsaEncCtx(ssl, myCtx);
3495 wolfSSL_SetRsaDecCtx(ssl, myCtx);
3504#if defined(__hpux__) || defined(__MINGW32__) || defined (WOLFSSL_TIRTOS) \
3505 || defined(_MSC_VER)
3508static WC_INLINE
char* strsep(
char **stringp,
const char *delim)
3517 if ((end = strpbrk(start, delim))) {
3532static WC_INLINE
const char* mymktemp(
char *tempfn,
int len,
int num)
3535 static const char alphanum[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3536 "abcdefghijklmnopqrstuvwxyz";
3540 if (tempfn == NULL || len < 1 || num < 1 || len <= num) {
3541 printf(
"Bad input\n");
3548 printf(
"InitRng failed\n");
3552 for (x = size; x > size - num; x--) {
3554 printf(
"RNG_GenerateBlock failed\n");
3557 tempfn[x] = alphanum[out % (
sizeof(alphanum) - 1)];
3569#if defined(HAVE_SESSION_TICKET) && defined(HAVE_CHACHA) && \
3570 defined(HAVE_POLY1305)
3575 byte name[WOLFSSL_TICKET_NAME_SZ];
3576 byte key[CHACHA20_POLY1305_AEAD_KEYSIZE];
3579 static THREAD_LS_T
key_ctx myKey_ctx;
3580 static THREAD_LS_T
WC_RNG myKey_rng;
3582 static WC_INLINE
int TicketInit(
void)
3585 if (ret != 0)
return ret;
3588 if (ret != 0)
return ret;
3591 if (ret != 0)
return ret;
3596 static WC_INLINE
void TicketCleanup(
void)
3601 static WC_INLINE
int myTicketEncCb(
WOLFSSL* ssl,
3602 byte key_name[WOLFSSL_TICKET_NAME_SZ],
3603 byte iv[WOLFSSL_TICKET_IV_SZ],
3604 byte mac[WOLFSSL_TICKET_MAC_SZ],
3605 int enc,
byte* ticket,
int inLen,
int* outLen,
3612 word16 sLen = XHTONS(inLen);
3613 byte aad[WOLFSSL_TICKET_NAME_SZ + WOLFSSL_TICKET_IV_SZ + 2];
3614 int aadSz = WOLFSSL_TICKET_NAME_SZ + WOLFSSL_TICKET_IV_SZ + 2;
3618 XMEMCPY(key_name, myKey_ctx.name, WOLFSSL_TICKET_NAME_SZ);
3621 if (ret != 0)
return WOLFSSL_TICKET_RET_REJECT;
3624 XMEMCPY(tmp, key_name, WOLFSSL_TICKET_NAME_SZ);
3625 tmp += WOLFSSL_TICKET_NAME_SZ;
3626 XMEMCPY(tmp, iv, WOLFSSL_TICKET_IV_SZ);
3627 tmp += WOLFSSL_TICKET_IV_SZ;
3628 XMEMCPY(tmp, &sLen, 2);
3635 if (ret != 0)
return WOLFSSL_TICKET_RET_REJECT;
3641 if (XMEMCMP(key_name, myKey_ctx.name, WOLFSSL_TICKET_NAME_SZ) != 0){
3642 printf(
"client presented unknown ticket key name ");
3643 return WOLFSSL_TICKET_RET_FATAL;
3647 XMEMCPY(tmp, key_name, WOLFSSL_TICKET_NAME_SZ);
3648 tmp += WOLFSSL_TICKET_NAME_SZ;
3649 XMEMCPY(tmp, iv, WOLFSSL_TICKET_IV_SZ);
3650 tmp += WOLFSSL_TICKET_IV_SZ;
3651 XMEMCPY(tmp, &sLen, 2);
3658 if (ret != 0)
return WOLFSSL_TICKET_RET_REJECT;
3662 return WOLFSSL_TICKET_RET_OK;
3667static WC_INLINE word16 GetRandomPort(
void)
WOLFSSL_API int wc_AesCbcDecrypt(Aes *aes, byte *out, const byte *in, word32 sz)
Decrypts a cipher from the input buffer in, and places the resulting plain text in the output buffer ...
Definition aes.c:3008
WOLFSSL_API int wc_AesSetKey(Aes *aes, const byte *key, word32 len, const byte *iv, int dir)
This function initializes an AES structure by setting the key and then setting the initialization vec...
Definition aes.c:2178
WOLFSSL_API int wc_AesCbcEncrypt(Aes *aes, byte *out, const byte *in, word32 sz)
Encrypts a plaintext message from the input buffer in, and places the resulting cipher text in the ou...
Definition aes.c:2951
WOLFSSL_API int wc_EccPrivateKeyDecode(const byte *, word32 *, ecc_key *, word32)
This function reads in an ECC private key from the input buffer, input, parses the private key,...
Definition asn.c:15166
WOLFSSL_API int wc_EccPublicKeyDecode(const byte *, word32 *, ecc_key *, word32)
Decodes an ECC public key from an input buffer. It will parse an ASN sequence to retrieve the ECC key...
Definition asn.c:15369
WOLFSSL_API WOLFSSL_X509_NAME * wolfSSL_X509_get_subject_name(WOLFSSL_X509 *)
This function returns the subject member of the WOLFSSL_X509 structure.
Definition ssl.c:19584
WOLFSSL_API WOLFSSL_X509 * wolfSSL_get_peer_certificate(WOLFSSL *ssl)
This function gets the peer’s certificate.
Definition ssl.c:16929
WOLFSSL_API int wolfSSL_SetTmpDH(WOLFSSL *, const unsigned char *p, int pSz, const unsigned char *g, int gSz)
Server Diffie-Hellman Ephemeral parameters setting. This function sets up the group parameters to be ...
Definition ssl.c:1711
WOLFSSL_API int wolfSSL_X509_NAME_get_text_by_NID(WOLFSSL_X509_NAME *, int, char *, int)
This function gets the text related to the passed in NID value.
Definition ssl.c:19673
WOLFSSL_API int wolfSSL_CTX_use_PrivateKey_buffer(WOLFSSL_CTX *, const unsigned char *, long, int)
This function loads a private key buffer into the SSL Context. It behaves like the non-buffered versi...
Definition ssl.c:13667
WOLFSSL_API int wolfSSL_GetDhKey_Sz(WOLFSSL *)
Returns the value of dhKeySz that is a member of the options structure. This value represents the Dif...
Definition ssl.c:1922
WOLFSSL_API int wolfSSL_CTX_load_verify_buffer(WOLFSSL_CTX *, const unsigned char *, long, int)
This function loads a CA certificate buffer into the WOLFSSL Context. It behaves like the non-buffere...
Definition ssl.c:13619
WOLFSSL_API char * wolfSSL_X509_get_next_altname(WOLFSSL_X509 *)
This function returns the next, if any, altname from the peer certificate.
Definition ssl.c:17287
WOLFSSL_API WOLFSSL_X509_NAME * wolfSSL_X509_get_issuer_name(WOLFSSL_X509 *)
This function returns the name of the certificate issuer.
Definition ssl.c:19636
WOLFSSL_API int wolfSSL_CTX_SetTmpDH(WOLFSSL_CTX *, const unsigned char *p, int pSz, const unsigned char *g, int gSz)
Sets the parameters for the server CTX Diffie-Hellman.
Definition ssl.c:1817
WOLFSSL_API int wolfSSL_CTX_use_certificate_buffer(WOLFSSL_CTX *, const unsigned char *, long, int)
This function loads a certificate buffer into the WOLFSSL Context. It behaves like the non-buffered v...
Definition ssl.c:13658
WOLFSSL_API int wc_KeyPemToDer(const unsigned char *, int, unsigned char *, int, const char *)
Converts a key in PEM format to DER format.
Definition asn.c:10636
WOLFSSL_API char * wolfSSL_X509_NAME_oneline(WOLFSSL_X509_NAME *, char *, int)
This function copies the name of the x509 into a buffer.
Definition ssl.c:17076
WOLFSSL_API WOLFSSL_X509 * wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN *, int idx)
This function gets the peer’s wolfSSL_X509_certificate at index (idx) from the chain of certificates.
Definition ssl.c:35586
WOLFSSL_API int wolfSSL_use_certificate_buffer(WOLFSSL *, const unsigned char *, long, int)
This function loads a certificate buffer into the WOLFSSL object. It behaves like the non-buffered ve...
Definition ssl.c:13818
WOLFSSL_API int wolfSSL_use_PrivateKey_buffer(WOLFSSL *, const unsigned char *, long, int)
This function loads a private key buffer into the WOLFSSL object. It behaves like the non-buffered ve...
Definition ssl.c:13830
WOLFSSL_API int wc_ChaCha20Poly1305_Encrypt(const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE], const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE], const byte *inAAD, const word32 inAADLen, const byte *inPlaintext, const word32 inPlaintextLen, byte *outCiphertext, byte outAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE])
This function encrypts an input message, inPlaintext, using the ChaCha20 stream cipher,...
Definition chacha20_poly1305.c:44
WOLFSSL_API int wc_ChaCha20Poly1305_Decrypt(const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE], const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE], const byte *inAAD, const word32 inAADLen, const byte *inCiphertext, const word32 inCiphertextLen, const byte inAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE], byte *outPlaintext)
This function decrypts input ciphertext, inCiphertext, using the ChaCha20 stream cipher,...
Definition chacha20_poly1305.c:76
WOLFSSL_API int wc_curve25519_import_public_ex(const byte *in, word32 inLen, curve25519_key *key, int endian)
This function imports a public key from the given in buffer and stores it in the curve25519_key struc...
Definition curve25519.c:226
WOLFSSL_API int wc_curve25519_export_public_ex(curve25519_key *key, byte *out, word32 *outLen, int endian)
This function exports a public key from the given key structure and stores the result in the out buff...
Definition curve25519.c:186
WOLFSSL_API int wc_curve25519_make_key(WC_RNG *rng, int keysize, curve25519_key *key)
This function generates a curve25519 key using the given random number generator, rng,...
Definition curve25519.c:54
WOLFSSL_API int wc_curve25519_shared_secret_ex(curve25519_key *private_key, curve25519_key *public_key, byte *out, word32 *outlen, int endian)
This function computes a shared secret key given a secret private key and a received public key....
Definition curve25519.c:109
WOLFSSL_API void wc_curve25519_free(curve25519_key *key)
This function frees a curve 25519 object.
Definition curve25519.c:488
WOLFSSL_API int wc_curve25519_init(curve25519_key *key)
This function initializes a curve25519 key. It should be called before generating a key for the struc...
Definition curve25519.c:469
WOLFSSL_API char * wolfSSL_ERR_error_string(unsigned long, char *)
This function converts an error code returned by wolfSSL_get_error() into a more human-readable error...
Definition ssl.c:3121
WOLFSSL_API int wc_DhAgree(DhKey *key, byte *agree, word32 *agreeSz, const byte *priv, word32 privSz, const byte *otherPub, word32 pubSz)
This function generates an agreed upon secret key based on a local private key and a received public ...
Definition dh.c:2045
WOLFSSL_API int wc_ecc_make_key_ex(WC_RNG *rng, int keysize, ecc_key *key, int curve_id)
This function generates a new ecc_key and stores it in key.
Definition ecc.c:4126
WOLFSSL_API int wc_ecc_sign_hash(const byte *in, word32 inlen, byte *out, word32 *outlen, WC_RNG *rng, ecc_key *key)
This function signs a message digest using an ecc_key object to guarantee authenticity.
Definition ecc.c:4749
WOLFSSL_API int wc_ecc_verify_hash(const byte *sig, word32 siglen, const byte *hash, word32 hashlen, int *stat, ecc_key *key)
This function verifies the ECC signature of a hash to ensure authenticity. It returns the answer thro...
Definition ecc.c:5704
WOLFSSL_API int wc_ecc_init(ecc_key *key)
This function initializes an ecc_key object for future use with message verification or key negotiati...
Definition ecc.c:4495
WOLFSSL_API int wc_ecc_shared_secret(ecc_key *private_key, ecc_key *public_key, byte *out, word32 *outlen)
This function generates a new secret key using a local private key and a received public key....
Definition ecc.c:3533
WOLFSSL_API int wc_ecc_free(ecc_key *key)
This function frees an ecc_key object after it has been used.
Definition ecc.c:5312
WOLFSSL_API int wc_ecc_export_x963(ecc_key *, byte *out, word32 *outLen)
This function exports the ECC key from the ecc_key structure, storing the result in out....
Definition ecc.c:6610
WOLFSSL_API void wc_ed25519_free(ed25519_key *key)
This function frees an ed25519 object after it has been used.
Definition ed25519.c:529
WOLFSSL_API int wc_ed25519_sign_msg(const byte *in, word32 inlen, byte *out, word32 *outlen, ed25519_key *key)
This function signs a message digest using an ed25519_key object to guarantee authenticity.
Definition ed25519.c:263
WOLFSSL_API int wc_ed25519_import_public(const byte *in, word32 inLen, ed25519_key *key)
This function imports a public ed25519_key pair from a buffer containing the public key....
Definition ed25519.c:572
WOLFSSL_API int wc_ed25519_verify_msg(const byte *sig, word32 siglen, const byte *msg, word32 msglen, int *stat, ed25519_key *key)
This function verifies the ed25519 signature of a message to ensure authenticity. It returns the answ...
Definition ed25519.c:439
WOLFSSL_API int wc_ed25519_init(ed25519_key *key)
This function initializes an ed25519_key object for future use with message verification.
Definition ed25519.c:513
WOLFSSL_API int wc_HmacFinal(Hmac *, byte *)
This function computes the final hash of an Hmac object's message.
Definition hmac.c:757
WOLFSSL_API int wc_HmacSetKey(Hmac *, int type, const byte *key, word32 keySz)
This function initializes an Hmac object, setting its encryption type, key and HMAC length.
Definition hmac.c:279
WOLFSSL_API int wc_HmacUpdate(Hmac *, const byte *, word32)
This function updates the message to authenticate using HMAC. It should be called after the Hmac obje...
Definition hmac.c:654
WOLFSSL_API long wolfSSL_BIO_set_fp(WOLFSSL_BIO *bio, XFILE fp, int c)
This is used to set the internal file pointer for a BIO.
Definition bio.c:1324
WOLFSSL_API WOLFSSL_CIPHER * wolfSSL_get_current_cipher(WOLFSSL *)
This function returns a pointer to the current cipher in the ssl session.
Definition ssl.c:19312
WOLFSSL_API int wolfSSL_isQSH(WOLFSSL *ssl)
Checks if QSH is used in the supplied SSL session.
Definition ssl.c:2455
WOLFSSL_API const char * wolfSSL_get_version(WOLFSSL *)
Returns the SSL version being used as a string.
Definition ssl.c:19279
WOLFSSL_API int wolfSSL_session_reused(WOLFSSL *)
This function returns the resuming member of the options struct. The flag indicates whether or not to...
Definition ssl.c:19137
WOLFSSL_API const char * wolfSSL_CIPHER_get_name(const WOLFSSL_CIPHER *cipher)
This function matches the cipher suite in the SSL object with the available suites and returns the st...
Definition ssl.c:19325
WOLFSSL_API void XFREE(void *p, void *heap, int type)
This is not actually a function, but rather a preprocessor macro, which allows the user to substitute...
Definition memory.c:1015
WOLFSSL_API int wc_InitRsaKey(RsaKey *key, void *heap)
This function initializes a provided RsaKey struct. It also takes in a heap identifier,...
Definition rsa.c:333
WOLFSSL_API int wc_RsaPublicKeyDecode(const byte *input, word32 *inOutIdx, RsaKey *, word32)
This function parses a DER-formatted RSA public key, extracts the public key and stores it in the giv...
Definition asn.c:4321
WOLFSSL_API int wc_FreeRsaKey(RsaKey *key)
This function frees a provided RsaKey struct using mp_clear.
Definition rsa.c:512
WOLFSSL_API int wc_RsaSSL_VerifyInline(byte *in, word32 inLen, byte **out, RsaKey *key)
Used to verify that the message was signed by RSA key. The output uses the same byte array as the inp...
Definition rsa.c:3116
WOLFSSL_API int wc_RsaPrivateDecryptInline(byte *in, word32 inLen, byte **out, RsaKey *key)
This functions is utilized by the wc_RsaPrivateDecrypt function for decrypting.
Definition rsa.c:3050
WOLFSSL_API int wc_RsaPrivateKeyDecode(const byte *input, word32 *inOutIdx, RsaKey *, word32)
This function parses a DER-formatted RSA private key, extracts the private key and stores it in the g...
Definition asn.c:2567
WOLFSSL_API int wc_RsaPublicEncrypt(const byte *in, word32 inLen, byte *out, word32 outLen, RsaKey *key, WC_RNG *rng)
This function encrypts a message from in and stores the result in out. It requires an initialized pub...
Definition rsa.c:3027
WOLFSSL_API int wc_RsaSSL_Sign(const byte *in, word32 inLen, byte *out, word32 outLen, RsaKey *key, WC_RNG *rng)
Signs the provided array with the private key.
Definition rsa.c:3481
WOLFSSL_API int wc_RNG_GenerateBlock(WC_RNG *, byte *, word32 sz)
Copies a sz bytes of pseudorandom data to output. Will reseed rng if needed (blocking).
Definition random.c:896
WOLFSSL_API int wc_InitRng(WC_RNG *)
Gets the seed (from OS) and key cipher for rng. rng->drbg (deterministic random bit generator) alloca...
Definition random.c:869
WOLFSSL_API int wc_FreeRng(WC_RNG *)
Should be called when RNG no longer needed in order to securely free drgb. Zeros and XFREEs rng-drbg.
Definition random.c:995
WOLFSSL_API long wolfSSL_get_verify_result(const WOLFSSL *ssl)
This is used to get the results after trying to verify the peer's certificate.
Definition ssl.c:25460
WOLFSSL_API int wolfSSL_get_chain_count(WOLFSSL_X509_CHAIN *chain)
Retrieve's the peers certificate chain count.
Definition ssl.c:35553
WOLFSSL_API int wolfSSL_get_chain_cert_pem(WOLFSSL_X509_CHAIN *, int idx, unsigned char *buf, int inLen, int *outLen)
Retrieves the peer’s PEM certificate at index (idx).
Definition ssl.c:35642
WOLFSSL_API int wolfSSL_X509_get_serial_number(WOLFSSL_X509 *, unsigned char *, int *)
Retrieves the peer’s certificate serial number. The serial number buffer (in) should be at least 32 b...
Definition ssl.c:17423
WOLFSSL_API WOLFSSL_X509_CHAIN * wolfSSL_get_peer_chain(WOLFSSL *ssl)
Retrieves the peer’s certificate chain.
Definition ssl.c:35542
Definition internal.h:1833
Definition internal.h:2595
Definition internal.h:1628
Definition internal.h:3109
Definition internal.h:3546
Definition internal.h:3102
Definition internal.h:3598
Definition internal.h:3849
Definition curve25519.h:70
Definition wolfssl_MDK_ARM.h:46
Definition wolfssl_MDK_ARM.h:51