예제 #1
0
        /// <summary>
        /// Returns the computed <see cref="T:TigerHash" /> hash value after all data has been written to the object.
        /// </summary>
        /// <returns>The computed hash code.</returns>
        protected override byte[] HashFinal()
        {
            int bufferOffset = this.bufferPosition;

            byte[] buffer = this.internalDataBuffer;

            buffer[bufferOffset] = 1;
            bufferOffset        += 1;

            if ((BLOCKSIZE - 8) <= bufferOffset)
            {
                Array.Clear(buffer, bufferOffset, BLOCKSIZE - bufferOffset);

                this.ProcessBlock();
                bufferOffset = 0;
            }

            Array.Clear(buffer, bufferOffset, BLOCKSIZE - bufferOffset - 8);

            TigerHash.LongToBytes(((ulong)this.totalLength) << 3, buffer, BLOCKSIZE - 8);

            this.ProcessBlock();

            byte[] retval = new byte[24];

            TigerHash.LongToBytes(this.a, retval, 0);
            TigerHash.LongToBytes(this.b, retval, 8);
            TigerHash.LongToBytes(this.c, retval, 16);

            return(retval);
        }
예제 #2
0
        private void Compress()
        {
            ulong aa, bb, cc;

            ulong[] tmpBlock;

            aa = this.a;
            bb = this.b;
            cc = this.c;

            tmpBlock = this.block;

            this.RoundABC(tmpBlock[0], 5);
            this.RoundBCA(tmpBlock[1], 5);
            this.RoundCAB(tmpBlock[2], 5);
            this.RoundABC(tmpBlock[3], 5);
            this.RoundBCA(tmpBlock[4], 5);
            this.RoundCAB(tmpBlock[5], 5);
            this.RoundABC(tmpBlock[6], 5);
            this.RoundBCA(tmpBlock[7], 5);

            TigerHash.Schedule(tmpBlock);

            this.RoundCAB(tmpBlock[0], 7);
            this.RoundABC(tmpBlock[1], 7);
            this.RoundBCA(tmpBlock[2], 7);
            this.RoundCAB(tmpBlock[3], 7);
            this.RoundABC(tmpBlock[4], 7);
            this.RoundBCA(tmpBlock[5], 7);
            this.RoundCAB(tmpBlock[6], 7);
            this.RoundABC(tmpBlock[7], 7);

            TigerHash.Schedule(tmpBlock);

            this.RoundBCA(tmpBlock[0], 9);
            this.RoundCAB(tmpBlock[1], 9);
            this.RoundABC(tmpBlock[2], 9);
            this.RoundBCA(tmpBlock[3], 9);
            this.RoundCAB(tmpBlock[4], 9);
            this.RoundABC(tmpBlock[5], 9);
            this.RoundBCA(tmpBlock[6], 9);
            this.RoundCAB(tmpBlock[7], 9);

            this.a  = this.a ^ aa;
            this.b -= bb;
            this.c += cc;
        }