XTEA.update

Undocumented in source. Be warned that the author may not have intended to support it.

Examples

Some XTEA test vectors.

1 __gshared immutable immutable(char)[][] test_keys = [
2     "00000000000000000000000000000000",
3     "00000000000000000000000000000000",
4     "0123456712345678234567893456789a",
5     "0123456712345678234567893456789a",
6     "00000000000000000000000000000001",
7     "01010101010101010101010101010101",
8     "0123456789abcdef0123456789abcdef",
9     "0123456789abcdef0123456789abcdef",
10     "00000000000000000000000000000000",
11     "00000000000000000000000000000000"
12 ];
13 
14 __gshared immutable immutable(char)[][] test_plaintexts = [
15     "0000000000000000",
16     "0102030405060708",
17     "0000000000000000",
18     "0102030405060708",
19     "0000000000000001",
20     "0101010101010101",
21     "0123456789abcdef",
22     "0000000000000000",
23     "0123456789abcdef",
24     "4141414141414141"
25 ];
26 
27 __gshared immutable immutable(char)[][] test_ciphertexts = [
28     "dee9d4d8f7131ed9",
29     "065c1b8975c6a816",
30     "1ff9a0261ac64264",
31     "8c67155b2ef91ead",
32     "9f25fa5b0f86b758",
33     "c2eca7cec9b7f992",
34     "27e795e076b2b537",
35     "5c8eddc60a95b3e1",
36     "7e66c71c88897221",
37     "ed23375a821a8c2d"
38 ];
39 
40 XTEA t = new XTEA();
41 foreach (uint i, immutable(char)[] test_key; test_keys)
42 {
43     ubyte[] buffer = new ubyte[t.blockSize];
44     char[] result;
45     auto key = ByteConverter.hexDecode(test_key);
46 
47     // Encryption
48     t.init(true, key);
49     t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer);
50     result = ByteConverter.hexEncode(buffer);
51     assert(result == test_ciphertexts[i],
52             t.name~": ("~result~") != ("~test_ciphertexts[i]~")");
53 
54     // Decryption
55     t.init(false, key);
56     t.update(ByteConverter.hexDecode(test_ciphertexts[i]), buffer);
57     result = ByteConverter.hexEncode(buffer);
58     assert(result == test_plaintexts[i],
59             t.name~": ("~result~") != ("~test_plaintexts[i]~")");
60 }

Meta