comparison NaCl/crypto_stream/xsalsa20.cs @ 20:c873e3dd73fe

Added NaCl cryptography code
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 15 Apr 2013 00:43:48 +0200
parents
children
comparison
equal deleted inserted replaced
19:b9ef273964fd 20:c873e3dd73fe
1 using System;
2
3 namespace UCIS.NaCl.crypto_stream {
4 static unsafe class xsalsa20 {
5 public const int KEYBYTES = 32;
6 public const int NONCEBYTES = 24;
7
8 //Never written to
9 static Byte[] sigma = new Byte[16] {(Byte)'e', (Byte)'x', (Byte)'p', (Byte)'a', //[16] = "expand 32-byte k";
10 (Byte)'n', (Byte)'d', (Byte)' ', (Byte)'3',
11 (Byte)'2', (Byte)'-', (Byte)'b', (Byte)'y',
12 (Byte)'t', (Byte)'e', (Byte)' ', (Byte)'k', };
13
14 public static void crypto_stream(Byte* c, int clen, Byte* n, Byte* k) {
15 Byte* subkey = stackalloc Byte[32];
16 crypto_core.hsalsa20.crypto_core(subkey, n, k, sigma);
17 salsa20.crypto_stream(c, clen, n + 16, subkey);
18 }
19
20 public static void crypto_stream_xor(Byte* c, Byte* m, UInt64 mlen, Byte* n, Byte* k) {
21 Byte* subkey = stackalloc Byte[32];
22 crypto_core.hsalsa20.crypto_core(subkey, n, k, sigma);
23 salsa20.crypto_stream_xor(c, m, (int)mlen, n + 16, subkey);
24 }
25
26 internal static void crypto_stream_xor_split(Byte* mcpad, int padbytes, Byte* c, Byte* m, UInt64 mlen, Byte* n, Byte* k) {
27 Byte* subkey = stackalloc Byte[32];
28 crypto_core.hsalsa20.crypto_core(subkey, n, k, sigma);
29 salsa20.crypto_stream_xor_split(mcpad, padbytes, c, m, (int)mlen, n + 16, subkey);
30 }
31 }
32 }