Mercurial > projects > dcrypt
diff 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 |
line wrap: on
line diff
--- a/dcrypt/crypto/modes/CTR.d Sat Aug 16 22:55:38 2008 -0400 +++ b/dcrypt/crypto/modes/CTR.d Mon Aug 18 01:14:37 2008 -0400 @@ -62,26 +62,25 @@ initialized = true; } - uint processBlock(void[] input_, uint inOff, void[] output_, uint outOff) { + ubyte[] process(void[] input_) { if (!initialized) throw new NotInitializedError( name()~": Block mode not initialized"); ubyte[] input = cast(ubyte[]) input_; - ubyte[] output = cast(ubyte[]) output_; // Encrypt the counter - m_cipher.processBlock(counter, 0, counterOutput, 0); + counterOutput[] = m_cipher.process(counter); // XOR output with plaintext to create ciphertext for (int i = 0; i < counter.length; i++) - output[outOff++] = (counterOutput[i] ^ input[inOff++]); + counterOutput[i] ^= input[i]; // Increment the counter for (int i = counter.length-1; i >= 0; i--) if (++counter[i]) break; - return counter.length; + return counterOutput; } uint blockSize() {