Implements the Tiger hash. (http://www.cs.technion.ac.il/~biham/Reports/Tiger/) Ported (and cleaned&sped up) from the Tiger.NET VB code. (http://www.hotpixel.net/software.html)
Наследование: System.Security.Cryptography.HashAlgorithm
Пример #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;
        }
        private void btnDefaultNodeLocatorDefaultHasing_Click(object sender, EventArgs e)
        {
            Initialise();
            DefaultNodeLocatorDefaultHasingIndex();

            Debug.WriteLine("Finished building index");

            foreach (IPEndPoint key in _nodes)
            {
                if (!_defaultLocatorKeyDistirbution.ContainsKey(key))
                {
                    _defaultLocatorKeyDistirbution.Add(key, new KeyCount());
                }
                else
                {
                    _defaultLocatorKeyDistirbution[key] = new KeyCount();
                }

            }

            Debug.WriteLine("Finished count reset");

            Debug.WriteLine("Starting test for 10000 random rawproductId key distirbution");

            for (int i = 0; i < 10000; i++)
            {
                string key = CreateKey(Guid.NewGuid());

                //Default Key
                IPEndPoint defaultNodeEndPoint = FindNodeDefault(key);

                KeyCount currentKeyCount = _defaultLocatorKeyDistirbution[defaultNodeEndPoint];
                currentKeyCount.Default = currentKeyCount.Default + 1;
                _defaultLocatorKeyDistirbution[defaultNodeEndPoint] = currentKeyCount;

                //base64key

                string base64Key = Convert.ToBase64String(Encoding.UTF8.GetBytes(key), Base64FormattingOptions.None);
                IPEndPoint base64EndPoint = FindNodeDefault(base64Key);

                KeyCount base64KeyCount = _defaultLocatorKeyDistirbution[base64EndPoint];
                base64KeyCount.Base64 = base64KeyCount.Base64 + 1;
                _defaultLocatorKeyDistirbution[base64EndPoint] = base64KeyCount;

                //sha1
                SHA1Managed sh = new SHA1Managed();
                byte[] data = sh.ComputeHash(Encoding.Unicode.GetBytes(key));

                IPEndPoint sha1EndPoint = FindNodeDefault(Convert.ToBase64String(data, Base64FormattingOptions.None));

                KeyCount sha1KeyCount = _defaultLocatorKeyDistirbution[sha1EndPoint];
                sha1KeyCount.Sha1 = sha1KeyCount.Sha1 + 1;
                _defaultLocatorKeyDistirbution[sha1EndPoint] = sha1KeyCount;

                //Tiger Hash
                TigerHash th = new TigerHash();
                byte[] tigerData = th.ComputeHash(Encoding.Unicode.GetBytes(key));

                IPEndPoint tigerEndPoint = FindNodeDefault(Convert.ToBase64String(tigerData, Base64FormattingOptions.None));

                KeyCount tigerHashKeyCount = _defaultLocatorKeyDistirbution[tigerEndPoint];
                tigerHashKeyCount.TigerHash = tigerHashKeyCount.TigerHash + 1;
                _defaultLocatorKeyDistirbution[tigerEndPoint] = tigerHashKeyCount;
            }

            Debug.WriteLine("Finished 10000 items test");

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("***Default Node Locator Tests****");

            sb.AppendLine(GetDefaultKeyResultString(_defaultLocatorKeyDistirbution));
            sb.AppendLine("*******************");
            sb.AppendLine(GetBase64ResultString(_defaultLocatorKeyDistirbution));
            sb.AppendLine("*******************");
            sb.AppendLine(GetSha1ResultString(_defaultLocatorKeyDistirbution));
            sb.AppendLine("*******************");
            sb.AppendLine(GetTigerHasResultString(_defaultLocatorKeyDistirbution));

            txtResults.Clear();

            txtResults.Text = sb.ToString();

            Debug.WriteLine("DONE");
        }