Exemplo n.º 1
0
        public Ed2k()
        {
            md4HashBlocks = new List <byte[]>();
            md4           = new Md4();

            nullMd4Hash = md4.ComputeHash(nullArray);
            md4.Initialize();
        }
Exemplo n.º 2
0
        public Ed2k()
        {
            md4HashBlocks = new List<byte[]>();
            md4 = new Md4();

            nullMd4Hash = md4.ComputeHash(nullArray);
            md4.Initialize();
        }
Exemplo n.º 3
0
        /// <summary>Calculates both ed2k hashes</summary>
        /// <returns>Always returns the red hash</returns>
        protected override byte[] HashFinal()
        {
            blueIsRed = false;
            redHash   = null;
            blueHash  = null;

            if (md4HashBlocks.Count == 0)
            {
                md4.TransformFinalBlock(nullArray, 0, 0);
                blueHash = md4.Hash;
            }
            else if (md4HashBlocks.Count == 1 && missing == BLOCKSIZE)
            {
                blueHash = md4HashBlocks[0];

                md4.TransformBlock(md4HashBlocks[0], 0, 16, null, 0);
                md4.TransformFinalBlock(md4.ComputeHash(nullArray), 0, 16);
                redHash = md4.Hash;
            }
            else
            {
                if (missing != BLOCKSIZE)
                {
                    md4.TransformFinalBlock(nullArray, 0, 0);
                    md4HashBlocks.Add(md4.Hash);
                }

                md4.Initialize();
                foreach (var md4HashBlock in md4HashBlocks)
                {
                    md4.TransformBlock(md4HashBlock, 0, 16, null, 0);
                }
                var state = md4.GetState();

                md4.TransformFinalBlock(nullArray, 0, 0);
                blueHash = md4.Hash;

                if (missing == BLOCKSIZE)
                {
                    md4.Initialize(state);
                    md4.TransformFinalBlock(nullMd4Hash, 0, 16);
                    redHash = md4.Hash;
                }
            }

            if (redHash == null)
            {
                blueIsRed = true;
            }
            return(redHash == null ? blueHash : redHash);
        }