view dcrypt/crypto/Cipher.d @ 32:2b4bccdc8387

Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[].
author Thomas Dixon <reikon@reikon.us>
date Tue, 12 May 2009 22:09:33 -0400
parents ad687db713a4
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.Cipher;

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 Cipher
{
    static const bool ENCRYPT = true,
                      DECRYPT = false;
                      
    protected bool _initialized,
                   _encrypt;
    
    /**
     * 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 place it in the output array.
     *
     * Params:
     *     input_  = Array containing input data.
     *     output_  = Array to hold the output data.
     *
     * Returns: The amount of encrypted data processed.
     */
    uint update(void[] input_, void[] output_);
    
    /** Play nice with D2's idea of const. */
    version (D_Version2)
    {
        uint update(string input_, void[] output_)
        {
            return update(cast(ubyte[])input_, output_);
        }
    }
    
    /** Returns: The name of the algorithm of this cipher. */
    string name();
    
    /** Returns: Whether or not the cipher has been initialized. */
    bool initialized()
    {
        return _initialized;
    }
    
    /** Reset cipher to its state immediately subsequent the last init. */
    void reset();
}