Ignore:
Timestamp:
Jun 22, 2021, 9:00:19 PM (3 years ago)
Author:
coas-nagasima
Message:

WolfSSLとAzure IoT SDKを更新

Location:
azure_iot_hub_f767zi/trunk/wolfssl-4.7.0
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfssl/wolfcrypt/ecc.h

    r457 r464  
    5151#endif
    5252
    53 #ifdef WOLFSSL_ATECC508A
     53#if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A)
    5454    #include <wolfssl/wolfcrypt/port/atmel/atmel.h>
    5555#endif /* WOLFSSL_ATECC508A */
     
    5858    #include <wolfssl/wolfcrypt/port/arm/cryptoCell.h>
    5959#endif
     60
     61#ifdef WOLFSSL_SILABS_SE_ACCEL
     62    #include <wolfssl/wolfcrypt/port/silabs/silabs_ecc.h>
     63#endif
     64
     65#ifdef WOLFSSL_HAVE_SP_ECC
     66    #include <wolfssl/wolfcrypt/sp_int.h>
     67#endif
     68
    6069
    6170#ifdef __cplusplus
     
    121130    SIG_HEADER_SZ   =  7,   /* ECC signature header size (30 81 87 02 42 [R] 02 42 [S]) */
    122131    ECC_BUFSIZE     = 256,  /* for exported keys temp buffer */
    123     ECC_MINSIZE     = 20,   /* MIN Private Key size */
     132    ECC_MINSIZE     = ECC_MIN_KEY_SZ/8,   /* MIN Private Key size */
    124133    ECC_MAXSIZE     = 66,   /* MAX Private Key size */
    125134    ECC_MAXSIZE_GEN = 74,   /* MAX Buffer size required when generating ECC keys*/
     
    128137
    129138    /* max crypto hardware size */
    130 #ifdef WOLFSSL_ATECC508A
     139#if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A)
    131140    ECC_MAX_CRYPTO_HW_SIZE = ATECC_KEY_SIZE, /* from port/atmel/atmel.h */
    132141    ECC_MAX_CRYPTO_HW_PUBKEY_SIZE = (ATECC_KEY_SIZE*2),
    133142#elif defined(PLUTON_CRYPTO_ECC)
     143    ECC_MAX_CRYPTO_HW_SIZE = 32,
     144#elif defined(WOLFSSL_SILABS_SE_ACCEL)
    134145    ECC_MAX_CRYPTO_HW_SIZE = 32,
    135146#elif defined(WOLFSSL_CRYPTOCELL)
     
    148159    SHAMIR_PRECOMP_SZ = 16,
    149160
    150 #ifdef HAVE_PKCS11
     161#ifdef WOLF_CRYPTO_CB
    151162    ECC_MAX_ID_LEN    = 32,
     163    ECC_MAX_LABEL_LEN = 32,
    152164#endif
    153165};
     
    204216    ECC_CURVE_CUSTOM,
    205217#endif
     218    ECC_CURVE_MAX
    206219} ecc_curve_id;
    207220
     
    279292 * of the point are pointers that are set to each of a three item array of
    280293 * alt_fp_ints. While an mp_int will have 4096 bits of digit inside the
    281  * structure, the alt_fp_int will only have 528 bits. A size value was added
    282  * in the ALT case, as well, and is set by mp_init() and alt_fp_init(). The
    283  * functions fp_zero() and fp_copy() use the size parameter. An int needs to
    284  * be initialized before using it instead of just fp_zeroing it, the init will
    285  * call zero. FP_MAX_BITS_ECC defaults to 528, but can be set to change the
    286  * number of bits used in the alternate FP_INT.
     294 * structure, the alt_fp_int will only have 512 bits for ECC 256-bit and
     295 * 1056-bits for ECC 521-bit. A size value was added in the ALT case, as well,
     296 * and is set by mp_init() and alt_fp_init(). The functions fp_zero() and
     297 * fp_copy() use the size parameter. An int needs to be initialized before
     298 * using it instead of just fp_zeroing it, the init will call zero. The
     299 * FP_MAX_BITS_ECC defaults to calculating based on MAX_ECC_BITS, but
     300 * can be set to change the number of bits used in the alternate FP_INT.
    287301 *
    288  * Do not enable ALT_ECC_SIZE and disable fast math in the configuration.
     302 * The ALT_ECC_SIZE option only applies to stack based fast math USE_FAST_MATH.
    289303 */
    290304
     
    295309/* determine max bits required for ECC math */
    296310#ifndef FP_MAX_BITS_ECC
    297     /* check alignment */
    298     #if ((MAX_ECC_BITS * 2) % DIGIT_BIT) == 0
    299         /* max bits is double */
    300         #define FP_MAX_BITS_ECC     (MAX_ECC_BITS * 2)
    301     #else
    302         /* max bits is doubled, plus one digit of fudge */
    303         #define FP_MAX_BITS_ECC     ((MAX_ECC_BITS * 2) + DIGIT_BIT)
    304     #endif
    305 #else
    306     /* verify alignment */
    307     #if FP_MAX_BITS_ECC % CHAR_BIT
    308        #error FP_MAX_BITS_ECC must be a multiple of CHAR_BIT
    309     #endif
     311    /* max bits rounded up by 8 then doubled */
     312    /* (ROUND8(MAX_ECC_BITS) * 2) */
     313    #define FP_MAX_BITS_ECC (2 * \
     314        ((MAX_ECC_BITS + DIGIT_BIT - 1) / DIGIT_BIT) * DIGIT_BIT)
     315
     316    /* Note: For ECC verify only FP_MAX_BITS_ECC can be reduced to:
     317             ROUND8(MAX_ECC_BITS) + ROUND8(DIGIT_BIT) */
     318#endif
     319
     320/* verify alignment */
     321#if FP_MAX_BITS_ECC % CHAR_BIT
     322    #error FP_MAX_BITS_ECC must be a multiple of CHAR_BIT
    310323#endif
    311324
    312325/* determine buffer size */
    313 #define FP_SIZE_ECC    (FP_MAX_BITS_ECC/DIGIT_BIT)
     326/* Add one to accommodate extra digit used by sp_mul(), sp_mulmod(), sp_sqr(), and sp_sqrmod(). */
     327#define FP_SIZE_ECC    ((FP_MAX_BITS_ECC/DIGIT_BIT) + 1)
    314328
    315329
     
    348362/* ECC Flags */
    349363enum {
    350     WC_ECC_FLAG_NONE = 0x00,
     364    WC_ECC_FLAG_NONE     = 0x00,
    351365#ifdef HAVE_ECC_CDH
    352366    WC_ECC_FLAG_COFACTOR = 0x01,
    353367#endif
     368    WC_ECC_FLAG_DEC_SIGN = 0x02,
    354369};
     370
     371/* ECC non-blocking */
     372#ifdef WC_ECC_NONBLOCK
     373    typedef struct ecc_nb_ctx {
     374    #if defined(WOLFSSL_HAVE_SP_ECC) && defined(WOLFSSL_SP_NONBLOCK)
     375        sp_ecc_ctx_t sp_ctx;
     376    #else
     377        /* build configuration not supported */
     378        #error ECC non-blocking only supports SP (--enable-sp=nonblock)
     379    #endif
     380    } ecc_nb_ctx_t;
     381#endif /* WC_ECC_NONBLOCK */
     382
    355383
    356384/* An ECC Key */
     
    370398    ecc_point pubkey;   /* public key */
    371399    mp_int    k;        /* private key */
    372 #ifdef WOLFSSL_ATECC508A
     400#if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A)
    373401    int  slot;        /* Key Slot Number (-1 unknown) */
    374402    byte pubkey_raw[ECC_MAX_CRYPTO_HW_PUBKEY_SIZE];
     
    377405    int devId;
    378406#endif
     407#ifdef WOLFSSL_SILABS_SE_ACCEL
     408    sl_se_command_context_t  cmd_ctx;
     409    sl_se_key_descriptor_t   key;
     410    /* Used for SiLabs "plaintext" with public X, public Y, and
     411     * private D concatenated. These are respectively at offset `0`,
     412     * offset `keysize`, and offset `2 * keysize`.
     413     */
     414    byte key_raw[3 * ECC_MAX_CRYPTO_HW_SIZE];
     415#endif
     416
    379417#ifdef WOLFSSL_ASYNC_CRYPT
    380418    mp_int* r;          /* sign/verify temps */
     
    389427    #endif
    390428#endif /* WOLFSSL_ASYNC_CRYPT */
    391 #ifdef HAVE_PKCS11
     429#ifdef WOLF_CRYPTO_CB
    392430    byte id[ECC_MAX_ID_LEN];
    393431    int  idLen;
     432    char label[ECC_MAX_LABEL_LEN];
     433    int  labelLen;
    394434#endif
    395435#if defined(WOLFSSL_CRYPTOCELL)
     
    414454    remote_handle64 handle;
    415455#endif
     456#ifdef ECC_TIMING_RESISTANT
     457    WC_RNG* rng;
     458#endif
     459#ifdef WC_ECC_NONBLOCK
     460    ecc_nb_ctx_t* nb_ctx;
     461#endif
    416462};
    417463
     
    428474const char* wc_ecc_get_name(int curve_id);
    429475
    430 #ifndef WOLFSSL_ATECC508A
     476#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
    431477
    432478#ifdef WOLFSSL_PUBLIC_ECC_ADD_DBL
     
    447493                                     mp_int* modulus, mp_digit mp);
    448494
     495WOLFSSL_LOCAL
     496int ecc_projective_add_point_safe(ecc_point* A, ecc_point* B, ecc_point* R,
     497    mp_int* a, mp_int* modulus, mp_digit mp, int* infinity);
     498WOLFSSL_LOCAL
     499int ecc_projective_dbl_point_safe(ecc_point* P, ecc_point* R, mp_int* a,
     500                                  mp_int* modulus, mp_digit mp);
     501
    449502#endif
    450503
     
    454507int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id);
    455508WOLFSSL_API
     509int wc_ecc_make_key_ex2(WC_RNG* rng, int keysize, ecc_key* key, int curve_id,
     510                        int flags);
     511WOLFSSL_API
    456512int wc_ecc_make_pub(ecc_key* key, ecc_point* pubOut);
     513WOLFSSL_API
     514int wc_ecc_make_pub_ex(ecc_key* key, ecc_point* pubOut, WC_RNG* rng);
    457515WOLFSSL_API
    458516int wc_ecc_check_key(ecc_key* key);
     
    473531                             byte* out, word32 *outlen);
    474532
    475 #if defined(WOLFSSL_ATECC508A) || defined(PLUTON_CRYPTO_ECC) || defined(WOLFSSL_CRYPTOCELL)
     533#if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
     534    defined(PLUTON_CRYPTO_ECC) || defined(WOLFSSL_CRYPTOCELL)
    476535#define wc_ecc_shared_secret_ssh wc_ecc_shared_secret
    477536#else
     
    507566WOLFSSL_ABI WOLFSSL_API
    508567int wc_ecc_init_ex(ecc_key* key, void* heap, int devId);
    509 #ifdef HAVE_PKCS11
     568#ifdef WOLF_CRYPTO_CB
    510569WOLFSSL_API
    511570int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap,
    512571                   int devId);
     572WOLFSSL_API
     573int wc_ecc_init_label(ecc_key* key, const char* label, void* heap, int devId);
    513574#endif
    514575#ifdef WOLFSSL_CUSTOM_CURVES
     
    522583WOLFSSL_API
    523584void wc_ecc_fp_free(void);
     585WOLFSSL_LOCAL
     586void wc_ecc_fp_init(void);
     587#ifdef ECC_TIMING_RESISTANT
     588WOLFSSL_API
     589int wc_ecc_set_rng(ecc_key* key, WC_RNG* rng);
     590#endif
    524591
    525592WOLFSSL_API
     
    569636WOLFSSL_API
    570637int wc_ecc_point_is_at_infinity(ecc_point *p);
    571 
    572 #ifndef WOLFSSL_ATECC508A
     638WOLFSSL_API
     639int wc_ecc_point_is_on_curve(ecc_point *p, int curve_idx);
     640
     641#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
    573642WOLFSSL_API
    574643int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R,
     
    577646int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R,
    578647                  mp_int* a, mp_int* modulus, int map, void* heap);
     648WOLFSSL_LOCAL
     649int wc_ecc_mulmod_ex2(mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
     650                      mp_int* modulus, mp_int* order, WC_RNG* rng, int map,
     651                      void* heap);
    579652#endif /* !WOLFSSL_ATECC508A */
    580653
     
    755828#endif
    756829
     830#ifdef WC_ECC_NONBLOCK
     831    WOLFSSL_API int wc_ecc_set_nonblock(ecc_key *key, ecc_nb_ctx_t* ctx);
     832#endif
     833
    757834#ifdef __cplusplus
    758835    }    /* extern "C" */
Note: See TracChangeset for help on using the changeset viewer.