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

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

Location:
asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt
Files:
1 added
38 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/aes.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/aes.h
     24*/
     25
    2226
    2327#ifndef WOLF_CRYPT_AES_H
     
    2832#ifndef NO_AES
    2933
     34#if defined(HAVE_FIPS) && \
     35    defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     36    #include <wolfssl/wolfcrypt/fips.h>
     37#endif /* HAVE_FIPS_VERSION >= 2 */
     38
    3039/* included for fips @wc_fips */
    31 #ifdef HAVE_FIPS
     40#if defined(HAVE_FIPS) && \
     41    (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
    3242#include <cyassl/ctaocrypt/aes.h>
    3343#if defined(CYASSL_AES_COUNTER) && !defined(WOLFSSL_AES_COUNTER)
     
    3949#endif
    4050
    41 #ifndef HAVE_FIPS /* to avoid redefinition of macros */
     51#ifndef WC_NO_RNG
     52    #include <wolfssl/wolfcrypt/random.h>
     53#endif
     54#ifdef STM32_CRYPTO
     55    #include <wolfssl/wolfcrypt/port/st/stm32.h>
     56#endif
    4257
    4358#ifdef WOLFSSL_AESNI
     
    4964#endif /* WOLFSSL_AESNI */
    5065
     66
    5167#ifdef WOLFSSL_XILINX_CRYPT
    5268#include "xsecure_aes.h"
    5369#endif
    5470
    55 #endif /* HAVE_FIPS */
     71#ifdef WOLFSSL_AFALG
     72/* included for struct msghdr */
     73#include <sys/socket.h>
     74#endif
     75
     76#if defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC)
     77#include <wolfssl/wolfcrypt/port/devcrypto/wc_devcrypto.h>
     78#endif
     79
     80#if defined(HAVE_AESGCM) && !defined(WC_NO_RNG)
     81    #include <wolfssl/wolfcrypt/random.h>
     82#endif
     83
    5684
    5785#ifdef __cplusplus
     
    5987#endif
    6088
    61 #ifndef HAVE_FIPS /* to avoid redefinition of structures */
     89/* these are required for FIPS and non-FIPS */
     90enum {
     91    AES_128_KEY_SIZE    = 16,  /* for 128 bit             */
     92    AES_192_KEY_SIZE    = 24,  /* for 192 bit             */
     93    AES_256_KEY_SIZE    = 32,  /* for 256 bit             */
     94
     95    AES_IV_SIZE         = 16,  /* always block size       */
     96};
     97
     98
     99/* avoid redefinition of structs */
     100#if !defined(HAVE_FIPS) || \
     101    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    62102
    63103#ifdef WOLFSSL_ASYNC_CRYPT
     
    66106
    67107enum {
    68     AES_ENC_TYPE   = 1,   /* cipher unique type */
     108    AES_ENC_TYPE   = WC_CIPHER_AES,   /* cipher unique type */
    69109    AES_ENCRYPTION = 0,
    70110    AES_DECRYPTION = 1,
     111
     112    AES_BLOCK_SIZE      = 16,
     113
    71114    KEYWRAP_BLOCK_SIZE = 8,
    72     AES_BLOCK_SIZE = 16
     115
     116    GCM_NONCE_MAX_SZ = 16, /* wolfCrypt's maximum nonce size allowed. */
     117    GCM_NONCE_MID_SZ = 12, /* The usual default nonce size for AES-GCM. */
     118    GCM_NONCE_MIN_SZ = 8,  /* wolfCrypt's minimum nonce size allowed. */
     119    CCM_NONCE_MIN_SZ = 7,
     120    CCM_NONCE_MAX_SZ = 13,
     121    CTR_SZ   = 4,
     122    AES_IV_FIXED_SZ = 4,
     123
     124#ifdef HAVE_PKCS11
     125    AES_MAX_ID_LEN   = 32,
     126#endif
    73127};
    74128
     
    83137    ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)];      /* same         */
    84138
     139#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
     140    word32 invokeCtr[2];
     141    word32 nonceSz;
     142#endif
    85143#ifdef HAVE_AESGCM
    86144    ALIGN16 byte H[AES_BLOCK_SIZE];
     
    93151    byte use_aesni;
    94152#endif /* WOLFSSL_AESNI */
     153#ifdef WOLF_CRYPTO_DEV
     154    int   devId;
     155#endif
     156#ifdef HAVE_PKCS11
     157    byte id[AES_MAX_ID_LEN];
     158    int  idLen;
     159#endif
    95160#ifdef WOLFSSL_ASYNC_CRYPT
    96161    word32 asyncKey[AES_MAX_KEY_SIZE/8/sizeof(word32)]; /* raw key */
     
    98163    WC_ASYNC_DEV asyncDev;
    99164#endif /* WOLFSSL_ASYNC_CRYPT */
    100 #ifdef WOLFSSL_AES_COUNTER
     165#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB)
    101166    word32  left;            /* unused bytes left from last call */
    102167#endif
     
    106171    word32      key_init[8];
    107172    word32      kup;
     173#endif
     174#ifdef WOLFSSL_AFALG
     175    int alFd; /* server socket to bind to */
     176    int rdFd; /* socket to read from */
     177    struct msghdr msg;
     178    int dir;  /* flag for encrpyt or decrypt */
     179#endif
     180#if defined(WOLFSSL_DEVCRYPTO) && \
     181    (defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC))
     182    word32       devKey[AES_MAX_KEY_SIZE/WOLFSSL_BIT_SIZE/sizeof(word32)]; /* raw key */
     183    WC_CRYPTODEV ctx;
    108184#endif
    109185    void*  heap; /* memory hint to use */
     
    141217                              const byte* iv, int dir);
    142218WOLFSSL_API int  wc_AesSetIV(Aes* aes, const byte* iv);
     219
     220#ifdef HAVE_AES_CBC
    143221WOLFSSL_API int  wc_AesCbcEncrypt(Aes* aes, byte* out,
    144222                                  const byte* in, word32 sz);
    145223WOLFSSL_API int  wc_AesCbcDecrypt(Aes* aes, byte* out,
    146224                                  const byte* in, word32 sz);
     225#endif
     226
     227#ifdef WOLFSSL_AES_CFB
     228WOLFSSL_API int wc_AesCfbEncrypt(Aes* aes, byte* out,
     229                                    const byte* in, word32 sz);
     230#ifdef HAVE_AES_DECRYPT
     231WOLFSSL_API int wc_AesCfbDecrypt(Aes* aes, byte* out,
     232                                    const byte* in, word32 sz);
     233#endif /* HAVE_AES_DECRYPT */
     234#endif /* WOLFSSL_AES_CFB */
    147235
    148236#ifdef HAVE_AES_ECB
     
    165253                                const byte* iv, int dir);
    166254#endif
     255
    167256#ifdef HAVE_AESGCM
    168257#ifdef WOLFSSL_XILINX_CRYPT
     
    182271                                   const byte* authIn, word32 authInSz);
    183272
     273#ifndef WC_NO_RNG
     274 WOLFSSL_API int  wc_AesGcmSetExtIV(Aes* aes, const byte* iv, word32 ivSz);
     275 WOLFSSL_API int  wc_AesGcmSetIV(Aes* aes, word32 ivSz,
     276                                   const byte* ivFixed, word32 ivFixedSz,
     277                                   WC_RNG* rng);
     278 WOLFSSL_API int  wc_AesGcmEncrypt_ex(Aes* aes, byte* out,
     279                                   const byte* in, word32 sz,
     280                                   byte* ivOut, word32 ivOutSz,
     281                                   byte* authTag, word32 authTagSz,
     282                                   const byte* authIn, word32 authInSz);
     283#endif /* WC_NO_RNG */
     284
    184285 WOLFSSL_API int wc_GmacSetKey(Gmac* gmac, const byte* key, word32 len);
    185286 WOLFSSL_API int wc_GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz,
    186287                               const byte* authIn, word32 authInSz,
    187288                               byte* authTag, word32 authTagSz);
     289#ifndef WC_NO_RNG
     290 WOLFSSL_API int wc_Gmac(const byte* key, word32 keySz, byte* iv, word32 ivSz,
     291                               const byte* authIn, word32 authInSz,
     292                               byte* authTag, word32 authTagSz, WC_RNG* rng);
     293 WOLFSSL_API int wc_GmacVerify(const byte* key, word32 keySz,
     294                               const byte* iv, word32 ivSz,
     295                               const byte* authIn, word32 authInSz,
     296                               const byte* authTag, word32 authTagSz);
     297#endif /* WC_NO_RNG */
    188298 WOLFSSL_LOCAL void GHASH(Aes* aes, const byte* a, word32 aSz, const byte* c,
    189299                               word32 cSz, byte* s, word32 sSz);
     
    200310                                   const byte* nonce, word32 nonceSz,
    201311                                   const byte* authTag, word32 authTagSz,
     312                                   const byte* authIn, word32 authInSz);
     313 WOLFSSL_API int  wc_AesCcmSetNonce(Aes* aes,
     314                                   const byte* nonce, word32 nonceSz);
     315 WOLFSSL_API int  wc_AesCcmEncrypt_ex(Aes* aes, byte* out,
     316                                   const byte* in, word32 sz,
     317                                   byte* ivOut, word32 ivOutSz,
     318                                   byte* authTag, word32 authTagSz,
    202319                                   const byte* authIn, word32 authInSz);
    203320#endif /* HAVE_AESCCM */
     
    214331
    215332#ifdef WOLFSSL_AES_XTS
    216 /*!
    217     \ingroup AES
    218 
    219     \brief This is to help with setting keys to correct encrypt or decrypt type.
    220 
    221     \note Is up to user to call wc_AesXtsFree on aes key when done.
    222 
    223     \return 0 Success
    224 
    225     \param aes   AES keys for encrypt/decrypt process
    226     \param key   buffer holding aes key | tweak key
    227     \param len   length of key buffer in bytes. Should be twice that of key size.
    228                  i.e. 32 for a 16 byte key.
    229     \param dir   direction, either AES_ENCRYPTION or AES_DECRYPTION
    230     \param heap  heap hint to use for memory. Can be NULL
    231     \param devId id to use with async crypto. Can be 0
    232 
    233     _Example_
    234     \code
    235     XtsAes aes;
    236 
    237     if(wc_AesXtsSetKey(&aes, key, sizeof(key), AES_ENCRYPTION, NULL, 0) != 0)
    238     {
    239         // Handle error
    240     }
    241     wc_AesXtsFree(&aes);
    242     \endcode
    243 
    244     \sa wc_AesXtsEncrypt
    245     \sa wc_AesXtsDecrypt
    246     \sa wc_AesXtsFree
    247 */
     333
    248334WOLFSSL_API int wc_AesXtsSetKey(XtsAes* aes, const byte* key,
    249335         word32 len, int dir, void* heap, int devId);
    250336
    251 
    252 /*!
    253     \ingroup AES
    254 
    255     \brief Same process as wc_AesXtsEncrypt but uses a word64 type as the tweak
    256            value instead of a byte array. This just converts the word64 to a
    257            byte array and calls wc_AesXtsEncrypt.
    258 
    259     \return 0 Success
    260 
    261     \param aes    AES keys to use for block encrypt/decrypt
    262     \param out    output buffer to hold cipher text
    263     \param in     input plain text buffer to encrypt
    264     \param sz     size of both out and in buffers
    265     \param sector value to use for tweak
    266 
    267     _Example_
    268     \code
    269     XtsAes aes;
    270     unsigned char plain[SIZE];
    271     unsigned char cipher[SIZE];
    272     word64 s = VALUE;
    273 
    274     //set up keys with AES_ENCRYPTION as dir
    275 
    276     if(wc_AesXtsEncryptSector(&aes, cipher, plain, SIZE, s) != 0)
    277     {
    278         // Handle error
    279     }
    280     wc_AesXtsFree(&aes);
    281     \endcode
    282 
    283     \sa wc_AesXtsEncrypt
    284     \sa wc_AesXtsDecrypt
    285     \sa wc_AesXtsSetKey
    286     \sa wc_AesXtsFree
    287 */
    288337WOLFSSL_API int wc_AesXtsEncryptSector(XtsAes* aes, byte* out,
    289338         const byte* in, word32 sz, word64 sector);
    290339
    291 
    292 /*!
    293     \ingroup AES
    294 
    295     \brief Same process as wc_AesXtsDecrypt but uses a word64 type as the tweak
    296            value instead of a byte array. This just converts the word64 to a
    297            byte array.
    298 
    299     \return 0 Success
    300 
    301     \param aes    AES keys to use for block encrypt/decrypt
    302     \param out    output buffer to hold plain text
    303     \param in     input cipher text buffer to decrypt
    304     \param sz     size of both out and in buffers
    305     \param sector value to use for tweak
    306 
    307     _Example_
    308     \code
    309     XtsAes aes;
    310     unsigned char plain[SIZE];
    311     unsigned char cipher[SIZE];
    312     word64 s = VALUE;
    313 
    314     //set up aes key with AES_DECRYPTION as dir and tweak with AES_ENCRYPTION
    315 
    316     if(wc_AesXtsDecryptSector(&aes, plain, cipher, SIZE, s) != 0)
    317     {
    318         // Handle error
    319     }
    320     wc_AesXtsFree(&aes);
    321     \endcode
    322 
    323     \sa wc_AesXtsEncrypt
    324     \sa wc_AesXtsDecrypt
    325     \sa wc_AesXtsSetKey
    326     \sa wc_AesXtsFree
    327 */
    328340WOLFSSL_API int wc_AesXtsDecryptSector(XtsAes* aes, byte* out,
    329341         const byte* in, word32 sz, word64 sector);
    330342
    331 
    332 /*!
    333     \ingroup AES
    334 
    335     \brief AES with XTS mode. (XTS) XEX encryption with Tweak and cipher text
    336            Stealing.
    337 
    338     \return 0 Success
    339 
    340     \param aes   AES keys to use for block encrypt/decrypt
    341     \param out   output buffer to hold cipher text
    342     \param in    input plain text buffer to encrypt
    343     \param sz    size of both out and in buffers
    344     \param i     value to use for tweak
    345     \param iSz   size of i buffer, should always be AES_BLOCK_SIZE but having
    346                  this input adds a sanity check on how the user calls the
    347                  function.
    348 
    349     _Example_
    350     \code
    351     XtsAes aes;
    352     unsigned char plain[SIZE];
    353     unsigned char cipher[SIZE];
    354     unsigned char i[AES_BLOCK_SIZE];
    355 
    356     //set up key with AES_ENCRYPTION as dir
    357 
    358     if(wc_AesXtsEncrypt(&aes, cipher, plain, SIZE, i, sizeof(i)) != 0)
    359     {
    360         // Handle error
    361     }
    362     wc_AesXtsFree(&aes);
    363     \endcode
    364 
    365     \sa wc_AesXtsDecrypt
    366     \sa wc_AesXtsSetKey
    367     \sa wc_AesXtsFree
    368 */
    369343WOLFSSL_API int wc_AesXtsEncrypt(XtsAes* aes, byte* out,
    370344         const byte* in, word32 sz, const byte* i, word32 iSz);
    371345
    372 
    373 /*!
    374     \ingroup AES
    375 
    376     \brief Same process as encryption but Aes key is AES_DECRYPTION type.
    377 
    378     \return 0 Success
    379 
    380     \param aes   AES keys to use for block encrypt/decrypt
    381     \param out   output buffer to hold plain text
    382     \param in    input cipher text buffer to decrypt
    383     \param sz    size of both out and in buffers
    384     \param i     value to use for tweak
    385     \param iSz   size of i buffer, should always be AES_BLOCK_SIZE but having
    386                  this input adds a sanity check on how the user calls the
    387                  function.
    388     _Example_
    389     \code
    390     XtsAes aes;
    391     unsigned char plain[SIZE];
    392     unsigned char cipher[SIZE];
    393     unsigned char i[AES_BLOCK_SIZE];
    394 
    395     //set up key with AES_DECRYPTION as dir and tweak with AES_ENCRYPTION
    396 
    397     if(wc_AesXtsDecrypt(&aes, plain, cipher, SIZE, i, sizeof(i)) != 0)
    398     {
    399         // Handle error
    400     }
    401     wc_AesXtsFree(&aes);
    402     \endcode
    403 
    404     \sa wc_AesXtsEncrypt
    405     \sa wc_AesXtsSetKey
    406     \sa wc_AesXtsFree
    407 */
    408346WOLFSSL_API int wc_AesXtsDecrypt(XtsAes* aes, byte* out,
    409347        const byte* in, word32 sz, const byte* i, word32 iSz);
    410348
    411 
    412 /*!
    413     \ingroup AES
    414 
    415     \brief This is to free up any resources used by the XtsAes structure
    416 
    417     \return 0 Success
    418 
    419     \param aes AES keys to free
    420 
    421     _Example_
    422     \code
    423     XtsAes aes;
    424 
    425     if(wc_AesXtsSetKey(&aes, key, sizeof(key), AES_ENCRYPTION, NULL, 0) != 0)
    426     {
    427         // Handle error
    428     }
    429     wc_AesXtsFree(&aes);
    430     \endcode
    431 
    432     \sa wc_AesXtsEncrypt
    433     \sa wc_AesXtsDecrypt
    434     \sa wc_AesXtsSetKey
    435 */
    436349WOLFSSL_API int wc_AesXtsFree(XtsAes* aes);
    437350#endif
     
    439352WOLFSSL_API int wc_AesGetKeySize(Aes* aes, word32* keySize);
    440353
    441 WOLFSSL_API int  wc_AesInit(Aes*, void*, int);
    442 WOLFSSL_API void wc_AesFree(Aes*);
     354WOLFSSL_API int  wc_AesInit(Aes* aes, void* heap, int devId);
     355#ifdef HAVE_PKCS11
     356WOLFSSL_API int  wc_AesInit_Id(Aes* aes, unsigned char* id, int len, void* heap,
     357        int devId);
     358#endif
     359WOLFSSL_API void wc_AesFree(Aes* aes);
    443360
    444361#ifdef __cplusplus
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/arc4.h

    r352 r372  
    2020 */
    2121
    22 
     22/*!
     23    \file wolfssl/wolfcrypt/arc4.h
     24*/
    2325
    2426#ifndef WOLF_CRYPT_ARC4_H
     
    3739enum {
    3840        ARC4_ENC_TYPE   = 4,    /* cipher unique type */
    39     ARC4_STATE_SIZE = 256
     41    ARC4_STATE_SIZE = 256,
     42    RC4_KEY_SIZE    = 16,   /* always 128bit           */
    4043};
    4144
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/asn.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/asn.h
     24*/
    2225
    2326#ifndef WOLF_CRYPT_ASN_H
     
    2831#ifndef NO_ASN
    2932
     33
     34#if !defined(NO_ASN_TIME) && defined(NO_TIME_H)
     35    #define NO_ASN_TIME /* backwards compatibility with NO_TIME_H */
     36#endif
     37
    3038#include <wolfssl/wolfcrypt/integer.h>
    3139
    3240/* fips declare of RsaPrivateKeyDecode @wc_fips */
    33 #if defined(HAVE_FIPS) && !defined(NO_RSA)
     41#if defined(HAVE_FIPS) && !defined(NO_RSA) && \
     42        (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
    3443    #include <cyassl/ctaocrypt/rsa.h>
    3544#endif
     
    5059#include <wolfssl/wolfcrypt/asn_public.h>   /* public interface */
    5160
     61#if defined(NO_SHA) && defined(NO_SHA256)
     62    #define WC_SHA256_DIGEST_SIZE 32
     63#endif
    5264
    5365#ifdef __cplusplus
     
    7789    ASN_SEQUENCE          = 0x10,
    7890    ASN_SET               = 0x11,
     91    ASN_PRINTABLE_STRING  = 0x13,
    7992    ASN_UTC_TIME          = 0x17,
    8093    ASN_OTHER_TYPE        = 0x00,
     
    8295    ASN_DNS_TYPE          = 0x02,
    8396    ASN_DIR_TYPE          = 0x04,
     97    ASN_URI_TYPE          = 0x06, /* the value 6 is from GeneralName OID */
    8498    ASN_GENERALIZED_TIME  = 0x18,
    8599    CRL_EXTENSIONS        = 0xa0,
    86100    ASN_EXTENSIONS        = 0xa3,
    87     ASN_LONG_LENGTH       = 0x80
    88 };
    89 
    90 enum ASN_Flags {
     101    ASN_LONG_LENGTH       = 0x80,
     102    ASN_INDEF_LENGTH      = 0x80,
     103
     104    /* ASN_Flags - Bitmask */
    91105    ASN_CONSTRUCTED       = 0x20,
    92     ASN_CONTEXT_SPECIFIC  = 0x80
    93 };
     106    ASN_APPLICATION       = 0x40,
     107    ASN_CONTEXT_SPECIFIC  = 0x80,
     108};
     109
     110#define ASN_UTC_TIME_SIZE 14
     111#define ASN_GENERALIZED_TIME_SIZE 16
     112#define ASN_GENERALIZED_TIME_MAX 68
    94113
    95114enum DN_Tags {
     
    101120    ASN_STATE_NAME    = 0x08,   /* ST */
    102121    ASN_ORG_NAME      = 0x0a,   /* O  */
    103     ASN_ORGUNIT_NAME  = 0x0b    /* OU */
    104 };
    105 
    106 enum PBES {
    107     PBE_MD5_DES      = 0,
    108     PBE_SHA1_DES     = 1,
    109     PBE_SHA1_DES3    = 2,
    110     PBE_SHA1_RC4_128 = 3,
    111     PBES2            = 13       /* algo ID */
    112 };
    113 
    114 enum ENCRYPTION_TYPES {
    115     DES_TYPE  = 0,
    116     DES3_TYPE = 1,
    117     RC4_TYPE  = 2
    118 };
    119 
    120 enum ECC_TYPES {
     122    ASN_ORGUNIT_NAME  = 0x0b,   /* OU */
     123    ASN_BUS_CAT       = 0x0f,   /* businessCategory */
     124    ASN_EMAIL_NAME    = 0x98,   /* not oid number there is 97 in 2.5.4.0-97 */
     125
     126    /* pilot attribute types
     127     * OID values of 0.9.2342.19200300.100.1.* */
     128    ASN_USER_ID          = 0x01, /* UID */
     129    ASN_DOMAIN_COMPONENT = 0x19  /* DC */
     130};
     131
     132/* DN Tag Strings */
     133#define WOLFSSL_COMMON_NAME      "/CN="
     134#define WOLFSSL_SUR_NAME         "/SN="
     135#define WOLFSSL_SERIAL_NUMBER    "/serialNumber="
     136#define WOLFSSL_COUNTRY_NAME     "/C="
     137#define WOLFSSL_LOCALITY_NAME    "/L="
     138#define WOLFSSL_STATE_NAME       "/ST="
     139#define WOLFSSL_ORG_NAME         "/O="
     140#define WOLFSSL_ORGUNIT_NAME     "/OU="
     141#define WOLFSSL_DOMAIN_COMPONENT "/DC="
     142#define WOLFSSL_BUS_CAT          "/businessCategory="
     143#define WOLFSSL_JOI_C            "/jurisdictionC="
     144#define WOLFSSL_JOI_ST           "/jurisdictionST="
     145#define WOLFSSL_EMAIL_ADDR       "/emailAddress="
     146
     147/* NIDs */
     148enum
     149{
     150    NID_undef = 0,
     151    NID_des = 66,
     152    NID_des3 = 67,
     153    NID_sha256 = 672,
     154    NID_sha384 = 673,
     155    NID_sha512 = 674,
     156    NID_hw_name_oid = 73,
     157    NID_id_pkix_OCSP_basic = 74,
     158    NID_any_policy = 75,
     159    NID_anyExtendedKeyUsage = 76,
     160    NID_basic_constraints = 133,
     161    NID_key_usage = 129,     /* 2.5.29.15 */
     162    NID_ext_key_usage = 151, /* 2.5.29.37 */
     163    NID_subject_key_identifier = 128,
     164    NID_authority_key_identifier = 149,
     165    NID_private_key_usage_period = 130, /* 2.5.29.16 */
     166    NID_subject_alt_name = 131,
     167    NID_issuer_alt_name = 132,
     168    NID_info_access = 69,
     169    NID_sinfo_access = 79,      /* id-pe 11 */
     170    NID_name_constraints = 144, /* 2.5.29.30 */
     171    NID_certificate_policies = 146,
     172    NID_policy_mappings = 147,
     173    NID_policy_constraints = 150,
     174    NID_inhibit_any_policy = 168,      /* 2.5.29.54 */
     175    NID_tlsfeature = 92,               /* id-pe 24 */
     176    NID_commonName = 0x03,             /* matchs ASN_COMMON_NAME in asn.h */
     177    NID_surname = 0x04,                /* SN */
     178    NID_serialNumber = 0x05,           /* serialNumber */
     179    NID_countryName = 0x06,            /* C  */
     180    NID_localityName = 0x07,           /* L  */
     181    NID_stateOrProvinceName = 0x08,    /* ST */
     182    NID_organizationName = 0x0a,       /* O  */
     183    NID_organizationalUnitName = 0x0b, /* OU */
     184    NID_domainComponent = 0x19,        /* matchs ASN_DOMAIN_COMPONENT in asn.h */
     185    NID_emailAddress = 0x30,           /* emailAddress */
     186};
     187
     188enum ECC_TYPES
     189{
    121190    ECC_PREFIX_0 = 160,
    122191    ECC_PREFIX_1 = 161
    123192};
    124193
     194#ifdef WOLFSSL_CERT_PIV
     195    enum PIV_Tags {
     196        ASN_PIV_CERT          = 0x0A,
     197        ASN_PIV_NONCE         = 0x0B,
     198        ASN_PIV_SIGNED_NONCE  = 0x0C,
     199           
     200        ASN_PIV_TAG_CERT      = 0x70,
     201        ASN_PIV_TAG_CERT_INFO = 0x71,
     202        ASN_PIV_TAG_MSCUID    = 0x72,
     203        ASN_PIV_TAG_ERR_DET   = 0xFE,
     204           
     205        /* certificate info masks */
     206        ASN_PIV_CERT_INFO_COMPRESSED = 0x03,
     207        ASN_PIV_CERT_INFO_ISX509     = 0x04,
     208    };
     209#endif /* WOLFSSL_CERT_PIV */
     210
     211
     212#define ASN_JOI_PREFIX "\x2b\x06\x01\x04\x01\x82\x37\x3c\x02\x01"
     213#define ASN_JOI_C      0x3
     214#define ASN_JOI_ST     0x2
     215
     216#ifndef WC_ASN_NAME_MAX
     217    #define WC_ASN_NAME_MAX 256
     218#endif
     219
    125220enum Misc_ASN {
    126     ASN_NAME_MAX        = 256,
     221    ASN_NAME_MAX        = WC_ASN_NAME_MAX,
    127222    MAX_SALT_SIZE       =  64,     /* MAX PKCS Salt length */
    128223    MAX_IV_SIZE         =  64,     /* MAX PKCS Iv length */
    129     MAX_KEY_SIZE        =  64,     /* MAX PKCS Key  length */
    130     PKCS5               =   5,     /* PKCS oid tag */
    131     PKCS5v2             =   6,     /* PKCS #5 v2.0 */
    132     PKCS8v0             =   0,     /* default PKCS#8 version */
    133     PKCS12v1            =  12,     /* PKCS #12 */
    134     MAX_UNICODE_SZ      = 256,
    135224    ASN_BOOL_SIZE       =   2,     /* including type */
    136225    ASN_ECC_HEADER_SZ   =   2,     /* String type + 1 byte len */
     
    146235    MAX_DATE_SIZE       =  32,
    147236    ASN_GEN_TIME_SZ     =  15,     /* 7 numbers * 2 + Zulu tag */
     237#ifndef NO_RSA
    148238    MAX_ENCODED_SIG_SZ  = 512,
     239#elif defined(HAVE_ECC)
     240    MAX_ENCODED_SIG_SZ  = 140,
     241#else
     242    MAX_ENCODED_SIG_SZ  =  64,
     243#endif
    149244    MAX_SIG_SZ          = 256,
    150245    MAX_ALGO_SZ         =  20,
     246    MAX_SHORT_SZ        =   6,     /* asn int + byte len + 4 byte length */
    151247    MAX_SEQ_SZ          =   5,     /* enum(seq | con) + length(4) */
    152248    MAX_SET_SZ          =   5,     /* enum(set | con) + length(4) */
     
    155251    MAX_PRSTR_SZ        =   5,     /* enum(prstr) + length(4) */
    156252    MAX_VERSION_SZ      =   5,     /* enum + id + version(byte) + (header(2))*/
    157     MAX_ENCODED_DIG_SZ  =  73,     /* sha512 + enum(bit or octet) + length(4) */
     253    MAX_ENCODED_DIG_ASN_SZ= 9,     /* enum(bit or octet) + length(4) */
     254    MAX_ENCODED_DIG_SZ  =  64 + MAX_ENCODED_DIG_ASN_SZ, /* asn header + sha512 */
    158255    MAX_RSA_INT_SZ      = 517,     /* RSA raw sz 4096 for bits + tag + len(4) */
    159256    MAX_NTRU_KEY_SZ     = 610,     /* NTRU 112 bit public key */
     
    163260    MAX_CA_SZ           =  32,     /* Max encoded CA basic constraint length */
    164261    MAX_SN_SZ           =  35,     /* Max encoded serial number (INT) length */
    165     MAX_DER_DIGEST_SZ   = MAX_ENCODED_DIG_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ, /* Maximum DER digest size */
     262    MAX_DER_DIGEST_SZ     = MAX_ENCODED_DIG_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ,
     263                            /* Maximum DER digest size */
     264    MAX_DER_DIGEST_ASN_SZ = MAX_ENCODED_DIG_ASN_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ,
     265                            /* Maximum DER digest ASN header size */
    166266#ifdef WOLFSSL_CERT_GEN
    167267    #ifdef WOLFSSL_CERT_REQ
     
    177277                                   /* Max total extensions, id + len + others */
    178278#endif
     279#if defined(WOLFSSL_CERT_EXT) || defined(OPENSSL_EXTRA) || defined(HAVE_PKCS7)
     280    MAX_OID_SZ          = 32,      /* Max DER length of OID*/
     281    MAX_OID_STRING_SZ   = 64,      /* Max string length representation of OID*/
     282#endif
    179283#ifdef WOLFSSL_CERT_EXT
    180284    MAX_KID_SZ                  = 45,      /* Max encoded KID length (SHA-256 case) */
    181285    MAX_KEYUSAGE_SZ     = 18,      /* Max encoded Key Usage length */
    182     MAX_EXTKEYUSAGE_SZ  = 12 + (6 * (8 + 2)), /* Max encoded ExtKeyUsage
    183                         (SEQ/LEN + OBJID + OCTSTR/LEN + SEQ + (6 * (SEQ + OID))) */
    184     MAX_OID_SZ          = 32,      /* Max DER length of OID*/
    185     MAX_OID_STRING_SZ   = 64,      /* Max string length representation of OID*/
     286    MAX_EXTKEYUSAGE_SZ  = 12 + (6 * (8 + 2)) +
     287                          CTC_MAX_EKU_OID_SZ, /* Max encoded ExtKeyUsage
     288                          (SEQ/LEN + OBJID + OCTSTR/LEN + SEQ +
     289                          (6 * (SEQ + OID))) */
    186290    MAX_CERTPOL_NB      = CTC_MAX_CERTPOL_NB,/* Max number of Cert Policy */
    187291    MAX_CERTPOL_SZ      = CTC_MAX_CERTPOL_SZ,
    188292#endif
     293    MAX_NAME_ENTRIES    = 5,       /* extra entries added to x509 name struct */
    189294    OCSP_NONCE_EXT_SZ   = 35,      /* OCSP Nonce Extension size */
    190295    MAX_OCSP_EXT_SZ     = 58,      /* Max OCSP Extension length */
     
    193298    MAX_PUBLIC_KEY_SZ   = MAX_NTRU_ENC_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ * 2,
    194299                                   /* use bigger NTRU size */
     300#ifdef WOLFSSL_ENCRYPTED_KEYS
    195301    HEADER_ENCRYPTED_KEY_SIZE = 88,/* Extra header size for encrypted key */
     302#else
     303    HEADER_ENCRYPTED_KEY_SIZE = 0,
     304#endif
    196305    TRAILING_ZERO       = 1,       /* Used for size of zero pad */
     306    ASN_TAG_SZ          = 1,       /* single byte ASN.1 tag */
    197307    MIN_VERSION_SZ      = 3,       /* Min bytes needed for GetMyVersion */
    198 #if defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
     308#if defined(OPENSSL_ALL)  || defined(WOLFSSL_MYSQL_COMPATIBLE) || \
     309    defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
     310    defined(OPENSSL_EXTRA) || defined(HAVE_PKCS7)
    199311    MAX_TIME_STRING_SZ  = 25,      /* Max length of formatted time string */
    200312#endif
     313
     314    PKCS5_SALT_SZ       = 8,
     315
     316    PEM_LINE_LEN       = 80,       /* PEM line max + fudge */
    201317};
    202318
     
    217333    oidKeyWrapType      = 12,
    218334    oidCmsKeyAgreeType  = 13,
     335    oidPBEType          = 14,
     336    oidHmacType         = 15,
     337    oidCompressType     = 16,
     338    oidCertNameType     = 17,
    219339    oidIgnoreType
    220340};
     
    232352
    233353
     354#if !defined(NO_DES3) || !defined(NO_AES)
    234355enum Block_Sum {
     356#ifdef WOLFSSL_AES_128
    235357    AES128CBCb = 414,
     358    AES128GCMb = 418,
     359    AES128CCMb = 419,
     360#endif
     361#ifdef WOLFSSL_AES_192
    236362    AES192CBCb = 434,
     363    AES192GCMb = 438,
     364    AES192CCMb = 439,
     365#endif
     366#ifdef WOLFSSL_AES_256
    237367    AES256CBCb = 454,
     368    AES256GCMb = 458,
     369    AES256CCMb = 459,
     370#endif
     371#ifndef NO_DES3
    238372    DESb       = 69,
    239373    DES3b      = 652
    240 };
     374#endif
     375};
     376#endif /* !NO_DES3 || !NO_AES */
    241377
    242378
     
    250386
    251387
     388#if !defined(NO_AES) || defined(HAVE_PKCS7)
    252389enum KeyWrap_Sum {
     390#ifdef WOLFSSL_AES_128
    253391    AES128_WRAP = 417,
     392#endif
     393#ifdef WOLFSSL_AES_192
    254394    AES192_WRAP = 437,
    255     AES256_WRAP = 457
    256 };
    257 
     395#endif
     396#ifdef WOLFSSL_AES_256
     397    AES256_WRAP  = 457,
     398#endif
     399#ifdef HAVE_PKCS7
     400    PWRI_KEK_WRAP = 680  /*id-alg-PWRI-KEK, 1.2.840.113549.1.9.16.3.9 */
     401#endif
     402};
     403#endif /* !NO_AES || PKCS7 */
    258404
    259405enum Key_Agree {
     
    304450
    305451
     452enum HMAC_Sum {
     453    HMAC_SHA224_OID = 652,
     454    HMAC_SHA256_OID = 653,
     455    HMAC_SHA384_OID = 654,
     456    HMAC_SHA512_OID = 655
     457};
     458
     459
    306460enum Extensions_Sum {
    307461    BASIC_CA_OID    = 133,
     
    347501};
    348502
     503#ifdef HAVE_LIBZ
     504enum CompressAlg_Sum {
     505    ZLIBc = 679  /* 1.2.840.113549.1.9.16.3.8, id-alg-zlibCompress */
     506};
     507#endif
    349508
    350509enum VerifyType {
     
    352511    VERIFY      = 1,
    353512    VERIFY_CRL  = 2,
    354     VERIFY_OCSP = 3
     513    VERIFY_OCSP = 3,
     514    VERIFY_NAME = 4
    355515};
    356516
     
    374534
    375535/* Extended Key Usage bits (internal mapping only) */
     536#define EXTKEYUSE_USER        0x80
    376537#define EXTKEYUSE_OCSP_SIGN   0x40
    377538#define EXTKEYUSE_TIMESTAMP   0x20
     
    386547struct DNS_entry {
    387548    DNS_entry* next;   /* next on DNS list */
     549    int        type;   /* i.e. ASN_DNS_TYPE */
     550    int        len;    /* actual DNS len */
    388551    char*      name;   /* actual DNS name */
    389552};
     
    399562};
    400563
     564#define DOMAIN_COMPONENT_MAX 10
    401565
    402566struct DecodedName {
     
    406570    int     cnIdx;
    407571    int     cnLen;
     572    int     cnNid;
    408573    int     snIdx;
    409574    int     snLen;
     575    int     snNid;
    410576    int     cIdx;
    411577    int     cLen;
     578    int     cNid;
    412579    int     lIdx;
    413580    int     lLen;
     581    int     lNid;
    414582    int     stIdx;
    415583    int     stLen;
     584    int     stNid;
    416585    int     oIdx;
    417586    int     oLen;
     587    int     oNid;
    418588    int     ouIdx;
    419589    int     ouLen;
     590#ifdef WOLFSSL_CERT_EXT
     591    int     bcIdx;
     592    int     bcLen;
     593    int     jcIdx;
     594    int     jcLen;
     595    int     jsIdx;
     596    int     jsLen;
     597#endif
     598    int     ouNid;
    420599    int     emailIdx;
    421600    int     emailLen;
     601    int     emailNid;
    422602    int     uidIdx;
    423603    int     uidLen;
     604    int     uidNid;
    424605    int     serialIdx;
    425606    int     serialLen;
     607    int     serialNid;
     608    int     dcIdx[DOMAIN_COMPONENT_MAX];
     609    int     dcLen[DOMAIN_COMPONENT_MAX];
     610    int     dcNum;
     611    int     dcMode;
    426612};
    427613
     
    433619    SIG_STATE_CHECK,
    434620};
     621
     622
     623#ifdef HAVE_PK_CALLBACKS
     624#ifdef HAVE_ECC
     625    typedef int (*wc_CallbackEccVerify)(
     626           const unsigned char* sig, unsigned int sigSz,
     627           const unsigned char* hash, unsigned int hashSz,
     628           const unsigned char* keyDer, unsigned int keySz,
     629           int* result, void* ctx);
     630#endif
     631#ifndef NO_RSA
     632    typedef int (*wc_CallbackRsaVerify)(
     633           unsigned char* sig, unsigned int sigSz,
     634           unsigned char** out,
     635           const unsigned char* keyDer, unsigned int keySz,
     636           void* ctx);
     637#endif
     638#endif /* HAVE_PK_CALLBACKS */
    435639
    436640struct SignatureCtx {
     
    465669    void* asyncCtx;
    466670#endif
     671
     672#ifdef HAVE_PK_CALLBACKS
     673#ifdef HAVE_ECC
     674    wc_CallbackEccVerify pkCbEcc;
     675    void* pkCtxEcc;
     676#endif
     677#ifndef NO_RSA
     678    wc_CallbackRsaVerify pkCbRsa;
     679    void* pkCtxRsa;
     680#endif
     681#endif /* HAVE_PK_CALLBACKS */
    467682};
    468683
     
    496711
    497712struct DecodedCert {
    498     byte*  publicKey;
     713    const byte* publicKey;
    499714    word32  pubKeySize;
    500715    int     pubKeyStored;
     
    516731    byte    issuerKeyHash[KEYID_SIZE]; /* hash of the public Key         */
    517732#endif /* HAVE_OCSP */
    518     byte*   signature;               /* not owned, points into raw cert  */
     733    const byte* signature;           /* not owned, points into raw cert  */
    519734    char*   subjectCN;               /* CommonName                       */
    520735    int     subjectCNLen;            /* CommonName Length                */
    521736    char    subjectCNEnc;            /* CommonName Encoding              */
    522     int     subjectCNStored;         /* have we saved a copy we own      */
    523737    char    issuer[ASN_NAME_MAX];    /* full name including common name  */
    524738    char    subject[ASN_NAME_MAX];   /* full name including common name  */
    525739    int     verify;                  /* Default to yes, but could be off */
    526     byte*   source;                  /* byte buffer holder cert, NOT owner */
     740    const byte* source;              /* byte buffer holder cert, NOT owner */
    527741    word32  srcIdx;                  /* current offset into buffer       */
    528742    word32  maxIdx;                  /* max offset based on init size    */
     
    530744    byte    serial[EXTERNAL_SERIAL_SIZE];  /* raw serial number          */
    531745    int     serialSz;                /* raw serial bytes stored */
    532     byte*   extensions;              /* not owned, points into raw cert  */
     746    const byte* extensions;          /* not owned, points into raw cert  */
    533747    int     extensionsSz;            /* length of cert extensions */
    534748    word32  extensionsIdx;           /* if want to go back and parse later */
    535     byte*   extAuthInfo;             /* Authority Information Access URI */
     749    const byte* extAuthInfo;         /* Authority Information Access URI */
    536750    int     extAuthInfoSz;           /* length of the URI                */
    537     byte*   extCrlInfo;              /* CRL Distribution Points          */
     751    const byte* extCrlInfo;          /* CRL Distribution Points          */
    538752    int     extCrlInfoSz;            /* length of the URI                */
    539753    byte    extSubjKeyId[KEYID_SIZE]; /* Subject Key ID                  */
    540     byte    extSubjKeyIdSet;         /* Set when the SKID was read from cert */
    541754    byte    extAuthKeyId[KEYID_SIZE]; /* Authority Key ID                */
    542     byte    extAuthKeyIdSet;         /* Set when the AKID was read from cert */
    543 #ifndef IGNORE_NAME_CONSTRAINTS
    544     byte    extNameConstraintSet;
    545 #endif /* IGNORE_NAME_CONSTRAINTS */
    546     byte    isCA;                    /* CA basic constraint true         */
    547     byte    pathLengthSet;           /* CA basic const path length set   */
    548755    byte    pathLength;              /* CA basic constraint path length  */
    549     byte    weOwnAltNames;           /* altNames haven't been given to copy */
    550     byte    extKeyUsageSet;
    551756    word16  extKeyUsage;             /* Key usage bitfield               */
    552     byte    extExtKeyUsageSet;       /* Extended Key Usage               */
    553757    byte    extExtKeyUsage;          /* Extended Key usage bitfield      */
    554 #ifdef OPENSSL_EXTRA
    555     byte    extCRLdistSet;
    556     byte    extCRLdistCrit;
    557     byte    extAuthInfoSet;
    558     byte    extAuthInfoCrit;
    559     byte    extBasicConstSet;
    560     byte    extBasicConstCrit;
    561     byte    extSubjAltNameSet;
    562     byte    extSubjAltNameCrit;
    563     byte    extAuthKeyIdCrit;
    564 #ifndef IGNORE_NAME_CONSTRAINTS
    565     byte    extNameConstraintCrit;
    566 #endif /* IGNORE_NAME_CONSTRAINTS */
    567     byte    extSubjKeyIdCrit;
    568     byte    extKeyUsageCrit;
    569     byte    extExtKeyUsageCrit;
    570     byte*   extExtKeyUsageSrc;
     758
     759#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
     760    const byte* extExtKeyUsageSrc;
    571761    word32  extExtKeyUsageSz;
    572762    word32  extExtKeyUsageCount;
    573     byte*  extAuthKeyIdSrc;
     763    const byte* extAuthKeyIdSrc;
    574764    word32  extAuthKeyIdSz;
    575     byte*  extSubjKeyIdSrc;
     765    const byte* extSubjKeyIdSrc;
    576766    word32  extSubjKeyIdSz;
    577767#endif
     768
    578769#if defined(HAVE_ECC) || defined(HAVE_ED25519)
    579770    word32  pkCurveOID;           /* Public Key's curve OID */
    580771#endif /* HAVE_ECC */
    581     byte*  beforeDate;
     772    const byte* beforeDate;
    582773    int     beforeDateLen;
    583     byte*  afterDate;
     774    const byte* afterDate;
    584775    int     afterDateLen;
    585 #ifdef HAVE_PKCS7
    586     byte*   issuerRaw;               /* pointer to issuer inside source */
     776#if defined(HAVE_PKCS7) || defined(WOLFSSL_CERT_EXT)
     777    const byte* issuerRaw;           /* pointer to issuer inside source */
    587778    int     issuerRawLen;
    588779#endif
    589780#ifndef IGNORE_NAME_CONSTRAINT
    590     byte*   subjectRaw;               /* pointer to subject inside source */
     781    const byte* subjectRaw;          /* pointer to subject inside source */
    591782    int     subjectRawLen;
    592783#endif
    593 #if defined(WOLFSSL_CERT_GEN)
     784#if defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_CERT_EXT)
    594785    /* easy access to subject info for other sign */
    595786    char*   subjectSN;
     
    611802    int     subjectOULen;
    612803    char    subjectOUEnc;
     804    char*   subjectSND;
     805    int     subjectSNDLen;
     806    char    subjectSNDEnc;
     807#ifdef WOLFSSL_CERT_EXT
     808    char*   subjectBC;
     809    int     subjectBCLen;
     810    char    subjectBCEnc;
     811    char*   subjectJC;
     812    int     subjectJCLen;
     813    char    subjectJCEnc;
     814    char*   subjectJS;
     815    int     subjectJSLen;
     816    char    subjectJSEnc;
     817#endif
    613818    char*   subjectEmail;
    614819    int     subjectEmailLen;
    615820#endif /* WOLFSSL_CERT_GEN */
    616 #ifdef OPENSSL_EXTRA
     821#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
    617822    DecodedName issuerName;
    618823    DecodedName subjectName;
     
    625830    int     hwSerialNumSz;
    626831    byte*   hwSerialNum;
    627     #ifdef OPENSSL_EXTRA
    628         byte    extCertPolicySet;
    629         byte    extCertPolicyCrit;
    630     #endif /* OPENSSL_EXTRA */
    631832#endif /* WOLFSSL_SEP */
    632833#ifdef WOLFSSL_CERT_EXT
    633834    char    extCertPolicies[MAX_CERTPOL_NB][MAX_CERTPOL_SZ];
    634835    int     extCertPoliciesNb;
    635 #endif /* WOLFSSL_CERT_EXT */
     836#endif /* defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_CERT_EXT) */
    636837
    637838    Signer* ca;
    638839    SignatureCtx sigCtx;
    639 };
    640 
    641 
    642 struct WOLFSSL_ASN1_OBJECT {
    643     void*  heap;
    644     byte*  obj;
    645     int    type; /* oid */
    646     word32 objSz;
    647     byte   dynamic; /* if 1 then obj was dynamiclly created, 0 otherwise */
    648 };
    649 
    650 
    651 extern const char* BEGIN_CERT;
    652 extern const char* END_CERT;
    653 extern const char* BEGIN_CERT_REQ;
    654 extern const char* END_CERT_REQ;
    655 extern const char* BEGIN_DSA_PARAM;
    656 extern const char* END_DSA_PARAM;
    657 extern const char* BEGIN_DH_PARAM;
    658 extern const char* END_DH_PARAM;
    659 extern const char* BEGIN_X509_CRL;
    660 extern const char* END_X509_CRL;
    661 extern const char* BEGIN_RSA_PRIV;
    662 extern const char* END_RSA_PRIV;
    663 extern const char* BEGIN_PRIV_KEY;
    664 extern const char* END_PRIV_KEY;
    665 extern const char* BEGIN_ENC_PRIV_KEY;
    666 extern const char* END_ENC_PRIV_KEY;
    667 extern const char* BEGIN_EC_PRIV;
    668 extern const char* END_EC_PRIV;
    669 extern const char* BEGIN_DSA_PRIV;
    670 extern const char* END_DSA_PRIV;
    671 extern const char* BEGIN_PUB_KEY;
    672 extern const char* END_PUB_KEY;
    673 extern const char* BEGIN_EDDSA_PRIV;
    674 extern const char* END_EDDSA_PRIV;
     840
     841    /* Option Bits */
     842    byte subjectCNStored : 1;      /* have we saved a copy we own */
     843    byte extSubjKeyIdSet : 1;      /* Set when the SKID was read from cert */
     844    byte extAuthKeyIdSet : 1;      /* Set when the AKID was read from cert */
     845#ifndef IGNORE_NAME_CONSTRAINTS
     846    byte extNameConstraintSet : 1;
     847#endif
     848    byte isCA : 1;                 /* CA basic constraint true */
     849    byte pathLengthSet : 1;        /* CA basic const path length set */
     850    byte weOwnAltNames : 1;        /* altNames haven't been given to copy */
     851    byte extKeyUsageSet : 1;
     852    byte extExtKeyUsageSet : 1;    /* Extended Key Usage set */
     853    byte extCRLdistSet : 1;
     854    byte extAuthInfoSet : 1;
     855    byte extBasicConstSet : 1;
     856    byte extSubjAltNameSet : 1;
     857    byte inhibitAnyOidSet : 1;
     858#ifdef WOLFSSL_SEP
     859    byte extCertPolicySet : 1;
     860#endif
     861#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
     862    byte extCRLdistCrit : 1;
     863    byte extAuthInfoCrit : 1;
     864    byte extBasicConstCrit : 1;
     865    byte extSubjAltNameCrit : 1;
     866    byte extAuthKeyIdCrit : 1;
     867    #ifndef IGNORE_NAME_CONSTRAINTS
     868        byte extNameConstraintCrit : 1;
     869    #endif
     870    byte extSubjKeyIdCrit : 1;
     871    byte extKeyUsageCrit : 1;
     872    byte extExtKeyUsageCrit : 1;
     873#endif /* OPENSSL_EXTRA */
     874#ifdef WOLFSSL_SEP
     875    byte extCertPolicyCrit : 1;
     876#endif
     877
     878};
     879
    675880
    676881#ifdef NO_SHA
     
    688893    byte    pathLength;
    689894    byte    pathLengthSet;
    690     byte*  publicKey;
     895    const byte* publicKey;
    691896    int     nameLen;
    692897    char*   name;                    /* common name */
     
    701906                                     /* sha hash of names in certificate */
    702907    #endif
     908#ifdef WOLFSSL_SIGNER_DER_CERT
     909    DerBuffer* derCert;
     910#endif
    703911    Signer* next;
    704912};
     
    728936
    729937/* for testing or custom openssl wrappers */
    730 #if defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA)
     938#if defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
     939    defined(OPENSSL_EXTRA_X509_SMALL)
    731940    #define WOLFSSL_ASN_API WOLFSSL_API
    732941#else
    733942    #define WOLFSSL_ASN_API WOLFSSL_LOCAL
    734943#endif
     944
     945/* Macro for calculating hashId */
     946#if defined(NO_SHA) && defined(NO_SHA256)
     947    #ifdef WOLF_CRYPTO_DEV
     948        #define CalcHashId(data, len, hash) wc_CryptoDevSha256Hash(data, len, hash)
     949    #else
     950        #define CalcHashId(data, len, hash) NOT_COMPILED_IN
     951    #endif
     952#elif defined(NO_SHA)
     953    #define CalcHashId(data, len, hash)     wc_Sha256Hash(data, len, hash)
     954#else
     955    #define CalcHashId(data, len, hash)     wc_ShaHash(data, len, hash)
     956#endif
     957
     958
     959WOLFSSL_ASN_API int wc_BerToDer(const byte* ber, word32 berSz, byte* der,
     960                                word32* derSz);
    735961
    736962WOLFSSL_ASN_API void FreeAltNames(DNS_entry*, void*);
     
    738964    WOLFSSL_ASN_API void FreeNameSubtrees(Base_entry*, void*);
    739965#endif /* IGNORE_NAME_CONSTRAINTS */
    740 WOLFSSL_ASN_API void InitDecodedCert(DecodedCert*, byte*, word32, void*);
     966WOLFSSL_ASN_API void InitDecodedCert(DecodedCert*, const byte*, word32, void*);
    741967WOLFSSL_ASN_API void FreeDecodedCert(DecodedCert*);
    742968WOLFSSL_ASN_API int  ParseCert(DecodedCert*, int type, int verify, void* cm);
    743969
     970WOLFSSL_LOCAL int DecodePolicyOID(char *o, word32 oSz,
     971                                  const byte *in, word32 inSz);
     972WOLFSSL_API int CheckCertSignature(const byte*,word32,void*,void* cm);
    744973WOLFSSL_LOCAL int ParseCertRelative(DecodedCert*,int type,int verify,void* cm);
    745974WOLFSSL_LOCAL int DecodeToKey(DecodedCert*, int verify);
    746975
     976WOLFSSL_LOCAL const byte* OidFromId(word32 id, word32 type, word32* oidSz);
    747977WOLFSSL_LOCAL Signer* MakeSigner(void*);
    748978WOLFSSL_LOCAL void    FreeSigner(Signer*, void*);
     
    754984
    755985WOLFSSL_ASN_API int ToTraditional(byte* buffer, word32 length);
     986WOLFSSL_ASN_API int ToTraditional_ex(byte* buffer, word32 length,
     987                                     word32* algId);
    756988WOLFSSL_LOCAL int ToTraditionalInline(const byte* input, word32* inOutIdx,
    757989                                      word32 length);
    758 WOLFSSL_LOCAL int ToTraditionalEnc(byte* buffer, word32 length,const char*,int);
     990WOLFSSL_LOCAL int ToTraditionalInline_ex(const byte* input, word32* inOutIdx,
     991                                         word32 length, word32* algId);
     992WOLFSSL_LOCAL int ToTraditionalEnc(byte* buffer, word32 length,const char*,int,
     993                                   word32* algId);
     994WOLFSSL_ASN_API int UnTraditionalEnc(byte* key, word32 keySz, byte* out,
     995        word32* outSz, const char* password, int passwordSz, int vPKCS,
     996        int vAlgo, byte* salt, word32 saltSz, int itt, WC_RNG* rng, void* heap);
     997WOLFSSL_ASN_API int TraditionalEnc(byte* key, word32 keySz, byte* out,
     998        word32* outSz, const char* password, int passwordSz, int vPKCS,
     999        int vAlgo, int encAlgId, byte* salt, word32 saltSz, int itt,
     1000        WC_RNG* rng, void* heap);
    7591001WOLFSSL_LOCAL int DecryptContent(byte* input, word32 sz,const char* psw,int pswSz);
     1002WOLFSSL_LOCAL int EncryptContent(byte* input, word32 sz, byte* out, word32* outSz,
     1003        const char* password,int passwordSz, int vPKCS, int vAlgo,
     1004        byte* salt, word32 saltSz, int itt, WC_RNG* rng, void* heap);
    7601005WOLFSSL_LOCAL int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID,
    7611006        word32* oidSz, int* algoID, void* heap);
    7621007
    7631008typedef struct tm wolfssl_tm;
    764 #if defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
     1009#if defined(OPENSSL_ALL) || defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(OPENSSL_EXTRA) || \
     1010    defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
    7651011WOLFSSL_LOCAL int GetTimeString(byte* date, int format, char* buf, int len);
     1012#endif
     1013#if !defined(NO_ASN_TIME) && defined(HAVE_PKCS7)
     1014WOLFSSL_LOCAL int GetAsnTimeString(void* currTime, byte* buf, word32 len);
    7661015#endif
    7671016WOLFSSL_LOCAL int ExtractDate(const unsigned char* date, unsigned char format,
    7681017                                                 wolfssl_tm* certTime, int* idx);
    7691018WOLFSSL_LOCAL int ValidateDate(const byte* date, byte format, int dateType);
     1019WOLFSSL_LOCAL int OBJ_sn2nid(const char *sn);
    7701020
    7711021/* ASN.1 helper functions */
     
    7751025WOLFSSL_LOCAL int GetShortInt(const byte* input, word32* inOutIdx, int* number,
    7761026                              word32 maxIdx);
     1027WOLFSSL_LOCAL char* GetSigName(int oid);
    7771028WOLFSSL_LOCAL int GetLength(const byte* input, word32* inOutIdx, int* len,
    7781029                           word32 maxIdx);
     1030WOLFSSL_LOCAL int GetLength_ex(const byte* input, word32* inOutIdx, int* len,
     1031                           word32 maxIdx, int check);
    7791032WOLFSSL_LOCAL int GetSequence(const byte* input, word32* inOutIdx, int* len,
    7801033                             word32 maxIdx);
     1034WOLFSSL_LOCAL int GetSequence_ex(const byte* input, word32* inOutIdx, int* len,
     1035                           word32 maxIdx, int check);
    7811036WOLFSSL_LOCAL int GetSet(const byte* input, word32* inOutIdx, int* len,
    7821037                        word32 maxIdx);
     
    7931048        word16* out, word32* outSz);
    7941049#endif
     1050WOLFSSL_LOCAL int GetASNObjectId(const byte* input, word32* inOutIdx, int* len,
     1051                                 word32 maxIdx);
     1052WOLFSSL_LOCAL int SetObjectId(int len, byte* output);
    7951053WOLFSSL_LOCAL int GetObjectId(const byte* input, word32* inOutIdx, word32* oid,
    7961054                              word32 oidType, word32 maxIdx);
     
    8121070                             int maxIdx);
    8131071WOLFSSL_LOCAL int wc_CheckPrivateKey(byte* key, word32 keySz, DecodedCert* der);
     1072WOLFSSL_LOCAL int RsaPublicKeyDerSize(RsaKey* key, int with_header);
    8141073
    8151074#ifdef HAVE_ECC
     
    8241083WOLFSSL_LOCAL void FreeSignatureCtx(SignatureCtx* sigCtx);
    8251084
     1085#ifndef NO_CERTS
     1086
     1087WOLFSSL_LOCAL int wc_EncryptedInfoParse(EncryptedInfo* info, char** pBuffer,
     1088                                        size_t bufSz);
     1089
     1090WOLFSSL_LOCAL int PemToDer(const unsigned char* buff, long sz, int type,
     1091                          DerBuffer** pDer, void* heap, EncryptedInfo* info,
     1092                          int* eccKey);
     1093WOLFSSL_LOCAL int AllocDer(DerBuffer** der, word32 length, int type, void* heap);
     1094WOLFSSL_LOCAL void FreeDer(DerBuffer** der);
     1095
     1096#endif /* !NO_CERTS */
    8261097
    8271098#ifdef WOLFSSL_CERT_GEN
    8281099
    8291100enum cert_enums {
    830     NAME_ENTRIES    =  8,
     1101#ifdef WOLFSSL_CERT_EXT
     1102    NAME_ENTRIES    =  10,
     1103#else
     1104    NAME_ENTRIES    =  9,
     1105#endif
    8311106    JOINT_LEN       =  2,
    8321107    EMAIL_JOINT_LEN =  9,
     1108    PILOT_JOINT_LEN =  10,
    8331109    RSA_KEY         = 10,
    8341110    NTRU_KEY        = 11,
     
    8361112    ED25519_KEY     = 13
    8371113};
    838 
    839 #ifndef WOLFSSL_PEMCERT_TODER_DEFINED
    840 #ifndef NO_FILESYSTEM
    841 /* forward from wolfSSL */
    842 WOLFSSL_API
    843 int wolfSSL_PemCertToDer(const char* fileName,unsigned char* derBuf,int derSz);
    844 #define WOLFSSL_PEMCERT_TODER_DEFINED
    845 #endif
    846 #endif
    8471114
    8481115#endif /* WOLFSSL_CERT_GEN */
     
    8771144};
    8781145
     1146#ifdef OPENSSL_EXTRA
     1147enum Ocsp_Verify_Error {
     1148    OCSP_VERIFY_ERROR_NONE = 0,
     1149    OCSP_BAD_ISSUER = 1
     1150};
     1151#endif
     1152
    8791153
    8801154typedef struct OcspRequest  OcspRequest;
     
    8941168    byte thisDateFormat;
    8951169    byte nextDateFormat;
    896 #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
     1170#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
    8971171    byte* thisDateAsn;
    8981172    byte* nextDateAsn;
     
    9301204    byte*   source;          /* pointer to source buffer, not owned */
    9311205    word32  maxIdx;          /* max offset based on init size */
     1206
     1207#ifdef OPENSSL_EXTRA
     1208    int     verifyError;
     1209#endif
    9321210};
    9331211
     
    10111289
    10121290#endif /* !NO_ASN */
     1291
     1292
     1293#if !defined(NO_ASN) || !defined(NO_PWDBASED)
     1294
     1295#ifndef MAX_KEY_SIZE
     1296    #define MAX_KEY_SIZE    64  /* MAX PKCS Key length */
     1297#endif
     1298#ifndef MAX_UNICODE_SZ
     1299    #define MAX_UNICODE_SZ  256
     1300#endif
     1301
     1302enum PBESTypes {
     1303    PBE_MD5_DES      = 0,
     1304    PBE_SHA1_RC4_128 = 1,
     1305    PBE_SHA1_DES     = 2,
     1306    PBE_SHA1_DES3    = 3,
     1307    PBE_AES256_CBC   = 4,
     1308
     1309    PBE_SHA1_RC4_128_SUM = 657,
     1310    PBE_SHA1_DES3_SUM    = 659,
     1311    PBES2            = 13       /* algo ID */
     1312};
     1313
     1314enum PKCSTypes {
     1315    PKCS5v2             =   6,     /* PKCS #5 v2.0 */
     1316    PKCS12v1            =  12,     /* PKCS #12 */
     1317    PKCS5               =   5,     /* PKCS oid tag */
     1318    PKCS8v0             =   0,     /* default PKCS#8 version */
     1319};
     1320
     1321#endif /* !NO_ASN || !NO_PWDBASED */
     1322
    10131323#endif /* WOLF_CRYPT_ASN_H */
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/asn_public.h

    r352 r372  
    2020 */
    2121
    22 
     22/*!
     23    \file wolfssl/wolfcrypt/asn_public.h
     24*/
    2325
    2426#ifndef WOLF_CRYPT_ASN_PUBLIC_H
     
    4850    #define WC_RNG_TYPE_DEFINED
    4951#endif
     52
    5053
    5154/* Certificate file Type */
     
    6871    TRUSTED_PEER_TYPE,
    6972    EDDSA_PRIVATEKEY_TYPE,
    70     ED25519_TYPE
     73    ED25519_TYPE,
     74    PKCS12_TYPE,
     75    PKCS8_PRIVATEKEY_TYPE,
     76    PKCS8_ENC_PRIVATEKEY_TYPE
    7177};
    7278
     
    8086    CTC_SHAwECDSA    = 520,
    8187    CTC_SHA224wRSA   = 658,
    82     CTC_SHA224wECDSA = 527,
     88    CTC_SHA224wECDSA = 523,
    8389    CTC_SHA256wRSA   = 655,
    8490    CTC_SHA256wECDSA = 524,
     
    95101};
    96102
     103#ifndef WC_CTC_NAME_SIZE
     104    #define WC_CTC_NAME_SIZE 64
     105#endif
     106#ifndef WC_CTC_MAX_ALT_SIZE
     107    #define WC_CTC_MAX_ALT_SIZE 16384
     108#endif
     109
    97110enum Ctc_Misc {
    98111    CTC_COUNTRY_SIZE  =     2,
    99     CTC_NAME_SIZE     =    64,
     112    CTC_NAME_SIZE     = WC_CTC_NAME_SIZE,
    100113    CTC_DATE_SIZE     =    32,
    101     CTC_MAX_ALT_SIZE  = 16384,   /* may be huge */
     114    CTC_MAX_ALT_SIZE  = WC_CTC_MAX_ALT_SIZE, /* may be huge, default: 16384 */
    102115    CTC_SERIAL_SIZE   =    16,
    103116#ifdef WOLFSSL_CERT_EXT
     
    111124};
    112125
     126/* DER buffer */
     127typedef struct DerBuffer {
     128    byte*  buffer;
     129    void*  heap;
     130    word32 length;
     131    int    type;    /* enum CertType */
     132    int    dynType; /* DYNAMIC_TYPE_* */
     133} DerBuffer;
     134
     135enum {
     136    IV_SZ   = 32,                   /* max iv sz */
     137    NAME_SZ = 80,                   /* max one line */
     138
     139    PEM_PASS_READ  = 0,
     140    PEM_PASS_WRITE = 1,
     141};
     142
     143
     144typedef int (pem_password_cb)(char* passwd, int sz, int rw, void* userdata);
     145
     146typedef struct EncryptedInfo {
     147    pem_password_cb* passwd_cb;
     148    void*            passwd_userdata;
     149
     150    long     consumed;         /* tracks PEM bytes consumed */
     151
     152    int      cipherType;
     153    word32   keySz;
     154    word32   ivSz;             /* salt or encrypted IV size */
     155
     156    char     name[NAME_SZ];    /* cipher name, such as "DES-CBC" */
     157    byte     iv[IV_SZ];        /* salt or encrypted IV */
     158
     159    word16   set:1;            /* if encryption set */
     160} EncryptedInfo;
     161
     162
     163#if defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_CERT_EXT)
     164#ifdef WOLFSSL_EKU_OID
     165    #ifndef CTC_MAX_EKU_NB
     166        #define CTC_MAX_EKU_NB 1
     167    #endif
     168    #ifndef CTC_MAX_EKU_OID_SZ
     169        #define CTC_MAX_EKU_OID_SZ 30
     170    #endif
     171#else
     172    #undef CTC_MAX_EKU_OID_SZ
     173    #define CTC_MAX_EKU_OID_SZ 0
     174#endif
     175#endif /* WOLFSSL_CERT_GEN || WOLFSSL_CERT_EXT */
    113176
    114177#ifdef WOLFSSL_CERT_GEN
     178
     179#ifdef WOLFSSL_MULTI_ATTRIB
     180#ifndef CTC_MAX_ATTRIB
     181    #define CTC_MAX_ATTRIB 4
     182#endif
     183
     184/* ASN Encoded Name field */
     185typedef struct NameAttrib {
     186    int  sz;                     /* actual string value length */
     187    int  id;                     /* id of name */
     188    int  type;                   /* enc of name */
     189    char value[CTC_NAME_SIZE];   /* name */
     190} NameAttrib;
     191#endif /* WOLFSSL_MULTI_ATTRIB */
     192
    115193
    116194typedef struct CertName {
     
    129207    char commonName[CTC_NAME_SIZE];
    130208    char commonNameEnc;
     209    char serialDev[CTC_NAME_SIZE];
     210    char serialDevEnc;
     211#ifdef WOLFSSL_CERT_EXT
     212    char busCat[CTC_NAME_SIZE];
     213    char busCatEnc;
     214    char joiC[CTC_NAME_SIZE];
     215    char joiCEnc;
     216    char joiSt[CTC_NAME_SIZE];
     217    char joiStEnc;
     218#endif
    131219    char email[CTC_NAME_SIZE];  /* !!!! email has to be last !!!! */
     220#ifdef WOLFSSL_MULTI_ATTRIB
     221    NameAttrib name[CTC_MAX_ATTRIB];
     222#endif
    132223} CertName;
    133224
     
    162253    word16  keyUsage;                    /* Key Usage */
    163254    byte    extKeyUsage;                 /* Extended Key Usage */
     255#ifdef WOLFSSL_EKU_OID
     256    /* Extended Key Usage OIDs */
     257    byte    extKeyUsageOID[CTC_MAX_EKU_NB][CTC_MAX_EKU_OID_SZ];
     258    byte    extKeyUsageOIDSz[CTC_MAX_EKU_NB];
     259#endif
    164260    char    certPolicies[CTC_MAX_CERTPOL_NB][CTC_MAX_CERTPOL_SZ];
    165261    word16  certPoliciesNb;              /* Number of Cert Policy */
     262    byte     issRaw[sizeof(CertName)];   /* raw issuer info */
     263    byte     sbjRaw[sizeof(CertName)];   /* raw subject info */
    166264#endif
    167265#ifdef WOLFSSL_CERT_REQ
     
    170268    void*   heap; /* heap hint */
    171269} Cert;
     270
    172271
    173272
     
    211310WOLFSSL_API int  wc_SetDatesBuffer(Cert*, const byte*, int);
    212311
     312#ifndef NO_ASN_TIME
     313WOLFSSL_API int wc_GetCertDates(Cert* cert, struct tm* before,
     314    struct tm* after);
     315#endif
     316
    213317#ifdef WOLFSSL_CERT_EXT
    214318WOLFSSL_API int wc_SetAuthKeyIdFromPublicKey_ex(Cert *cert, int keyType,
     
    223327                                                ecc_key *eckey);
    224328WOLFSSL_API int wc_SetSubjectKeyId(Cert *cert, const char* file);
     329WOLFSSL_API int wc_GetSubjectRaw(byte **subjectRaw, Cert *cert);
     330WOLFSSL_API int wc_SetSubjectRaw(Cert* cert, const byte* der, int derSz);
     331WOLFSSL_API int wc_SetIssuerRaw(Cert* cert, const byte* der, int derSz);
    225332
    226333#ifdef HAVE_NTRU
     
    244351WOLFSSL_API int wc_SetExtKeyUsage(Cert *cert, const char *value);
    245352
     353
     354#ifdef WOLFSSL_EKU_OID
     355/* Set ExtendedKeyUsage with unique OID
     356 * oid is expected to be in byte representation
     357 */
     358WOLFSSL_API int wc_SetExtKeyUsageOID(Cert *cert, const char *oid, word32 sz,
     359                                     byte idx, void* heap);
     360#endif /* WOLFSSL_EKU_OID */
    246361#endif /* WOLFSSL_CERT_EXT */
    247362
     
    254369#endif /* WOLFSSL_CERT_GEN */
    255370
     371WOLFSSL_API int wc_GetDateInfo(const byte* certDate, int certDateSz,
     372    const byte** date, byte* format, int* length);
     373#ifndef NO_ASN_TIME
     374WOLFSSL_API int wc_GetDateAsCalendarTime(const byte* date, int length,
     375    byte format, struct tm* time);
     376#endif
     377
     378#if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
     379
     380    WOLFSSL_API int wc_PemGetHeaderFooter(int type, const char** header,
     381        const char** footer);
     382
     383#endif
     384
     385WOLFSSL_API  int wc_AllocDer(DerBuffer** pDer, word32 length, int type, void* heap);
     386WOLFSSL_API void wc_FreeDer(DerBuffer** pDer);
     387
     388#ifdef WOLFSSL_PEM_TO_DER
     389    WOLFSSL_API int wc_PemToDer(const unsigned char* buff, long longSz, int type,
     390              DerBuffer** pDer, void* heap, EncryptedInfo* info, int* eccKey);
     391
     392    WOLFSSL_API int wc_KeyPemToDer(const unsigned char*, int,
     393                                   unsigned char*, int, const char*);
     394    WOLFSSL_API int wc_CertPemToDer(const unsigned char*, int,
     395                                    unsigned char*, int, int);
     396#endif /* WOLFSSL_PEM_TO_DER */
     397
    256398#if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER)
    257     #ifndef WOLFSSL_PEMPUBKEY_TODER_DEFINED
    258399        #ifndef NO_FILESYSTEM
    259         /* forward from wolfssl */
    260         WOLFSSL_API int wolfSSL_PemPubKeyToDer(const char* fileName,
     400        WOLFSSL_API int wc_PemPubKeyToDer(const char* fileName,
    261401                                               unsigned char* derBuf, int derSz);
    262402        #endif
    263403
    264         /* forward from wolfssl */
    265         WOLFSSL_API int wolfSSL_PubKeyPemToDer(const unsigned char*, int,
     404    WOLFSSL_API int wc_PubKeyPemToDer(const unsigned char*, int,
    266405                                               unsigned char*, int);
    267         #define WOLFSSL_PEMPUBKEY_TODER_DEFINED
    268     #endif /* WOLFSSL_PEMPUBKEY_TODER_DEFINED */
    269406#endif /* WOLFSSL_CERT_EXT || WOLFSSL_PUB_PEM_TO_DER */
    270407
    271 #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN) || !defined(NO_DSA) \
    272                              || defined(OPENSSL_EXTRA)
     408#ifdef WOLFSSL_CERT_GEN
     409    #ifndef NO_FILESYSTEM
     410        WOLFSSL_API int wc_PemCertToDer(const char* fileName,
     411                                        unsigned char* derBuf, int derSz);
     412    #endif
     413#endif /* WOLFSSL_CERT_GEN */
     414
     415#ifdef WOLFSSL_DER_TO_PEM
    273416    WOLFSSL_API int wc_DerToPem(const byte* der, word32 derSz, byte* output,
    274417                                word32 outputSz, int type);
    275418    WOLFSSL_API int wc_DerToPemEx(const byte* der, word32 derSz, byte* output,
    276419                                word32 outputSz, byte *cipherIno, int type);
     420#endif
     421
     422#if !defined(NO_RSA) && !defined(HAVE_USER_RSA)
     423    WOLFSSL_API int wc_RsaPublicKeyDecode_ex(const byte* input, word32* inOutIdx,
     424        word32 inSz, const byte** n, word32* nSz, const byte** e, word32* eSz);
    277425#endif
    278426
     
    284432    WOLFSSL_API int wc_EccPrivateKeyToDer(ecc_key* key, byte* output,
    285433                                          word32 inLen);
     434    WOLFSSL_API int wc_EccPrivateKeyToPKCS8(ecc_key* key, byte* output,
     435                                            word32* outLen);
    286436
    287437    /* public key helper */
    288438    WOLFSSL_API int wc_EccPublicKeyDecode(const byte*, word32*,
    289439                                              ecc_key*, word32);
    290     #if (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
    291440        WOLFSSL_API int wc_EccPublicKeyToDer(ecc_key*, byte* output,
    292441                                               word32 inLen, int with_AlgCurve);
    293442    #endif
    294 #endif
    295443
    296444#ifdef HAVE_ED25519
     
    322470       byte* key, word32 keySz, int algoID, const byte* curveOID, word32 oidSz);
    323471
     472#ifndef NO_ASN_TIME
    324473/* Time */
    325474/* Returns seconds (Epoch/UTC)
     
    330479*/
    331480WOLFSSL_API int wc_GetTime(void* timePtr, word32 timeSize);
     481#endif
     482
     483#ifdef WOLFSSL_ENCRYPTED_KEYS
     484    WOLFSSL_API int wc_EncryptedInfoGet(EncryptedInfo* info,
     485        const char* cipherInfo);
     486#endif
     487
     488
     489#ifdef WOLFSSL_CERT_PIV
     490
     491typedef struct _wc_CertPIV {
     492    const byte*  cert;
     493    word32       certSz;
     494    const byte*  certErrDet;
     495    word32       certErrDetSz;
     496    const byte*  nonce;         /* Identiv Only */
     497    word32       nonceSz;       /* Identiv Only */
     498    const byte*  signedNonce;   /* Identiv Only */
     499    word32       signedNonceSz; /* Identiv Only */
     500
     501    /* flags */
     502    word16       compression:2;
     503    word16       isX509:1;
     504    word16       isIdentiv:1;
     505} wc_CertPIV;
     506
     507WOLFSSL_API int wc_ParseCertPIV(wc_CertPIV* cert, const byte* buf, word32 totalSz);
     508#endif /* WOLFSSL_CERT_PIV */
     509
    332510
    333511#ifdef __cplusplus
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/coding.h

    r352 r372  
    2020 */
    2121
    22 
     22/*!
     23    \file wolfssl/wolfcrypt/coding.h
     24*/
    2325
    2426#ifndef WOLF_CRYPT_CODING_H
     
    6264#endif
    6365
    64 #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(HAVE_FIPS) \
    65                            || defined(HAVE_ECC_CDH)
     66#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
     67    defined(HAVE_WEBSERVER) || defined(HAVE_FIPS) || \
     68    defined(HAVE_ECC_CDH) || defined(HAVE_SELFTEST) || \
     69    defined(WOLFSSL_ENCRYPTED_KEYS)
     70    #ifndef WOLFSSL_BASE16
     71        #define WOLFSSL_BASE16
     72    #endif
     73#endif
     74
     75#ifdef WOLFSSL_BASE16
    6676    WOLFSSL_API
    6777    int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen);
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/curve25519.h

    r352 r372  
    1919 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
    2020 */
     21
     22/*!
     23    \file wolfssl/wolfcrypt/curve25519.h
     24*/
    2125
    2226
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/des3.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/des3.h
     24*/
    2225
    2326#ifndef WOLF_CRYPT_DES3_H
     
    2831#ifndef NO_DES3
    2932
    30 #ifdef HAVE_FIPS
     33#if defined(HAVE_FIPS) && \
     34    defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     35    #include <wolfssl/wolfcrypt/fips.h>
     36#endif /* HAVE_FIPS_VERSION >= 2 */
     37
     38#if defined(HAVE_FIPS) && \
     39        (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
    3140/* included for fips @wc_fips */
    3241#include <cyassl/ctaocrypt/des3.h>
     
    3746#endif
    3847
    39 #ifndef HAVE_FIPS /* to avoid redefinition of macros */
     48/* these are required for FIPS and non-FIPS */
     49enum {
     50    DES_KEY_SIZE        =  8,  /* des                     */
     51    DES3_KEY_SIZE       = 24,  /* 3 des ede               */
     52    DES_IV_SIZE         =  8,  /* should be the same as DES_BLOCK_SIZE */
     53};
     54
     55
     56/* avoid redefinition of structs */
     57#if !defined(HAVE_FIPS) || \
     58    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    4059
    4160#ifdef WOLFSSL_ASYNC_CRYPT
     
    4463
    4564enum {
    46     DES_ENC_TYPE    = 2,     /* cipher unique type */
    47     DES3_ENC_TYPE   = 3,     /* cipher unique type */
     65    DES_ENC_TYPE    = WC_CIPHER_DES,     /* cipher unique type */
     66    DES3_ENC_TYPE   = WC_CIPHER_DES3,    /* cipher unique type */
     67
    4868    DES_BLOCK_SIZE  = 8,
    49     DES_KS_SIZE     = 32,
     69    DES_KS_SIZE     = 32,    /* internal DES key buffer size */
    5070
    5171    DES_ENCRYPTION  = 0,
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/dh.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/dh.h
     24*/
    2225
    2326#ifndef WOLF_CRYPT_DH_H
     
    2730
    2831#ifndef NO_DH
     32
     33#if defined(HAVE_FIPS) && \
     34    defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     35    #include <wolfssl/wolfcrypt/fips.h>
     36#endif /* HAVE_FIPS_VERSION >= 2 */
    2937
    3038#include <wolfssl/wolfcrypt/integer.h>
     
    3947#endif
    4048typedef struct DhParams {
     49    #ifdef HAVE_FFDHE_Q
     50    const byte* q;
     51    word32      q_len;
     52    #endif /* HAVE_FFDHE_Q */
    4153    const byte* p;
    4254    word32      p_len;
     
    4759/* Diffie-Hellman Key */
    4860typedef struct DhKey {
    49     mp_int p, g;                            /* group parameters  */
     61    mp_int p, g, q;                         /* group parameters  */
    5062    void* heap;
    5163#ifdef WOLFSSL_ASYNC_CRYPT
     
    7385WOLFSSL_API int wc_InitDhKey(DhKey* key);
    7486WOLFSSL_API int wc_InitDhKey_ex(DhKey* key, void* heap, int devId);
    75 WOLFSSL_API void wc_FreeDhKey(DhKey* key);
     87WOLFSSL_API int wc_FreeDhKey(DhKey* key);
    7688
    7789WOLFSSL_API int wc_DhGenerateKeyPair(DhKey* key, WC_RNG* rng, byte* priv,
     
    8597WOLFSSL_API int wc_DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g,
    8698                        word32 gSz);
     99WOLFSSL_API int wc_DhSetKey_ex(DhKey* key, const byte* p, word32 pSz,
     100                        const byte* g, word32 gSz, const byte* q, word32 qSz);
     101WOLFSSL_API int wc_DhSetCheckKey(DhKey* key, const byte* p, word32 pSz,
     102                        const byte* g, word32 gSz, const byte* q, word32 qSz,
     103                        int trusted, WC_RNG* rng);
    87104WOLFSSL_API int wc_DhParamsLoad(const byte* input, word32 inSz, byte* p,
    88105                            word32* pInOutSz, byte* g, word32* gInOutSz);
    89106WOLFSSL_API int wc_DhCheckPubKey(DhKey* key, const byte* pub, word32 pubSz);
     107WOLFSSL_API int wc_DhCheckPubKey_ex(DhKey* key, const byte* pub, word32 pubSz,
     108                            const byte* prime, word32 primeSz);
     109WOLFSSL_API int wc_DhCheckPrivKey(DhKey* key, const byte* priv, word32 pubSz);
     110WOLFSSL_API int wc_DhCheckPrivKey_ex(DhKey* key, const byte* priv, word32 pubSz,
     111                            const byte* prime, word32 primeSz);
     112WOLFSSL_API int wc_DhCheckKeyPair(DhKey* key, const byte* pub, word32 pubSz,
     113                        const byte* priv, word32 privSz);
     114WOLFSSL_API int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh);
     115WOLFSSL_API int wc_DhExportParamsRaw(DhKey* dh, byte* p, word32* pSz,
     116                       byte* q, word32* qSz, byte* g, word32* gSz);
     117
    90118
    91119#ifdef __cplusplus
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/dsa.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/dsa.h
     24*/
    2225
    2326#ifndef WOLF_CRYPT_DSA_H
     
    7578#endif
    7679
     80/* raw export functions */
     81WOLFSSL_API int wc_DsaImportParamsRaw(DsaKey* dsa, const char* p,
     82                                      const char* q, const char* g);
     83WOLFSSL_API int wc_DsaImportParamsRawCheck(DsaKey* dsa, const char* p,
     84                                      const char* q, const char* g,
     85                                      int trusted, WC_RNG* rng);
     86WOLFSSL_API int wc_DsaExportParamsRaw(DsaKey* dsa, byte* p, word32* pSz,
     87                                      byte* q, word32* qSz, byte* g,
     88                                      word32* gSz);
     89WOLFSSL_API int wc_DsaExportKeyRaw(DsaKey* dsa, byte* x, word32* xSz, byte* y,
     90                                   word32* ySz);
    7791#ifdef __cplusplus
    7892    } /* extern "C" */
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/ecc.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/ecc.h
     24*/
     25
    2226
    2327#ifndef WOLF_CRYPT_ECC_H
     
    2731
    2832#ifdef HAVE_ECC
     33
     34#if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     35    #include <wolfssl/wolfcrypt/fips.h>
     36#endif /* HAVE_FIPS_VERSION >= 2 */
    2937
    3038#include <wolfssl/wolfcrypt/integer.h>
     
    7381#elif defined(HAVE_ECC320)
    7482    #define MAX_ECC_BITS    320
     83#elif !defined(NO_ECC256)
     84    #define MAX_ECC_BITS    256
    7585#elif defined(HAVE_ECC239)
    7686    #define MAX_ECC_BITS    239
    7787#elif defined(HAVE_ECC224)
    7888    #define MAX_ECC_BITS    224
    79 #elif !defined(NO_ECC256)
    80     #define MAX_ECC_BITS    256
    8189#elif defined(HAVE_ECC192)
    8290    #define MAX_ECC_BITS    192
     
    110118    ECC_MAX_PAD_SZ  = 4,    /* ECC maximum padding size */
    111119    ECC_MAX_OID_LEN = 16,
    112     ECC_MAX_SIG_SIZE= ((MAX_ECC_BYTES * 2) + ECC_MAX_PAD_SZ + SIG_HEADER_SZ)
     120    ECC_MAX_SIG_SIZE= ((MAX_ECC_BYTES * 2) + ECC_MAX_PAD_SZ + SIG_HEADER_SZ),
     121
     122    /* max crypto hardware size */
     123#ifdef WOLFSSL_ATECC508A
     124    ECC_MAX_CRYPTO_HW_SIZE = ATECC_KEY_SIZE, /* from port/atmel/atmel.h */
     125    ECC_MAX_CRYPTO_HW_PUBKEY_SIZE = (ATECC_KEY_SIZE*2),
     126#elif defined(PLUTON_CRYPTO_ECC)
     127    ECC_MAX_CRYPTO_HW_SIZE = 32,
     128#endif
     129
     130    /* point compression type */
     131    ECC_POINT_COMP_EVEN = 0x02,
     132    ECC_POINT_COMP_ODD = 0x03,
     133    ECC_POINT_UNCOMP = 0x04,
     134
     135    /* Shamir's dual add constants */
     136    SHAMIR_PRECOMP_SZ = 16,
     137
     138#ifdef HAVE_PKCS11
     139    ECC_MAX_ID_LEN    = 32,
     140#endif
    113141};
    114142
     
    176204
    177205/* ECC set type defined a GF(p) curve */
     206#ifndef USE_WINDOWS_API
    178207typedef struct ecc_set_type {
    179208    int size;             /* The size of the curve in octets */
     
    191220    int         cofactor;
    192221} ecc_set_type;
     222#else
     223/* MSC does something different with the pointers to the arrays than GCC,
     224 * and it causes the FIPS checksum to fail. In the case of windows builds,
     225 * store everything as arrays instead of pointers to strings. */
     226
     227#define MAX_ECC_NAME 16
     228#define MAX_ECC_STRING ((MAX_ECC_BYTES * 2) + 1)
     229    /* The values are stored as text strings. */
     230
     231typedef struct ecc_set_type {
     232    int size;             /* The size of the curve in octets */
     233    int id;               /* id of this curve */
     234    const char name[MAX_ECC_NAME];     /* name of this curve */
     235    const char prime[MAX_ECC_STRING];    /* prime that defines the field, curve is in (hex) */
     236    const char Af[MAX_ECC_STRING];       /* fields A param (hex) */
     237    const char Bf[MAX_ECC_STRING];       /* fields B param (hex) */
     238    const char order[MAX_ECC_STRING];    /* order of the curve (hex) */
     239    const char Gx[MAX_ECC_STRING];       /* x coordinate of the base point on curve (hex) */
     240    const char Gy[MAX_ECC_STRING];       /* y coordinate of the base point on curve (hex) */
     241    const ecc_oid_t oid[10];
     242    word32      oidSz;
     243    word32      oidSum;    /* sum of encoded OID bytes */
     244    int         cofactor;
     245} ecc_set_type;
     246#endif
    193247
    194248
     
    247301typedef struct alt_fp_int {
    248302    int used, sign, size;
    249     fp_digit dp[FP_SIZE_ECC];
     303    mp_digit dp[FP_SIZE_ECC];
    250304} alt_fp_int;
    251305#endif /* ALT_ECC_SIZE */
     306
     307#ifndef WC_ECCKEY_TYPE_DEFINED
     308    typedef struct ecc_key ecc_key;
     309    #define WC_ECCKEY_TYPE_DEFINED
     310#endif
    252311
    253312
     
    265324    alt_fp_int xyz[3];
    266325#endif
     326#ifdef WOLFSSL_SMALL_STACK_CACHE
     327    ecc_key* key;
     328#endif
    267329} ecc_point;
    268330
     
    285347    const ecc_set_type* dp;     /* domain parameters, either points to NIST
    286348                                   curves (idx >= 0) or user supplied */
     349#ifdef WOLFSSL_CUSTOM_CURVES
     350    int deallocSet;
     351#endif
    287352    void* heap;         /* heap hint */
     353    ecc_point pubkey;   /* public key */
     354    mp_int    k;        /* private key */
    288355#ifdef WOLFSSL_ATECC508A
    289356    int  slot;        /* Key Slot Number (-1 unknown) */
    290     byte pubkey[PUB_KEY_SIZE];
    291 #else
    292     ecc_point pubkey;   /* public key */
    293     mp_int    k;        /* private key */
     357    byte pubkey_raw[ECC_MAX_CRYPTO_HW_PUBKEY_SIZE];
     358#endif
     359#if defined(PLUTON_CRYPTO_ECC) || defined(WOLF_CRYPTO_DEV)
     360    int devId;
    294361#endif
    295362#ifdef WOLFSSL_ASYNC_CRYPT
     
    297364    mp_int* s;
    298365    WC_ASYNC_DEV asyncDev;
     366    #ifdef HAVE_CAVIUM_V
     367        mp_int* e;      /* Sign, Verify and Shared Secret */
     368        mp_int* signK;
     369    #endif
    299370    #ifdef WOLFSSL_CERT_GEN
    300371        CertSignCtx certSignCtx; /* context info for cert sign (MakeSignature) */
    301372    #endif
    302373#endif /* WOLFSSL_ASYNC_CRYPT */
    303 };
    304 
    305 #ifndef WC_ECCKEY_TYPE_DEFINED
    306     typedef struct ecc_key ecc_key;
    307     #define WC_ECCKEY_TYPE_DEFINED
    308 #endif
     374#ifdef HAVE_PKCS11
     375    byte id[ECC_MAX_ID_LEN];
     376    int  idLen;
     377#endif
     378#ifdef WOLFSSL_SMALL_STACK_CACHE
     379    mp_int* t1;
     380    mp_int* t2;
     381#ifdef ALT_ECC_SIZE
     382    mp_int* x;
     383    mp_int* y;
     384    mp_int* z;
     385#endif
     386#endif
     387};
    309388
    310389
     
    322401    #define ECC_API    WOLFSSL_LOCAL
    323402#endif
     403
     404ECC_API int ecc_mul2add(ecc_point* A, mp_int* kA,
     405                ecc_point* B, mp_int* kB,
     406                ecc_point* C, mp_int* a, mp_int* modulus, void* heap);
    324407
    325408ECC_API int ecc_map(ecc_point*, mp_int*, mp_digit);
     
    378461WOLFSSL_API
    379462int wc_ecc_init_ex(ecc_key* key, void* heap, int devId);
    380 WOLFSSL_API
    381 void wc_ecc_free(ecc_key* key);
     463#ifdef HAVE_PKCS11
     464WOLFSSL_API
     465int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap,
     466                   int devId);
     467#endif
     468#ifdef WOLFSSL_CUSTOM_CURVES
     469WOLFSSL_LOCAL
     470void wc_ecc_free_curve(const ecc_set_type* curve, void* heap);
     471#endif
     472WOLFSSL_API
     473int wc_ecc_free(ecc_key* key);
    382474WOLFSSL_API
    383475int wc_ecc_set_flags(ecc_key* key, word32 flags);
     
    410502        const byte* Gx, word32 GxSz, const byte* Gy, word32 GySz, int cofactor);
    411503
     504WOLFSSL_API
     505int wc_ecc_get_curve_id_from_oid(const byte* oid, word32 len);
     506
     507WOLFSSL_API
     508ecc_point* wc_ecc_new_point(void);
     509WOLFSSL_API
     510ecc_point* wc_ecc_new_point_h(void* h);
     511WOLFSSL_API
     512void wc_ecc_del_point(ecc_point* p);
     513WOLFSSL_API
     514void wc_ecc_del_point_h(ecc_point* p, void* h);
     515WOLFSSL_API
     516int wc_ecc_copy_point(ecc_point* p, ecc_point *r);
     517WOLFSSL_API
     518int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);
     519WOLFSSL_API
     520int wc_ecc_point_is_at_infinity(ecc_point *p);
     521
    412522#ifndef WOLFSSL_ATECC508A
    413 
    414 WOLFSSL_API
    415 ecc_point* wc_ecc_new_point(void);
    416 WOLFSSL_API
    417 ecc_point* wc_ecc_new_point_h(void* h);
    418 WOLFSSL_API
    419 void wc_ecc_del_point(ecc_point* p);
    420 WOLFSSL_API
    421 void wc_ecc_del_point_h(ecc_point* p, void* h);
    422 WOLFSSL_API
    423 int wc_ecc_copy_point(ecc_point* p, ecc_point *r);
    424 WOLFSSL_API
    425 int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);
    426 WOLFSSL_API
    427 int wc_ecc_point_is_at_infinity(ecc_point *p);
    428523WOLFSSL_API
    429524int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R,
     
    459554int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen);
    460555WOLFSSL_API
     556int wc_ecc_rs_raw_to_sig(const byte* r, word32 rSz, const byte* s, word32 sSz,
     557    byte* out, word32* outlen);
     558WOLFSSL_API
    461559int wc_ecc_sig_to_rs(const byte* sig, word32 sigLen, byte* r, word32* rLen,
    462560                   byte* s, word32* sLen);
     
    467565int wc_ecc_import_raw_ex(ecc_key* key, const char* qx, const char* qy,
    468566                   const char* d, int curve_id);
     567WOLFSSL_API
     568int wc_ecc_import_unsigned(ecc_key* key, byte* qx, byte* qy,
     569                   byte* d, int curve_id);
    469570#endif /* HAVE_ECC_KEY_IMPORT */
    470571
    471572#ifdef HAVE_ECC_KEY_EXPORT
     573WOLFSSL_API
     574int wc_ecc_export_ex(ecc_key* key, byte* qx, word32* qxLen,
     575                     byte* qy, word32* qyLen, byte* d, word32* dLen,
     576                     int encType);
    472577WOLFSSL_API
    473578int wc_ecc_export_private_only(ecc_key* key, byte* out, word32* outLen);
     
    497602WOLFSSL_API
    498603int wc_ecc_size(ecc_key* key);
     604WOLFSSL_API
     605int wc_ecc_sig_size_calc(int sz);
    499606WOLFSSL_API
    500607int wc_ecc_sig_size(ecc_key* key);
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/ed25519.h

    r352 r372  
    1919 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
    2020 */
     21
     22/*!
     23    \file wolfssl/wolfcrypt/ed25519.h
     24*/
    2125
    2226
     
    7478    byte pointY[ED25519_KEY_SIZE]; /* Y coordinate is the public key with The most significant bit of the final octet always zero. */
    7579#endif
     80    word16 pubKeySet:1;
    7681#ifdef WOLFSSL_ASYNC_CRYPT
    7782    WC_ASYNC_DEV asyncDev;
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/error-crypt.h

    r352 r372  
    2020 */
    2121
    22 
     22/*!
     23    \file wolfssl/wolfcrypt/error-crypt.h
     24*/
    2325
    2426#ifndef WOLF_CRYPT_ERROR_H
     
    98100    ASN_NTRU_KEY_E     = -159,  /* ASN ntru key decode error, invalid input */
    99101    ASN_CRIT_EXT_E     = -160,  /* ASN unsupported critical extension */
     102    ASN_ALT_NAME_E     = -161,  /* ASN alternate name error */
     103    ASN_NO_PEM_HEADER  = -162,  /* ASN no PEM header found */
    100104
    101105    ECC_BAD_ARG_E      = -170,  /* ECC input argument of wrong type */
     
    192196    ECC_PRIVATEONLY_E   = -246,  /* Invalid use of private only ECC key*/
    193197    EXTKEYUSAGE_E       = -247,  /* Bad Extended Key Usage value */
    194 
    195     WC_LAST_E           = -247,  /* Update this to indicate last error */
     198    WC_HW_E             = -248,  /* Error with hardware crypto use */
     199    WC_HW_WAIT_E        = -249,  /* Hardware waiting on resource */
     200
     201    PSS_SALTLEN_E       = -250,  /* PSS length of salt is to long for hash */
     202    PRIME_GEN_E         = -251,  /* Failure finding a prime. */
     203    BER_INDEF_E         = -252,  /* Cannot decode indefinite length BER. */
     204    RSA_OUT_OF_RANGE_E  = -253,  /* Ciphertext to decrypt out of range. */
     205    RSAPSS_PAT_FIPS_E   = -254,  /* RSA-PSS PAT failure */
     206    ECDSA_PAT_FIPS_E    = -255,  /* ECDSA PAT failure */
     207    DH_KAT_FIPS_E       = -256,  /* DH KAT failure */
     208    AESCCM_KAT_FIPS_E   = -257,  /* AESCCM KAT failure */
     209    SHA3_KAT_FIPS_E     = -258,  /* SHA-3 KAT failure */
     210    ECDHE_KAT_FIPS_E    = -259,  /* ECDHE KAT failure */
     211    AES_GCM_OVERFLOW_E  = -260,  /* AES-GCM invocation counter overflow. */
     212    AES_CCM_OVERFLOW_E  = -261,  /* AES-CCM invocation counter overflow. */
     213    RSA_KEY_PAIR_E      = -262,  /* RSA Key Pair-Wise Consistency check fail. */
     214    DH_CHECK_PRIV_E     = -263,  /* DH Check Priv Key error */
     215
     216    WC_AFALG_SOCK_E     = -264,  /* AF_ALG socket error */
     217    WC_DEVCRYPTO_E      = -265,  /* /dev/crypto error */
     218
     219    ZLIB_INIT_ERROR     = -266,   /* zlib init error  */
     220    ZLIB_COMPRESS_ERROR = -267,   /* zlib compression error  */
     221    ZLIB_DECOMPRESS_ERROR = -268,  /* zlib decompression error  */
     222
     223    PKCS7_NO_SIGNER_E   = -269,  /* No signer in PKCS#7 signed data msg */
     224    WC_PKCS7_WANT_READ_E= -270,  /* PKCS7 operations wants more input */
     225
     226    WC_LAST_E           = -270,  /* Update this to indicate last error */
    196227    MIN_CODE_E          = -300   /* errors -101 - -299 */
    197228
     
    201232
    202233
     234#ifdef NO_ERROR_STRINGS
     235    #define wc_GetErrorString(error) "no support for error strings built in"
     236    #define wc_ErrorString(err, buf) \
     237        (void)err; XSTRNCPY((buf), wc_GetErrorString((err)), \
     238        WOLFSSL_MAX_ERROR_SZ);
     239
     240#else
    203241WOLFSSL_API void wc_ErrorString(int err, char* buff);
    204242WOLFSSL_API const char* wc_GetErrorString(int error);
    205 
     243#endif
    206244
    207245#ifdef __cplusplus
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/hash.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/hash.h
     24*/
    2225
    2326#ifndef WOLF_CRYPT_HASH_H
     
    3841    #include <wolfssl/wolfcrypt/sha512.h>
    3942#endif
     43#ifdef HAVE_BLAKE2
     44    #include <wolfssl/wolfcrypt/blake2.h>
     45#endif
     46#ifdef WOLFSSL_SHA3
     47    #include <wolfssl/wolfcrypt/sha3.h>
     48#endif
     49#ifndef NO_MD4
     50    #include <wolfssl/wolfcrypt/md4.h>
     51#endif
     52#ifdef WOLFSSL_MD2
     53    #include <wolfssl/wolfcrypt/md2.h>
     54#endif
     55
    4056
    4157#ifdef __cplusplus
     
    4359#endif
    4460
    45 /* Hash types */
    46 enum wc_HashType {
    47     WC_HASH_TYPE_NONE = 0,
    48     WC_HASH_TYPE_MD2 = 1,
    49     WC_HASH_TYPE_MD4 = 2,
    50     WC_HASH_TYPE_MD5 = 3,
    51     WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */
    52     WC_HASH_TYPE_SHA224 = 9,
    53     WC_HASH_TYPE_SHA256 = 5,
    54     WC_HASH_TYPE_SHA384 = 6,
    55     WC_HASH_TYPE_SHA512 = 7,
    56     WC_HASH_TYPE_MD5_SHA = 8,
    57 };
     61#if !defined(HAVE_FIPS) && !defined(NO_OLD_WC_NAMES)
     62    #define MAX_DIGEST_SIZE WC_MAX_DIGEST_SIZE
     63#endif
     64
    5865
    5966typedef union {
     
    8087/* Find largest possible digest size
    8188   Note if this gets up to the size of 80 or over check smallstack build */
    82 #if defined(WOLFSSL_SHA512)
     89#if defined(WOLFSSL_SHA3)
     90    #define WC_MAX_DIGEST_SIZE WC_SHA3_512_DIGEST_SIZE
     91    #define WC_MAX_BLOCK_SIZE  WC_SHA3_224_BLOCK_SIZE /* 224 is the largest block size */
     92#elif defined(WOLFSSL_SHA512)
    8393    #define WC_MAX_DIGEST_SIZE WC_SHA512_DIGEST_SIZE
     94    #define WC_MAX_BLOCK_SIZE  WC_SHA512_BLOCK_SIZE
     95#elif defined(HAVE_BLAKE2)
     96    #define WC_MAX_DIGEST_SIZE BLAKE2B_OUTBYTES
     97    #define WC_MAX_BLOCK_SIZE  BLAKE2B_BLOCKBYTES
    8498#elif defined(WOLFSSL_SHA384)
    8599    #define WC_MAX_DIGEST_SIZE WC_SHA384_DIGEST_SIZE
     100    #define WC_MAX_BLOCK_SIZE  WC_SHA384_BLOCK_SIZE
    86101#elif !defined(NO_SHA256)
    87102    #define WC_MAX_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
     103    #define WC_MAX_BLOCK_SIZE  WC_SHA256_BLOCK_SIZE
    88104#elif defined(WOLFSSL_SHA224)
    89105    #define WC_MAX_DIGEST_SIZE WC_SHA224_DIGEST_SIZE
     106    #define WC_MAX_BLOCK_SIZE  WC_SHA224_BLOCK_SIZE
    90107#elif !defined(NO_SHA)
    91108    #define WC_MAX_DIGEST_SIZE WC_SHA_DIGEST_SIZE
     109    #define WC_MAX_BLOCK_SIZE  WC_SHA_BLOCK_SIZE
    92110#elif !defined(NO_MD5)
    93111    #define WC_MAX_DIGEST_SIZE WC_MD5_DIGEST_SIZE
     112    #define WC_MAX_BLOCK_SIZE  WC_MD5_BLOCK_SIZE
    94113#else
    95114    #define WC_MAX_DIGEST_SIZE 64 /* default to max size of 64 */
     115    #define WC_MAX_BLOCK_SIZE  128
    96116#endif
    97117
    98118#if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
    99119WOLFSSL_API int wc_HashGetOID(enum wc_HashType hash_type);
     120WOLFSSL_API enum wc_HashType wc_OidGetHash(int oid);
    100121#endif
    101122
     123WOLFSSL_API enum wc_HashType wc_HashTypeConvert(int hashType);
     124
    102125WOLFSSL_API int wc_HashGetDigestSize(enum wc_HashType hash_type);
     126WOLFSSL_API int wc_HashGetBlockSize(enum wc_HashType hash_type);
    103127WOLFSSL_API int wc_Hash(enum wc_HashType hash_type,
    104128    const byte* data, word32 data_len,
     
    111135WOLFSSL_API int wc_HashFinal(wc_HashAlg* hash, enum wc_HashType type,
    112136    byte* out);
    113 
     137WOLFSSL_API int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type);
    114138
    115139#ifndef NO_MD5
     
    123147#endif
    124148
     149#ifdef WOLFSSL_SHA224
     150#include <wolfssl/wolfcrypt/sha256.h>
     151        WOLFSSL_API int wc_Sha224Hash(const byte*, word32, byte*);
     152    #endif /* defined(WOLFSSL_SHA224) */
     153
    125154#ifndef NO_SHA256
    126155#include <wolfssl/wolfcrypt/sha256.h>
    127156WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*);
     157#endif
    128158
    129     #if defined(WOLFSSL_SHA224)
    130         WOLFSSL_API int wc_Sha224Hash(const byte*, word32, byte*);
    131     #endif /* defined(WOLFSSL_SHA224) */
    132 #endif
     159#ifdef WOLFSSL_SHA384
     160#include <wolfssl/wolfcrypt/sha512.h>
     161        WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*);
     162    #endif /* defined(WOLFSSL_SHA384) */
    133163
    134164#ifdef WOLFSSL_SHA512
    135165#include <wolfssl/wolfcrypt/sha512.h>
    136166WOLFSSL_API int wc_Sha512Hash(const byte*, word32, byte*);
    137 
    138     #if defined(WOLFSSL_SHA384)
    139         WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*);
    140     #endif /* defined(WOLFSSL_SHA384) */
    141167#endif /* WOLFSSL_SHA512 */
    142168
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/hc128.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/hc128.h
     24*/
     25
    2226
    2327#ifndef WOLF_CRYPT_HC128_H
     
    3337
    3438enum {
    35         HC128_ENC_TYPE    =  6    /* cipher unique type */
     39        HC128_ENC_TYPE =  WC_CIPHER_HC128,     /* cipher unique type */
    3640};
    3741
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/hmac.h

    r352 r372  
    2020 */
    2121
    22 
     22/*!
     23    \file wolfssl/wolfcrypt/hmac.h
     24*/
    2325
    2426#ifndef NO_HMAC
     
    2729#define WOLF_CRYPT_HMAC_H
    2830
    29 #include <wolfssl/wolfcrypt/types.h>
     31#include <wolfssl/wolfcrypt/hash.h>
    3032
    31 #ifndef NO_MD5
    32     #include <wolfssl/wolfcrypt/md5.h>
     33#if defined(HAVE_FIPS) && \
     34        (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
     35/* for fips @wc_fips */
     36    #include <cyassl/ctaocrypt/hmac.h>
     37    #define WC_HMAC_BLOCK_SIZE HMAC_BLOCK_SIZE
    3338#endif
    3439
    35 #ifndef NO_SHA
    36     #include <wolfssl/wolfcrypt/sha.h>
     40
     41#if defined(HAVE_FIPS) && \
     42        defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     43        #include <wolfssl/wolfcrypt/fips.h>
    3744#endif
    38 
    39 #if !defined(NO_SHA256) || defined(WOLFSSL_SHA224)
    40     #include <wolfssl/wolfcrypt/sha256.h>
    41 #endif
    42 
    43 #ifdef WOLFSSL_SHA512
    44     #include <wolfssl/wolfcrypt/sha512.h>
    45 #endif
    46 
    47 #ifdef HAVE_BLAKE2
    48     #include <wolfssl/wolfcrypt/blake2.h>
    49 #endif
    50 
    51 #ifdef HAVE_FIPS
    52 /* for fips */
    53     #include <cyassl/ctaocrypt/hmac.h>
    54 #endif
    55 
    5645
    5746#ifdef __cplusplus
    5847    extern "C" {
    5948#endif
    60 #ifndef HAVE_FIPS
     49
     50/* avoid redefinition of structs */
     51#if !defined(HAVE_FIPS) || \
     52    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    6153
    6254#ifdef WOLFSSL_ASYNC_CRYPT
    6355    #include <wolfssl/wolfcrypt/async.h>
     56#endif
     57
     58#ifndef NO_OLD_WC_NAMES
     59    #define HMAC_BLOCK_SIZE WC_HMAC_BLOCK_SIZE
    6460#endif
    6561
     
    7268/* If any hash is not enabled, add the ID here. */
    7369#ifdef NO_MD5
    74     WC_MD5     = 0,
     70    WC_MD5     = WC_HASH_TYPE_MD5,
    7571#endif
    7672#ifdef NO_SHA
    77     WC_SHA     = 1,
     73    WC_SHA     = WC_HASH_TYPE_SHA,
    7874#endif
    7975#ifdef NO_SHA256
    80     WC_SHA256  = 2,
     76    WC_SHA256  = WC_HASH_TYPE_SHA256,
    8177#endif
    8278#ifndef WOLFSSL_SHA512
    83     WC_SHA512  = 4,
     79    WC_SHA512  = WC_HASH_TYPE_SHA512,
    8480#endif
    8581#ifndef WOLFSSL_SHA384
    86     WC_SHA384  = 5,
     82    WC_SHA384  = WC_HASH_TYPE_SHA384,
    8783#endif
    8884#ifndef HAVE_BLAKE2
    89     BLAKE2B_ID = 7,
     85    BLAKE2B_ID = WC_HASH_TYPE_BLAKE2B,
    9086#endif
    9187#ifndef WOLFSSL_SHA224
    92     WC_SHA224  = 8,
     88    WC_SHA224  = WC_HASH_TYPE_SHA224,
    9389#endif
    94 
     90#ifndef WOLFSSL_SHA3
     91    WC_SHA3_224 = WC_HASH_TYPE_SHA3_224,
     92    WC_SHA3_256 = WC_HASH_TYPE_SHA3_256,
     93    WC_SHA3_384 = WC_HASH_TYPE_SHA3_384,
     94    WC_SHA3_512 = WC_HASH_TYPE_SHA3_512,
     95#endif
     96};
    9597
    9698/* Select the largest available hash for the buffer size. */
    97 #if defined(WOLFSSL_SHA512)
    98     MAX_DIGEST_SIZE = WC_SHA512_DIGEST_SIZE,
    99     HMAC_BLOCK_SIZE = WC_SHA512_BLOCK_SIZE,
    100 #elif defined(HAVE_BLAKE2)
    101     MAX_DIGEST_SIZE = BLAKE2B_OUTBYTES,
    102     HMAC_BLOCK_SIZE = BLAKE2B_BLOCKBYTES,
    103 #elif defined(WOLFSSL_SHA384)
    104     MAX_DIGEST_SIZE = WC_SHA384_DIGEST_SIZE,
    105     HMAC_BLOCK_SIZE = WC_SHA384_BLOCK_SIZE
    106 #elif !defined(NO_SHA256)
    107     MAX_DIGEST_SIZE = WC_SHA256_DIGEST_SIZE,
    108     HMAC_BLOCK_SIZE = WC_SHA256_BLOCK_SIZE
    109 #elif defined(WOLFSSL_SHA224)
    110     MAX_DIGEST_SIZE = WC_SHA224_DIGEST_SIZE,
    111     HMAC_BLOCK_SIZE = WC_SHA224_BLOCK_SIZE
    112 #elif !defined(NO_SHA)
    113     MAX_DIGEST_SIZE = WC_SHA_DIGEST_SIZE,
    114     HMAC_BLOCK_SIZE = WC_SHA_BLOCK_SIZE,
    115 #elif !defined(NO_MD5)
    116     MAX_DIGEST_SIZE = WC_MD5_DIGEST_SIZE,
    117     HMAC_BLOCK_SIZE = WC_MD5_BLOCK_SIZE,
    118 #else
     99#define WC_HMAC_BLOCK_SIZE WC_MAX_BLOCK_SIZE
     100
     101#if !defined(WOLFSSL_SHA3) && !defined(WOLFSSL_SHA512) && !defined(HAVE_BLAKE2) && \
     102    !defined(WOLFSSL_SHA384) && defined(NO_SHA256) && defined(WOLFSSL_SHA224) && \
     103     defined(NO_SHA) && defined(NO_MD5)
    119104    #error "You have to have some kind of hash if you want to use HMAC."
    120105#endif
    121 };
    122106
    123107
     
    136120    wc_Sha256 sha256;
    137121#endif
    138 #ifdef WOLFSSL_SHA512
    139122#ifdef WOLFSSL_SHA384
    140123    wc_Sha384 sha384;
    141124#endif
     125#ifdef WOLFSSL_SHA512
    142126    wc_Sha512 sha512;
    143127#endif
    144128#ifdef HAVE_BLAKE2
    145129    Blake2b blake2b;
     130#endif
     131#ifdef WOLFSSL_SHA3
     132    wc_Sha3 sha3;
    146133#endif
    147134} Hash;
     
    150137typedef struct Hmac {
    151138    Hash    hash;
    152     word32  ipad[HMAC_BLOCK_SIZE  / sizeof(word32)];  /* same block size all*/
    153     word32  opad[HMAC_BLOCK_SIZE  / sizeof(word32)];
    154     word32  innerHash[MAX_DIGEST_SIZE / sizeof(word32)];
     139    word32  ipad[WC_HMAC_BLOCK_SIZE  / sizeof(word32)];  /* same block size all*/
     140    word32  opad[WC_HMAC_BLOCK_SIZE  / sizeof(word32)];
     141    word32  innerHash[WC_MAX_DIGEST_SIZE / sizeof(word32)];
    155142    void*   heap;                 /* heap hint */
    156143    byte    macType;              /* md5 sha or sha256 */
     
    160147    WC_ASYNC_DEV asyncDev;
    161148    word16       keyLen;          /* hmac key length (key in ipad) */
    162     #ifdef HAVE_CAVIUM
    163         byte*    data;            /* buffered input data for one call */
    164         word16   dataLen;
    165     #endif /* HAVE_CAVIUM */
    166149#endif /* WOLFSSL_ASYNC_CRYPT */
    167150} Hmac;
     
    179162
    180163WOLFSSL_API int wolfSSL_GetHmacMaxSize(void);
     164
     165WOLFSSL_LOCAL int _InitHmac(Hmac* hmac, int type, void* heap);
    181166
    182167#ifdef HAVE_HKDF
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/idea.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/idea.h
     24*/
    2225
    2326#ifndef WOLF_CRYPT_IDEA_H
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/integer.h

    r352 r372  
    3434*/
    3535#include <wolfssl/wolfcrypt/types.h>       /* will set MP_xxBIT if not default */
    36 #ifdef USE_FAST_MATH
     36#ifdef WOLFSSL_SP_MATH
     37    #include <wolfssl/wolfcrypt/sp_int.h>
     38#elif defined(USE_FAST_MATH)
    3739    #include <wolfssl/wolfcrypt/tfm.h>
    3840#else
     
    6870
    6971/* C++ compilers don't like assigning void * to mp_digit * */
     72#define  OPT_CAST(x)  (x *)
     73
     74#elif defined(_SH3)
     75
     76/* SuperH SH3 compiler doesn't like assigning voi* to mp_digit* */
    7077#define  OPT_CAST(x)  (x *)
    7178
     
    249256#define mp_tomag(mp, str)         mp_to_unsigned_bin((mp), (str))
    250257
    251 #define mp_tobinary(M, S)  mp_toradix((M), (S), 2)
    252 #define mp_tooctal(M, S)   mp_toradix((M), (S), 8)
    253 #define mp_todecimal(M, S) mp_toradix((M), (S), 10)
    254 #define mp_tohex(M, S)     mp_toradix((M), (S), 16)
     258#define MP_RADIX_BIN  2
     259#define MP_RADIX_OCT  8
     260#define MP_RADIX_DEC  10
     261#define MP_RADIX_HEX  16
     262#define MP_RADIX_MAX  64
     263
     264#define mp_tobinary(M, S)  mp_toradix((M), (S), MP_RADIX_BIN)
     265#define mp_tooctal(M, S)   mp_toradix((M), (S), MP_RADIX_OCT)
     266#define mp_todecimal(M, S) mp_toradix((M), (S), MP_RADIX_DEC)
     267#define mp_tohex(M, S)     mp_toradix((M), (S), MP_RADIX_HEX)
    255268
    256269#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
    257270
     271#if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) || \
     272    defined(WOLFSSL_DEBUG_MATH) || defined(DEBUG_WOLFSSL)
    258273extern const char *mp_s_rmap;
     274#endif
    259275
    260276/* 6 functions needed by Rsa */
     
    267283MP_API int  mp_to_unsigned_bin_at_pos(int x, mp_int *t, unsigned char *b);
    268284MP_API int  mp_to_unsigned_bin (mp_int * a, unsigned char *b);
     285MP_API int  mp_to_unsigned_bin_len(mp_int * a, unsigned char *b, int c);
    269286MP_API int  mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y);
    270287/* end functions needed by Rsa */
     
    353370#endif
    354371
    355 #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
     372#if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || !defined(NO_RSA) || \
     373    !defined(NO_DSA) || !defined(NO_DH)
    356374    MP_API int mp_sqrmod(mp_int* a, mp_int* b, mp_int* c);
    357375#endif
    358 #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
     376#if !defined(NO_DSA) || defined(HAVE_ECC)
    359377    MP_API int mp_read_radix(mp_int* a, const char* str, int radix);
    360378#endif
    361379
     380#if defined(WOLFSSL_KEY_GEN) || !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH)
     381    MP_API int mp_prime_is_prime (mp_int * a, int t, int *result);
     382    MP_API int mp_prime_is_prime_ex (mp_int * a, int t, int *result, WC_RNG*);
     383#endif /* WOLFSSL_KEY_GEN NO_RSA NO_DSA NO_DH */
    362384#ifdef WOLFSSL_KEY_GEN
    363     MP_API int mp_prime_is_prime (mp_int * a, int t, int *result);
    364385    MP_API int mp_gcd (mp_int * a, mp_int * b, mp_int * c);
    365386    MP_API int mp_lcm (mp_int * a, mp_int * b, mp_int * c);
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/logging.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/logging.h
     24*/
     25
    2226
    2327/* submitted by eof */
     
    3438
    3539
    36 enum  CYA_Log_Levels {
     40enum wc_LogLevels {
    3741    ERROR_LOG = 0,
    3842    INFO_LOG,
     
    4246};
    4347
     48#ifdef WOLFSSL_FUNC_TIME
     49/* WARNING: This code is only to be used for debugging performance.
     50 *          The code is not thread-safe.
     51 *          Do not use WOLFSSL_FUNC_TIME in production code.
     52 */
     53enum wc_FuncNum {
     54    WC_FUNC_HELLO_REQUEST_SEND = 0,
     55    WC_FUNC_HELLO_REQUEST_DO,
     56    WC_FUNC_CLIENT_HELLO_SEND,
     57    WC_FUNC_CLIENT_HELLO_DO,
     58    WC_FUNC_SERVER_HELLO_SEND,
     59    WC_FUNC_SERVER_HELLO_DO,
     60    WC_FUNC_ENCRYPTED_EXTENSIONS_SEND,
     61    WC_FUNC_ENCRYPTED_EXTENSIONS_DO,
     62    WC_FUNC_CERTIFICATE_REQUEST_SEND,
     63    WC_FUNC_CERTIFICATE_REQUEST_DO,
     64    WC_FUNC_CERTIFICATE_SEND,
     65    WC_FUNC_CERTIFICATE_DO,
     66    WC_FUNC_CERTIFICATE_VERIFY_SEND,
     67    WC_FUNC_CERTIFICATE_VERIFY_DO,
     68    WC_FUNC_FINISHED_SEND,
     69    WC_FUNC_FINISHED_DO,
     70    WC_FUNC_KEY_UPDATE_SEND,
     71    WC_FUNC_KEY_UPDATE_DO,
     72    WC_FUNC_EARLY_DATA_SEND,
     73    WC_FUNC_EARLY_DATA_DO,
     74    WC_FUNC_NEW_SESSION_TICKET_SEND,
     75    WC_FUNC_NEW_SESSION_TICKET_DO,
     76    WC_FUNC_SERVER_HELLO_DONE_SEND,
     77    WC_FUNC_SERVER_HELLO_DONE_DO,
     78    WC_FUNC_TICKET_SEND,
     79    WC_FUNC_TICKET_DO,
     80    WC_FUNC_CLIENT_KEY_EXCHANGE_SEND,
     81    WC_FUNC_CLIENT_KEY_EXCHANGE_DO,
     82    WC_FUNC_CERTIFICATE_STATUS_SEND,
     83    WC_FUNC_CERTIFICATE_STATUS_DO,
     84    WC_FUNC_SERVER_KEY_EXCHANGE_SEND,
     85    WC_FUNC_SERVER_KEY_EXCHANGE_DO,
     86    WC_FUNC_END_OF_EARLY_DATA_SEND,
     87    WC_FUNC_END_OF_EARLY_DATA_DO,
     88    WC_FUNC_COUNT
     89};
     90#endif
     91
    4492typedef void (*wolfSSL_Logging_cb)(const int logLevel,
    4593                                  const char *const logMessage);
    4694
    4795WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
     96
     97/* turn logging on, only if compiled in */
     98WOLFSSL_API int  wolfSSL_Debugging_ON(void);
     99/* turn logging off */
     100WOLFSSL_API void wolfSSL_Debugging_OFF(void);
     101
    48102
    49103#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
     
    56110    WOLFSSL_LOCAL void wc_RemoveErrorNode(int index);
    57111    WOLFSSL_LOCAL void wc_ClearErrorNodes(void);
     112    WOLFSSL_LOCAL int wc_PullErrorNode(const char **file, const char **reason,
     113                            int *line);
    58114    WOLFSSL_API   int wc_SetLoggingHeap(void* h);
     115    WOLFSSL_API   int wc_ERR_remove_state(void);
    59116    #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
    60         WOLFSSL_API   void wc_ERR_print_errors_fp(FILE* fp);
     117        WOLFSSL_API   void wc_ERR_print_errors_fp(XFILE fp);
    61118    #endif
    62 #endif /* defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE) */
     119#endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
    63120
    64 #ifdef DEBUG_WOLFSSL
     121#ifdef WOLFSSL_FUNC_TIME
     122    /* WARNING: This code is only to be used for debugging performance.
     123     *          The code is not thread-safe.
     124     *          Do not use WOLFSSL_FUNC_TIME in production code.
     125     */
     126    WOLFSSL_API void WOLFSSL_START(int funcNum);
     127    WOLFSSL_API void WOLFSSL_END(int funcNum);
     128    WOLFSSL_API void WOLFSSL_TIME(int count);
     129#else
     130    #define WOLFSSL_START(n)
     131    #define WOLFSSL_END(n)
     132    #define WOLFSSL_TIME(n)
     133#endif
     134
     135#if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_DEBUG_ERRORS_ONLY)
    65136    #if defined(_WIN32)
    66137        #if defined(INTIME_RTOS)
     
    74145    #define WOLFSSL_LOG_CAT(a, m, b) #a " " m " "  #b
    75146
    76     void WOLFSSL_ENTER(const char* msg);
    77     void WOLFSSL_LEAVE(const char* msg, int ret);
     147    WOLFSSL_API void WOLFSSL_ENTER(const char* msg);
     148    WOLFSSL_API void WOLFSSL_LEAVE(const char* msg, int ret);
    78149    #define WOLFSSL_STUB(m) \
    79150        WOLFSSL_MSG(WOLFSSL_LOG_CAT(wolfSSL Stub, m, not implemented))
    80151
    81     void WOLFSSL_MSG(const char* msg);
    82     void WOLFSSL_BUFFER(const byte* buffer, word32 length);
     152    WOLFSSL_API void WOLFSSL_MSG(const char* msg);
     153    WOLFSSL_API void WOLFSSL_BUFFER(const byte* buffer, word32 length);
    83154
    84 #else /* DEBUG_WOLFSSL   */
     155#else
    85156
    86157    #define WOLFSSL_ENTER(m)
     
    91162    #define WOLFSSL_BUFFER(b, l)
    92163
    93 #endif /* DEBUG_WOLFSSL */
     164#endif /* DEBUG_WOLFSSL && !WOLFSSL_DEBUG_ERRORS_ONLY */
    94165
    95 #if (defined(DEBUG_WOLFSSL) || defined(WOLFSSL_NGINX)) || defined(WOLFSSL_HAPROXY)
    96     #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE))
    97     void WOLFSSL_ERROR_LINE(int err, const char* func, unsigned int line,
     166#if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
     167
     168    #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
     169        WOLFSSL_API void WOLFSSL_ERROR_LINE(int err, const char* func, unsigned int line,
    98170            const char* file, void* ctx);
    99     #define WOLFSSL_ERROR(x) WOLFSSL_ERROR_LINE((x), __func__, __LINE__, __FILE__,NULL)
     171        #define WOLFSSL_ERROR(x) \
     172            WOLFSSL_ERROR_LINE((x), __func__, __LINE__, __FILE__, NULL)
    100173    #else
    101     void WOLFSSL_ERROR(int);
     174        WOLFSSL_API void WOLFSSL_ERROR(int err);
    102175    #endif
     176    WOLFSSL_API void WOLFSSL_ERROR_MSG(const char* msg);
     177
    103178#else
    104179    #define WOLFSSL_ERROR(e)
     180    #define WOLFSSL_ERROR_MSG(m)
    105181#endif
    106182
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/md2.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/md2.h
     24*/
     25
    2226
    2327#ifndef WOLF_CRYPT_MD2_H
     
    3438/* in bytes */
    3539enum {
    36     MD2             =  6,    /* hash type unique */
     40    MD2             =  WC_HASH_TYPE_MD2,
    3741    MD2_BLOCK_SIZE  = 16,
    3842    MD2_DIGEST_SIZE = 16,
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/md4.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/md4.h
     24*/
    2225
    2326#ifndef WOLF_CRYPT_MD4_H
     
    3437/* in bytes */
    3538enum {
     39    MD4             =  WC_HASH_TYPE_MD4,
    3640    MD4_BLOCK_SIZE  = 64,
    3741    MD4_DIGEST_SIZE = 16,
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/md5.h

    r352 r372  
    1919 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
    2020 */
     21
     22/*!
     23    \file wolfssl/wolfcrypt/md5.h
     24*/
    2125
    2226
     
    4953/* in bytes */
    5054enum {
    51     WC_MD5             =  0,      /* hash type unique */
     55    WC_MD5             =  WC_HASH_TYPE_MD5,
    5256    WC_MD5_BLOCK_SIZE  = 64,
    5357    WC_MD5_DIGEST_SIZE = 16,
     
    5559};
    5660
     61
    5762#ifdef WOLFSSL_MICROCHIP_PIC32MZ
    5863    #include <wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h>
     64#endif
     65#ifdef STM32_HASH
     66    #include <wolfssl/wolfcrypt/port/st/stm32.h>
    5967#endif
    6068#ifdef WOLFSSL_ASYNC_CRYPT
     
    6472#ifdef WOLFSSL_TI_HASH
    6573    #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
     74#elif defined(WOLFSSL_IMX6_CAAM)
     75    #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
    6676#else
    6777
    6878/* MD5 digest */
    6979typedef struct wc_Md5 {
     80#ifdef STM32_HASH
     81    STM32_HASH_Context stmCtx;
     82#else
    7083    word32  buffLen;   /* in bytes          */
    7184    word32  loLen;     /* length in bytes   */
     
    8194    hashUpdCache cache; /* cache for updates */
    8295#endif
    83 #if defined(STM32_HASH) && defined(WOLFSSL_STM32_CUBEMX)
    84     HASH_HandleTypeDef hashHandle;
    85 #endif
     96#endif /* STM32_HASH */
    8697#ifdef WOLFSSL_ASYNC_CRYPT
    8798    WC_ASYNC_DEV asyncDev;
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/memory.h

    r352 r372  
    2323/* submitted by eof */
    2424
     25/*!
     26    \file wolfssl/wolfcrypt/memory.h
     27*/
    2528
    2629#ifndef WOLFSSL_MEMORY_H
     
    3235#ifdef __cplusplus
    3336    extern "C" {
     37#endif
     38
     39#ifdef WOLFSSL_FORCE_MALLOC_FAIL_TEST
     40    WOLFSSL_API void wolfSSL_SetMemFailCount(int memFailCount);
    3441#endif
    3542
     
    7582                                      wolfSSL_Free_cb,
    7683                                      wolfSSL_Realloc_cb);
    77 
    7884WOLFSSL_API int wolfSSL_GetAllocators(wolfSSL_Malloc_cb*,
    7985                                      wolfSSL_Free_cb*,
     
    8995    #endif
    9096    #define WOLFMEM_DEF_BUCKETS  9     /* number of default memory blocks */
     97    #ifndef WOLFMEM_IO_SZ
    9198    #define WOLFMEM_IO_SZ        16992 /* 16 byte aligned */
     99    #endif
    92100    #ifndef WOLFMEM_BUCKETS
    93         /* default size of chunks of memory to seperate into
    94          * having session certs enabled makes a 21k SSL struct */
    95101        #ifndef SESSION_CERTS
     102            /* default size of chunks of memory to separate into */
    96103            #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,16128
     104        #elif defined (WOLFSSL_CERT_EXT)
     105            /* certificate extensions requires 24k for the SSL struct */
     106            #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,24576
    97107        #else
    98             #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,21056
     108            /* increase 23k for object member of WOLFSSL_X509_NAME_ENTRY */
     109            #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,23440
    99110        #endif
    100111    #endif
    101112    #ifndef WOLFMEM_DIST
    102         #define WOLFMEM_DIST    8,4,4,12,4,5,8,1,1
     113        #define WOLFMEM_DIST    49,10,6,14,5,6,9,1,1
    103114    #endif
    104115
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/misc.h

    r352 r372  
    9292word32 btoi(byte b);
    9393
     94
     95WOLFSSL_LOCAL byte ctMaskGT(int a, int b);
     96WOLFSSL_LOCAL byte ctMaskGTE(int a, int b);
     97WOLFSSL_LOCAL byte ctMaskLT(int a, int b);
     98WOLFSSL_LOCAL byte ctMaskLTE(int a, int b);
     99WOLFSSL_LOCAL byte ctMaskEq(int a, int b);
     100WOLFSSL_LOCAL byte ctMaskNotEq(int a, int b);
     101WOLFSSL_LOCAL byte ctMaskSel(byte m, byte a, byte b);
     102WOLFSSL_LOCAL int  ctMaskSelInt(byte m, int a, int b);
     103WOLFSSL_LOCAL byte ctSetLTE(int a, int b);
     104
    94105#endif /* NO_INLINE */
    95106
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/pkcs12.h

    r352 r372  
    4040} WC_DerCertList;
    4141
    42 
     42/* default values for creating PKCS12 */
     43enum {
     44    WC_PKCS12_ITT_DEFAULT = 2048,
     45    WC_PKCS12_MAC_DEFAULT = 1,
     46};
    4347
    4448WOLFSSL_API WC_PKCS12* wc_PKCS12_new(void);
     
    4852        byte** pkey, word32* pkeySz, byte** cert, word32* certSz,
    4953        WC_DerCertList** ca);
     54WOLFSSL_API WC_PKCS12* wc_PKCS12_create(char* pass, word32 passSz,
     55        char* name, byte* key, word32 keySz, byte* cert, word32 certSz,
     56        WC_DerCertList* ca, int nidKey, int nidCert, int iter, int macIter,
     57        int keyType, void* heap);
     58
    5059
    5160WOLFSSL_LOCAL int wc_PKCS12_SetHeap(WC_PKCS12* pkcs12, void* heap);
    5261WOLFSSL_LOCAL void* wc_PKCS12_GetHeap(WC_PKCS12* pkcs12);
    5362
     63WOLFSSL_LOCAL void wc_FreeCertList(WC_DerCertList* list, void* heap);
    5464
    5565#ifdef __cplusplus
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/pwdbased.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/pwdbased.h
     24*/
    2225
    2326#ifndef WOLF_CRYPT_PWDBASED_H
     
    2831#ifndef NO_PWDBASED
    2932
    30 #ifndef NO_MD5
    31     #include <wolfssl/wolfcrypt/md5.h>       /* for hash type */
    32 #endif
    33 
    34 #include <wolfssl/wolfcrypt/sha.h>
    3533
    3634#ifdef __cplusplus
     
    4240 * wolfssl/wolfcrypt/asn.h line 173 in enum Oid_Types
    4341 */
     42WOLFSSL_API int wc_PBKDF1_ex(byte* key, int keyLen, byte* iv, int ivLen,
     43                      const byte* passwd, int passwdLen,
     44                      const byte* salt, int saltLen, int iterations,
     45                      int hashType, void* heap);
    4446WOLFSSL_API int wc_PBKDF1(byte* output, const byte* passwd, int pLen,
    4547                      const byte* salt, int sLen, int iterations, int kLen,
     
    6163#endif
    6264
    63 /* helper functions */
    64 WOLFSSL_LOCAL int GetDigestSize(int typeH);
    65 WOLFSSL_LOCAL int GetPKCS12HashSizes(int typeH, word32* v, word32* u);
    66 WOLFSSL_LOCAL int DoPKCS12Hash(int typeH, byte* buffer, word32 totalLen,
    67                                byte* Ai, word32 u, int iterations);
    68 
    6965
    7066#ifdef __cplusplus
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/rabbit.h

    r352 r372  
    1919 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
    2020 */
     21
     22/*!
     23    \file wolfssl/wolfcrypt/rabbit.h
     24*/
    2125
    2226
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/random.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/random.h
     24*/
     25
    2226
    2327
     
    2731#include <wolfssl/wolfcrypt/types.h>
    2832
    29 #ifdef HAVE_FIPS
    30 /* for fips @wc_fips */
     33#if defined(HAVE_FIPS) && \
     34    defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     35    #include <wolfssl/wolfcrypt/fips.h>
     36#endif /* HAVE_FIPS_VERSION >= 2 */
     37
     38/* included for fips @wc_fips */
     39#if defined(HAVE_FIPS) && \
     40        (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
    3141#include <cyassl/ctaocrypt/random.h>
    3242#endif
     
    5868/* make sure Hash DRBG is enabled, unless WC_NO_HASHDRBG is defined
    5969    or CUSTOM_RAND_GENERATE_BLOCK is defined*/
    60 #if !defined(WC_NO_HASHDRBG) || !defined(CUSTOM_RAND_GENERATE_BLOCK)
     70#if !defined(WC_NO_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
    6171    #undef  HAVE_HASHDRBG
    6272    #define HAVE_HASHDRBG
     
    6777
    6878
    69 #ifndef HAVE_FIPS /* avoid redefining structs and macros */
     79/* avoid redefinition of structs */
     80#if !defined(HAVE_FIPS) || \
     81    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    7082
    7183/* RNG supports the following sources (in order):
     
    95107#elif defined(HAVE_WNR)
    96108     /* allow whitewood as direct RNG source using wc_GenerateSeed directly */
    97 #else
     109#elif defined(HAVE_INTEL_RDRAND)
     110    /* Intel RDRAND or RDSEED */
     111#elif !defined(WC_NO_RNG)
    98112    #error No RNG source defined!
    99113#endif
     
    131145    typedef struct WC_RNG WC_RNG;
    132146    #define WC_RNG_TYPE_DEFINED
    133 #endif
    134 
    135 #ifdef HAVE_HASHDRBG
    136     /* Private DRBG state */
    137     struct DRBG;
    138147#endif
    139148
     
    153162};
    154163
    155 #endif /* HAVE_FIPS */
     164#endif /* NO FIPS or have FIPS v2*/
    156165
    157166/* NO_OLD_RNGNAME removes RNG struct name to prevent possible type conflicts,
     
    172181#endif /* HAVE_WNR */
    173182
    174 
     183#ifndef WC_NO_RNG
    175184WOLFSSL_API int  wc_InitRng(WC_RNG*);
    176185WOLFSSL_API int  wc_InitRng_ex(WC_RNG* rng, void* heap, int devId);
     186WOLFSSL_API int  wc_InitRngNonce(WC_RNG* rng, byte* nonce, word32 nonceSz);
     187WOLFSSL_API int  wc_InitRngNonce_ex(WC_RNG* rng, byte* nonce, word32 nonceSz,
     188                                    void* heap, int devId);
    177189WOLFSSL_API int  wc_RNG_GenerateBlock(WC_RNG*, byte*, word32 sz);
    178190WOLFSSL_API int  wc_RNG_GenerateByte(WC_RNG*, byte*);
    179191WOLFSSL_API int  wc_FreeRng(WC_RNG*);
     192#else
     193#include <wolfssl/wolfcrypt/error-crypt.h>
     194#define wc_InitRng(rng) NOT_COMPILED_IN
     195#define wc_InitRng_ex(rng, h, d) NOT_COMPILED_IN
     196#define wc_InitRngNonce(rng, n, s) NOT_COMPILED_IN
     197#define wc_InitRngNonce_ex(rng, n, s, h, d) NOT_COMPILED_IN
     198#define wc_RNG_GenerateBlock(rng, b, s) NOT_COMPILED_IN
     199#define wc_RNG_GenerateByte(rng, b) NOT_COMPILED_IN
     200#define wc_FreeRng(rng) (void)NOT_COMPILED_IN
     201#endif
     202
    180203
    181204
    182205#ifdef HAVE_HASHDRBG
     206    WOLFSSL_LOCAL int wc_RNG_DRBG_Reseed(WC_RNG* rng, const byte* entropy,
     207                                        word32 entropySz);
     208    WOLFSSL_API int wc_RNG_TestSeed(const byte* seed, word32 seedSz);
    183209    WOLFSSL_API int wc_RNG_HealthTest(int reseed,
    184210                                        const byte* entropyA, word32 entropyASz,
    185211                                        const byte* entropyB, word32 entropyBSz,
    186212                                        byte* output, word32 outputSz);
     213    WOLFSSL_API int wc_RNG_HealthTest_ex(int reseed,
     214                                        const byte* nonce, word32 nonceSz,
     215                                        const byte* entropyA, word32 entropyASz,
     216                                        const byte* entropyB, word32 entropyBSz,
     217                                        byte* output, word32 outputSz,
     218                                        void* heap, int devId);
    187219#endif /* HAVE_HASHDRBG */
    188220
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/ripemd.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/ripemd.h
     24*/
    2225
    2326#ifndef WOLF_CRYPT_RIPEMD_H
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/rsa.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/rsa.h
     24*/
     25
    2226
    2327#ifndef WOLF_CRYPT_RSA_H
     
    2731
    2832#ifndef NO_RSA
     33
     34
     35/* RSA default exponent */
     36#ifndef WC_RSA_EXPONENT
     37    #define WC_RSA_EXPONENT 65537L
     38#endif
     39
     40#if defined(WC_RSA_NONBLOCK)
     41    /* enable support for fast math based non-blocking exptmod */
     42    /* this splits the RSA function into many smaller operations */
     43    #ifndef USE_FAST_MATH
     44        #error RSA non-blocking mode only supported using fast math
     45    #endif
     46    #ifndef TFM_TIMING_RESISTANT
     47      #error RSA non-blocking mode only supported with timing resistance enabled
     48    #endif
     49
     50    /* RSA bounds check is not supported with RSA non-blocking mode */
     51    #undef  NO_RSA_BOUNDS_CHECK
     52    #define NO_RSA_BOUNDS_CHECK
     53#endif
    2954
    3055/* allow for user to plug in own crypto */
     
    3358#else
    3459
    35 #ifdef HAVE_FIPS
     60#if defined(HAVE_FIPS) && \
     61        (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
    3662/* for fips @wc_fips */
    3763#include <cyassl/ctaocrypt/rsa.h>
     
    4268    #include <wolfssl/wolfcrypt/integer.h>
    4369    #include <wolfssl/wolfcrypt/random.h>
    44 #endif /* HAVE_FIPS */
     70#endif /* HAVE_FIPS && HAVE_FIPS_VERION 1 */
     71#if defined(HAVE_FIPS) && \
     72        defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     73#include <wolfssl/wolfcrypt/fips.h>
     74#endif
    4575
    4676/* header file needed for OAEP padding */
     
    5585#endif
    5686
     87enum {
     88    RSA_MIN_SIZE = 512,
     89    RSA_MAX_SIZE = 4096,
     90};
     91
    5792/* avoid redefinition of structs */
    58 #if !defined(HAVE_FIPS)
     93#if !defined(HAVE_FIPS) || \
     94    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    5995
    6096#ifdef WOLFSSL_ASYNC_CRYPT
     
    78114    RSA_BLOCK_TYPE_2 = 2,
    79115
    80     RSA_MIN_SIZE = 512,
    81     RSA_MAX_SIZE = 4096,
    82 
    83116    RSA_MIN_PAD_SZ   = 11,     /* separator + 0 + pad value + 8 pads */
    84117
    85118    RSA_PSS_PAD_SZ = 8,
     119    RSA_PSS_SALT_MAX_SZ = 62,
    86120
    87121#ifdef OPENSSL_EXTRA
    88122    RSA_PKCS1_PADDING_SIZE = 11,
    89     RSA_PKCS1_OAEP_PADDING_SIZE = 42 /* (2 * hashlen(SHA-1)) + 2 */
     123    RSA_PKCS1_OAEP_PADDING_SIZE = 42, /* (2 * hashlen(SHA-1)) + 2 */
     124#endif
     125#ifdef WC_RSA_PSS
     126    RSA_PSS_PAD_TERM = 0xBC,
     127#endif
     128
     129#ifdef HAVE_PKCS11
     130    RSA_MAX_ID_LEN      = 32,
    90131  #endif
    91132};
    92133
     134#ifdef WC_RSA_NONBLOCK
     135typedef struct RsaNb {
     136    exptModNb_t exptmod; /* non-block expt_mod */
     137    mp_int tmp;
     138} RsaNb;
     139#endif
    93140
    94141/* RSA */
    95142struct RsaKey {
    96     mp_int n, e, d, p, q, dP, dQ, u;
     143    mp_int n, e;
     144#ifndef WOLFSSL_RSA_PUBLIC_ONLY
     145    mp_int d, p, q;
     146#if defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || !defined(RSA_LOW_MEM)
     147    mp_int dP, dQ, u;
     148#endif
     149#endif
    97150    void* heap;                               /* for user memory overrides */
    98151    byte* data;                               /* temp buffer for async RSA */
     
    103156    WC_RNG* rng;                              /* for PrivateDecrypt blinding */
    104157#endif
     158#ifdef WOLF_CRYPTO_DEV
     159    int   devId;
     160#endif
    105161#ifdef WOLFSSL_ASYNC_CRYPT
    106162    WC_ASYNC_DEV asyncDev;
     
    114170    XSecure_Rsa xRsa;
    115171#endif
     172#ifdef HAVE_PKCS11
     173    byte id[RSA_MAX_ID_LEN];
     174    int  idLen;
     175#endif
     176#if defined(WOLFSSL_ASYNC_CRYPT) || !defined(WOLFSSL_RSA_VERIFY_INLINE)
    116177    byte   dataIsAlloc;
     178#endif
     179#ifdef WC_RSA_NONBLOCK
     180    RsaNb* nb;
     181#endif
    117182};
    118183
     
    127192WOLFSSL_API int  wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId);
    128193WOLFSSL_API int  wc_FreeRsaKey(RsaKey* key);
     194#ifdef HAVE_PKCS11
     195WOLFSSL_API int wc_InitRsaKey_Id(RsaKey* key, unsigned char* id, int len,
     196                                 void* heap, int devId);
     197#endif
     198WOLFSSL_API int  wc_CheckRsaKey(RsaKey* key);
    129199#ifdef WOLFSSL_XILINX_CRYPT
    130200WOLFSSL_LOCAL int wc_InitRsaHw(RsaKey* key);
    131201#endif /* WOLFSSL_XILINX_CRYPT */
    132202
    133 WOLFSSL_LOCAL int wc_RsaFunction(const byte* in, word32 inLen, byte* out,
     203WOLFSSL_API int wc_RsaFunction(const byte* in, word32 inLen, byte* out,
    134204                           word32* outLen, int type, RsaKey* key, WC_RNG* rng);
    135205
     
    145215                                word32 outLen, enum wc_HashType hash, int mgf,
    146216                                RsaKey* key, WC_RNG* rng);
     217WOLFSSL_API int  wc_RsaPSS_Sign_ex(const byte* in, word32 inLen, byte* out,
     218                                   word32 outLen, enum wc_HashType hash,
     219                                   int mgf, int saltLen, RsaKey* key,
     220                                   WC_RNG* rng);
    147221WOLFSSL_API int  wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out,
    148222                                    RsaKey* key);
     
    152226                                        enum wc_HashType hash, int mgf,
    153227                                        RsaKey* key);
     228WOLFSSL_API int  wc_RsaPSS_VerifyInline_ex(byte* in, word32 inLen, byte** out,
     229                                           enum wc_HashType hash, int mgf,
     230                                           int saltLen, RsaKey* key);
     231WOLFSSL_API int  wc_RsaPSS_Verify(byte* in, word32 inLen, byte* out,
     232                                  word32 outLen, enum wc_HashType hash, int mgf,
     233                                  RsaKey* key);
     234WOLFSSL_API int  wc_RsaPSS_Verify_ex(byte* in, word32 inLen, byte* out,
     235                                     word32 outLen, enum wc_HashType hash,
     236                                     int mgf, int saltLen, RsaKey* key);
    154237WOLFSSL_API int  wc_RsaPSS_CheckPadding(const byte* in, word32 inLen, byte* sig,
    155238                                        word32 sigSz,
    156239                                        enum wc_HashType hashType);
     240WOLFSSL_API int  wc_RsaPSS_CheckPadding_ex(const byte* in, word32 inLen,
     241                                           byte* sig, word32 sigSz,
     242                                           enum wc_HashType hashType,
     243                                           int saltLen, int bits);
     244WOLFSSL_API int  wc_RsaPSS_VerifyCheckInline(byte* in, word32 inLen, byte** out,
     245                               const byte* digest, word32 digentLen,
     246                               enum wc_HashType hash, int mgf,
     247                               RsaKey* key);
     248WOLFSSL_API int  wc_RsaPSS_VerifyCheck(byte* in, word32 inLen,
     249                               byte* out, word32 outLen,
     250                               const byte* digest, word32 digestLen,
     251                               enum wc_HashType hash, int mgf,
     252                               RsaKey* key);
    157253
    158254WOLFSSL_API int  wc_RsaEncryptSize(RsaKey* key);
    159255
    160 #ifndef HAVE_FIPS /* to avoid asn duplicate symbols @wc_fips */
     256#if !defined(HAVE_FIPS) || \
     257        (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
     258/* to avoid asn duplicate symbols @wc_fips */
    161259WOLFSSL_API int  wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
    162260                                                               RsaKey*, word32);
     
    169267#endif
    170268
     269#ifdef WC_RSA_BLINDING
    171270WOLFSSL_API int wc_RsaSetRNG(RsaKey* key, WC_RNG* rng);
     271#endif
     272#ifdef WC_RSA_NONBLOCK
     273    WOLFSSL_API int wc_RsaSetNonBlock(RsaKey* key, RsaNb* nb);
     274    #ifdef WC_RSA_NONBLOCK_TIME
     275    WOLFSSL_API int wc_RsaSetNonBlockTime(RsaKey* key, word32 maxBlockUs,
     276                                          word32 cpuMHz);
     277    #endif
     278#endif
    172279
    173280/*
     
    187294#define WC_RSA_OAEP_PAD    1
    188295#define WC_RSA_PSS_PAD     2
     296#define WC_RSA_NO_PAD      3
    189297
    190298WOLFSSL_API int  wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out,
     
    197305                      byte** out, RsaKey* key, int type, enum wc_HashType hash,
    198306                      int mgf, byte* label, word32 lableSz);
     307#if defined(WC_RSA_DIRECT) || defined(WC_RSA_NO_PADDING)
     308WOLFSSL_API int wc_RsaDirect(byte* in, word32 inLen, byte* out, word32* outSz,
     309                   RsaKey* key, int type, WC_RNG* rng);
     310#endif
     311
    199312#endif /* HAVE_FIPS*/
     313
    200314WOLFSSL_API int  wc_RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*,
    201315                                                                       word32*);
     316WOLFSSL_API int wc_RsaExportKey(RsaKey* key,
     317                                byte* e, word32* eSz,
     318                                byte* n, word32* nSz,
     319                                byte* d, word32* dSz,
     320                                byte* p, word32* pSz,
     321                                byte* q, word32* qSz);
     322
     323    WOLFSSL_API int wc_RsaKeyToPublicDer(RsaKey*, byte* output, word32 inLen);
    202324
    203325#ifdef WOLFSSL_KEY_GEN
    204     WOLFSSL_API int wc_RsaKeyToPublicDer(RsaKey*, byte* output, word32 inLen);
    205326    WOLFSSL_API int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng);
     327    WOLFSSL_API int wc_CheckProbablePrime_ex(const byte* p, word32 pSz,
     328                                          const byte* q, word32 qSz,
     329                                          const byte* e, word32 eSz,
     330                                          int nlen, int* isPrime, WC_RNG* rng);
     331    WOLFSSL_API int wc_CheckProbablePrime(const byte* p, word32 pSz,
     332                                          const byte* q, word32 qSz,
     333                                          const byte* e, word32 eSz,
     334                                          int nlen, int* isPrime);
    206335#endif
    207336
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/settings.h

    r352 r372  
    7777/* #define WOLFSSL_LSR */
    7878
     79/* Uncomment next line if building for Freescale Classic MQX version 4.0 */
     80/* #define FREESCALE_MQX_4_0 */
     81
    7982/* Uncomment next line if building for Freescale Classic MQX/RTCS/MFS */
    8083/* #define FREESCALE_MQX */
     
    8689/* #define FREESCALE_KSDK_BM */
    8790
    88 /* Uncomment next line if building for Freescale KSDK FreeRTOS (old name FREESCALE_FREE_RTOS) */
     91/* Uncomment next line if building for Freescale KSDK FreeRTOS, */
     92/* (old name FREESCALE_FREE_RTOS) */
    8993/* #define FREESCALE_KSDK_FREERTOS */
    9094
     
    9498/* Uncomment next line if using STM32F4 */
    9599/* #define WOLFSSL_STM32F4 */
     100
     101/* Uncomment next line if using STM32FL */
     102/* #define WOLFSSL_STM32FL */
    96103
    97104/* Uncomment next line if using STM32F7 */
     
    162169/* Uncomment next line if building for using XILINX */
    163170/* #define WOLFSSL_XILINX */
     171
     172/* Uncomment next line if building for Nucleus 1.2 */
     173/* #define WOLFSSL_NUCLEUS_1_2 */
     174
     175/* Uncomment next line if building for using Apache mynewt */
     176/* #define WOLFSSL_APACHE_MYNEWT */
     177
     178/* Uncomment next line if building for using ESP-IDF */
     179/* #define WOLFSSL_ESPIDF */
     180
     181/* Uncomment next line if using Espressif ESP32-WROOM-32 */
     182/* #define WOLFSSL_ESPWROOM32 */
    164183
    165184#include <wolfssl/wolfcrypt/visibility.h>
     
    203222    #include <nx_api.h>
    204223#endif
     224
     225#if defined(WOLFSSL_ESPIDF)
     226    #define FREERTOS
     227    #define WOLFSSL_LWIP
     228    #define NO_WRITEV
     229    #define SIZEOF_LONG_LONG 8
     230    #define NO_WOLFSSL_DIR
     231    #define WOLFSSL_NO_CURRDIR
     232
     233    #define TFM_TIMING_RESISTANT
     234    #define ECC_TIMING_RESISTANT
     235    #define WC_RSA_BLINDING
     236#if !defined(WOLFSSL_USER_SETTINGS)
     237    #define HAVE_ECC
     238#endif /* !WOLFSSL_USER_SETTINGS */
     239#endif /* WOLFSSL_ESPIDF */
    205240
    206241#if defined(HAVE_LWIP_NATIVE) /* using LwIP native TCP socket */
     
    210245    #define WOLFSSL_USER_IO
    211246    #define NO_FILESYSTEM
     247#endif
     248
     249#if defined(WOLFSSL_CONTIKI)
     250    #include <contiki.h>
     251    #define WOLFSSL_UIP
     252    #define NO_WOLFSSL_MEMORY
     253    #define NO_WRITEV
     254    #define SINGLE_THREADED
     255    #define WOLFSSL_USER_IO
     256    #define NO_FILESYSTEM
     257    #define CUSTOM_RAND_TYPE uint16_t
     258    #define CUSTOM_RAND_GENERATE random_rand
     259    static inline unsigned int LowResTimer(void)
     260    {
     261        return clock_seconds();
     262    }
    212263#endif
    213264
     
    241292
    242293#ifdef WOLFSSL_MICROCHIP_PIC32MZ
     294    #ifndef NO_PIC32MZ_CRYPT
    243295    #define WOLFSSL_PIC32MZ_CRYPT
     296    #endif
     297    #ifndef NO_PIC32MZ_RNG
    244298    #define WOLFSSL_PIC32MZ_RNG
     299    #endif
     300    #ifndef NO_PIC32MZ_HASH
    245301    #define WOLFSSL_PIC32MZ_HASH
     302#endif
    246303#endif
    247304
     
    342399        #define TFM_NO_ASM
    343400    #endif
    344     #define WOLFSSL_PTHREADS
     401    /* For VxWorks pthreads wrappers for mutexes uncomment the next line. */
     402    /* #define WOLFSSL_PTHREADS */
    345403    #define WOLFSSL_HAVE_MIN
    346404    #define WOLFSSL_HAVE_MAX
     
    441499    #define NO_FILESYSTEM
    442500    #define USE_CERT_BUFFERS_2048
     501#endif
     502
     503#ifdef WOLFSSL_CHIBIOS
     504    /* ChibiOS definitions. This file is distributed with chibiOS. */
     505    #include "wolfssl_chibios.h"
     506#endif
     507
     508#ifdef WOLFSSL_PB
     509    /* PB is using older 1.2 version of Nucleus */
     510    #undef WOLFSSL_NUCLEUS
     511    #define WOLFSSL_NUCLEUS_1_2
     512#endif
     513
     514#ifdef WOLFSSL_NUCLEUS_1_2
     515    #define NO_WRITEV
     516    #define NO_WOLFSSL_DIR
     517
     518    #if !defined(NO_ASN_TIME) && !defined(USER_TIME)
     519        #error User must define XTIME, see manual
     520    #endif
     521
     522    #if !defined(XMALLOC_OVERRIDE) && !defined(XMALLOC_USER)
     523        extern void* nucleus_malloc(unsigned long size, void* heap, int type);
     524        extern void* nucleus_realloc(void* ptr, unsigned long size, void* heap,
     525                                     int type);
     526        extern void  nucleus_free(void* ptr, void* heap, int type);
     527
     528        #define XMALLOC(s, h, type)  nucleus_malloc((s), (h), (type))
     529        #define XREALLOC(p, n, h, t) nucleus_realloc((p), (n), (h), (t))
     530        #define XFREE(p, h, type)    nucleus_free((p), (h), (type))
     531    #endif
    443532#endif
    444533
     
    499588
    500589    /* static char* gets(char *buff); */
    501     static char* fgets(char *buff, int sz, FILE *fp) {
     590    static char* fgets(char *buff, int sz, XFILE fp) {
    502591        char * p = buff;
    503592        *p = '\0';
     
    539628
    540629    /* FreeRTOS pvPortRealloc() only in AVR32_UC3 port */
    541     #if !defined(XMALLOC_USER) && !defined(NO_WOLFSSL_MEMORY)
     630    #if !defined(XMALLOC_USER) && !defined(NO_WOLFSSL_MEMORY) && \
     631        !defined(WOLFSSL_STATIC_MEMORY)
    542632        #define XMALLOC(s, h, type)  pvPortMalloc((s))
    543633        #define XFREE(p, h, type)    vPortFree((p))
    544634    #endif
    545 
     635    #if defined(HAVE_ED25519) || defined(WOLFSSL_ESPIDF)
     636        #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
     637    #endif
    546638    #ifndef NO_WRITEV
    547639        #define NO_WRITEV
     
    570662
    571663#ifdef FREERTOS_TCP
    572 
    573 #if !defined(NO_WOLFSSL_MEMORY) && !defined(XMALLOC_USER)
     664    #if !defined(NO_WOLFSSL_MEMORY) && !defined(XMALLOC_USER) && \
     665        !defined(WOLFSSL_STATIC_MEMORY)
    574666#define XMALLOC(s, h, type)  pvPortMalloc((s))
    575667#define XFREE(p, h, type)    vPortFree((p))
     
    583675#define TFM_TIMING_RESISTANT
    584676#define NO_MAIN_DRIVER
    585 
    586677#endif
    587678
     
    592683    #define USE_FAST_MATH
    593684    #define TFM_TIMING_RESISTANT
     685    #define ECC_TIMING_RESISTANT
     686    #define WC_RSA_BLINDING
    594687    #define NO_DEV_RANDOM
    595688    #define NO_FILESYSTEM
     
    599692    #define HAVE_ECC
    600693    #define HAVE_ALPN
     694    #define USE_WOLF_STRTOK /* use with HAVE_ALPN */
    601695    #define HAVE_TLS_EXTENSIONS
    602696    #define HAVE_AESGCM
     
    702796#endif
    703797
     798#ifdef FREESCALE_MQX_4_0
     799    /* use normal Freescale MQX port, but with minor changes for 4.0 */
     800    #define FREESCALE_MQX
     801#endif
     802
    704803#ifdef FREESCALE_MQX
    705804    #define FREESCALE_COMMON
     
    718817    #endif
    719818
     819    #if !defined(XMALLOC_OVERRIDE) && !defined(XMALLOC_USER)
    720820    #define XMALLOC_OVERRIDE
    721821    #define XMALLOC(s, h, t)    (void *)_mem_alloc_system((s))
    722822    #define XFREE(p, h, t)      {void* xp = (p); if ((xp)) _mem_free((xp));}
    723823    /* Note: MQX has no realloc, using fastmath above */
     824#endif
    724825#endif
    725826
     
    9481049                    #define HAVE_ECC384
    9491050                #endif
    950 
    951                 /* enable features */
    952                 #undef  HAVE_CURVE25519
    953                 #define HAVE_CURVE25519
    954                 #undef  HAVE_ED25519
    955                 #define HAVE_ED25519
    956                 #undef  WOLFSSL_SHA512
    957                 #define WOLFSSL_SHA512
    9581051            #endif
    9591052        #endif
     
    9791072
    9801073#if defined(WOLFSSL_STM32F2) || defined(WOLFSSL_STM32F4) || \
    981     defined(WOLFSSL_STM32F7)
     1074    defined(WOLFSSL_STM32F7) || defined(WOLFSSL_STM32F1) || \
     1075    defined(WOLFSSL_STM32L4)
    9821076
    9831077    #define SIZEOF_LONG_LONG 8
     
    9861080    #undef  NO_RABBIT
    9871081    #define NO_RABBIT
    988     #undef  NO_64BIT
    989     #define NO_64BIT
    9901082    #ifndef NO_STM32_RNG
    9911083        #undef  STM32_RNG
    9921084        #define STM32_RNG
     1085        #ifdef WOLFSSL_STM32F427_RNG
     1086            #include "stm32f427xx.h"
     1087        #endif
    9931088    #endif
    9941089    #ifndef NO_STM32_CRYPTO
    9951090        #undef  STM32_CRYPTO
    9961091        #define STM32_CRYPTO
     1092
     1093        #ifdef WOLFSSL_STM32L4
     1094            #define NO_AES_192 /* hardware does not support 192-bit */
     1095        #endif
    9971096    #endif
    9981097    #ifndef NO_STM32_HASH
     
    10071106        #if defined(WOLFSSL_STM32F2)
    10081107            #include "stm32f2xx_hal.h"
     1108        #elif defined(WOLFSSL_STM32L4)
     1109            #include "stm32l4xx_hal.h"
    10091110        #elif defined(WOLFSSL_STM32F4)
    10101111            #include "stm32f4xx_hal.h"
    10111112        #elif defined(WOLFSSL_STM32F7)
    10121113            #include "stm32f7xx_hal.h"
     1114        #elif defined(WOLFSSL_STM32F1)
     1115            #include "stm32f1xx_hal.h"
    10131116        #endif
    10141117
     
    10331136                #include "stm32f4xx_hash.h"
    10341137            #endif
     1138        #elif defined(WOLFSSL_STM32L4)
     1139            #include "stm32l4xx.h"
     1140            #ifdef STM32_CRYPTO
     1141                #include "stm32l4xx_cryp.h"
     1142            #endif
     1143            #ifdef STM32_HASH
     1144                #include "stm32l4xx_hash.h"
     1145            #endif
    10351146        #elif defined(WOLFSSL_STM32F7)
    10361147            #include "stm32f7xx.h"
     1148        #elif defined(WOLFSSL_STM32F1)
     1149            #include "stm32f1xx.h"
    10371150        #endif
    10381151    #endif /* WOLFSSL_STM32_CUBEMX */
    1039 #endif /* WOLFSSL_STM32F2 || WOLFSSL_STM32F4 || WOLFSSL_STM32F7 */
     1152#endif /* WOLFSSL_STM32F2 || WOLFSSL_STM32F4 || WOLFSSL_STM32L4 || WOLFSSL_STM32F7 */
    10401153
    10411154#ifdef MICRIUM
     
    10741187        #define CUSTOM_RAND_GENERATE Math_Rand
    10751188    #endif
    1076 
    1077     #define WOLFSSL_TYPES
    1078     typedef CPU_INT08U byte;
    1079     typedef CPU_INT16U word16;
    1080     typedef CPU_INT32U word32;
    1081 
    10821189    #define STRING_USER
    10831190    #define XSTRLEN(pstr) ((CPU_SIZE_T)Str_Len((CPU_CHAR *)(pstr)))
     
    11761283#endif /*(WOLFSSL_XILINX_CRYPT)*/
    11771284
     1285#if defined(WOLFSSL_APACHE_MYNEWT)
     1286    #include "os/os_malloc.h"
     1287    #if !defined(WOLFSSL_LWIP)
     1288        #include <mn_socket/mn_socket.h>
     1289    #endif
     1290
     1291    #if !defined(SIZEOF_LONG)
     1292        #define SIZEOF_LONG 4
     1293    #endif
     1294    #if !defined(SIZEOF_LONG_LONG)
     1295        #define SIZEOF_LONG_LONG 8
     1296    #endif
     1297    #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
     1298        #define BIG_ENDIAN_ORDER
     1299    #else
     1300        #undef  BIG_ENDIAN_ORDER
     1301        #define LITTLE_ENDIAN_ORDER
     1302    #endif
     1303    #define NO_WRITEV
     1304    #define WOLFSSL_USER_IO
     1305    #define SINGLE_THREADED
     1306    #define NO_DEV_RANDOM
     1307    #define NO_DH
     1308    #define NO_WOLFSSL_DIR
     1309    #define NO_ERROR_STRINGS
     1310    #define HAVE_ECC
     1311    #define NO_SESSION_CACHE
     1312    #define NO_ERROR_STRINGS
     1313    #define XMALLOC_USER
     1314    #define XMALLOC(sz, heap, type)     os_malloc(sz)
     1315    #define XREALLOC(p, sz, heap, type) os_realloc(p, sz)
     1316    #define XFREE(p, heap, type)        os_free(p)
     1317
     1318#endif /*(WOLFSSL_APACHE_MYNEWT)*/
     1319
     1320#ifdef WOLFSSL_IMX6
     1321    #ifndef SIZEOF_LONG_LONG
     1322        #define SIZEOF_LONG_LONG 8
     1323    #endif
     1324#endif
     1325
     1326/* if defined turn on all CAAM support */
     1327#ifdef WOLFSSL_IMX6_CAAM
     1328    #undef  WOLFSSL_IMX6_CAAM_RNG
     1329    #define WOLFSSL_IMX6_CAAM_RNG
     1330
     1331    #undef  WOLFSSL_IMX6_CAAM_BLOB
     1332    #define WOLFSSL_IMX6_CAAM_BLOB
     1333
     1334#if defined(HAVE_AESGCM) || defined(WOLFSSL_AES_XTS)
     1335    /* large performance gain with HAVE_AES_ECB defined */
     1336    #undef HAVE_AES_ECB
     1337    #define HAVE_AES_ECB
     1338#endif
     1339#endif
     1340
    11781341#if !defined(XMALLOC_USER) && !defined(MICRIUM_MALLOC) && \
    11791342    !defined(WOLFSSL_LEANPSK) && !defined(NO_WOLFSSL_MEMORY) && \
     
    12061369#ifdef WOLFSSL_SGX
    12071370    #ifdef _MSC_VER
    1208         #define WOLFCRYPT_ONLY
    12091371        #define NO_RC4
     1372        #ifndef HAVE_FIPS
     1373            #define WOLFCRYPT_ONLY
    12101374        #define NO_DES3
    12111375        #define NO_SHA
    12121376        #define NO_MD5
    12131377    #else
     1378        #define TFM_TIMING_RESISTANT
     1379            #define NO_WOLFSSL_DIR
     1380            #define NO_WRITEV
     1381            #define NO_MAIN_DRIVER
     1382            #define WOLFSSL_LOG_PRINTF
     1383            #define WOLFSSL_DH_CONST
     1384        #endif
     1385    #else
    12141386        #define HAVE_ECC
    1215         #define ECC_TIMING_RESISTANT
    1216         #define TFM_TIMING_RESISTANT
    1217         #define NO_FILESYSTEM
    12181387        #define NO_WRITEV
    12191388        #define NO_MAIN_DRIVER
     
    12221391        #define WOLFSSL_DH_CONST
    12231392    #endif /* _MSC_VER */
    1224     #ifndef NO_RSA
     1393    #if !defined(HAVE_FIPS) && !defined(NO_RSA)
    12251394        #define WC_RSA_BLINDING
    12261395    #endif
     1396
     1397    #define NO_FILESYSTEM
     1398    #define ECC_TIMING_RESISTANT
     1399    #define TFM_TIMING_RESISTANT
    12271400    #define SINGLE_THREADED
    12281401    #define NO_ASN_TIME /* can not use headers such as windows.h */
     
    12841457 * all curves are on by default for now */
    12851458#ifndef ECC_USER_CURVES
    1286     #ifndef HAVE_ALL_CURVES
     1459    #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_ALL_CURVES)
    12871460        #define HAVE_ALL_CURVES
    12881461    #endif
     
    13001473        #define HAVE_ECC_VERIFY
    13011474    #endif
     1475    #ifndef NO_ECC_CHECK_KEY
     1476        #undef HAVE_ECC_CHECK_KEY
     1477        #define HAVE_ECC_CHECK_KEY
     1478    #endif
    13021479    #ifndef NO_ECC_DHE
    13031480        #undef HAVE_ECC_DHE
     
    13591536        #define AES_MAX_KEY_SIZE    256
    13601537    #endif
     1538
     1539    #ifndef NO_AES_128
     1540        #undef  WOLFSSL_AES_128
     1541        #define WOLFSSL_AES_128
     1542    #endif
     1543    #if !defined(NO_AES_192) && AES_MAX_KEY_SIZE >= 192
     1544        #undef  WOLFSSL_AES_192
     1545        #define WOLFSSL_AES_192
     1546    #endif
     1547    #if !defined(NO_AES_256) && AES_MAX_KEY_SIZE >= 256
     1548        #undef  WOLFSSL_AES_256
     1549        #define WOLFSSL_AES_256
     1550    #endif
     1551    #if !defined(WOLFSSL_AES_128) && defined(HAVE_ECC_ENCRYPT)
     1552        #warning HAVE_ECC_ENCRYPT uses AES 128 bit keys
     1553     #endif
     1554
    13611555    #ifndef NO_AES_DECRYPT
    13621556        #undef  HAVE_AES_DECRYPT
     
    13661560        #undef  HAVE_AES_CBC
    13671561        #define HAVE_AES_CBC
    1368     #else
    1369         #ifndef WOLFCRYPT_ONLY
    1370             #error "AES CBC is required for TLS and can only be disabled for WOLFCRYPT_ONLY builds"
    1371         #endif
    13721562    #endif
    13731563    #ifdef WOLFSSL_AES_XTS
     
    13771567        #endif
    13781568    #endif
     1569    #ifdef WOLFSSL_AES_CFB
     1570        /* AES-CFB makes calls to AES direct functions */
     1571        #ifndef WOLFSSL_AES_DIRECT
     1572        #define WOLFSSL_AES_DIRECT
     1573        #endif
     1574    #endif
     1575#endif
     1576
     1577#if (defined(WOLFSSL_TLS13) && defined(WOLFSSL_NO_TLS12)) || \
     1578    (!defined(HAVE_AES_CBC) && defined(NO_DES3) && defined(NO_RC4) && \
     1579     !defined(HAVE_CAMELLIA) && !defined(HAVE_IDEA) && \
     1580     !defined(HAVE_NULL_CIPHER) && !defined(HAVE_HC128))
     1581    #define WOLFSSL_AEAD_ONLY
    13791582#endif
    13801583
     
    14451648
    14461649    #ifdef WOLFSSL_ASYNC_CRYPT_TEST
    1447         #define WC_ASYNC_DEV_SIZE 320+24
     1650        #define WC_ASYNC_DEV_SIZE 328+24
    14481651    #else
    1449         #define WC_ASYNC_DEV_SIZE 320
     1652        #define WC_ASYNC_DEV_SIZE 328
    14501653    #endif
    14511654
     
    14911694
    14921695#ifdef HAVE_PKCS7
     1696    #if defined(NO_AES) && defined(NO_DES3)
     1697        #error PKCS7 needs either AES or 3DES enabled, please enable one
     1698    #endif
    14931699    #ifndef HAVE_AES_KEYWRAP
    14941700        #error PKCS7 requires AES key wrap please define HAVE_AES_KEYWRAP
    14951701    #endif
    1496     #ifndef HAVE_X963_KDF
     1702    #if defined(HAVE_ECC) && !defined(HAVE_X963_KDF)
    14971703        #error PKCS7 requires X963 KDF please define HAVE_X963_KDF
    14981704    #endif
     
    15171723#endif /* WOLFSSL_MYSQL_COMPATIBLE */
    15181724
    1519 #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
     1725#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
    15201726    #define SSL_OP_NO_COMPRESSION    SSL_OP_NO_COMPRESSION
    15211727    #define OPENSSL_NO_ENGINE
     
    15571763    #if (defined(USE_FAST_MATH) && !defined(TFM_TIMING_RESISTANT)) || \
    15581764        (defined(HAVE_ECC) && !defined(ECC_TIMING_RESISTANT)) || \
    1559         (!defined(NO_RSA) && !defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS))
     1765        (!defined(NO_RSA) && !defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS) && \
     1766            !defined(WC_NO_RNG))
    15601767
    15611768        #ifndef _MSC_VER
     
    15671774#endif
    15681775
     1776#if defined(NO_OLD_WC_NAMES) || defined(OPENSSL_EXTRA)
     1777    /* added to have compatibility with SHA256() */
     1778    #if !defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS)
     1779        #define NO_OLD_SHA_NAMES
     1780    #endif
     1781#endif
     1782
     1783/* switch for compatibility layer functionality. Has subparts i.e. BIO/X509
     1784 * When opensslextra is enabled all subparts should be turned on. */
     1785#ifdef OPENSSL_EXTRA
     1786    #undef  OPENSSL_EXTRA_X509_SMALL
     1787    #define OPENSSL_EXTRA_X509_SMALL
     1788#endif /* OPENSSL_EXTRA */
     1789
     1790/* support for converting DER to PEM */
     1791#if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN) || \
     1792        defined(OPENSSL_EXTRA)
     1793    #undef  WOLFSSL_DER_TO_PEM
     1794    #define WOLFSSL_DER_TO_PEM
     1795#endif
     1796
     1797/* keep backwards compatibility enabling encrypted private key */
     1798#ifndef WOLFSSL_ENCRYPTED_KEYS
     1799    #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
     1800        defined(HAVE_WEBSERVER)
     1801        #define WOLFSSL_ENCRYPTED_KEYS
     1802    #endif
     1803#endif
     1804
     1805/* support for disabling PEM to DER */
     1806#if !defined(WOLFSSL_NO_PEM)
     1807    #undef  WOLFSSL_PEM_TO_DER
     1808    #define WOLFSSL_PEM_TO_DER
     1809#endif
     1810
     1811/* Parts of the openssl compatibility layer require peer certs */
     1812#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
     1813    #undef  KEEP_PEER_CERT
     1814    #define KEEP_PEER_CERT
     1815#endif
     1816
     1817/* RAW hash function APIs are not implemented with ARMv8 hardware acceleration*/
     1818#ifdef WOLFSSL_ARMASM
     1819    #undef  WOLFSSL_NO_HASH_RAW
     1820    #define WOLFSSL_NO_HASH_RAW
     1821#endif
     1822
     1823#if !defined(WOLFSSL_SHA384) && !defined(WOLFSSL_SHA512) && defined(NO_AES) && \
     1824                                                          !defined(WOLFSSL_SHA3)
     1825    #undef  WOLFSSL_NO_WORD64_OPS
     1826    #define WOLFSSL_NO_WORD64_OPS
     1827#endif
     1828
     1829#if defined(NO_AES) && defined(NO_DES3) && !defined(HAVE_CAMELLIA) && \
     1830                                     defined(NO_PWDBASED) && !defined(HAVE_IDEA)
     1831    #undef  WOLFSSL_NO_XOR_OPS
     1832    #define WOLFSSL_NO_XOR_OPS
     1833#endif
     1834
     1835#if defined(NO_ASN) && defined(WOLFCRYPT_ONLY)
     1836    #undef  WOLFSSL_NO_INT_ENCODE
     1837    #define WOLFSSL_NO_INT_ENCODE
     1838    #undef  WOLFSSL_NO_INT_DECODE
     1839    #define WOLFSSL_NO_INT_DECODE
     1840#endif
     1841
     1842#if defined(WOLFCRYPT_ONLY) && defined(WOLFSSL_RSA_VERIFY_ONLY) && \
     1843    defined(WC_NO_RSA_OAEP)
     1844    #undef  WOLFSSL_NO_CT_OPS
     1845    #define WOLFSSL_NO_CT_OPS
     1846#endif
     1847
     1848#if defined(WOLFCRYPT_ONLY) && defined(NO_AES) && !defined(HAVE_CURVE25519) && \
     1849                                   defined(WC_NO_RNG) && defined(WC_NO_RSA_OAEP)
     1850    #undef  WOLFSSL_NO_CONST_CMP
     1851    #define WOLFSSL_NO_CONST_CMP
     1852#endif
     1853
     1854#if defined(WOLFCRYPT_ONLY) && defined(NO_AES) && !defined(WOLFSSL_SHA384) && \
     1855    !defined(WOLFSSL_SHA512) && defined(WC_NO_RNG) && \
     1856                    defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_RSA_PUBLIC_ONLY)
     1857    #undef  WOLFSSL_NO_FORCE_ZERO
     1858    #define WOLFSSL_NO_FORCE_ZERO
     1859#endif
     1860
    15691861#ifdef __cplusplus
    15701862    }   /* extern "C" */
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/sha.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/sha.h
     24*/
     25
    2226
    2327#ifndef WOLF_CRYPT_SHA_H
     
    2832#ifndef NO_SHA
    2933
    30 #ifdef HAVE_FIPS
     34#if defined(HAVE_FIPS) && \
     35    defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     36    #include <wolfssl/wolfcrypt/fips.h>
     37#endif /* HAVE_FIPS_VERSION >= 2 */
     38
     39#if defined(HAVE_FIPS) && \
     40        (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
    3141#define wc_Sha             Sha
    3242#define WC_SHA             SHA
     
    4757#endif
    4858
    49 #ifndef HAVE_FIPS /* avoid redefining structs */
     59/* avoid redefinition of structs */
     60#if !defined(HAVE_FIPS) || \
     61    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    5062
    5163#ifdef WOLFSSL_MICROCHIP_PIC32MZ
    5264    #include <wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h>
     65#endif
     66#ifdef STM32_HASH
     67    #include <wolfssl/wolfcrypt/port/st/stm32.h>
    5368#endif
    5469#ifdef WOLFSSL_ASYNC_CRYPT
     
    5671#endif
    5772
     73#if !defined(NO_OLD_SHA_NAMES)
     74    #define SHA             WC_SHA
     75#endif
     76
    5877#ifndef NO_OLD_WC_NAMES
    5978    #define Sha             wc_Sha
    60     #define SHA             WC_SHA
    6179    #define SHA_BLOCK_SIZE  WC_SHA_BLOCK_SIZE
    6280    #define SHA_DIGEST_SIZE WC_SHA_DIGEST_SIZE
     
    6684/* in bytes */
    6785enum {
    68     WC_SHA              =  1,    /* hash type unique */
     86    WC_SHA              =  WC_HASH_TYPE_SHA,
    6987    WC_SHA_BLOCK_SIZE   = 64,
    7088    WC_SHA_DIGEST_SIZE  = 20,
     
    7391
    7492
    75 #ifndef WOLFSSL_TI_HASH
     93#if defined(WOLFSSL_TI_HASH)
     94    #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
     95
     96#elif defined(WOLFSSL_IMX6_CAAM)
     97    #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
     98
     99#else
    76100/* Sha digest */
    77101typedef struct wc_Sha {
    78102    #ifdef FREESCALE_LTC_SHA
    79103        ltc_hash_ctx_t ctx;
     104#elif defined(STM32_HASH)
     105        STM32_HASH_Context stmCtx;
    80106    #else
    81107        word32  buffLen;   /* in bytes          */
     
    95121        WC_ASYNC_DEV asyncDev;
    96122    #endif /* WOLFSSL_ASYNC_CRYPT */
    97 #endif /* FREESCALE_LTC_SHA */
     123#endif
    98124} wc_Sha;
    99125
    100 #else
    101     #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
    102126#endif /* WOLFSSL_TI_HASH */
    103127
     
    108132WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId);
    109133WOLFSSL_API int wc_ShaUpdate(wc_Sha*, const byte*, word32);
     134WOLFSSL_API int wc_ShaFinalRaw(wc_Sha*, byte*);
    110135WOLFSSL_API int wc_ShaFinal(wc_Sha*, byte*);
    111136WOLFSSL_API void wc_ShaFree(wc_Sha*);
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/sha256.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/sha256.h
     24*/
     25
    2226
    2327/* code submitted by raphael.huck@efixo.com */
     
    3034#ifndef NO_SHA256
    3135
    32 #ifdef HAVE_FIPS
     36#if defined(HAVE_FIPS) && \
     37    defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     38    #include <wolfssl/wolfcrypt/fips.h>
     39#endif /* HAVE_FIPS_VERSION >= 2 */
     40
     41#if defined(HAVE_FIPS) && \
     42        (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
    3343    #define wc_Sha256             Sha256
    3444    #define WC_SHA256             SHA256
     
    5868#endif
    5969
    60 #ifndef HAVE_FIPS /* avoid redefinition of structs */
     70/* avoid redefinition of structs */
     71#if !defined(HAVE_FIPS) || \
     72    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    6173
    6274#ifdef WOLFSSL_MICROCHIP_PIC32MZ
    6375    #include <wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h>
    6476#endif
     77#ifdef STM32_HASH
     78    #include <wolfssl/wolfcrypt/port/st/stm32.h>
     79#endif
    6580#ifdef WOLFSSL_ASYNC_CRYPT
    6681    #include <wolfssl/wolfcrypt/async.h>
    6782#endif
     83#if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_DEVCRYPTO_HASH)
     84    #include <wolfssl/wolfcrypt/port/devcrypto/wc_devcrypto.h>
     85#endif
     86
     87#if defined(_MSC_VER)
     88    #define SHA256_NOINLINE __declspec(noinline)
     89#elif defined(__GNUC__)
     90    #define SHA256_NOINLINE __attribute__((noinline))
     91#else
     92    #define SHA256_NOINLINE
     93#endif
     94
     95#if !defined(NO_OLD_SHA_NAMES)
     96    #define SHA256             WC_SHA256
     97#endif
    6898
    6999#ifndef NO_OLD_WC_NAMES
    70100    #define Sha256             wc_Sha256
    71     #define SHA256             WC_SHA256
    72101    #define SHA256_BLOCK_SIZE  WC_SHA256_BLOCK_SIZE
    73102    #define SHA256_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
     
    77106/* in bytes */
    78107enum {
    79     WC_SHA256              =  2,   /* hash type unique */
     108    WC_SHA256              =  WC_HASH_TYPE_SHA256,
    80109    WC_SHA256_BLOCK_SIZE   = 64,
    81110    WC_SHA256_DIGEST_SIZE  = 32,
     
    83112};
    84113
    85 #ifndef WOLFSSL_TI_HASH
    86 
     114
     115#ifdef WOLFSSL_TI_HASH
     116    #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
     117#elif defined(WOLFSSL_IMX6_CAAM)
     118    #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
     119#elif defined(WOLFSSL_AFALG_HASH)
     120    #include "wolfssl/wolfcrypt/port/af_alg/afalg_hash.h"
     121#else
    87122/* wc_Sha256 digest */
    88123typedef struct wc_Sha256 {
    89124#ifdef FREESCALE_LTC_SHA
    90125    ltc_hash_ctx_t ctx;
     126#elif defined(STM32_HASH)
     127    STM32_HASH_Context stmCtx;
    91128#else
    92129    /* alignment on digest and buffer speeds up ARMv8 crypto operations */
     
    97134    word32  hiLen;     /* length in bytes   */
    98135    void*   heap;
     136#ifdef USE_INTEL_SPEEDUP
     137    const byte* data;
     138#endif
    99139#ifdef WOLFSSL_PIC32MZ_HASH
    100140    hashUpdCache cache; /* cache for updates */
    101 #endif
    102 #if defined(STM32_HASH) && defined(WOLFSSL_STM32_CUBEMX)
    103     HASH_HandleTypeDef hashHandle;
    104141#endif
    105142#ifdef WOLFSSL_ASYNC_CRYPT
    106143    WC_ASYNC_DEV asyncDev;
    107144#endif /* WOLFSSL_ASYNC_CRYPT */
    108 #endif /* FREESCALE_LTC_SHA */
     145#ifdef WOLFSSL_SMALL_STACK_CACHE
     146    word32* W;
     147#endif
     148#ifdef WOLFSSL_DEVCRYPTO_HASH
     149    WC_CRYPTODEV ctx;
     150    byte*  msg;
     151    word32 used;
     152    word32 len;
     153#endif
     154#endif
    109155} wc_Sha256;
    110156
    111 #else
    112     #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
    113157#endif
    114158
     
    118162WOLFSSL_API int wc_InitSha256_ex(wc_Sha256*, void*, int);
    119163WOLFSSL_API int wc_Sha256Update(wc_Sha256*, const byte*, word32);
     164WOLFSSL_API int wc_Sha256FinalRaw(wc_Sha256*, byte*);
    120165WOLFSSL_API int wc_Sha256Final(wc_Sha256*, byte*);
    121166WOLFSSL_API void wc_Sha256Free(wc_Sha256*);
     
    129174
    130175#ifdef WOLFSSL_SHA224
    131 #ifndef HAVE_FIPS /* avoid redefinition of structs */
     176/* avoid redefinition of structs */
     177#if !defined(HAVE_FIPS) || \
     178    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    132179
    133180#ifndef NO_OLD_WC_NAMES
     
    141188/* in bytes */
    142189enum {
    143     WC_SHA224              =   8,   /* hash type unique */
     190    WC_SHA224              =   WC_HASH_TYPE_SHA224,
    144191    WC_SHA224_BLOCK_SIZE   =   WC_SHA256_BLOCK_SIZE,
    145192    WC_SHA224_DIGEST_SIZE  =   28,
    146193    WC_SHA224_PAD_SIZE     =   WC_SHA256_PAD_SIZE
    147194};
     195
    148196
    149197typedef wc_Sha256 wc_Sha224;
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/sha512.h

    r352 r372  
    11/* sha512.h
    22 *
    3  * Copyright (C) 2006-2017 wolfSSL Inc.
     3 * Copyright (C) 2006-2018 wolfSSL Inc.
    44 *
    55 * This file is part of wolfSSL.
     
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/sha512.h
     24*/
     25
    2226
    2327#ifndef WOLF_CRYPT_SHA512_H
     
    2630#include <wolfssl/wolfcrypt/types.h>
    2731
    28 #ifdef WOLFSSL_SHA512
     32#if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
    2933
    30 /* for fips @wc_fips */
    31 #ifdef HAVE_FIPS
     34#if defined(HAVE_FIPS) && \
     35    defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
     36    #include <wolfssl/wolfcrypt/fips.h>
     37#endif /* HAVE_FIPS_VERSION >= 2 */
     38
     39#if defined(HAVE_FIPS) && \
     40        (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
     41    #ifdef WOLFSSL_SHA512
    3242    #define wc_Sha512             Sha512
    3343    #define WC_SHA512             SHA512
     
    3545    #define WC_SHA512_DIGEST_SIZE SHA512_DIGEST_SIZE
    3646    #define WC_SHA512_PAD_SIZE    SHA512_PAD_SIZE
     47    #endif /* WOLFSSL_SHA512 */
    3748    #ifdef WOLFSSL_SHA384
    3849        #define wc_Sha384             Sha384
     
    4758        #define CYASSL_SHA384
    4859    #endif
     60        /* for fips @wc_fips */
    4961    #include <cyassl/ctaocrypt/sha512.h>
    5062#endif
     
    5466#endif
    5567
    56 #ifndef HAVE_FIPS /* avoid redefinition of structs */
     68/* avoid redefinition of structs */
     69#if !defined(HAVE_FIPS) || \
     70    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    5771
    5872#ifdef WOLFSSL_ASYNC_CRYPT
     
    6074#endif
    6175
    62 #ifndef NO_OLD_WC_NAMES
     76#if defined(_MSC_VER)
     77    #define SHA512_NOINLINE __declspec(noinline)
     78#elif defined(__GNUC__)
     79    #define SHA512_NOINLINE __attribute__((noinline))
     80#else
     81    #define SHA512_NOINLINE
     82#endif
     83
     84#ifdef WOLFSSL_SHA512
     85
     86#if !defined(NO_OLD_SHA_NAMES)
     87    #define SHA512             WC_SHA512
     88#endif
     89
     90#if !defined(NO_OLD_WC_NAMES)
    6391    #define Sha512             wc_Sha512
    64     #define SHA512             WC_SHA512
    6592    #define SHA512_BLOCK_SIZE  WC_SHA512_BLOCK_SIZE
    6693    #define SHA512_DIGEST_SIZE WC_SHA512_DIGEST_SIZE
     
    6895#endif
    6996
     97#endif /* WOLFSSL_SHA512 */
     98
    7099/* in bytes */
    71100enum {
    72     WC_SHA512              =   4,   /* hash type unique */
     101#ifdef WOLFSSL_SHA512
     102    WC_SHA512              =   WC_HASH_TYPE_SHA512,
     103#endif
    73104    WC_SHA512_BLOCK_SIZE   = 128,
    74105    WC_SHA512_DIGEST_SIZE  =  64,
     
    77108
    78109
     110#ifdef WOLFSSL_IMX6_CAAM
     111    #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
     112#else
    79113/* wc_Sha512 digest */
    80114typedef struct wc_Sha512 {
     115    word64  digest[WC_SHA512_DIGEST_SIZE / sizeof(word64)];
     116    word64  buffer[WC_SHA512_BLOCK_SIZE  / sizeof(word64)];
    81117    word32  buffLen;   /* in bytes          */
    82118    word64  loLen;     /* length in bytes   */
    83119    word64  hiLen;     /* length in bytes   */
    84     word64  digest[WC_SHA512_DIGEST_SIZE / sizeof(word64)];
    85     word64  buffer[WC_SHA512_BLOCK_SIZE  / sizeof(word64)];
    86120    void*   heap;
     121#ifdef USE_INTEL_SPEEDUP
     122    const byte* data;
     123#endif
    87124#ifdef WOLFSSL_ASYNC_CRYPT
    88125    WC_ASYNC_DEV asyncDev;
    89126#endif /* WOLFSSL_ASYNC_CRYPT */
     127#ifdef WOLFSSL_SMALL_STACK_CACHE
     128    word64* W;
     129#endif
    90130} wc_Sha512;
     131#endif
    91132
    92133#endif /* HAVE_FIPS */
     134
     135#ifdef WOLFSSL_SHA512
    93136
    94137WOLFSSL_API int wc_InitSha512(wc_Sha512*);
    95138WOLFSSL_API int wc_InitSha512_ex(wc_Sha512*, void*, int);
    96139WOLFSSL_API int wc_Sha512Update(wc_Sha512*, const byte*, word32);
     140WOLFSSL_API int wc_Sha512FinalRaw(wc_Sha512*, byte*);
    97141WOLFSSL_API int wc_Sha512Final(wc_Sha512*, byte*);
    98142WOLFSSL_API void wc_Sha512Free(wc_Sha512*);
     
    101145WOLFSSL_API int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst);
    102146
     147#endif /* WOLFSSL_SHA512 */
     148
    103149#if defined(WOLFSSL_SHA384)
    104150
    105 #ifndef HAVE_FIPS /* avoid redefinition of structs */
     151/* avoid redefinition of structs */
     152#if !defined(HAVE_FIPS) || \
     153    (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
    106154
    107 #ifndef NO_OLD_WC_NAMES
     155#if !defined(NO_OLD_SHA_NAMES)
     156    #define SHA384             WC_SHA384
     157#endif
     158
     159#if !defined(NO_OLD_WC_NAMES)
    108160    #define Sha384             wc_Sha384
    109     #define SHA384             WC_SHA384
    110161    #define SHA384_BLOCK_SIZE  WC_SHA384_BLOCK_SIZE
    111162    #define SHA384_DIGEST_SIZE WC_SHA384_DIGEST_SIZE
     
    115166/* in bytes */
    116167enum {
    117     WC_SHA384              =   5,   /* hash type unique */
     168    WC_SHA384              =   WC_HASH_TYPE_SHA384,
    118169    WC_SHA384_BLOCK_SIZE   =   WC_SHA512_BLOCK_SIZE,
    119170    WC_SHA384_DIGEST_SIZE  =   48,
    120171    WC_SHA384_PAD_SIZE     =   WC_SHA512_PAD_SIZE
    121172};
     173
    122174
    123175typedef wc_Sha512 wc_Sha384;
     
    127179WOLFSSL_API int wc_InitSha384_ex(wc_Sha384*, void*, int);
    128180WOLFSSL_API int wc_Sha384Update(wc_Sha384*, const byte*, word32);
     181WOLFSSL_API int wc_Sha384FinalRaw(wc_Sha384*, byte*);
    129182WOLFSSL_API int wc_Sha384Final(wc_Sha384*, byte*);
    130183WOLFSSL_API void wc_Sha384Free(wc_Sha384*);
     
    139192#endif
    140193
    141 #endif /* WOLFSSL_SHA512 */
     194#endif /* WOLFSSL_SHA512 || WOLFSSL_SHA384 */
    142195#endif /* WOLF_CRYPT_SHA512_H */
    143196
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/types.h

    r352 r372  
    2020 */
    2121
    22 
     22/*!
     23    \file wolfssl/wolfcrypt/types.h
     24*/
    2325
    2426#ifndef WOLF_CRYPT_TYPES_H
     
    5254
    5355        /* try to set SIZEOF_LONG or LONG_LONG if user didn't */
    54         #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__)
     56    #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__) && !defined(__EMSCRIPTEN__)
    5557            #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG)
    56                 #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) \
    57                         || defined(__mips64)  || defined(__x86_64__) || \
     58            #if (defined(__alpha__) || defined(__ia64__) || \
     59                defined(_ARCH_PPC64) || defined(__mips64) || \
     60                defined(__x86_64__) || \
    5861                    ((defined(sun) || defined(__sun)) && \
    5962                     (defined(LP64) || defined(_LP64))))
     
    6770        #endif
    6871
    69 
    7072        #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
    7173            #define WORD64_AVAILABLE
    7274            #define W64LIT(x) x##ui64
    7375            typedef unsigned __int64 word64;
     76    #elif defined(__EMSCRIPTEN__)
     77        #define WORD64_AVAILABLE
     78        #define W64LIT(x) x##ull
     79        typedef unsigned long long word64;
    7480        #elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8
    7581            #define WORD64_AVAILABLE
     
    8490            #define W64LIT(x) x##LL
    8591            typedef unsigned long long word64;
    86         #else
    87             #define MP_16BIT  /* for mp_int, mp_word needs to be twice as big as
    88                                  mp_digit, no 64 bit type so make mp_digit 16 bit */
    89         #endif
    90 
    91 
     92        #endif
     93
     94#if !defined(NO_64BIT) && defined(WORD64_AVAILABLE)
    9295        /* These platforms have 64-bit CPU registers.  */
    9396        #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
     
    100103        /* LP64 with GNU GCC compiler is reserved for when long int is 64 bits
    101104         * and int uses 32 bits. When using Solaris Studio sparc and __sparc are
    102          * avialable for 32 bit detection but __sparc64__ could be missed. This
     105         * available for 32 bit detection but __sparc64__ could be missed. This
    103106         * uses LP64 for checking 64 bit CPU arch. */
    104107            typedef word64 wolfssl_word;
     
    110113            #endif
    111114        #endif
    112 
     115#else
     116        #undef WORD64_AVAILABLE
     117        typedef word32 wolfssl_word;
     118        #define MP_16BIT  /* for mp_int, mp_word needs to be twice as big as
     119                             mp_digit, no 64 bit type so make mp_digit 16 bit */
     120#endif
    113121
    114122        enum {
     
    121129
    122130        /* use inlining if compiler allows */
    123         #ifndef INLINE
     131    #ifndef WC_INLINE
    124132        #ifndef NO_INLINE
    125133            #ifdef _MSC_VER
    126                 #define INLINE __inline
     134            #define WC_INLINE __inline
    127135            #elif defined(__GNUC__)
    128136               #ifdef WOLFSSL_VXWORKS
    129                    #define INLINE __inline__
     137                   #define WC_INLINE __inline__
    130138               #else
    131                    #define INLINE inline
     139                   #define WC_INLINE inline
    132140               #endif
    133141            #elif defined(__IAR_SYSTEMS_ICC__)
    134                 #define INLINE inline
     142            #define WC_INLINE inline
    135143            #elif defined(THREADX)
    136                 #define INLINE _Inline
     144            #define WC_INLINE _Inline
    137145            #else
    138                 #define INLINE
     146            #define WC_INLINE
    139147            #endif
    140148        #else
    141             #define INLINE
    142         #endif
     149        #define WC_INLINE
     150    #endif
     151        #endif
     152
     153    #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
     154        #define INLINE WC_INLINE
    143155        #endif
    144156
     
    164176                #define THREAD_LS_T __declspec(thread)
    165177            /* Thread local storage only in FreeRTOS v8.2.1 and higher */
    166             #elif defined(FREERTOS)
     178        #elif defined(FREERTOS) || defined(FREERTOS_TCP)
    167179                #define THREAD_LS_T
    168180            #else
     
    176188    #if defined(__GNUC__)
    177189        #if ((__GNUC__ > 7) || ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 1)))
    178             #define FALL_THROUGH __attribute__ ((fallthrough));
     190            #define FALL_THROUGH __attribute__ ((fallthrough))
    179191        #endif
    180192    #endif
     
    194206        /* default to libc stuff */
    195207        /* XREALLOC is used once in normal math lib, not in fast math lib */
    196         /* XFREE on some embeded systems doesn't like free(0) so test  */
     208    /* XFREE on some embedded systems doesn't like free(0) so test  */
    197209        #if defined(HAVE_IO_POOL)
    198210                WOLFSSL_API void* XMALLOC(size_t n, void* heap, int type);
     
    217229            extern void *XREALLOC(void *p, size_t n, void* heap, int type);
    218230            extern void XFREE(void *p, void* heap, int type);
     231    #elif defined(WOLFSSL_MEMORY_LOG)
     232        #define XMALLOC(n, h, t)        xmalloc(n, h, t, __func__, __FILE__, __LINE__)
     233        #define XREALLOC(p, n, h, t)    xrealloc(p, n, h, t, __func__,  __FILE__, __LINE__)
     234        #define XFREE(p, h, t)          xfree(p, h, t, __func__, __FILE__, __LINE__)
     235
     236        /* prototypes for user heap override functions */
     237        #include <stddef.h>  /* for size_t */
     238        #include <stdlib.h>
     239        extern void *xmalloc(size_t n, void* heap, int type, const char* func,
     240              const char* file, unsigned int line);
     241        extern void *xrealloc(void *p, size_t n, void* heap, int type,
     242              const char* func, const char* file, unsigned int line);
     243        extern void xfree(void *p, void* heap, int type, const char* func,
     244              const char* file, unsigned int line);
    219245    #elif defined(XMALLOC_OVERRIDE)
    220246        /* override the XMALLOC, XFREE and XREALLOC macros */
     
    228254                && !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \
    229255                && !defined(FREESCALE_KSDK_MQX) && !defined(FREESCALE_FREE_RTOS) \
    230             && !defined(WOLFSSL_LEANPSK) && !defined(FREERTOS) && !defined(FREERTOS_TCP)\
    231             && !defined(WOLFSSL_uITRON4)
     256            && !defined(WOLFSSL_LEANPSK) && !defined(WOLFSSL_uITRON4)
    232257            /* default C runtime, can install different routines at runtime via cbs */
    233258            #include <wolfssl/wolfcrypt/memory.h>
     
    242267                                #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t))
    243268            #endif /* WOLFSSL_DEBUG_MEMORY */
    244         #else
     269        #elif !defined(FREERTOS) && !defined(FREERTOS_TCP)
    245270            #ifdef WOLFSSL_DEBUG_MEMORY
    246271                                #define XMALLOC(s, h, t)     ((void)h, (void)t, wolfSSL_Malloc((s), __func__, __LINE__))
     
    258283    #ifdef WOLFSSL_ASYNC_CRYPT
    259284        #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
    260             VAR_TYPE* VAR_NAME = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, HEAP, DYNAMIC_TYPE_WOLF_BIGINT);
     285            VAR_TYPE* VAR_NAME = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT);
    261286        #define DECLARE_VAR_INIT(VAR_NAME, VAR_TYPE, VAR_SIZE, INIT_VALUE, HEAP) \
    262287            VAR_TYPE* VAR_NAME = ({ \
    263                 VAR_TYPE* ptr = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \
     288                VAR_TYPE* ptr = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \
    264289                if (ptr && INIT_VALUE) { \
    265290                    XMEMCPY(ptr, INIT_VALUE, sizeof(VAR_TYPE) * VAR_SIZE); \
     
    271296            int idx##VAR_NAME; \
    272297            for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
    273                 VAR_NAME[idx##VAR_NAME] = (VAR_TYPE*)XMALLOC(VAR_SIZE, HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \
     298                VAR_NAME[idx##VAR_NAME] = (VAR_TYPE*)XMALLOC(VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \
    274299            }
    275300        #define FREE_VAR(VAR_NAME, HEAP) \
    276             XFREE(VAR_NAME, HEAP, DYNAMIC_TYPE_WOLF_BIGINT);
     301            XFREE(VAR_NAME, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT);
    277302        #define FREE_ARRAY(VAR_NAME, VAR_ITEMS, HEAP) \
    278303            for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
    279                 XFREE(VAR_NAME[idx##VAR_NAME], HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \
     304                XFREE(VAR_NAME[idx##VAR_NAME], (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \
    280305            }
    281306    #else
     
    290315    #endif
    291316
    292     #ifndef WOLFSSL_LEANPSK
    293             char* mystrnstr(const char* s1, const char* s2, unsigned int n);
     317    #if !defined(USE_WOLF_STRTOK) && \
     318            ((defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) || \
     319             defined(WOLFSSL_TIRTOS) || defined(WOLF_C99))
     320        #define USE_WOLF_STRTOK
     321    #endif
     322    #if !defined(USE_WOLF_STRSEP) && (defined(WOLF_C99))
     323        #define USE_WOLF_STRSEP
    294324    #endif
    295325
     
    310340            #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
    311341
    312         #ifdef MICROCHIP_PIC32
     342        #ifdef USE_WOLF_STRSEP
     343            #define XSTRSEP(s1,d) wc_strsep((s1),(d))
     344        #else
     345            #define XSTRSEP(s1,d) strsep((s1),(d))
     346        #endif
     347
     348        #if defined(MICROCHIP_PIC32) || defined(WOLFSSL_TIRTOS)
    313349            /* XC32 does not support strncasecmp, so use case sensitive one */
    314350            #define XSTRNCASECMP(s1,s2,n) strncmp((s1),(s2),(n))
    315         #elif defined(USE_WINDOWS_API)
     351        #elif defined(USE_WINDOWS_API) || defined(FREERTOS_TCP_WINSIM)
    316352                #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
    317353        #else
     354            #if defined(HAVE_STRINGS_H) && defined(WOLF_C99) && \
     355                !defined(WOLFSSL_SGX)
     356                #include <strings.h>
     357            #endif
    318358                #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
    319359            #endif
    320360
    321         /* snprintf is used in asn.c for GetTimeString and PKCS7 test */
     361        /* snprintf is used in asn.c for GetTimeString, PKCS7 test, and when
     362           debugging is turned on */
    322363        #ifndef USE_WINDOWS_API
     364            #if defined(NO_FILESYSTEM) && (defined(OPENSSL_EXTRA) || \
     365                   defined(HAVE_PKCS7)) && !defined(NO_STDIO_FILESYSTEM)
     366                /* case where stdio is not included else where but is needed for
     367                 * snprintf */
     368                #include <stdio.h>
     369            #endif
    323370            #define XSNPRINTF snprintf
    324371        #else
     
    328375        #if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
    329376            /* use only Thread Safe version of strtok */
    330             #if !defined(USE_WINDOWS_API) && !defined(INTIME_RTOS)
    331                 #define XSTRTOK strtok_r
    332             #elif defined(__MINGW32__) || defined(WOLFSSL_TIRTOS) || \
    333                     defined(USE_WOLF_STRTOK)
    334                 #ifndef USE_WOLF_STRTOK
    335                     #define USE_WOLF_STRTOK
    336                 #endif
    337                 #define XSTRTOK wc_strtok
     377            #if defined(USE_WOLF_STRTOK)
     378                #define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
     379            #elif defined(USE_WINDOWS_API) || defined(INTIME_RTOS)
     380                #define XSTRTOK(s1,d,ptr) strtok_s((s1),(d),(ptr))
    338381            #else
    339                 #define XSTRTOK strtok_s
     382                #define XSTRTOK(s1,d,ptr) strtok_r((s1),(d),(ptr))
    340383            #endif
    341384        #endif
    342         #endif
     385    #endif
     386
     387    #ifdef USE_WOLF_STRTOK
     388        WOLFSSL_API char* wc_strtok(char *str, const char *delim, char **nextp);
     389            #endif
     390    #ifdef USE_WOLF_STRSEP
     391        WOLFSSL_API char* wc_strsep(char **stringp, const char *delim);
     392        #endif
     393
     394    #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
     395        !defined(NO_STDIO_FILESYSTEM)
     396        #ifndef XGETENV
     397            #include <stdlib.h>
     398            #define XGETENV getenv
     399        #endif
     400    #endif /* OPENSSL_EXTRA */
    343401
    344402        #ifndef CTYPE_USER
    345403            #include <ctype.h>
    346             #if defined(HAVE_ECC) || defined(HAVE_OCSP) || defined(WOLFSSL_KEY_GEN)
     404        #if defined(HAVE_ECC) || defined(HAVE_OCSP) || \
     405            defined(WOLFSSL_KEY_GEN) || !defined(NO_DSA)
    347406                #define XTOUPPER(c)     toupper((c))
    348407                #define XISALPHA(c)     isalpha((c))
     
    438497        DYNAMIC_TYPE_HASHCTX      = 82,
    439498        DYNAMIC_TYPE_SEED         = 83,
    440         DYNAMIC_TYPE_SYMETRIC_KEY = 84,
     499        DYNAMIC_TYPE_SYMMETRIC_KEY= 84,
    441500        DYNAMIC_TYPE_ECC_BUFFER   = 85,
    442501        DYNAMIC_TYPE_QSH          = 86,
    443502        DYNAMIC_TYPE_SALT         = 87,
    444503        DYNAMIC_TYPE_HASH_TMP     = 88,
     504        DYNAMIC_TYPE_BLOB         = 89,
     505        DYNAMIC_TYPE_NAME_ENTRY   = 90,
    445506        };
    446507
    447508        /* max error buffer string size */
    448         enum {
    449             WOLFSSL_MAX_ERROR_SZ = 80
    450         };
     509    #ifndef WOLFSSL_MAX_ERROR_SZ
     510        #define WOLFSSL_MAX_ERROR_SZ 80
     511    #endif
    451512
    452513        /* stack protection */
     
    455516        };
    456517
     518
     519    /* Algorithm Types */
     520    enum wc_AlgoType {
     521        WC_ALGO_TYPE_NONE = 0,
     522        WC_ALGO_TYPE_HASH = 1,
     523        WC_ALGO_TYPE_CIPHER = 2,
     524        WC_ALGO_TYPE_PK = 3,
     525
     526        WC_ALGO_TYPE_MAX = WC_ALGO_TYPE_PK
     527    };
     528
     529    /* hash types */
     530    enum wc_HashType {
     531    #if defined(HAVE_SELFTEST) || defined(HAVE_FIPS)
     532        /* In selftest build, WC_* types are not mapped to WC_HASH_TYPE types.
     533         * Values here are based on old selftest hmac.h enum, with additions */
     534        WC_HASH_TYPE_NONE = 15,
     535        WC_HASH_TYPE_MD2 = 16,
     536        WC_HASH_TYPE_MD4 = 17,
     537        WC_HASH_TYPE_MD5 = 0,
     538        WC_HASH_TYPE_SHA = 1, /* SHA-1 (not old SHA-0) */
     539        WC_HASH_TYPE_SHA224 = 8,
     540        WC_HASH_TYPE_SHA256 = 2,
     541        WC_HASH_TYPE_SHA384 = 5,
     542        WC_HASH_TYPE_SHA512 = 4,
     543        WC_HASH_TYPE_MD5_SHA = 18,
     544        WC_HASH_TYPE_SHA3_224 = 10,
     545        WC_HASH_TYPE_SHA3_256 = 11,
     546        WC_HASH_TYPE_SHA3_384 = 12,
     547        WC_HASH_TYPE_SHA3_512 = 13,
     548        WC_HASH_TYPE_BLAKE2B = 14,
     549
     550        WC_HASH_TYPE_MAX = WC_HASH_TYPE_MD5_SHA
     551    #else
     552        WC_HASH_TYPE_NONE = 0,
     553        WC_HASH_TYPE_MD2 = 1,
     554        WC_HASH_TYPE_MD4 = 2,
     555        WC_HASH_TYPE_MD5 = 3,
     556        WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */
     557        WC_HASH_TYPE_SHA224 = 5,
     558        WC_HASH_TYPE_SHA256 = 6,
     559        WC_HASH_TYPE_SHA384 = 7,
     560        WC_HASH_TYPE_SHA512 = 8,
     561        WC_HASH_TYPE_MD5_SHA = 9,
     562        WC_HASH_TYPE_SHA3_224 = 10,
     563        WC_HASH_TYPE_SHA3_256 = 11,
     564        WC_HASH_TYPE_SHA3_384 = 12,
     565        WC_HASH_TYPE_SHA3_512 = 13,
     566        WC_HASH_TYPE_BLAKE2B = 14,
     567
     568        WC_HASH_TYPE_MAX = WC_HASH_TYPE_BLAKE2B
     569    #endif /* HAVE_SELFTEST */
     570    };
     571
     572    /* cipher types */
     573    enum wc_CipherType {
     574        WC_CIPHER_NONE = 0,
     575        WC_CIPHER_AES = 1,
     576        WC_CIPHER_AES_CBC = 2,
     577        WC_CIPHER_AES_GCM = 3,
     578        WC_CIPHER_AES_CTR = 4,
     579        WC_CIPHER_AES_XTS = 5,
     580        WC_CIPHER_AES_CFB = 6,
     581        WC_CIPHER_DES3 = 7,
     582        WC_CIPHER_DES = 8,
     583        WC_CIPHER_CHACHA = 9,
     584        WC_CIPHER_HC128 = 10,
     585        WC_CIPHER_IDEA = 11,
     586
     587        WC_CIPHER_MAX = WC_CIPHER_HC128
     588    };
     589
     590    /* PK=public key (asymmetric) based algorithms */
     591    enum wc_PkType {
     592        WC_PK_TYPE_NONE = 0,
     593        WC_PK_TYPE_RSA = 1,
     594        WC_PK_TYPE_DH = 2,
     595        WC_PK_TYPE_ECDH = 3,
     596        WC_PK_TYPE_ECDSA_SIGN = 4,
     597        WC_PK_TYPE_ECDSA_VERIFY = 5,
     598        WC_PK_TYPE_ED25519 = 6,
     599        WC_PK_TYPE_CURVE25519 = 7,
     600        WC_PK_TYPE_RSA_KEYGEN = 8,
     601        WC_PK_TYPE_EC_KEYGEN = 9,
     602
     603        WC_PK_TYPE_MAX = WC_PK_TYPE_EC_KEYGEN
     604    };
    457605
    458606
     
    582730    #endif
    583731
     732
     733    #if defined(__GNUC__)
     734        #define WOLFSSL_PACK __attribute__ ((packed))
     735    #else
     736        #define WOLFSSL_PACK
     737    #endif
     738
     739    #ifndef __GNUC_PREREQ
     740        #if defined(__GNUC__) && defined(__GNUC_MINOR__)
     741            #define __GNUC_PREREQ(maj, min) \
     742                ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
     743        #else
     744            #define __GNUC_PREREQ(maj, min) (0) /* not GNUC */
     745        #endif
     746    #endif
     747
     748    #if defined(__GNUC__)
     749        #define WC_NORETURN __attribute__((noreturn))
     750    #else
     751        #define WC_NORETURN
     752    #endif
     753
     754    #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) || \
     755        defined(WOLFSSL_DEBUG_MATH) || defined(DEBUG_WOLFSSL) || \
     756        defined(WOLFSSL_PUBLIC_MP) || defined(OPENSSL_EXTRA) || \
     757            (defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT))
     758        #undef  WC_MP_TO_RADIX
     759        #define WC_MP_TO_RADIX
     760    #endif
     761
    584762        #ifdef __cplusplus
    585763            }   /* extern "C" */
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/visibility.h

    r352 r372  
    2828
    2929/* for compatibility and so that fips is using same name of macro @wc_fips */
    30 #ifdef HAVE_FIPS
     30/* The following visibility wrappers are for old FIPS. New FIPS should use
     31 * the same as a non-FIPS build. */
     32#if defined(HAVE_FIPS) && \
     33    (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
    3134    #include <cyassl/ctaocrypt/visibility.h>
    3235    #define WOLFSSL_API   CYASSL_API
     
    4144
    4245#if defined(BUILDING_WOLFSSL)
    43     #if defined(HAVE_VISIBILITY) && HAVE_VISIBILITY
    44         #define WOLFSSL_API   __attribute__ ((visibility("default")))
    45         #define WOLFSSL_LOCAL __attribute__ ((visibility("hidden")))
    46     #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
    47         #define WOLFSSL_API   __global
    48         #define WOLFSSL_LOCAL __hidden
    49     #elif defined(_MSC_VER) || defined(__MINGW32__)
     46    #if defined(_MSC_VER) || defined(__MINGW32__)
    5047        #if defined(WOLFSSL_DLL)
    5148            #define WOLFSSL_API __declspec(dllexport)
     
    5451        #endif
    5552        #define WOLFSSL_LOCAL
     53    #elif defined(HAVE_VISIBILITY) && HAVE_VISIBILITY
     54        #define WOLFSSL_API   __attribute__ ((visibility("default")))
     55        #define WOLFSSL_LOCAL __attribute__ ((visibility("hidden")))
     56    #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
     57        #define WOLFSSL_API   __global
     58        #define WOLFSSL_LOCAL __hidden
    5659    #else
    5760        #define WOLFSSL_API
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/wc_encrypt.h

    r352 r372  
    2020 */
    2121
     22/*!
     23    \file wolfssl/wolfcrypt/wc_encrypt.h
     24*/
    2225
    2326
     
    2629
    2730#include <wolfssl/wolfcrypt/types.h>
     31#include <wolfssl/wolfcrypt/aes.h>
     32#include <wolfssl/wolfcrypt/chacha.h>
     33#include <wolfssl/wolfcrypt/des3.h>
     34#include <wolfssl/wolfcrypt/arc4.h>
    2835
    2936#ifdef __cplusplus
     
    3138#endif
    3239
     40/* determine max cipher key size */
    3341#ifndef NO_AES
     42    #define WC_MAX_SYM_KEY_SIZE     (AES_MAX_KEY_SIZE/8)
     43#elif defined(HAVE_CHACHA)
     44    #define WC_MAX_SYM_KEY_SIZE     CHACHA_MAX_KEY_SZ
     45#elif !defined(NO_DES3)
     46    #define WC_MAX_SYM_KEY_SIZE     DES3_KEY_SIZE
     47#elif !defined(NO_RC4)
     48    #define WC_MAX_SYM_KEY_SIZE     RC4_KEY_SIZE
     49#else
     50    #define WC_MAX_SYM_KEY_SIZE     32
     51#endif
     52
     53
     54#if !defined(NO_AES) && defined(HAVE_AES_CBC)
    3455WOLFSSL_API int  wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
    3556                                         const byte* key, word32 keySz,
     
    5677#endif /* !NO_DES3 */
    5778
     79
     80
     81
     82#ifdef WOLFSSL_ENCRYPTED_KEYS
     83    struct EncryptedInfo;
     84    WOLFSSL_API int wc_BufferKeyDecrypt(struct EncryptedInfo* info, byte* der, word32 derSz,
     85        const byte* password, int passwordSz, int hashType);
     86    WOLFSSL_API int wc_BufferKeyEncrypt(struct EncryptedInfo* info, byte* der, word32 derSz,
     87        const byte* password, int passwordSz, int hashType);
     88#endif /* WOLFSSL_ENCRYPTED_KEYS */
     89
     90#ifndef NO_PWDBASED
     91    WOLFSSL_LOCAL int wc_CryptKey(const char* password, int passwordSz,
     92        byte* salt, int saltSz, int iterations, int id, byte* input, int length,
     93        int version, byte* cbcIv, int enc);
     94#endif
     95
    5896#ifdef __cplusplus
    5997    }  /* extern "C" */
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/wc_port.h

    r352 r372  
    2020 */
    2121
    22 
     22/*!
     23    \file wolfssl/wolfcrypt/wc_port.h
     24*/
    2325
    2426#ifndef WOLF_CRYPT_PORT_H
     
    3234#endif
    3335
     36/* Detect if compiler supports C99. "NO_WOLF_C99" can be defined in
     37 * user_settings.h to disable checking for C99 support. */
     38#if !defined(WOLF_C99) && defined(__STDC_VERSION__) && \
     39    !defined(WOLFSSL_ARDUINO) && !defined(NO_WOLF_C99)
     40    #if __STDC_VERSION__ >= 199901L
     41        #define WOLF_C99
     42    #endif
     43#endif
    3444
    3545#ifdef USE_WINDOWS_API
     
    6575#elif defined(FREESCALE_FREE_RTOS)
    6676    #include "fsl_os_abstraction.h"
     77#elif defined(WOLFSSL_VXWORKS)
     78    #include <semLib.h>
    6779#elif defined(WOLFSSL_uITRON4)
    6880    #include "stddef.h"
     
    7082#elif  defined(WOLFSSL_uTKERNEL2)
    7183    #include "tk/tkernel.h"
     84#elif defined(WOLFSSL_CMSIS_RTOS)
     85    #include "cmsis_os.h"
    7286#elif defined(WOLFSSL_MDK_ARM)
    7387    #if defined(WOLFSSL_MDK5)
     
    86100    #include <rt.h>
    87101    #include <io.h>
     102#elif defined(WOLFSSL_NUCLEUS_1_2)
     103    /* NU_DEBUG needed struct access in nucleus_realloc */
     104    #define NU_DEBUG
     105    #include "plus/nucleus.h"
     106    #include "nucleus.h"
     107#elif defined(WOLFSSL_APACHE_MYNEWT)
     108    /* do nothing */
    88109#else
    89110    #ifndef SINGLE_THREADED
     
    133154    #elif defined(FREESCALE_FREE_RTOS)
    134155        typedef mutex_t wolfSSL_Mutex;
     156    #elif defined(WOLFSSL_VXWORKS)
     157        typedef SEM_ID wolfSSL_Mutex;
    135158    #elif defined(WOLFSSL_uITRON4)
    136159        typedef struct wolfSSL_Mutex {
     
    157180    #elif defined(INTIME_RTOS)
    158181        typedef RTHANDLE wolfSSL_Mutex;
     182    #elif defined(WOLFSSL_NUCLEUS_1_2)
     183        typedef NU_SEMAPHORE wolfSSL_Mutex;
    159184    #else
    160185        #error Need a mutex type in multithreaded mode
     
    185210    #define wolfSSL_CryptHwMutexInit()      0 /* Success */
    186211    #define wolfSSL_CryptHwMutexLock()      0 /* Success */
    187     #define wolfSSL_CryptHwMutexUnLock()    0 /* Success */
     212    #define wolfSSL_CryptHwMutexUnLock()    (void)0 /* Success */
    188213#endif /* WOLFSSL_CRYPT_HW_MUTEX */
    189214
     
    194219WOLFSSL_API int wc_LockMutex(wolfSSL_Mutex*);
    195220WOLFSSL_API int wc_UnLockMutex(wolfSSL_Mutex*);
     221#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
     222/* dynamiclly set which mutex to use. unlock / lock is controlled by flag */
     223typedef void (mutex_cb)(int flag, int type, const char* file, int line);
     224
     225WOLFSSL_API int wc_LockMutex_ex(int flag, int type, const char* file, int line);
     226WOLFSSL_API int wc_SetMutexCb(mutex_cb* cb);
     227#endif
    196228
    197229/* main crypto initialization function */
     
    255287    #define XBADFILE   NULL
    256288    #define XFGETS(b,s,f) -2 /* Not ported yet */
     289#elif defined(WOLFSSL_NUCLEUS_1_2)
     290    #include "fal/inc/fal.h"
     291    #define XFILE      FILE*
     292    #define XFOPEN     fopen
     293    #define XFSEEK     fseek
     294    #define XFTELL     ftell
     295    #define XREWIND    rewind
     296    #define XFREAD     fread
     297    #define XFWRITE    fwrite
     298    #define XFCLOSE    fclose
     299    #define XSEEK_END  PSEEK_END
     300    #define XBADFILE   NULL
     301#elif defined(WOLFSSL_APACHE_MYNEWT)
     302    #include <fs/fs.h>
     303    #define XFILE  struct fs_file*
     304
     305    #define XFOPEN     mynewt_fopen
     306    #define XFSEEK     mynewt_fseek
     307    #define XFTELL     mynewt_ftell
     308    #define XREWIND    mynewt_rewind
     309    #define XFREAD     mynewt_fread
     310    #define XFWRITE    mynewt_fwrite
     311    #define XFCLOSE    mynewt_fclose
     312    #define XSEEK_END  2
     313    #define XBADFILE   NULL
     314    #define XFGETS(b,s,f) -2 /* Not ported yet */
     315#elif defined(WOLFSSL_USER_FILESYSTEM)
     316    /* To be defined in user_settings.h */
    257317#else
    258318    /* stdio, default case */
     
    275335    #define XFGETS     fgets
    276336
    277     #if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR)
     337    #if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR)\
     338        && !defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
    278339        #include <dirent.h>
    279340        #include <unistd.h>
     
    289350    #endif
    290351
    291 #if !defined(NO_WOLFSSL_DIR)
     352#if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_NUCLEUS) && \
     353    !defined(WOLFSSL_NUCLEUS_1_2)
    292354    typedef struct ReadDirCtx {
    293355    #ifdef USE_WINDOWS_API
     
    302364    } ReadDirCtx;
    303365
     366    #define WC_READDIR_NOFILE -1
     367
    304368    WOLFSSL_API int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name);
    305369    WOLFSSL_API int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name);
     
    308372
    309373#endif /* !NO_FILESYSTEM */
    310 
    311 #ifdef USE_WOLF_STRTOK
    312     WOLFSSL_LOCAL char* wc_strtok(char *str, const char *delim, char **nextp);
    313 #endif
    314374
    315375/* Windows API defines its own min() macro. */
     
    323383#endif /* USE_WINDOWS_API */
    324384
     385/* Time functions */
     386#ifndef NO_ASN_TIME
     387#if defined(USER_TIME)
     388    /* Use our gmtime and time_t/struct tm types.
     389       Only needs seconds since EPOCH using XTIME function.
     390       time_t XTIME(time_t * timer) {}
     391    */
     392    #define WOLFSSL_GMTIME
     393    #define USE_WOLF_TM
     394    #define USE_WOLF_TIME_T
     395
     396#elif defined(TIME_OVERRIDES)
     397    /* Override XTIME() and XGMTIME() functionality.
     398       Requires user to provide these functions:
     399        time_t XTIME(time_t * timer) {}
     400        struct tm* XGMTIME(const time_t* timer, struct tm* tmp) {}
     401    */
     402    #ifndef HAVE_TIME_T_TYPE
     403        #define USE_WOLF_TIME_T
     404    #endif
     405    #ifndef HAVE_TM_TYPE
     406        #define USE_WOLF_TM
     407    #endif
     408    #define NEED_TMP_TIME
     409
     410#elif defined(HAVE_RTP_SYS)
     411    #include "os.h"           /* dc_rtc_api needs    */
     412    #include "dc_rtc_api.h"   /* to get current time */
     413
     414    /* uses parital <time.h> structures */
     415    #define XTIME(tl)       (0)
     416    #define XGMTIME(c, t)   rtpsys_gmtime((c))
     417
     418#elif defined(MICRIUM)
     419    #include <clk.h>
     420    #include <time.h>
     421    #define XTIME(t1)       micrium_time((t1))
     422    #define WOLFSSL_GMTIME
     423
     424#elif defined(MICROCHIP_TCPIP_V5) || defined(MICROCHIP_TCPIP)
     425    #include <time.h>
     426    #define XTIME(t1)       pic32_time((t1))
     427    #define XGMTIME(c, t)   gmtime((c))
     428
     429#elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
     430    #ifdef FREESCALE_MQX_4_0
     431        #include <time.h>
     432        extern time_t mqx_time(time_t* timer);
     433    #else
     434        #define HAVE_GMTIME_R
     435    #endif
     436    #define XTIME(t1)       mqx_time((t1))
     437
     438#elif defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS) || defined(FREESCALE_KSDK_FREERTOS)
     439    #include <time.h>
     440    #ifndef XTIME
     441        /*extern time_t ksdk_time(time_t* timer);*/
     442        #define XTIME(t1)   ksdk_time((t1))
     443    #endif
     444    #define XGMTIME(c, t)   gmtime((c))
     445
     446#elif defined(WOLFSSL_ATMEL) && defined(WOLFSSL_ATMEL_TIME)
     447    #define XTIME(t1)       atmel_get_curr_time_and_date((t1))
     448    #define WOLFSSL_GMTIME
     449    #define USE_WOLF_TM
     450    #define USE_WOLF_TIME_T
     451
     452#elif defined(IDIRECT_DEV_TIME)
     453    /*Gets the timestamp from cloak software owned by VT iDirect
     454    in place of time() from <time.h> */
     455    #include <time.h>
     456    #define XTIME(t1)       idirect_time((t1))
     457    #define XGMTIME(c, t)   gmtime((c))
     458
     459#elif defined(_WIN32_WCE)
     460    #include <windows.h>
     461    #define XTIME(t1)       windows_time((t1))
     462    #define WOLFSSL_GMTIME
     463
     464#elif defined(WOLFSSL_APACHE_MYNEWT)
     465    #include "os/os_time.h"
     466    #define XTIME(t1)       mynewt_time((t1))
     467    #define WOLFSSL_GMTIME
     468    #define USE_WOLF_TM
     469    #define USE_WOLF_TIME_T
     470#else
     471    /* default */
     472    /* uses complete <time.h> facility */
     473    #include <time.h>
     474    #if defined(HAVE_SYS_TIME_H)
     475        #include <sys/time.h>
     476    #endif
     477
     478    /* PowerPC time_t is int */
     479    #ifdef __PPC__
     480        #define TIME_T_NOT_64BIT
     481    #endif
     482#endif
     483
     484#ifdef SIZEOF_TIME_T
     485    /* check if size of time_t from autoconf is less than 8 bytes (64bits) */
     486    #if SIZEOF_TIME_T < 8
     487        #undef  TIME_T_NOT_64BIT
     488        #define TIME_T_NOT_64BIT
     489    #endif
     490#endif
     491#ifdef TIME_T_NOT_LONG
     492    /* one old reference to TIME_T_NOT_LONG in GCC-ARM example README
     493     * this keeps support for the old macro name */
     494    #undef TIME_T_NOT_64BIT
     495    #define TIME_T_NOT_64BIT
     496#endif
     497
     498/* Map default time functions */
     499#if !defined(XTIME) && !defined(TIME_OVERRIDES) && !defined(USER_TIME)
     500    #define XTIME(tl)       time((tl))
     501#endif
     502#if !defined(XGMTIME) && !defined(TIME_OVERRIDES)
     503    #if defined(WOLFSSL_GMTIME) || !defined(HAVE_GMTIME_R) || defined(WOLF_C99)
     504        #define XGMTIME(c, t)   gmtime((c))
     505    #else
     506        #define XGMTIME(c, t)   gmtime_r((c), (t))
     507        #define NEED_TMP_TIME
     508    #endif
     509#endif
     510#if !defined(XVALIDATE_DATE) && !defined(HAVE_VALIDATE_DATE)
     511    #define USE_WOLF_VALIDDATE
     512    #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
     513#endif
     514
     515/* wolf struct tm and time_t */
     516#if defined(USE_WOLF_TM)
     517    struct tm {
     518        int  tm_sec;     /* seconds after the minute [0-60] */
     519        int  tm_min;     /* minutes after the hour [0-59] */
     520        int  tm_hour;    /* hours since midnight [0-23] */
     521        int  tm_mday;    /* day of the month [1-31] */
     522        int  tm_mon;     /* months since January [0-11] */
     523        int  tm_year;    /* years since 1900 */
     524        int  tm_wday;    /* days since Sunday [0-6] */
     525        int  tm_yday;    /* days since January 1 [0-365] */
     526        int  tm_isdst;   /* Daylight Savings Time flag */
     527        long tm_gmtoff;  /* offset from CUT in seconds */
     528        char *tm_zone;   /* timezone abbreviation */
     529    };
     530#endif /* USE_WOLF_TM */
     531#if defined(USE_WOLF_TIME_T)
     532    typedef long time_t;
     533#endif
     534#if defined(USE_WOLF_SUSECONDS_T)
     535    typedef long suseconds_t;
     536#endif
     537#if defined(USE_WOLF_TIMEVAL_T)
     538    struct timeval
     539    {
     540        time_t tv_sec;
     541        suseconds_t tv_usec;
     542    };
     543#endif
     544
     545    /* forward declarations */
     546#if defined(USER_TIME)
     547    struct tm* gmtime(const time_t* timer);
     548    extern time_t XTIME(time_t * timer);
     549
     550    #ifdef STACK_TRAP
     551        /* for stack trap tracking, don't call os gmtime on OS X/linux,
     552           uses a lot of stack spce */
     553        extern time_t time(time_t * timer);
     554        #define XTIME(tl)  time((tl))
     555    #endif /* STACK_TRAP */
     556
     557#elif defined(TIME_OVERRIDES)
     558    extern time_t XTIME(time_t * timer);
     559    extern struct tm* XGMTIME(const time_t* timer, struct tm* tmp);
     560#elif defined(WOLFSSL_GMTIME)
     561    struct tm* gmtime(const time_t* timer);
     562#endif
     563#endif /* NO_ASN_TIME */
     564
     565#ifndef WOLFSSL_LEANPSK
     566    char* mystrnstr(const char* s1, const char* s2, unsigned int n);
     567#endif
     568
     569#ifndef FILE_BUFFER_SIZE
     570    #define FILE_BUFFER_SIZE 1024     /* default static file buffer size for input,
     571                                    will use dynamic buffer if not big enough */
     572#endif
     573
    325574
    326575#ifdef __cplusplus
  • asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/wolfmath.h

    r352 r372  
    5252    int mp_rand(mp_int* a, int digits, WC_RNG* rng);
    5353
     54    enum {
     55        /* format type */
     56        WC_TYPE_HEX_STR = 1,
     57        WC_TYPE_UNSIGNED_BIN = 2,
     58    };
     59
     60    WOLFSSL_API int wc_export_int(mp_int* mp, byte* buf, word32* len,
     61        word32 keySz, int encType);
    5462
    5563    #ifdef HAVE_WOLF_BIGINT
     
    6270
    6371        int wc_mp_to_bigint(mp_int* src, WC_BIGINT* dst);
     72        int wc_mp_to_bigint_sz(mp_int* src, WC_BIGINT* dst, word32 sz);
    6473        int wc_bigint_to_mp(WC_BIGINT* src, mp_int* dst);
    6574    #endif /* HAVE_WOLF_BIGINT */
Note: See TracChangeset for help on using the changeset viewer.