- Timestamp:
- Jun 22, 2021, 9:00:19 PM (3 years ago)
- 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 51 51 #endif 52 52 53 #if def WOLFSSL_ATECC508A53 #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) 54 54 #include <wolfssl/wolfcrypt/port/atmel/atmel.h> 55 55 #endif /* WOLFSSL_ATECC508A */ … … 58 58 #include <wolfssl/wolfcrypt/port/arm/cryptoCell.h> 59 59 #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 60 69 61 70 #ifdef __cplusplus … … 121 130 SIG_HEADER_SZ = 7, /* ECC signature header size (30 81 87 02 42 [R] 02 42 [S]) */ 122 131 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 */ 124 133 ECC_MAXSIZE = 66, /* MAX Private Key size */ 125 134 ECC_MAXSIZE_GEN = 74, /* MAX Buffer size required when generating ECC keys*/ … … 128 137 129 138 /* max crypto hardware size */ 130 #if def WOLFSSL_ATECC508A139 #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) 131 140 ECC_MAX_CRYPTO_HW_SIZE = ATECC_KEY_SIZE, /* from port/atmel/atmel.h */ 132 141 ECC_MAX_CRYPTO_HW_PUBKEY_SIZE = (ATECC_KEY_SIZE*2), 133 142 #elif defined(PLUTON_CRYPTO_ECC) 143 ECC_MAX_CRYPTO_HW_SIZE = 32, 144 #elif defined(WOLFSSL_SILABS_SE_ACCEL) 134 145 ECC_MAX_CRYPTO_HW_SIZE = 32, 135 146 #elif defined(WOLFSSL_CRYPTOCELL) … … 148 159 SHAMIR_PRECOMP_SZ = 16, 149 160 150 #ifdef HAVE_PKCS11161 #ifdef WOLF_CRYPTO_CB 151 162 ECC_MAX_ID_LEN = 32, 163 ECC_MAX_LABEL_LEN = 32, 152 164 #endif 153 165 }; … … 204 216 ECC_CURVE_CUSTOM, 205 217 #endif 218 ECC_CURVE_MAX 206 219 } ecc_curve_id; 207 220 … … 279 292 * of the point are pointers that are set to each of a three item array of 280 293 * 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. 287 301 * 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. 289 303 */ 290 304 … … 295 309 /* determine max bits required for ECC math */ 296 310 #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 310 323 #endif 311 324 312 325 /* 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) 314 328 315 329 … … 348 362 /* ECC Flags */ 349 363 enum { 350 WC_ECC_FLAG_NONE = 0x00,364 WC_ECC_FLAG_NONE = 0x00, 351 365 #ifdef HAVE_ECC_CDH 352 366 WC_ECC_FLAG_COFACTOR = 0x01, 353 367 #endif 368 WC_ECC_FLAG_DEC_SIGN = 0x02, 354 369 }; 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 355 383 356 384 /* An ECC Key */ … … 370 398 ecc_point pubkey; /* public key */ 371 399 mp_int k; /* private key */ 372 #if def WOLFSSL_ATECC508A400 #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) 373 401 int slot; /* Key Slot Number (-1 unknown) */ 374 402 byte pubkey_raw[ECC_MAX_CRYPTO_HW_PUBKEY_SIZE]; … … 377 405 int devId; 378 406 #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 379 417 #ifdef WOLFSSL_ASYNC_CRYPT 380 418 mp_int* r; /* sign/verify temps */ … … 389 427 #endif 390 428 #endif /* WOLFSSL_ASYNC_CRYPT */ 391 #ifdef HAVE_PKCS11429 #ifdef WOLF_CRYPTO_CB 392 430 byte id[ECC_MAX_ID_LEN]; 393 431 int idLen; 432 char label[ECC_MAX_LABEL_LEN]; 433 int labelLen; 394 434 #endif 395 435 #if defined(WOLFSSL_CRYPTOCELL) … … 414 454 remote_handle64 handle; 415 455 #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 416 462 }; 417 463 … … 428 474 const char* wc_ecc_get_name(int curve_id); 429 475 430 #if ndef WOLFSSL_ATECC508A476 #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) 431 477 432 478 #ifdef WOLFSSL_PUBLIC_ECC_ADD_DBL … … 447 493 mp_int* modulus, mp_digit mp); 448 494 495 WOLFSSL_LOCAL 496 int 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); 498 WOLFSSL_LOCAL 499 int ecc_projective_dbl_point_safe(ecc_point* P, ecc_point* R, mp_int* a, 500 mp_int* modulus, mp_digit mp); 501 449 502 #endif 450 503 … … 454 507 int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id); 455 508 WOLFSSL_API 509 int wc_ecc_make_key_ex2(WC_RNG* rng, int keysize, ecc_key* key, int curve_id, 510 int flags); 511 WOLFSSL_API 456 512 int wc_ecc_make_pub(ecc_key* key, ecc_point* pubOut); 513 WOLFSSL_API 514 int wc_ecc_make_pub_ex(ecc_key* key, ecc_point* pubOut, WC_RNG* rng); 457 515 WOLFSSL_API 458 516 int wc_ecc_check_key(ecc_key* key); … … 473 531 byte* out, word32 *outlen); 474 532 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) 476 535 #define wc_ecc_shared_secret_ssh wc_ecc_shared_secret 477 536 #else … … 507 566 WOLFSSL_ABI WOLFSSL_API 508 567 int wc_ecc_init_ex(ecc_key* key, void* heap, int devId); 509 #ifdef HAVE_PKCS11568 #ifdef WOLF_CRYPTO_CB 510 569 WOLFSSL_API 511 570 int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap, 512 571 int devId); 572 WOLFSSL_API 573 int wc_ecc_init_label(ecc_key* key, const char* label, void* heap, int devId); 513 574 #endif 514 575 #ifdef WOLFSSL_CUSTOM_CURVES … … 522 583 WOLFSSL_API 523 584 void wc_ecc_fp_free(void); 585 WOLFSSL_LOCAL 586 void wc_ecc_fp_init(void); 587 #ifdef ECC_TIMING_RESISTANT 588 WOLFSSL_API 589 int wc_ecc_set_rng(ecc_key* key, WC_RNG* rng); 590 #endif 524 591 525 592 WOLFSSL_API … … 569 636 WOLFSSL_API 570 637 int wc_ecc_point_is_at_infinity(ecc_point *p); 571 572 #ifndef WOLFSSL_ATECC508A 638 WOLFSSL_API 639 int wc_ecc_point_is_on_curve(ecc_point *p, int curve_idx); 640 641 #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) 573 642 WOLFSSL_API 574 643 int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, … … 577 646 int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, 578 647 mp_int* a, mp_int* modulus, int map, void* heap); 648 WOLFSSL_LOCAL 649 int 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); 579 652 #endif /* !WOLFSSL_ATECC508A */ 580 653 … … 755 828 #endif 756 829 830 #ifdef WC_ECC_NONBLOCK 831 WOLFSSL_API int wc_ecc_set_nonblock(ecc_key *key, ecc_nb_ctx_t* ctx); 832 #endif 833 757 834 #ifdef __cplusplus 758 835 } /* extern "C" */
Note:
See TracChangeset
for help on using the changeset viewer.