curve25519.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /*!
  2. \ingroup Curve25519
  3. \brief This function generates a Curve25519 key using the given random
  4. number generator, rng, of the size given (keysize), and stores it in
  5. the given curve25519_key structure. It should be called after the key
  6. structure has been initialized through wc_curve25519_init().
  7. \return 0 Returned on successfully generating the key and and storing
  8. it in the given curve25519_key structure.
  9. \return ECC_BAD_ARG_E Returned if the input keysize does not correspond to
  10. the keysize for a curve25519 key (32 bytes).
  11. \return RNG_FAILURE_E Returned if the rng internal status is not
  12. DRBG_OK or if there is in generating the next random block with rng.
  13. \return BAD_FUNC_ARG Returned if any of the input parameters passed in
  14. are NULL.
  15. \param [in] rng Pointer to the RNG object used to generate the ecc key.
  16. \param [in] keysize Size of the key to generate. Must be 32 bytes for
  17. curve25519.
  18. \param [in,out] key Pointer to the curve25519_key structure in which to
  19. store the generated key.
  20. _Example_
  21. \code
  22. int ret;
  23. curve25519_key key;
  24. wc_curve25519_init(&key); // initialize key
  25. WC_RNG rng;
  26. wc_InitRng(&rng); // initialize random number generator
  27. ret = wc_curve25519_make_key(&rng, 32, &key);
  28. if (ret != 0) {
  29. // error making Curve25519 key
  30. }
  31. \endcode
  32. \sa wc_curve25519_init
  33. */
  34. int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key);
  35. /*!
  36. \ingroup Curve25519
  37. \brief This function computes a shared secret key given a secret private
  38. key and a received public key. It stores the generated secret key in the
  39. buffer out and assigns the variable of the secret key to outlen. Only
  40. supports big endian.
  41. \return 0 Returned on successfully computing a shared secret key.
  42. \return BAD_FUNC_ARG Returned if any of the input parameters passed in
  43. are NULL.
  44. \return ECC_BAD_ARG_E Returned if the first bit of the public key is
  45. set, to avoid implementation fingerprinting.
  46. \param [in] private_key Pointer to the curve25519_key structure initialized
  47. with the user’s private key.
  48. \param [in] public_key Pointer to the curve25519_key structure containing
  49. the received public key.
  50. \param [out] out Pointer to a buffer in which to store the 32 byte computed
  51. secret key.
  52. \param [in,out] outlen Pointer in which to store the length written to the
  53. output buffer.
  54. _Example_
  55. \code
  56. int ret;
  57. byte sharedKey[32];
  58. word32 keySz;
  59. curve25519_key privKey, pubKey;
  60. // initialize both keys
  61. ret = wc_curve25519_shared_secret(&privKey, &pubKey, sharedKey, &keySz);
  62. if (ret != 0) {
  63. // error generating shared key
  64. }
  65. \endcode
  66. \sa wc_curve25519_init
  67. \sa wc_curve25519_make_key
  68. \sa wc_curve25519_shared_secret_ex
  69. */
  70. int wc_curve25519_shared_secret(curve25519_key* private_key,
  71. curve25519_key* public_key,
  72. byte* out, word32* outlen);
  73. /*!
  74. \ingroup Curve25519
  75. \brief This function computes a shared secret key given a secret private
  76. key and a received public key. It stores the generated secret key in the
  77. buffer out and assigns the variable of the secret key to outlen. Supports
  78. both big and little endian.
  79. \return 0 Returned on successfully computing a shared secret key.
  80. \return BAD_FUNC_ARG Returned if any of the input parameters passed in
  81. are NULL.
  82. \return ECC_BAD_ARG_E Returned if the first bit of the public key is set,
  83. to avoid implementation fingerprinting.
  84. \param [in] private_key Pointer to the curve25519_key structure initialized
  85. with the user’s private key.
  86. \param [in] public_key Pointer to the curve25519_key structure containing
  87. the received public key.
  88. \param [out] out Pointer to a buffer in which to store the 32 byte computed
  89. secret key.
  90. \param pin,out] outlen Pointer in which to store the length written to the
  91. output buffer.
  92. \param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
  93. form to use.
  94. _Example_
  95. \code
  96. int ret;
  97. byte sharedKey[32];
  98. word32 keySz;
  99. curve25519_key privKey, pubKey;
  100. // initialize both keys
  101. ret = wc_curve25519_shared_secret_ex(&privKey, &pubKey, sharedKey, &keySz,
  102. EC25519_BIG_ENDIAN);
  103. if (ret != 0) {
  104. // error generating shared key
  105. }
  106. \endcode
  107. \sa wc_curve25519_init
  108. \sa wc_curve25519_make_key
  109. \sa wc_curve25519_shared_secret
  110. */
  111. int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
  112. curve25519_key* public_key,
  113. byte* out, word32* outlen, int endian);
  114. /*!
  115. \ingroup Curve25519
  116. \brief This function initializes a Curve25519 key. It should be called
  117. before generating a key for the structure.
  118. \return 0 Returned on successfully initializing the curve25519_key
  119. structure.
  120. \return BAD_FUNC_ARG Returned when key is NULL.
  121. \param [in,out] key Pointer to the curve25519_key structure to initialize.
  122. _Example_
  123. \code
  124. curve25519_key key;
  125. wc_curve25519_init(&key); // initialize key
  126. // make key and proceed to encryption
  127. \endcode
  128. \sa wc_curve25519_make_key
  129. */
  130. int wc_curve25519_init(curve25519_key* key);
  131. /*!
  132. \ingroup Curve25519
  133. \brief This function frees a Curve25519 object.
  134. \param [in,out] key Pointer to the key object to free.
  135. _Example_
  136. \code
  137. curve25519_key privKey;
  138. // initialize key, use it to generate shared secret key
  139. wc_curve25519_free(&privKey);
  140. \endcode
  141. \sa wc_curve25519_init
  142. \sa wc_curve25519_make_key
  143. */
  144. void wc_curve25519_free(curve25519_key* key);
  145. /*!
  146. \ingroup Curve25519
  147. \brief This function imports a curve25519 private key only. (Big endian).
  148. \return 0 Returned on successfully importing private key.
  149. \return BAD_FUNC_ARG Returns if key or priv is null.
  150. \return ECC_BAD_ARG_E Returns if privSz is not equal to CURVE25519_KEY_SIZE.
  151. \param [in] priv Pointer to a buffer containing the private key to import.
  152. \param [in] privSz Length of the private key to import.
  153. \param [in,out] key Pointer to the structure in which to store the imported
  154. key.
  155. _Example_
  156. \code
  157. int ret;
  158. byte priv[] = { Contents of private key };
  159. curve25519_key key;
  160. wc_curve25519_init(&key);
  161. ret = wc_curve25519_import_private(priv, sizeof(priv), &key);
  162. if (ret != 0) {
  163. // error importing keys
  164. }
  165. \endcode
  166. \sa wc_curve25519_import_private_ex
  167. \sa wc_curve25519_size
  168. */
  169. int wc_curve25519_import_private(const byte* priv, word32 privSz,
  170. curve25519_key* key);
  171. /*!
  172. \ingroup Curve25519
  173. \brief curve25519 private key import only. (Big or Little endian).
  174. \return 0 Returned on successfully importing private key.
  175. \return BAD_FUNC_ARG Returns if key or priv is null.
  176. \return ECC_BAD_ARG_E Returns if privSz is not equal to CURVE25519_KEY_SIZE.
  177. \param [in] priv Pointer to a buffer containing the private key to import.
  178. \param [in] privSz Length of the private key to import.
  179. \param [in,out] key Pointer to the structure in which to store the imported
  180. key.
  181. \param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to
  182. set which form to use.
  183. _Example_
  184. \code
  185. int ret;
  186. byte priv[] = { // Contents of private key };
  187. curve25519_key key;
  188. wc_curve25519_init(&key);
  189. ret = wc_curve25519_import_private_ex(priv, sizeof(priv), &key,
  190. EC25519_BIG_ENDIAN);
  191. if (ret != 0) {
  192. // error importing keys
  193. }
  194. \endcode
  195. \sa wc_curve25519_import_private
  196. \sa wc_curve25519_size
  197. */
  198. int wc_curve25519_import_private_ex(const byte* priv, word32 privSz,
  199. curve25519_key* key, int endian);
  200. /*!
  201. \ingroup Curve25519
  202. \brief This function imports a public-private key pair into a
  203. curve25519_key structure. Big endian only.
  204. \return 0 Returned on importing into the curve25519_key structure
  205. \return BAD_FUNC_ARG Returns if any of the input parameters are null.
  206. \return ECC_BAD_ARG_E Returned if the input key’s key size does not match
  207. the public or private key sizes.
  208. \param [in] priv Pointer to a buffer containing the private key to import.
  209. \param [in] privSz Length of the private key to import.
  210. \param [in] pub Pointer to a buffer containing the public key to import.
  211. \param [in] pubSz Length of the public key to import.
  212. \param [in,out] key Pointer to the structure in which to store the imported
  213. keys.
  214. _Example_
  215. \code
  216. int ret;
  217. byte priv[32];
  218. byte pub[32];
  219. // initialize with public and private keys
  220. curve25519_key key;
  221. wc_curve25519_init(&key);
  222. // initialize key
  223. ret = wc_curve25519_import_private_raw(&priv, sizeof(priv), pub,
  224. sizeof(pub), &key);
  225. if (ret != 0) {
  226. // error importing keys
  227. }
  228. \endcode
  229. \sa wc_curve25519_init
  230. \sa wc_curve25519_make_key
  231. \sa wc_curve25519_import_public
  232. \sa wc_curve25519_export_private_raw
  233. */
  234. int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
  235. const byte* pub, word32 pubSz, curve25519_key* key);
  236. /*!
  237. \ingroup Curve25519
  238. \brief This function imports a public-private key pair into a curve25519_key structure. Supports both big and little endian.
  239. \return 0 Returned on importing into the curve25519_key structure
  240. \return BAD_FUNC_ARG Returns if any of the input parameters are null.
  241. \return ECC_BAD_ARG_E Returned if or the input key’s key size does not match
  242. the public or private key sizes
  243. \param [in] priv Pointer to a buffer containing the private key to import.
  244. \param [in] privSz Length of the private key to import.
  245. \param [in] pub Pointer to a buffer containing the public key to import.
  246. \param [in] pubSz Length of the public key to import.
  247. \param [in,out] key Pointer to the structure in which to store the imported
  248. keys.
  249. \param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set
  250. which form to use.
  251. _Example_
  252. \code
  253. int ret;
  254. byte priv[32];
  255. byte pub[32];
  256. // initialize with public and private keys
  257. curve25519_key key;
  258. wc_curve25519_init(&key);
  259. // initialize key
  260. ret = wc_curve25519_import_private_raw_ex(&priv, sizeof(priv), pub,
  261. sizeof(pub), &key, EC25519_BIG_ENDIAN);
  262. if (ret != 0) {
  263. // error importing keys
  264. }
  265. \endcode
  266. \sa wc_curve25519_init
  267. \sa wc_curve25519_make_key
  268. \sa wc_curve25519_import_public
  269. \sa wc_curve25519_export_private_raw
  270. \sa wc_curve25519_import_private_raw
  271. */
  272. int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
  273. const byte* pub, word32 pubSz,
  274. curve25519_key* key, int endian);
  275. /*!
  276. \ingroup Curve25519
  277. \brief This function exports a private key from a curve25519_key structure
  278. and stores it in the given out buffer. It also sets outLen to be the size
  279. of the exported key. Big Endian only.
  280. \return 0 Returned on successfully exporting the private key from the
  281. curve25519_key structure.
  282. \return BAD_FUNC_ARG Returned if any input parameters are NULL.
  283. \return ECC_BAD_ARG_E Returned if wc_curve25519_size() is not equal to key.
  284. \param [in] key Pointer to the structure from which to export the key.
  285. \param [out] out Pointer to the buffer in which to store the exported key.
  286. \param [in,out] outLen On in, is the size of the out in bytes.
  287. On out, will store the bytes written to the output buffer.
  288. _Example_
  289. \code
  290. int ret;
  291. byte priv[32];
  292. int privSz;
  293. curve25519_key key;
  294. // initialize and make key
  295. ret = wc_curve25519_export_private_raw(&key, priv, &privSz);
  296. if (ret != 0) {
  297. // error exporting key
  298. }
  299. \endcode
  300. \sa wc_curve25519_init
  301. \sa wc_curve25519_make_key
  302. \sa wc_curve25519_import_private_raw
  303. \sa wc_curve25519_export_private_raw_ex
  304. */
  305. int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
  306. word32* outLen);
  307. /*!
  308. \ingroup Curve25519
  309. \brief This function exports a private key from a curve25519_key structure
  310. and stores it in the given out buffer. It also sets outLen to be the size
  311. of the exported key. Can specify whether it's big or little endian.
  312. \return 0 Returned on successfully exporting the private key from the
  313. curve25519_key structure.
  314. \return BAD_FUNC_ARG Returned if any input parameters are NULL.
  315. \return ECC_BAD_ARG_E Returned if wc_curve25519_size() is not equal to key.
  316. \param [in] key Pointer to the structure from which to export the key.
  317. \param [out] out Pointer to the buffer in which to store the exported key.
  318. \param [in,out] outLen On in, is the size of the out in bytes.
  319. On out, will store the bytes written to the output buffer.
  320. \param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
  321. form to use.
  322. _Example_
  323. \code
  324. int ret;
  325. byte priv[32];
  326. int privSz;
  327. curve25519_key key;
  328. // initialize and make key
  329. ret = wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
  330. EC25519_BIG_ENDIAN);
  331. if (ret != 0) {
  332. // error exporting key
  333. }
  334. \endcode
  335. \sa wc_curve25519_init
  336. \sa wc_curve25519_make_key
  337. \sa wc_curve25519_import_private_raw
  338. \sa wc_curve25519_export_private_raw
  339. \sa wc_curve25519_size
  340. */
  341. int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out,
  342. word32* outLen, int endian);
  343. /*!
  344. \ingroup Curve25519
  345. \brief This function imports a public key from the given in buffer and
  346. stores it in the curve25519_key structure.
  347. \return 0 Returned on successfully importing the public key into the
  348. curve25519_key structure.
  349. \return ECC_BAD_ARG_E Returned if the inLen parameter does not match the key
  350. size of the key structure.
  351. \return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
  352. \param [in] in Pointer to the buffer containing the public key to import.
  353. \param [in] inLen Length of the public key to import.
  354. \param [in,out] key Pointer to the curve25519_key structure in which to
  355. store the key.
  356. _Example_
  357. \code
  358. int ret;
  359. byte pub[32];
  360. // initialize pub with public key
  361. curve25519_key key;
  362. // initialize key
  363. ret = wc_curve25519_import_public(pub,sizeof(pub), &key);
  364. if (ret != 0) {
  365. // error importing key
  366. }
  367. \endcode
  368. \sa wc_curve25519_init
  369. \sa wc_curve25519_export_public
  370. \sa wc_curve25519_import_private_raw
  371. \sa wc_curve25519_import_public_ex
  372. \sa wc_curve25519_check_public
  373. \sa wc_curve25519_size
  374. */
  375. int wc_curve25519_import_public(const byte* in, word32 inLen,
  376. curve25519_key* key);
  377. /*!
  378. \ingroup Curve25519
  379. \brief This function imports a public key from the given in buffer and
  380. stores it in the curve25519_key structure.
  381. \return 0 Returned on successfully importing the public key into the
  382. curve25519_key structure.
  383. \return ECC_BAD_ARG_E Returned if the inLen parameter does not match the
  384. key size of the key structure.
  385. \return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
  386. \param [in] in Pointer to the buffer containing the public key to import.
  387. \param [in] inLen Length of the public key to import.
  388. \param [in,out] key Pointer to the curve25519_key structure in which to
  389. store the key.
  390. \param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
  391. form to use.
  392. _Example_
  393. \code
  394. int ret;
  395. byte pub[32];
  396. // initialize pub with public key
  397. curve25519_key key;
  398. // initialize key
  399. ret = wc_curve25519_import_public_ex(pub, sizeof(pub), &key,
  400. EC25519_BIG_ENDIAN);
  401. if (ret != 0) {
  402. // error importing key
  403. }
  404. \endcode
  405. \sa wc_curve25519_init
  406. \sa wc_curve25519_export_public
  407. \sa wc_curve25519_import_private_raw
  408. \sa wc_curve25519_import_public
  409. \sa wc_curve25519_check_public
  410. \sa wc_curve25519_size
  411. */
  412. int wc_curve25519_import_public_ex(const byte* in, word32 inLen,
  413. curve25519_key* key, int endian);
  414. /*!
  415. \ingroup Curve25519
  416. \brief This function checks that a public key buffer holds a valid
  417. Curve25519 key value given the endian ordering.
  418. \return 0 Returned when the public key value is valid.
  419. \return ECC_BAD_ARG_E Returned if the public key value is not valid.
  420. \return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
  421. \param [in] pub Pointer to the buffer containing the public key to check.
  422. \param [in] pubLen Length of the public key to check.
  423. \param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
  424. form to use.
  425. _Example_
  426. \code
  427. int ret;
  428. byte pub[] = { Contents of public key };
  429. ret = wc_curve25519_check_public_ex(pub, sizeof(pub), EC25519_BIG_ENDIAN);
  430. if (ret != 0) {
  431. // error importing key
  432. }
  433. \endcode
  434. \sa wc_curve25519_init
  435. \sa wc_curve25519_import_public
  436. \sa wc_curve25519_import_public_ex
  437. \sa wc_curve25519_size
  438. */
  439. int wc_curve25519_check_public(const byte* pub, word32 pubSz, int endian);
  440. /*!
  441. \ingroup Curve25519
  442. \brief This function exports a public key from the given key structure and
  443. stores the result in the out buffer. Big endian only.
  444. \return 0 Returned on successfully exporting the public key from the
  445. curve25519_key structure.
  446. \return ECC_BAD_ARG_E Returned if outLen is less than
  447. CURVE25519_PUB_KEY_SIZE.
  448. \return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
  449. \param [in] key Pointer to the curve25519_key structure in from which to
  450. export the key.
  451. \param [out] out Pointer to the buffer in which to store the public key.
  452. \param [in,out] outLen On in, is the size of the out in bytes.
  453. On out, will store the bytes written to the output buffer.
  454. _Example_
  455. \code
  456. int ret;
  457. byte pub[32];
  458. int pubSz;
  459. curve25519_key key;
  460. // initialize and make key
  461. ret = wc_curve25519_export_public(&key, pub, &pubSz);
  462. if (ret != 0) {
  463. // error exporting key
  464. }
  465. \endcode
  466. \sa wc_curve25519_init
  467. \sa wc_curve25519_export_private_raw
  468. \sa wc_curve25519_import_public
  469. */
  470. int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
  471. /*!
  472. \ingroup Curve25519
  473. \brief This function exports a public key from the given key structure and
  474. stores the result in the out buffer. Supports both big and little endian.
  475. \return 0 Returned on successfully exporting the public key from the
  476. curve25519_key structure.
  477. \return ECC_BAD_ARG_E Returned if outLen is less than
  478. CURVE25519_PUB_KEY_SIZE.
  479. \return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
  480. \param [in] key Pointer to the curve25519_key structure in from which to
  481. export the key.
  482. \param [out] out Pointer to the buffer in which to store the public key.
  483. \param [in,out] outLen On in, is the size of the out in bytes.
  484. On out, will store the bytes written to the output buffer.
  485. \param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
  486. form to use.
  487. _Example_
  488. \code
  489. int ret;
  490. byte pub[32];
  491. int pubSz;
  492. curve25519_key key;
  493. // initialize and make key
  494. ret = wc_curve25519_export_public_ex(&key, pub, &pubSz, EC25519_BIG_ENDIAN);
  495. if (ret != 0) {
  496. // error exporting key
  497. }
  498. \endcode
  499. \sa wc_curve25519_init
  500. \sa wc_curve25519_export_private_raw
  501. \sa wc_curve25519_import_public
  502. */
  503. int wc_curve25519_export_public_ex(curve25519_key* key, byte* out,
  504. word32* outLen, int endian);
  505. /*!
  506. \ingroup Curve25519
  507. \brief Export Curve25519 key pair. Big endian only.
  508. \return 0 Returned on successfully exporting the key pair from the
  509. curve25519_key structure.
  510. \return BAD_FUNC_ARG Returned if any input parameters are NULL.
  511. \return ECC_BAD_ARG_E Returned if privSz is less than CURVE25519_KEY_SIZE or
  512. pubSz is less than CURVE25519_PUB_KEY_SIZE.
  513. \param [in] key Pointer to the curve448_key structure in from which to
  514. export the key pair.
  515. \param [out] priv Pointer to the buffer in which to store the private key.
  516. \param [in,out] privSz On in, is the size of the priv buffer in bytes.
  517. On out, will store the bytes written to the priv buffer.
  518. \param [out] pub Pointer to the buffer in which to store the public key.
  519. \param [in,out] pubSz On in, is the size of the pub buffer in bytes.
  520. On out, will store the bytes written to the pub buffer.
  521. _Example_
  522. \code
  523. int ret;
  524. byte pub[32];
  525. byte priv[32];
  526. int pubSz;
  527. int privSz;
  528. curve25519_key key;
  529. // initialize and make key
  530. ret = wc_curve25519_export_key_raw(&key, priv, &privSz, pub, &pubSz);
  531. if (ret != 0) {
  532. // error exporting key
  533. }
  534. \endcode
  535. \sa wc_curve25519_export_key_raw_ex
  536. \sa wc_curve25519_export_private_raw
  537. */
  538. int wc_curve25519_export_key_raw(curve25519_key* key,
  539. byte* priv, word32 *privSz,
  540. byte* pub, word32 *pubSz);
  541. /*!
  542. \ingroup Curve25519
  543. \brief Export curve25519 key pair. Big or little endian.
  544. \return 0 Returned on successfully exporting the key pair from the
  545. curve25519_key structure.
  546. \return BAD_FUNC_ARG Returned if any input parameters are NULL.
  547. \return ECC_BAD_ARG_E Returned if privSz is less than CURVE25519_KEY_SIZE or
  548. pubSz is less than CURVE25519_PUB_KEY_SIZE.
  549. \param [in] key Pointer to the curve448_key structure in from which to
  550. export the key pair.
  551. \param [out] priv Pointer to the buffer in which to store the private key.
  552. \param [in,out] privSz On in, is the size of the priv buffer in bytes.
  553. On out, will store the bytes written to the priv buffer.
  554. \param [out] pub Pointer to the buffer in which to store the public key.
  555. \param [in,out] pubSz On in, is the size of the pub buffer in bytes.
  556. On out, will store the bytes written to the pub buffer.
  557. \param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
  558. form to use.
  559. _Example_
  560. \code
  561. int ret;
  562. byte pub[32];
  563. byte priv[32];
  564. int pubSz;
  565. int privSz;
  566. curve25519_key key;
  567. // initialize and make key
  568. ret = wc_curve25519_export_key_raw_ex(&key,priv, &privSz, pub, &pubSz,
  569. EC25519_BIG_ENDIAN);
  570. if (ret != 0) {
  571. // error exporting key
  572. }
  573. \endcode
  574. \sa wc_curve25519_export_key_raw
  575. \sa wc_curve25519_export_private_raw_ex
  576. \sa wc_curve25519_export_public_ex
  577. */
  578. int wc_curve25519_export_key_raw_ex(curve25519_key* key,
  579. byte* priv, word32 *privSz,
  580. byte* pub, word32 *pubSz,
  581. int endian);
  582. /*!
  583. \ingroup Curve25519
  584. \brief This function returns the key size of the given key structure.
  585. \return Success Given a valid, initialized curve25519_key structure,
  586. returns the size of the key.
  587. \return 0 Returned if key is NULL
  588. \param [in] key Pointer to the curve25519_key structure in for which to
  589. determine the key size.
  590. _Example_
  591. \code
  592. int keySz;
  593. curve25519_key key;
  594. // initialize and make key
  595. keySz = wc_curve25519_size(&key);
  596. \endcode
  597. \sa wc_curve25519_init
  598. \sa wc_curve25519_make_key
  599. */
  600. int wc_curve25519_size(curve25519_key* key);