diff options
Diffstat (limited to 'nacl/crypto_stream/salsa2012/ref/stream.c')
-rw-r--r-- | nacl/crypto_stream/salsa2012/ref/stream.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/nacl/crypto_stream/salsa2012/ref/stream.c b/nacl/crypto_stream/salsa2012/ref/stream.c new file mode 100644 index 00000000..86053337 --- /dev/null +++ b/nacl/crypto_stream/salsa2012/ref/stream.c | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | version 20080913 | ||
3 | D. J. Bernstein | ||
4 | Public domain. | ||
5 | */ | ||
6 | |||
7 | #include "crypto_core_salsa2012.h" | ||
8 | #include "crypto_stream.h" | ||
9 | |||
10 | typedef unsigned int uint32; | ||
11 | |||
12 | static const unsigned char sigma[16] = "expand 32-byte k"; | ||
13 | |||
14 | int crypto_stream( | ||
15 | unsigned char *c,unsigned long long clen, | ||
16 | const unsigned char *n, | ||
17 | const unsigned char *k | ||
18 | ) | ||
19 | { | ||
20 | unsigned char in[16]; | ||
21 | unsigned char block[64]; | ||
22 | int i; | ||
23 | unsigned int u; | ||
24 | |||
25 | if (!clen) return 0; | ||
26 | |||
27 | for (i = 0;i < 8;++i) in[i] = n[i]; | ||
28 | for (i = 8;i < 16;++i) in[i] = 0; | ||
29 | |||
30 | while (clen >= 64) { | ||
31 | crypto_core_salsa2012(c,in,k,sigma); | ||
32 | |||
33 | u = 1; | ||
34 | for (i = 8;i < 16;++i) { | ||
35 | u += (unsigned int) in[i]; | ||
36 | in[i] = u; | ||
37 | u >>= 8; | ||
38 | } | ||
39 | |||
40 | clen -= 64; | ||
41 | c += 64; | ||
42 | } | ||
43 | |||
44 | if (clen) { | ||
45 | crypto_core_salsa2012(block,in,k,sigma); | ||
46 | for (i = 0;i < clen;++i) c[i] = block[i]; | ||
47 | } | ||
48 | return 0; | ||
49 | } | ||