b77b9f781d70c3dbc14fa0ae93345ecc63ccb1d3
[trex.git] /
1 /*
2 version 20080913
3 D. J. Bernstein
4 Public domain.
5 */
6
7 #include "api.h"
8 #include "crypto_core_hsalsa20.h"
9 #include "crypto_stream_salsa20.h"
10 #include "utils.h"
11
12 static const unsigned char sigma[16] = {
13     'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k'
14 };
15
16 int crypto_stream_xor(
17         unsigned char *c,
18   const unsigned char *m,unsigned long long mlen,
19   const unsigned char *n,
20   const unsigned char *k
21 )
22 {
23   unsigned char subkey[32];
24   int ret;
25   crypto_core_hsalsa20(subkey,n,k,sigma);
26   ret = crypto_stream_salsa20_xor(c,m,mlen,n + 16,subkey);
27   sodium_memzero(subkey, sizeof subkey);
28   return ret;
29 }