Example #1
0
        private byte[] LeafHash(byte[] Raw_Data) //leaf hash.
        {
            byte[] Data = new byte[Raw_Data.Length + 1];

            Data[0] = 0x00; //leaf hash mark.
            Raw_Data.CopyTo(Data, 1);

            //gets tiger hash value for leafs blocks.
            Tiger TG = new Tiger();

            TG.Initialize();
            return(TG.ComputeHash(Data));
        }
Example #2
0
        void ProcessInternalLeaf(int Level, int Index, byte[] LeafA, byte[] LeafB)
        {
            Tiger TG = new Tiger();

            byte[] Data = new byte[LeafA.Length + LeafB.Length + 1];

            Data[0] = InternalHash;

            Buffer.BlockCopy(LeafA, 0, Data, 1, LeafA.Length);
            Buffer.BlockCopy(LeafB, 0, Data, LeafA.Length + 1, LeafA.Length);

            TG.Initialize();
            TTH[Level][Index] = TG.ComputeHash(Data);
        }
Example #3
0
        private byte[] InternalHash(byte[] LeafA, byte[] LeafB) //internal hash.
        {
            byte[] Data = new byte[LeafA.Length + LeafB.Length + 1];

            Data[0] = 0x01; //internal hash mark.

            //combines two leafs.
            LeafA.CopyTo(Data, 1);
            LeafB.CopyTo(Data, LeafA.Length + 1);

            //gets tiger hash value for combined leaf hash.
            Tiger TG = new Tiger();

            TG.Initialize();
            return(TG.ComputeHash(Data));
        }
Example #4
0
        public static bool SelfTest()
        {
            ASCIIEncoding enc = null;

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

            byte[] TEST_HASH  = null;
            Tiger  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 Tiger();
            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);
        }
Example #5
0
        void StartThreads()
        {
            for (int i = 0; i < ThreadCount; i++)
            {
                ThreadsList[i]              = new Thread(new ThreadStart(ProcessLeafs));
                ThreadsList[i].Priority     = threadPriority;
                ThreadsList[i].IsBackground = true;
                ThreadsList[i].Name         = i.ToString();
#if !COMPACT_FRAMEWORK
                ThreadsList[i].Start();
#else
                ThreadsList[i].Start(true);
#endif
            }

            bool ThreadsAreWorking = false;

            do
            {
                // FLOW84 : START
                //Thread.Sleep(1000);
                Thread.Sleep(100);
                // FLOW84 : END
                ThreadsAreWorking = false;

                for (int i = 0; i < ThreadCount; i++)
#if !COMPACT_FRAMEWORK
                { if (ThreadsList[i].IsAlive)
#else
                { if (ThreadsList[i].IsAlive())
#endif
                  { ThreadsAreWorking = true; } }
            } while (ThreadsAreWorking);
        }

        void StopThreads()
        {
            for (int i = 0; i < ThreadCount; i++)
#if !COMPACT_FRAMEWORK
            { if (ThreadsList[i] != null && ThreadsList[i].IsAlive)
#else
                if (ThreadsList[i] != null && ThreadsList[i].IsAlive())
#endif
              { ThreadsList[i].Abort(); } }
        }

        void ProcessLeafs()
        {
            try
            {
                FileStream ThreadFilePtr   = new FileStream(Filename, FileMode.Open, FileAccess.Read);
                FileBlock  ThreadFileBlock = FileParts[System.Convert.ToInt16(Thread.CurrentThread.Name)];
                Tiger      TG = new Tiger();
                byte[]     DataBlock;
                byte[]     Data = new byte[LeafSize + 1];
                long       LeafIndex;
                int        BlockLeafs;
                int        i;

                ThreadFilePtr.Position = ThreadFileBlock.Start;

                while (ThreadFilePtr.Position < ThreadFileBlock.End)
                {
                    LeafIndex = (long)ThreadFilePtr.Position / 1024;

                    if (ThreadFileBlock.End - ThreadFilePtr.Position < DataBlockSize)
                    {
                        DataBlock = new byte[ThreadFileBlock.End - ThreadFilePtr.Position];
                    }
                    else
                    {
                        DataBlock = new byte[DataBlockSize];
                    }

                    ThreadFilePtr.Read(DataBlock, 0, DataBlock.Length); //read block

                    BlockLeafs = DataBlock.Length / 1024;

                    for (i = 0; i < BlockLeafs; i++)
                    {
                        Buffer.BlockCopy(DataBlock, i * LeafSize, Data, 1, LeafSize);

                        TG.Initialize();
                        TTH[0][LeafIndex++] = TG.ComputeHash(Data);
                    }

                    if (i * LeafSize < DataBlock.Length)
                    {
                        Data    = new byte[DataBlock.Length - BlockLeafs * LeafSize + 1];
                        Data[0] = LeafHash;

                        Buffer.BlockCopy(DataBlock, BlockLeafs * LeafSize, Data, 1, (Data.Length - 1));

                        TG.Initialize();
                        TTH[0][LeafIndex++] = TG.ComputeHash(Data);

                        Data    = new byte[LeafSize + 1];
                        Data[0] = LeafHash;
                    }
                }

                DataBlock = null;
                Data      = null;
            }
            catch (ThreadAbortException) { }
            finally
            {
                // We remove the object to indicate that we are finished
#if COMPACT_FRAMEWORK
                Thread.CurrentThread.GetData();
#endif
            }
        }

        void CompressTree()
        {
            int InternalLeafCount;
            int Level = 0, i, LeafIndex;

            while (Level + 1 < LevelCount)
            {
                LeafIndex         = 0;
                InternalLeafCount = (LeafCount / 2) + (LeafCount % 2);
                TTH[Level + 1]    = new byte[InternalLeafCount][];

                for (i = 1; i < LeafCount; i += 2)
                    ProcessInternalLeaf(Level + 1, LeafIndex++, TTH[Level][i - 1], TTH[Level][i]); }

                if (LeafIndex < InternalLeafCount)
                {
                    TTH[Level + 1][LeafIndex] = TTH[Level][LeafCount - 1];
                }

                Level++;
                LeafCount = InternalLeafCount;
            }
        }
