ChaCha.salsa20WordToByte

Undocumented in source. Be warned that the author may not have intended to support it.
class ChaCha
protected override
void
salsa20WordToByte
(
const(uint[]) input
,
ref ubyte[] output
)

Examples

ChaCha test vectors

1 __gshared immutable immutable(char)[][] test_keys = [
2     "80000000000000000000000000000000", 
3     "0053a6f94c9ff24598eb3e91e4378add",
4     "00002000000000000000000000000000"~
5     "00000000000000000000000000000000",
6     "0f62b5085bae0154a7fa4da0f34699ec"~
7     "3f92e5388bde3184d72a7dd02376c91c"
8 
9 ];
10 
11 __gshared immutable immutable(char)[][] test_ivs = [
12     "0000000000000000",            
13     "0d74db42a91077de",
14     "0000000000000000",
15     "288ff65dc42b92f9"
16 ];
17 
18 __gshared immutable immutable(char)[][] test_plaintexts = [
19     "00000000000000000000000000000000"~
20     "00000000000000000000000000000000"~
21     "00000000000000000000000000000000"~
22     "00000000000000000000000000000000",
23 
24     "00000000000000000000000000000000"~
25     "00000000000000000000000000000000"~
26     "00000000000000000000000000000000"~
27     "00000000000000000000000000000000",
28 
29     "00000000000000000000000000000000"~
30     "00000000000000000000000000000000"~
31     "00000000000000000000000000000000"~
32     "00000000000000000000000000000000",
33 
34     "00000000000000000000000000000000"~
35     "00000000000000000000000000000000"~
36     "00000000000000000000000000000000"~
37     "00000000000000000000000000000000"
38 
39 
40 ];
41 
42 __gshared immutable immutable(char)[][] test_ciphertexts = [
43     "beb1e81e0f747e43ee51922b3e87fb38"~
44     "d0163907b4ed49336032ab78b67c2457"~
45     "9fe28f751bd3703e51d876c017faa435"~
46     "89e63593e03355a7d57b2366f30047c5",
47 
48     "509b267e7266355fa2dc0a25c023fce4"~
49     "7922d03dd9275423d7cb7118b2aedf22"~
50     "0568854bf47920d6fc0fd10526cfe7f9"~
51     "de472835afc73c916b849e91eee1f529",
52 
53     "653f4a18e3d27daf51f841a00b6c1a2b"~
54     "d2489852d4ae0711e1a4a32ad166fa6f"~
55     "881a2843238c7e17786ba5162bc019d5"~
56     "73849c167668510ada2f62b4ff31ad04",
57 
58     "db165814f66733b7a8e34d1ffc123427"~
59     "1256d3bf8d8da2166922e598acac70f4"~
60     "12b3fe35a94190ad0ae2e8ec62134819"~
61     "ab61addcccfe99d867ca3d73183fa3fd"
62 ];
63 
64 ChaCha cc = new ChaCha();
65 ubyte[] buffer = new ubyte[64];
66 char[] result;
67 for (int i = 0; i < test_keys.length; i++)
68 {
69     auto key = ByteConverter.hexDecode(test_keys[i]);
70     auto iv = ByteConverter.hexDecode(test_ivs[i]);
71 
72     // Encryption
73     cc.init(true, key, iv);
74     cc.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer);
75     result = ByteConverter.hexEncode(buffer);
76     assert(result == test_ciphertexts[i],
77             cc.name()~": ("~result~") != ("~test_ciphertexts[i]~")");           
78 
79     // Decryption
80     cc.init(false, key, iv);
81     cc.update(ByteConverter.hexDecode(test_ciphertexts[i]), buffer);
82     result = ByteConverter.hexEncode(buffer);
83     assert(result == test_plaintexts[i],
84             cc.name()~": ("~result~") != ("~test_plaintexts[i]~")");
85 }

Meta