annotate dcrypt/crypto/ciphers/Salsa20.d @ 24:6428dfd7fede

Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
author Thomas Dixon <reikon@reikon.us>
date Thu, 19 Feb 2009 14:45:13 -0500
parents
children 528676d20398
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
1 /**
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
2 * This file is part of the dcrypt project.
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
3 *
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
4 * Copyright: Copyright (C) dcrypt contributors 2009. All rights reserved.
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
5 * License: MIT
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
6 * Authors: Thomas Dixon
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
7 */
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
8
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
9 module dcrypt.crypto.ciphers.Salsa20;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
10
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
11 import dcrypt.crypto.StreamCipher;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
12 import dcrypt.crypto.params.ParametersWithIV;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
13 import dcrypt.misc.ByteConverter;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
14 import dcrypt.misc.Bitwise;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
15
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
16 /** Implementation of Salsa20 designed by Daniel J. Bernstein. */
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
17 class Salsa20 : StreamCipher {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
18 private {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
19 // Constants
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
20 final ubyte[] sigma = cast(ubyte[])"expand 32-byte k",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
21 tau = cast(ubyte[])"expand 16-byte k";
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
22
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
23 // Internal state
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
24 uint[] state;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
25
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
26 // Keystream and index marker
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
27 ubyte[] keyStream;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
28 uint index;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
29
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
30 // Internal copies of the key and IV for resetting the cipher
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
31 ubyte[] workingKey,
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
32 workingIV;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
33 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
34
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
35 this() {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
36 state = new uint[16];
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
37
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
38 // State expanded into bytes
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
39 keyStream = new ubyte[64];
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
40 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
41
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
42 void init(bool encrypt, CipherParameters params) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
43 ParametersWithIV ivParams = cast(ParametersWithIV)params;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
44
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
45 if (!ivParams)
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
46 throw new InvalidParameterError(
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
47 name()~": init parameters must include an IV. (use ParametersWithIV)");
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
48
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
49 SymmetricKey keyParams = cast(SymmetricKey)ivParams.parameters;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
50
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
51 ubyte[] iv = ivParams.iv,
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
52 key = keyParams.key;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
53
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
54 if (key) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
55 if (key.length != 16 && key.length != 32)
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
56 throw new InvalidKeyError(
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
57 name()~": Invalid key length. (requires 16 or 32 bytes)");
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
58
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
59 workingKey = key;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
60 keySetup();
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
61
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
62 index = 0;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
63 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
64
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
65 if (!workingKey)
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
66 throw new InvalidKeyError(name()~": Key not set.");
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
67
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
68 if (!iv || iv.length != 8)
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
69 throw new InvalidParameterError(name()~": 8 byte IV required.");
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
70
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
71 workingIV = iv;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
72 ivSetup();
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
73
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
74 _encrypt = _initialized = true;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
75 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
76
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
77 char[] name() {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
78 return "Salsa20";
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
79 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
80
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
81 ubyte returnByte(ubyte input) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
82 if (!_initialized)
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
83 throw new NotInitializedError(name()~": Cipher not initialized");
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
84
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
85 if (index == 0) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
86 salsa20WordToByte(state, keyStream);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
87 state[8]++;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
88 if (!state[8])
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
89 state[9]++;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
90 // As in djb's, changing the IV after 2^70 bytes is the user's responsibility
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
91 // lol glwt
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
92 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
93
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
94 ubyte result = (keyStream[index]^input);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
95 index = (index + 1) & 0x3f;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
96
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
97 return result;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
98 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
99
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
100 uint update(void[] input_, void[] output_) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
101 if (!_initialized)
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
102 throw new NotInitializedError(name()~": Cipher not initialized");
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
103
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
104 ubyte[] input = cast(ubyte[]) input_,
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
105 output = cast(ubyte[]) output_;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
106
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
107 if (input.length > output.length)
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
108 throw new ShortBufferError(name()~": Output buffer too short");
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
109
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
110 for (int i = 0; i < input.length; i++) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
111 if (index == 0) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
112 salsa20WordToByte(state, keyStream);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
113 state[8]++;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
114 if (!state[8])
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
115 state[9]++;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
116 // As in djb's, changing the IV after 2^70 bytes is the user's responsibility
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
117 // lol glwt
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
118 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
119 output[i] = (keyStream[index]^input[i]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
120 index = (index + 1) & 0x3f;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
121 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
122
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
123 return input.length;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
124 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
125
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
126 void reset() {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
127 keySetup();
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
128 ivSetup();
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
129 index = 0;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
130 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
131
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
132 private void keySetup() {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
133 uint offset;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
134 ubyte[] constants;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
135
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
136 state[1] = ByteConverter.LittleEndian.to!(uint)(workingKey[0..4]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
137 state[2] = ByteConverter.LittleEndian.to!(uint)(workingKey[4..8]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
138 state[3] = ByteConverter.LittleEndian.to!(uint)(workingKey[8..12]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
139 state[4] = ByteConverter.LittleEndian.to!(uint)(workingKey[12..16]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
140
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
141 if (workingKey.length == 32) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
142 constants = sigma;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
143 offset = 16;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
144 } else
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
145 constants = tau;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
146
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
147 state[11] = ByteConverter.LittleEndian.to!(uint)(workingKey[offset..offset+4]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
148 state[12] = ByteConverter.LittleEndian.to!(uint)(workingKey[offset+4..offset+8]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
149 state[13] = ByteConverter.LittleEndian.to!(uint)(workingKey[offset+8..offset+12]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
150 state[14] = ByteConverter.LittleEndian.to!(uint)(workingKey[offset+12..offset+16]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
151 state[ 0] = ByteConverter.LittleEndian.to!(uint)(constants[0..4]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
152 state[ 5] = ByteConverter.LittleEndian.to!(uint)(constants[4..8]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
153 state[10] = ByteConverter.LittleEndian.to!(uint)(constants[8..12]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
154 state[15] = ByteConverter.LittleEndian.to!(uint)(constants[12..16]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
155 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
156
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
157 private void ivSetup() {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
158 state[6] = ByteConverter.LittleEndian.to!(uint)(workingIV[0..4]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
159 state[7] = ByteConverter.LittleEndian.to!(uint)(workingIV[4..8]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
160 state[8] = state[9] = 0;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
161 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
162
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
163 private void salsa20WordToByte(uint[] input, ref ubyte[] output) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
164 uint[] x = new uint[16];
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
165 x[] = input;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
166
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
167 int i;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
168 for (i = 0; i < 10; i++) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
169 x[ 4] ^= Bitwise.rotateLeft(x[ 0]+x[12], 7);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
170 x[ 8] ^= Bitwise.rotateLeft(x[ 4]+x[ 0], 9);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
171 x[12] ^= Bitwise.rotateLeft(x[ 8]+x[ 4], 13);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
172 x[ 0] ^= Bitwise.rotateLeft(x[12]+x[ 8], 18);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
173 x[ 9] ^= Bitwise.rotateLeft(x[ 5]+x[ 1], 7);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
174 x[13] ^= Bitwise.rotateLeft(x[ 9]+x[ 5], 9);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
175 x[ 1] ^= Bitwise.rotateLeft(x[13]+x[ 9], 13);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
176 x[ 5] ^= Bitwise.rotateLeft(x[ 1]+x[13], 18);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
177 x[14] ^= Bitwise.rotateLeft(x[10]+x[ 6], 7);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
178 x[ 2] ^= Bitwise.rotateLeft(x[14]+x[10], 9);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
179 x[ 6] ^= Bitwise.rotateLeft(x[ 2]+x[14], 13);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
180 x[10] ^= Bitwise.rotateLeft(x[ 6]+x[ 2], 18);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
181 x[ 3] ^= Bitwise.rotateLeft(x[15]+x[11], 7);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
182 x[ 7] ^= Bitwise.rotateLeft(x[ 3]+x[15], 9);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
183 x[11] ^= Bitwise.rotateLeft(x[ 7]+x[ 3], 13);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
184 x[15] ^= Bitwise.rotateLeft(x[11]+x[ 7], 18);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
185 x[ 1] ^= Bitwise.rotateLeft(x[ 0]+x[ 3], 7);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
186 x[ 2] ^= Bitwise.rotateLeft(x[ 1]+x[ 0], 9);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
187 x[ 3] ^= Bitwise.rotateLeft(x[ 2]+x[ 1], 13);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
188 x[ 0] ^= Bitwise.rotateLeft(x[ 3]+x[ 2], 18);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
189 x[ 6] ^= Bitwise.rotateLeft(x[ 5]+x[ 4], 7);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
190 x[ 7] ^= Bitwise.rotateLeft(x[ 6]+x[ 5], 9);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
191 x[ 4] ^= Bitwise.rotateLeft(x[ 7]+x[ 6], 13);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
192 x[ 5] ^= Bitwise.rotateLeft(x[ 4]+x[ 7], 18);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
193 x[11] ^= Bitwise.rotateLeft(x[10]+x[ 9], 7);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
194 x[ 8] ^= Bitwise.rotateLeft(x[11]+x[10], 9);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
195 x[ 9] ^= Bitwise.rotateLeft(x[ 8]+x[11], 13);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
196 x[10] ^= Bitwise.rotateLeft(x[ 9]+x[ 8], 18);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
197 x[12] ^= Bitwise.rotateLeft(x[15]+x[14], 7);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
198 x[13] ^= Bitwise.rotateLeft(x[12]+x[15], 9);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
199 x[14] ^= Bitwise.rotateLeft(x[13]+x[12], 13);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
200 x[15] ^= Bitwise.rotateLeft(x[14]+x[13], 18);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
201 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
202
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
203 for (i = 0; i < 16; i++)
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
204 x[i] += input[i];
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
205
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
206 int j;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
207 for (i = j = 0; i < x.length; i++,j+=int.sizeof)
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
208 output[j..j+int.sizeof] = ByteConverter.LittleEndian.from!(uint)(x[i]);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
209 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
210
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
211 /** Salsa20 test vectors */
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
212 version (UnitTest) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
213 unittest {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
214 static const char[][] test_keys = [
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
215 "80000000000000000000000000000000",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
216 "0053a6f94c9ff24598eb3e91e4378add",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
217 "00002000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
218 "00000000000000000000000000000000",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
219 "0f62b5085bae0154a7fa4da0f34699ec"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
220 "3f92e5388bde3184d72a7dd02376c91c"
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
221
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
222 ];
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
223
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
224 static const char[][] test_ivs = [
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
225 "0000000000000000",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
226 "0d74db42a91077de",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
227 "0000000000000000",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
228 "288ff65dc42b92f9"
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
229 ];
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
230
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
231 static const char[][] test_plaintexts = [
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
232 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
233 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
234 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
235 "00000000000000000000000000000000",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
236
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
237 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
238 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
239 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
240 "00000000000000000000000000000000",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
241
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
242 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
243 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
244 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
245 "00000000000000000000000000000000",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
246
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
247 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
248 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
249 "00000000000000000000000000000000"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
250 "00000000000000000000000000000000"
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
251
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
252
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
253 ];
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
254
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
255 static const char[][] test_ciphertexts = [
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
256 "4dfa5e481da23ea09a31022050859936"~ // Expected output
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
257 "da52fcee218005164f267cb65f5cfd7f"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
258 "2b4f97e0ff16924a52df269515110a07"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
259 "f9e460bc65ef95da58f740b7d1dbb0aa",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
260
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
261 "05e1e7beb697d999656bf37c1b978806"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
262 "735d0b903a6007bd329927efbe1b0e2a"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
263 "8137c1ae291493aa83a821755bee0b06"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
264 "cd14855a67e46703ebf8f3114b584cba",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
265
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
266 "c29ba0da9ebebfacdebbdd1d16e5f598"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
267 "7e1cb12e9083d437eaaaa4ba0cdc909e"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
268 "53d052ac387d86acda8d956ba9e6f654"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
269 "3065f6912a7df710b4b57f27809bafe3",
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
270
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
271 "5e5e71f90199340304abb22a37b6625b"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
272 "f883fb89ce3b21f54a10b81066ef87da"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
273 "30b77699aa7379da595c77dd59542da2"~
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
274 "08e5954f89e40eb7aa80a84a6176663f"
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
275 ];
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
276
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
277 Salsa20 s20 = new Salsa20();
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
278 ubyte[] buffer = new ubyte[64];
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
279 char[] result;
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
280 for (int i = 0; i < test_keys.length; i++) {
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
281 SymmetricKey key = new SymmetricKey(ByteConverter.hexDecode(test_keys[i]));
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
282 ParametersWithIV params = new ParametersWithIV(key, ByteConverter.hexDecode(test_ivs[i]));
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
283
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
284 // Encryption
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
285 s20.init(true, params);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
286 s20.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
287 result = ByteConverter.hexEncode(buffer);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
288 assert(result == test_ciphertexts[i],
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
289 s20.name()~": ("~result~") != ("~test_ciphertexts[i]~")");
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
290
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
291 // Decryption
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
292 s20.init(false, params);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
293 s20.update(ByteConverter.hexDecode(test_ciphertexts[i]), buffer);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
294 result = ByteConverter.hexEncode(buffer);
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
295 assert(result == test_plaintexts[i],
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
296 s20.name()~": ("~result~") != ("~test_plaintexts[i]~")");
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
297 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
298 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
299 }
6428dfd7fede Implemented Salsa20. Added some error checking to RC4's returnByte. Fixed copyright year in Bitwise.d and ByteConverter.d. Added Robert Smith to contributors file. Thanks buddy :)
Thomas Dixon <reikon@reikon.us>
parents:
diff changeset
300 }