Mercurial > projects > dcrypt
diff dcrypt/crypto/modes/CTR.d @ 27:8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Sat, 09 May 2009 23:29:20 -0400 |
parents | 4589f8c5eb3c |
children | ad687db713a4 |
line wrap: on
line diff
--- a/dcrypt/crypto/modes/CTR.d Sun Mar 01 13:06:48 2009 -0500 +++ b/dcrypt/crypto/modes/CTR.d Sat May 09 23:29:20 2009 -0400 @@ -14,27 +14,34 @@ /** This class implements the counter (CTR/SIC/ICM) block mode, treating the counter as a big endian integer. */ -class CTR : BlockCipher { - private BlockCipher wrappedCipher; - private ubyte[] iv, - counter, - counterOutput; - private bool initialized = false; +class CTR : BlockCipher +{ + private + { + BlockCipher wrappedCipher; + + ubyte[] iv, + counter, + counterOutput; + } /** * Params: * cipher = Block cipher to wrap. */ - this (BlockCipher cipher) { + this (BlockCipher cipher) + { wrappedCipher = cipher; } /** Returns: The underlying cipher we are wrapping. */ - BlockCipher cipher() { + BlockCipher cipher() + { return wrappedCipher; } - char[] name() { + char[] name() + { return wrappedCipher.name~"/CTR"; } @@ -42,7 +49,8 @@ * Throws: dcrypt.crypto.errors.InvalidParameterError if params aren't * an instance of dcrypt.crypto.params.ParametersWithIV. */ - void init(bool encrypt, CipherParameters params) { + void init(bool encrypt, CipherParameters params) + { ParametersWithIV ivParams = cast(ParametersWithIV)params; if (!ivParams) @@ -59,13 +67,13 @@ counter[] = iv; counterOutput = new ubyte[blockSize]; - initialized = true; + _initialized = _encrypt = true; } - uint update(void[] input_, void[] output_) { - if (!initialized) - throw new NotInitializedError( - name()~": Block mode not initialized"); + uint update(void[] input_, void[] output_) + { + if (!_initialized) + throw new NotInitializedError(name()~": Block mode not initialized"); ubyte[] input = cast(ubyte[]) input_, output = cast(ubyte[]) output_; @@ -91,11 +99,13 @@ return len; } - uint blockSize() { + uint blockSize() + { return wrappedCipher.blockSize; } - void reset() { + void reset() + { counter[] = iv; wrappedCipher.reset(); }