comparison dcrypt/crypto/SymmetricCipher.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
comparison
equal deleted inserted replaced
7:23e6e80f8ee3 8:23c62e28b3a4
6 * Authors: Thomas Dixon 6 * Authors: Thomas Dixon
7 */ 7 */
8 8
9 module dcrypt.crypto.SymmetricCipher; 9 module dcrypt.crypto.SymmetricCipher;
10 10
11 import dcrypt.crypto.Cipher; 11 public import dcrypt.crypto.errors.InvalidKeyError;
12 import dcrypt.crypto.params.CipherParameters; 12 public import dcrypt.crypto.errors.ShortBufferError;
13 public import dcrypt.crypto.errors.NotInitializedError;
14 public import dcrypt.crypto.errors.InvalidParameterError;
13 15
14 /** Unified cipher class for high-level API. */ 16 public import dcrypt.crypto.params.CipherParameters;
15 interface SymmetricCipher : Cipher { 17
16 /** 18 /** Base symmetric cipher class */
17 * Pass bytes through the cipher object. 19 abstract class SymmetricCipher {
20 static const bool ENCRYPT = true,
21 DECRYPT = false;
22
23 /**
24 * Initialize a cipher.
18 * 25 *
19 * Params: 26 * Params:
27 * encrypt = True if we are encrypting.
28 * params = Parameters to be passed to the cipher. (Key, rounds, etc.)
29 */
30 void init(bool encrypt, CipherParameters params);
31
32 /**
33 * Process a block of plaintext data from the input array
34 * and return the encrypted data.
35 *
36 * Params:
20 * input_ = Array containing input data. 37 * input_ = Array containing input data.
21 * inOff = Offset at where the data in input_ starts.
22 * len = Length of input_ to process.
23 * output_ = Array which will hold the output data.
24 * outOff = Offset at which to begin placing data in output_.
25 * 38 *
26 * Returns: The amount of bytes processed. 39 * Returns: The encrypted data.
27 */ 40 */
28 uint update(void[] input_, uint inOff, uint len, void[] output_, uint outOff); 41 ubyte[] process(void[] input_);
29 42
30 /** Finalize and output the rest of the buffer. */ 43 /** Returns: The name of the algorithm of this cipher. */
31 uint finish(void[] output_, uint outOff); 44 char[] name();
45
46 /** Reset cipher to its state immediately subsequent the last init. */
47 void reset();
32 } 48 }