Example #6
0
        //leaf hash.
        private byte[] LH(byte[] Raw_Data)
        {
            byte[] Data = new byte[Raw_Data.Length + 1];

            Data[0] = 0x00; //leaf hash mark.
            Raw_Data.CopyTo(Data, 1);

            //gets tiger hash value for leafs blocks.
            Tiger TG = new Tiger();
            TG.Initialize();
            return TG.ComputeHash(Data);
        }
Example #7
0
        //internal hash.
        private byte[] IH(byte[] LeafA, byte[] LeafB)
        {
            byte[] Data = new byte[LeafA.Length + LeafB.Length + 1];

            Data[0] = 0x01; //internal hash mark.

            //combines two leafs.
            LeafA.CopyTo(Data, 1);
            LeafB.CopyTo(Data, LeafA.Length + 1);

            //gets tiger hash value for combined leaf hash.
            Tiger TG = new Tiger();
            TG.Initialize();
            return TG.ComputeHash(Data);
        }
Example #8
0
        void ProcessLeafs()
        {
            try
            {
                FileStream ThreadFilePtr = new FileStream(Filename, FileMode.Open, FileAccess.Read);
                FileBlock ThreadFileBlock = FileParts[System.Convert.ToInt16(Thread.CurrentThread.Name)];
                Tiger TG = new Tiger();
                byte[] DataBlock;
                byte[] Data = new byte[LeafSize + 1];
                long LeafIndex;
                int BlockLeafs;
                int i;

                ThreadFilePtr.Position = ThreadFileBlock.Start;

                while (ThreadFilePtr.Position < ThreadFileBlock.End)
                {
                    LeafIndex = (long)ThreadFilePtr.Position / 1024;

                    if (ThreadFileBlock.End - ThreadFilePtr.Position < DataBlockSize)
                        DataBlock = new byte[ThreadFileBlock.End - ThreadFilePtr.Position];
                    else
                        DataBlock = new byte[DataBlockSize];

                    ThreadFilePtr.Read(DataBlock, 0, DataBlock.Length); //read block

                    BlockLeafs = DataBlock.Length / 1024;

                    for (i = 0; i < BlockLeafs; i++)
                    {
                        Buffer.BlockCopy(DataBlock, i * LeafSize, Data, 1, LeafSize);

                        TG.Initialize();
                        TTH[0][LeafIndex++] = TG.ComputeHash(Data);
                    }

                    if (i * LeafSize < DataBlock.Length)
                    {
                        Data = new byte[DataBlock.Length - BlockLeafs * LeafSize + 1];
                        Data[0] = LeafHash;

                        Buffer.BlockCopy(DataBlock, BlockLeafs * LeafSize, Data, 1, (Data.Length - 1));

                        TG.Initialize();
                        TTH[0][LeafIndex++] = TG.ComputeHash(Data);

                        Data = new byte[LeafSize + 1];
                        Data[0] = LeafHash;
                    }
                }

                DataBlock = null;
                Data = null;
            }
            catch (ThreadAbortException) { }
            finally
            {
                // We remove the object to indicate that we are finished
            #if COMPACT_FRAMEWORK
                Thread.CurrentThread.GetData();
            #endif
            }
        }
Example #9
0
        void ProcessInternalLeaf(int Level, int Index, byte[] LeafA, byte[] LeafB)
        {
            Tiger TG = new Tiger();
            byte[] Data = new byte[LeafA.Length + LeafB.Length + 1];

            Data[0] = InternalHash;

            Buffer.BlockCopy(LeafA, 0, Data, 1, LeafA.Length);
            Buffer.BlockCopy(LeafB, 0, Data, LeafA.Length + 1, LeafA.Length);

            TG.Initialize();
            TTH[Level][Index] = TG.ComputeHash(Data);
        }
Example #10
0
 public static bool SelfTest()
 {
     ASCIIEncoding enc = null;
     byte[] hash = null;
     int nI = 0;
     string TEST_DATA = null;
     byte[] TEST_HASH = null;
     Tiger 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 Tiger();
     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;
 }