view 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
line wrap: on
line source

/**
 * This file is part of the dcrypt project.
 *
 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved.
 * License:   MIT
 * Authors:   Thomas Dixon
 */

module dcrypt.crypto.SymmetricCipher;

public import dcrypt.crypto.errors.InvalidKeyError;
public import dcrypt.crypto.errors.ShortBufferError;
public import dcrypt.crypto.errors.NotInitializedError;
public import dcrypt.crypto.errors.InvalidParameterError;

public import dcrypt.crypto.params.CipherParameters;

/** Base symmetric cipher class */
abstract class SymmetricCipher {
    static const bool ENCRYPT = true,
                      DECRYPT = false;
    
    /**
     * Initialize a cipher.
     * 
     * Params:
     *     encrypt = True if we are encrypting.
     *     params  = Parameters to be passed to the cipher. (Key, rounds, etc.)
     */
    void init(bool encrypt, CipherParameters params);
    
    /**
     * Process a block of plaintext data from the input array
     * and return the encrypted data.
     *
     * Params:
     *     input_  = Array containing input data.
     *
     * Returns: The encrypted data.
     */
    ubyte[] process(void[] input_);
    
    /** Returns: The name of the algorithm of this cipher. */
    char[] name();
    
    /** Reset cipher to its state immediately subsequent the last init. */
    void reset();
}