ecc.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. /* ecc.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*!
  22. \file wolfssl/wolfcrypt/ecc.h
  23. */
  24. #ifndef WOLF_CRYPT_ECC_H
  25. #define WOLF_CRYPT_ECC_H
  26. #include <wolfssl/wolfcrypt/types.h>
  27. #ifdef HAVE_ECC
  28. #if defined(HAVE_FIPS) && \
  29. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
  30. #include <wolfssl/wolfcrypt/fips.h>
  31. #endif /* HAVE_FIPS_VERSION >= 2 */
  32. #include <wolfssl/wolfcrypt/wolfmath.h>
  33. #include <wolfssl/wolfcrypt/random.h>
  34. #ifdef HAVE_X963_KDF
  35. #include <wolfssl/wolfcrypt/hash.h>
  36. #endif
  37. #ifdef WOLFSSL_ASYNC_CRYPT
  38. #include <wolfssl/wolfcrypt/async.h>
  39. #ifdef WOLFSSL_CERT_GEN
  40. #include <wolfssl/wolfcrypt/asn.h>
  41. #endif
  42. #endif
  43. #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A)
  44. #include <wolfssl/wolfcrypt/port/atmel/atmel.h>
  45. #endif /* WOLFSSL_ATECC508A */
  46. #if defined(WOLFSSL_CRYPTOCELL)
  47. #include <wolfssl/wolfcrypt/port/arm/cryptoCell.h>
  48. #endif
  49. #ifdef WOLFSSL_SILABS_SE_ACCEL
  50. #include <wolfssl/wolfcrypt/port/silabs/silabs_ecc.h>
  51. #endif
  52. #if defined(WOLFSSL_KCAPI_ECC)
  53. #include <wolfssl/wolfcrypt/port/kcapi/kcapi_ecc.h>
  54. #endif
  55. #ifdef WOLFSSL_SE050
  56. #include <wolfssl/wolfcrypt/port/nxp/se050_port.h>
  57. #endif
  58. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  59. #include <wolfssl/wolfcrypt/port/xilinx/xil-versal-glue.h>
  60. #endif
  61. #ifdef WOLFSSL_HAVE_SP_ECC
  62. #include <wolfssl/wolfcrypt/sp_int.h>
  63. #endif
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif
  67. /* Enable curve B parameter if needed */
  68. #if defined(HAVE_COMP_KEY) || defined(ECC_CACHE_CURVE)
  69. #ifndef USE_ECC_B_PARAM /* Allow someone to force enable */
  70. #define USE_ECC_B_PARAM
  71. #endif
  72. #endif
  73. /* Use this as the key->idx if a custom ecc_set is used for key->dp */
  74. #define ECC_CUSTOM_IDX (-1)
  75. /* Determine max ECC bits based on enabled curves */
  76. #if defined(WOLFCRYPT_HAVE_SAKKE)
  77. #define MAX_ECC_BITS_NEEDED 1024
  78. #elif defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
  79. #define MAX_ECC_BITS_NEEDED 521
  80. #elif defined(HAVE_ECC512)
  81. #define MAX_ECC_BITS_NEEDED 512
  82. #elif defined(HAVE_ECC384)
  83. #define MAX_ECC_BITS_NEEDED 384
  84. #elif defined(HAVE_ECC320)
  85. #define MAX_ECC_BITS_NEEDED 320
  86. #elif !defined(NO_ECC256) || defined(WOLFSSL_SM2)
  87. #define MAX_ECC_BITS_NEEDED 256
  88. #elif defined(HAVE_ECC239)
  89. #define MAX_ECC_BITS_NEEDED 239
  90. #elif defined(HAVE_ECC224)
  91. #define MAX_ECC_BITS_NEEDED 224
  92. #elif defined(HAVE_ECC192)
  93. #define MAX_ECC_BITS_NEEDED 192
  94. #elif defined(HAVE_ECC160)
  95. #define MAX_ECC_BITS_NEEDED 160
  96. #elif defined(HAVE_ECC128)
  97. #define MAX_ECC_BITS_NEEDED 128
  98. #elif defined(HAVE_ECC112)
  99. #define MAX_ECC_BITS_NEEDED 112
  100. #endif
  101. #ifndef MAX_ECC_BITS
  102. #define MAX_ECC_BITS MAX_ECC_BITS_NEEDED
  103. #else
  104. #if MAX_ECC_BITS_NEEDED > MAX_ECC_BITS
  105. #error configured MAX_ECC_BITS is less than required by enabled curves.
  106. #endif
  107. #endif
  108. /* calculate max ECC bytes */
  109. #if ((MAX_ECC_BITS * 2) % 8) == 0
  110. #define MAX_ECC_BYTES (MAX_ECC_BITS / 8)
  111. #else
  112. /* add byte if not aligned */
  113. #define MAX_ECC_BYTES ((MAX_ECC_BITS / 8) + 1)
  114. #endif
  115. #ifndef ECC_MAX_PAD_SZ
  116. /* ECC maximum padding size (when MSB is set extra byte required for R and S) */
  117. #define ECC_MAX_PAD_SZ 2
  118. #endif
  119. enum {
  120. ECC_PUBLICKEY = 1,
  121. ECC_PRIVATEKEY = 2,
  122. ECC_PRIVATEKEY_ONLY = 3,
  123. ECC_MAXNAME = 16, /* MAX CURVE NAME LENGTH */
  124. SIG_HEADER_SZ = 7, /* ECC signature header size (30 81 87 02 42 [R] 02 42 [S]) */
  125. ECC_BUFSIZE = 257, /* for exported keys temp buffer */
  126. ECC_MINSIZE = ECC_MIN_KEY_SZ/8, /* MIN Private Key size */
  127. #ifdef WOLFCRYPT_HAVE_SAKKE
  128. ECC_MAXSIZE = 128, /* MAX Private Key size */
  129. ECC_MAXSIZE_GEN = 128, /* MAX Buffer size required when generating ECC keys*/
  130. #else
  131. ECC_MAXSIZE = 66, /* MAX Private Key size */
  132. ECC_MAXSIZE_GEN = 74, /* MAX Buffer size required when generating ECC keys*/
  133. #endif
  134. ECC_MAX_OID_LEN = 16,
  135. ECC_MAX_SIG_SIZE= ((MAX_ECC_BYTES * 2) + ECC_MAX_PAD_SZ + SIG_HEADER_SZ),
  136. /* max crypto hardware size */
  137. #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A)
  138. ECC_MAX_CRYPTO_HW_SIZE = ATECC_KEY_SIZE, /* from port/atmel/atmel.h */
  139. ECC_MAX_CRYPTO_HW_PUBKEY_SIZE = (ATECC_KEY_SIZE*2),
  140. #elif defined(PLUTON_CRYPTO_ECC)
  141. ECC_MAX_CRYPTO_HW_SIZE = 32,
  142. #elif defined(WOLFSSL_SILABS_SE_ACCEL)
  143. ECC_MAX_CRYPTO_HW_SIZE = 32,
  144. #elif defined(WOLFSSL_CRYPTOCELL)
  145. #ifndef CRYPTOCELL_KEY_SIZE
  146. CRYPTOCELL_KEY_SIZE = ECC_MAXSIZE,
  147. #endif
  148. ECC_MAX_CRYPTO_HW_SIZE = CRYPTOCELL_KEY_SIZE,
  149. #elif defined(WOLFSSL_SE050)
  150. ECC_MAX_CRYPTO_HW_SIZE = 66,
  151. #elif defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  152. ECC_MAX_CRYPTO_HW_SIZE = MAX_ECC_BYTES,
  153. #endif
  154. /* point compression type */
  155. ECC_POINT_COMP_EVEN = 0x02,
  156. ECC_POINT_COMP_ODD = 0x03,
  157. ECC_POINT_UNCOMP = 0x04,
  158. /* Shamir's dual add constants */
  159. SHAMIR_PRECOMP_SZ = 16,
  160. #ifdef WOLF_PRIVATE_KEY_ID
  161. ECC_MAX_ID_LEN = 32,
  162. ECC_MAX_LABEL_LEN = 32,
  163. #endif
  164. WOLF_ENUM_DUMMY_LAST_ELEMENT(ECC)
  165. };
  166. #endif /* HAVE_ECC */
  167. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || \
  168. defined(HAVE_CURVE448) || defined(WOLFCRYPT_HAVE_SAKKE)
  169. /* Curve Types */
  170. typedef enum ecc_curve_id {
  171. ECC_CURVE_INVALID = -1,
  172. ECC_CURVE_DEF = 0, /* NIST or SECP */
  173. /* NIST Prime Curves */
  174. ECC_SECP192R1,
  175. ECC_PRIME192V2,
  176. ECC_PRIME192V3,
  177. ECC_PRIME239V1,
  178. ECC_PRIME239V2,
  179. ECC_PRIME239V3,
  180. ECC_SECP256R1,
  181. /* SECP Curves */
  182. ECC_SECP112R1,
  183. ECC_SECP112R2,
  184. ECC_SECP128R1,
  185. ECC_SECP128R2,
  186. ECC_SECP160R1,
  187. ECC_SECP160R2,
  188. ECC_SECP224R1,
  189. ECC_SECP384R1,
  190. ECC_SECP521R1,
  191. /* Koblitz */
  192. ECC_SECP160K1,
  193. ECC_SECP192K1,
  194. ECC_SECP224K1,
  195. ECC_SECP256K1,
  196. /* Brainpool Curves */
  197. ECC_BRAINPOOLP160R1,
  198. ECC_BRAINPOOLP192R1,
  199. ECC_BRAINPOOLP224R1,
  200. ECC_BRAINPOOLP256R1,
  201. ECC_BRAINPOOLP320R1,
  202. ECC_BRAINPOOLP384R1,
  203. ECC_BRAINPOOLP512R1,
  204. /* SM2 */
  205. ECC_SM2P256V1,
  206. /* Twisted Edwards Curves */
  207. #ifdef HAVE_CURVE25519
  208. ECC_X25519,
  209. #endif
  210. #ifdef HAVE_CURVE448
  211. ECC_X448,
  212. #endif
  213. #ifdef WOLFCRYPT_HAVE_SAKKE
  214. ECC_SAKKE_1,
  215. #endif
  216. #ifdef WOLFSSL_CUSTOM_CURVES
  217. ECC_CURVE_CUSTOM,
  218. #endif
  219. ECC_CURVE_MAX
  220. } ecc_curve_id;
  221. #endif
  222. #ifdef HAVE_ECC
  223. #ifdef HAVE_OID_ENCODING
  224. typedef word16 ecc_oid_t;
  225. #else
  226. typedef byte ecc_oid_t;
  227. /* OID encoded with ASN scheme:
  228. first element = (oid[0] * 40) + oid[1]
  229. if any element > 127 then MSB 0x80 indicates additional byte */
  230. #endif
  231. #if !defined(WOLFSSL_ECC_CURVE_STATIC) && defined(USE_WINDOWS_API)
  232. /* MSC does something different with the pointers to the arrays than GCC,
  233. * and it causes the FIPS checksum to fail. In the case of windows builds,
  234. * store everything as arrays instead of pointers to strings. */
  235. #define WOLFSSL_ECC_CURVE_STATIC
  236. #endif
  237. /* ECC set type defined a GF(p) curve */
  238. #ifndef WOLFSSL_ECC_CURVE_STATIC
  239. typedef struct ecc_set_type {
  240. int size; /* The size of the curve in octets */
  241. int id; /* id of this curve */
  242. const char* name; /* name of this curve */
  243. const char* prime; /* prime that defines the field, curve is in (hex) */
  244. const char* Af; /* fields A param (hex) */
  245. const char* Bf; /* fields B param (hex) */
  246. const char* order; /* order of the curve (hex) */
  247. const char* Gx; /* x coordinate of the base point on curve (hex) */
  248. const char* Gy; /* y coordinate of the base point on curve (hex) */
  249. const ecc_oid_t* oid;
  250. word32 oidSz;
  251. word32 oidSum; /* sum of encoded OID bytes */
  252. int cofactor;
  253. } ecc_set_type;
  254. #else
  255. #define MAX_ECC_NAME 16
  256. #define MAX_ECC_STRING ((MAX_ECC_BYTES * 2) + 2)
  257. /* The values are stored as text strings. */
  258. typedef struct ecc_set_type {
  259. int size; /* The size of the curve in octets */
  260. int id; /* id of this curve */
  261. char name[MAX_ECC_NAME]; /* name of this curve */
  262. char prime[MAX_ECC_STRING]; /* prime that defines the field, curve is in (hex) */
  263. char Af[MAX_ECC_STRING]; /* fields A param (hex) */
  264. char Bf[MAX_ECC_STRING]; /* fields B param (hex) */
  265. char order[MAX_ECC_STRING]; /* order of the curve (hex) */
  266. char Gx[MAX_ECC_STRING]; /* x coordinate of the base point on curve (hex) */
  267. char Gy[MAX_ECC_STRING]; /* y coordinate of the base point on curve (hex) */
  268. ecc_oid_t oid[10];
  269. word32 oidSz;
  270. word32 oidSum; /* sum of encoded OID bytes */
  271. int cofactor;
  272. } ecc_set_type;
  273. #endif
  274. #ifdef ALT_ECC_SIZE
  275. /* Note on ALT_ECC_SIZE:
  276. * The fast math code uses an array of a fixed size to store the big integers.
  277. * By default, the array is big enough for RSA keys. There is a size,
  278. * FP_MAX_BITS which can be used to make the array smaller when one wants ECC
  279. * but not RSA. Some people want fast math sized for both RSA and ECC, where
  280. * ECC won't use as much as RSA. The flag ALT_ECC_SIZE switches in an alternate
  281. * ecc_point structure that uses an alternate fp_int that has a shorter array
  282. * of fp_digits.
  283. *
  284. * Now, without ALT_ECC_SIZE, the ecc_point has three single item arrays of
  285. * mp_ints for the components of the point. With ALT_ECC_SIZE, the components
  286. * of the point are pointers that are set to each of a three item array of
  287. * alt_fp_ints. While an mp_int will have 4096 bits of digit inside the
  288. * structure, the alt_fp_int will only have 512 bits for ECC 256-bit and
  289. * 1056-bits for ECC 521-bit. A size value was added in the ALT case, as well,
  290. * and is set by mp_init() and alt_fp_init(). The functions fp_zero() and
  291. * fp_copy() use the size parameter. An int needs to be initialized before
  292. * using it instead of just fp_zeroing it, the init will call zero. The
  293. * FP_MAX_BITS_ECC defaults to calculating based on MAX_ECC_BITS, but
  294. * can be set to change the number of bits used in the alternate FP_INT.
  295. *
  296. * The ALT_ECC_SIZE option only applies to stack based fast math USE_FAST_MATH.
  297. */
  298. #if defined(USE_INTEGER_HEAP_MATH)
  299. #error Cannot use integer math with ALT_ECC_SIZE
  300. #endif
  301. #ifdef WOLFSSL_NO_MALLOC
  302. #error ALT_ECC_SIZE cannot be used with no malloc (WOLFSSL_NO_MALLOC)
  303. #endif
  304. #ifdef USE_FAST_MATH
  305. /* determine max bits required for ECC math */
  306. #ifndef FP_MAX_BITS_ECC
  307. /* max bits rounded up by 8 then doubled */
  308. /* (ROUND8(MAX_ECC_BITS) * 2) */
  309. #define FP_MAX_BITS_ECC (2 * \
  310. ((MAX_ECC_BITS + DIGIT_BIT - 1) / DIGIT_BIT) * DIGIT_BIT)
  311. /* Note: For ECC verify only FP_MAX_BITS_ECC can be reduced to:
  312. ROUND8(MAX_ECC_BITS) + ROUND8(DIGIT_BIT) */
  313. #endif
  314. /* verify alignment */
  315. #if CHAR_BIT == 0
  316. #error CHAR_BIT must be nonzero
  317. #endif
  318. #if FP_MAX_BITS_ECC % CHAR_BIT
  319. #error FP_MAX_BITS_ECC must be a multiple of CHAR_BIT
  320. #endif
  321. /* determine buffer size */
  322. /* Add one to accommodate extra digit used by sp_mul(), sp_mulmod(), sp_sqr(), and sp_sqrmod(). */
  323. #define FP_SIZE_ECC ((FP_MAX_BITS_ECC/DIGIT_BIT) + 1)
  324. /* This needs to match the size of the fp_int struct, except the
  325. * fp_digit array will be shorter. */
  326. typedef struct alt_fp_int {
  327. int used, sign, size;
  328. mp_digit dp[FP_SIZE_ECC];
  329. } alt_fp_int;
  330. #else
  331. #ifdef FP_MAX_BITS_ECC
  332. #define SP_INT_BITS_ECC (FP_MAX_BITS_ECC / 2)
  333. #elif SP_INT_BITS < MAX_ECC_BITS
  334. #define SP_INT_BITS_ECC SP_INT_BITS
  335. #else
  336. #define SP_INT_BITS_ECC MAX_ECC_BITS
  337. #endif
  338. #define SP_INT_DIGITS_ECC \
  339. (((SP_INT_BITS_ECC + SP_WORD_SIZE - 1) / SP_WORD_SIZE) * 2 + 1)
  340. #define FP_SIZE_ECC SP_INT_DIGITS_ECC
  341. typedef struct alt_fp_int {
  342. /** Number of words that contain data. */
  343. unsigned int used;
  344. /** Maximum number of words in data. */
  345. unsigned int size;
  346. #ifdef WOLFSSL_SP_INT_NEGATIVE
  347. /** Indicates whether number is 0/positive or negative. */
  348. unsigned int sign;
  349. #endif
  350. #ifdef HAVE_WOLF_BIGINT
  351. /** Unsigned binary (big endian) representation of number. */
  352. struct WC_BIGINT raw;
  353. #endif
  354. /** Data of number. */
  355. sp_int_digit dp[SP_INT_DIGITS_ECC];
  356. } alt_fp_int;
  357. #endif
  358. #endif /* ALT_ECC_SIZE */
  359. #ifndef WC_ECCKEY_TYPE_DEFINED
  360. typedef struct ecc_key ecc_key;
  361. #define WC_ECCKEY_TYPE_DEFINED
  362. #endif
  363. /* A point on an ECC curve, stored in Jacobian format such that (x,y,z) =>
  364. (x/z^2, y/z^3, 1) when interpreted as affine */
  365. typedef struct {
  366. #ifndef ALT_ECC_SIZE
  367. mp_int x[1]; /* The x coordinate */
  368. mp_int y[1]; /* The y coordinate */
  369. mp_int z[1]; /* The z coordinate */
  370. #else
  371. mp_int* x; /* The x coordinate */
  372. mp_int* y; /* The y coordinate */
  373. mp_int* z; /* The z coordinate */
  374. alt_fp_int xyz[3];
  375. #endif
  376. #if defined(WOLFSSL_SMALL_STACK_CACHE) && !defined(WOLFSSL_ECC_NO_SMALL_STACK)
  377. ecc_key* key;
  378. #endif
  379. } ecc_point;
  380. /* ECC Flags */
  381. enum {
  382. WC_ECC_FLAG_NONE = 0x00,
  383. WC_ECC_FLAG_COFACTOR = 0x01,
  384. WC_ECC_FLAG_DEC_SIGN = 0x02
  385. };
  386. /* ECC non-blocking */
  387. #ifdef WC_ECC_NONBLOCK
  388. typedef struct ecc_nb_ctx {
  389. #if defined(WOLFSSL_HAVE_SP_ECC) && defined(WOLFSSL_SP_NONBLOCK)
  390. sp_ecc_ctx_t sp_ctx;
  391. #else
  392. /* build configuration not supported */
  393. #error ECC non-blocking only supports SP (--enable-sp=nonblock)
  394. #endif
  395. } ecc_nb_ctx_t;
  396. #endif /* WC_ECC_NONBLOCK */
  397. /* An ECC Key */
  398. struct ecc_key {
  399. int type; /* Public or Private */
  400. int idx; /* Index into the ecc_sets[] for the parameters of
  401. this curve if -1, this key is using user supplied
  402. curve in dp */
  403. int state;
  404. word32 flags;
  405. const ecc_set_type* dp; /* domain parameters, either points to NIST
  406. curves (idx >= 0) or user supplied */
  407. #ifdef WOLFSSL_CUSTOM_CURVES
  408. int deallocSet;
  409. #endif
  410. void* heap; /* heap hint */
  411. ecc_point pubkey; /* public key */
  412. #ifndef ALT_ECC_SIZE
  413. mp_int k[1]; /* private key */
  414. #else
  415. mp_int* k;
  416. alt_fp_int ka[1];
  417. #endif
  418. #ifdef WOLFSSL_CAAM
  419. word32 blackKey; /* address of key encrypted and in secure memory */
  420. word32 securePubKey; /* address of public key in secure memory */
  421. int partNum; /* partition number*/
  422. #endif
  423. #ifdef WOLFSSL_SE050
  424. word32 keyId;
  425. byte keyIdSet;
  426. #endif
  427. #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A)
  428. int slot; /* Key Slot Number (-1 unknown) */
  429. byte pubkey_raw[ECC_MAX_CRYPTO_HW_PUBKEY_SIZE];
  430. #endif
  431. #if defined(PLUTON_CRYPTO_ECC) || defined(WOLF_CRYPTO_CB)
  432. void* devCtx;
  433. int devId;
  434. #endif
  435. #if defined(HAVE_PKCS11)
  436. byte isPkcs11 : 1; /* indicate if PKCS11 is preferred */
  437. #endif
  438. #ifdef WOLFSSL_SILABS_SE_ACCEL
  439. sl_se_command_context_t cmd_ctx;
  440. sl_se_key_descriptor_t key;
  441. /* Used for SiLabs "plaintext" with public X, public Y, and
  442. * private D concatenated. These are respectively at offset `0`,
  443. * offset `keysize`, and offset `2 * keysize`.
  444. */
  445. byte key_raw[3 * ECC_MAX_CRYPTO_HW_SIZE];
  446. #endif
  447. #ifdef WOLFSSL_MAXQ10XX_CRYPTO
  448. maxq_ecc_t maxq_ctx;
  449. #endif
  450. #ifdef WOLFSSL_KCAPI_ECC
  451. struct kcapi_handle* handle;
  452. byte pubkey_raw[MAX_ECC_BYTES * 2];
  453. #endif
  454. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  455. wc_Xsecure xSec;
  456. byte keyRaw[3 * ECC_MAX_CRYPTO_HW_SIZE] ALIGN32;
  457. byte* privKey;
  458. #endif
  459. #ifdef WOLFSSL_ASYNC_CRYPT
  460. mp_int* r; /* sign/verify temps */
  461. mp_int* s;
  462. WC_ASYNC_DEV asyncDev;
  463. #ifdef HAVE_CAVIUM_V
  464. mp_int* e; /* Sign, Verify and Shared Secret */
  465. mp_int* signK;
  466. #endif
  467. #ifdef WOLFSSL_CERT_GEN
  468. CertSignCtx certSignCtx; /* context info for cert sign (MakeSignature) */
  469. #endif
  470. #endif /* WOLFSSL_ASYNC_CRYPT */
  471. #ifdef WOLF_PRIVATE_KEY_ID
  472. byte id[ECC_MAX_ID_LEN];
  473. int idLen;
  474. char label[ECC_MAX_LABEL_LEN];
  475. int labelLen;
  476. #endif
  477. #if defined(WOLFSSL_CRYPTOCELL)
  478. ecc_context_t ctx;
  479. #endif
  480. #if defined(WOLFSSL_ECDSA_SET_K) || defined(WOLFSSL_ECDSA_SET_K_ONE_LOOP) || \
  481. defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  482. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  483. #ifndef WOLFSSL_NO_MALLOC
  484. mp_int* sign_k;
  485. #else
  486. mp_int sign_k[1];
  487. byte sign_k_set:1;
  488. #endif
  489. #endif
  490. #if defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  491. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  492. byte deterministic:1;
  493. #endif
  494. #if defined(WOLFSSL_SMALL_STACK_CACHE) && !defined(WOLFSSL_ECC_NO_SMALL_STACK)
  495. mp_int* t1;
  496. mp_int* t2;
  497. #ifdef ALT_ECC_SIZE
  498. mp_int* x;
  499. mp_int* y;
  500. mp_int* z;
  501. #endif
  502. #endif
  503. #ifdef WOLFSSL_DSP
  504. remote_handle64 handle;
  505. #endif
  506. #ifdef ECC_TIMING_RESISTANT
  507. WC_RNG* rng;
  508. #endif
  509. #ifdef WC_ECC_NONBLOCK
  510. ecc_nb_ctx_t* nb_ctx;
  511. #endif
  512. };
  513. #define wc_ecc_key_get_priv(key) ((key)->k)
  514. #define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  515. WOLFSSL_ABI WOLFSSL_API ecc_key* wc_ecc_key_new(void* heap);
  516. WOLFSSL_ABI WOLFSSL_API void wc_ecc_key_free(ecc_key* key);
  517. /* ECC predefined curve sets */
  518. extern const ecc_set_type ecc_sets[];
  519. extern const size_t ecc_sets_count;
  520. WOLFSSL_API
  521. const char* wc_ecc_get_name(int curve_id);
  522. #ifdef WOLFSSL_PUBLIC_ECC_ADD_DBL
  523. #define ECC_API WOLFSSL_API
  524. #else
  525. #define ECC_API WOLFSSL_LOCAL
  526. #endif
  527. ECC_API int ecc_mul2add(ecc_point* A, mp_int* kA,
  528. ecc_point* B, mp_int* kB,
  529. ecc_point* C, mp_int* a, mp_int* modulus, void* heap);
  530. ECC_API int ecc_map(ecc_point* P, mp_int* modulus, mp_digit mp);
  531. ECC_API int ecc_map_ex(ecc_point* P, mp_int* modulus, mp_digit mp, int ct);
  532. ECC_API int ecc_projective_add_point(ecc_point* P, ecc_point* Q, ecc_point* R,
  533. mp_int* a, mp_int* modulus, mp_digit mp);
  534. ECC_API int ecc_projective_dbl_point(ecc_point* P, ecc_point* R, mp_int* a,
  535. mp_int* modulus, mp_digit mp);
  536. ECC_API int ecc_projective_add_point_safe(ecc_point* A, ecc_point* B,
  537. ecc_point* R, mp_int* a, mp_int* modulus, mp_digit mp, int* infinity);
  538. ECC_API int ecc_projective_dbl_point_safe(ecc_point* P, ecc_point* R, mp_int* a,
  539. mp_int* modulus, mp_digit mp);
  540. WOLFSSL_ABI WOLFSSL_API
  541. int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key);
  542. WOLFSSL_ABI WOLFSSL_API
  543. int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id);
  544. WOLFSSL_API
  545. int wc_ecc_make_key_ex2(WC_RNG* rng, int keysize, ecc_key* key, int curve_id,
  546. int flags);
  547. WOLFSSL_API
  548. int wc_ecc_make_pub(ecc_key* key, ecc_point* pubOut);
  549. WOLFSSL_API
  550. int wc_ecc_make_pub_ex(ecc_key* key, ecc_point* pubOut, WC_RNG* rng);
  551. WOLFSSL_ABI WOLFSSL_API
  552. int wc_ecc_check_key(ecc_key* key);
  553. WOLFSSL_API
  554. int wc_ecc_is_point(ecc_point* ecp, mp_int* a, mp_int* b, mp_int* prime);
  555. WOLFSSL_API
  556. int wc_ecc_get_generator(ecc_point* ecp, int curve_idx);
  557. #ifdef HAVE_ECC_DHE
  558. WOLFSSL_ABI WOLFSSL_API
  559. int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
  560. word32* outlen);
  561. WOLFSSL_API
  562. int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
  563. byte* out, word32 *outlen);
  564. /* Internal API for blocking ECDHE call */
  565. WOLFSSL_LOCAL
  566. int wc_ecc_shared_secret_gen_sync(ecc_key* private_key,
  567. ecc_point* point, byte* out, word32* outlen);
  568. #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
  569. defined(PLUTON_CRYPTO_ECC) || defined(WOLFSSL_CRYPTOCELL)
  570. #define wc_ecc_shared_secret_ssh wc_ecc_shared_secret
  571. #else
  572. #define wc_ecc_shared_secret_ssh wc_ecc_shared_secret_ex /* For backwards compat */
  573. #endif
  574. #endif /* HAVE_ECC_DHE */
  575. #ifdef HAVE_ECC_SIGN
  576. WOLFSSL_ABI WOLFSSL_API
  577. int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen,
  578. WC_RNG* rng, ecc_key* key);
  579. WOLFSSL_API
  580. int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
  581. ecc_key* key, mp_int *r, mp_int *s);
  582. #if defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  583. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  584. WOLFSSL_API
  585. int wc_ecc_set_deterministic(ecc_key* key, byte flag);
  586. WOLFSSL_API
  587. int wc_ecc_gen_deterministic_k(const byte* hash, word32 hashSz,
  588. enum wc_HashType hashType, mp_int* priv, mp_int* k, mp_int* order,
  589. void* heap);
  590. #endif
  591. #if defined(WOLFSSL_ECDSA_SET_K) || defined(WOLFSSL_ECDSA_SET_K_ONE_LOOP)
  592. WOLFSSL_API
  593. int wc_ecc_sign_set_k(const byte* k, word32 klen, ecc_key* key);
  594. #endif
  595. #endif /* HAVE_ECC_SIGN */
  596. #ifdef HAVE_ECC_VERIFY
  597. WOLFSSL_ABI WOLFSSL_API
  598. int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash,
  599. word32 hashlen, int* res, ecc_key* key);
  600. WOLFSSL_API
  601. int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
  602. word32 hashlen, int* res, ecc_key* key);
  603. #endif /* HAVE_ECC_VERIFY */
  604. WOLFSSL_ABI WOLFSSL_API
  605. int wc_ecc_init(ecc_key* key);
  606. WOLFSSL_ABI WOLFSSL_API
  607. int wc_ecc_init_ex(ecc_key* key, void* heap, int devId);
  608. #ifdef WOLF_PRIVATE_KEY_ID
  609. WOLFSSL_API
  610. int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap,
  611. int devId);
  612. WOLFSSL_API
  613. int wc_ecc_init_label(ecc_key* key, const char* label, void* heap, int devId);
  614. #endif
  615. #ifdef WOLFSSL_CUSTOM_CURVES
  616. WOLFSSL_LOCAL
  617. void wc_ecc_free_curve(const ecc_set_type* curve, void* heap);
  618. #endif
  619. WOLFSSL_ABI WOLFSSL_API
  620. int wc_ecc_free(ecc_key* key);
  621. WOLFSSL_API
  622. int wc_ecc_set_flags(ecc_key* key, word32 flags);
  623. WOLFSSL_ABI WOLFSSL_API
  624. void wc_ecc_fp_free(void);
  625. WOLFSSL_LOCAL
  626. void wc_ecc_fp_init(void);
  627. WOLFSSL_API
  628. int wc_ecc_set_rng(ecc_key* key, WC_RNG* rng);
  629. WOLFSSL_API
  630. int wc_ecc_set_curve(ecc_key* key, int keysize, int curve_id);
  631. WOLFSSL_API
  632. int wc_ecc_is_valid_idx(int n);
  633. WOLFSSL_API
  634. int wc_ecc_get_curve_idx(int curve_id);
  635. WOLFSSL_API
  636. int wc_ecc_get_curve_id(int curve_idx);
  637. #define wc_ecc_get_curve_name_from_id wc_ecc_get_name
  638. WOLFSSL_API
  639. int wc_ecc_get_curve_size_from_id(int curve_id);
  640. WOLFSSL_API
  641. int wc_ecc_get_curve_idx_from_name(const char* curveName);
  642. WOLFSSL_API
  643. int wc_ecc_get_curve_size_from_name(const char* curveName);
  644. WOLFSSL_API
  645. int wc_ecc_get_curve_id_from_name(const char* curveName);
  646. WOLFSSL_API
  647. int wc_ecc_get_curve_id_from_params(int fieldSize,
  648. const byte* prime, word32 primeSz, const byte* Af, word32 AfSz,
  649. const byte* Bf, word32 BfSz, const byte* order, word32 orderSz,
  650. const byte* Gx, word32 GxSz, const byte* Gy, word32 GySz, int cofactor);
  651. WOLFSSL_API
  652. int wc_ecc_get_curve_id_from_dp_params(const ecc_set_type* dp);
  653. WOLFSSL_API
  654. int wc_ecc_get_curve_id_from_oid(const byte* oid, word32 len);
  655. WOLFSSL_API const ecc_set_type* wc_ecc_get_curve_params(int curve_idx);
  656. WOLFSSL_API
  657. ecc_point* wc_ecc_new_point(void);
  658. WOLFSSL_API
  659. ecc_point* wc_ecc_new_point_h(void* h);
  660. WOLFSSL_API
  661. void wc_ecc_del_point(ecc_point* p);
  662. WOLFSSL_API
  663. void wc_ecc_del_point_h(ecc_point* p, void* h);
  664. WOLFSSL_API
  665. void wc_ecc_forcezero_point(ecc_point* p);
  666. WOLFSSL_API
  667. int wc_ecc_copy_point(const ecc_point* p, ecc_point *r);
  668. WOLFSSL_API
  669. int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);
  670. WOLFSSL_API
  671. int wc_ecc_point_is_at_infinity(ecc_point *p);
  672. WOLFSSL_API
  673. int wc_ecc_point_is_on_curve(ecc_point *p, int curve_idx);
  674. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  675. WOLFSSL_API
  676. int wc_ecc_mulmod(const mp_int* k, ecc_point *G, ecc_point *R,
  677. mp_int* a, mp_int* modulus, int map);
  678. ECC_API
  679. int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R,
  680. mp_int* a, mp_int* modulus, int map, void* heap);
  681. ECC_API
  682. int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
  683. mp_int* modulus, mp_int* order, WC_RNG* rng, int map,
  684. void* heap);
  685. #endif /* !WOLFSSL_ATECC508A */
  686. #ifdef HAVE_ECC_KEY_EXPORT
  687. /* ASN key helpers */
  688. WOLFSSL_ABI WOLFSSL_API
  689. int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen);
  690. WOLFSSL_ABI WOLFSSL_API
  691. int wc_ecc_export_x963_ex(ecc_key* key, byte* out, word32* outLen,
  692. int compressed);
  693. /* extended functionality with compressed option */
  694. #endif /* HAVE_ECC_KEY_EXPORT */
  695. #ifdef HAVE_ECC_KEY_IMPORT
  696. WOLFSSL_ABI WOLFSSL_API
  697. int wc_ecc_import_x963(const byte* in, word32 inLen, ecc_key* key);
  698. WOLFSSL_API
  699. int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
  700. int curve_id);
  701. WOLFSSL_ABI WOLFSSL_API
  702. int wc_ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub,
  703. word32 pubSz, ecc_key* key);
  704. WOLFSSL_API
  705. int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
  706. const byte* pub, word32 pubSz, ecc_key* key, int curve_id);
  707. WOLFSSL_ABI WOLFSSL_API
  708. int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen);
  709. WOLFSSL_API
  710. int wc_ecc_rs_raw_to_sig(const byte* r, word32 rSz, const byte* s, word32 sSz,
  711. byte* out, word32* outlen);
  712. WOLFSSL_API
  713. int wc_ecc_sig_to_rs(const byte* sig, word32 sigLen, byte* r, word32* rLen,
  714. byte* s, word32* sLen);
  715. WOLFSSL_ABI WOLFSSL_API
  716. int wc_ecc_import_raw(ecc_key* key, const char* qx, const char* qy,
  717. const char* d, const char* curveName);
  718. WOLFSSL_API
  719. int wc_ecc_import_raw_ex(ecc_key* key, const char* qx, const char* qy,
  720. const char* d, int curve_id);
  721. WOLFSSL_API
  722. int wc_ecc_import_unsigned(ecc_key* key, const byte* qx, const byte* qy,
  723. const byte* d, int curve_id);
  724. #endif /* HAVE_ECC_KEY_IMPORT */
  725. #ifdef HAVE_ECC_KEY_EXPORT
  726. WOLFSSL_API
  727. int wc_ecc_export_ex(ecc_key* key, byte* qx, word32* qxLen,
  728. byte* qy, word32* qyLen, byte* d, word32* dLen,
  729. int encType);
  730. WOLFSSL_ABI WOLFSSL_API
  731. int wc_ecc_export_private_only(ecc_key* key, byte* out, word32* outLen);
  732. WOLFSSL_API
  733. int wc_ecc_export_public_raw(ecc_key* key, byte* qx, word32* qxLen,
  734. byte* qy, word32* qyLen);
  735. WOLFSSL_API
  736. int wc_ecc_export_private_raw(ecc_key* key, byte* qx, word32* qxLen,
  737. byte* qy, word32* qyLen, byte* d, word32* dLen);
  738. #endif /* HAVE_ECC_KEY_EXPORT */
  739. #ifdef HAVE_ECC_KEY_EXPORT
  740. WOLFSSL_API
  741. int wc_ecc_export_point_der_ex(const int curve_idx, ecc_point* point, byte* out,
  742. word32* outLen, int compressed);
  743. WOLFSSL_API
  744. int wc_ecc_export_point_der(const int curve_idx, ecc_point* point,
  745. byte* out, word32* outLen);
  746. WOLFSSL_LOCAL
  747. int wc_ecc_export_point_der_compressed(const int curve_idx, ecc_point* point,
  748. byte* out, word32* outLen);
  749. #endif /* HAVE_ECC_KEY_EXPORT */
  750. #ifdef HAVE_ECC_KEY_IMPORT
  751. WOLFSSL_API
  752. int wc_ecc_import_point_der_ex(const byte* in, word32 inLen,
  753. const int curve_idx, ecc_point* point,
  754. int shortKeySize);
  755. WOLFSSL_API
  756. int wc_ecc_import_point_der(const byte* in, word32 inLen, const int curve_idx,
  757. ecc_point* point);
  758. #endif /* HAVE_ECC_KEY_IMPORT */
  759. /* size helper */
  760. WOLFSSL_ABI WOLFSSL_API
  761. int wc_ecc_size(ecc_key* key);
  762. WOLFSSL_ABI WOLFSSL_API
  763. int wc_ecc_sig_size_calc(int sz);
  764. WOLFSSL_ABI WOLFSSL_API
  765. int wc_ecc_sig_size(const ecc_key* key);
  766. WOLFSSL_API
  767. int wc_ecc_get_oid(word32 oidSum, const byte** oid, word32* oidSz);
  768. #ifdef WOLFSSL_CUSTOM_CURVES
  769. WOLFSSL_API
  770. int wc_ecc_set_custom_curve(ecc_key* key, const ecc_set_type* dp);
  771. #endif
  772. #ifdef HAVE_ECC_ENCRYPT
  773. /* ecc encrypt */
  774. enum ecEncAlgo {
  775. ecAES_128_CBC = 1, /* default */
  776. ecAES_256_CBC = 2,
  777. ecAES_128_CTR = 3,
  778. ecAES_256_CTR = 4
  779. };
  780. enum ecKdfAlgo {
  781. ecHKDF_SHA256 = 1, /* default */
  782. ecHKDF_SHA1 = 2,
  783. ecKDF_X963_SHA1 = 3,
  784. ecKDF_X963_SHA256 = 4,
  785. ecKDF_SHA1 = 5,
  786. ecKDF_SHA256 = 6
  787. };
  788. enum ecMacAlgo {
  789. ecHMAC_SHA256 = 1, /* default */
  790. ecHMAC_SHA1 = 2
  791. };
  792. enum {
  793. KEY_SIZE_128 = 16,
  794. KEY_SIZE_256 = 32,
  795. IV_SIZE_64 = 8,
  796. IV_SIZE_128 = 16,
  797. ECC_MAX_IV_SIZE = 16,
  798. EXCHANGE_SALT_SZ = 16,
  799. EXCHANGE_INFO_SZ = 23
  800. };
  801. enum ecFlags {
  802. REQ_RESP_CLIENT = 1,
  803. REQ_RESP_SERVER = 2
  804. };
  805. #ifndef WOLFSSL_ECIES_GEN_IV_SIZE
  806. #define WOLFSSL_ECIES_GEN_IV_SIZE 12
  807. #endif
  808. typedef struct ecEncCtx ecEncCtx;
  809. WOLFSSL_ABI WOLFSSL_API
  810. ecEncCtx* wc_ecc_ctx_new(int flags, WC_RNG* rng);
  811. WOLFSSL_API
  812. ecEncCtx* wc_ecc_ctx_new_ex(int flags, WC_RNG* rng, void* heap);
  813. WOLFSSL_ABI WOLFSSL_API
  814. void wc_ecc_ctx_free(ecEncCtx* ctx);
  815. WOLFSSL_ABI WOLFSSL_API
  816. int wc_ecc_ctx_reset(ecEncCtx* ctx, WC_RNG* rng); /* reset for use again w/o alloc/free */
  817. WOLFSSL_API
  818. int wc_ecc_ctx_set_algo(ecEncCtx* ctx, byte encAlgo, byte kdfAlgo,
  819. byte macAlgo);
  820. WOLFSSL_API
  821. const byte* wc_ecc_ctx_get_own_salt(ecEncCtx* ctx);
  822. WOLFSSL_API
  823. int wc_ecc_ctx_set_peer_salt(ecEncCtx* ctx, const byte* salt);
  824. WOLFSSL_API
  825. int wc_ecc_ctx_set_kdf_salt(ecEncCtx* ctx, const byte* salt, word32 sz);
  826. WOLFSSL_API
  827. int wc_ecc_ctx_set_info(ecEncCtx* ctx, const byte* info, int sz);
  828. WOLFSSL_ABI WOLFSSL_API
  829. int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
  830. word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx);
  831. WOLFSSL_API
  832. int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
  833. word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx, int compressed);
  834. WOLFSSL_ABI WOLFSSL_API
  835. int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
  836. word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx);
  837. #endif /* HAVE_ECC_ENCRYPT */
  838. #ifdef HAVE_X963_KDF
  839. WOLFSSL_API int wc_X963_KDF(enum wc_HashType type, const byte* secret,
  840. word32 secretSz, const byte* sinfo, word32 sinfoSz,
  841. byte* out, word32 outSz);
  842. #endif
  843. #ifdef ECC_CACHE_CURVE
  844. WOLFSSL_API int wc_ecc_curve_cache_init(void);
  845. WOLFSSL_API void wc_ecc_curve_cache_free(void);
  846. #endif
  847. WOLFSSL_API
  848. int wc_ecc_gen_k(WC_RNG* rng, int size, mp_int* k, mp_int* order);
  849. #ifdef WOLFSSL_DSP
  850. WOLFSSL_API
  851. int wc_ecc_set_handle(ecc_key* key, remote_handle64 handle);
  852. WOLFSSL_LOCAL
  853. int sp_dsp_ecc_verify_256(remote_handle64 handle, const byte* hash, word32 hashLen, mp_int* pX,
  854. mp_int* pY, mp_int* pZ, mp_int* r, mp_int* sm, int* res, void* heap);
  855. #endif
  856. #ifdef WOLFSSL_SE050
  857. WOLFSSL_API
  858. int wc_ecc_use_key_id(ecc_key* key, word32 keyId, word32 flags);
  859. WOLFSSL_API
  860. int wc_ecc_get_key_id(ecc_key* key, word32* keyId);
  861. #endif
  862. #ifdef WC_ECC_NONBLOCK
  863. WOLFSSL_API int wc_ecc_set_nonblock(ecc_key *key, ecc_nb_ctx_t* ctx);
  864. #endif
  865. #ifdef __cplusplus
  866. } /* extern "C" */
  867. #endif
  868. #endif /* HAVE_ECC */
  869. #endif /* WOLF_CRYPT_ECC_H */