Changeset 372 for asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/test.h
- Timestamp:
- Feb 7, 2019, 8:36:33 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/test.h
r352 r372 11 11 #include <wolfssl/wolfcrypt/error-crypt.h> 12 12 #include <wolfssl/wolfcrypt/random.h> 13 #include <wolfssl/wolfcrypt/mem_track.h> 14 #if defined(OPENSSL_EXTRA) && defined(SHOW_CERTS) 15 #include <wolfssl/wolfcrypt/asn.h> /* for domain component NID value */ 16 #endif 13 17 14 18 #ifdef ATOMIC_USER … … 25 29 #include <wolfssl/wolfcrypt/ecc.h> 26 30 #endif /* HAVE_ECC */ 31 #ifndef NO_DH 32 #include <wolfssl/wolfcrypt/dh.h> 33 #endif /* !NO_DH */ 27 34 #ifdef HAVE_ED25519 28 35 #include <wolfssl/wolfcrypt/ed25519.h> … … 59 66 #define sleep(t) osDelay(t/1000+1) ; 60 67 #endif 61 62 static int wolfssl_tcp_select(int sd, int timeout)63 { return 0 ; }64 #define tcp_select(sd,t) wolfssl_tcp_select(sd, t) /* avoid conflicting Keil TCP tcp_select */65 68 #elif defined(WOLFSSL_TIRTOS) 66 69 #include <string.h> … … 122 125 #include <wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h> 123 126 #endif 124 125 127 #ifdef _MSC_VER 126 128 /* disable conversion warning */ … … 136 138 #ifndef WOLFSSL_HAVE_MIN 137 139 #define WOLFSSL_HAVE_MIN 138 static INLINE word32 min(word32 a, word32 b)140 static WC_INLINE word32 min(word32 a, word32 b) 139 141 { 140 142 return a > b ? b : a; … … 181 183 #endif 182 184 183 184 #ifdef USE_WINDOWS_API185 #define CloseSocket(s) closesocket(s)186 #define StartTCP() { WSADATA wsd; WSAStartup(0x0002, &wsd); }187 #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)188 #define CloseSocket(s) closesocket(s)189 #define StartTCP()190 #else191 #define CloseSocket(s) close(s)192 #define StartTCP()193 #endif194 185 195 186 … … 230 221 231 222 223 #ifndef WOLFSSL_NO_TLS12 232 224 #define SERVER_DEFAULT_VERSION 3 225 #else 226 #define SERVER_DEFAULT_VERSION 4 227 #endif 233 228 #define SERVER_DTLS_DEFAULT_VERSION (-2) 234 229 #define SERVER_INVALID_VERSION (-99) 230 #define SERVER_DOWNGRADE_VERSION (-98) 231 #ifndef WOLFSSL_NO_TLS12 235 232 #define CLIENT_DEFAULT_VERSION 3 233 #else 234 #define CLIENT_DEFAULT_VERSION 4 235 #endif 236 236 #define CLIENT_DTLS_DEFAULT_VERSION (-2) 237 237 #define CLIENT_INVALID_VERSION (-99) 238 #define CLIENT_DOWNGRADE_VERSION (-98) 239 #define EITHER_DOWNGRADE_VERSION (-97) 238 240 #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_MAX_STRENGTH) 239 241 #define DEFAULT_MIN_DHKEY_BITS 2048 242 #define DEFAULT_MAX_DHKEY_BITS 3072 240 243 #else 241 244 #define DEFAULT_MIN_DHKEY_BITS 1024 245 #define DEFAULT_MAX_DHKEY_BITS 2048 242 246 #endif 243 247 #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_MAX_STRENGTH) … … 257 261 #define eccCertFile "certs/server-ecc.pem" 258 262 #define eccKeyFile "certs/ecc-key.pem" 263 #define eccRsaCertFile "certs/server-ecc-rsa.pem" 259 264 #define svrCertFile "certs/server-cert.pem" 260 265 #define svrKeyFile "certs/server-key.pem" 261 266 #define cliCertFile "certs/client-cert.pem" 267 #define cliCertDerFile "certs/client-cert.der" 262 268 #define cliKeyFile "certs/client-key.pem" 263 269 #define ntruCertFile "certs/ntru-cert.pem" … … 268 274 #define caEccCertFile "certs/ca-ecc-cert/pem" 269 275 #define crlPemDir "certs/crl" 276 #define edCertFile "certs/ed25519/server-ed25519-cert.pem" 277 #define edKeyFile "certs/ed25519/server-ed25519-priv.pem" 278 #define cliEdCertFile "certs/ed25519/client-ed25519.pem" 279 #define cliEdKeyFile "certs/ed25519/client-ed25519-priv.pem" 280 #define caEdCertFile "certs/ed25519/ca-ed25519.pem" 270 281 #ifdef HAVE_WNR 271 282 /* Whitewood netRandom default config file */ … … 276 287 #define eccCertFile "./certs/server-ecc.pem" 277 288 #define eccKeyFile "./certs/ecc-key.pem" 289 #define eccRsaCertFile "./certs/server-ecc-rsa.pem" 278 290 #define svrCertFile "./certs/server-cert.pem" 279 291 #define svrKeyFile "./certs/server-key.pem" 280 292 #define cliCertFile "./certs/client-cert.pem" 293 #define cliCertDerFile "./certs/client-cert.der" 281 294 #define cliKeyFile "./certs/client-key.pem" 282 295 #define ntruCertFile "./certs/ntru-cert.pem" … … 287 300 #define caEccCertFile "./certs/ca-ecc-cert.pem" 288 301 #define crlPemDir "./certs/crl" 302 #define edCertFile "./certs/ed25519/server-ed25519.pem" 303 #define edKeyFile "./certs/ed25519/server-ed25519-priv.pem" 304 #define cliEdCertFile "./certs/ed25519/client-ed25519.pem" 305 #define cliEdKeyFile "./certs/ed25519/client-ed25519-priv.pem" 306 #define caEdCertFile "./certs/ed25519/root-ed25519.pem" 289 307 #ifdef HAVE_WNR 290 308 /* Whitewood netRandom default config file */ … … 304 322 305 323 306 static INLINE void InitTcpReady(tcp_ready* ready)324 static WC_INLINE void InitTcpReady(tcp_ready* ready) 307 325 { 308 326 ready->ready = 0; … … 317 335 318 336 319 static INLINE void FreeTcpReady(tcp_ready* ready)337 static WC_INLINE void FreeTcpReady(tcp_ready* ready) 320 338 { 321 339 #ifdef SINGLE_THREADED … … 338 356 ssl_callback ssl_ready; 339 357 ssl_callback on_result; 358 WOLFSSL_CTX* ctx; 340 359 } callback_functions; 341 360 … … 367 386 368 387 369 #if defined(__GNUC__) 370 #define WC_NORETURN __attribute__((noreturn)) 388 389 #ifndef MY_EX_USAGE 390 #define MY_EX_USAGE 2 391 #endif 392 393 #ifndef EXIT_FAILURE 394 #define EXIT_FAILURE 1 395 #endif 396 397 #ifdef WOLFSSL_FORCE_MALLOC_FAIL_TEST 398 #define XEXIT(rc) return rc 399 #define XEXIT_T(rc) return (THREAD_RETURN)rc 371 400 #else 372 #define WC_NORETURN 373 #endif 374 375 static INLINE WC_NORETURN void err_sys(const char* msg) 401 #define XEXIT(rc) exit((int)(rc)) 402 #define XEXIT_T(rc) exit((int)(rc)) 403 #endif 404 405 406 static WC_INLINE 407 #ifdef WOLFSSL_FORCE_MALLOC_FAIL_TEST 408 THREAD_RETURN 409 #else 410 WC_NORETURN void 411 #endif 412 err_sys(const char* msg) 376 413 { 377 414 printf("wolfSSL error: %s\n", msg); … … 387 424 #endif 388 425 { 389 exit(EXIT_FAILURE); 390 } 391 } 392 393 394 #define MY_EX_USAGE 2 426 XEXIT_T(EXIT_FAILURE); 427 } 428 } 429 395 430 396 431 extern int myoptind; 397 432 extern char* myoptarg; 398 433 399 static INLINE int mygetopt(int argc, char** argv, const char* optstring)434 static WC_INLINE int mygetopt(int argc, char** argv, const char* optstring) 400 435 { 401 436 static char* next = NULL; … … 461 496 462 497 463 #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)464 465 static INLINE int PasswordCallBack(char* passwd, int sz, int rw, void* userdata)498 #ifdef WOLFSSL_ENCRYPTED_KEYS 499 500 static WC_INLINE int PasswordCallBack(char* passwd, int sz, int rw, void* userdata) 466 501 { 467 502 (void)rw; 468 503 (void)userdata; 504 if (userdata != NULL) { 505 strncpy(passwd, (char*)userdata, sz); 506 return (int)XSTRLEN((char*)userdata); 507 } 508 else { 469 509 strncpy(passwd, "yassl123", sz); 470 510 return 8; 471 511 } 472 473 #endif 474 512 } 513 514 #endif 515 516 static const char* client_showpeer_msg[][8] = { 517 /* English */ 518 { 519 "SSL version is", 520 "SSL cipher suite is", 521 "SSL curve name is", 522 "SSL DH size is", 523 "SSL reused session", 524 "Alternate cert chain used", 525 "peer's cert info:", 526 NULL 527 }, 528 /* Japanese */ 529 { 530 "SSL バージョンは", 531 "SSL 暗号スイートは", 532 "SSL 曲線名は", 533 "SSL DH サイズは", 534 "SSL 再利用セッション", 535 "代替証明チェーンを使用", 536 "相手方証明書情報", 537 NULL 538 } 539 }; 475 540 476 541 #if defined(KEEP_PEER_CERT) || defined(SESSION_CERTS) 477 478 static INLINE void ShowX509(WOLFSSL_X509* x509, const char* hdr) 542 static const char* client_showx509_msg[][5] = { 543 /* English */ 544 { 545 "issuer", 546 "subject", 547 "altname", 548 "serial number", 549 NULL 550 }, 551 /* Japanese */ 552 { 553 "発行者", 554 "サブジェクト", 555 "代替名", 556 "シリアル番号", 557 NULL 558 }, 559 }; 560 561 /* lng_index is to specify the language for displaying message. */ 562 /* 0:English, 1:Japanese */ 563 static WC_INLINE void ShowX509Ex(WOLFSSL_X509* x509, const char* hdr, 564 int lng_index) 479 565 { 480 566 char* altName; … … 484 570 int ret; 485 571 int sz = sizeof(serial); 572 const char** words = client_showx509_msg[lng_index]; 486 573 487 574 if (x509 == NULL) { … … 495 582 wolfSSL_X509_get_subject_name(x509), 0, 0); 496 583 497 printf("%s\n issuer : %s\n subject: %s\n", hdr, issuer, subject);584 printf("%s\n %s : %s\n %s: %s\n", hdr, words[0], issuer, words[1], subject); 498 585 499 586 while ( (altName = wolfSSL_X509_get_next_altname(x509)) != NULL) 500 printf(" altname = %s\n", altName);587 printf(" %s = %s\n", words[2], altName); 501 588 502 589 ret = wolfSSL_X509_get_serial_number(x509, serial, &sz); … … 508 595 /* testsuite has multiple threads writing to stdout, get output 509 596 message ready to write once */ 510 strLen = sprintf(serialMsg, " serial number");597 strLen = sprintf(serialMsg, " %s", words[3]); 511 598 for (i = 0; i < sz; i++) 512 599 sprintf(serialMsg + strLen + (i*3), ":%02x ", serial[i]); … … 516 603 XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL); 517 604 XFREE(issuer, 0, DYNAMIC_TYPE_OPENSSL); 605 606 #if defined(OPENSSL_EXTRA) && defined(SHOW_CERTS) 607 { 608 WOLFSSL_BIO* bio; 609 char buf[256]; /* should be size of ASN_NAME_MAX */ 610 int textSz; 611 612 613 /* print out domain component if certificate has it */ 614 textSz = wolfSSL_X509_NAME_get_text_by_NID( 615 wolfSSL_X509_get_subject_name(x509), NID_domainComponent, 616 buf, sizeof(buf)); 617 if (textSz > 0) { 618 printf("Domain Component = %s\n", buf); 619 } 620 621 bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file()); 622 if (bio != NULL) { 623 wolfSSL_BIO_set_fp(bio, stdout, BIO_NOCLOSE); 624 wolfSSL_X509_print(bio, x509); 625 wolfSSL_BIO_free(bio); 626 } 627 } 628 #endif 629 } 630 /* original ShowX509 to maintain compatibility */ 631 static WC_INLINE void ShowX509(WOLFSSL_X509* x509, const char* hdr) 632 { 633 ShowX509Ex(x509, hdr, 0); 518 634 } 519 635 … … 521 637 522 638 #if defined(SESSION_CERTS) && defined(SHOW_CERTS) 523 static INLINE void ShowX509Chain(WOLFSSL_X509_CHAIN* chain, int count,639 static WC_INLINE void ShowX509Chain(WOLFSSL_X509_CHAIN* chain, int count, 524 640 const char* hdr) 525 641 { … … 544 660 #endif 545 661 546 static INLINE void showPeer(WOLFSSL* ssl) 662 /* lng_index is to specify the language for displaying message. */ 663 /* 0:English, 1:Japanese */ 664 static WC_INLINE void showPeerEx(WOLFSSL* ssl, int lng_index) 547 665 { 548 666 WOLFSSL_CIPHER* cipher; 667 const char** words = client_showpeer_msg[lng_index]; 668 549 669 #ifdef HAVE_ECC 550 670 const char *name; … … 556 676 WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl); 557 677 if (peer) 558 ShowX509 (peer, "peer's cert info:");678 ShowX509Ex(peer, words[6], lng_index); 559 679 else 560 680 printf("peer has no cert!\n"); … … 565 685 printf("Peer verify result = %lu\n", wolfSSL_get_verify_result(ssl)); 566 686 #endif /* SHOW_CERTS */ 567 printf(" SSL version is %s\n", wolfSSL_get_version(ssl));687 printf("%s %s\n", words[0], wolfSSL_get_version(ssl)); 568 688 569 689 cipher = wolfSSL_get_current_cipher(ssl); 570 690 #ifdef HAVE_QSH 571 printf(" SSL cipher suite is %s%s\n", (wolfSSL_isQSH(ssl))? "QSH:": "",691 printf("%s %s%s\n", words[1], (wolfSSL_isQSH(ssl))? "QSH:": "", 572 692 wolfSSL_CIPHER_get_name(cipher)); 573 693 #else 574 printf(" SSL cipher suite is %s\n", wolfSSL_CIPHER_get_name(cipher));694 printf("%s %s\n", words[1], wolfSSL_CIPHER_get_name(cipher)); 575 695 #endif 576 696 #ifdef HAVE_ECC 577 697 if ((name = wolfSSL_get_curve_name(ssl)) != NULL) 578 printf(" SSL curve name is %s\n", name);698 printf("%s %s\n", words[2], name); 579 699 #endif 580 700 #ifndef NO_DH 581 701 if ((bits = wolfSSL_GetDhKey_Sz(ssl)) > 0) 582 printf(" SSL DH size is %d bits\n", bits);702 printf("%s %d bits\n", words[3], bits); 583 703 #endif 584 704 if (wolfSSL_session_reused(ssl)) 585 printf(" SSL reused session\n");705 printf("%s\n", words[4]); 586 706 #ifdef WOLFSSL_ALT_CERT_CHAINS 587 707 if (wolfSSL_is_peer_alt_cert_chain(ssl)) 588 printf(" Alternate cert chain used\n");708 printf("%s\n", words[5]); 589 709 #endif 590 710 … … 606 726 (void)ssl; 607 727 } 608 609 610 static INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer, 728 /* original showPeer to maintain compatibility */ 729 static WC_INLINE void showPeer(WOLFSSL* ssl) 730 { 731 showPeerEx(ssl, 0); 732 } 733 734 static WC_INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer, 611 735 word16 port, int udp, int sctp) 612 736 { … … 619 743 err_sys("invalid argument to build_addr, addr is NULL"); 620 744 621 memset(addr, 0, sizeof(SOCKADDR_IN_T));745 XMEMSET(addr, 0, sizeof(SOCKADDR_IN_T)); 622 746 623 747 #ifndef TEST_IPV6 … … 662 786 addr->sin6_family = AF_INET_V; 663 787 addr->sin6_port = XHTONS(port); 664 if ( peer == INADDR_ANY)788 if ((size_t)peer == INADDR_ANY) { 665 789 addr->sin6_addr = in6addr_any; 790 } 666 791 else { 667 792 #ifdef HAVE_GETADDRINFO … … 671 796 char strPort[80]; 672 797 673 memset(&hints, 0, sizeof(hints));798 XMEMSET(&hints, 0, sizeof(hints)); 674 799 675 800 hints.ai_family = AF_INET_V; … … 707 832 708 833 709 static INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp)834 static WC_INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp) 710 835 { 711 836 (void)sctp; … … 753 878 } 754 879 755 static INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port,880 static WC_INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port, 756 881 int udp, int sctp, WOLFSSL* ssl) 757 882 { … … 770 895 771 896 772 static INLINE void udp_connect(SOCKET_T* sockfd, void* addr, int addrSz)897 static WC_INLINE void udp_connect(SOCKET_T* sockfd, void* addr, int addrSz) 773 898 { 774 899 if (connect(*sockfd, (const struct sockaddr*)addr, addrSz) != 0) … … 787 912 #if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_TCP_NET) && \ 788 913 !defined(WOLFSSL_TIRTOS) 789 static INLINE int tcp_select(SOCKET_T socketfd, int to_sec)914 static WC_INLINE int tcp_select(SOCKET_T socketfd, int to_sec) 790 915 { 791 916 fd_set recvfds, errfds; 792 917 SOCKET_T nfds = socketfd + 1; 918 #if !defined(__INTEGRITY) 793 919 struct timeval timeout = { (to_sec > 0) ? to_sec : 0, 0}; 920 #else 921 struct timeval timeout; 922 #endif 794 923 int result; 795 924 … … 799 928 FD_SET(socketfd, &errfds); 800 929 930 #if defined(__INTEGRITY) 931 timeout.tv_sec = (long long)(to_sec > 0) ? to_sec : 0, 0; 932 #endif 801 933 result = select(nfds, &recvfds, NULL, &errfds, &timeout); 802 934 … … 812 944 return TEST_SELECT_FAIL; 813 945 } 814 #elif defined(WOLFSSL_TIRTOS) 815 static INLINE int tcp_select(SOCKET_T socketfd, int to_sec)946 #elif defined(WOLFSSL_TIRTOS) || defined(WOLFSSL_KEIL_TCP_NET) 947 static WC_INLINE int tcp_select(SOCKET_T socketfd, int to_sec) 816 948 { 817 949 return TEST_RECV_READY; … … 820 952 821 953 822 static INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr,954 static WC_INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr, 823 955 int udp, int sctp) 824 956 { … … 844 976 err_sys("tcp bind failed"); 845 977 if (!udp) { 846 if (listen(*sockfd, 5) != 0) 978 #ifdef WOLFSSL_KEIL_TCP_NET 979 #define SOCK_LISTEN_MAX_QUEUE 1 980 #else 981 #define SOCK_LISTEN_MAX_QUEUE 5 982 #endif 983 if (listen(*sockfd, SOCK_LISTEN_MAX_QUEUE) != 0) 847 984 err_sys("tcp listen failed"); 848 985 } … … 863 1000 864 1001 #if 0 865 static INLINE int udp_read_connect(SOCKET_T sockfd)1002 static WC_INLINE int udp_read_connect(SOCKET_T sockfd) 866 1003 { 867 1004 SOCKADDR_IN_T cliaddr; … … 884 1021 #endif 885 1022 886 static INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,1023 static WC_INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, 887 1024 int useAnyAddr, word16 port, func_args* args) 888 1025 { … … 941 1078 } 942 1079 943 static INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,1080 static WC_INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, 944 1081 func_args* args, word16 port, int useAnyAddr, 945 1082 int udp, int sctp, int ready_file, int do_listen) … … 982 1119 if (ready_file) { 983 1120 #if !defined(NO_FILESYSTEM) || defined(FORCE_BUFFER_TEST) 984 FILE*srf = NULL;1121 XFILE srf = NULL; 985 1122 if (args) 986 1123 ready = args->signal; … … 1011 1148 1012 1149 1013 static INLINE void tcp_set_nonblocking(SOCKET_T* sockfd)1150 static WC_INLINE void tcp_set_nonblocking(SOCKET_T* sockfd) 1014 1151 { 1015 1152 #ifdef USE_WINDOWS_API … … 1037 1174 static const char* kIdentityStr = "Client_identity"; 1038 1175 1039 static INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,1176 static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint, 1040 1177 char* identity, unsigned int id_max_len, unsigned char* key, 1041 1178 unsigned int key_max_len) … … 1048 1185 strncpy(identity, kIdentityStr, id_max_len); 1049 1186 1187 if (wolfSSL_GetVersion(ssl) < WOLFSSL_TLSV1_3) { 1050 1188 /* test key in hex is 0x1a2b3c4d , in decimal 439,041,101 , we're using 1051 1189 unsigned binary */ 1052 key[0] = 26; 1053 key[1] = 43; 1054 key[2] = 60; 1055 key[3] = 77; 1190 key[0] = 0x1a; 1191 key[1] = 0x2b; 1192 key[2] = 0x3c; 1193 key[3] = 0x4d; 1194 1056 1195 1057 1196 return 4; /* length of key in octets or 0 for error */ 1058 1197 } 1059 1060 1061 static INLINE unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity, 1198 else { 1199 int i; 1200 int b = 0x01; 1201 1202 for (i = 0; i < 32; i++, b += 0x22) { 1203 if (b >= 0x100) 1204 b = 0x01; 1205 key[i] = b; 1206 } 1207 1208 return 32; /* length of key in octets or 0 for error */ 1209 } 1210 } 1211 1212 1213 static WC_INLINE unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity, 1062 1214 unsigned char* key, unsigned int key_max_len) 1063 1215 { … … 1069 1221 return 0; 1070 1222 1223 if (wolfSSL_GetVersion(ssl) < WOLFSSL_TLSV1_3) { 1071 1224 /* test key in hex is 0x1a2b3c4d , in decimal 439,041,101 , we're using 1072 1225 unsigned binary */ 1073 key[0] = 26; 1074 key[1] = 43; 1075 key[2] = 60; 1076 key[3] = 77; 1226 key[0] = 0x1a; 1227 key[1] = 0x2b; 1228 key[2] = 0x3c; 1229 key[3] = 0x4d; 1230 1077 1231 1078 1232 return 4; /* length of key in octets or 0 for error */ 1233 } 1234 else { 1235 int i; 1236 int b = 0x01; 1237 1238 for (i = 0; i < 32; i++, b += 0x22) { 1239 if (b >= 0x100) 1240 b = 0x01; 1241 key[i] = b; 1242 } 1243 1244 return 32; /* length of key in octets or 0 for error */ 1245 } 1246 } 1247 1248 1249 static WC_INLINE unsigned int my_psk_client_tls13_cb(WOLFSSL* ssl, 1250 const char* hint, char* identity, unsigned int id_max_len, 1251 unsigned char* key, unsigned int key_max_len, const char** ciphersuite) 1252 { 1253 int i; 1254 int b = 0x01; 1255 1256 (void)ssl; 1257 (void)hint; 1258 (void)key_max_len; 1259 1260 /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */ 1261 strncpy(identity, kIdentityStr, id_max_len); 1262 1263 for (i = 0; i < 32; i++, b += 0x22) { 1264 if (b >= 0x100) 1265 b = 0x01; 1266 key[i] = b; 1267 } 1268 1269 *ciphersuite = "TLS13-AES128-GCM-SHA256"; 1270 1271 return 32; /* length of key in octets or 0 for error */ 1272 } 1273 1274 1275 static WC_INLINE unsigned int my_psk_server_tls13_cb(WOLFSSL* ssl, 1276 const char* identity, unsigned char* key, unsigned int key_max_len, 1277 const char** ciphersuite) 1278 { 1279 int i; 1280 int b = 0x01; 1281 1282 (void)ssl; 1283 (void)key_max_len; 1284 1285 /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */ 1286 if (strncmp(identity, kIdentityStr, strlen(kIdentityStr)) != 0) 1287 return 0; 1288 1289 for (i = 0; i < 32; i++, b += 0x22) { 1290 if (b >= 0x100) 1291 b = 0x01; 1292 key[i] = b; 1293 } 1294 1295 *ciphersuite = "TLS13-AES128-GCM-SHA256"; 1296 1297 return 32; /* length of key in octets or 0 for error */ 1079 1298 } 1080 1299 … … 1090 1309 #include <windows.h> 1091 1310 1092 static INLINE double current_time(int reset)1311 static WC_INLINE double current_time(int reset) 1093 1312 { 1094 1313 static int init = 0; … … 1112 1331 #else 1113 1332 1114 #if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_TCP_NET) 1333 #if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_CHIBIOS) 1115 1334 #include <sys/time.h> 1116 1335 1117 static INLINE double current_time(int reset)1336 static WC_INLINE double current_time(int reset) 1118 1337 { 1119 1338 struct timeval tv; … … 1129 1348 1130 1349 1350 #if defined(HAVE_OCSP) && defined(WOLFSSL_NONBLOCK_OCSP) 1351 static WC_INLINE int OCSPIOCb(void* ioCtx, const char* url, int urlSz, 1352 unsigned char* request, int requestSz, unsigned char** response) 1353 { 1354 #ifdef TEST_NONBLOCK_CERTS 1355 static int ioCbCnt = 0; 1356 #endif 1357 1358 (void)ioCtx; 1359 (void)url; 1360 (void)urlSz; 1361 (void)request; 1362 (void)requestSz; 1363 (void)response; 1364 1365 #ifdef TEST_NONBLOCK_CERTS 1366 if (ioCbCnt) { 1367 ioCbCnt = 0; 1368 return EmbedOcspLookup(ioCtx, url, urlSz, request, requestSz, response); 1369 } 1370 else { 1371 ioCbCnt = 1; 1372 return WOLFSSL_CBIO_ERR_WANT_READ; 1373 } 1374 #else 1375 return EmbedOcspLookup(ioCtx, url, urlSz, request, requestSz, response); 1376 #endif 1377 } 1378 1379 static WC_INLINE void OCSPRespFreeCb(void* ioCtx, unsigned char* response) 1380 { 1381 (void)ioCtx; 1382 (void)response; 1383 } 1384 #endif 1385 1131 1386 #if !defined(NO_CERTS) 1132 1387 #if !defined(NO_FILESYSTEM) || \ … … 1134 1389 1135 1390 /* reads file size, allocates buffer, reads into buffer, returns buffer */ 1136 static INLINE int load_file(const char* fname, byte** buf, size_t* bufLen)1391 static WC_INLINE int load_file(const char* fname, byte** buf, size_t* bufLen) 1137 1392 { 1138 1393 int ret; 1139 1394 long int fileSz; 1140 FILE*file;1395 XFILE file; 1141 1396 1142 1397 if (fname == NULL || buf == NULL || bufLen == NULL) … … 1186 1441 }; 1187 1442 1188 static INLINE void load_buffer(WOLFSSL_CTX* ctx, const char* fname, int type)1443 static WC_INLINE void load_buffer(WOLFSSL_CTX* ctx, const char* fname, int type) 1189 1444 { 1190 1445 int format = WOLFSSL_FILETYPE_PEM; … … 1225 1480 free(buff); 1226 1481 } 1482 1483 static WC_INLINE void load_ssl_buffer(WOLFSSL* ssl, const char* fname, int type) 1484 { 1485 int format = WOLFSSL_FILETYPE_PEM; 1486 byte* buff = NULL; 1487 size_t sz = 0; 1488 1489 if (load_file(fname, &buff, &sz) != 0) { 1490 err_sys("can't open file for buffer load " 1491 "Please run from wolfSSL home directory if not"); 1492 } 1493 1494 /* determine format */ 1495 if (strstr(fname, ".der")) 1496 format = WOLFSSL_FILETYPE_ASN1; 1497 1498 if (type == WOLFSSL_CA) { 1499 /* verify certs (CA's) use the shared ctx->cm (WOLFSSL_CERT_MANAGER) */ 1500 WOLFSSL_CTX* ctx = wolfSSL_get_SSL_CTX(ssl); 1501 if (wolfSSL_CTX_load_verify_buffer(ctx, buff, (long)sz, format) 1502 != WOLFSSL_SUCCESS) 1503 err_sys("can't load buffer ca file"); 1504 } 1505 else if (type == WOLFSSL_CERT) { 1506 if (wolfSSL_use_certificate_buffer(ssl, buff, (long)sz, 1507 format) != WOLFSSL_SUCCESS) 1508 err_sys("can't load buffer cert file"); 1509 } 1510 else if (type == WOLFSSL_KEY) { 1511 if (wolfSSL_use_PrivateKey_buffer(ssl, buff, (long)sz, 1512 format) != WOLFSSL_SUCCESS) 1513 err_sys("can't load buffer key file"); 1514 } 1515 else if (type == WOLFSSL_CERT_CHAIN) { 1516 if (wolfSSL_use_certificate_chain_buffer_format(ssl, buff, 1517 (long)sz, format) != WOLFSSL_SUCCESS) 1518 err_sys("can't load cert chain buffer"); 1519 } 1520 1521 if (buff) 1522 free(buff); 1523 } 1524 1525 #ifdef TEST_PK_PRIVKEY 1526 static WC_INLINE int load_key_file(const char* fname, byte** derBuf, word32* derLen) 1527 { 1528 int ret; 1529 byte* buf = NULL; 1530 size_t bufLen; 1531 1532 ret = load_file(fname, &buf, &bufLen); 1533 if (ret != 0) 1534 return ret; 1535 1536 *derBuf = (byte*)malloc(bufLen); 1537 if (*derBuf == NULL) { 1538 free(buf); 1539 return MEMORY_E; 1540 } 1541 1542 ret = wc_KeyPemToDer(buf, (word32)bufLen, *derBuf, (word32)bufLen, NULL); 1543 if (ret < 0) { 1544 free(buf); 1545 free(*derBuf); 1546 return ret; 1547 } 1548 *derLen = ret; 1549 free(buf); 1550 1551 return 0; 1552 } 1553 #endif /* TEST_PK_PRIVKEY */ 1554 1227 1555 #endif /* !NO_FILESYSTEM || (NO_FILESYSTEM && FORCE_BUFFER_TEST) */ 1228 1556 #endif /* !NO_CERTS */ 1229 1557 1230 static INLINE int myVerify(int preverify, WOLFSSL_X509_STORE_CTX* store) 1558 static int myVerifyFail = 0; 1559 static WC_INLINE int myVerify(int preverify, WOLFSSL_X509_STORE_CTX* store) 1231 1560 { 1232 1561 char buffer[WOLFSSL_MAX_ERROR_SZ]; 1233 #if def OPENSSL_EXTRA1562 #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) 1234 1563 WOLFSSL_X509* peer; 1235 1564 #endif 1236 1565 (void)preverify; 1566 1567 /* Verify Callback Arguments: 1568 * preverify: 1=Verify Okay, 0=Failure 1569 * store->error: Failure error code (0 indicates no failure) 1570 * store->current_cert: Current WOLFSSL_X509 object (only with OPENSSL_EXTRA) 1571 * store->error_depth: Current Index 1572 * store->domain: Subject CN as string (null term) 1573 * store->totalCerts: Number of certs presented by peer 1574 * store->certs[i]: A `WOLFSSL_BUFFER_INFO` with plain DER for each cert 1575 * store->store: WOLFSSL_X509_STORE with CA cert chain 1576 * store->store->cm: WOLFSSL_CERT_MANAGER 1577 * store->ex_data: The WOLFSSL object pointer 1578 * store->discardSessionCerts: When set to non-zero value session certs 1579 will be discarded (only with SESSION_CERTS) 1580 */ 1237 1581 1238 1582 printf("In verification callback, error = %d, %s\n", store->error, 1239 1583 wolfSSL_ERR_error_string(store->error, buffer)); 1240 #if def OPENSSL_EXTRA1584 #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) 1241 1585 peer = store->current_cert; 1242 1586 if (peer) { … … 1264 1608 #endif 1265 1609 1266 printf("\tSubject's domain name is %s\n", store->domain); 1267 1268 printf("\tAllowing to continue anyway (shouldn't do this, EVER!!!)\n"); 1610 printf("\tSubject's domain name at %d is %s\n", store->error_depth, store->domain); 1611 1612 /* Testing forced fail case by return zero */ 1613 if (myVerifyFail) { 1614 return 0; /* test failure case */ 1615 } 1616 1617 /* If error indicate we are overriding it for testing purposes */ 1618 if (store->error != 0) { 1619 printf("\tAllowing failed certificate check, testing only " 1620 "(shouldn't do this in production)\n"); 1621 } 1622 1623 /* A non-zero return code indicates failure override */ 1269 1624 return 1; 1270 1625 } 1271 1626 1272 1627 1273 static INLINE int myDateCb(int preverify, WOLFSSL_X509_STORE_CTX* store)1628 static WC_INLINE int myDateCb(int preverify, WOLFSSL_X509_STORE_CTX* store) 1274 1629 { 1275 1630 char buffer[WOLFSSL_MAX_ERROR_SZ]; … … 1290 1645 1291 1646 1647 #ifdef HAVE_EXT_CACHE 1648 1649 static WC_INLINE WOLFSSL_SESSION* mySessGetCb(WOLFSSL* ssl, unsigned char* id, 1650 int id_len, int* copy) 1651 { 1652 (void)ssl; 1653 (void)id; 1654 (void)id_len; 1655 (void)copy; 1656 1657 /* using internal cache, this is for testing only */ 1658 return NULL; 1659 } 1660 1661 static WC_INLINE int mySessNewCb(WOLFSSL* ssl, WOLFSSL_SESSION* session) 1662 { 1663 (void)ssl; 1664 (void)session; 1665 1666 /* using internal cache, this is for testing only */ 1667 return 0; 1668 } 1669 1670 static WC_INLINE void mySessRemCb(WOLFSSL_CTX* ctx, WOLFSSL_SESSION* session) 1671 { 1672 (void)ctx; 1673 (void)session; 1674 1675 /* using internal cache, this is for testing only */ 1676 } 1677 1678 #endif /* HAVE_EXT_CACHE */ 1679 1680 1292 1681 #ifdef HAVE_CRL 1293 1682 1294 static INLINE void CRL_CallBack(const char* url)1683 static WC_INLINE void CRL_CallBack(const char* url) 1295 1684 { 1296 1685 printf("CRL callback url = %s\n", url); … … 1300 1689 1301 1690 #ifndef NO_DH 1302 static INLINE void SetDH(WOLFSSL* ssl)1691 static WC_INLINE void SetDH(WOLFSSL* ssl) 1303 1692 { 1304 1693 /* dh1024 p */ 1305 static unsigned char p[] =1694 static const unsigned char p[] = 1306 1695 { 1307 1696 0xE6, 0x96, 0x9D, 0x3D, 0x49, 0x5B, 0xE3, 0x2C, 0x7C, 0xF1, 0x80, 0xC3, … … 1319 1708 1320 1709 /* dh1024 g */ 1321 static unsigned char g[] =1710 static const unsigned char g[] = 1322 1711 { 1323 1712 0x02, … … 1327 1716 } 1328 1717 1329 static INLINE void SetDHCtx(WOLFSSL_CTX* ctx)1718 static WC_INLINE void SetDHCtx(WOLFSSL_CTX* ctx) 1330 1719 { 1331 1720 /* dh1024 p */ 1332 static unsigned char p[] =1721 static const unsigned char p[] = 1333 1722 { 1334 1723 0xE6, 0x96, 0x9D, 0x3D, 0x49, 0x5B, 0xE3, 0x2C, 0x7C, 0xF1, 0x80, 0xC3, … … 1346 1735 1347 1736 /* dh1024 g */ 1348 static unsigned char g[] =1737 static const unsigned char g[] = 1349 1738 { 1350 1739 0x02, … … 1357 1746 #ifndef NO_CERTS 1358 1747 1359 static INLINE void CaCb(unsigned char* der, int sz, int type)1748 static WC_INLINE void CaCb(unsigned char* der, int sz, int type) 1360 1749 { 1361 1750 (void)der; … … 1372 1761 #define MAX_WOLF_ROOT_DEPTH 5 1373 1762 1374 static INLINE int ChangeToWolfRoot(void)1763 static WC_INLINE int ChangeToWolfRoot(void) 1375 1764 { 1376 1765 #if !defined(NO_FILESYSTEM) || defined(FORCE_BUFFER_TEST) 1377 1766 int depth, res; 1378 FILE*file;1767 XFILE file; 1379 1768 for(depth = 0; depth <= MAX_WOLF_ROOT_DEPTH; depth++) { 1380 1769 file = fopen(ntruKeyFile, "rb"); … … 1407 1796 #define STACK_CHECK_VAL 0x01 1408 1797 1409 static INLINE int StackSizeCheck(func_args* args, thread_func tf)1798 static WC_INLINE int StackSizeCheck(func_args* args, thread_func tf) 1410 1799 { 1411 1800 int ret, i, used; … … 1476 1865 #endif /* HAVE_STACK_SIZE */ 1477 1866 1478 static INLINE void StackTrap(void)1867 static WC_INLINE void StackTrap(void) 1479 1868 { 1480 1869 struct rlimit rl; … … 1491 1880 #else /* STACK_TRAP */ 1492 1881 1493 static INLINE void StackTrap(void)1882 static WC_INLINE void StackTrap(void) 1494 1883 { 1495 1884 } … … 1514 1903 1515 1904 1516 static INLINE int myMacEncryptCb(WOLFSSL* ssl, unsigned char* macOut,1905 static WC_INLINE int myMacEncryptCb(WOLFSSL* ssl, unsigned char* macOut, 1517 1906 const unsigned char* macIn, unsigned int macInSz, int macContent, 1518 1907 int macVerify, unsigned char* encOut, const unsigned char* encIn, … … 1582 1971 1583 1972 1584 static INLINE int myDecryptVerifyCb(WOLFSSL* ssl,1973 static WC_INLINE int myDecryptVerifyCb(WOLFSSL* ssl, 1585 1974 unsigned char* decOut, const unsigned char* decIn, 1586 1975 unsigned int decSz, int macContent, int macVerify, … … 1596 1985 Hmac hmac; 1597 1986 byte myInner[WOLFSSL_TLS_HMAC_INNER_SZ]; 1598 byte verify[ MAX_DIGEST_SIZE];1987 byte verify[WC_MAX_DIGEST_SIZE]; 1599 1988 const char* tlsStr = "TLS"; 1600 1989 … … 1680 2069 1681 2070 1682 static INLINE void SetupAtomicUser(WOLFSSL_CTX* ctx, WOLFSSL* ssl)2071 static WC_INLINE void SetupAtomicUser(WOLFSSL_CTX* ctx, WOLFSSL* ssl) 1683 2072 { 1684 2073 AtomicEncCtx* encCtx; … … 1688 2077 if (encCtx == NULL) 1689 2078 err_sys("AtomicEncCtx malloc failed"); 1690 memset(encCtx, 0, sizeof(AtomicEncCtx));2079 XMEMSET(encCtx, 0, sizeof(AtomicEncCtx)); 1691 2080 1692 2081 decCtx = (AtomicDecCtx*)malloc(sizeof(AtomicDecCtx)); … … 1695 2084 err_sys("AtomicDecCtx malloc failed"); 1696 2085 } 1697 memset(decCtx, 0, sizeof(AtomicDecCtx));2086 XMEMSET(decCtx, 0, sizeof(AtomicDecCtx)); 1698 2087 1699 2088 wolfSSL_CTX_SetMacEncryptCb(ctx, myMacEncryptCb); … … 1705 2094 1706 2095 1707 static INLINE void FreeAtomicUser(WOLFSSL* ssl)2096 static WC_INLINE void FreeAtomicUser(WOLFSSL* ssl) 1708 2097 { 1709 2098 AtomicEncCtx* encCtx = (AtomicEncCtx*)wolfSSL_GetMacEncryptCtx(ssl); … … 1717 2106 1718 2107 #ifdef WOLFSSL_STATIC_MEMORY 1719 static INLINE int wolfSSL_PrintStats(WOLFSSL_MEM_STATS* stats)2108 static WC_INLINE int wolfSSL_PrintStats(WOLFSSL_MEM_STATS* stats) 1720 2109 { 1721 2110 word16 i; … … 1744 2133 #ifdef HAVE_PK_CALLBACKS 1745 2134 2135 typedef struct PkCbInfo { 2136 const char* ourKey; 2137 #ifdef TEST_PK_PRIVKEY 2138 union { 1746 2139 #ifdef HAVE_ECC 1747 1748 static INLINE int myEccSign(WOLFSSL* ssl, const byte* in, word32 inSz, 1749 byte* out, word32* outSz, const byte* key, word32 keySz, void* ctx) 1750 { 2140 ecc_key ecc; 2141 #endif 2142 #ifdef HAVE_CURVE25519 2143 curve25519_key curve; 2144 #endif 2145 } keyGen; 2146 #endif 2147 } PkCbInfo; 2148 2149 #if defined(DEBUG_PK_CB) || defined(TEST_PK_PRIVKEY) 2150 #define WOLFSSL_PKMSG(_f_, ...) printf(_f_, ##__VA_ARGS__) 2151 #else 2152 #define WOLFSSL_PKMSG(_f_, ...) 2153 #endif 2154 2155 #ifdef HAVE_ECC 2156 2157 static WC_INLINE int myEccKeyGen(WOLFSSL* ssl, ecc_key* key, word32 keySz, 2158 int ecc_curve, void* ctx) 2159 { 2160 int ret; 1751 2161 WC_RNG rng; 1752 int ret; 1753 word32 idx = 0; 1754 ecc_key myKey; 2162 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2163 ecc_key* new_key = key; 2164 #ifdef TEST_PK_PRIVKEY 2165 byte qx[MAX_ECC_BYTES], qy[MAX_ECC_BYTES]; 2166 word32 qxLen = sizeof(qx), qyLen = sizeof(qy); 2167 new_key = &cbInfo->keyGen.ecc; 2168 #endif 1755 2169 1756 2170 (void)ssl; 1757 (void)ctx; 2171 (void)cbInfo; 2172 2173 WOLFSSL_PKMSG("PK ECC KeyGen: keySz %d, Curve ID %d\n", keySz, ecc_curve); 1758 2174 1759 2175 ret = wc_InitRng(&rng); … … 1761 2177 return ret; 1762 2178 2179 ret = wc_ecc_init(new_key); 2180 if (ret == 0) { 2181 /* create new key */ 2182 ret = wc_ecc_make_key_ex(&rng, keySz, new_key, ecc_curve); 2183 2184 #ifdef TEST_PK_PRIVKEY 2185 if (ret == 0) { 2186 /* extract public portion from new key into `key` arg */ 2187 ret = wc_ecc_export_public_raw(new_key, qx, &qxLen, qy, &qyLen); 2188 if (ret == 0) { 2189 /* load public portion only into key */ 2190 ret = wc_ecc_import_unsigned(key, qx, qy, NULL, ecc_curve); 2191 } 2192 (void)qxLen; 2193 (void)qyLen; 2194 } 2195 #endif 2196 } 2197 2198 WOLFSSL_PKMSG("PK ECC KeyGen: ret %d\n", ret); 2199 2200 wc_FreeRng(&rng); 2201 2202 return ret; 2203 } 2204 2205 static WC_INLINE int myEccSign(WOLFSSL* ssl, const byte* in, word32 inSz, 2206 byte* out, word32* outSz, const byte* key, word32 keySz, void* ctx) 2207 { 2208 int ret; 2209 WC_RNG rng; 2210 word32 idx = 0; 2211 ecc_key myKey; 2212 byte* keyBuf = (byte*)key; 2213 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2214 2215 (void)ssl; 2216 (void)cbInfo; 2217 2218 WOLFSSL_PKMSG("PK ECC Sign: inSz %d, keySz %d\n", inSz, keySz); 2219 2220 #ifdef TEST_PK_PRIVKEY 2221 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz); 2222 if (ret != 0) 2223 return ret; 2224 #endif 2225 2226 ret = wc_InitRng(&rng); 2227 if (ret != 0) 2228 return ret; 2229 1763 2230 ret = wc_ecc_init(&myKey); 1764 2231 if (ret == 0) { 1765 ret = wc_EccPrivateKeyDecode(key, &idx, &myKey, keySz); 1766 if (ret == 0) 2232 ret = wc_EccPrivateKeyDecode(keyBuf, &idx, &myKey, keySz); 2233 if (ret == 0) { 2234 WOLFSSL_PKMSG("PK ECC Sign: Curve ID %d\n", myKey.dp->id); 1767 2235 ret = wc_ecc_sign_hash(in, inSz, out, outSz, &rng, &myKey); 2236 } 1768 2237 wc_ecc_free(&myKey); 1769 2238 } 1770 2239 wc_FreeRng(&rng); 1771 2240 2241 #ifdef TEST_PK_PRIVKEY 2242 free(keyBuf); 2243 #endif 2244 2245 WOLFSSL_PKMSG("PK ECC Sign: ret %d outSz %d\n", ret, *outSz); 2246 1772 2247 return ret; 1773 2248 } 1774 2249 1775 2250 1776 static INLINE int myEccVerify(WOLFSSL* ssl, const byte* sig, word32 sigSz,2251 static WC_INLINE int myEccVerify(WOLFSSL* ssl, const byte* sig, word32 sigSz, 1777 2252 const byte* hash, word32 hashSz, const byte* key, word32 keySz, 1778 2253 int* result, void* ctx) 1779 2254 { 1780 2255 int ret; 2256 word32 idx = 0; 1781 2257 ecc_key myKey; 2258 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 1782 2259 1783 2260 (void)ssl; 1784 (void)ctx; 2261 (void)cbInfo; 2262 2263 WOLFSSL_PKMSG("PK ECC Verify: sigSz %d, hashSz %d, keySz %d\n", sigSz, hashSz, keySz); 1785 2264 1786 2265 ret = wc_ecc_init(&myKey); 1787 2266 if (ret == 0) { 1788 ret = wc_ ecc_import_x963(key, keySz, &myKey);2267 ret = wc_EccPublicKeyDecode(key, &idx, &myKey, keySz); 1789 2268 if (ret == 0) 1790 2269 ret = wc_ecc_verify_hash(sig, sigSz, hash, hashSz, result, &myKey); … … 1792 2271 } 1793 2272 2273 WOLFSSL_PKMSG("PK ECC Verify: ret %d, result %d\n", ret, *result); 2274 1794 2275 return ret; 1795 2276 } 1796 2277 1797 static INLINE int myEccSharedSecret(WOLFSSL* ssl, ecc_key* otherKey,2278 static WC_INLINE int myEccSharedSecret(WOLFSSL* ssl, ecc_key* otherKey, 1798 2279 unsigned char* pubKeyDer, unsigned int* pubKeySz, 1799 2280 unsigned char* out, unsigned int* outlen, … … 1804 2285 ecc_key* pubKey = NULL; 1805 2286 ecc_key tmpKey; 2287 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 1806 2288 1807 2289 (void)ssl; 1808 (void)ctx; 2290 (void)cbInfo; 2291 2292 WOLFSSL_PKMSG("PK ECC PMS: Side %s, Peer Curve %d\n", 2293 side == WOLFSSL_CLIENT_END ? "client" : "server", otherKey->dp->id); 1809 2294 1810 2295 ret = wc_ecc_init(&tmpKey); … … 1836 2321 /* for server: import public key */ 1837 2322 else if (side == WOLFSSL_SERVER_END) { 2323 #ifdef TEST_PK_PRIVKEY 2324 privKey = &cbInfo->keyGen.ecc; 2325 #else 1838 2326 privKey = otherKey; 2327 #endif 1839 2328 pubKey = &tmpKey; 1840 2329 … … 1857 2346 } 1858 2347 2348 #ifdef TEST_PK_PRIVKEY 2349 if (side == WOLFSSL_SERVER_END) { 2350 wc_ecc_free(&cbInfo->keyGen.ecc); 2351 } 2352 #endif 2353 1859 2354 wc_ecc_free(&tmpKey); 1860 2355 2356 WOLFSSL_PKMSG("PK ECC PMS: ret %d, PubKeySz %d, OutLen %d\n", ret, *pubKeySz, *outlen); 2357 1861 2358 return ret; 1862 2359 } 1863 2360 1864 2361 #ifdef HAVE_ED25519 1865 static INLINE int myEd25519Sign(WOLFSSL* ssl, const byte* in, word32 inSz,2362 static WC_INLINE int myEd25519Sign(WOLFSSL* ssl, const byte* in, word32 inSz, 1866 2363 byte* out, word32* outSz, const byte* key, word32 keySz, void* ctx) 1867 2364 { … … 1869 2366 word32 idx = 0; 1870 2367 ed25519_key myKey; 2368 byte* keyBuf = (byte*)key; 2369 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 1871 2370 1872 2371 (void)ssl; 1873 (void)ctx; 2372 (void)cbInfo; 2373 2374 WOLFSSL_PKMSG("PK 25519 Sign: inSz %d, keySz %d\n", inSz, keySz); 2375 2376 #ifdef TEST_PK_PRIVKEY 2377 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz); 2378 if (ret != 0) 2379 return ret; 2380 #endif 1874 2381 1875 2382 ret = wc_ed25519_init(&myKey); 1876 2383 if (ret == 0) { 1877 ret = wc_Ed25519PrivateKeyDecode(key , &idx, &myKey, keySz);2384 ret = wc_Ed25519PrivateKeyDecode(keyBuf, &idx, &myKey, keySz); 1878 2385 if (ret == 0) 1879 2386 ret = wc_ed25519_sign_msg(in, inSz, out, outSz, &myKey); … … 1881 2388 } 1882 2389 2390 #ifdef TEST_PK_PRIVKEY 2391 free(keyBuf); 2392 #endif 2393 2394 WOLFSSL_PKMSG("PK 25519 Sign: ret %d, outSz %d\n", ret, *outSz); 2395 1883 2396 return ret; 1884 2397 } 1885 2398 1886 2399 1887 static INLINE int myEd25519Verify(WOLFSSL* ssl, const byte* sig, word32 sigSz,2400 static WC_INLINE int myEd25519Verify(WOLFSSL* ssl, const byte* sig, word32 sigSz, 1888 2401 const byte* msg, word32 msgSz, const byte* key, word32 keySz, 1889 2402 int* result, void* ctx) … … 1891 2404 int ret; 1892 2405 ed25519_key myKey; 2406 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 1893 2407 1894 2408 (void)ssl; 1895 (void)ctx; 2409 (void)cbInfo; 2410 2411 WOLFSSL_PKMSG("PK 25519 Verify: sigSz %d, msgSz %d, keySz %d\n", sigSz, msgSz, keySz); 1896 2412 1897 2413 ret = wc_ed25519_init(&myKey); … … 1904 2420 } 1905 2421 2422 WOLFSSL_PKMSG("PK 25519 Verify: ret %d, result %d\n", ret, *result); 2423 1906 2424 return ret; 1907 2425 } … … 1909 2427 1910 2428 #ifdef HAVE_CURVE25519 1911 static INLINE int myX25519SharedSecret(WOLFSSL* ssl, curve25519_key* otherKey, 2429 static WC_INLINE int myX25519KeyGen(WOLFSSL* ssl, curve25519_key* key, 2430 unsigned int keySz, void* ctx) 2431 { 2432 int ret; 2433 WC_RNG rng; 2434 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2435 2436 (void)ssl; 2437 (void)cbInfo; 2438 2439 WOLFSSL_PKMSG("PK 25519 KeyGen: keySz %d\n", keySz); 2440 2441 ret = wc_InitRng(&rng); 2442 if (ret != 0) 2443 return ret; 2444 2445 ret = wc_curve25519_make_key(&rng, keySz, key); 2446 2447 wc_FreeRng(&rng); 2448 2449 WOLFSSL_PKMSG("PK 25519 KeyGen: ret %d\n", ret); 2450 2451 return ret; 2452 } 2453 2454 static WC_INLINE int myX25519SharedSecret(WOLFSSL* ssl, curve25519_key* otherKey, 1912 2455 unsigned char* pubKeyDer, unsigned int* pubKeySz, 1913 2456 unsigned char* out, unsigned int* outlen, … … 1918 2461 curve25519_key* pubKey = NULL; 1919 2462 curve25519_key tmpKey; 2463 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 1920 2464 1921 2465 (void)ssl; 1922 (void)ctx; 2466 (void)cbInfo; 2467 2468 WOLFSSL_PKMSG("PK 25519 PMS: side %s\n", 2469 side == WOLFSSL_CLIENT_END ? "client" : "server"); 1923 2470 1924 2471 ret = wc_curve25519_init(&tmpKey); … … 1965 2512 wc_curve25519_free(&tmpKey); 1966 2513 2514 WOLFSSL_PKMSG("PK 25519 PMS: ret %d, pubKeySz %d, outLen %d\n", 2515 ret, *pubKeySz, *outlen); 2516 1967 2517 return ret; 1968 2518 } … … 1971 2521 #endif /* HAVE_ECC */ 1972 2522 2523 #ifndef NO_DH 2524 static WC_INLINE int myDhCallback(WOLFSSL* ssl, struct DhKey* key, 2525 const unsigned char* priv, unsigned int privSz, 2526 const unsigned char* pubKeyDer, unsigned int pubKeySz, 2527 unsigned char* out, unsigned int* outlen, 2528 void* ctx) 2529 { 2530 int ret; 2531 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2532 2533 (void)ssl; 2534 (void)cbInfo; 2535 2536 /* return 0 on success */ 2537 ret = wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz); 2538 2539 WOLFSSL_PKMSG("PK ED Agree: ret %d, privSz %d, pubKeySz %d, outlen %d\n", 2540 ret, privSz, pubKeySz, *outlen); 2541 2542 return ret; 2543 }; 2544 2545 #endif /* !NO_DH */ 2546 1973 2547 #ifndef NO_RSA 1974 2548 1975 static INLINE int myRsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,2549 static WC_INLINE int myRsaSign(WOLFSSL* ssl, const byte* in, word32 inSz, 1976 2550 byte* out, word32* outSz, const byte* key, word32 keySz, void* ctx) 1977 2551 { … … 1980 2554 word32 idx = 0; 1981 2555 RsaKey myKey; 2556 byte* keyBuf = (byte*)key; 2557 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 1982 2558 1983 2559 (void)ssl; 1984 (void)ctx; 2560 (void)cbInfo; 2561 2562 WOLFSSL_PKMSG("PK RSA Sign: inSz %d, keySz %d\n", inSz, keySz); 2563 2564 #ifdef TEST_PK_PRIVKEY 2565 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz); 2566 if (ret != 0) 2567 return ret; 2568 #endif 1985 2569 1986 2570 ret = wc_InitRng(&rng); … … 1990 2574 ret = wc_InitRsaKey(&myKey, NULL); 1991 2575 if (ret == 0) { 1992 ret = wc_RsaPrivateKeyDecode(key , &idx, &myKey, keySz);2576 ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz); 1993 2577 if (ret == 0) 1994 2578 ret = wc_RsaSSL_Sign(in, inSz, out, *outSz, &myKey, &rng); … … 2001 2585 wc_FreeRng(&rng); 2002 2586 2587 #ifdef TEST_PK_PRIVKEY 2588 free(keyBuf); 2589 #endif 2590 2591 WOLFSSL_PKMSG("PK RSA Sign: ret %d, outSz %d\n", ret, *outSz); 2592 2003 2593 return ret; 2004 2594 } 2005 2595 2006 2596 2007 static INLINE int myRsaVerify(WOLFSSL* ssl, byte* sig, word32 sigSz, 2008 byte** out, 2009 const byte* key, word32 keySz, 2010 void* ctx) 2597 static WC_INLINE int myRsaVerify(WOLFSSL* ssl, byte* sig, word32 sigSz, 2598 byte** out, const byte* key, word32 keySz, void* ctx) 2011 2599 { 2012 2600 int ret; 2013 2601 word32 idx = 0; 2014 2602 RsaKey myKey; 2603 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2015 2604 2016 2605 (void)ssl; 2017 (void)ctx; 2606 (void)cbInfo; 2607 2608 WOLFSSL_PKMSG("PK RSA Verify: sigSz %d, keySz %d\n", sigSz, keySz); 2018 2609 2019 2610 ret = wc_InitRsaKey(&myKey, NULL); … … 2025 2616 } 2026 2617 2618 WOLFSSL_PKMSG("PK RSA Verify: ret %d\n", ret); 2619 2027 2620 return ret; 2028 2621 } 2029 2622 2623 static WC_INLINE int myRsaSignCheck(WOLFSSL* ssl, byte* sig, word32 sigSz, 2624 byte** out, const byte* key, word32 keySz, void* ctx) 2625 { 2626 int ret; 2627 word32 idx = 0; 2628 RsaKey myKey; 2629 byte* keyBuf = (byte*)key; 2630 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2631 2632 (void)ssl; 2633 (void)cbInfo; 2634 2635 WOLFSSL_PKMSG("PK RSA SignCheck: sigSz %d, keySz %d\n", sigSz, keySz); 2636 2637 #ifdef TEST_PK_PRIVKEY 2638 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz); 2639 if (ret != 0) 2640 return ret; 2641 #endif 2642 2643 ret = wc_InitRsaKey(&myKey, NULL); 2644 if (ret == 0) { 2645 ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz); 2646 if (ret == 0) 2647 ret = wc_RsaSSL_VerifyInline(sig, sigSz, out, &myKey); 2648 wc_FreeRsaKey(&myKey); 2649 } 2650 #ifdef TEST_PK_PRIVKEY 2651 free(keyBuf); 2652 #endif 2653 2654 WOLFSSL_PKMSG("PK RSA SignCheck: ret %d\n", ret); 2655 2656 return ret; 2657 } 2658 2030 2659 #ifdef WC_RSA_PSS 2031 static INLINE int myRsaPssSign(WOLFSSL* ssl, const byte* in, word32 inSz,2660 static WC_INLINE int myRsaPssSign(WOLFSSL* ssl, const byte* in, word32 inSz, 2032 2661 byte* out, word32* outSz, int hash, int mgf, const byte* key, 2033 2662 word32 keySz, void* ctx) … … 2038 2667 word32 idx = 0; 2039 2668 RsaKey myKey; 2669 byte* keyBuf = (byte*)key; 2670 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2040 2671 2041 2672 (void)ssl; 2042 (void)ctx; 2673 (void)cbInfo; 2674 2675 WOLFSSL_PKMSG("PK RSA PSS Sign: inSz %d, hash %d, mgf %d, keySz %d\n", 2676 inSz, hash, mgf, keySz); 2677 2678 #ifdef TEST_PK_PRIVKEY 2679 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz); 2680 if (ret != 0) 2681 return ret; 2682 #endif 2043 2683 2044 2684 switch (hash) { … … 2066 2706 ret = wc_InitRsaKey(&myKey, NULL); 2067 2707 if (ret == 0) { 2068 ret = wc_RsaPrivateKeyDecode(key , &idx, &myKey, keySz);2708 ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz); 2069 2709 if (ret == 0) { 2070 2710 ret = wc_RsaPSS_Sign(in, inSz, out, *outSz, hashType, mgf, &myKey, … … 2079 2719 wc_FreeRng(&rng); 2080 2720 2721 #ifdef TEST_PK_PRIVKEY 2722 free(keyBuf); 2723 #endif 2724 2725 WOLFSSL_PKMSG("PK RSA PSS Sign: ret %d, outSz %d\n", ret, *outSz); 2726 2081 2727 return ret; 2082 2728 } 2083 2729 2084 2730 2085 static INLINE int myRsaPssVerify(WOLFSSL* ssl, byte* sig, word32 sigSz,2731 static WC_INLINE int myRsaPssVerify(WOLFSSL* ssl, byte* sig, word32 sigSz, 2086 2732 byte** out, int hash, int mgf, const byte* key, word32 keySz, void* ctx) 2087 2733 { 2088 enum wc_HashType hashType = WC_HASH_TYPE_NONE;2089 2734 int ret; 2090 2735 word32 idx = 0; 2091 2736 RsaKey myKey; 2737 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2738 enum wc_HashType hashType = WC_HASH_TYPE_NONE; 2092 2739 2093 2740 (void)ssl; 2094 (void)ctx; 2741 (void)cbInfo; 2742 2743 WOLFSSL_PKMSG("PK RSA PSS Verify: sigSz %d, hash %d, mgf %d, keySz %d\n", 2744 sigSz, hash, mgf, keySz); 2095 2745 2096 2746 switch (hash) { … … 2122 2772 } 2123 2773 2774 WOLFSSL_PKMSG("PK RSA PSS Verify: ret %d\n", ret); 2775 2124 2776 return ret; 2125 2777 } 2126 #endif 2127 2128 2129 static INLINE int myRsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz, 2778 2779 static WC_INLINE int myRsaPssSignCheck(WOLFSSL* ssl, byte* sig, word32 sigSz, 2780 byte** out, int hash, int mgf, const byte* key, word32 keySz, void* ctx) 2781 { 2782 int ret; 2783 word32 idx = 0; 2784 RsaKey myKey; 2785 byte* keyBuf = (byte*)key; 2786 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2787 enum wc_HashType hashType = WC_HASH_TYPE_NONE; 2788 2789 (void)ssl; 2790 (void)cbInfo; 2791 2792 WOLFSSL_PKMSG("PK RSA PSS SignCheck: sigSz %d, hash %d, mgf %d, keySz %d\n", 2793 sigSz, hash, mgf, keySz); 2794 2795 #ifdef TEST_PK_PRIVKEY 2796 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz); 2797 if (ret != 0) 2798 return ret; 2799 #endif 2800 2801 switch (hash) { 2802 #ifndef NO_SHA256 2803 case SHA256h: 2804 hashType = WC_HASH_TYPE_SHA256; 2805 break; 2806 #endif 2807 #ifdef WOLFSSL_SHA384 2808 case SHA384h: 2809 hashType = WC_HASH_TYPE_SHA384; 2810 break; 2811 #endif 2812 #ifdef WOLFSSL_SHA512 2813 case SHA512h: 2814 hashType = WC_HASH_TYPE_SHA512; 2815 break; 2816 #endif 2817 } 2818 2819 ret = wc_InitRsaKey(&myKey, NULL); 2820 if (ret == 0) { 2821 ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz); 2822 if (ret == 0) { 2823 ret = wc_RsaPSS_VerifyInline(sig, sigSz, out, hashType, mgf, 2824 &myKey); 2825 } 2826 wc_FreeRsaKey(&myKey); 2827 } 2828 2829 #ifdef TEST_PK_PRIVKEY 2830 free(keyBuf); 2831 #endif 2832 2833 WOLFSSL_PKMSG("PK RSA PSS SignCheck: ret %d\n", ret); 2834 2835 return ret; 2836 } 2837 #endif 2838 2839 2840 static WC_INLINE int myRsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz, 2130 2841 byte* out, word32* outSz, const byte* key, 2131 2842 word32 keySz, void* ctx) … … 2135 2846 RsaKey myKey; 2136 2847 WC_RNG rng; 2848 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2137 2849 2138 2850 (void)ssl; 2139 (void)ctx; 2851 (void)cbInfo; 2852 2853 WOLFSSL_PKMSG("PK RSA Enc: inSz %d, keySz %d\n", inSz, keySz); 2140 2854 2141 2855 ret = wc_InitRng(&rng); … … 2157 2871 wc_FreeRng(&rng); 2158 2872 2873 WOLFSSL_PKMSG("PK RSA Enc: ret %d, outSz %d\n", ret, *outSz); 2874 2159 2875 return ret; 2160 2876 } 2161 2877 2162 static INLINE int myRsaDec(WOLFSSL* ssl, byte* in, word32 inSz,2878 static WC_INLINE int myRsaDec(WOLFSSL* ssl, byte* in, word32 inSz, 2163 2879 byte** out, 2164 2880 const byte* key, word32 keySz, void* ctx) … … 2167 2883 word32 idx = 0; 2168 2884 RsaKey myKey; 2885 byte* keyBuf = (byte*)key; 2886 PkCbInfo* cbInfo = (PkCbInfo*)ctx; 2169 2887 2170 2888 (void)ssl; 2171 (void)ctx; 2889 (void)cbInfo; 2890 2891 WOLFSSL_PKMSG("PK RSA Dec: inSz %d, keySz %d\n", inSz, keySz); 2892 2893 #ifdef TEST_PK_PRIVKEY 2894 ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz); 2895 if (ret != 0) 2896 return ret; 2897 #endif 2172 2898 2173 2899 ret = wc_InitRsaKey(&myKey, NULL); 2174 2900 if (ret == 0) { 2175 ret = wc_RsaPrivateKeyDecode(key , &idx, &myKey, keySz);2901 ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz); 2176 2902 if (ret == 0) { 2177 2903 #ifdef WC_RSA_BLINDING … … 2187 2913 } 2188 2914 2915 #ifdef TEST_PK_PRIVKEY 2916 free(keyBuf); 2917 #endif 2918 2919 WOLFSSL_PKMSG("PK RSA Dec: ret %d\n", ret); 2920 2189 2921 return ret; 2190 2922 } … … 2192 2924 #endif /* NO_RSA */ 2193 2925 2194 static INLINE void SetupPkCallbacks(WOLFSSL_CTX* ctx, WOLFSSL* ssl)2926 static WC_INLINE void SetupPkCallbacks(WOLFSSL_CTX* ctx) 2195 2927 { 2196 2928 (void)ctx; 2197 (void)ssl;2198 2929 2199 2930 #ifdef HAVE_ECC 2931 wolfSSL_CTX_SetEccKeyGenCb(ctx, myEccKeyGen); 2200 2932 wolfSSL_CTX_SetEccSignCb(ctx, myEccSign); 2201 2933 wolfSSL_CTX_SetEccVerifyCb(ctx, myEccVerify); 2202 2934 wolfSSL_CTX_SetEccSharedSecretCb(ctx, myEccSharedSecret); 2203 2935 #endif /* HAVE_ECC */ 2936 #ifndef NO_DH 2937 wolfSSL_CTX_SetDhAgreeCb(ctx, myDhCallback); 2938 #endif 2204 2939 #ifdef HAVE_ED25519 2205 2940 wolfSSL_CTX_SetEd25519SignCb(ctx, myEd25519Sign); … … 2207 2942 #endif 2208 2943 #ifdef HAVE_CURVE25519 2944 wolfSSL_CTX_SetX25519KeyGenCb(ctx, myX25519KeyGen); 2209 2945 wolfSSL_CTX_SetX25519SharedSecretCb(ctx, myX25519SharedSecret); 2210 2946 #endif … … 2212 2948 wolfSSL_CTX_SetRsaSignCb(ctx, myRsaSign); 2213 2949 wolfSSL_CTX_SetRsaVerifyCb(ctx, myRsaVerify); 2950 wolfSSL_CTX_SetRsaSignCheckCb(ctx, myRsaSignCheck); 2214 2951 #ifdef WC_RSA_PSS 2215 2952 wolfSSL_CTX_SetRsaPssSignCb(ctx, myRsaPssSign); 2216 2953 wolfSSL_CTX_SetRsaPssVerifyCb(ctx, myRsaPssVerify); 2954 wolfSSL_CTX_SetRsaPssSignCheckCb(ctx, myRsaPssSignCheck); 2217 2955 #endif 2218 2956 wolfSSL_CTX_SetRsaEncCb(ctx, myRsaEnc); … … 2221 2959 } 2222 2960 2961 static WC_INLINE void SetupPkCallbackContexts(WOLFSSL* ssl, void* myCtx) 2962 { 2963 #ifdef HAVE_ECC 2964 wolfSSL_SetEccKeyGenCtx(ssl, myCtx); 2965 wolfSSL_SetEccSignCtx(ssl, myCtx); 2966 wolfSSL_SetEccVerifyCtx(ssl, myCtx); 2967 wolfSSL_SetEccSharedSecretCtx(ssl, myCtx); 2968 #endif /* HAVE_ECC */ 2969 #ifndef NO_DH 2970 wolfSSL_SetDhAgreeCtx(ssl, myCtx); 2971 #endif 2972 #ifdef HAVE_ED25519 2973 wolfSSL_SetEd25519SignCtx(ssl, myCtx); 2974 wolfSSL_SetEd25519VerifyCtx(ssl, myCtx); 2975 #endif 2976 #ifdef HAVE_CURVE25519 2977 wolfSSL_SetX25519KeyGenCtx(ssl, myCtx); 2978 wolfSSL_SetX25519SharedSecretCtx(ssl, myCtx); 2979 #endif 2980 #ifndef NO_RSA 2981 wolfSSL_SetRsaSignCtx(ssl, myCtx); 2982 wolfSSL_SetRsaVerifyCtx(ssl, myCtx); 2983 #ifdef WC_RSA_PSS 2984 wolfSSL_SetRsaPssSignCtx(ssl, myCtx); 2985 wolfSSL_SetRsaPssVerifyCtx(ssl, myCtx); 2986 #endif 2987 wolfSSL_SetRsaEncCtx(ssl, myCtx); 2988 wolfSSL_SetRsaDecCtx(ssl, myCtx); 2989 #endif /* NO_RSA */ 2990 } 2991 2223 2992 #endif /* HAVE_PK_CALLBACKS */ 2224 2225 2993 2226 2994 … … 2231 2999 2232 3000 /* HP/UX doesn't have strsep, needed by test/suites.c */ 2233 static INLINE char* strsep(char **stringp, const char *delim)3001 static WC_INLINE char* strsep(char **stringp, const char *delim) 2234 3002 { 2235 3003 char* start; … … 2255 3023 len does not include null terminating character, 2256 3024 num is number of characters in tempfn name to randomize */ 2257 static INLINE const char* mymktemp(char *tempfn, int len, int num)3025 static WC_INLINE const char* mymktemp(char *tempfn, int len, int num) 2258 3026 { 2259 3027 int x, size; … … 2285 3053 2286 3054 wc_FreeRng(&rng); 3055 (void)rng; /* for WC_NO_RNG case */ 2287 3056 2288 3057 return tempfn; … … 2301 3070 } key_ctx; 2302 3071 2303 static key_ctx myKey_ctx;2304 static WC_RNG myKey_rng;2305 2306 static INLINE int TicketInit(void)3072 static THREAD_LS_T key_ctx myKey_ctx; 3073 static THREAD_LS_T WC_RNG myKey_rng; 3074 3075 static WC_INLINE int TicketInit(void) 2307 3076 { 2308 3077 int ret = wc_InitRng(&myKey_rng); … … 2318 3087 } 2319 3088 2320 static INLINE void TicketCleanup(void)3089 static WC_INLINE void TicketCleanup(void) 2321 3090 { 2322 3091 wc_FreeRng(&myKey_rng); 2323 3092 } 2324 3093 2325 static INLINE int myTicketEncCb(WOLFSSL* ssl,3094 static WC_INLINE int myTicketEncCb(WOLFSSL* ssl, 2326 3095 byte key_name[WOLFSSL_TICKET_NAME_SZ], 2327 3096 byte iv[WOLFSSL_TICKET_IV_SZ], … … 2389 3158 #endif /* HAVE_SESSION_TICKET && CHACHA20 && POLY1305 */ 2390 3159 2391 static INLINE word16 GetRandomPort(void)3160 static WC_INLINE word16 GetRandomPort(void) 2392 3161 { 2393 3162 word16 port = 0; … … 2396 3165 WC_RNG rng; 2397 3166 if (wc_InitRng(&rng) == 0) { 2398 wc_RNG_GenerateBlock(&rng, (byte*)&port, sizeof(port));3167 if (wc_RNG_GenerateBlock(&rng, (byte*)&port, sizeof(port)) == 0) { 2399 3168 port |= 0xC000; /* Make sure its in the 49152 - 65535 range */ 3169 } 2400 3170 wc_FreeRng(&rng); 2401 3171 } 3172 (void)rng; /* for WC_NO_RNG case */ 2402 3173 return port; 2403 3174 }
Note:
See TracChangeset
for help on using the changeset viewer.