Ignore:
Timestamp:
Feb 7, 2019, 8:36:33 AM (5 years ago)
Author:
coas-nagasima
Message:

wolfsslを3.15.7にバージョンアップ

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_rx/trunk/wolfssl-3.12.2/wolfssl/internal.h

    r337 r372  
    7070    #include <wolfssl/wolfcrypt/arc4.h>
    7171#endif
     72#ifndef NO_SHA256
     73    #include <wolfssl/wolfcrypt/sha256.h>
     74#endif
     75#ifdef HAVE_OCSP
     76    #include <wolfssl/ocsp.h>
     77#endif
     78#ifdef WOLFSSL_SHA384
     79    #include <wolfssl/wolfcrypt/sha512.h>
     80#endif
     81#ifdef WOLFSSL_SHA512
     82    #include <wolfssl/wolfcrypt/sha512.h>
     83#endif
     84#ifdef HAVE_AESGCM
     85    #include <wolfssl/wolfcrypt/sha512.h>
     86#endif
     87#ifdef WOLFSSL_RIPEMD
     88    #include <wolfssl/wolfcrypt/ripemd.h>
     89#endif
     90#ifdef HAVE_IDEA
     91    #include <wolfssl/wolfcrypt/idea.h>
     92#endif
     93#ifndef NO_RSA
     94    #include <wolfssl/wolfcrypt/rsa.h>
     95#endif
    7296#ifdef HAVE_ECC
    7397    #include <wolfssl/wolfcrypt/ecc.h>
    7498#endif
     99#ifndef NO_DH
     100    #include <wolfssl/wolfcrypt/dh.h>
     101#endif
    75102#ifdef HAVE_ED25519
    76103    #include <wolfssl/wolfcrypt/ed25519.h>
     
    79106    #include <wolfssl/wolfcrypt/curve25519.h>
    80107#endif
    81 #ifndef NO_SHA256
    82     #include <wolfssl/wolfcrypt/sha256.h>
    83 #endif
    84 #ifdef HAVE_OCSP
    85     #include <wolfssl/ocsp.h>
    86 #endif
    87 #ifdef WOLFSSL_SHA512
    88     #include <wolfssl/wolfcrypt/sha512.h>
    89 #endif
    90 #ifdef HAVE_AESGCM
    91     #include <wolfssl/wolfcrypt/sha512.h>
    92 #endif
    93 #ifdef WOLFSSL_RIPEMD
    94     #include <wolfssl/wolfcrypt/ripemd.h>
    95 #endif
    96 #ifdef HAVE_IDEA
    97     #include <wolfssl/wolfcrypt/idea.h>
    98 #endif
    99 #ifndef NO_RSA
    100     #include <wolfssl/wolfcrypt/rsa.h>
    101 #endif
    102 #ifdef HAVE_ECC
    103     #include <wolfssl/wolfcrypt/ecc.h>
    104 #endif
    105 #ifndef NO_DH
    106     #include <wolfssl/wolfcrypt/dh.h>
    107 #endif
    108 
     108
     109#include <wolfssl/wolfcrypt/wc_encrypt.h>
    109110#include <wolfssl/wolfcrypt/hash.h>
    110111
     112#if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
     113    #include <wolfssl/callbacks.h>
     114#endif
    111115#ifdef WOLFSSL_CALLBACKS
    112     #include <wolfssl/callbacks.h>
    113116    #include <signal.h>
    114117#endif
     
    142145#elif defined(WOLFSSL_uTKERNEL2)
    143146        /* do nothing */
     147#elif defined(WOLFSSL_CMSIS_RTOS)
     148    #include "cmsis_os.h"
    144149#elif defined(WOLFSSL_MDK_ARM)
    145150    #if defined(WOLFSSL_MDK5)
     
    155160#elif defined(INTIME_RTOS)
    156161    #include <rt.h>
     162#elif defined(WOLFSSL_NUCLEUS_1_2)
     163    /* do nothing */
     164#elif defined(WOLFSSL_APACHE_MYNEWT)
     165    #if !defined(WOLFSSL_LWIP)
     166        void mynewt_ctx_clear(void *ctx);
     167        void* mynewt_ctx_new();
     168    #endif
    157169#else
    158170    #ifndef SINGLE_THREADED
     
    160172        #include <pthread.h>
    161173    #endif
    162     #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)
     174    #ifdef OPENSSL_EXTRA
    163175        #include <unistd.h>      /* for close of BIO */
    164176    #endif
     
    177189#ifdef WOLFSSL_ASYNC_CRYPT
    178190    #include <wolfssl/wolfcrypt/async.h>
     191#endif
     192
     193#ifdef OPENSSL_EXTRA
     194    #ifdef WOLFCRYPT_HAVE_SRP
     195        #include <wolfssl/wolfcrypt/srp.h>
     196    #endif
    179197#endif
    180198
     
    232250#ifndef WOLFSSL_MAX_STRENGTH
    233251
     252#ifdef WOLFSSL_AEAD_ONLY
     253    /* AES CBC ciphers are not allowed in AEAD only mode */
     254    #undef HAVE_AES_CBC
     255#endif
     256
     257#ifndef WOLFSSL_AEAD_ONLY
    234258    #if !defined(NO_RSA) && !defined(NO_RC4)
    235259        #if defined(WOLFSSL_STATIC_RSA)
     
    264288        #endif
    265289    #endif
     290#endif /* !WOLFSSL_AEAD_ONLY */
    266291
    267292    #if !defined(NO_RSA) && !defined(NO_AES) && !defined(NO_TLS)
    268         #if !defined(NO_SHA)
     293        #if !defined(NO_SHA) && defined(HAVE_AES_CBC)
    269294            #if defined(WOLFSSL_STATIC_RSA)
     295                #ifdef WOLFSSL_AES_128
    270296                #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA
     297                #endif
     298                #ifdef WOLFSSL_AES_256
    271299                #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA
    272300            #endif
     301            #endif
    273302            #if defined(HAVE_NTRU) && defined(WOLFSSL_STATIC_RSA)
     303                #ifdef WOLFSSL_AES_128
    274304                    #define BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA
     305                #endif
     306                #ifdef WOLFSSL_AES_256
    275307                    #define BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA
    276308            #endif
    277309        #endif
     310        #endif
    278311        #if defined(WOLFSSL_STATIC_RSA)
    279             #if !defined (NO_SHA256)
     312            #if !defined (NO_SHA256) && defined(HAVE_AES_CBC)
     313                #ifdef WOLFSSL_AES_128
    280314                #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256
     315                #endif
     316                #ifdef WOLFSSL_AES_256
    281317                #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256
    282318            #endif
     319            #endif
    283320            #if defined (HAVE_AESGCM)
     321                #ifdef WOLFSSL_AES_128
    284322                #define BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256
    285                 #if defined (WOLFSSL_SHA384)
     323                #endif
     324                #if defined (WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
    286325                    #define BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384
    287326                #endif
    288327            #endif
    289328            #if defined (HAVE_AESCCM)
     329                #ifdef WOLFSSL_AES_128
    290330                #define BUILD_TLS_RSA_WITH_AES_128_CCM_8
     331                #endif
     332                #ifdef WOLFSSL_AES_256
    291333                #define BUILD_TLS_RSA_WITH_AES_256_CCM_8
    292334            #endif
    293             #if defined(HAVE_BLAKE2)
     335            #endif
     336            #if defined(HAVE_BLAKE2) && defined(HAVE_AES_CBC)
     337                #ifdef WOLFSSL_AES_128
    294338                #define BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256
     339                #endif
     340                #ifdef WOLFSSL_AES_256
    295341                #define BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256
    296342            #endif
    297343        #endif
    298344    #endif
    299 
    300     #if defined(HAVE_CAMELLIA) && !defined(NO_TLS)
     345    #endif
     346
     347    #if defined(HAVE_CAMELLIA) && !defined(NO_TLS) && !defined(NO_CAMELLIA_CBC)
    301348        #ifndef NO_RSA
    302349          #if defined(WOLFSSL_STATIC_RSA)
     
    326373    #if !defined(NO_PSK) && !defined(NO_AES) && !defined(NO_TLS)
    327374        #if !defined(NO_SHA)
     375            #ifdef WOLFSSL_AES_128
    328376            #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA
     377            #endif
     378            #ifdef WOLFSSL_AES_256
    329379            #define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA
    330380        #endif
     381        #endif
    331382        #ifndef NO_SHA256
     383            #ifdef WOLFSSL_AES_128
     384                #ifdef HAVE_AES_CBC
    332385            #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256
     386                #endif
    333387            #ifdef HAVE_AESGCM
    334388                #define BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256
    335389            #endif
     390            #endif /* WOLFSSL_AES_128 */
    336391            #ifdef HAVE_AESCCM
     392                #ifdef WOLFSSL_AES_128
    337393                #define BUILD_TLS_PSK_WITH_AES_128_CCM_8
    338                 #define BUILD_TLS_PSK_WITH_AES_256_CCM_8
    339394                #define BUILD_TLS_PSK_WITH_AES_128_CCM
     395                #endif
     396                #ifdef WOLFSSL_AES_256
     397                    #define BUILD_TLS_PSK_WITH_AES_256_CCM_8
    340398                #define BUILD_TLS_PSK_WITH_AES_256_CCM
    341399            #endif
    342400        #endif
    343         #ifdef WOLFSSL_SHA384
     401        #endif
     402        #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
     403            #ifdef HAVE_AES_CBC
    344404            #define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA384
     405            #endif
    345406            #ifdef HAVE_AESGCM
    346407                #define BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384
     
    398459
    399460        #if !defined(NO_SHA)
     461            #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
    400462            #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
     463            #endif
     464            #if defined(WOLFSSL_AES_256) && defined(HAVE_AES_CBC)
    401465            #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
     466            #endif
    402467            #if !defined(NO_DES3)
    403468                #define BUILD_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
    404469            #endif
    405470        #endif
    406         #if !defined(NO_SHA256)
     471        #if !defined(NO_SHA256) && defined(HAVE_AES_CBC)
     472            #ifdef WOLFSSL_AES_128
    407473            #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
     474            #endif
     475            #ifdef WOLFSSL_AES_256
    408476            #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
    409477        #endif
    410478    #endif
     479    #endif
    411480
    412481    #if defined(HAVE_ANON) && !defined(NO_TLS) && !defined(NO_DH) && \
    413         !defined(NO_AES) && !defined(NO_SHA)
     482        !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
     483        #ifdef HAVE_AES_CBC
    414484        #define BUILD_TLS_DH_anon_WITH_AES_128_CBC_SHA
     485    #endif
     486
     487        #if defined(WOLFSSL_SHA384) && defined(HAVE_AESGCM)
     488            #define BUILD_TLS_DH_anon_WITH_AES_256_GCM_SHA384
     489        #endif
    415490    #endif
    416491
    417492    #if !defined(NO_DH) && !defined(NO_PSK) && !defined(NO_TLS)
    418493        #ifndef NO_SHA256
    419             #ifndef NO_AES
     494            #if !defined(NO_AES) && defined(WOLFSSL_AES_128) && \
     495                                                           defined(HAVE_AES_CBC)
    420496                #define BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
    421497            #endif
     
    425501        #endif
    426502        #ifdef WOLFSSL_SHA384
    427             #ifndef NO_AES
     503            #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && \
     504                                                           defined(HAVE_AES_CBC)
    428505                #define BUILD_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
    429506            #endif
     
    434511    #endif
    435512
    436     #if defined(HAVE_ECC) && !defined(NO_TLS)
     513    #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519)) && !defined(NO_TLS)
    437514        #if !defined(NO_AES)
    438             #if !defined(NO_SHA)
     515            #if !defined(NO_SHA) && defined(HAVE_AES_CBC)
    439516                #if !defined(NO_RSA)
     517                    #ifdef WOLFSSL_AES_128
    440518                    #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
     519                    #endif
     520                    #ifdef WOLFSSL_AES_256
    441521                    #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
    442                     #if defined(WOLFSSL_STATIC_DH)
     522                    #endif
     523                    #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
     524                        #ifdef WOLFSSL_AES_128
    443525                        #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
     526                        #endif
     527                        #ifdef WOLFSSL_AES_256
    444528                        #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
    445529                    #endif
    446530                #endif
    447 
     531                #endif
     532
     533                #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     534                                                          defined(HAVE_ED25519))
     535                    #ifdef WOLFSSL_AES_128
    448536                #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
     537                    #endif
     538                    #ifdef WOLFSSL_AES_256
    449539                #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
    450 
    451                 #if defined(WOLFSSL_STATIC_DH)
     540                    #endif
     541                #endif
     542
     543                #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
     544                    #ifdef WOLFSSL_AES_128
    452545                    #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
     546                    #endif
     547                    #ifdef WOLFSSL_AES_256
    453548                    #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
    454549                #endif
     550                #endif
    455551            #endif /* NO_SHA */
    456             #ifndef NO_SHA256
     552            #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
     553                                                           defined(HAVE_AES_CBC)
    457554                #if !defined(NO_RSA)
    458555                    #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
    459                     #if defined(WOLFSSL_STATIC_DH)
     556                    #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
    460557                        #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
    461558                    #endif
    462559                #endif
     560                #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     561                                                          defined(HAVE_ED25519))
    463562                #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
    464                 #if defined(WOLFSSL_STATIC_DH)
     563                #endif
     564                #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
    465565                    #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
    466566                #endif
    467567            #endif
    468568
    469             #ifdef WOLFSSL_SHA384
     569            #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
     570                                                           defined(HAVE_AES_CBC)
    470571                #if !defined(NO_RSA)
    471572                    #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
    472                     #if defined(WOLFSSL_STATIC_DH)
     573                    #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
    473574                        #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
    474575                    #endif
    475576                #endif
     577                #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     578                                                          defined(HAVE_ED25519))
    476579                #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
    477                 #if defined(WOLFSSL_STATIC_DH)
     580                #endif
     581                #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
    478582                    #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
    479583                #endif
     
    482586            #if defined (HAVE_AESGCM)
    483587                #if !defined(NO_RSA)
    484                     #if defined(WOLFSSL_STATIC_DH)
     588                    #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
     589                        #ifdef WOLFSSL_AES_128
    485590                        #define BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
    486591                    #endif
     592                    #endif
    487593                    #if defined(WOLFSSL_SHA384)
    488                         #if defined(WOLFSSL_STATIC_DH)
     594                        #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
     595                            #ifdef WOLFSSL_AES_256
    489596                            #define BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
    490597                        #endif
    491598                    #endif
    492599                #endif
    493 
    494                 #if defined(WOLFSSL_STATIC_DH)
     600                #endif
     601
     602                #if defined(WOLFSSL_STATIC_DH) && defined(WOLFSSL_AES_128) && \
     603                                                               defined(HAVE_ECC)
    495604                    #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
    496605                #endif
    497606
    498607                #if defined(WOLFSSL_SHA384)
    499                     #if defined(WOLFSSL_STATIC_DH)
     608                    #if defined(WOLFSSL_STATIC_DH) && \
     609                                   defined(WOLFSSL_AES_256) && defined(HAVE_ECC)
    500610                        #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
    501611                    #endif
     
    507617                #if !defined(NO_RSA)
    508618                    #define BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA
    509                     #if defined(WOLFSSL_STATIC_DH)
     619                    #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
    510620                        #define BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA
    511621                    #endif
    512622                #endif
    513623
     624                #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     625                                                          defined(HAVE_ED25519))
    514626                #define BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
    515                 #if defined(WOLFSSL_STATIC_DH)
     627                #endif
     628                #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
    516629                    #define BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
    517630                #endif
     
    522635                #if !defined(NO_RSA)
    523636                    #define BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
    524                     #if defined(WOLFSSL_STATIC_DH)
     637                    #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
    525638                        #define BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
    526639                    #endif
    527640                #endif
    528641
     642                #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     643                                                          defined(HAVE_ED25519))
    529644                #define BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
    530                 #if defined(WOLFSSL_STATIC_DH)
     645                #endif
     646                #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
    531647                    #define BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
    532648                #endif
     
    535651        #if defined(HAVE_NULL_CIPHER)
    536652            #if !defined(NO_SHA)
     653                #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     654                                                          defined(HAVE_ED25519))
    537655                #define BUILD_TLS_ECDHE_ECDSA_WITH_NULL_SHA
     656            #endif
    538657            #endif
    539658            #if !defined(NO_PSK) && !defined(NO_SHA256)
     
    541660            #endif
    542661        #endif
    543         #if !defined(NO_PSK) && !defined(NO_SHA256) && !defined(NO_AES)
     662        #if !defined(NO_PSK) && !defined(NO_SHA256) && !defined(NO_AES) && \
     663            defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
    544664            #define BUILD_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
    545665        #endif
     
    547667    #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
    548668        #if !defined(NO_OLD_POLY1305)
    549         #ifdef HAVE_ECC
     669        #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     670                                                          defined(HAVE_ED25519))
    550671            #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256
    551             #ifndef NO_RSA
    552                 #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256
    553             #endif
     672            #endif
     673        #if !defined(NO_RSA) && defined(HAVE_ECC)
     674            #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256
    554675        #endif
    555676        #if !defined(NO_DH) && !defined(NO_RSA)
     
    559680        #if !defined(NO_PSK)
    560681            #define BUILD_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256
    561             #ifdef HAVE_ECC
     682            #if defined(HAVE_ECC) || defined(HAVE_ED25519)
    562683                #define BUILD_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256
    563684            #endif
     
    573694    !defined(NO_RSA) && defined(HAVE_AESGCM)
    574695
    575     #ifndef NO_SHA256
     696    #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
    576697        #define BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
    577698    #endif
    578699
    579     #ifdef WOLFSSL_SHA384
     700    #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
    580701        #define BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
    581702    #endif
     
    584705#if !defined(NO_DH) && !defined(NO_PSK) && !defined(NO_TLS)
    585706    #ifndef NO_SHA256
    586         #ifdef HAVE_AESGCM
     707        #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
    587708            #define BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
    588709        #endif
    589710        #ifdef HAVE_AESCCM
     711            #ifdef WOLFSSL_AES_128
    590712            #define BUILD_TLS_DHE_PSK_WITH_AES_128_CCM
     713            #endif
     714            #ifdef WOLFSSL_AES_256
    591715            #define BUILD_TLS_DHE_PSK_WITH_AES_256_CCM
    592716        #endif
    593717    #endif
    594     #if defined(WOLFSSL_SHA384) && defined(HAVE_AESGCM)
     718    #endif
     719    #if defined(WOLFSSL_SHA384) && defined(HAVE_AESGCM) && \
     720        defined(WOLFSSL_AES_256)
    595721        #define BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
    596722    #endif
    597723#endif
    598724
    599 #if defined(HAVE_ECC) && !defined(NO_TLS) && !defined(NO_AES)
     725#if (defined(HAVE_ECC) || defined(HAVE_CURVE25519)) && !defined(NO_TLS) && \
     726                                                                !defined(NO_AES)
    600727    #ifdef HAVE_AESGCM
    601         #ifndef NO_SHA256
     728        #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
     729            #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     730                                                          defined(HAVE_ED25519))
    602731            #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
     732            #endif
    603733            #ifndef NO_RSA
    604734                #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
    605735            #endif
    606736        #endif
    607         #ifdef WOLFSSL_SHA384
     737        #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
     738            #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     739                                                          defined(HAVE_ED25519))
    608740            #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
     741            #endif
    609742            #ifndef NO_RSA
    610743                #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
     
    613746    #endif
    614747    #if defined(HAVE_AESCCM) && !defined(NO_SHA256)
     748        #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     749                                                          defined(HAVE_ED25519))
     750            #ifdef WOLFSSL_AES_128
    615751        #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM
    616752        #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
     753            #endif
     754            #ifdef WOLFSSL_AES_256
    617755        #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8
    618756    #endif
    619757#endif
     758    #endif
     759#endif
    620760
    621761#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
    622     #ifdef HAVE_ECC
     762    #if defined(HAVE_ECC) || defined(HAVE_CURVE25519)
     763        #if defined(HAVE_ECC) || (defined(HAVE_CURVE25519) && \
     764                                                          defined(HAVE_ED25519))
    623765        #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
     766        #endif
    624767        #ifndef NO_RSA
    625768            #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
     
    633776#if defined(WOLFSSL_TLS13)
    634777    #ifdef HAVE_AESGCM
    635         #ifndef NO_SHA256
     778        #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
    636779            #define BUILD_TLS_AES_128_GCM_SHA256
    637780        #endif
    638         #ifdef WOLFSSL_SHA384
     781        #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
    639782            #define BUILD_TLS_AES_256_GCM_SHA384
    640783        #endif
    641784    #endif
    642785
    643     #ifdef HAVE_CHACHA
     786    #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
    644787        #ifndef NO_SHA256
    645788            #define BUILD_TLS_CHACHA20_POLY1305_SHA256
     
    648791
    649792    #ifdef HAVE_AESCCM
    650         #ifndef NO_SHA256
     793        #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
    651794            #define BUILD_TLS_AES_128_CCM_SHA256
    652795            #define BUILD_TLS_AES_128_CCM_8_SHA256
     
    689832    defined(BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384)
    690833    #define BUILD_AESGCM
     834#else
     835    /* No AES-GCM cipher suites available with build */
     836    #define NO_AESGCM_AEAD
     837#endif
     838
     839#if defined(BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256) || \
     840    defined(BUILD_TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256) || \
     841    defined(BUILD_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256) || \
     842    defined(BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256) || \
     843    defined(BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256) || \
     844    defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) || \
     845    defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256) || \
     846    defined(BUILD_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256) || \
     847    defined(BUILD_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256) || \
     848    defined(BUILD_TLS_CHACHA20_POLY1305_SHA256)
     849    /* Have an available ChaCha Poly cipher suite */
     850#else
     851    /* No ChaCha Poly cipher suites available with build */
     852    #define NO_CHAPOL_AEAD
    691853#endif
    692854
     
    726888
    727889#if defined(WOLFSSL_MAX_STRENGTH) || \
    728     defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || \
    729     (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
     890    (defined(HAVE_AESGCM) && !defined(NO_AESGCM_AEAD)) || \
     891     defined(HAVE_AESCCM) || \
     892    (defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_CHAPOL_AEAD))
    730893
    731894    #define HAVE_AEAD
     
    833996    TLS_DHE_RSA_WITH_AES_128_GCM_SHA256      = 0x9e,
    834997    TLS_DHE_RSA_WITH_AES_256_GCM_SHA384      = 0x9f,
     998    TLS_DH_anon_WITH_AES_256_GCM_SHA384      = 0xa7,
    835999    TLS_PSK_WITH_AES_128_GCM_SHA256          = 0xa8,
    8361000    TLS_PSK_WITH_AES_256_GCM_SHA384          = 0xa9,
     
    9271091
    9281092
     1093/* set minimum DH key size allowed */
     1094#ifndef WOLFSSL_MIN_DHKEY_BITS
     1095    #ifdef WOLFSSL_MAX_STRENGTH
     1096        #define WOLFSSL_MIN_DHKEY_BITS 2048
     1097    #else
     1098        #define WOLFSSL_MIN_DHKEY_BITS 1024
     1099    #endif
     1100#endif
     1101#if (WOLFSSL_MIN_DHKEY_BITS % 8)
     1102    #error DH minimum bit size must be multiple of 8
     1103#endif
     1104#if (WOLFSSL_MIN_DHKEY_BITS > 16000)
     1105    #error DH minimum bit size must not be greater than 16000
     1106#endif
     1107#define MIN_DHKEY_SZ (WOLFSSL_MIN_DHKEY_BITS / 8)
     1108/* set maximum DH key size allowed */
     1109#ifndef WOLFSSL_MAX_DHKEY_BITS
     1110    #define WOLFSSL_MAX_DHKEY_BITS 4096
     1111#endif
     1112#if (WOLFSSL_MAX_DHKEY_BITS % 8)
     1113    #error DH maximum bit size must be multiple of 8
     1114#endif
     1115#if (WOLFSSL_MAX_DHKEY_BITS > 16000)
     1116    #error DH maximum bit size must not be greater than 16000
     1117#endif
     1118#define MAX_DHKEY_SZ (WOLFSSL_MAX_DHKEY_BITS / 8)
     1119
     1120
    9291121
    9301122enum Misc {
     1123    CIPHER_BYTE = 0x00,            /* Default ciphers */
    9311124    ECC_BYTE    = 0xC0,            /* ECC first cipher suite byte */
    9321125    QSH_BYTE    = 0xD0,            /* Quantum-safe Handshake cipher suite */
     
    9461139    TLSv1_2_MINOR   = 3,        /* TLSv1_2 minor version number */
    9471140    TLSv1_3_MINOR   = 4,        /* TLSv1_3 minor version number */
     1141#ifdef WOLFSSL_TLS13_DRAFT
    9481142    TLS_DRAFT_MAJOR = 0x7f,     /* Draft TLS major version number */
    9491143#ifdef WOLFSSL_TLS13_DRAFT_18
    9501144    TLS_DRAFT_MINOR = 0x12,     /* Minor version number of TLS draft */
     1145#elif defined(WOLFSSL_TLS13_DRAFT_22)
     1146    TLS_DRAFT_MINOR = 0x16,     /* Minor version number of TLS draft */
     1147#elif defined(WOLFSSL_TLS13_DRAFT_23)
     1148    TLS_DRAFT_MINOR = 0x17,     /* Minor version number of TLS draft */
     1149#elif defined(WOLFSSL_TLS13_DRAFT_26)
     1150    TLS_DRAFT_MINOR = 0x1a,     /* Minor version number of TLS draft */
    9511151#else
    952     TLS_DRAFT_MINOR = 0x14,     /* Minor version number of TLS draft */
     1152    TLS_DRAFT_MINOR = 0x1c,     /* Minor version number of TLS draft */
     1153#endif
    9531154#endif
    9541155    OLD_HELLO_ID    = 0x01,     /* SSLv2 Client Hello Indicator */
     
    9681169    FINISHED_SZ     = 36,       /* WC_MD5_DIGEST_SIZE + WC_SHA_DIGEST_SIZE */
    9691170    MAX_RECORD_SIZE = 16384,    /* 2^14, max size by standard */
    970     MAX_MSG_EXTRA   = 38 + MAX_DIGEST_SIZE,
     1171    MAX_MSG_EXTRA   = 38 + WC_MAX_DIGEST_SIZE,
    9711172                                /* max added to msg, mac + pad  from */
    9721173                                /* RECORD_HEADER_SZ + BLOCK_SZ (pad) + Max
     
    9751176    MAX_MTU         = WOLFSSL_MAX_MTU,     /* max expected MTU */
    9761177    MAX_UDP_SIZE    = 8192 - 100, /* was MAX_MTU - 100 */
    977     MAX_DH_SZ       = 1036,     /* 4096 p, pub, g + 2 byte size for each */
     1178    MAX_DH_SZ       = (MAX_DHKEY_SZ * 3) + 12, /* DH_P, DH_G and DH_Pub */
     1179                                /* 4096 p, pub, g + 2 byte size for each */
    9781180    MAX_STR_VERSION = 8,        /* string rep of protocol version */
    9791181
     
    9811183    PAD_SHA        = 40,       /* pad length for finished */
    9821184    MAX_PAD_SIZE   = 256,      /* maximum length of padding */
    983     COMPRESS_DUMMY_SIZE = 64,  /* compression dummy round size */
    984     COMPRESS_CONSTANT   = 13,  /* compression calc constant */
    985     COMPRESS_UPPER      = 55,  /* compression calc numerator */
    986     COMPRESS_LOWER      = 64,  /* compression calc denominator */
    987 
    988     PEM_LINE_LEN   = 80,       /* PEM line max + fudge */
     1185
    9891186    LENGTH_SZ      =  2,       /* length field for HMAC, data only */
    9901187    VERSION_SZ     =  2,       /* length of proctocol version */
     
    9941191    EXTS_SZ        =  2,       /* always use 2 bytes      */
    9951192    EXT_ID_SZ      =  2,       /* always use 2 bytes      */
    996     MAX_DH_SIZE    = 513,      /* 4096 bit plus possible leading 0 */
     1193    MAX_DH_SIZE    = MAX_DHKEY_SZ+1,
     1194                               /* Max size plus possible leading 0 */
    9971195    NAMED_DH_MASK  = 0x100,    /* Named group mask for DH parameters  */
    9981196    SESSION_HINT_SZ = 4,       /* session timeout hint */
    9991197    SESSION_ADD_SZ = 4,        /* session age add */
     1198    TICKET_NONCE_LEN_SZ = 1,   /* Ticket nonce length size */
     1199    DEF_TICKET_NONCE_SZ = 1,   /* Default ticket nonce size */
     1200    MAX_TICKET_NONCE_SZ = 8,   /* maximum ticket nonce size */
    10001201    MAX_LIFETIME   = 604800,   /* maximum ticket lifetime */
    10011202    MAX_EARLY_DATA_SZ = 4096,  /* maximum early data size */
     
    10291230    HELLO_EXT_SZ_SZ       = 2,  /* length of a hello extension size */
    10301231    HELLO_EXT_SIGALGO_SZ  = 2,  /* length of number of items in sigalgo list */
    1031     HELLO_EXT_SIGALGO_MAX = 32, /* number of items in the signature algo list */
    10321232
    10331233    DTLS_HANDSHAKE_HEADER_SZ = 12, /* normal + seq(2) + offset(3) + length(3) */
     
    10401240    DTLS_EXPORT_PRO          = 165,/* wolfSSL protocol for serialized session */
    10411241    DTLS_EXPORT_VERSION      = 4,  /* wolfSSL version for serialized session */
    1042     DTLS_EXPORT_OPT_SZ       = 58, /* amount of bytes used from Options */
     1242    DTLS_EXPORT_OPT_SZ       = 60, /* amount of bytes used from Options */
    10431243    DTLS_EXPORT_VERSION_3    = 3,  /* wolfSSL version before TLS 1.3 addition */
    1044     DTLS_EXPORT_OPT_SZ_3     = 57, /* amount of bytes used from Options */
     1244    DTLS_EXPORT_OPT_SZ_3     = 59, /* amount of bytes used from Options */
    10451245    DTLS_EXPORT_KEY_SZ       = 325 + (DTLS_SEQ_SZ * 2),
    10461246                                   /* max amount of bytes used from Keys */
     
    10631263    MAX_HKDF_LABEL_SZ   = OPAQUE16_LEN +
    10641264                          OPAQUE8_LEN + PROTOCOL_LABEL_SZ + MAX_LABEL_SZ +
    1065                           OPAQUE8_LEN + MAX_DIGEST_SIZE,
     1265                          OPAQUE8_LEN + WC_MAX_DIGEST_SIZE,
    10661266    MAX_REQUEST_SZ      = 256, /* Maximum cert req len (no auth yet */
    10671267    SESSION_FLUSH_COUNT = 256, /* Flush session cache unless user turns off */
    1068 
    1069     RC4_KEY_SIZE        = 16,  /* always 128bit           */
    1070     DES_KEY_SIZE        =  8,  /* des                     */
    1071     DES3_KEY_SIZE       = 24,  /* 3 des ede               */
    1072     DES_IV_SIZE         = DES_BLOCK_SIZE,
    1073     AES_256_KEY_SIZE    = 32,  /* for 256 bit             */
    1074     AES_192_KEY_SIZE    = 24,  /* for 192 bit             */
    1075     AES_IV_SIZE         = 16,  /* always block size       */
    1076     AES_128_KEY_SIZE    = 16,  /* for 128 bit             */
     1268    TLS_MAX_PAD_SZ      = 255, /* Max padding in TLS */
     1269
     1270#if defined(HAVE_FIPS) && \
     1271    (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
     1272    MAX_SYM_KEY_SIZE    = AES_256_KEY_SIZE,
     1273#else
     1274    MAX_SYM_KEY_SIZE    = WC_MAX_SYM_KEY_SIZE,
     1275#endif
     1276
     1277#ifdef HAVE_SELFTEST
     1278    #define WOLFSSL_AES_KEY_SIZE_ENUM
     1279    AES_IV_SIZE         = 16,
     1280    AES_128_KEY_SIZE    = 16,
     1281    AES_192_KEY_SIZE    = 24,
     1282    AES_256_KEY_SIZE    = 32,
     1283#endif
     1284
     1285    MAX_IV_SZ           = AES_BLOCK_SIZE,
    10771286
    10781287    AEAD_SEQ_OFFSET     = 4,   /* Auth Data: Sequence number */
     
    11171326    EVP_SALT_SIZE       =  8,  /* evp salt size 64 bits   */
    11181327
     1328#ifndef ECDHE_SIZE /* allow this to be overriden at compile-time */
    11191329    ECDHE_SIZE          = 32,  /* ECHDE server size defaults to 256 bit */
     1330#endif
    11201331    MAX_EXPORT_ECC_SZ   = 256, /* Export ANS X9.62 max future size */
    11211332    MAX_CURVE_NAME_SZ   = 16,  /* Maximum size of curve name string */
     
    11301341    MIN_RSA_SHA384_PSS_BITS = 384 * 2 + 8 * 8, /* Min key size */
    11311342
    1132 #ifdef HAVE_QSH
    1133     /* qsh handshake sends 600+ size keys over hello extensions */
    1134     MAX_HELLO_SZ       = 2048,  /* max client or server hello */
     1343#ifndef NO_RSA
     1344    MAX_CERT_VERIFY_SZ = 4096 / 8, /* max RSA - default 4096-bits */
     1345#elif defined(HAVE_ECC)
     1346    MAX_CERT_VERIFY_SZ = ECC_MAX_SIG_SIZE, /* max ECC  */
     1347#elif defined(HAVE_ED25519)
     1348    MAX_CERT_VERIFY_SZ = ED25519_SIG_SIZE, /* max Ed25519  */
    11351349#else
    1136     MAX_HELLO_SZ       = 128,  /* max client or server hello */
    1137 #endif
    1138     MAX_CERT_VERIFY_SZ = 1024, /* max   */
     1350    MAX_CERT_VERIFY_SZ = 1024, /* max default  */
     1351#endif
    11391352    CLIENT_HELLO_FIRST =  35,  /* Protocol + RAN_LEN + sizeof(id_len) */
    11401353    MAX_SUITE_NAME     =  48,  /* maximum length of cipher suite string */
     
    11591372    MAX_X509_SIZE      = 2048, /* max static x509 buffer size */
    11601373    CERT_MIN_SIZE      =  256, /* min PEM cert size with header/footer */
    1161     FILE_BUFFER_SIZE   = 1024, /* default static file buffer size for input,
    1162                                   will use dynamic buffer if not big enough */
    11631374
    11641375    MAX_NTRU_PUB_KEY_SZ = 1027, /* NTRU max for now */
     
    11771388    PREV_ORDER         = -1,   /* Sequence number is in previous epoch. */
    11781389    PEER_ORDER         = 1,    /* Peer sequence number for verify. */
    1179     CUR_ORDER          = 0     /* Current sequence number. */
    1180 };
    1181 
     1390    CUR_ORDER          = 0,    /* Current sequence number. */
     1391    WRITE_PROTO        = 1,    /* writing a protocol message */
     1392    READ_PROTO         = 0     /* reading a protocol message */
     1393};
     1394
     1395/* minimum Downgrade Minor version */
     1396#ifndef WOLFSSL_MIN_DOWNGRADE
     1397    #ifndef NO_OLD_TLS
     1398        #define WOLFSSL_MIN_DOWNGRADE TLSv1_MINOR
     1399    #else
     1400        #define WOLFSSL_MIN_DOWNGRADE TLSv1_2_MINOR
     1401    #endif
     1402#endif
    11821403
    11831404/* Set max implicit IV size for AEAD cipher suites */
     
    11921413    /* 150 suites for now! */
    11931414#endif
     1415
     1416/* number of items in the signature algo list */
     1417#ifndef WOLFSSL_MAX_SIGALGO
     1418    #define WOLFSSL_MAX_SIGALGO 32
     1419#endif
     1420
    11941421
    11951422/* set minimum ECC key size allowed */
     
    12261453#define MIN_RSAKEY_SZ (WOLFSSL_MIN_RSA_BITS / 8)
    12271454
    1228 /* set minimum DH key size allowed */
    1229 #ifndef WOLFSSL_MIN_DHKEY_BITS
    1230     #ifdef WOLFSSL_MAX_STRENGTH
    1231         #define WOLFSSL_MIN_DHKEY_BITS 2048
    1232     #else
    1233         #define WOLFSSL_MIN_DHKEY_BITS 1024
    1234     #endif
    1235 #endif
    1236 #if (WOLFSSL_MIN_DHKEY_BITS % 8)
    1237     #error DH minimum bit size must be multiple of 8
    1238 #endif
    1239 #if (WOLFSSL_MIN_DHKEY_BITS > 16000)
    1240     #error DH minimum bit size must not be greater than 16000
    1241 #endif
    1242 #define MIN_DHKEY_SZ (WOLFSSL_MIN_DHKEY_BITS / 8)
    1243 
    1244 
    12451455#ifdef SESSION_INDEX
    12461456/* Shift values for making a session index */
     
    12901500
    12911501    SERVER_HELLOVERIFYREQUEST_COMPLETE,
     1502    SERVER_HELLO_RETRY_REQUEST_COMPLETE,
    12921503    SERVER_HELLO_COMPLETE,
    12931504    SERVER_ENCRYPTED_EXTENSIONS_COMPLETE,
     
    12951506    SERVER_KEYEXCHANGE_COMPLETE,
    12961507    SERVER_HELLODONE_COMPLETE,
     1508        SERVER_CHANGECIPHERSPEC_COMPLETE,
    12971509    SERVER_FINISHED_COMPLETE,
    1298     SERVER_HELLO_RETRY_REQUEST,
    1299 
     1510
     1511    CLIENT_HELLO_RETRY,
    13001512    CLIENT_HELLO_COMPLETE,
    13011513    CLIENT_KEYEXCHANGE_COMPLETE,
     1514        CLIENT_CHANGECIPHERSPEC_COMPLETE,
    13021515    CLIENT_FINISHED_COMPLETE,
    13031516
    13041517    HANDSHAKE_DONE
    13051518};
    1306 
    1307 
    1308 #if defined(__GNUC__)
    1309     #define WOLFSSL_PACK __attribute__ ((packed))
    1310 #else
    1311     #define WOLFSSL_PACK
    1312 #endif
    13131519
    13141520/* SSL Version */
     
    13391545
    13401546
    1341 enum BIO_TYPE {
    1342     BIO_BUFFER = 1,
    1343     BIO_SOCKET = 2,
    1344     BIO_SSL    = 3,
    1345     BIO_MEMORY = 4,
    1346     BIO_BIO    = 5,
    1347     BIO_FILE   = 6
    1348 };
    1349 
    1350 
    13511547/* wolfSSL BIO_METHOD type */
    13521548struct WOLFSSL_BIO_METHOD {
     
    13571553/* wolfSSL BIO type */
    13581554struct WOLFSSL_BIO {
     1555    WOLFSSL_BUF_MEM* mem_buf;
    13591556    WOLFSSL*     ssl;           /* possible associated ssl */
    13601557#ifndef NO_FILESYSTEM
     
    13731570    int         fd;            /* possible file descriptor */
    13741571    int         eof;           /* eof flag */
     1572    int         flags;
    13751573    byte        type;          /* method type */
    13761574    byte        close;         /* close flag */
     
    13881586typedef WOLFSSL_BUFFER_INFO buffer;
    13891587
     1588typedef struct Suites Suites;
     1589
    13901590
    13911591/* defaults to client */
    13921592WOLFSSL_LOCAL void InitSSL_Method(WOLFSSL_METHOD*, ProtocolVersion);
     1593
     1594WOLFSSL_LOCAL int InitSSL_Suites(WOLFSSL* ssl);
     1595WOLFSSL_LOCAL int InitSSL_Side(WOLFSSL* ssl, word16 side);
    13931596
    13941597/* for sniffer */
     
    13971600WOLFSSL_LOCAL int DoApplicationData(WOLFSSL* ssl, byte* input, word32* inOutIdx);
    13981601/* TLS v1.3 needs these */
     1602WOLFSSL_LOCAL int  HandleTlsResumption(WOLFSSL* ssl, int bogusID,
     1603                                       Suites* clSuites);
    13991604WOLFSSL_LOCAL int  DoClientHello(WOLFSSL* ssl, const byte* input, word32*,
    14001605                                 word32);
     
    14051610WOLFSSL_LOCAL int  DoServerHello(WOLFSSL* ssl, const byte* input, word32*,
    14061611                                 word32);
     1612WOLFSSL_LOCAL int  CompleteServerHello(WOLFSSL *ssl);
    14071613WOLFSSL_LOCAL int  CheckVersion(WOLFSSL *ssl, ProtocolVersion pv);
    14081614WOLFSSL_LOCAL void PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo,
    14091615                                   word32 hashSigAlgoSz);
    14101616WOLFSSL_LOCAL int  DecodePrivateKey(WOLFSSL *ssl, word16* length);
     1617#ifdef HAVE_PK_CALLBACKS
     1618WOLFSSL_LOCAL int GetPrivateKeySigSize(WOLFSSL* ssl);
     1619#ifndef NO_ASN
     1620    WOLFSSL_LOCAL int  InitSigPkCb(WOLFSSL* ssl, SignatureCtx* sigCtx);
     1621#endif
     1622#endif
    14111623WOLFSSL_LOCAL void FreeKeyExchange(WOLFSSL* ssl);
    14121624WOLFSSL_LOCAL int  ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 size);
     
    14201632                              int ivSz);
    14211633WOLFSSL_LOCAL int  HashInput(WOLFSSL* ssl, const byte* input, int sz);
    1422 #if defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || defined (WOLFSSL_HAPROXY)
     1634#if defined(OPENSSL_ALL) || defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
    14231635WOLFSSL_LOCAL int SNI_Callback(WOLFSSL* ssl);
    14241636#endif
    14251637#ifdef WOLFSSL_TLS13
    14261638WOLFSSL_LOCAL int  DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input,
    1427                                 word16 sz);
     1639                                word16 sz, const byte* aad, word16 aadSz);
    14281640WOLFSSL_LOCAL int  DoTls13HandShakeMsgType(WOLFSSL* ssl, byte* input,
    14291641                                           word32* inOutIdx, byte type,
     
    14321644                                       word32* inOutIdx, word32 totalSz);
    14331645WOLFSSL_LOCAL int DoTls13ServerHello(WOLFSSL* ssl, const byte* input,
    1434                                      word32* inOutIdx, word32 helloSz);
    1435 #endif
    1436 
    1437 #ifndef NO_CERTS
    1438     /* wolfSSL DER buffer */
    1439     typedef struct DerBuffer {
    1440         byte*  buffer;
    1441         void* heap;
    1442         word32 length;
    1443         int type; /* enum CertType */
    1444         int dynType; /* DYNAMIC_TYPE_* */
    1445     } DerBuffer;
    1446 #endif /* !NO_CERTS */
     1646                                     word32* inOutIdx, word32 helloSz,
     1647                                     byte* extMsgType);
     1648#endif
     1649int TimingPadVerify(WOLFSSL* ssl, const byte* input, int padLen, int t,
     1650                    int pLen, int content);
    14471651
    14481652
     
    15241728
    15251729/* Cipher Suites holder */
    1526 typedef struct Suites {
     1730struct Suites {
    15271731    word16 suiteSz;                 /* suite length in bytes        */
    15281732    word16 hashSigAlgoSz;           /* SigAlgo extension length in bytes */
    15291733    byte   suites[WOLFSSL_MAX_SUITE_SZ];
    1530     byte   hashSigAlgo[HELLO_EXT_SIGALGO_MAX]; /* sig/algo to offer */
     1734    byte   hashSigAlgo[WOLFSSL_MAX_SIGALGO]; /* sig/algo to offer */
    15311735    byte   setSuites;               /* user set suites from default */
    15321736    byte   hashAlgo;                /* selected hash algorithm */
    15331737    byte   sigAlgo;                 /* selected sig algorithm */
    1534 } Suites;
     1738};
    15351739
    15361740
     
    15481752    typedef unsigned int (*wc_psk_server_callback)(WOLFSSL*, const char*,
    15491753                          unsigned char*, unsigned int);
     1754#ifdef WOLFSSL_TLS13
     1755    typedef unsigned int (*wc_psk_client_tls13_callback)(WOLFSSL*, const char*,
     1756                          char*, unsigned int, unsigned char*, unsigned int,
     1757                          const char**);
     1758    typedef unsigned int (*wc_psk_server_tls13_callback)(WOLFSSL*, const char*,
     1759                          unsigned char*, unsigned int, const char**);
     1760#endif
    15501761#endif /* PSK_TYPES_DEFINED */
    1551 #ifdef WOLFSSL_DTLS
     1762#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
     1763   !defined(WOLFSSL_DTLS_EXPORT_TYPES)
    15521764    typedef int (*wc_dtls_export)(WOLFSSL* ssl,
    15531765                   unsigned char* exportBuffer, unsigned int sz, void* userCtx);
    1554 #endif
     1766#define WOLFSSL_DTLS_EXPORT_TYPES
     1767#endif /* WOLFSSL_DTLS_EXPORT_TYPES */
    15551768
    15561769
     
    15921805    OcspEntry*            ocspList;      /* OCSP response list */
    15931806    wolfSSL_Mutex         ocspLock;      /* OCSP list lock */
    1594 #if defined(WOLFSSL_NGINX) || defined (WOLFSSL_HAPROXY)
     1807#if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
     1808    defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
    15951809    int(*statusCb)(WOLFSSL*, void*);
    15961810#endif
     
    17651979 * keep as a constant size (no additional ifdefs) for session export */
    17661980typedef struct Keys {
    1767     byte client_write_MAC_secret[MAX_DIGEST_SIZE];   /* max sizes */
    1768     byte server_write_MAC_secret[MAX_DIGEST_SIZE];
    1769     byte client_write_key[AES_256_KEY_SIZE];         /* max sizes */
    1770     byte server_write_key[AES_256_KEY_SIZE];
     1981#if !defined(WOLFSSL_AEAD_ONLY) || defined(WOLFSSL_TLS13)
     1982    byte client_write_MAC_secret[WC_MAX_DIGEST_SIZE];   /* max sizes */
     1983    byte server_write_MAC_secret[WC_MAX_DIGEST_SIZE];
     1984#endif
     1985    byte client_write_key[MAX_SYM_KEY_SIZE];         /* max sizes */
     1986    byte server_write_key[MAX_SYM_KEY_SIZE];
    17711987    byte client_write_IV[MAX_WRITE_IV_SZ];               /* max sizes */
    17721988    byte server_write_IV[MAX_WRITE_IV_SZ];
     
    18302046    TLSX_SESSION_TICKET             = 0x0023,
    18312047#ifdef WOLFSSL_TLS13
    1832     TLSX_KEY_SHARE                  = 0x0028,
    18332048    #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
    18342049    TLSX_PRE_SHARED_KEY             = 0x0029,
     
    18442059    #ifdef WOLFSSL_POST_HANDSHAKE_AUTH
    18452060    TLSX_POST_HANDSHAKE_AUTH        = 0x0031,
     2061    #endif
     2062    #if defined(WOLFSSL_TLS13_DRAFT_18) || defined(WOLFSSL_TLS13_DRAFT_22)
     2063    TLSX_KEY_SHARE                  = 0x0028,
     2064    #else
     2065    TLSX_SIGNATURE_ALGORITHMS_CERT  = 0x0032,
     2066    TLSX_KEY_SHARE                  = 0x0033,
    18462067    #endif
    18472068#endif
     
    18582079
    18592080WOLFSSL_LOCAL TLSX*  TLSX_Find(TLSX* list, TLSX_Type type);
     2081WOLFSSL_LOCAL void  TLSX_Remove(TLSX** list, TLSX_Type type, void* heap);
    18602082WOLFSSL_LOCAL void   TLSX_FreeAll(TLSX* list, void* heap);
    18612083WOLFSSL_LOCAL int    TLSX_SupportExtensions(WOLFSSL* ssl);
    18622084WOLFSSL_LOCAL int    TLSX_PopulateExtensions(WOLFSSL* ssl, byte isRequest);
    18632085
    1864 #ifndef NO_WOLFSSL_CLIENT
    1865 WOLFSSL_LOCAL word16 TLSX_GetRequestSize(WOLFSSL* ssl, byte msgType);
    1866 WOLFSSL_LOCAL word16 TLSX_WriteRequest(WOLFSSL* ssl, byte* output,
    1867                                        byte msgType);
    1868 #endif
    1869 
    1870 #ifndef NO_WOLFSSL_SERVER
    1871 WOLFSSL_LOCAL word16 TLSX_GetResponseSize(WOLFSSL* ssl, byte msgType);
    1872 WOLFSSL_LOCAL word16 TLSX_WriteResponse(WOLFSSL* ssl, byte* output,
    1873                                         byte msgType);
     2086#if defined(WOLFSSL_TLS13) || !defined(NO_WOLFSSL_CLIENT)
     2087WOLFSSL_LOCAL int   TLSX_GetRequestSize(WOLFSSL* ssl, byte msgType,
     2088                                         word16* pLength);
     2089WOLFSSL_LOCAL int   TLSX_WriteRequest(WOLFSSL* ssl, byte* output,
     2090                                       byte msgType, word16* pOffset);
     2091#endif
     2092
     2093#if defined(WOLFSSL_TLS13) || !defined(NO_WOLFSSL_SERVER)
     2094/* TLS 1.3 Certificate messages have extensions. */
     2095WOLFSSL_LOCAL int   TLSX_GetResponseSize(WOLFSSL* ssl, byte msgType,
     2096                                          word16* pLength);
     2097WOLFSSL_LOCAL int   TLSX_WriteResponse(WOLFSSL *ssl, byte* output, byte msgType,
     2098                                        word16* pOffset);
    18742099#endif
    18752100
     
    19002125    union { char* host_name; } data;    /* SNI Data          */
    19012126    struct SNI*                next;    /* List Behavior     */
     2127    byte                       status;  /* Matching result  */
    19022128#ifndef NO_WOLFSSL_SERVER
    19032129    byte                       options; /* Behavior options */
    1904     byte                       status;  /* Matching result   */
    19052130#endif
    19062131} SNI;
     
    19082133WOLFSSL_LOCAL int TLSX_UseSNI(TLSX** extensions, byte type, const void* data,
    19092134                                                       word16 size, void* heap);
     2135WOLFSSL_LOCAL byte TLSX_SNI_Status(TLSX* extensions, byte type);
     2136WOLFSSL_LOCAL word16 TLSX_SNI_GetRequest(TLSX* extensions, byte type,
     2137                                                                   void** data);
    19102138
    19112139#ifndef NO_WOLFSSL_SERVER
    19122140WOLFSSL_LOCAL void   TLSX_SNI_SetOptions(TLSX* extensions, byte type,
    19132141                                                                  byte options);
    1914 WOLFSSL_LOCAL byte   TLSX_SNI_Status(TLSX* extensions, byte type);
    1915 WOLFSSL_LOCAL word16 TLSX_SNI_GetRequest(TLSX* extensions, byte type,
    1916                                                                    void** data);
    19172142WOLFSSL_LOCAL int    TLSX_SNI_GetFromBuffer(const byte* buffer, word32 bufferSz,
    19182143                                         byte type, byte* sni, word32* inOutSz);
     
    19602185    byte status_type;
    19612186    byte options;
     2187    WOLFSSL* ssl;
    19622188    union {
    19632189        OcspRequest ocsp;
    19642190    } request;
     2191#if defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_SERVER)
     2192    buffer response;
     2193#endif
    19652194} CertificateStatusRequest;
    19662195
    19672196WOLFSSL_LOCAL int   TLSX_UseCertificateStatusRequest(TLSX** extensions,
    1968                                     byte status_type, byte options, void* heap, int devId);
     2197           byte status_type, byte options, WOLFSSL* ssl, void* heap, int devId);
    19692198#ifndef NO_CERTS
    19702199WOLFSSL_LOCAL int   TLSX_CSR_InitRequest(TLSX* extensions, DecodedCert* cert,
     
    20232252WOLFSSL_LOCAL int TLSX_ValidateSupportedCurves(WOLFSSL* ssl, byte first,
    20242253                                                                   byte second);
    2025 #endif
     2254WOLFSSL_LOCAL int TLSX_SupportedCurve_CheckPriority(WOLFSSL* ssl);
     2255#endif
     2256WOLFSSL_LOCAL int TLSX_SupportedCurve_Preferred(WOLFSSL* ssl,
     2257                                                            int checkSupported);
    20262258
    20272259#endif /* HAVE_SUPPORTED_CURVES */
     
    20422274typedef struct SecureRenegotiation {
    20432275   byte                 enabled;  /* secure_renegotiation flag in rfc */
     2276   byte                 verifySet;
    20442277   byte                 startScr; /* server requested client to start scr */
    20452278   enum key_cache_state cache_status;  /* track key cache state */
     
    20532286
    20542287#ifdef HAVE_SERVER_RENEGOTIATION_INFO
    2055 WOLFSSL_LOCAL int TLSX_AddEmptyRenegotiationInfo(TLSX** extensions, void* heap);
     2288WOLFSSL_LOCAL int TLSX_AddEmptyRenegotiationInfo(TLSX** extensions);
    20562289#endif
    20572290
     
    21412374    void*                 key;    /* Private key              */
    21422375    word32                keyLen; /* Private key length       */
     2376    byte*                 pubKey;    /* Public key               */
     2377    word32                pubKeyLen; /* Public key length        */
    21432378    struct KeyShareEntry* next;   /* List pointer             */
    21442379} KeyShareEntry;
     
    21482383WOLFSSL_LOCAL int TLSX_KeyShare_Empty(WOLFSSL* ssl);
    21492384WOLFSSL_LOCAL int TLSX_KeyShare_Establish(WOLFSSL* ssl);
     2385WOLFSSL_LOCAL int TLSX_KeyShare_DeriveSecret(WOLFSSL* ssl);
    21502386
    21512387
    21522388#if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
     2389#ifndef WOLFSSL_TLS13_DRAFT_18
     2390/* Ticket nonce - for deriving PSK.
     2391 * Length allowed to be: 1..255. Only support 4 bytes.
     2392 */
     2393typedef struct TicketNonce {
     2394    byte len;
     2395    byte data[MAX_TICKET_NONCE_SZ];
     2396} TicketNonce;
     2397#endif
     2398
    21532399/* The PreSharedKey extension information - entry in a linked list. */
    21542400typedef struct PreSharedKey {
     
    21592405    byte                 cipherSuite;             /* Cipher Suite       */
    21602406    word32               binderLen;               /* Length of HMAC     */
    2161     byte                 binder[MAX_DIGEST_SIZE]; /* HMAC of hanshake   */
     2407    byte                 binder[WC_MAX_DIGEST_SIZE]; /* HMAC of hanshake   */
    21622408    byte                 hmac;                    /* HMAC algorithm     */
    21632409    byte                 resumption:1;            /* Resumption PSK     */
     
    22122458
    22132459
     2460#ifdef OPENSSL_EXTRA
     2461enum SetCBIO {
     2462    WOLFSSL_CBIO_NONE = 0,
     2463    WOLFSSL_CBIO_RECV = 0x1,
     2464    WOLFSSL_CBIO_SEND = 0x2,
     2465};
     2466#endif
     2467
    22142468/* wolfSSL context type */
    22152469struct WOLFSSL_CTX {
     
    22322486    WOLF_STACK_OF(WOLFSSL_X509_NAME)* ca_names;
    22332487    #endif
    2234     #if defined(WOLFSSL_NGINX) || defined (WOLFSSL_HAPROXY)
     2488    #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
     2489        defined(WOLFSSL_NGINX) || defined (WOLFSSL_HAPROXY)
    22352490    WOLF_STACK_OF(WOLFSSL_X509)* x509Chain;
    22362491    #endif
     
    22492504    Suites*     suites;           /* make dynamic, user may not need/set */
    22502505    void*       heap;             /* for user memory overrides */
    2251     byte        verifyPeer;
    2252     byte        verifyNone;
    2253     byte        failNoCert;
    2254     byte        failNoCertxPSK;   /* fail if no cert with the exception of PSK*/
    2255     byte        sessionCacheOff;
    2256     byte        sessionCacheFlushOff;
     2506    byte        verifyDepth;
     2507    byte        verifyPeer:1;
     2508    byte        verifyNone:1;
     2509    byte        failNoCert:1;
     2510    byte        failNoCertxPSK:1; /* fail if no cert with the exception of PSK*/
     2511    byte        sessionCacheOff:1;
     2512    byte        sessionCacheFlushOff:1;
    22572513#ifdef HAVE_EXT_CACHE
    2258     byte        internalCacheOff;
    2259 #endif
    2260     byte        sendVerify;       /* for client side */
    2261     byte        haveRSA        /* RSA available */
    2262     byte        haveECC        /* ECC available */
    2263     byte        haveDH         /* server DH parms set by user */
    2264     byte        haveNTRU       /* server private NTRU  key loaded */
    2265     byte        haveECDSAsig   /* server cert signed w/ ECDSA */
    2266     byte        haveStaticECC  /* static server ECC private key */
    2267     byte        partialWrite   /* only one msg per write call */
    2268     byte        quietShutdown  /* don't send close notify */
    2269     byte        groupMessages  /* group handshake messages before sending */
     2514    byte        internalCacheOff:1;
     2515#endif
     2516    byte        sendVerify:2;     /* for client side (can not be single bit) */
     2517    byte        haveRSA:1;        /* RSA available */
     2518    byte        haveECC:1;        /* ECC available */
     2519    byte        haveDH:1;         /* server DH parms set by user */
     2520    byte        haveNTRU:1;       /* server private NTRU  key loaded */
     2521    byte        haveECDSAsig:1;   /* server cert signed w/ ECDSA */
     2522    byte        haveStaticECC:1;  /* static server ECC private key */
     2523    byte        partialWrite:1;   /* only one msg per write call */
     2524    byte        quietShutdown:1;  /* don't send close notify */
     2525    byte        groupMessages:1;  /* group handshake messages before sending */
    22702526    byte        minDowngrade;     /* minimum downgrade version */
    2271     byte        haveEMS        /* have extended master secret extension */
     2527    byte        haveEMS:1;        /* have extended master secret extension */
    22722528    byte        useClientOrder:1; /* Use client's cipher preference order */
    22732529#ifdef WOLFSSL_TLS13
     
    22782534    byte        postHandshakeAuth:1;  /* Post-handshake auth supported. */
    22792535#endif
     2536#ifndef NO_DH
     2537    #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
     2538        !defined(HAVE_SELFTEST)
     2539    byte        dhKeyTested:1;   /* Set when key has been tested. */
     2540    #endif
     2541#endif
    22802542#ifdef WOLFSSL_MULTICAST
    22812543    byte        haveMcast;        /* multicast requested */
     
    22882550#ifndef NO_DH
    22892551    word16      minDhKeySz;       /* minimum DH key size */
     2552    word16      maxDhKeySz;       /* maximum DH key size */
    22902553#endif
    22912554#ifndef NO_RSA
     
    22952558    short       minEccKeySz;      /* minimum ECC key size */
    22962559#endif
     2560#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
     2561    unsigned long     mask;             /* store SSL_OP_ flags */
     2562#endif
    22972563#ifdef OPENSSL_EXTRA
     2564    byte              sessionCtx[ID_LEN]; /* app session context ID */
    22982565    word32            disabledCurves;   /* curves disabled by user */
    2299     byte              verifyDepth;      /* maximum verification depth */
    2300     unsigned long     mask;             /* store SSL_OP_ flags */
     2566    const unsigned char *alpn_cli_protos;/* ALPN client protocol list */
     2567    unsigned int         alpn_cli_protos_len;
     2568    byte              sessionCtxSz;
     2569    byte              cbioFlag;  /* WOLFSSL_CBIO_RECV/SEND: CBIORecv/Send is set */
     2570    CallbackInfoState* CBIS;      /* used to get info about SSL state */
    23012571#endif
    23022572    CallbackIORecv CBIORecv;
     
    23042574#ifdef WOLFSSL_DTLS
    23052575    CallbackGenCookie CBIOCookie;       /* gen cookie callback */
    2306     wc_dtls_export    dtls_export;      /* export function for DTLS session */
    23072576#ifdef WOLFSSL_SESSION_EXPORT
     2577    wc_dtls_export  dtls_export;        /* export function for DTLS session */
    23082578    CallbackGetPeer CBGetPeer;
    23092579    CallbackSetPeer CBSetPeer;
     
    23172587#ifdef HAVE_ECC
    23182588    word16          eccTempKeySz;       /* in octets 20 - 66 */
     2589#endif
     2590#if defined(HAVE_ECC) || defined(HAVE_ED25519)
    23192591    word32          pkCurveOID;         /* curve Ecc_Sum */
    23202592#endif
     
    23232595    wc_psk_client_callback client_psk_cb;  /* client callback */
    23242596    wc_psk_server_callback server_psk_cb;  /* server callback */
     2597#ifdef WOLFSSL_TLS13
     2598    wc_psk_client_tls13_callback client_psk_tls13_cb;  /* client callback */
     2599    wc_psk_server_tls13_callback server_psk_tls13_cb;  /* server callback */
     2600#endif
    23252601    char        server_hint[MAX_PSK_ID_LEN + NULL_TERM_LEN];
    23262602#endif /* HAVE_SESSION_TICKET || !NO_PSK */
     2603#ifdef WOLFSSL_TLS13
     2604    word16          group[WOLFSSL_MAX_GROUP_COUNT];
     2605    byte            numGroups;
     2606#endif
    23272607#ifdef WOLFSSL_EARLY_DATA
    23282608    word32          maxEarlyDataSz;
     
    23312611    byte        haveAnon;               /* User wants to allow Anon suites */
    23322612#endif /* HAVE_ANON */
     2613#ifdef WOLFSSL_ENCRYPTED_KEYS
     2614    pem_password_cb* passwd_cb;
     2615    void*            passwd_userdata;
     2616#endif
    23332617#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
    2334     pem_password_cb* passwd_cb;
    2335     void*           userdata;
    23362618    WOLFSSL_X509_STORE x509_store; /* points to ctx->cm */
     2619    WOLFSSL_X509_STORE* x509_store_pt; /* take ownership of external store */
    23372620    byte            readAhead;
    23382621    void*           userPRFArg; /* passed to prf callback */
    2339 #endif /* OPENSSL_EXTRA */
     2622#endif
    23402623#ifdef HAVE_EX_DATA
    23412624    void*           ex_data[MAX_EX_DATA];
    23422625#endif
    2343 #if defined(HAVE_ALPN) && (defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY))
     2626#if defined(HAVE_ALPN) && (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY))
    23442627    CallbackALPNSelect alpnSelect;
    23452628    void*              alpnSelectArg;
    23462629#endif
    2347 #if defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
     2630#if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && (defined(HAVE_STUNNEL) || \
     2631                             defined(WOLFSSL_NGINX) || defined(HAVE_LIGHTY) || \
     2632                             defined(WOLFSSL_HAPROXY)))
    23482633    CallbackSniRecv sniRecvCb;
    23492634    void*           sniRecvCbArg;
     
    23852670#ifdef HAVE_PK_CALLBACKS
    23862671    #ifdef HAVE_ECC
     2672        CallbackEccKeyGen EccKeyGenCb;  /* User EccKeyGen Callback Handler */
    23872673        CallbackEccSign   EccSignCb;    /* User EccSign   Callback handler */
    23882674        CallbackEccVerify EccVerifyCb;  /* User EccVerify Callback handler */
     
    23952681        #endif
    23962682        #ifdef HAVE_CURVE25519
    2397             /* User EccSharedSecret Callback handler */
     2683            /* User X25519 KeyGen Callback Handler */
     2684            CallbackX25519KeyGen X25519KeyGenCb;
     2685            /* User X25519 SharedSecret Callback handler */
    23982686            CallbackX25519SharedSecret X25519SharedSecretCb;
    23992687        #endif
    24002688    #endif /* HAVE_ECC */
     2689    #ifndef NO_DH
     2690        CallbackDhAgree DhAgreeCb;      /* User DH Agree Callback handler */
     2691    #endif
    24012692    #ifndef NO_RSA
    2402         CallbackRsaSign   RsaSignCb;    /* User RsaSign   Callback handler */
    2403         CallbackRsaVerify RsaVerifyCb;  /* User RsaVerify Callback handler */
     2693        CallbackRsaSign   RsaSignCb;      /* User RsaSign Callback handler (priv key) */
     2694        CallbackRsaVerify RsaVerifyCb;    /* User RsaVerify Callback handler (pub key) */
     2695        CallbackRsaVerify RsaSignCheckCb; /* User VerifyRsaSign Callback handler (priv key) */
    24042696        #ifdef WC_RSA_PSS
    2405             CallbackRsaPssSign   RsaPssSignCb;    /* User RsaPssSign */
    2406             CallbackRsaPssVerify RsaPssVerifyCb;  /* User RsaPssVerify */
     2697            CallbackRsaPssSign   RsaPssSignCb;       /* User RsaSign (priv key) */
     2698            CallbackRsaPssVerify RsaPssVerifyCb;     /* User RsaVerify (pub key) */
     2699            CallbackRsaPssVerify RsaPssSignCheckCb; /* User VerifyRsaSign (priv key) */
    24072700        #endif
    24082701        CallbackRsaEnc    RsaEncCb;     /* User Rsa Public Encrypt  handler */
     
    24182711        void (*rem_sess_cb)(WOLFSSL_CTX*, WOLFSSL_SESSION*);
    24192712#endif
    2420 };
    2421 
     2713#if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && !defined(NO_SHA256)
     2714        Srp*  srp;  /* TLS Secure Remote Password Protocol*/
     2715        byte* srp_password;
     2716#endif
     2717};
    24222718
    24232719WOLFSSL_LOCAL
     
    25312827
    25322828
     2829#ifndef WOLFSSL_AEAD_ONLY
    25332830enum CipherType { stream, block, aead };
     2831#else
     2832enum CipherType { aead };
     2833#endif
    25342834
    25352835
     
    26622962    byte               serverID[SERVER_ID_LEN];   /* for easier client lookup */
    26632963#endif
     2964#ifdef OPENSSL_EXTRA
     2965    byte               sessionCtxSz;              /* sessionCtx length        */
     2966    byte               sessionCtx[ID_LEN];        /* app specific context id  */
     2967#endif
     2968#ifdef WOLFSSL_TLS13
     2969    word16             namedGroup;
     2970#endif
    26642971#if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
    26652972    #ifdef WOLFSSL_TLS13
    2666     byte               namedGroup;
    26672973    word32             ticketSeen;                /* Time ticket seen (ms) */
    26682974    word32             ticketAdd;                 /* Added by client */
     2975        #ifndef WOLFSSL_TLS13_DRAFT_18
     2976    TicketNonce        ticketNonce;               /* Nonce used to derive PSK */
     2977        #endif
    26692978    #endif
    26702979    #ifdef WOLFSSL_EARLY_DATA
    26712980    word32             maxEarlyDataSz;
    26722981    #endif
     2982#endif
     2983#ifdef HAVE_SESSION_TICKET
    26732984    byte*              ticket;
    26742985    word16             ticketLen;
     
    26903001int          SetSession(WOLFSSL*, WOLFSSL_SESSION*);
    26913002
    2692 typedef int (*hmacfp) (WOLFSSL*, byte*, const byte*, word32, int, int);
     3003typedef int (*hmacfp) (WOLFSSL*, byte*, const byte*, word32, int, int, int);
    26933004
    26943005#ifndef NO_CLIENT_CACHE
     
    27313042    ACCEPT_FINISHED_DONE,
    27323043    ACCEPT_THIRD_REPLY_DONE
     3044};
     3045
     3046/* TLS 1.3 server accept state for nonblocking restart */
     3047enum AcceptStateTls13 {
     3048    TLS13_ACCEPT_BEGIN = 0,
     3049    TLS13_ACCEPT_CLIENT_HELLO_DONE,
     3050    TLS13_ACCEPT_HELLO_RETRY_REQUEST_DONE,
     3051    TLS13_ACCEPT_FIRST_REPLY_DONE,
     3052    TLS13_ACCEPT_SECOND_REPLY_DONE,
     3053    TLS13_SERVER_HELLO_SENT,
     3054    TLS13_ACCEPT_THIRD_REPLY_DONE,
     3055    TLS13_SERVER_EXTENSIONS_SENT,
     3056    TLS13_CERT_REQ_SENT,
     3057    TLS13_CERT_SENT,
     3058    TLS13_CERT_VERIFY_SENT,
     3059    TLS13_ACCEPT_FINISHED_SENT,
     3060    TLS13_PRE_TICKET_SENT,
     3061    TLS13_ACCEPT_FINISHED_DONE,
     3062    TLS13_TICKET_SENT
    27333063};
    27343064
     
    27653095#ifdef WOLFSSL_TLS13
    27663096    int             certChainCnt;
     3097    DerBuffer*      certExts;
    27673098#endif
    27683099#endif
     
    28193150    wc_psk_client_callback client_psk_cb;
    28203151    wc_psk_server_callback server_psk_cb;
     3152#ifdef WOLFSSL_TLS13
     3153    wc_psk_client_tls13_callback client_psk_tls13_cb;  /* client callback */
     3154    wc_psk_server_tls13_callback server_psk_tls13_cb;  /* server callback */
     3155#endif
    28213156#endif /* NO_PSK */
    28223157#ifdef OPENSSL_EXTRA
     
    28343169    word16            internalCacheOff:1;
    28353170#endif
    2836     word16            side:1;             /* client or server end */
     3171    word16            side:2;             /* client, server or neither end */
    28373172    word16            verifyPeer:1;
    28383173    word16            verifyNone:1;
     
    28683203    word16            certOnly:1;         /* stop once we get cert */
    28693204    word16            groupMessages:1;    /* group handshake messages */
    2870     word16            usingNonblock:1;    /* are we using nonblocking socket */
    28713205    word16            saveArrays:1;       /* save array Memory for user get keys
    28723206                                           or psk */
     
    28883222#endif
    28893223#ifdef WOLFSSL_DTLS
     3224    word16            dtlsUseNonblock:1;  /* are we using nonblocking socket */
    28903225    word16            dtlsHsRetain:1;     /* DTLS retaining HS data */
    28913226    word16            haveMcast:1;        /* using multicast ? */
     
    29093244    word16            usingAltCertChain:1;/* Alternate cert chain was used */
    29103245#endif
    2911 
     3246#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
     3247    word16            sentChangeCipher:1; /* Change Cipher Spec sent */
     3248#endif
     3249#if !defined(WOLFSSL_NO_CLIENT_AUTH) && defined(HAVE_ED25519) && \
     3250                                                !defined(NO_ED25519_CLIENT_AUTH)
     3251    word16            cacheMessages:1;    /* Cache messages for sign/verify */
     3252#endif
     3253#ifndef NO_DH
     3254    #if !defined(WOLFSSL_OLD_PRIME_CHECK) && \
     3255        !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
     3256        word16        dhDoKeyTest:1;      /* Need to do the DH Key prime test */
     3257        word16        dhKeyTested:1;      /* Set when key has been tested. */
     3258    #endif
     3259#endif
    29123260    /* need full byte values for this section */
    29133261    byte            processReply;           /* nonblocking resume */
     
    29293277#ifndef NO_DH
    29303278    word16          minDhKeySz;         /* minimum DH key size */
     3279    word16          maxDhKeySz;         /* minimum DH key size */
    29313280    word16          dhKeySz;            /* actual DH key size */
    29323281#endif
     
    29413290#endif
    29423291#ifdef WOLFSSL_EARLY_DATA
     3292    word16          pskIdIndex;
    29433293    word32          maxEarlyDataSz;
    29443294#endif
    2945 
     3295#ifdef WOLFSSL_TLS13
     3296    byte            oldMinor;          /* client preferred version < TLS 1.3 */
     3297#endif
    29463298} Options;
    29473299
     
    29633315    byte            sessionIDSz;
    29643316#ifdef WOLFSSL_TLS13
    2965     byte            clientSecret[SECRET_LEN];
    2966     byte            serverSecret[SECRET_LEN];
    29673317    byte            secret[SECRET_LEN];
    29683318#endif
     
    29993349struct WOLFSSL_X509_NAME {
    30003350    char  *name;
    3001     char  staticName[ASN_NAME_MAX];
    30023351    int   dynamicName;
    30033352    int   sz;
    3004 #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
     3353    char  staticName[ASN_NAME_MAX];
     3354#if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
     3355    !defined(NO_ASN)
    30053356    DecodedName fullName;
    30063357    WOLFSSL_X509_NAME_ENTRY cnEntry;
     3358    WOLFSSL_X509_NAME_ENTRY extra[MAX_NAME_ENTRIES]; /* extra entries added */
    30073359    WOLFSSL_X509*           x509;   /* x509 that struct belongs to */
    30083360#endif /* OPENSSL_EXTRA */
    3009 #ifdef WOLFSSL_NGINX
     3361#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX)
    30103362    byte  raw[ASN_NAME_MAX];
    30113363    int   rawLen;
     
    30233375struct WOLFSSL_X509 {
    30243376    int              version;
    3025     WOLFSSL_X509_NAME issuer;
    3026     WOLFSSL_X509_NAME subject;
    30273377    int              serialSz;
    3028     byte             serial[EXTERNAL_SERIAL_SIZE];
    3029     char             subjectCN[ASN_NAME_MAX];        /* common name short cut */
    30303378#ifdef WOLFSSL_SEP
    30313379    int              deviceTypeSz;
     3380    int              hwTypeSz;
    30323381    byte             deviceType[EXTERNAL_SERIAL_SIZE];
    3033     int              hwTypeSz;
    30343382    byte             hwType[EXTERNAL_SERIAL_SIZE];
    30353383    int              hwSerialNumSz;
    30363384    byte             hwSerialNum[EXTERNAL_SERIAL_SIZE];
    3037     #ifdef OPENSSL_EXTRA
     3385    #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
    30383386        byte             certPolicySet;
    30393387        byte             certPolicyCrit;
     
    30413389#endif
    30423390    int              notBeforeSz;
     3391    int              notAfterSz;
    30433392    byte             notBefore[MAX_DATE_SZ];
    3044     int              notAfterSz;
    30453393    byte             notAfter[MAX_DATE_SZ];
     3394    buffer           sig;
    30463395    int              sigOID;
    3047     buffer           sig;
     3396    DNS_entry*       altNames;                       /* alt names list */
     3397    buffer           pubKey;
    30483398    int              pubKeyOID;
    3049     buffer           pubKey;
    3050     #ifdef HAVE_ECC
     3399    DNS_entry*       altNamesNext;                   /* hint for retrieval */
     3400    #if defined(HAVE_ECC) || defined(HAVE_ED25519)
    30513401        word32       pkCurveOID;
    30523402    #endif /* HAVE_ECC */
     
    30543404        DerBuffer*   derCert;                        /* may need  */
    30553405    #endif
    3056     DNS_entry*       altNames;                       /* alt names list */
    3057     DNS_entry*       altNamesNext;                   /* hint for retrieval */
    30583406    void*            heap;                           /* heap hint */
    30593407    byte             dynamicMemory;                  /* dynamic memory flag */
    3060     byte             isCa;
     3408    byte             isCa:1;
    30613409#ifdef WOLFSSL_CERT_EXT
    30623410    char             certPolicies[MAX_CERTPOL_NB][MAX_CERTPOL_SZ];
    30633411    int              certPoliciesNb;
    30643412#endif /* WOLFSSL_CERT_EXT */
    3065 #ifdef OPENSSL_EXTRA
     3413#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
    30663414#ifdef HAVE_EX_DATA
    30673415    void*            ex_data[MAX_EX_DATA];
    30683416#endif
     3417    byte*            authKeyId;
     3418    byte*            subjKeyId;
     3419    byte*            extKeyUsageSrc;
     3420    const byte*      CRLInfo;
     3421    byte*            authInfo;
    30693422    word32           pathLength;
    30703423    word16           keyUsage;
    3071     byte             CRLdistSet;
    3072     byte             CRLdistCrit;
    3073     byte*            CRLInfo;
    30743424    int              CRLInfoSz;
    3075     byte             authInfoSet;
    3076     byte             authInfoCrit;
    3077     byte*            authInfo;
    30783425    int              authInfoSz;
    3079     byte             basicConstSet;
    3080     byte             basicConstCrit;
    3081     byte             basicConstPlSet;
    3082     byte             subjAltNameSet;
    3083     byte             subjAltNameCrit;
    3084     byte             authKeyIdSet;
    3085     byte             authKeyIdCrit;
    3086     byte*            authKeyId;
    30873426    word32           authKeyIdSz;
    3088     byte             subjKeyIdSet;
    3089     byte             subjKeyIdCrit;
    3090     byte*            subjKeyId;
    30913427    word32           subjKeyIdSz;
    3092     byte             keyUsageSet;
    3093     byte             keyUsageCrit;
    3094     byte             extKeyUsageCrit;
    3095     byte*            extKeyUsageSrc;
    30963428    word32           extKeyUsageSz;
    30973429    word32           extKeyUsageCount;
    3098 #endif /* OPENSSL_EXTRA */
     3430
     3431    byte             CRLdistSet:1;
     3432    byte             CRLdistCrit:1;
     3433    byte             authInfoSet:1;
     3434    byte             authInfoCrit:1;
     3435    byte             keyUsageSet:1;
     3436    byte             keyUsageCrit:1;
     3437    byte             extKeyUsageCrit:1;
     3438    byte             subjKeyIdSet:1;
     3439
     3440    byte             subjKeyIdCrit:1;
     3441    byte             basicConstSet:1;
     3442    byte             basicConstCrit:1;
     3443    byte             basicConstPlSet:1;
     3444    byte             subjAltNameSet:1;
     3445    byte             subjAltNameCrit:1;
     3446    byte             authKeyIdSet:1;
     3447    byte             authKeyIdCrit:1;
     3448#endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
     3449    byte             serial[EXTERNAL_SERIAL_SIZE];
     3450    char             subjectCN[ASN_NAME_MAX];        /* common name short cut */
     3451#ifdef WOLFSSL_CERT_REQ
     3452    char             challengePw[CTC_NAME_SIZE]; /* for REQ certs */
     3453#endif
     3454    WOLFSSL_X509_NAME issuer;
     3455    WOLFSSL_X509_NAME subject;
    30993456};
    31003457
     
    31333490    word32          fragSz;    /* Length of fragments received */
    31343491    word32          seq;       /* Handshake sequence number    */
    3135     word32          sz;        /* Length of whole mesage       */
     3492    word32          sz;        /* Length of whole message      */
    31363493    byte            type;
    31373494} DtlsMsg;
     
    31503507#endif
    31513508
    3152 
    31533509/* Handshake messages received from peer (plus change cipher */
    31543510typedef struct MsgsReceived {
    31553511    word16 got_hello_request:1;
    31563512    word16 got_client_hello:2;
    3157     word16 got_server_hello:1;
     3513    word16 got_server_hello:2;
    31583514    word16 got_hello_verify_request:1;
    31593515    word16 got_session_ticket:1;
     
    31933549    wc_Sha512       hashSha512;         /* sha512 hash of handshake msgs */
    31943550#endif
     3551#if defined(HAVE_ED25519) && !defined(WOLFSSL_NO_CLIENT_AUTH)
     3552    byte*           messages;           /* handshake messages */
     3553    int             length;             /* length of handshake messages' data */
     3554    int             prevLen;            /* length of messages but last */
     3555#endif
    31953556} HS_Hashes;
    31963557
     
    32323593#endif
    32333594
     3595#ifdef WOLFSSL_EARLY_DATA
     3596typedef enum EarlyDataState {
     3597    no_early_data,
     3598    expecting_early_data,
     3599    process_early_data,
     3600    done_early_data
     3601} EarlyDataState;
     3602#endif
     3603
    32343604/* wolfSSL ssl type */
    32353605struct WOLFSSL {
     
    32373607    Suites*         suites;             /* only need during handshake */
    32383608    Arrays*         arrays;
     3609#ifdef WOLFSSL_TLS13
     3610    byte            clientSecret[SECRET_LEN];
     3611    byte            serverSecret[SECRET_LEN];
     3612#endif
    32393613    HS_Hashes*      hsHashes;
    32403614    void*           IOCB_ReadCtx;
     
    32493623    byte            dupSide;            /* write side or read side */
    32503624#endif
     3625#ifdef OPENSSL_EXTRA
     3626    byte              cbioFlag;  /* WOLFSSL_CBIO_RECV/SEND: CBIORecv/Send is set */
     3627#endif
     3628    CallbackIORecv  CBIORecv;
     3629    CallbackIOSend  CBIOSend;
    32513630#ifdef WOLFSSL_STATIC_MEMORY
    32523631    WOLFSSL_HEAP_HINT heap_hint;
     
    32583637#ifdef WOLFSSL_ASYNC_CRYPT
    32593638    struct WOLFSSL_ASYNC async;
     3639#elif defined(WOLFSSL_NONBLOCK_OCSP)
     3640    void*           nonblockarg;        /* dynamic arg for handling non-block resume */
    32603641#endif
    32613642    void*           hsKey;              /* Handshake key (RsaKey or ecc_key) allocated from heap */
    32623643    word32          hsType;             /* Type of Handshake key (hsKey) */
    32633644    WOLFSSL_CIPHER  cipher;
     3645#ifndef WOLFSSL_AEAD_ONLY
    32643646    hmacfp          hmac;
     3647#endif
    32653648    Ciphers         encrypt;
    32663649    Ciphers         decrypt;
     
    32793662    word32          fragOffset;         /* fragment offset */
    32803663    word16          curSize;
     3664    byte            verifyDepth;
    32813665    RecordLayerHeader curRL;
    32823666    MsgsReceived    msgsReceived;       /* peer messages received */
     
    32873671    Options         options;
    32883672#ifdef OPENSSL_EXTRA
     3673    CallbackInfoState* CBIS;             /* used to get info about SSL state */
     3674    int              cbmode;             /* read or write on info callback */
     3675    int              cbtype;             /* event type in info callback */
    32893676    WOLFSSL_BIO*     biord;              /* socket bio read  to free/close */
    32903677    WOLFSSL_BIO*     biowr;              /* socket bio write to free/close */
     3678    byte             sessionCtx[ID_LEN]; /* app session context ID */
    32913679    unsigned long    peerVerifyRet;
    32923680    byte             readAhead;
     3681    byte             sessionCtxSz;       /* size of sessionCtx stored */
    32933682#ifdef HAVE_PK_CALLBACKS
    32943683    void*            loggingCtx;         /* logging callback argument */
    32953684#endif
    3296 #endif
     3685#endif /* OPENSSL_EXTRA */
    32973686#ifndef NO_RSA
    32983687    RsaKey*         peerRsaKey;
     
    33133702#ifdef WOLFSSL_TLS13
    33143703    word16          namedGroup;
     3704    word16          group[WOLFSSL_MAX_GROUP_COUNT];
     3705    byte            numGroups;
    33153706#endif
    33163707    byte            pssAlgo;
     3708#ifdef WOLFSSL_TLS13
     3709    #if !defined(WOLFSSL_TLS13_DRAFT_18) && !defined(WOLFSSL_TLS13_DRAFT_22)
     3710    word16          certHashSigAlgoSz;  /* SigAlgoCert ext length in bytes */
     3711    byte            certHashSigAlgo[WOLFSSL_MAX_SIGALGO]; /* cert sig/algo to
     3712                                                           * offer */
     3713    #endif /* !WOLFSSL_TLS13_DRAFT_18 && !WOLFSSL_TLS13_DRAFT_22 */
     3714#endif
    33173715#ifdef HAVE_NTRU
    33183716    word16          peerNtruKeyLen;
     
    33323730    ecc_key*        peerEccKey;              /* peer's  ECDHE key */
    33333731    ecc_key*        peerEccDsaKey;           /* peer's  ECDSA key */
    3334     word32          pkCurveOID;              /* curve Ecc_Sum     */
    33353732    word16          eccTempKeySz;            /* in octets 20 - 66 */
    33363733    byte            peerEccDsaKeyPresent;
     3734#endif
     3735#if defined(HAVE_ECC) || defined(HAVE_ED25519)
     3736    word32          pkCurveOID;              /* curve Ecc_Sum     */
    33373737#endif
    33383738#ifdef HAVE_ED25519
     
    33593759    void*           IOCB_CookieCtx;     /* gen cookie ctx */
    33603760    word32          dtls_expected_rx;
     3761#ifdef WOLFSSL_SESSION_EXPORT
    33613762    wc_dtls_export  dtls_export;        /* export function for session */
     3763#endif
    33623764#ifdef WOLFSSL_SCTP
    33633765    word16          dtlsMtuSz;
     
    33723774#endif /* WOLFSSL_DTLS */
    33733775#ifdef WOLFSSL_CALLBACKS
     3776    TimeoutInfo     timeoutInfo;        /* info saved during handshake */
    33743777    HandShakeInfo   handShakeInfo;      /* info saved during handshake */
    3375     TimeoutInfo     timeoutInfo;        /* info saved during handshake */
     3778#endif
     3779#ifdef OPENSSL_EXTRA
     3780    SSL_Msg_Cb      protoMsgCb;         /* inspect protocol message callback */
     3781    void*           protoMsgCtx;        /* user set context with msg callback */
     3782#endif
     3783#if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
    33763784    byte            hsInfoOn;           /* track handshake info        */
    33773785    byte            toInfoOn;           /* track timeout   info        */
     
    34203828    #ifdef HAVE_ALPN
    34213829        char*   alpn_client_list;  /* keep the client's list */
    3422         #if defined(WOLFSSL_NGINX)  || defined(WOLFSSL_HAPROXY)
     3830        #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX)  || defined(WOLFSSL_HAPROXY)
    34233831            CallbackALPNSelect alpnSelect;
    34243832            void*              alpnSelectArg;
     
    34363844        byte*       ocspResp;
    34373845        int         ocspRespSz;
    3438         #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
     3846        #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
    34393847            char*   url;
    34403848        #endif
     
    34443852    NetX_Ctx        nxCtx;             /* NetX IO Context */
    34453853#endif
     3854#if defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP)
     3855    void*           mnCtx;             /* mynewt mn_socket IO Context */
     3856#endif /* defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP) */
    34463857#ifdef SESSION_INDEX
    34473858    int sessionIndex;                  /* Session's location in the cache. */
     
    34533864#ifdef HAVE_PK_CALLBACKS
    34543865    #ifdef HAVE_ECC
     3866        void* EccKeyGenCtx;              /* EccKeyGen  Callback Context */
    34553867        void* EccSignCtx;     /* Ecc Sign   Callback Context */
    34563868        void* EccVerifyCtx;   /* Ecc Verify Callback Context */
     
    34613873        #endif
    34623874        #ifdef HAVE_CURVE25519
     3875            void* X25519KeyGenCtx;       /* X25519 KeyGen Callback Context */
    34633876            void* X25519SharedSecretCtx; /* X25519 Pms Callback Context */
    34643877        #endif
    34653878    #endif /* HAVE_ECC */
     3879    #ifndef NO_DH
     3880        void* DhAgreeCtx; /* DH Pms Callback Context */
     3881    #endif /* !NO_DH */
    34663882    #ifndef NO_RSA
    34673883        void* RsaSignCtx;     /* Rsa Sign   Callback Context */
     
    34833899#endif /* WOLFSSL_JNI */
    34843900#ifdef WOLFSSL_EARLY_DATA
    3485     int earlyData;
     3901    EarlyDataState earlyData;
    34863902    word32 earlyDataSz;
    34873903#endif
     
    34983914
    34993915
    3500 enum {
    3501     IV_SZ   = 32,          /* max iv sz */
    3502     NAME_SZ = 80          /* max one line */
    3503 };
    3504 
    3505 
    3506 typedef struct EncryptedInfo {
    3507     char     name[NAME_SZ];    /* encryption name */
    3508     byte     iv[IV_SZ];        /* encrypted IV */
    3509     word32   ivSz;             /* encrypted IV size */
    3510     long     consumed;         /* tracks PEM bytes consumed */
    3511     byte     set;              /* if encryption set */
    3512     WOLFSSL_CTX* ctx;              /* CTX owner */
    3513 } EncryptedInfo;
    3514 
    35153916
    35163917#ifndef NO_CERTS
    3517 
    3518     WOLFSSL_LOCAL int AllocDer(DerBuffer** der, word32 length, int type, void* heap);
    3519     WOLFSSL_LOCAL void FreeDer(DerBuffer** der);
    3520 
    3521     WOLFSSL_LOCAL int PemToDer(const unsigned char* buff, long sz, int type,
    3522                               DerBuffer** pDer, void* heap, EncryptedInfo* info,
    3523                               int* eccKey);
    35243918
    35253919    WOLFSSL_LOCAL int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
     
    35373931
    35383932
    3539 #ifdef WOLFSSL_CALLBACKS
     3933#if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
    35403934    WOLFSSL_LOCAL
    35413935    void InitHandShakeInfo(HandShakeInfo*, WOLFSSL*);
     
    35433937    void FinishHandShakeInfo(HandShakeInfo*);
    35443938    WOLFSSL_LOCAL
    3545     void AddPacketName(const char*, HandShakeInfo*);
     3939    void AddPacketName(WOLFSSL* ssl, const char* name);
    35463940
    35473941    WOLFSSL_LOCAL
     
    35503944    void FreeTimeoutInfo(TimeoutInfo*, void*);
    35513945    WOLFSSL_LOCAL
    3552     void AddPacketInfo(const char*, TimeoutInfo*, const byte*, int, void*);
     3946    void AddPacketInfo(WOLFSSL* ssl, const char* name, int type,
     3947                               const byte* data, int sz, int write, void* heap);
    35533948    WOLFSSL_LOCAL
    35543949    void AddLateName(const char*, TimeoutInfo*);
     
    36304025WOLFSSL_LOCAL int SendData(WOLFSSL*, const void*, int);
    36314026#ifdef WOLFSSL_TLS13
     4027#ifdef WOLFSSL_TLS13_DRAFT_18
    36324028WOLFSSL_LOCAL int SendTls13HelloRetryRequest(WOLFSSL*);
     4029#else
     4030WOLFSSL_LOCAL int SendTls13ServerHello(WOLFSSL*, byte);
     4031#endif
    36334032#endif
    36344033WOLFSSL_LOCAL int SendCertificate(WOLFSSL*);
    36354034WOLFSSL_LOCAL int SendCertificateRequest(WOLFSSL*);
     4035#if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
     4036 || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
     4037WOLFSSL_LOCAL int CreateOcspResponse(WOLFSSL*, OcspRequest**, buffer*);
     4038#endif
     4039#if defined(HAVE_SECURE_RENEGOTIATION) && \
     4040    defined(HAVE_SERVER_RENEGOTIATION_INFO)
     4041WOLFSSL_LOCAL int SendHelloRequest(WOLFSSL*);
     4042#endif
    36364043WOLFSSL_LOCAL int SendCertificateStatus(WOLFSSL*);
    36374044WOLFSSL_LOCAL int SendServerKeyExchange(WOLFSSL*);
     
    36604067
    36614068WOLFSSL_LOCAL int SetTicket(WOLFSSL*, const byte*, word32);
     4069WOLFSSL_LOCAL int wolfSSL_GetMaxRecordSize(WOLFSSL* ssl, int maxFragment);
    36624070
    36634071#ifndef NO_CERTS
     
    36654073        #ifdef WC_RSA_PSS
    36664074            WOLFSSL_LOCAL int CheckRsaPssPadding(const byte* plain, word32 plainSz,
    3667                                                  byte* out, word32 sigSz,
    3668                                                  enum wc_HashType hashType);
    3669             WOLFSSL_LOCAL int ConvertHashPss(int hashAlgo, enum wc_HashType* hashType, int* mgf);
    3670         #endif
    3671         WOLFSSL_LOCAL int VerifyRsaSign(WOLFSSL* ssl,
    3672                                         byte* verifySig, word32 sigSz,
    3673                                         const byte* plain, word32 plainSz,
    3674                                         int sigAlgo, int hashAlgo,
    3675                                         RsaKey* key);
     4075                byte* out, word32 sigSz, enum wc_HashType hashType);
     4076            WOLFSSL_LOCAL int ConvertHashPss(int hashAlgo,
     4077                enum wc_HashType* hashType, int* mgf);
     4078        #endif
     4079        WOLFSSL_LOCAL int VerifyRsaSign(WOLFSSL* ssl, byte* verifySig,
     4080            word32 sigSz, const byte* plain, word32 plainSz, int sigAlgo,
     4081            int hashAlgo, RsaKey* key, DerBuffer* keyBufInfo);
    36764082        WOLFSSL_LOCAL int RsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,
    36774083            byte* out, word32* outSz, int sigAlgo, int hashAlgo, RsaKey* key,
    3678             const byte* keyBuf, word32 keySz, void* ctx);
     4084            DerBuffer* keyBufInfo);
    36794085        WOLFSSL_LOCAL int RsaVerify(WOLFSSL* ssl, byte* in, word32 inSz,
    36804086            byte** out, int sigAlgo, int hashAlgo, RsaKey* key,
    3681             const byte* keyBuf, word32 keySz, void* ctx);
     4087            buffer* keyBufInfo);
    36824088        WOLFSSL_LOCAL int RsaDec(WOLFSSL* ssl, byte* in, word32 inSz, byte** out,
    3683             word32* outSz, RsaKey* key, const byte* keyBuf, word32 keySz, void* ctx);
     4089            word32* outSz, RsaKey* key, DerBuffer* keyBufInfo);
    36844090        WOLFSSL_LOCAL int RsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz, byte* out,
    3685             word32* outSz, RsaKey* key, const byte* keyBuf, word32 keySz, void* ctx);
     4091            word32* outSz, RsaKey* key, buffer* keyBufInfo);
    36864092    #endif /* !NO_RSA */
    36874093
    36884094    #ifdef HAVE_ECC
    36894095        WOLFSSL_LOCAL int EccSign(WOLFSSL* ssl, const byte* in, word32 inSz,
    3690             byte* out, word32* outSz, ecc_key* key, byte* keyBuf, word32 keySz,
    3691             void* ctx);
     4096            byte* out, word32* outSz, ecc_key* key, DerBuffer* keyBufInfo);
    36924097        WOLFSSL_LOCAL int EccVerify(WOLFSSL* ssl, const byte* in, word32 inSz,
    3693             const byte* out, word32 outSz, ecc_key* key, byte* keyBuf, word32 keySz,
    3694             void* ctx);
     4098            const byte* out, word32 outSz, ecc_key* key, buffer* keyBufInfo);
    36954099        WOLFSSL_LOCAL int EccSharedSecret(WOLFSSL* ssl, ecc_key* priv_key,
    36964100            ecc_key* pub_key, byte* pubKeyDer, word32* pubKeySz, byte* out,
    3697             word32* outlen, int side, void* ctx);
     4101            word32* outlen, int side);
    36984102    #endif /* HAVE_ECC */
    36994103    #ifdef HAVE_ED25519
     4104        WOLFSSL_LOCAL int Ed25519CheckPubKey(WOLFSSL* ssl);
    37004105        WOLFSSL_LOCAL int Ed25519Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
    3701             byte* out, word32* outSz, ed25519_key* key, byte* keyBuf,
    3702             word32 keySz, void* ctx);
     4106            byte* out, word32* outSz, ed25519_key* key, DerBuffer* keyBufInfo);
    37034107        WOLFSSL_LOCAL int Ed25519Verify(WOLFSSL* ssl, const byte* in,
    37044108            word32 inSz, const byte* msg, word32 msgSz, ed25519_key* key,
    3705             byte* keyBuf, word32 keySz, void* ctx);
     4109            buffer* keyBufInfo);
    37064110    #endif /* HAVE_ED25519 */
    37074111
     
    37344138#ifndef NO_TLS
    37354139    WOLFSSL_LOCAL int  MakeTlsMasterSecret(WOLFSSL*);
     4140#ifndef WOLFSSL_AEAD_ONLY
    37364141    WOLFSSL_LOCAL int  TLS_hmac(WOLFSSL* ssl, byte* digest, const byte* in,
    3737                                word32 sz, int content, int verify);
     4142                                word32 sz, int padSz, int content, int verify);
     4143#endif
    37384144#endif
    37394145
     
    37884194#endif
    37894195
    3790 WOLFSSL_LOCAL const char* const* GetCipherNames(void);
     4196typedef struct CipherSuiteInfo {
     4197    const char* name;
     4198#ifndef NO_ERROR_STRINGS
     4199    const char* name_iana;
     4200#endif
     4201    byte cipherSuite0;
     4202    byte cipherSuite;
     4203} CipherSuiteInfo;
     4204
     4205WOLFSSL_LOCAL const CipherSuiteInfo* GetCipherNames(void);
    37914206WOLFSSL_LOCAL int GetCipherNamesSize(void);
    3792 WOLFSSL_LOCAL const char* GetCipherNameInternal(const char* cipherName, int cipherSuite);
     4207WOLFSSL_LOCAL const char* GetCipherNameInternal(const byte cipherSuite0, const byte cipherSuite);
     4208WOLFSSL_LOCAL const char* GetCipherNameIana(const byte cipherSuite0, const byte cipherSuite);
    37934209WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl);
    3794 WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_from_suite(
    3795     const unsigned char cipherSuite, const unsigned char cipherSuite0);
     4210WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_iana(WOLFSSL* ssl);
     4211WOLFSSL_LOCAL int GetCipherSuiteFromName(const char* name, byte* cipherSuite0,
     4212                                         byte* cipherSuite);
    37964213
    37974214enum encrypt_side {
Note: See TracChangeset for help on using the changeset viewer.