libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / src / libsodium / crypto_stream / salsa20 / ref / stream_salsa20_ref.c
blob66015e32229d2729aff65b76cd15eacb380bb549
1 /*
2 version 20080913
3 D. J. Bernstein
4 Public domain.
5 */
7 #include "api.h"
8 #include "crypto_core_salsa20.h"
10 #ifndef HAVE_AMD64_ASM
12 typedef unsigned int uint32;
14 static const unsigned char sigma[16] = {
15 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k'
18 int crypto_stream(
19 unsigned char *c,unsigned long long clen,
20 const unsigned char *n,
21 const unsigned char *k
24 unsigned char in[16];
25 unsigned char block[64];
26 unsigned long long i;
27 unsigned int u;
29 if (!clen) return 0;
31 for (i = 0;i < 8;++i) in[i] = n[i];
32 for (i = 8;i < 16;++i) in[i] = 0;
34 while (clen >= 64) {
35 crypto_core_salsa20(c,in,k,sigma);
37 u = 1;
38 for (i = 8;i < 16;++i) {
39 u += (unsigned int) in[i];
40 in[i] = u;
41 u >>= 8;
44 clen -= 64;
45 c += 64;
48 if (clen) {
49 crypto_core_salsa20(block,in,k,sigma);
50 for (i = 0;i < clen;++i) c[i] = block[i];
52 return 0;
55 #endif