xref: /freebsd/sys/contrib/libsodium/src/libsodium/crypto_stream/crypto_stream.c (revision 3611ec604864a7d4dcc9a3ea898c80eb35eef8a0)
1 
2 #include "crypto_stream.h"
3 #include "randombytes.h"
4 
5 size_t
crypto_stream_keybytes(void)6 crypto_stream_keybytes(void)
7 {
8     return crypto_stream_KEYBYTES;
9 }
10 
11 size_t
crypto_stream_noncebytes(void)12 crypto_stream_noncebytes(void)
13 {
14     return crypto_stream_NONCEBYTES;
15 }
16 
17 size_t
crypto_stream_messagebytes_max(void)18 crypto_stream_messagebytes_max(void)
19 {
20     return crypto_stream_MESSAGEBYTES_MAX;
21 }
22 
23 const char *
crypto_stream_primitive(void)24 crypto_stream_primitive(void)
25 {
26     return crypto_stream_PRIMITIVE;
27 }
28 
29 int
crypto_stream(unsigned char * c,unsigned long long clen,const unsigned char * n,const unsigned char * k)30 crypto_stream(unsigned char *c, unsigned long long clen,
31               const unsigned char *n, const unsigned char *k)
32 {
33     return crypto_stream_xsalsa20(c, clen, n, k);
34 }
35 
36 
37 int
crypto_stream_xor(unsigned char * c,const unsigned char * m,unsigned long long mlen,const unsigned char * n,const unsigned char * k)38 crypto_stream_xor(unsigned char *c, const unsigned char *m,
39                   unsigned long long mlen, const unsigned char *n,
40                   const unsigned char *k)
41 {
42     return crypto_stream_xsalsa20_xor(c, m, mlen, n, k);
43 }
44 
45 void
crypto_stream_keygen(unsigned char k[crypto_stream_KEYBYTES])46 crypto_stream_keygen(unsigned char k[crypto_stream_KEYBYTES])
47 {
48     randombytes_buf(k, crypto_stream_KEYBYTES);
49 }
50