日期:2012-07-27  浏览次数:20334 次

/*
Copyright 2002 Blood (eaststarbuy@sina.com)

This code is ported from Norbert Hranitzky's
(norbert.hranitzky@mchp.siemens.de)
Java version.
*/

//reference Namespace
using System;
using System.Text;

namespace Blood.COM.Security
{

    /// <summary>
    /// Implements the MD4 message digest algorithm in C#
    /// </summary>
    public class MD4
    {
        
        // MD4 specific object variables
        //-----------------------------------------------------------------------
    
        /// <summary>
        /// The size in bytes of the input block to the transformation algorithm
        /// </summary>
        private const int BLOCK_LENGTH = 64;        // = 512 / 8

        /// <summary>
        /// 4 32-bit words (interim result)
        /// </summary>
        private uint[] context = new uint[4];

        /// <summary>
        /// Number of bytes procesed so far mod. 2 power of 64.
        /// </summary>
        private long count;

        /// <summary>
        /// 512-bit input buffer = 16 x 32-bit words holds until it reaches 512 bits
        /// </summary>
        private byte[] buffer = new byte[BLOCK_LENGTH];

        /// <summary>
        /// 512-bit work buffer = 16 x 32-bit words
        /// </summary>
        private uint[] X = new uint[16];

    
        // Constructors
        //------------------------------------------------------------------------

        public MD4()
        {
           engineReset();
        }

        /// <summary>
        /// This constructor is here to implement the clonability of this class
        /// </summary>
        /// <param name="md"> </param>
        private MD4(MD4 md): this()
        {
            //this();
            context = (uint[])md.context.Clone();
            buffer = (byte[])md.buffer.Clone();