Пример #1
0
        public override IHash Clone()
        {
            Blake2SP HashInstance = new Blake2SP(HashSize);

            HashInstance.Key = Key.DeepCopy();

            HashInstance.RootHash = (Blake2S)RootHash?.Clone();

            if (LeafHashes != null)
            {
                HashInstance.LeafHashes = new Blake2S[LeafHashes.Length];
                for (Int32 i = 0; i < LeafHashes.Length; i++)
                {
                    HashInstance.LeafHashes[i] = (Blake2S)LeafHashes[i].Clone();
                }
            }

            HashInstance.Buffer = Buffer.DeepCopy();

            HashInstance.BufferLength = BufferLength;

            HashInstance.BufferSize = BufferSize;

            return(HashInstance);
        }
Пример #2
0
        public override unsafe void Initialize()
        {
            RootHash.Initialize();
            for (Int32 i = 0; i < ParallelismDegree; i++)
            {
                LeafHashes[i].Initialize();
                LeafHashes[i].HashSize = OutSizeInBytes;
            }

            ArrayUtils.ZeroFill(ref Buffer);
            BufferLength = 0;
        }
Пример #3
0
        /// <summary>
        /// 将当前的地址信息组合成URL地址
        /// </summary>
        /// <returns></returns>
        protected override void GenerateUrl(StringBuilder sb)
        {
            base.GenerateUrl(sb);

            var list = new List <string>(10)
            {
                "", TypeString
            };

            if (UrlType == LinkType.File)
            {
                list.Add(FileName);
                list.Add(Size.ToString());
                list.Add(FileHash);

                if (!RootHash.IsNullOrEmpty())
                {
                    list.Add("h=" + RootHash);
                }
                if (HashSet.Count > 0)
                {
                    list.Add("p=" + string.Join(":", HashSet.ToArray()));
                }
                if (WebSources.Count > 0)
                {
                    WebSources.ForEach(s => list.Add("s=" + s));
                }
                if (Sources.Count > 0)
                {
                    list.Add("/");
                    list.Add("sources," + string.Join(",", Sources.Select(s => s.Host + ":" + s.Port).ToArray()));
                }
            }
            else if (UrlType == LinkType.NodesList || UrlType == LinkType.ServerList)
            {
                list.Add(SourceUrl);
            }
            else if (UrlType == LinkType.Server)
            {
                var host = ServerAddress;
                list.Add(host.Host);
                list.Add(host.Port.ToString());
            }

            sb.Append(string.Join("|", list.ToArray()));
            sb.Append("/");
        }
Пример #4
0
        public override unsafe IHashResult TransformFinal()
        {
            Int32  i;
            UInt64 left;

            byte[][] hash = new byte[ParallelismDegree][];

            for (i = 0; i < hash.Length; i++)
            {
                hash[i] = new byte[OutSizeInBytes];
            }

            for (i = 0; i < ParallelismDegree; i++)
            {
                if (BufferLength > (UInt64)(i * BlockSizeInBytes))
                {
                    left = BufferLength - (UInt64)(i * BlockSizeInBytes);
                    if (left > (UInt64)BlockSizeInBytes)
                    {
                        left = (UInt64)BlockSizeInBytes;
                    }

                    LeafHashes[i].TransformBytes(Buffer, i * BlockSizeInBytes, (Int32)left);
                }

                hash[i] = LeafHashes[i].TransformFinal().GetBytes();
            }

            for (i = 0; i < ParallelismDegree; i++)
            {
                RootHash.TransformBytes(hash[i], 0, OutSizeInBytes);
            }

            IHashResult result = RootHash.TransformFinal();

            Initialize();

            return(result);
        }