crypto_stream_chacha20.h (3672B)
1 #ifndef crypto_stream_chacha20_H 2 #define crypto_stream_chacha20_H 3 4 /* 5 * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 * While it provides some protection against eavesdropping, it does NOT 7 * provide any security against active attacks. 8 * Unless you know what you're doing, what you are looking for is probably 9 * the crypto_box functions. 10 */ 11 12 #include <stddef.h> 13 #include <stdint.h> 14 #include "export.h" 15 16 #ifdef __cplusplus 17 # ifdef __GNUC__ 18 # pragma GCC diagnostic ignored "-Wlong-long" 19 # endif 20 extern "C" { 21 #endif 22 23 #define crypto_stream_chacha20_KEYBYTES 32U 24 SODIUM_EXPORT 25 size_t crypto_stream_chacha20_keybytes(void); 26 27 #define crypto_stream_chacha20_NONCEBYTES 8U 28 SODIUM_EXPORT 29 size_t crypto_stream_chacha20_noncebytes(void); 30 31 #define crypto_stream_chacha20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX 32 SODIUM_EXPORT 33 size_t crypto_stream_chacha20_messagebytes_max(void); 34 35 /* ChaCha20 with a 64-bit nonce and a 64-bit counter, as originally designed */ 36 37 SODIUM_EXPORT 38 int crypto_stream_chacha20(unsigned char *c, unsigned long long clen, 39 const unsigned char *n, const unsigned char *k) 40 __attribute__ ((nonnull)); 41 42 SODIUM_EXPORT 43 int crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m, 44 unsigned long long mlen, const unsigned char *n, 45 const unsigned char *k) 46 __attribute__ ((nonnull)); 47 48 SODIUM_EXPORT 49 int crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m, 50 unsigned long long mlen, 51 const unsigned char *n, uint64_t ic, 52 const unsigned char *k) 53 __attribute__ ((nonnull)); 54 55 SODIUM_EXPORT 56 void crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES]) 57 __attribute__ ((nonnull)); 58 59 /* ChaCha20 with a 96-bit nonce and a 32-bit counter (IETF) */ 60 61 #define crypto_stream_chacha20_ietf_KEYBYTES 32U 62 SODIUM_EXPORT 63 size_t crypto_stream_chacha20_ietf_keybytes(void); 64 65 #define crypto_stream_chacha20_ietf_NONCEBYTES 12U 66 SODIUM_EXPORT 67 size_t crypto_stream_chacha20_ietf_noncebytes(void); 68 69 #define crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX \ 70 SODIUM_MIN(SODIUM_SIZE_MAX, 64ULL * (1ULL << 32)) 71 SODIUM_EXPORT 72 size_t crypto_stream_chacha20_ietf_messagebytes_max(void); 73 74 SODIUM_EXPORT 75 int crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen, 76 const unsigned char *n, const unsigned char *k) 77 __attribute__ ((nonnull)); 78 79 SODIUM_EXPORT 80 int crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m, 81 unsigned long long mlen, const unsigned char *n, 82 const unsigned char *k) 83 __attribute__ ((nonnull)); 84 85 SODIUM_EXPORT 86 int crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m, 87 unsigned long long mlen, 88 const unsigned char *n, uint32_t ic, 89 const unsigned char *k) 90 __attribute__ ((nonnull)); 91 92 SODIUM_EXPORT 93 void crypto_stream_chacha20_ietf_keygen(unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES]) 94 __attribute__ ((nonnull)); 95 96 /* Aliases */ 97 98 #define crypto_stream_chacha20_IETF_KEYBYTES crypto_stream_chacha20_ietf_KEYBYTES 99 #define crypto_stream_chacha20_IETF_NONCEBYTES crypto_stream_chacha20_ietf_NONCEBYTES 100 #define crypto_stream_chacha20_IETF_MESSAGEBYTES_MAX crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX 101 102 #ifdef __cplusplus 103 } 104 #endif 105 106 #endif