crypto_box.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #ifndef crypto_box_H
  2. #define crypto_box_H
  3. /*
  4. * THREAD SAFETY: crypto_box_keypair() is thread-safe,
  5. * provided that sodium_init() was called before.
  6. *
  7. * Other functions are always thread-safe.
  8. */
  9. #include <stddef.h>
  10. #include "crypto_box_curve25519xsalsa20poly1305.h"
  11. #include "export.h"
  12. #ifdef __cplusplus
  13. # ifdef __GNUC__
  14. # pragma GCC diagnostic ignored "-Wlong-long"
  15. # endif
  16. extern "C" {
  17. #endif
  18. #define crypto_box_SEEDBYTES crypto_box_curve25519xsalsa20poly1305_SEEDBYTES
  19. SODIUM_EXPORT
  20. size_t crypto_box_seedbytes(void);
  21. #define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
  22. SODIUM_EXPORT
  23. size_t crypto_box_publickeybytes(void);
  24. #define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
  25. SODIUM_EXPORT
  26. size_t crypto_box_secretkeybytes(void);
  27. #define crypto_box_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_NONCEBYTES
  28. SODIUM_EXPORT
  29. size_t crypto_box_noncebytes(void);
  30. #define crypto_box_MACBYTES crypto_box_curve25519xsalsa20poly1305_MACBYTES
  31. SODIUM_EXPORT
  32. size_t crypto_box_macbytes(void);
  33. #define crypto_box_MESSAGEBYTES_MAX crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX
  34. SODIUM_EXPORT
  35. size_t crypto_box_messagebytes_max(void);
  36. #define crypto_box_PRIMITIVE "curve25519xsalsa20poly1305"
  37. SODIUM_EXPORT
  38. const char *crypto_box_primitive(void);
  39. SODIUM_EXPORT
  40. int crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk,
  41. const unsigned char *seed)
  42. __attribute__ ((nonnull));
  43. SODIUM_EXPORT
  44. int crypto_box_keypair(unsigned char *pk, unsigned char *sk)
  45. __attribute__ ((nonnull));
  46. SODIUM_EXPORT
  47. int crypto_box_easy(unsigned char *c, const unsigned char *m,
  48. unsigned long long mlen, const unsigned char *n,
  49. const unsigned char *pk, const unsigned char *sk)
  50. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));
  51. SODIUM_EXPORT
  52. int crypto_box_open_easy(unsigned char *m, const unsigned char *c,
  53. unsigned long long clen, const unsigned char *n,
  54. const unsigned char *pk, const unsigned char *sk)
  55. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));
  56. SODIUM_EXPORT
  57. int crypto_box_detached(unsigned char *c, unsigned char *mac,
  58. const unsigned char *m, unsigned long long mlen,
  59. const unsigned char *n, const unsigned char *pk,
  60. const unsigned char *sk)
  61. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 2, 5, 6, 7)));
  62. SODIUM_EXPORT
  63. int crypto_box_open_detached(unsigned char *m, const unsigned char *c,
  64. const unsigned char *mac,
  65. unsigned long long clen,
  66. const unsigned char *n,
  67. const unsigned char *pk,
  68. const unsigned char *sk)
  69. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6, 7)));
  70. /* -- Precomputation interface -- */
  71. #define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
  72. SODIUM_EXPORT
  73. size_t crypto_box_beforenmbytes(void);
  74. SODIUM_EXPORT
  75. int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
  76. const unsigned char *sk)
  77. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
  78. SODIUM_EXPORT
  79. int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
  80. unsigned long long mlen, const unsigned char *n,
  81. const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));
  82. SODIUM_EXPORT
  83. int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,
  84. unsigned long long clen, const unsigned char *n,
  85. const unsigned char *k)
  86. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
  87. SODIUM_EXPORT
  88. int crypto_box_detached_afternm(unsigned char *c, unsigned char *mac,
  89. const unsigned char *m, unsigned long long mlen,
  90. const unsigned char *n, const unsigned char *k)
  91. __attribute__ ((nonnull(1, 2, 5, 6)));
  92. SODIUM_EXPORT
  93. int crypto_box_open_detached_afternm(unsigned char *m, const unsigned char *c,
  94. const unsigned char *mac,
  95. unsigned long long clen, const unsigned char *n,
  96. const unsigned char *k)
  97. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));
  98. /* -- Ephemeral SK interface -- */
  99. #define crypto_box_SEALBYTES (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
  100. SODIUM_EXPORT
  101. size_t crypto_box_sealbytes(void);
  102. SODIUM_EXPORT
  103. int crypto_box_seal(unsigned char *c, const unsigned char *m,
  104. unsigned long long mlen, const unsigned char *pk)
  105. __attribute__ ((nonnull(1, 4)));
  106. SODIUM_EXPORT
  107. int crypto_box_seal_open(unsigned char *m, const unsigned char *c,
  108. unsigned long long clen,
  109. const unsigned char *pk, const unsigned char *sk)
  110. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
  111. /* -- NaCl compatibility interface ; Requires padding -- */
  112. #define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES
  113. SODIUM_EXPORT
  114. size_t crypto_box_zerobytes(void);
  115. #define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES
  116. SODIUM_EXPORT
  117. size_t crypto_box_boxzerobytes(void);
  118. SODIUM_EXPORT
  119. int crypto_box(unsigned char *c, const unsigned char *m,
  120. unsigned long long mlen, const unsigned char *n,
  121. const unsigned char *pk, const unsigned char *sk)
  122. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));
  123. SODIUM_EXPORT
  124. int crypto_box_open(unsigned char *m, const unsigned char *c,
  125. unsigned long long clen, const unsigned char *n,
  126. const unsigned char *pk, const unsigned char *sk)
  127. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));
  128. SODIUM_EXPORT
  129. int crypto_box_afternm(unsigned char *c, const unsigned char *m,
  130. unsigned long long mlen, const unsigned char *n,
  131. const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));
  132. SODIUM_EXPORT
  133. int crypto_box_open_afternm(unsigned char *m, const unsigned char *c,
  134. unsigned long long clen, const unsigned char *n,
  135. const unsigned char *k)
  136. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif