- Timestamp:
- Feb 7, 2019, 8:36:33 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_rx/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/ecc.h
r337 r372 20 20 */ 21 21 22 /*! 23 \file wolfssl/wolfcrypt/ecc.h 24 */ 25 22 26 23 27 #ifndef WOLF_CRYPT_ECC_H … … 27 31 28 32 #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 */ 29 37 30 38 #include <wolfssl/wolfcrypt/integer.h> … … 73 81 #elif defined(HAVE_ECC320) 74 82 #define MAX_ECC_BITS 320 83 #elif !defined(NO_ECC256) 84 #define MAX_ECC_BITS 256 75 85 #elif defined(HAVE_ECC239) 76 86 #define MAX_ECC_BITS 239 77 87 #elif defined(HAVE_ECC224) 78 88 #define MAX_ECC_BITS 224 79 #elif !defined(NO_ECC256)80 #define MAX_ECC_BITS 25681 89 #elif defined(HAVE_ECC192) 82 90 #define MAX_ECC_BITS 192 … … 110 118 ECC_MAX_PAD_SZ = 4, /* ECC maximum padding size */ 111 119 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 113 141 }; 114 142 … … 176 204 177 205 /* ECC set type defined a GF(p) curve */ 206 #ifndef USE_WINDOWS_API 178 207 typedef struct ecc_set_type { 179 208 int size; /* The size of the curve in octets */ … … 191 220 int cofactor; 192 221 } 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 231 typedef 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 193 247 194 248 … … 247 301 typedef struct alt_fp_int { 248 302 int used, sign, size; 249 fp_digit dp[FP_SIZE_ECC];303 mp_digit dp[FP_SIZE_ECC]; 250 304 } alt_fp_int; 251 305 #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 252 311 253 312 … … 265 324 alt_fp_int xyz[3]; 266 325 #endif 326 #ifdef WOLFSSL_SMALL_STACK_CACHE 327 ecc_key* key; 328 #endif 267 329 } ecc_point; 268 330 … … 285 347 const ecc_set_type* dp; /* domain parameters, either points to NIST 286 348 curves (idx >= 0) or user supplied */ 349 #ifdef WOLFSSL_CUSTOM_CURVES 350 int deallocSet; 351 #endif 287 352 void* heap; /* heap hint */ 353 ecc_point pubkey; /* public key */ 354 mp_int k; /* private key */ 288 355 #ifdef WOLFSSL_ATECC508A 289 356 int slot; /* Key Slot Number (-1 unknown) */ 290 byte pubkey [PUB_KEY_SIZE];291 #e lse292 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; 294 361 #endif 295 362 #ifdef WOLFSSL_ASYNC_CRYPT … … 297 364 mp_int* s; 298 365 WC_ASYNC_DEV asyncDev; 366 #ifdef HAVE_CAVIUM_V 367 mp_int* e; /* Sign, Verify and Shared Secret */ 368 mp_int* signK; 369 #endif 299 370 #ifdef WOLFSSL_CERT_GEN 300 371 CertSignCtx certSignCtx; /* context info for cert sign (MakeSignature) */ 301 372 #endif 302 373 #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 }; 309 388 310 389 … … 322 401 #define ECC_API WOLFSSL_LOCAL 323 402 #endif 403 404 ECC_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); 324 407 325 408 ECC_API int ecc_map(ecc_point*, mp_int*, mp_digit); … … 378 461 WOLFSSL_API 379 462 int 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 464 WOLFSSL_API 465 int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap, 466 int devId); 467 #endif 468 #ifdef WOLFSSL_CUSTOM_CURVES 469 WOLFSSL_LOCAL 470 void wc_ecc_free_curve(const ecc_set_type* curve, void* heap); 471 #endif 472 WOLFSSL_API 473 int wc_ecc_free(ecc_key* key); 382 474 WOLFSSL_API 383 475 int wc_ecc_set_flags(ecc_key* key, word32 flags); … … 410 502 const byte* Gx, word32 GxSz, const byte* Gy, word32 GySz, int cofactor); 411 503 504 WOLFSSL_API 505 int wc_ecc_get_curve_id_from_oid(const byte* oid, word32 len); 506 507 WOLFSSL_API 508 ecc_point* wc_ecc_new_point(void); 509 WOLFSSL_API 510 ecc_point* wc_ecc_new_point_h(void* h); 511 WOLFSSL_API 512 void wc_ecc_del_point(ecc_point* p); 513 WOLFSSL_API 514 void wc_ecc_del_point_h(ecc_point* p, void* h); 515 WOLFSSL_API 516 int wc_ecc_copy_point(ecc_point* p, ecc_point *r); 517 WOLFSSL_API 518 int wc_ecc_cmp_point(ecc_point* a, ecc_point *b); 519 WOLFSSL_API 520 int wc_ecc_point_is_at_infinity(ecc_point *p); 521 412 522 #ifndef WOLFSSL_ATECC508A 413 414 WOLFSSL_API415 ecc_point* wc_ecc_new_point(void);416 WOLFSSL_API417 ecc_point* wc_ecc_new_point_h(void* h);418 WOLFSSL_API419 void wc_ecc_del_point(ecc_point* p);420 WOLFSSL_API421 void wc_ecc_del_point_h(ecc_point* p, void* h);422 WOLFSSL_API423 int wc_ecc_copy_point(ecc_point* p, ecc_point *r);424 WOLFSSL_API425 int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);426 WOLFSSL_API427 int wc_ecc_point_is_at_infinity(ecc_point *p);428 523 WOLFSSL_API 429 524 int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, … … 459 554 int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen); 460 555 WOLFSSL_API 556 int wc_ecc_rs_raw_to_sig(const byte* r, word32 rSz, const byte* s, word32 sSz, 557 byte* out, word32* outlen); 558 WOLFSSL_API 461 559 int wc_ecc_sig_to_rs(const byte* sig, word32 sigLen, byte* r, word32* rLen, 462 560 byte* s, word32* sLen); … … 467 565 int wc_ecc_import_raw_ex(ecc_key* key, const char* qx, const char* qy, 468 566 const char* d, int curve_id); 567 WOLFSSL_API 568 int wc_ecc_import_unsigned(ecc_key* key, byte* qx, byte* qy, 569 byte* d, int curve_id); 469 570 #endif /* HAVE_ECC_KEY_IMPORT */ 470 571 471 572 #ifdef HAVE_ECC_KEY_EXPORT 573 WOLFSSL_API 574 int wc_ecc_export_ex(ecc_key* key, byte* qx, word32* qxLen, 575 byte* qy, word32* qyLen, byte* d, word32* dLen, 576 int encType); 472 577 WOLFSSL_API 473 578 int wc_ecc_export_private_only(ecc_key* key, byte* out, word32* outLen); … … 497 602 WOLFSSL_API 498 603 int wc_ecc_size(ecc_key* key); 604 WOLFSSL_API 605 int wc_ecc_sig_size_calc(int sz); 499 606 WOLFSSL_API 500 607 int wc_ecc_sig_size(ecc_key* key);
Note:
See TracChangeset
for help on using the changeset viewer.