Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of wolfSSL by
ecc.h
00001 /* ecc.h 00002 * 00003 * Copyright (C) 2006-2016 wolfSSL Inc. 00004 * 00005 * This file is part of wolfSSL. 00006 * 00007 * wolfSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * wolfSSL is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 00020 */ 00021 00022 00023 #ifndef WOLF_CRYPT_ECC_H 00024 #define WOLF_CRYPT_ECC_H 00025 00026 #include <wolfssl/wolfcrypt/types.h> 00027 00028 #ifdef HAVE_ECC 00029 00030 #include <wolfssl/wolfcrypt/integer.h> 00031 #include <wolfssl/wolfcrypt/random.h> 00032 00033 #ifdef HAVE_X963_KDF 00034 #include <wolfssl/wolfcrypt/hash.h> 00035 #endif 00036 00037 #ifdef WOLFSSL_ASYNC_CRYPT 00038 #include <wolfssl/wolfcrypt/async.h> 00039 #ifdef WOLFSSL_CERT_GEN 00040 #include <wolfssl/wolfcrypt/asn.h> 00041 #endif 00042 #endif 00043 00044 #ifdef WOLFSSL_ATECC508A 00045 #include <wolfssl/wolfcrypt/port/atmel/atmel.h> 00046 #endif /* WOLFSSL_ATECC508A */ 00047 00048 00049 #ifdef __cplusplus 00050 extern "C" { 00051 #endif 00052 00053 00054 /* Enable curve B parameter if needed */ 00055 #if defined(HAVE_COMP_KEY) || defined(ECC_CACHE_CURVE) 00056 #ifndef USE_ECC_B_PARAM /* Allow someone to force enable */ 00057 #define USE_ECC_B_PARAM 00058 #endif 00059 #endif 00060 00061 00062 /* Use this as the key->idx if a custom ecc_set is used for key->dp */ 00063 #define ECC_CUSTOM_IDX (-1) 00064 00065 00066 /* Determine max ECC bits based on enabled curves */ 00067 #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES) 00068 #define MAX_ECC_BITS 521 00069 #elif defined(HAVE_ECC512) 00070 #define MAX_ECC_BITS 512 00071 #elif defined(HAVE_ECC384) 00072 #define MAX_ECC_BITS 384 00073 #elif defined(HAVE_ECC320) 00074 #define MAX_ECC_BITS 320 00075 #elif defined(HAVE_ECC239) 00076 #define MAX_ECC_BITS 239 00077 #elif defined(HAVE_ECC224) 00078 #define MAX_ECC_BITS 224 00079 #elif !defined(NO_ECC256) 00080 #define MAX_ECC_BITS 256 00081 #elif defined(HAVE_ECC192) 00082 #define MAX_ECC_BITS 192 00083 #elif defined(HAVE_ECC160) 00084 #define MAX_ECC_BITS 160 00085 #elif defined(HAVE_ECC128) 00086 #define MAX_ECC_BITS 128 00087 #elif defined(HAVE_ECC112) 00088 #define MAX_ECC_BITS 112 00089 #endif 00090 00091 /* calculate max ECC bytes */ 00092 #if ((MAX_ECC_BITS * 2) % 8) == 0 00093 #define MAX_ECC_BYTES (MAX_ECC_BITS / 8) 00094 #else 00095 /* add byte if not aligned */ 00096 #define MAX_ECC_BYTES ((MAX_ECC_BITS / 8) + 1) 00097 #endif 00098 00099 00100 enum { 00101 ECC_PUBLICKEY = 1, 00102 ECC_PRIVATEKEY = 2, 00103 ECC_MAXNAME = 16, /* MAX CURVE NAME LENGTH */ 00104 SIG_HEADER_SZ = 6, /* ECC signature header size */ 00105 ECC_BUFSIZE = 256, /* for exported keys temp buffer */ 00106 ECC_MINSIZE = 20, /* MIN Private Key size */ 00107 ECC_MAXSIZE = 66, /* MAX Private Key size */ 00108 ECC_MAXSIZE_GEN = 74, /* MAX Buffer size required when generating ECC keys*/ 00109 ECC_MAX_PAD_SZ = 4, /* ECC maximum padding size */ 00110 ECC_MAX_OID_LEN = 16, 00111 ECC_MAX_SIG_SIZE= ((MAX_ECC_BYTES * 2) + ECC_MAX_PAD_SZ + SIG_HEADER_SZ) 00112 }; 00113 00114 /* Curve Types */ 00115 typedef enum ecc_curve_id { 00116 ECC_CURVE_INVALID = -1, 00117 ECC_CURVE_DEF = 0, /* NIST or SECP */ 00118 00119 /* NIST Prime Curves */ 00120 ECC_SECP192R1, 00121 ECC_PRIME192V2, 00122 ECC_PRIME192V3, 00123 ECC_PRIME239V1, 00124 ECC_PRIME239V2, 00125 ECC_PRIME239V3, 00126 ECC_SECP256R1, 00127 00128 /* SECP Curves */ 00129 ECC_SECP112R1, 00130 ECC_SECP112R2, 00131 ECC_SECP128R1, 00132 ECC_SECP128R2, 00133 ECC_SECP160R1, 00134 ECC_SECP160R2, 00135 ECC_SECP224R1, 00136 ECC_SECP384R1, 00137 ECC_SECP521R1, 00138 00139 /* Koblitz */ 00140 ECC_SECP160K1, 00141 ECC_SECP192K1, 00142 ECC_SECP224K1, 00143 ECC_SECP256K1, 00144 00145 /* Brainpool Curves */ 00146 ECC_BRAINPOOLP160R1, 00147 ECC_BRAINPOOLP192R1, 00148 ECC_BRAINPOOLP224R1, 00149 ECC_BRAINPOOLP256R1, 00150 ECC_BRAINPOOLP320R1, 00151 ECC_BRAINPOOLP384R1, 00152 ECC_BRAINPOOLP512R1, 00153 00154 /* Twisted Edwards Curves */ 00155 #ifdef HAVE_CURVE25519 00156 ECC_X25519, 00157 #endif 00158 #ifdef HAVE_X448 00159 ECC_X448, 00160 #endif 00161 } ecc_curve_id; 00162 00163 #ifdef HAVE_OID_ENCODING 00164 typedef word16 ecc_oid_t; 00165 #else 00166 typedef byte ecc_oid_t; 00167 /* OID encoded with ASN scheme: 00168 first element = (oid[0] * 40) + oid[1] 00169 if any element > 127 then MSB 0x80 indicates additional byte */ 00170 #endif 00171 00172 /* ECC set type defined a GF(p) curve */ 00173 typedef struct ecc_set_type { 00174 int size; /* The size of the curve in octets */ 00175 int id; /* id of this curve */ 00176 const char* name; /* name of this curve */ 00177 const char* prime; /* prime that defines the field, curve is in (hex) */ 00178 const char* Af; /* fields A param (hex) */ 00179 const char* Bf; /* fields B param (hex) */ 00180 const char* order; /* order of the curve (hex) */ 00181 const char* Gx; /* x coordinate of the base point on curve (hex) */ 00182 const char* Gy; /* y coordinate of the base point on curve (hex) */ 00183 const ecc_oid_t* oid; 00184 word32 oidSz; 00185 word32 oidSum; /* sum of encoded OID bytes */ 00186 int cofactor; 00187 } ecc_set_type; 00188 00189 00190 #ifdef ALT_ECC_SIZE 00191 00192 /* Note on ALT_ECC_SIZE: 00193 * The fast math code uses an array of a fixed size to store the big integers. 00194 * By default, the array is big enough for RSA keys. There is a size, 00195 * FP_MAX_BITS which can be used to make the array smaller when one wants ECC 00196 * but not RSA. Some people want fast math sized for both RSA and ECC, where 00197 * ECC won't use as much as RSA. The flag ALT_ECC_SIZE switches in an alternate 00198 * ecc_point structure that uses an alternate fp_int that has a shorter array 00199 * of fp_digits. 00200 * 00201 * Now, without ALT_ECC_SIZE, the ecc_point has three single item arrays of 00202 * mp_ints for the components of the point. With ALT_ECC_SIZE, the components 00203 * of the point are pointers that are set to each of a three item array of 00204 * alt_fp_ints. While an mp_int will have 4096 bits of digit inside the 00205 * structure, the alt_fp_int will only have 528 bits. A size value was added 00206 * in the ALT case, as well, and is set by mp_init() and alt_fp_init(). The 00207 * functions fp_zero() and fp_copy() use the size parameter. An int needs to 00208 * be initialized before using it instead of just fp_zeroing it, the init will 00209 * call zero. FP_MAX_BITS_ECC defaults to 528, but can be set to change the 00210 * number of bits used in the alternate FP_INT. 00211 * 00212 * Do not enable ALT_ECC_SIZE and disable fast math in the configuration. 00213 */ 00214 00215 #ifndef USE_FAST_MATH 00216 #error USE_FAST_MATH must be defined to use ALT_ECC_SIZE 00217 #endif 00218 00219 /* determine max bits required for ECC math */ 00220 #ifndef FP_MAX_BITS_ECC 00221 /* check alignment */ 00222 #if ((MAX_ECC_BITS * 2) % DIGIT_BIT) == 0 00223 /* max bits is double */ 00224 #define FP_MAX_BITS_ECC (MAX_ECC_BITS * 2) 00225 #else 00226 /* max bits is doubled, plus one digit of fudge */ 00227 #define FP_MAX_BITS_ECC ((MAX_ECC_BITS * 2) + DIGIT_BIT) 00228 #endif 00229 #else 00230 /* verify alignment */ 00231 #if FP_MAX_BITS_ECC % CHAR_BIT 00232 #error FP_MAX_BITS_ECC must be a multiple of CHAR_BIT 00233 #endif 00234 #endif 00235 00236 /* determine buffer size */ 00237 #define FP_SIZE_ECC (FP_MAX_BITS_ECC/DIGIT_BIT) 00238 00239 00240 /* This needs to match the size of the fp_int struct, except the 00241 * fp_digit array will be shorter. */ 00242 typedef struct alt_fp_int { 00243 int used, sign, size; 00244 fp_digit dp[FP_SIZE_ECC]; 00245 } alt_fp_int; 00246 #endif /* ALT_ECC_SIZE */ 00247 00248 00249 /* A point on an ECC curve, stored in Jacbobian format such that (x,y,z) => 00250 (x/z^2, y/z^3, 1) when interpreted as affine */ 00251 typedef struct { 00252 #ifndef ALT_ECC_SIZE 00253 mp_int x[1]; /* The x coordinate */ 00254 mp_int y[1]; /* The y coordinate */ 00255 mp_int z[1]; /* The z coordinate */ 00256 #else 00257 mp_int* x; /* The x coordinate */ 00258 mp_int* y; /* The y coordinate */ 00259 mp_int* z; /* The z coordinate */ 00260 alt_fp_int xyz[3]; 00261 #endif 00262 } ecc_point; 00263 00264 /* ECC Flags */ 00265 enum { 00266 WC_ECC_FLAG_NONE = 0x00, 00267 #ifdef HAVE_ECC_CDH 00268 WC_ECC_FLAG_COFACTOR = 0x01, 00269 #endif 00270 }; 00271 00272 /* An ECC Key */ 00273 struct ecc_key { 00274 int type; /* Public or Private */ 00275 int idx; /* Index into the ecc_sets[] for the parameters of 00276 this curve if -1, this key is using user supplied 00277 curve in dp */ 00278 int state; 00279 word32 flags; 00280 const ecc_set_type* dp; /* domain parameters, either points to NIST 00281 curves (idx >= 0) or user supplied */ 00282 void* heap; /* heap hint */ 00283 #ifdef WOLFSSL_ATECC508A 00284 int slot; /* Key Slot Number (-1 unknown) */ 00285 byte pubkey[PUB_KEY_SIZE]; 00286 #else 00287 ecc_point pubkey; /* public key */ 00288 mp_int k; /* private key */ 00289 #endif 00290 #ifdef WOLFSSL_ASYNC_CRYPT 00291 mp_int* r; /* sign/verify temps */ 00292 mp_int* s; 00293 WC_ASYNC_DEV asyncDev; 00294 #ifdef WOLFSSL_CERT_GEN 00295 CertSignCtx certSignCtx; /* context info for cert sign (MakeSignature) */ 00296 #endif 00297 #endif /* WOLFSSL_ASYNC_CRYPT */ 00298 }; 00299 00300 #ifndef WC_ECCKEY_TYPE_DEFINED 00301 typedef struct ecc_key ecc_key; 00302 #define WC_ECCKEY_TYPE_DEFINED 00303 #endif 00304 00305 00306 /* ECC predefined curve sets */ 00307 extern const ecc_set_type ecc_sets[]; 00308 00309 WOLFSSL_API 00310 const char* wc_ecc_get_name(int curve_id); 00311 00312 #ifndef WOLFSSL_ATECC508A 00313 00314 #ifdef WOLFSSL_PUBLIC_ECC_ADD_DBL 00315 #define ECC_API WOLFSSL_API 00316 #else 00317 #define ECC_API WOLFSSL_LOCAL 00318 #endif 00319 00320 ECC_API int ecc_map(ecc_point*, mp_int*, mp_digit); 00321 ECC_API int ecc_projective_add_point(ecc_point* P, ecc_point* Q, ecc_point* R, 00322 mp_int* a, mp_int* modulus, mp_digit mp); 00323 ECC_API int ecc_projective_dbl_point(ecc_point* P, ecc_point* R, mp_int* a, 00324 mp_int* modulus, mp_digit mp); 00325 00326 #endif 00327 00328 WOLFSSL_API 00329 int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key); 00330 WOLFSSL_API 00331 int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, 00332 int curve_id); 00333 WOLFSSL_API 00334 int wc_ecc_check_key(ecc_key* key); 00335 WOLFSSL_API 00336 int wc_ecc_is_point(ecc_point* ecp, mp_int* a, mp_int* b, mp_int* prime); 00337 00338 #ifdef HAVE_ECC_DHE 00339 WOLFSSL_API 00340 int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out, 00341 word32* outlen); 00342 WOLFSSL_LOCAL 00343 int wc_ecc_shared_secret_gen(ecc_key* private_key, ecc_point* point, 00344 byte* out, word32 *outlen); 00345 WOLFSSL_API 00346 int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point, 00347 byte* out, word32 *outlen); 00348 #define wc_ecc_shared_secret_ssh wc_ecc_shared_secret_ex /* For backwards compat */ 00349 #endif /* HAVE_ECC_DHE */ 00350 00351 #ifdef HAVE_ECC_SIGN 00352 WOLFSSL_API 00353 int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, 00354 WC_RNG* rng, ecc_key* key); 00355 WOLFSSL_API 00356 int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng, 00357 ecc_key* key, mp_int *r, mp_int *s); 00358 #endif /* HAVE_ECC_SIGN */ 00359 00360 #ifdef HAVE_ECC_VERIFY 00361 WOLFSSL_API 00362 int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, 00363 word32 hashlen, int* stat, ecc_key* key); 00364 WOLFSSL_API 00365 int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash, 00366 word32 hashlen, int* stat, ecc_key* key); 00367 #endif /* HAVE_ECC_VERIFY */ 00368 00369 WOLFSSL_API 00370 int wc_ecc_init(ecc_key* key); 00371 WOLFSSL_API 00372 int wc_ecc_init_ex(ecc_key* key, void* heap, int devId); 00373 WOLFSSL_API 00374 void wc_ecc_free(ecc_key* key); 00375 WOLFSSL_API 00376 int wc_ecc_set_flags(ecc_key* key, word32 flags); 00377 WOLFSSL_API 00378 void wc_ecc_fp_free(void); 00379 00380 WOLFSSL_API 00381 int wc_ecc_set_curve(ecc_key* key, int keysize, int curve_id); 00382 00383 WOLFSSL_API 00384 int wc_ecc_is_valid_idx(int n); 00385 WOLFSSL_API 00386 int wc_ecc_get_curve_idx(int curve_id); 00387 WOLFSSL_API 00388 int wc_ecc_get_curve_id(int curve_idx); 00389 #define wc_ecc_get_curve_name_from_id wc_ecc_get_name 00390 WOLFSSL_API 00391 int wc_ecc_get_curve_size_from_id(int curve_id); 00392 00393 WOLFSSL_API 00394 int wc_ecc_get_curve_idx_from_name(const char* curveName); 00395 WOLFSSL_API 00396 int wc_ecc_get_curve_size_from_name(const char* curveName); 00397 WOLFSSL_API 00398 int wc_ecc_get_curve_id_from_name(const char* curveName); 00399 WOLFSSL_API 00400 int wc_ecc_get_curve_id_from_params(int fieldSize, 00401 const byte* prime, word32 primeSz, const byte* Af, word32 AfSz, 00402 const byte* Bf, word32 BfSz, const byte* order, word32 orderSz, 00403 const byte* Gx, word32 GxSz, const byte* Gy, word32 GySz, int cofactor); 00404 00405 #ifndef WOLFSSL_ATECC508A 00406 00407 WOLFSSL_API 00408 ecc_point* wc_ecc_new_point(void); 00409 WOLFSSL_API 00410 ecc_point* wc_ecc_new_point_h(void* h); 00411 WOLFSSL_API 00412 void wc_ecc_del_point(ecc_point* p); 00413 WOLFSSL_API 00414 void wc_ecc_del_point_h(ecc_point* p, void* h); 00415 WOLFSSL_API 00416 int wc_ecc_copy_point(ecc_point* p, ecc_point *r); 00417 WOLFSSL_API 00418 int wc_ecc_cmp_point(ecc_point* a, ecc_point *b); 00419 WOLFSSL_API 00420 int wc_ecc_point_is_at_infinity(ecc_point *p); 00421 WOLFSSL_API 00422 int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, 00423 mp_int* a, mp_int* modulus, int map); 00424 WOLFSSL_LOCAL 00425 int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, 00426 mp_int* a, mp_int* modulus, int map, void* heap); 00427 #endif /* !WOLFSSL_ATECC508A */ 00428 00429 00430 #ifdef HAVE_ECC_KEY_EXPORT 00431 /* ASN key helpers */ 00432 WOLFSSL_API 00433 int wc_ecc_export_x963(ecc_key*, byte* out, word32* outLen); 00434 WOLFSSL_API 00435 int wc_ecc_export_x963_ex(ecc_key*, byte* out, word32* outLen, int compressed); 00436 /* extended functionality with compressed option */ 00437 #endif /* HAVE_ECC_KEY_EXPORT */ 00438 00439 #ifdef HAVE_ECC_KEY_IMPORT 00440 WOLFSSL_API 00441 int wc_ecc_import_x963(const byte* in, word32 inLen, ecc_key* key); 00442 WOLFSSL_API 00443 int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key, 00444 int curve_id); 00445 WOLFSSL_API 00446 int wc_ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub, 00447 word32 pubSz, ecc_key* key); 00448 WOLFSSL_API 00449 int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz, 00450 const byte* pub, word32 pubSz, ecc_key* key, int curve_id); 00451 WOLFSSL_API 00452 int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen); 00453 WOLFSSL_API 00454 int wc_ecc_sig_to_rs(const byte* sig, word32 sigLen, byte* r, word32* rLen, 00455 byte* s, word32* sLen); 00456 WOLFSSL_API 00457 int wc_ecc_import_raw(ecc_key* key, const char* qx, const char* qy, 00458 const char* d, const char* curveName); 00459 WOLFSSL_API 00460 int wc_ecc_import_raw_ex(ecc_key* key, const char* qx, const char* qy, 00461 const char* d, int curve_id); 00462 #endif /* HAVE_ECC_KEY_IMPORT */ 00463 00464 #ifdef HAVE_ECC_KEY_EXPORT 00465 WOLFSSL_API 00466 int wc_ecc_export_private_only(ecc_key* key, byte* out, word32* outLen); 00467 WOLFSSL_API 00468 int wc_ecc_export_public_raw(ecc_key* key, byte* qx, word32* qxLen, 00469 byte* qy, word32* qyLen); 00470 WOLFSSL_API 00471 int wc_ecc_export_private_raw(ecc_key* key, byte* qx, word32* qxLen, 00472 byte* qy, word32* qyLen, byte* d, word32* dLen); 00473 #endif /* HAVE_ECC_KEY_EXPORT */ 00474 00475 #ifdef HAVE_ECC_KEY_EXPORT 00476 00477 WOLFSSL_API 00478 int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, 00479 byte* out, word32* outLen); 00480 #endif /* HAVE_ECC_KEY_EXPORT */ 00481 00482 00483 #ifdef HAVE_ECC_KEY_IMPORT 00484 WOLFSSL_API 00485 int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx, 00486 ecc_point* point); 00487 #endif /* HAVE_ECC_KEY_IMPORT */ 00488 00489 /* size helper */ 00490 WOLFSSL_API 00491 int wc_ecc_size(ecc_key* key); 00492 WOLFSSL_API 00493 int wc_ecc_sig_size(ecc_key* key); 00494 00495 WOLFSSL_API 00496 int wc_ecc_get_oid(word32 oidSum, const byte** oid, word32* oidSz); 00497 00498 #ifdef WOLFSSL_CUSTOM_CURVES 00499 WOLFSSL_API 00500 int wc_ecc_set_custom_curve(ecc_key* key, const ecc_set_type* dp); 00501 #endif 00502 00503 #ifdef HAVE_ECC_ENCRYPT 00504 /* ecc encrypt */ 00505 00506 enum ecEncAlgo { 00507 ecAES_128_CBC = 1, /* default */ 00508 ecAES_256_CBC = 2 00509 }; 00510 00511 enum ecKdfAlgo { 00512 ecHKDF_SHA256 = 1, /* default */ 00513 ecHKDF_SHA1 = 2 00514 }; 00515 00516 enum ecMacAlgo { 00517 ecHMAC_SHA256 = 1, /* default */ 00518 ecHMAC_SHA1 = 2 00519 }; 00520 00521 enum { 00522 KEY_SIZE_128 = 16, 00523 KEY_SIZE_256 = 32, 00524 IV_SIZE_64 = 8, 00525 IV_SIZE_128 = 16, 00526 EXCHANGE_SALT_SZ = 16, 00527 EXCHANGE_INFO_SZ = 23 00528 }; 00529 00530 enum ecFlags { 00531 REQ_RESP_CLIENT = 1, 00532 REQ_RESP_SERVER = 2 00533 }; 00534 00535 00536 typedef struct ecEncCtx ecEncCtx; 00537 00538 WOLFSSL_API 00539 ecEncCtx* wc_ecc_ctx_new(int flags, WC_RNG* rng); 00540 WOLFSSL_API 00541 ecEncCtx* wc_ecc_ctx_new_ex(int flags, WC_RNG* rng, void* heap); 00542 WOLFSSL_API 00543 void wc_ecc_ctx_free(ecEncCtx*); 00544 WOLFSSL_API 00545 int wc_ecc_ctx_reset(ecEncCtx*, WC_RNG*); /* reset for use again w/o alloc/free */ 00546 00547 WOLFSSL_API 00548 const byte* wc_ecc_ctx_get_own_salt(ecEncCtx*); 00549 WOLFSSL_API 00550 int wc_ecc_ctx_set_peer_salt(ecEncCtx*, const byte* salt); 00551 WOLFSSL_API 00552 int wc_ecc_ctx_set_info(ecEncCtx*, const byte* info, int sz); 00553 00554 WOLFSSL_API 00555 int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, 00556 word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx); 00557 WOLFSSL_API 00558 int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, 00559 word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx); 00560 00561 #endif /* HAVE_ECC_ENCRYPT */ 00562 00563 #ifdef HAVE_X963_KDF 00564 WOLFSSL_API int wc_X963_KDF(enum wc_HashType type, const byte* secret, 00565 word32 secretSz, const byte* sinfo, word32 sinfoSz, 00566 byte* out, word32 outSz); 00567 #endif 00568 00569 #ifdef ECC_CACHE_CURVE 00570 WOLFSSL_API int wc_ecc_curve_cache_init(void); 00571 WOLFSSL_API void wc_ecc_curve_cache_free(void); 00572 #endif 00573 00574 00575 #ifdef __cplusplus 00576 } /* extern "C" */ 00577 #endif 00578 00579 #endif /* HAVE_ECC */ 00580 #endif /* WOLF_CRYPT_ECC_H */ 00581
Generated on Tue Jul 12 2022 23:30:55 by
1.7.2
