view dcrypt/crypto/Cipher.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 dcrypt/crypto/SymmetricCipher.d@23c62e28b3a4
children 8c7f8fecdd75
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;
    
    /**
     * 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();
}