naclite.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. // naclite.h - written and placed in the public domain by Jeffrey Walton
  2. // based on public domain NaCl source code written by
  3. // Daniel J. Bernstein, Bernard van Gastel, Wesley Janssen,
  4. // Tanja Lange, Peter Schwabe and Sjaak Smetsers.
  5. // The Tweet API was added to the Crypto++ library to cross-validate results.
  6. // We debated over putting it in the Test namespace, but settled for the NaCl
  7. // namespace to segregate it from other parts of the library.
  8. /// \file naclite.h
  9. /// \brief Crypto++ interface to TweetNaCl library (20140917)
  10. /// \details TweetNaCl is a compact reimplementation of the NaCl library
  11. /// by Daniel J. Bernstein, Bernard van Gastel, Wesley Janssen, Tanja
  12. /// Lange, Peter Schwabe and Sjaak Smetsers. The library is less than
  13. /// 20 KB in size and provides 25 of the NaCl library functions.
  14. /// \details The compact library uses curve25519, XSalsa20, Poly1305 and
  15. /// SHA-512 as default primitives, and includes both x25519 key exchange
  16. /// and ed25519 signatures. The complete list of functions can be found
  17. /// in <A
  18. /// HREF="https://tweetnacl.cr.yp.to/tweetnacl-20140917.pdf">TweetNaCl:
  19. /// A crypto library in 100 tweets</A> (20140917), Table 1, page 5.
  20. /// \details Crypto++ rejects small order elements using libsodium's
  21. /// blacklist. The TweetNaCl library allowed them but the library predated
  22. /// the attack. If you wish to allow small elements then use the "unchecked"
  23. /// versions of crypto_box_unchecked, crypto_box_open_unchecked and
  24. /// crypto_box_beforenm_unchecked.
  25. /// \details TweetNaCl is well written but not well optimzed. It runs about
  26. /// 10x slower than optimized routines from libsodium. However, the library
  27. /// is still 2x to 4x faster than the algorithms NaCl was designed to replace
  28. /// and allows cross-checking results from an independent implementation.
  29. /// \details The Crypto++ wrapper for TweetNaCl requires OS features. That is,
  30. /// <tt>NO_OS_DEPENDENCE</tt> cannot be defined. It is due to TweetNaCl's
  31. /// internal function <tt>randombytes</tt>. Crypto++ used
  32. /// <tt>DefaultAutoSeededRNG</tt> within <tt>randombytes</tt>, so OS
  33. /// integration must be enabled. You can use another generator like
  34. /// <tt>RDRAND</tt> to avoid the restriction.
  35. /// \sa <A HREF="https://cr.yp.to/highspeed/coolnacl-20120725.pdf">The security
  36. /// impact of a new cryptographic library</A>, <A
  37. /// HREF="https://tweetnacl.cr.yp.to/tweetnacl-20140917.pdf">TweetNaCl:
  38. /// A crypto library in 100 tweets</A> (20140917), <A
  39. /// HREF="https://eprint.iacr.org/2017/806.pdf">May the Fourth Be With You:
  40. /// A Microarchitectural Side Channel Attack on Several Real-World
  41. /// Applications of Curve25519</A>, <A
  42. /// HREF="https://github.com/jedisct1/libsodium/commit/afabd7e7386e1194">libsodium
  43. /// commit afabd7e7386e1194</A> and <A
  44. /// HREF="https://tools.ietf.org/html/rfc7748">RFC 7748, Elliptic Curves for
  45. /// Security</A>, Section 6.
  46. /// \since Crypto++ 6.0
  47. #ifndef CRYPTOPP_NACL_H
  48. #define CRYPTOPP_NACL_H
  49. #include "config.h"
  50. #include "stdcpp.h"
  51. #if defined(NO_OS_DEPENDENCE) || !defined(OS_RNG_AVAILABLE)
  52. # define CRYPTOPP_DISABLE_NACL 1
  53. #endif
  54. #ifndef CRYPTOPP_DISABLE_NACL
  55. NAMESPACE_BEGIN(CryptoPP)
  56. NAMESPACE_BEGIN(NaCl)
  57. /// \brief Hash size in bytes
  58. /// \sa <A HREF="https://nacl.cr.yp.to/hash.html">NaCl crypto_hash documentation</A>
  59. CRYPTOPP_CONSTANT(crypto_hash_BYTES = 64);
  60. /// \brief Key size in bytes
  61. /// \sa <A HREF="https://nacl.cr.yp.to/stream.html">NaCl crypto_stream documentation</A>
  62. CRYPTOPP_CONSTANT(crypto_stream_KEYBYTES = 32);
  63. /// \brief Nonce size in bytes
  64. /// \sa <A HREF="https://nacl.cr.yp.to/stream.html">NaCl crypto_stream documentation</A>
  65. CRYPTOPP_CONSTANT(crypto_stream_NONCEBYTES = 24);
  66. /// \brief Key size in bytes
  67. /// \sa <A HREF="https://nacl.cr.yp.to/auth.html">NaCl crypto_auth documentation</A>
  68. CRYPTOPP_CONSTANT(crypto_auth_KEYBYTES = 32);
  69. /// \brief Tag size in bytes
  70. /// \sa <A HREF="https://nacl.cr.yp.to/auth.html">NaCl crypto_auth documentation</A>
  71. CRYPTOPP_CONSTANT(crypto_auth_BYTES = 16);
  72. /// \brief Key size in bytes
  73. /// \sa <A HREF="https://nacl.cr.yp.to/onetimeauth.html">NaCl crypto_onetimeauth documentation</A>
  74. CRYPTOPP_CONSTANT(crypto_onetimeauth_KEYBYTES = 32);
  75. /// \brief Tag size in bytes
  76. /// \sa <A HREF="https://nacl.cr.yp.to/onetimeauth.html">NaCl crypto_onetimeauth documentation</A>
  77. CRYPTOPP_CONSTANT(crypto_onetimeauth_BYTES = 16);
  78. /// \brief Key size in bytes
  79. /// \sa <A HREF="https://nacl.cr.yp.to/secretbox.html">NaCl crypto_secretbox documentation</A>
  80. CRYPTOPP_CONSTANT(crypto_secretbox_KEYBYTES = 32);
  81. /// \brief Nonce size in bytes
  82. /// \sa <A HREF="https://nacl.cr.yp.to/secretbox.html">NaCl crypto_secretbox documentation</A>
  83. CRYPTOPP_CONSTANT(crypto_secretbox_NONCEBYTES = 24);
  84. /// \brief Zero-padded message prefix in bytes
  85. /// \sa <A HREF="https://nacl.cr.yp.to/secretbox.html">NaCl crypto_secretbox documentation</A>
  86. CRYPTOPP_CONSTANT(crypto_secretbox_ZEROBYTES = 32);
  87. /// \brief Zero-padded message prefix in bytes
  88. /// \sa <A HREF="https://nacl.cr.yp.to/secretbox.html">NaCl crypto_secretbox documentation</A>
  89. CRYPTOPP_CONSTANT(crypto_secretbox_BOXZEROBYTES = 16);
  90. /// \brief Private key size in bytes
  91. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  92. CRYPTOPP_CONSTANT(crypto_box_SECRETKEYBYTES = 32);
  93. /// \brief Public key size in bytes
  94. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  95. CRYPTOPP_CONSTANT(crypto_box_PUBLICKEYBYTES = 32);
  96. /// \brief Nonce size in bytes
  97. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  98. CRYPTOPP_CONSTANT(crypto_box_NONCEBYTES = 24);
  99. /// \brief Message 0-byte prefix in bytes
  100. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  101. CRYPTOPP_CONSTANT(crypto_box_ZEROBYTES = 32);
  102. /// \brief Open box 0-byte prefix in bytes
  103. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  104. CRYPTOPP_CONSTANT(crypto_box_BOXZEROBYTES = 16);
  105. /// \brief Precomputation 0-byte prefix in bytes in bytes
  106. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  107. CRYPTOPP_CONSTANT(crypto_box_BEFORENMBYTES = 32);
  108. /// \brief MAC size in bytes
  109. /// \details crypto_box_MACBYTES was missing from tweetnacl.h. Its is defined as
  110. /// crypto_box_curve25519xsalsa20poly1305_MACBYTES, which is defined as 16U.
  111. /// \sa <A HREF="https://nacl.cr.yp.to/hash.html">NaCl crypto_box documentation</A>
  112. CRYPTOPP_CONSTANT(crypto_box_MACBYTES = 16);
  113. /// \brief Private key size in bytes
  114. /// \sa <A HREF="https://nacl.cr.yp.to/sign.html">NaCl crypto_sign documentation</A>
  115. CRYPTOPP_CONSTANT(crypto_sign_SECRETKEYBYTES = 64);
  116. /// \brief Public key size in bytes
  117. /// \sa <A HREF="https://nacl.cr.yp.to/sign.html">NaCl crypto_sign documentation</A>
  118. CRYPTOPP_CONSTANT(crypto_sign_PUBLICKEYBYTES = 32);
  119. /// \brief Seed size in bytes
  120. /// \sa <A HREF="https://nacl.cr.yp.to/sign.html">NaCl crypto_sign documentation</A>
  121. CRYPTOPP_CONSTANT(crypto_sign_SEEDBYTES = 32);
  122. /// \brief Signature size in bytes
  123. /// \sa <A HREF="https://nacl.cr.yp.to/sign.html">NaCl crypto_sign documentation</A>
  124. CRYPTOPP_CONSTANT(crypto_sign_BYTES = 64);
  125. /// \brief Group element size in bytes
  126. /// \sa <A HREF="https://nacl.cr.yp.to/scalarmult.html">NaCl crypto_scalarmult documentation</A>
  127. CRYPTOPP_CONSTANT(crypto_scalarmult_BYTES = 32);
  128. /// \brief Integer size in bytes
  129. /// \sa <A HREF="https://nacl.cr.yp.to/scalarmult.html">NaCl crypto_scalarmult documentation</A>
  130. CRYPTOPP_CONSTANT(crypto_scalarmult_SCALARBYTES = 32);
  131. /// \brief Encrypt and authenticate a message
  132. /// \param c output byte buffer
  133. /// \param m input byte buffer
  134. /// \param d size of the input byte buffer
  135. /// \param n nonce byte buffer
  136. /// \param y other's public key
  137. /// \param x private key
  138. /// \details crypto_box() uses crypto_box_curve25519xsalsa20poly1305
  139. /// \return 0 on success, non-0 otherwise
  140. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  141. /// \since Crypto++ 6.0
  142. int crypto_box(byte *c,const byte *m,word64 d,const byte *n,const byte *y,const byte *x);
  143. /// \brief Verify and decrypt a message
  144. /// \param m output byte buffer
  145. /// \param c input byte buffer
  146. /// \param d size of the input byte buffer
  147. /// \param n nonce byte buffer
  148. /// \param y other's public key
  149. /// \param x private key
  150. /// \details crypto_box_open() uses crypto_box_curve25519xsalsa20poly1305
  151. /// \return 0 on success, non-0 otherwise
  152. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  153. /// \since Crypto++ 6.0
  154. int crypto_box_open(byte *m,const byte *c,word64 d,const byte *n,const byte *y,const byte *x);
  155. /// \brief Generate a keypair for encryption
  156. /// \param y public key byte buffer
  157. /// \param x private key byte buffer
  158. /// \return 0 on success, non-0 otherwise
  159. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  160. /// \since Crypto++ 6.0
  161. int crypto_box_keypair(byte *y,byte *x);
  162. /// \brief Encrypt and authenticate a message
  163. /// \param k shared secret byte buffer
  164. /// \param y other's public key
  165. /// \param x private key
  166. /// \details crypto_box_beforenm() performs message-independent precomputation to derive the key.
  167. /// Once the key is derived multiple calls to crypto_box_afternm() can be made to process the message.
  168. /// \return 0 on success, non-0 otherwise
  169. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  170. /// \since Crypto++ 6.0
  171. int crypto_box_beforenm(byte *k,const byte *y,const byte *x);
  172. /// \brief Encrypt and authenticate a message
  173. /// \param m output byte buffer
  174. /// \param c input byte buffer
  175. /// \param d size of the input byte buffer
  176. /// \param n nonce byte buffer
  177. /// \param k shared secret byte buffer
  178. /// \details crypto_box_afternm() performs message-dependent computation using the derived the key.
  179. /// Once the key is derived using crypto_box_beforenm() multiple calls to crypto_box_afternm()
  180. /// can be made to process the message.
  181. /// \return 0 on success, non-0 otherwise
  182. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  183. /// \since Crypto++ 6.0
  184. int crypto_box_afternm(byte *c,const byte *m,word64 d,const byte *n,const byte *k);
  185. /// \brief Verify and decrypt a message
  186. /// \param m output byte buffer
  187. /// \param c input byte buffer
  188. /// \param d size of the input byte buffer
  189. /// \param n nonce byte buffer
  190. /// \param k shared secret byte buffer
  191. /// \details crypto_box_afternm() performs message-dependent computation using the derived the key.
  192. /// Once the key is derived using crypto_box_beforenm() multiple calls to crypto_box_open_afternm()
  193. /// can be made to process the message.
  194. /// \return 0 on success, non-0 otherwise
  195. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>
  196. /// \since Crypto++ 6.0
  197. int crypto_box_open_afternm(byte *m,const byte *c,word64 d,const byte *n,const byte *k);
  198. /// \brief Encrypt and authenticate a message
  199. /// \param c output byte buffer
  200. /// \param m input byte buffer
  201. /// \param d size of the input byte buffer
  202. /// \param n nonce byte buffer
  203. /// \param y other's public key
  204. /// \param x private key
  205. /// \details crypto_box() uses crypto_box_curve25519xsalsa20poly1305.
  206. /// \details This version of crypto_box() does not check for small order elements. It can be unsafe
  207. /// but it exists for backwards compatibility with downlevel clients. Without the compatibility
  208. /// interop with early versions of NaCl, libsodium and other libraries does not exist. The
  209. /// downlevel interop may also be needed of cryptocurrencies like Bitcoin, Ethereum, Monero
  210. /// and Zcash.
  211. /// \return 0 on success, non-0 otherwise
  212. /// \warning This version of crypto_box() does not check for small order elements. It should not
  213. /// be used in new software.
  214. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>,
  215. /// <A HREF="https://eprint.iacr.org/2017/806.pdf">May the Fourth Be With You: A Microarchitectural
  216. /// Side Channel Attack on Several Real-World Applications of Curve25519</A>,
  217. /// <A HREF="https://github.com/jedisct1/libsodium/commit/afabd7e7386e1194">libsodium commit
  218. /// afabd7e7386e1194</A>.
  219. /// \since Crypto++ 6.0
  220. int crypto_box_unchecked(byte *c,const byte *m,word64 d,const byte *n,const byte *y,const byte *x);
  221. /// \brief Verify and decrypt a message
  222. /// \param m output byte buffer
  223. /// \param c input byte buffer
  224. /// \param d size of the input byte buffer
  225. /// \param n nonce byte buffer
  226. /// \param y other's public key
  227. /// \param x private key
  228. /// \details crypto_box_open() uses crypto_box_curve25519xsalsa20poly1305.
  229. /// \details This version of crypto_box_open() does not check for small order elements. It can be unsafe
  230. /// but it exists for backwards compatibility with downlevel clients. Without the compatibility
  231. /// interop with early versions of NaCl, libsodium and other libraries does not exist. The
  232. /// downlevel interop may also be needed of cryptocurrencies like Bitcoin, Ethereum, Monero
  233. /// and Zcash.
  234. /// \return 0 on success, non-0 otherwise
  235. /// \warning This version of crypto_box_open() does not check for small order elements. It should not
  236. /// be used in new software.
  237. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>,
  238. /// <A HREF="https://eprint.iacr.org/2017/806.pdf">May the Fourth Be With You: A Microarchitectural
  239. /// Side Channel Attack on Several Real-World Applications of Curve25519</A>,
  240. /// <A HREF="https://github.com/jedisct1/libsodium/commit/afabd7e7386e1194">libsodium commit
  241. /// afabd7e7386e1194</A>.
  242. /// \since Crypto++ 6.0
  243. int crypto_box_open_unchecked(byte *m,const byte *c,word64 d,const byte *n,const byte *y,const byte *x);
  244. /// \brief Encrypt and authenticate a message
  245. /// \param k shared secret byte buffer
  246. /// \param y other's public key
  247. /// \param x private key
  248. /// \details crypto_box_beforenm() performs message-independent precomputation to derive the key.
  249. /// Once the key is derived multiple calls to crypto_box_afternm() can be made to process the message.
  250. /// \details This version of crypto_box_beforenm() does not check for small order elements. It can be unsafe
  251. /// but it exists for backwards compatibility with downlevel clients. Without the compatibility
  252. /// interop with early versions of NaCl, libsodium and other libraries does not exist. The
  253. /// downlevel interop may also be needed of cryptocurrencies like Bitcoin, Ethereum, Monero
  254. /// and Zcash.
  255. /// \return 0 on success, non-0 otherwise
  256. /// \warning This version of crypto_box_beforenm() does not check for small order elements. It should not
  257. /// be used in new software.
  258. /// \sa <A HREF="https://nacl.cr.yp.to/box.html">NaCl crypto_box documentation</A>,
  259. /// <A HREF="https://eprint.iacr.org/2017/806.pdf">May the Fourth Be With You: A Microarchitectural
  260. /// Side Channel Attack on Several Real-World Applications of Curve25519</A>,
  261. /// <A HREF="https://github.com/jedisct1/libsodium/commit/afabd7e7386e1194">libsodium commit
  262. /// afabd7e7386e1194</A>.
  263. /// \since Crypto++ 6.0
  264. int crypto_box_beforenm_unchecked(byte *k,const byte *y,const byte *x);
  265. /// \brief TODO
  266. int crypto_core_salsa20(byte *out,const byte *in,const byte *k,const byte *c);
  267. /// \brief TODO
  268. /// \return 0 on success, non-0 otherwise
  269. /// \since Crypto++ 6.0
  270. int crypto_core_hsalsa20(byte *out,const byte *in,const byte *k,const byte *c);
  271. /// \brief Hash multiple blocks
  272. /// \details crypto_hashblocks() uses crypto_hashblocks_sha512.
  273. /// \return 0 on success, non-0 otherwise
  274. /// \sa <A HREF="https://nacl.cr.yp.to/hash.html">NaCl crypto_hash documentation</A>
  275. /// \since Crypto++ 6.0
  276. int crypto_hashblocks(byte *x,const byte *m,word64 n);
  277. /// \brief Hash a message
  278. /// \details crypto_hash() uses crypto_hash_sha512.
  279. /// \return 0 on success, non-0 otherwise
  280. /// \sa <A HREF="https://nacl.cr.yp.to/hash.html">NaCl crypto_hash documentation</A>
  281. /// \since Crypto++ 6.0
  282. int crypto_hash(byte *out,const byte *m,word64 n);
  283. /// \brief Create an authentication tag for a message
  284. /// \details crypto_onetimeauth() uses crypto_onetimeauth_poly1305.
  285. /// \return 0 on success, non-0 otherwise
  286. /// \sa <A HREF="https://nacl.cr.yp.to/onetimeauth.html">NaCl crypto_onetimeauth documentation</A>
  287. /// \since Crypto++ 6.0
  288. int crypto_onetimeauth(byte *out,const byte *m,word64 n,const byte *k);
  289. /// \brief Verify an authentication tag on a message
  290. /// \return 0 on success, non-0 otherwise
  291. /// \sa <A HREF="https://nacl.cr.yp.to/onetimeauth.html">NaCl crypto_onetimeauth documentation</A>
  292. /// \since Crypto++ 6.0
  293. int crypto_onetimeauth_verify(const byte *h,const byte *m,word64 n,const byte *k);
  294. /// \brief Scalar multiplication of a point
  295. /// \details crypto_scalarmult() uses crypto_scalarmult_curve25519
  296. /// \return 0 on success, non-0 otherwise
  297. /// \sa <A HREF="https://nacl.cr.yp.to/scalarmult.html">NaCl crypto_scalarmult documentation</A>
  298. /// \since Crypto++ 6.0
  299. int crypto_scalarmult(byte *q,const byte *n,const byte *p);
  300. /// \brief Scalar multiplication of base point
  301. /// \details crypto_scalarmult_base() uses crypto_scalarmult_curve25519
  302. /// \return 0 on success, non-0 otherwise
  303. /// \sa <A HREF="https://nacl.cr.yp.to/scalarmult.html">NaCl crypto_scalarmult documentation</A>
  304. /// \since Crypto++ 6.0
  305. int crypto_scalarmult_base(byte *q,const byte *n);
  306. /// \brief Encrypt and authenticate a message
  307. /// \details crypto_secretbox() uses a symmetric key to encrypt and authenticate a message.
  308. /// \return 0 on success, non-0 otherwise
  309. /// \sa <A HREF="https://nacl.cr.yp.to/secretbox.html">NaCl crypto_secretbox documentation</A>
  310. /// \since Crypto++ 6.0
  311. int crypto_secretbox(byte *c,const byte *m,word64 d,const byte *n,const byte *k);
  312. /// \brief Verify and decrypt a message
  313. /// \return 0 on success, non-0 otherwise
  314. /// \sa <A HREF="https://nacl.cr.yp.to/secretbox.html">NaCl crypto_secretbox documentation</A>
  315. /// \since Crypto++ 6.0
  316. int crypto_secretbox_open(byte *m,const byte *c,word64 d,const byte *n,const byte *k);
  317. /// \brief Sign a message
  318. /// \param sm output byte buffer
  319. /// \param smlen size of the output byte buffer
  320. /// \param m input byte buffer
  321. /// \param n size of the input byte buffer
  322. /// \param sk private key
  323. /// \details crypto_sign() uses crypto_sign_ed25519.
  324. /// \return 0 on success, non-0 otherwise
  325. /// \sa <A HREF="https://nacl.cr.yp.to/sign.html">NaCl crypto_sign documentation</A>
  326. /// \since Crypto++ 6.0
  327. int crypto_sign(byte *sm,word64 *smlen,const byte *m,word64 n,const byte *sk);
  328. /// \brief Verify a message
  329. /// \param m output byte buffer
  330. /// \param mlen size of the output byte buffer
  331. /// \param sm input byte buffer
  332. /// \param n size of the input byte buffer
  333. /// \param pk public key
  334. /// \return 0 on success, non-0 otherwise
  335. /// \sa <A HREF="https://nacl.cr.yp.to/sign.html">NaCl crypto_sign documentation</A>
  336. /// \since Crypto++ 6.0
  337. int crypto_sign_open(byte *m,word64 *mlen,const byte *sm,word64 n,const byte *pk);
  338. /// \brief Generate a keypair for signing
  339. /// \param pk public key byte buffer
  340. /// \param sk private key byte buffer
  341. /// \details crypto_sign_keypair() creates an ed25519 keypair.
  342. /// \return 0 on success, non-0 otherwise
  343. /// \sa <A HREF="https://nacl.cr.yp.to/sign.html">NaCl crypto_sign documentation</A>
  344. /// \since Crypto++ 6.0
  345. int crypto_sign_keypair(byte *pk, byte *sk);
  346. /// \brief Calculate a public key from a secret key
  347. /// \param pk public key byte buffer
  348. /// \param sk private key byte buffer
  349. /// \details crypto_sign_sk2pk() creates an ed25519 public key from an existing
  350. /// 32-byte secret key. The function does not backfill the tail bytes of the
  351. /// secret key with the calculated public key.
  352. /// \details crypto_sign_sk2pk() is not part of libsodium or Tweet API. It was
  353. /// added for interop with some anonymous routing protocols.
  354. /// \return 0 on success, non-0 otherwise
  355. /// \sa <A HREF="https://nacl.cr.yp.to/sign.html">NaCl crypto_sign documentation</A>
  356. /// \since Crypto++ 8.0
  357. int crypto_sign_sk2pk(byte *pk, const byte *sk);
  358. /// \brief Produce a keystream using XSalsa20
  359. /// \details crypto_stream() uses crypto_stream_xsalsa20
  360. /// \return 0 on success, non-0 otherwise
  361. /// \sa <A HREF="https://nacl.cr.yp.to/stream.html">NaCl crypto_stream documentation</A>
  362. /// \since Crypto++ 6.0
  363. int crypto_stream(byte *c,word64 d,const byte *n,const byte *k);
  364. /// \brief Encrypt a message using XSalsa20
  365. /// \return 0 on success, non-0 otherwise
  366. /// \sa <A HREF="https://nacl.cr.yp.to/stream.html">NaCl crypto_stream documentation</A>
  367. /// \since Crypto++ 6.0
  368. int crypto_stream_xor(byte *c,const byte *m,word64 d,const byte *n,const byte *k);
  369. /// \brief Produce a keystream using Salsa20
  370. /// \return 0 on success, non-0 otherwise
  371. /// \sa <A HREF="https://nacl.cr.yp.to/stream.html">NaCl crypto_stream documentation</A>
  372. /// \since Crypto++ 6.0
  373. int crypto_stream_salsa20(byte *c,word64 d,const byte *n,const byte *k);
  374. /// \brief Encrypt a message using Salsa20
  375. /// \return 0 on success, non-0 otherwise
  376. /// \sa <A HREF="https://nacl.cr.yp.to/stream.html">NaCl crypto_stream documentation</A>
  377. /// \since Crypto++ 6.0
  378. int crypto_stream_salsa20_xor(byte *c,const byte *m,word64 b,const byte *n,const byte *k);
  379. /// \brief Compare 16-byte buffers
  380. /// \return 0 on success, non-0 otherwise
  381. /// \sa <A HREF="https://nacl.cr.yp.to/verify.html">NaCl crypto_verify documentation</A>
  382. /// \since Crypto++ 6.0
  383. int crypto_verify_16(const byte *x,const byte *y);
  384. /// \brief Compare 32-byte buffers
  385. /// \return 0 on success, non-0 otherwise
  386. /// \sa <A HREF="https://nacl.cr.yp.to/verify.html">NaCl crypto_verify documentation</A>
  387. /// \since Crypto++ 6.0
  388. int crypto_verify_32(const byte *x,const byte *y);
  389. NAMESPACE_END // CryptoPP
  390. NAMESPACE_END // NaCl
  391. #endif // CRYPTOPP_DISABLE_NACL
  392. #endif // CRYPTOPP_NACL_H