comparison dcrypt/crypto/ciphers/ChaCha.d @ 28:ad687db713a4

Further reworked the code for hash padding. Replaced all instances of 'char[]' with 'string' and removed a few 'const' modifiers as per Glenn Haecker's patch for D2 compatibility. Updated CONTRIBUTORS file.
author Thomas Dixon <reikon@reikon.us>
date Sun, 10 May 2009 22:38:48 -0400
parents 8b5eaf3c2979
children
comparison
equal deleted inserted replaced
27:8b5eaf3c2979 28:ad687db713a4
15 import dcrypt.misc.Bitwise; 15 import dcrypt.misc.Bitwise;
16 16
17 /** Implementation of ChaCha designed by Daniel J. Bernstein. */ 17 /** Implementation of ChaCha designed by Daniel J. Bernstein. */
18 class ChaCha : Salsa20 18 class ChaCha : Salsa20
19 { 19 {
20 char[] name() 20 string name()
21 { 21 {
22 return "ChaCha"; 22 return "ChaCha";
23 } 23 }
24 24
25 this() 25 this()
115 /** ChaCha test vectors */ 115 /** ChaCha test vectors */
116 debug (UnitTest) 116 debug (UnitTest)
117 { 117 {
118 unittest 118 unittest
119 { 119 {
120 static const char[][] test_keys = [ 120 static string[] test_keys = [
121 "80000000000000000000000000000000", 121 "80000000000000000000000000000000",
122 "0053a6f94c9ff24598eb3e91e4378add", 122 "0053a6f94c9ff24598eb3e91e4378add",
123 "00002000000000000000000000000000"~ 123 "00002000000000000000000000000000"~
124 "00000000000000000000000000000000", 124 "00000000000000000000000000000000",
125 "0f62b5085bae0154a7fa4da0f34699ec"~ 125 "0f62b5085bae0154a7fa4da0f34699ec"~
126 "3f92e5388bde3184d72a7dd02376c91c" 126 "3f92e5388bde3184d72a7dd02376c91c"
127 127
128 ]; 128 ];
129 129
130 static const char[][] test_ivs = [ 130 static string[] test_ivs = [
131 "0000000000000000", 131 "0000000000000000",
132 "0d74db42a91077de", 132 "0d74db42a91077de",
133 "0000000000000000", 133 "0000000000000000",
134 "288ff65dc42b92f9" 134 "288ff65dc42b92f9"
135 ]; 135 ];
136 136
137 static const char[][] test_plaintexts = [ 137 static string[] test_plaintexts = [
138 "00000000000000000000000000000000"~ 138 "00000000000000000000000000000000"~
139 "00000000000000000000000000000000"~ 139 "00000000000000000000000000000000"~
140 "00000000000000000000000000000000"~ 140 "00000000000000000000000000000000"~
141 "00000000000000000000000000000000", 141 "00000000000000000000000000000000",
142 142
156 "00000000000000000000000000000000" 156 "00000000000000000000000000000000"
157 157
158 158
159 ]; 159 ];
160 160
161 static const char[][] test_ciphertexts = [ 161 static string[] test_ciphertexts = [
162 "beb1e81e0f747e43ee51922b3e87fb38"~ 162 "beb1e81e0f747e43ee51922b3e87fb38"~
163 "d0163907b4ed49336032ab78b67c2457"~ 163 "d0163907b4ed49336032ab78b67c2457"~
164 "9fe28f751bd3703e51d876c017faa435"~ 164 "9fe28f751bd3703e51d876c017faa435"~
165 "89e63593e03355a7d57b2366f30047c5", 165 "89e63593e03355a7d57b2366f30047c5",
166 166
180 "ab61addcccfe99d867ca3d73183fa3fd" 180 "ab61addcccfe99d867ca3d73183fa3fd"
181 ]; 181 ];
182 182
183 ChaCha cc = new ChaCha(); 183 ChaCha cc = new ChaCha();
184 ubyte[] buffer = new ubyte[64]; 184 ubyte[] buffer = new ubyte[64];
185 char[] result; 185 string result;
186 for (int i = 0; i < test_keys.length; i++) 186 for (int i = 0; i < test_keys.length; i++)
187 { 187 {
188 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_keys[i])); 188 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_keys[i]));
189 ParametersWithIV params = new ParametersWithIV(key, ByteConverter.hexDecode(test_ivs[i])); 189 ParametersWithIV params = new ParametersWithIV(key, ByteConverter.hexDecode(test_ivs[i]));
190 190