ed448.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. /*!
  2. \ingroup ED448
  3. \brief This function generates the Ed448 public key from the private key.
  4. It stores the public key in the buffer pubKey, and sets the bytes
  5. written to this buffer in pubKeySz.
  6. \return 0 Returned upon successfully making the public key.
  7. \return BAD_FUNC_ARG Returned ifi key or pubKey evaluate to NULL, or if the
  8. specified key size is not 57 bytes (Ed448 has 57 byte keys).
  9. \return MEMORY_E Returned if there is an error allocating memory
  10. during function execution.
  11. \param [in] key Pointer to the ed448_key for which to generate a key.
  12. \param [out] out Pointer to the buffer in which to store the public key.
  13. \param [in,out] outLen Pointer to a word32 object with the size available
  14. in out. Set with the number of bytes written to out after successfully
  15. exporting the public key.
  16. _Example_
  17. \code
  18. int ret;
  19. ed448_key key;
  20. byte priv[] = { initialize with 57 byte private key };
  21. byte pub[57];
  22. word32 pubSz = sizeof(pub);
  23. wc_ed448_init(&key);
  24. wc_ed448_import_private_only(priv, sizeof(priv), &key);
  25. ret = wc_ed448_make_public(&key, pub, &pubSz);
  26. if (ret != 0) {
  27. // error making public key
  28. }
  29. \endcode
  30. \sa wc_ed448_init
  31. \sa wc_ed448_import_private_only
  32. \sa wc_ed448_make_key
  33. */
  34. int wc_ed448_make_public(ed448_key* key, unsigned char* pubKey,
  35. word32 pubKeySz);
  36. /*!
  37. \ingroup ED448
  38. \brief This function generates a new Ed448 key and stores it in key.
  39. \return 0 Returned upon successfully making an ed448_key.
  40. \return BAD_FUNC_ARG Returned if rng or key evaluate to NULL, or if the
  41. specified key size is not 57 bytes (Ed448 has 57 byte keys).
  42. \return MEMORY_E Returned if there is an error allocating memory
  43. during function execution.
  44. \param [in] rng Pointer to an initialized RNG object with which to
  45. generate the key.
  46. \param [in] keysize Length of key to generate. Should always be 57 for
  47. Ed448.
  48. \param [in,out] key Pointer to the ed448_key for which to generate a key.
  49. _Example_
  50. \code
  51. int ret;
  52. WC_RNG rng;
  53. ed448_key key;
  54. wc_InitRng(&rng);
  55. wc_ed448_init(&key);
  56. ret = wc_ed448_make_key(&rng, 57, &key);
  57. if (ret != 0) {
  58. // error making key
  59. }
  60. \endcode
  61. \sa wc_ed448_init
  62. */
  63. int wc_ed448_make_key(WC_RNG* rng, int keysize, ed448_key* key);
  64. /*!
  65. \ingroup ED448
  66. \brief This function signs a message using an ed448_key object
  67. to guarantee authenticity.
  68. \return 0 Returned upon successfully generating a signature for the
  69. message.
  70. \return BAD_FUNC_ARG Returned if any of the input parameters evaluate to
  71. NULL, or if the output buffer is too small to store the generated signature.
  72. \return MEMORY_E Returned if there is an error allocating memory during
  73. function execution.
  74. \param [in] in Pointer to the buffer containing the message to sign.
  75. \param [in] inlen Length of the message to sign.
  76. \param [out] out Buffer in which to store the generated signature.
  77. \param [in,out] outlen Maximum length of the output buffer. Will store the
  78. bytes written to out upon successfully generating a message signature.
  79. \param [in] key Pointer to a private ed448_key with which to generate the
  80. signature.
  81. _Example_
  82. \code
  83. ed448_key key;
  84. WC_RNG rng;
  85. int ret, sigSz;
  86. byte sig[114]; // will hold generated signature
  87. sigSz = sizeof(sig);
  88. byte message[] = { initialize with message };
  89. wc_InitRng(&rng); // initialize rng
  90. wc_ed448_init(&key); // initialize key
  91. wc_ed448_make_key(&rng, 57, &key); // make public/private key pair
  92. ret = wc_ed448_sign_msg(message, sizeof(message), sig, &sigSz, &key);
  93. if (ret != 0 ) {
  94. // error generating message signature
  95. }
  96. \endcode
  97. \sa wc_ed448ph_sign_hash
  98. \sa wc_ed448ph_sign_msg
  99. \sa wc_ed448_verify_msg
  100. */
  101. int wc_ed448_sign_msg(const byte* in, word32 inlen, byte* out,
  102. word32 *outlen, ed448_key* key);
  103. /*!
  104. \ingroup ED448
  105. \brief This function signs a message digest using an ed448_key object
  106. to guarantee authenticity. The context is included as part of the data
  107. signed. The hash is the pre-hashed message before signature calculation.
  108. \return 0 Returned upon successfully generating a signature for the
  109. message digest.
  110. \return BAD_FUNC_ARG Returned any of the input parameters evaluate to
  111. NULL, or if the output buffer is too small to store the generated signature.
  112. \return MEMORY_E Returned if there is an error allocating memory during
  113. function execution.
  114. \param [in] hash Pointer to the buffer containing the hash of the message
  115. to sign.
  116. \param [in] hashLen Length of the hash of the message to sign.
  117. \param [out] out Buffer in which to store the generated signature.
  118. \param [in,out] outlen Maximum length of the output buffer. Will store the
  119. bytes written to out upon successfully generating a message signature.
  120. \param [in] key Pointer to a private ed448_key with which to generate the
  121. signature.
  122. \param [in] context Pointer to the buffer containing the context for which
  123. message is being signed.
  124. \param [in] contextLen Length of the context buffer.
  125. _Example_
  126. \code
  127. ed448_key key;
  128. WC_RNG rng;
  129. int ret, sigSz;
  130. byte sig[114]; // will hold generated signature
  131. sigSz = sizeof(sig);
  132. byte hash[] = { initialize hash of message };
  133. byte context[] = { initialize with context of signing };
  134. wc_InitRng(&rng); // initialize rng
  135. wc_ed448_init(&key); // initialize key
  136. wc_ed448_make_key(&rng, 57, &key); // make public/private key pair
  137. ret = wc_ed448ph_sign_hash(hash, sizeof(hash), sig, &sigSz, &key,
  138. context, sizeof(context));
  139. if (ret != 0) {
  140. // error generating message signature
  141. }
  142. \endcode
  143. \sa wc_ed448_sign_msg
  144. \sa wc_ed448ph_sign_msg
  145. \sa wc_ed448ph_verify_hash
  146. */
  147. int wc_ed448ph_sign_hash(const byte* hash, word32 hashLen, byte* out,
  148. word32 *outLen, ed448_key* key,
  149. const byte* context, byte contextLen);
  150. /*!
  151. \ingroup ED448
  152. \brief This function signs a message using an ed448_key object
  153. to guarantee authenticity. The context is included as part of the data
  154. signed. The message is pre-hashed before signature calculation.
  155. \return 0 Returned upon successfully generating a signature for the
  156. message.
  157. \return BAD_FUNC_ARG Returned any of the input parameters evaluate to
  158. NULL, or if the output buffer is too small to store the generated signature.
  159. \return MEMORY_E Returned if there is an error allocating memory during
  160. function execution.
  161. \param [in] in Pointer to the buffer containing the message to sign.
  162. \param [in] inlen Length of the message to sign.
  163. \param [out] out Buffer in which to store the generated signature.
  164. \param [in,out] outlen Maximum length of the output buffer. Will store the
  165. bytes written to out upon successfully generating a message signature.
  166. \param [in] key Pointer to a private ed448_key with which to generate the
  167. signature.
  168. \param [in] context Pointer to the buffer containing the context for which
  169. message is being signed.
  170. \param [in] contextLen Length of the context buffer.
  171. _Example_
  172. \code
  173. ed448_key key;
  174. WC_RNG rng;
  175. int ret, sigSz;
  176. byte sig[114]; // will hold generated signature
  177. sigSz = sizeof(sig);
  178. byte message[] = { initialize with message };
  179. byte context[] = { initialize with context of signing };
  180. wc_InitRng(&rng); // initialize rng
  181. wc_ed448_init(&key); // initialize key
  182. wc_ed448_make_key(&rng, 57, &key); // make public/private key pair
  183. ret = wc_ed448ph_sign_msg(message, sizeof(message), sig, &sigSz, &key,
  184. context, sizeof(context));
  185. if (ret != 0) {
  186. // error generating message signature
  187. }
  188. \endcode
  189. \sa wc_ed448_sign_msg
  190. \sa wc_ed448ph_sign_hash
  191. \sa wc_ed448ph_verify_msg
  192. */
  193. int wc_ed448ph_sign_msg(const byte* in, word32 inLen, byte* out,
  194. word32 *outLen, ed448_key* key, const byte* context,
  195. byte contextLen);
  196. /*!
  197. \ingroup ED448
  198. \brief This function verifies the Ed448 signature of a message to ensure
  199. authenticity. The context is included as part of the data
  200. verified. The answer is returned through res, with 1 corresponding to
  201. a valid signature, and 0 corresponding to an invalid signature.
  202. \return 0 Returned upon successfully performing the signature
  203. verification and authentication.
  204. \return BAD_FUNC_ARG Returned if any of the input parameters evaluate to
  205. NULL, or if the siglen does not match the actual length of a signature.
  206. \return SIG_VERIFY_E Returned if verification completes, but the signature
  207. generated does not match the signature provided.
  208. \param [in] sig Pointer to the buffer containing the signature to verify.
  209. \param [in] siglen Length of the signature to verify.
  210. \param [in] msg Pointer to the buffer containing the message to verify.
  211. \param [in] msgLen Length of the message to verify.
  212. \param [in] key Pointer to a public Ed448 key with which to verify the
  213. signature.
  214. \param [in] context Pointer to the buffer containing the context for which
  215. the message was signed.
  216. \param [in] contextLen Length of the context buffer.
  217. _Example_
  218. \code
  219. ed448_key key;
  220. int ret, verified = 0;
  221. byte sig[] { initialize with received signature };
  222. byte msg[] = { initialize with message };
  223. byte context[] = { initialize with context of signature };
  224. // initialize key with received public key
  225. ret = wc_ed448_verify_msg(sig, sizeof(sig), msg, sizeof(msg), &verified,
  226. &key, context, sizeof(context));
  227. if (ret < 0) {
  228. // error performing verification
  229. } else if (verified == 0)
  230. // the signature is invalid
  231. }
  232. \endcode
  233. \sa wc_ed448ph_verify_hash
  234. \sa wc_ed448ph_verify_msg
  235. \sa wc_ed448_sign_msg
  236. */
  237. int wc_ed448_verify_msg(const byte* sig, word32 siglen, const byte* msg,
  238. word32 msgLen, int* res, ed448_key* key,
  239. const byte* context, byte contextLen);
  240. /*!
  241. \ingroup ED448
  242. \brief This function verifies the Ed448 signature of the digest of a message
  243. to ensure authenticity. The context is included as part of the data
  244. verified. The hash is the pre-hashed message before signature calculation.
  245. The answer is returned through res, with 1 corresponding to a valid
  246. signature, and 0 corresponding to an invalid signature.
  247. \return 0 Returned upon successfully performing the signature
  248. verification and authentication.
  249. \return BAD_FUNC_ARG Returned if any of the input parameters evaluate to
  250. NULL, or if the siglen does not match the actual length of a signature.
  251. \return SIG_VERIFY_E Returned if verification completes, but the signature
  252. generated does not match the signature provided.
  253. \param [in] sig Pointer to the buffer containing the signature to verify.
  254. \param [in] siglen Length of the signature to verify.
  255. \param [in] hash Pointer to the buffer containing the hash of the message
  256. to verify.
  257. \param [in] hashLen Length of the hash to verify.
  258. \param [in] key Pointer to a public Ed448 key with which to verify the
  259. signature.
  260. \param [in] context Pointer to the buffer containing the context for which
  261. the message was signed.
  262. \param [in] contextLen Length of the context buffer.
  263. _Example_
  264. \code
  265. ed448_key key;
  266. int ret, verified = 0;
  267. byte sig[] { initialize with received signature };
  268. byte hash[] = { initialize hash of message };
  269. byte context[] = { initialize with context of signature };
  270. // initialize key with received public key
  271. ret = wc_ed448ph_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  272. &verified, &key, context, sizeof(context));
  273. if (ret < 0) {
  274. // error performing verification
  275. } else if (verified == 0)
  276. // the signature is invalid
  277. }
  278. \endcode
  279. \sa wc_ed448_verify_msg
  280. \sa wc_ed448ph_verify_msg
  281. \sa wc_ed448ph_sign_hash
  282. */
  283. int wc_ed448ph_verify_hash(const byte* sig, word32 siglen, const byte* hash,
  284. word32 hashlen, int* res, ed448_key* key,
  285. const byte* context, byte contextLen);
  286. /*!
  287. \ingroup ED448
  288. \brief This function verifies the Ed448 signature of a message to ensure
  289. authenticity. The context is included as part of the data
  290. verified. The message is pre-hashed before verification. The answer is
  291. returned through res, with 1 corresponding to a valid signature, and 0
  292. corresponding to an invalid signature.
  293. \return 0 Returned upon successfully performing the signature
  294. verification and authentication.
  295. \return BAD_FUNC_ARG Returned if any of the input parameters evaluate to
  296. NULL, or if the siglen does not match the actual length of a signature.
  297. \return SIG_VERIFY_E Returned if verification completes, but the signature
  298. generated does not match the signature provided.
  299. \param [in] sig Pointer to the buffer containing the signature to verify.
  300. \param [in] siglen Length of the signature to verify.
  301. \param [in] msg Pointer to the buffer containing the message to verify.
  302. \param [in] msgLen Length of the message to verify.
  303. \param [in] key Pointer to a public Ed448 key with which to verify the
  304. signature.
  305. \param [in] context Pointer to the buffer containing the context for which
  306. the message was signed.
  307. \param [in] contextLen Length of the context buffer.
  308. _Example_
  309. \code
  310. ed448_key key;
  311. int ret, verified = 0;
  312. byte sig[] { initialize with received signature };
  313. byte msg[] = { initialize with message };
  314. byte context[] = { initialize with context of signature };
  315. // initialize key with received public key
  316. ret = wc_ed448ph_verify_msg(sig, sizeof(sig), msg, sizeof(msg), &verified,
  317. &key, context, sizeof(context));
  318. if (ret < 0) {
  319. // error performing verification
  320. } else if (verified == 0)
  321. // the signature is invalid
  322. }
  323. \endcode
  324. \sa wc_ed448_verify_msg
  325. \sa wc_ed448ph_verify_hash
  326. \sa wc_ed448ph_sign_msg
  327. */
  328. int wc_ed448ph_verify_msg(const byte* sig, word32 siglen, const byte* msg,
  329. word32 msgLen, int* res, ed448_key* key,
  330. const byte* context, byte contextLen);
  331. /*!
  332. \ingroup ED448
  333. \brief This function initializes an ed448_key object for future use
  334. with message verification.
  335. \return 0 Returned upon successfully initializing the ed448_key object.
  336. \return BAD_FUNC_ARG Returned if key is NULL.
  337. \param [in,out] key Pointer to the ed448_key object to initialize.
  338. _Example_
  339. \code
  340. ed448_key key;
  341. wc_ed448_init(&key);
  342. \endcode
  343. \sa wc_ed448_make_key
  344. \sa wc_ed448_free
  345. */
  346. int wc_ed448_init(ed448_key* key);
  347. /*!
  348. \ingroup ED448
  349. \brief This function frees an Ed448 object after it has been used.
  350. \param [in,out] key Pointer to the ed448_key object to free
  351. _Example_
  352. \code
  353. ed448_key key;
  354. // initialize key and perform secure exchanges
  355. ...
  356. wc_ed448_free(&key);
  357. \endcode
  358. \sa wc_ed448_init
  359. */
  360. void wc_ed448_free(ed448_key* key);
  361. /*!
  362. \ingroup ED448
  363. \brief This function imports a public ed448_key pair from a buffer
  364. containing the public key. This function will handle both compressed and
  365. uncompressed keys. The public key is checked that it matches the private
  366. key when one is present.
  367. \return 0 Returned on successfully importing the ed448_key.
  368. \return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or inLen is
  369. less than the size of an Ed448 key.
  370. \param [in] in Pointer to the buffer containing the public key.
  371. \param [in] inLen Length of the buffer containing the public key.
  372. \param [in,out] key Pointer to the ed448_key object in which to store the
  373. public key.
  374. _Example_
  375. \code
  376. int ret;
  377. byte pub[] = { initialize Ed448 public key };
  378. ed_448 key;
  379. wc_ed448_init_key(&key);
  380. ret = wc_ed448_import_public(pub, sizeof(pub), &key);
  381. if (ret != 0) {
  382. // error importing key
  383. }
  384. \endcode
  385. \sa wc_ed448_import_public_ex
  386. \sa wc_ed448_import_private_key
  387. \sa wc_ed448_import_private_key_ex
  388. \sa wc_ed448_export_public
  389. */
  390. int wc_ed448_import_public(const byte* in, word32 inLen, ed448_key* key);
  391. /*!
  392. \ingroup ED448
  393. \brief This function imports a public ed448_key pair from a buffer
  394. containing the public key. This function will handle both compressed and
  395. uncompressed keys. Check public key matches private key, when present,
  396. when not trusted.
  397. \return 0 Returned on successfully importing the ed448_key.
  398. \return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or inLen is
  399. less than the size of an Ed448 key.
  400. \param [in] in Pointer to the buffer containing the public key.
  401. \param [in] inLen Length of the buffer containing the public key.
  402. \param [in,out] key Pointer to the ed448_key object in which to store the
  403. public key.
  404. \param [in] trusted Public key data is trusted or not.
  405. _Example_
  406. \code
  407. int ret;
  408. byte pub[] = { initialize Ed448 public key };
  409. ed_448 key;
  410. wc_ed448_init_key(&key);
  411. ret = wc_ed448_import_public_ex(pub, sizeof(pub), &key, 1);
  412. if (ret != 0) {
  413. // error importing key
  414. }
  415. \endcode
  416. \sa wc_ed448_import_public
  417. \sa wc_ed448_import_private_key
  418. \sa wc_ed448_import_private_key_ex
  419. \sa wc_ed448_export_public
  420. */
  421. int wc_ed448_import_public_ex(const byte* in, word32 inLen, ed448_key* key,
  422. int trusted);
  423. /*!
  424. \ingroup ED448
  425. \brief This function imports an Ed448 private key only from a
  426. buffer.
  427. \return 0 Returned on successfully importing the Ed448 private key.
  428. \return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or if
  429. privSz is less than ED448_KEY_SIZE.
  430. \param [in] priv Pointer to the buffer containing the private key.
  431. \param [in] privSz Length of the private key.
  432. \param [in,out] key Pointer to the ed448_key object in which to store the
  433. imported private key.
  434. _Example_
  435. \code
  436. int ret;
  437. byte priv[] = { initialize with 57 byte private key };
  438. ed448_key key;
  439. wc_ed448_init_key(&key);
  440. ret = wc_ed448_import_private_only(priv, sizeof(priv), &key);
  441. if (ret != 0) {
  442. // error importing private key
  443. }
  444. \endcode
  445. \sa wc_ed448_import_public
  446. \sa wc_ed448_import_public_ex
  447. \sa wc_ed448_import_private_key
  448. \sa wc_ed448_import_private_key_ex
  449. \sa wc_ed448_export_private_only
  450. */
  451. int wc_ed448_import_private_only(const byte* priv, word32 privSz,
  452. ed448_key* key);
  453. /*!
  454. \ingroup ED448
  455. \brief This function imports a public/private Ed448 key pair from a
  456. pair of buffers. This function will handle both compressed and
  457. uncompressed keys.
  458. \return 0 Returned on successfully importing the Ed448 key.
  459. \return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or if
  460. either privSz is less than ED448_KEY_SIZE or pubSz is less than
  461. ED448_PUB_KEY_SIZE.
  462. \param [in] priv Pointer to the buffer containing the private key.
  463. \param [in] privSz Length of the private key.
  464. \param [in] pub Pointer to the buffer containing the public key.
  465. \param [in] pubSz Length of the public key.
  466. \param [in,out] key Pointer to the ed448_key object in which to store the
  467. imported private/public key pair.
  468. _Example_
  469. \code
  470. int ret;
  471. byte priv[] = { initialize with 57 byte private key };
  472. byte pub[] = { initialize with the corresponding public key };
  473. ed448_key key;
  474. wc_ed448_init_key(&key);
  475. ret = wc_ed448_import_private_key(priv, sizeof(priv), pub, sizeof(pub),
  476. &key);
  477. if (ret != 0) {
  478. // error importing key
  479. }
  480. \endcode
  481. \sa wc_ed448_import_public
  482. \sa wc_ed448_import_public_ex
  483. \sa wc_ed448_import_private_only
  484. \sa wc_ed448_import_private_key_ex
  485. \sa wc_ed448_export_private
  486. */
  487. int wc_ed448_import_private_key(const byte* priv, word32 privSz,
  488. const byte* pub, word32 pubSz, ed448_key* key);
  489. /*!
  490. \ingroup ED448
  491. \brief This function imports a public/private Ed448 key pair from a
  492. pair of buffers. This function will handle both compressed and
  493. uncompressed keys. The public is checked against private key if not trusted.
  494. \return 0 Returned on successfully importing the Ed448 key.
  495. \return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or if
  496. either privSz is less than ED448_KEY_SIZE or pubSz is less than
  497. ED448_PUB_KEY_SIZE.
  498. \param [in] priv Pointer to the buffer containing the private key.
  499. \param [in] privSz Length of the private key.
  500. \param [in] pub Pointer to the buffer containing the public key.
  501. \param [in] pubSz Length of the public key.
  502. \param [in,out] key Pointer to the ed448_key object in which to store the
  503. imported private/public key pair.
  504. \param [in] trusted Public key data is trusted or not.
  505. _Example_
  506. \code
  507. int ret;
  508. byte priv[] = { initialize with 57 byte private key };
  509. byte pub[] = { initialize with the corresponding public key };
  510. ed448_key key;
  511. wc_ed448_init_key(&key);
  512. ret = wc_ed448_import_private_key_ex(priv, sizeof(priv), pub, sizeof(pub),
  513. &key, 1);
  514. if (ret != 0) {
  515. // error importing key
  516. }
  517. \endcode
  518. \sa wc_ed448_import_public
  519. \sa wc_ed448_import_public_ex
  520. \sa wc_ed448_import_private_only
  521. \sa wc_ed448_import_private_key
  522. \sa wc_ed448_export_private
  523. */
  524. int wc_ed448_import_private_key_ex(const byte* priv, word32 privSz,
  525. const byte* pub, word32 pubSz, ed448_key* key, int trusted);
  526. /*!
  527. \ingroup ED448
  528. \brief This function exports the private key from an ed448_key
  529. structure. It stores the public key in the buffer out, and sets the bytes
  530. written to this buffer in outLen.
  531. \return 0 Returned upon successfully exporting the public key.
  532. \return BAD_FUNC_ARG Returned if any of the input values evaluate to NULL.
  533. \return BUFFER_E Returned if the buffer provided is not large enough to
  534. store the private key. Upon returning this error, the function sets the
  535. size required in outLen.
  536. \param [in] key Pointer to an ed448_key structure from which to export the
  537. public key.
  538. \param [out] out Pointer to the buffer in which to store the public key.
  539. \param [in,out] outLen Pointer to a word32 object with the size available
  540. in out. Set with the number of bytes written to out after successfully
  541. exporting the public key.
  542. _Example_
  543. \code
  544. int ret;
  545. ed448_key key;
  546. // initialize key, make key
  547. char pub[57];
  548. word32 pubSz = sizeof(pub);
  549. ret = wc_ed448_export_public(&key, pub, &pubSz);
  550. if (ret != 0) {
  551. // error exporting public key
  552. }
  553. \endcode
  554. \sa wc_ed448_import_public
  555. \sa wc_ed448_import_public_ex
  556. \sa wc_ed448_export_private_only
  557. */
  558. int wc_ed448_export_public(ed448_key* key, byte* out, word32* outLen);
  559. /*!
  560. \ingroup ED448
  561. \brief This function exports only the private key from an ed448_key
  562. structure. It stores the private key in the buffer out, and sets
  563. the bytes written to this buffer in outLen.
  564. \return 0 Returned upon successfully exporting the private key.
  565. \return ECC_BAD_ARG_E Returned if any of the input values evaluate to NULL.
  566. \return BUFFER_E Returned if the buffer provided is not large enough
  567. to store the private key.
  568. \param [in] key Pointer to an ed448_key structure from which to export
  569. the private key.
  570. \param [out] out Pointer to the buffer in which to store the private key.
  571. \param [in,out] outLen Pointer to a word32 object with the size available in
  572. out. Set with the number of bytes written to out after successfully
  573. exporting the private key.
  574. _Example_
  575. \code
  576. int ret;
  577. ed448_key key;
  578. // initialize key, make key
  579. char priv[57]; // 57 bytes because only private key
  580. word32 privSz = sizeof(priv);
  581. ret = wc_ed448_export_private_only(&key, priv, &privSz);
  582. if (ret != 0) {
  583. // error exporting private key
  584. }
  585. \endcode
  586. \sa wc_ed448_export_public
  587. \sa wc_ed448_import_private_key
  588. \sa wc_ed448_import_private_key_ex
  589. */
  590. int wc_ed448_export_private_only(ed448_key* key, byte* out, word32* outLen);
  591. /*!
  592. \ingroup ED448
  593. \brief This function exports the key pair from an ed448_key
  594. structure. It stores the key pair in the buffer out, and sets
  595. the bytes written to this buffer in outLen.
  596. \return 0 Returned upon successfully exporting the key pair.
  597. \return ECC_BAD_ARG_E Returned if any of the input values evaluate to NULL.
  598. \return BUFFER_E Returned if the buffer provided is not large enough
  599. to store the key pair.
  600. \param [in] key Pointer to an ed448_key structure from which to export
  601. the key pair.
  602. \param [out] out Pointer to the buffer in which to store the key pair.
  603. \param [in,out] outLen Pointer to a word32 object with the size available in
  604. out. Set with the number of bytes written to out after successfully
  605. exporting the key pair.
  606. _Example_
  607. \code
  608. ed448_key key;
  609. wc_ed448_init(&key);
  610. WC_RNG rng;
  611. wc_InitRng(&rng);
  612. wc_ed448_make_key(&rng, 57, &key); // initialize 57 byte Ed448 key
  613. byte out[114]; // out needs to be a sufficient buffer size
  614. word32 outLen = sizeof(out);
  615. int key_size = wc_ed448_export_private(&key, out, &outLen);
  616. if (key_size == BUFFER_E) {
  617. // Check size of out compared to outLen to see if function reset outLen
  618. }
  619. \endcode
  620. \sa wc_ed448_import_private
  621. \sa wc_ed448_export_private_only
  622. */
  623. int wc_ed448_export_private(ed448_key* key, byte* out, word32* outLen);
  624. /*!
  625. \ingroup ED448
  626. \brief This function exports the private and public key separately from an
  627. ed448_key structure. It stores the private key in the buffer priv, and sets
  628. the bytes written to this buffer in privSz. It stores the public key in the
  629. buffer pub, and sets the bytes written to this buffer in pubSz.
  630. \return 0 Returned upon successfully exporting the key pair.
  631. \return ECC_BAD_ARG_E Returned if any of the input values evaluate to NULL.
  632. \return BUFFER_E Returned if the buffer provided is not large enough
  633. to store the key pair.
  634. \param [in] key Pointer to an ed448_key structure from which to export
  635. the key pair.
  636. \param [out] priv Pointer to the buffer in which to store the private key.
  637. \param [in,out] privSz Pointer to a word32 object with the size available in
  638. out. Set with the number of bytes written to out after successfully
  639. exporting the private key.
  640. \param [out] pub Pointer to the buffer in which to store the public key.
  641. \param [in,out] pubSz Pointer to a word32 object with the size available in
  642. out. Set with the number of bytes written to out after successfully
  643. exporting the public key.
  644. _Example_
  645. \code
  646. int ret;
  647. ed448_key key;
  648. // initialize key, make key
  649. char pub[57];
  650. word32 pubSz = sizeof(pub);
  651. char priv[57];
  652. word32 privSz = sizeof(priv);
  653. ret = wc_ed448_export_key(&key, priv, &pubSz, pub, &pubSz);
  654. if (ret != 0) {
  655. // error exporting private and public key
  656. }
  657. \endcode
  658. \sa wc_ed448_export_private
  659. \sa wc_ed448_export_public
  660. */
  661. int wc_ed448_export_key(ed448_key* key,
  662. byte* priv, word32 *privSz,
  663. byte* pub, word32 *pubSz);
  664. /*!
  665. \ingroup ED448
  666. \brief This function checks the public key in ed448_key structure matches
  667. the private key.
  668. \return 0 Returned if the private and public key matched.
  669. \return BAD_FUNC_ARGS Returned if the given key is NULL.
  670. \param [in] key Pointer to an ed448_key structure holding a private and
  671. public key.
  672. _Example_
  673. \code
  674. int ret;
  675. byte priv[] = { initialize with 57 byte private key };
  676. byte pub[] = { initialize with the corresponding public key };
  677. ed448_key key;
  678. wc_ed448_init_key(&key);
  679. wc_ed448_import_private_key_ex(priv, sizeof(priv), pub, sizeof(pub), &key,
  680. 1);
  681. ret = wc_ed448_check_key(&key);
  682. if (ret != 0) {
  683. // error checking key
  684. }
  685. \endcode
  686. \sa wc_ed448_import_private_key
  687. \sa wc_ed448_import_private_key_ex
  688. */
  689. int wc_ed448_check_key(ed448_key* key);
  690. /*!
  691. \ingroup ED448
  692. \brief This function returns the size of an Ed448 private key - 57 bytes.
  693. \return ED448_KEY_SIZE The size of a valid private key (57 bytes).
  694. \return BAD_FUNC_ARGS Returned if the given key is NULL.
  695. \param [in] key Pointer to an ed448_key structure for which to get the
  696. key size.
  697. _Example_
  698. \code
  699. int keySz;
  700. ed448_key key;
  701. // initialize key, make key
  702. keySz = wc_ed448_size(&key);
  703. if (keySz == 0) {
  704. // error determining key size
  705. }
  706. \endcode
  707. \sa wc_ed448_make_key
  708. */
  709. int wc_ed448_size(ed448_key* key);
  710. /*!
  711. \ingroup ED448
  712. \brief This function returns the private key size (secret + public) in
  713. bytes.
  714. \return ED448_PRV_KEY_SIZE The size of the private key (114 bytes).
  715. \return BAD_FUNC_ARG Returns if key argument is NULL.
  716. \param [in] key Pointer to an ed448_key structure for which to get the
  717. key size.
  718. _Example_
  719. \code
  720. ed448_key key;
  721. wc_ed448_init(&key);
  722. WC_RNG rng;
  723. wc_InitRng(&rng);
  724. wc_ed448_make_key(&rng, 57, &key); // initialize 57 byte Ed448 key
  725. int key_size = wc_ed448_priv_size(&key);
  726. \endcode
  727. \sa wc_ed448_pub_size
  728. */
  729. int wc_ed448_priv_size(ed448_key* key);
  730. /*!
  731. \ingroup ED448
  732. \brief This function returns the compressed key size in bytes (public key).
  733. \return ED448_PUB_KEY_SIZE The size of the compressed public key (57 bytes).
  734. \return BAD_FUNC_ARG Returns if key argument is NULL.
  735. \param [in] key Pointer to an ed448_key structure for which to get the
  736. key size.
  737. _Example_
  738. \code
  739. ed448_key key;
  740. wc_ed448_init(&key);
  741. WC_RNG rng;
  742. wc_InitRng(&rng);
  743. wc_ed448_make_key(&rng, 57, &key); // initialize 57 byte Ed448 key
  744. int key_size = wc_ed448_pub_size(&key);
  745. \endcode
  746. \sa wc_ed448_priv_size
  747. */
  748. int wc_ed448_pub_size(ed448_key* key);
  749. /*!
  750. \ingroup ED448
  751. \brief This function returns the size of an Ed448 signature (114 in bytes).
  752. \return ED448_SIG_SIZE The size of an Ed448 signature (114 bytes).
  753. \return BAD_FUNC_ARG Returns if key argument is NULL.
  754. \param [in] key Pointer to an ed448_key structure for which to get the
  755. signature size.
  756. _Example_
  757. \code
  758. int sigSz;
  759. ed448_key key;
  760. // initialize key, make key
  761. sigSz = wc_ed448_sig_size(&key);
  762. if (sigSz == 0) {
  763. // error determining sig size
  764. }
  765. \endcode
  766. \sa wc_ed448_sign_msg
  767. */
  768. int wc_ed448_sig_size(ed448_key* key);