comparison dcrypt/crypto/modes/CTR.d @ 8:23c62e28b3a4

Reworked symmetric cipher classes to have SymmetricCipher as their superclass, and follow the general interface of init(), process(), etc. Made sure everything still passed test vectors. Removed Cipher class. I'll worry about that shit when we support something other than symmetric ciphers.
author Thomas Dixon <reikon@reikon.us>
date Mon, 18 Aug 2008 01:14:37 -0400
parents 0e08791a1418
children cd376996cdb3
comparison
equal deleted inserted replaced
7:23e6e80f8ee3 8:23c62e28b3a4
60 counterOutput = new ubyte[blockSize]; 60 counterOutput = new ubyte[blockSize];
61 61
62 initialized = true; 62 initialized = true;
63 } 63 }
64 64
65 uint processBlock(void[] input_, uint inOff, void[] output_, uint outOff) { 65 ubyte[] process(void[] input_) {
66 if (!initialized) 66 if (!initialized)
67 throw new NotInitializedError( 67 throw new NotInitializedError(
68 name()~": Block mode not initialized"); 68 name()~": Block mode not initialized");
69 69
70 ubyte[] input = cast(ubyte[]) input_; 70 ubyte[] input = cast(ubyte[]) input_;
71 ubyte[] output = cast(ubyte[]) output_;
72 71
73 // Encrypt the counter 72 // Encrypt the counter
74 m_cipher.processBlock(counter, 0, counterOutput, 0); 73 counterOutput[] = m_cipher.process(counter);
75 74
76 // XOR output with plaintext to create ciphertext 75 // XOR output with plaintext to create ciphertext
77 for (int i = 0; i < counter.length; i++) 76 for (int i = 0; i < counter.length; i++)
78 output[outOff++] = (counterOutput[i] ^ input[inOff++]); 77 counterOutput[i] ^= input[i];
79 78
80 // Increment the counter 79 // Increment the counter
81 for (int i = counter.length-1; i >= 0; i--) 80 for (int i = counter.length-1; i >= 0; i--)
82 if (++counter[i]) break; 81 if (++counter[i]) break;
83 82
84 return counter.length; 83 return counterOutput;
85 } 84 }
86 85
87 uint blockSize() { 86 uint blockSize() {
88 return m_cipher.blockSize; 87 return m_cipher.blockSize;
89 } 88 }