Exemplo n.º 1
0
        protected override byte[] HashFinal()
        {
            byte[] buf     = null;
            int    nBufPos = 0;

            byte[] result = null;
            nBufPos      = this.nBufPos;
            buf          = this.buf;
            buf[nBufPos] = ((byte)1);
            nBufPos++;
            if (56 <= nBufPos)
            {
                Array.Clear(((Array)buf), nBufPos, ((int)(64 - nBufPos)));
                this.ProcessBlock();
                nBufPos = 0;
            }
            Array.Clear(((Array)buf), nBufPos, ((int)((64 - nBufPos) - 8)));
            TTH.LongToBytes(((long)(this.lLen << 3)), buf, 56);
            this.ProcessBlock();
            result = new byte[24];
            TTH.LongToBytes(this.a, result, 0);
            TTH.LongToBytes(this.b, result, 8);
            TTH.LongToBytes(this.c, result, 16);
            return(result);
        }
Exemplo n.º 2
0
        public static bool SelfTest()
        {
            ASCIIEncoding enc = null;

            byte[] hash      = null;
            int    nI        = 0;
            string TEST_DATA = null;

            byte[] TEST_HASH  = null;
            TTH    tg         = null;
            int    _Vb_t_i4_0 = 0;

            byte[] _Vb_t_array_0 = null;
            TEST_DATA     = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
            _Vb_t_array_0 = new byte[] { ((byte)15), ((byte)123), ((byte)249), ((byte)161), ((byte)155), ((byte)156), ((byte)88), ((byte)242), ((byte)183), ((byte)97),
                                         ((byte)13), ((byte)247), ((byte)232), ((byte)79), ((byte)10), ((byte)195), ((byte)167), ((byte)28), ((byte)99), ((byte)30),
                                         ((byte)123), ((byte)83), ((byte)247), ((byte)142) };
            TEST_HASH = _Vb_t_array_0;
            tg        = new TTH();
            tg.Initialize();
            enc  = new ASCIIEncoding();
            hash = tg.ComputeHash(enc.GetBytes(TEST_DATA));
            if (hash.Length != TEST_HASH.Length)
            {
                return(false);
            }
            _Vb_t_i4_0 = (TEST_HASH.Length - 1);
            for (nI = 0; (nI <= _Vb_t_i4_0); nI++)
            {
                if (hash[nI] != TEST_HASH[nI])
                {
                    return(false);
                }
            }
            return(true);
        }