comparison dcrypt/crypto/modes/CTR.d @ 10:cd376996cdb3

Renamed SymmetricCipher back to Cipher (we don't support any other kind atm, I'll deal with it when we do.). Added BlockCipherWrapper for the encryption of arbitrary streams with or without padding. Removed hashByName, and replaced it with createHash. Re-did the high-level API, and filled out Crypto. Added cipher creation via createCipher. Added dsk to the CONTRIBUTORS file for helping with the design of the high-level API.
author Thomas Dixon <reikon@reikon.us>
date Wed, 20 Aug 2008 20:08:07 -0400
parents 23c62e28b3a4
children 8c7f8fecdd75
comparison
equal deleted inserted replaced
9:29b910949588 10:cd376996cdb3
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 uint len = (counter.length > input.length) ? input.length : counter.length;
71 72
72 // Encrypt the counter 73 // Encrypt the counter
73 counterOutput[] = m_cipher.process(counter); 74 counterOutput[] = m_cipher.process(counter);
74 75
75 // XOR output with plaintext to create ciphertext 76 // XOR output with plaintext to create ciphertext
76 for (int i = 0; i < counter.length; i++) 77 for (int i = 0; i < len; i++)
77 counterOutput[i] ^= input[i]; 78 counterOutput[i] ^= input[i];
78 79
79 // Increment the counter 80 // Increment the counter
80 for (int i = counter.length-1; i >= 0; i--) 81 for (int i = counter.length-1; i >= 0; i--)
81 if (++counter[i]) break; 82 if (++counter[i]) break;
82 83
83 return counterOutput; 84 return counterOutput[0..len];
84 } 85 }
85 86
86 uint blockSize() { 87 uint blockSize() {
87 return m_cipher.blockSize; 88 return m_cipher.blockSize;
88 } 89 }