Esempio n. 1
0
        public static string GetHashSha1(string inputString)
        {
            var sb        = new StringBuilder();
            var alghoritm = new Sha1();

            foreach (var b in alghoritm.Hash(Encoding.UTF8.GetBytes(inputString)))
            {
                sb.Append(b.ToString("X2"));
            }
            return(sb.ToString());
        }
Esempio n. 2
0
 /// <inheritdoc/>
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (Sha1 != null ? Sha1.GetHashCode() : 0);
         result = (result * 397) ^ (Sha1New != null ? Sha1New.GetHashCode() : 0);
         result = (result * 397) ^ (Sha256 != null ? Sha256.GetHashCode() : 0);
         result = (result * 397) ^ (Sha256New != null ? Sha256New.GetHashCode() : 0);
         return(result);
     }
 }
Esempio n. 3
0
        public static Sha1Wire Convert(this Sha1 model)
        {
            var wire = new Sha1Wire
            {
                Blit0 = model.Blit0,
                Blit1 = model.Blit1,
                Blit2 = model.Blit2
            };

            return(wire);
        }
Esempio n. 4
0
        public void RunBasicScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));

            var result = Sha1.FixedRotate(
                Unsafe.Read <Vector64 <UInt32> >(_dataTable.inArray1Ptr)
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.outArrayPtr);
        }
        public void RunLclVarScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));

            var op1    = AdvSimd.LoadVector128((UInt32 *)(_dataTable.inArray1Ptr));
            var op2    = AdvSimd.LoadVector128((UInt32 *)(_dataTable.inArray2Ptr));
            var result = Sha1.ScheduleUpdate1(op1, op2);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(op1, op2, _dataTable.outArrayPtr);
        }
Esempio n. 6
0
        public void RunBasicScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));

            var result = Sha1.FixedRotate(
                AdvSimd.LoadVector64((UInt32 *)(_dataTable.inArray1Ptr))
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.outArrayPtr);
        }
Esempio n. 7
0
 /// <inheritdoc/>
 public override int GetHashCode()
 {
     unchecked
     {
         int result = Sha1?.GetHashCode() ?? 0;
         result = (result * 397) ^ (Sha1New?.GetHashCode() ?? 0);
         result = (result * 397) ^ (Sha256?.GetHashCode() ?? 0);
         result = (result * 397) ^ (Sha256New?.GetHashCode() ?? 0);
         return(result);
     }
 }
Esempio n. 8
0
        public void RunClsVarScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));

            var result = Sha1.FixedRotate(
                _clsVar1
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_clsVar1, _dataTable.outArrayPtr);
        }
Esempio n. 9
0
        public void RunStructLclFldScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario_Load));

            var test   = TestStruct.Create();
            var result = Sha1.FixedRotate(
                AdvSimd.LoadVector64((UInt32 *)(&test._fld1))
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(test._fld1, _dataTable.outArrayPtr);
        }
        public void RunLclVarScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));

            var op1    = Unsafe.Read <Vector128 <UInt32> >(_dataTable.inArray1Ptr);
            var op2    = Unsafe.Read <Vector64 <UInt32> >(_dataTable.inArray2Ptr);
            var op3    = Unsafe.Read <Vector128 <UInt32> >(_dataTable.inArray3Ptr);
            var result = Sha1.HashUpdateParity(op1, op2, op3);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(op1, op2, op3, _dataTable.outArrayPtr);
        }
Esempio n. 11
0
        public void OctalSequenceHashesCorrectly()
        {
            byte[] expectedResults = { 0xE0, 0xC0, 0x94, 0xE8, 0x67, 0xEF, 0x46, 0xC3, 0x50, 0xEF, 0x54, 0xA7, 0xF5, 0x9D, 0xD6, 0x0B, 0xED, 0x92, 0xAE, 0x83 };

            byte[] hashBytes = new Sha1().Compute(Encoding.UTF8.GetBytes("0123456701234567012345670123456701234567012345670123456701234567"));

            Assert.IsNotNull(hashBytes);
            for (int i = 0; i < expectedResults.Length; i++)
            {
                Assert.AreEqual(expectedResults[i], hashBytes[i]);
            }
        }
Esempio n. 12
0
        public void LettarAHashesCorrectly()
        {
            byte[] expectedResults = { 0x86, 0xF7, 0xE4, 0x37, 0xFA, 0xA5, 0xA7, 0xFC, 0xE1, 0x5D, 0x1D, 0xDC, 0xB9, 0xEA, 0xEA, 0xEA, 0x37, 0x76, 0x67, 0xB8 };

            byte[] hashBytes = new Sha1().Compute(Encoding.UTF8.GetBytes("a"));

            Assert.IsNotNull(hashBytes);
            for (int i = 0; i < expectedResults.Length; i++)
            {
                Assert.AreEqual(expectedResults[i], hashBytes[i]);
            }
        }
Esempio n. 13
0
        public void AlternatingLettersHashesCorrectly()
        {
            byte[] expectedResults = { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 };

            byte[] hashBytes = new Sha1().Compute(Encoding.UTF8.GetBytes("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"));

            Assert.IsNotNull(hashBytes);
            for (int i = 0; i < expectedResults.Length; i++)
            {
                Assert.AreEqual(expectedResults[i], hashBytes[i]);
            }
        }
Esempio n. 14
0
        public void AbcHashesCorrectly()
        {
            byte[] expectedResults = { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D };

            byte[] hashBytes = new Sha1().Compute(Encoding.UTF8.GetBytes("abc"));

            Assert.IsNotNull(hashBytes);
            for (int i = 0; i < expectedResults.Length; i++)
            {
                Assert.AreEqual(expectedResults[i], hashBytes[i]);
            }
        }
Esempio n. 15
0
        public static void Default_1_GenerateInBase64_WithContent()
        {
            var sha1 = Sha1.GetInstance();

            Assert.NotNull(sha1);
            var value = sha1.GenerateInBase64("");

            Assert.Equal("2jmj7l5rSw0yVb/vlWAYkK/YBwk=", value);
            var value2 = sha1.GenerateInBase64("123");

            Assert.Equal("QL0AFWMIX8NRZTKeof9cXsvbvu8=", value2);
        }
        public static void FileVerifierTest_Default_3_Sha1_Hex()
        {
            var filePath = Path.Combine(Path.GetTempPath(), $"__test_{Guid.NewGuid().ToString()}__");
            var fileInfo = new FileInfo(filePath);

            File.WriteAllText(filePath, Guid.NewGuid().ToString());
            var checksum = Sha1.GetInstance().GenerateInHex(fileInfo);
            var verified = FileVerifier.VerifyAsync(fileInfo, fileInfo.Length, checksum, FileVerifier.ChecksumType.Sha1, CancellationToken.None).Result;

            Assert.True(verified);
            try { fileInfo.Delete(); } catch (Exception) { }
        }
Esempio n. 17
0
            public void RunStructFldScenario_Load(SecureHashUnaryOpTest__FixedRotate_Vector64_UInt32 testClass)
            {
                fixed(Vector64 <UInt32> *pFld1 = &_fld1)
                {
                    var result = Sha1.FixedRotate(
                        AdvSimd.LoadVector64((UInt32 *)(pFld1))
                        );

                    Unsafe.Write(testClass._dataTable.outArrayPtr, result);
                    testClass.ValidateResult(_fld1, testClass._dataTable.outArrayPtr);
                }
            }
Esempio n. 18
0
        public async Task Cause_Exists_To_Return_True()
        {
            const string script = "return redis.call('LOLWUT')";
            var          eval   = new EVAL(script, Array.Empty <Key>(), Array.Empty <BulkString>());
            await connection.ExecuteAsync(eval).ConfigureAwait(false);

            var scriptHash   = Sha1.Create(script);
            var scriptExists = new SCRIPT.EXISTS(scriptHash);
            var response     = await connection.ExecuteAsync(scriptExists).ConfigureAwait(false);

            response.Should().Equal((scriptHash, true));
        }
Esempio n. 19
0
        public static Sha1 FromPartition(DataEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var str  = $"{entity.PartitionKey}{entity.RowKey}";
            var sha1 = Sha1.Parse(str);

            return(sha1);
        }
Esempio n. 20
0
        public static void Default_3_GenerateInHex_WithContent()
        {
            var sha1 = Sha1.GetInstance();

            Assert.NotNull(sha1);
            var value = sha1.GenerateInHex("");

            Assert.Equal("da39a3ee5e6b4b0d3255bfef95601890afd80709", value);
            var value2 = sha1.GenerateInHex("123");

            Assert.Equal("40bd001563085fc35165329ea1ff5c5ecbdbbeef", value2);
        }
            private static string GetBinaryFilePath(string platform, string fileName)
            {
                var path = GetApplicationDataPath();

                if (string.IsNullOrWhiteSpace(path))
                {
                    return(string.Empty);
                }
                var path2 = Sha1.GetInstance().GenerateInHex($"{ModuleAssembly.Location}_{NativeApiVersion}_{platform}_{fileName}");

                return(Path.Combine(path, path2, fileName));
            }
Esempio n. 22
0
        static void Main()
        {
            var stopwatch = new Stopwatch();


            byte[] data = { 0, 0, 5, 1, 1, 2 };
            string word = "abc";


            Sha1 hash = new Sha1();

            stopwatch.Start();
            Console.WriteLine("Proper HASH SHA1(data): " + UintArrayToString(hash.Hash(data)));
            stopwatch.Stop();
            Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s");
            stopwatch.Reset();
            stopwatch.Start();
            Console.WriteLine("Proper HASH SHA1 (word): " + UintArrayToString(hash.Hash(Encoding.ASCII.GetBytes(word))));
            stopwatch.Stop();
            Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s");
            Console.WriteLine($"Data hashed in: {stopwatch.ElapsedTicks} ticks");
            Console.WriteLine($"Speed of hashing: {Encoding.ASCII.GetBytes(word).Length * 1000000 / stopwatch.Elapsed.Ticks} bps");


            SHA3Managed hash5 = new SHA3Managed(512);

            //stopwatch.Start();
            //Console.WriteLine("Proper HASH SHA3-512(data): " + ToHexString(hash5.ComputeHash(data)));
            //stopwatch.Stop();
            //Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s");
            stopwatch.Reset();
            stopwatch.Start();
            Console.WriteLine("Proper HASH SHA3-512 (word): " + ByteArrayToString(hash5.ComputeHash(Encoding.UTF8.GetBytes(word))));
            stopwatch.Stop();
            Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s");
            Console.WriteLine($"Data hashed in: {stopwatch.ElapsedTicks} ticks");
            Console.WriteLine("Speed of hashing: {0:f2} bps", (double)(Encoding.ASCII.GetBytes(word).Length / 1024) * 1000L * 1000L * 10L / (stopwatch.ElapsedTicks));

            SHA2Managed hash6 = new SHA2Managed(512);

            stopwatch.Reset();
            Console.WriteLine("Proper HASH SHA-512(word): " + ByteArrayToString(hash6.ComputeHash(Encoding.UTF8.GetBytes(word))));

            SHA2Managed hash7 = new SHA2Managed(224);

            stopwatch.Reset();
            Console.WriteLine("Proper HASH SHA-224(word): " + ByteArrayToString(hash7.ComputeHash(Encoding.UTF8.GetBytes(word))));

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new HashFunctionAnalizerForm());
        }
Esempio n. 23
0
        public void RunClsVarScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));

            var result = Sha1.HashUpdateMajority(
                _clsVar1,
                _clsVar2,
                _clsVar3
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_clsVar1, _clsVar2, _clsVar3, _dataTable.outArrayPtr);
        }
Esempio n. 24
0
        internal static TableOperation BuildWriteOperation(Sha1 sha1, ArraySegment <byte> content)
        {
            if (sha1 == Sha1.Empty)
            {
                throw new ArgumentNullException(nameof(sha1));
            }

            var entity = Create(sha1, content);

            var op = TableOperation.InsertOrReplace(entity);

            return(op);
        }
Esempio n. 25
0
        internal static DataEntity Create(Sha1 sha1, ArraySegment <byte> content)
        {
            if (sha1 == Sha1.Empty)
            {
                throw new ArgumentNullException(nameof(sha1));
            }

            var split = GetPartition(sha1);

            var entity = new DataEntity(split.Key, split.Value, content);

            return(entity);
        }
        public void RunBasicScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));

            var result = Sha1.ScheduleUpdate0(
                Unsafe.Read <Vector128 <UInt32> >(_dataTable.inArray1Ptr),
                Unsafe.Read <Vector128 <UInt32> >(_dataTable.inArray2Ptr),
                Unsafe.Read <Vector128 <UInt32> >(_dataTable.inArray3Ptr)
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.inArray3Ptr, _dataTable.outArrayPtr);
        }
Esempio n. 27
0
        internal static TableOperation BuildWriteOperation(Sha1 sha1, IChasmBlob blob)
        {
            if (blob == null)
            {
                throw new ArgumentNullException(nameof(blob));
            }

            DataEntity entity = Create(sha1, blob);

            var op = TableOperation.InsertOrReplace(entity);

            return(op);
        }
Esempio n. 28
0
        internal static DataEntity Create(Sha1 sha1, IChasmBlob blob, bool forceOverwrite)
        {
            if (blob == null)
            {
                throw new ArgumentNullException(nameof(blob));
            }

            KeyValuePair <string, string> split = GetPartition(sha1);

            var entity = new DataEntity(split.Key, split.Value, blob, forceOverwrite);

            return(entity);
        }
Esempio n. 29
0
        /// <summary>
        /// 获得文件唯一Hash值
        /// </summary>
        void GetHashOne(string filename)
        {
            using (Stream s = File.OpenRead(filename))
            {
                var hash  = Sha1.ComputeHash(s);
                var shash = string.Format("{0}|{1}", Convert.ToBase64String(hash), s.Length);
                //去除文件组表头,只有文件名字信息
                filename = filename.Substring(Group.Length + 1);

                filename           = filename.Replace('\\', '/');
                FileHash[filename] = shash;
            }
        }
Esempio n. 30
0
        public IEnumerable <Job> GetBuilds(MergeRequest mergeRequest, Sha1 sha)
        {
            var projectClient   = client.GetRepository(mergeRequest.SourceProjectId.Value);
            var pipelinesClient = projectClient.Pipelines;
            var pipelines       = pipelinesClient.All();
            var pipeline        = pipelines.FirstOrDefault(x => object.Equals(x.Sha1, sha));

            if (pipeline == null)
            {
                return(Enumerable.Empty <Job>());
            }
            return(pipelinesClient.GetJobs(pipeline.Id));
        }
Esempio n. 31
0
 public IEnumerable<Build> GetBuildsForCommit(Sha1 sha)
 {
     return _api.Get().GetAll<Build>(_buildsFromCommitPath + "/" + sha.ToString().ToLowerInvariant() + Build.Url);
 }
Esempio n. 32
0
        public static async void AuthSessionHandler(AuthSession authSession, WorldSession session)
        {
            var accountParts = authSession.Account.Split(new[] { '#' });
            var authResult = AuthResult.Ok;

            if (accountParts.Length == 2)
            {
                var accountId = int.Parse(accountParts[0]);
                var gameIndex = byte.Parse(accountParts[1]);

                session.Account = DB.Auth.Single<Account>(a => a.Id == accountId);

                if (session.Account != null)
                    session.GameAccount = session.Account.GameAccounts.SingleOrDefault(ga => ga.Index == gameIndex);

                if (session.GameAccount != null)
                    session.Crypt = new WoWCrypt(session.GameAccount.SessionKey.ToByteArray());
                else
                    authResult = AuthResult.Failed;
            }

            session.Realm = DB.Auth.Single<Realm>(r => r.Id == authSession.RealmID);

            if (authSession.LoginServerType != (sbyte)LoginServerTypes.Battlenet || session.Realm == null)
                authResult = AuthResult.Reject;

            if (authResult == AuthResult.Ok)
            {
                var sha1 = new Sha1();

                sha1.Process(authSession.Account);
                sha1.Process(0u);
                sha1.Process(authSession.LocalChallenge);
                sha1.Process(session.Challenge);
                sha1.Finish(session.GameAccount.SessionKey.ToByteArray(), 40);

                // Check the password digest.
                if (!sha1.Digest.Compare(authSession.Digest))
                    authResult = AuthResult.Failed;
            }

            var authResponse = new AuthResponse
            {
                Result = authResult,
                HasSuccessInfo = authResult == AuthResult.Ok,
            };

            if (authResponse.HasSuccessInfo)
            {
                session.State = SessionState.Authenticated;

                var addonData = AddonHandler.GetAddonInfoData(session, authSession.AddonInfo, authSession.CompressedAddonInfoSize, authSession.UncompressedAddonInfoSize);

                if (addonData != null && addonData.Length != authSession.UncompressedAddonInfoSize)
                {
                    Log.Error("Addon Info data size mismatch.");

                    session.Dispose();

                    return;
                }

                authResponse.SuccessInfo.ActiveExpansionLevel = session.GameAccount.BoxLevel;
                authResponse.SuccessInfo.AccountExpansionLevel = session.GameAccount.BoxLevel;
                authResponse.SuccessInfo.AvailableRaces = Manager.GameAccount.GetAvailableRaces(session.GameAccount, session.Realm);
                authResponse.SuccessInfo.AvailableClasses = Manager.GameAccount.GetAvailableClasses(session.GameAccount, session.Realm);
                authResponse.SuccessInfo.Templates = Manager.GameAccount.GetAvailableCharacterTemplates(session.GameAccount, session.Realm);

                await session.Send(authResponse);

                AddonHandler.HandleAddonInfo(session, addonData);

                await session.Send(new TutorialFlags());
            }
            else
                await session.Send(authResponse);
        }
Esempio n. 33
0
 public Compare Compare(Sha1 from, Sha1 to) {
     return _api.Get().To<Compare>(_repoPath + "/compare?from=" + from + "&to=" + to);
 }
Esempio n. 34
0
 public bool Equals(Sha1 other)
 {
     return _p1 == other._p1 && _p2 == other._p2 && _p3 == other._p3;
 }
Esempio n. 35
0
 public SingleCommit GetCommit(Sha1 sha)
 {
     return _api.Get().To<SingleCommit>(_repoPath + "/commits/" + sha);
 }
Esempio n. 36
0
 public IEnumerable<Diff> GetCommitDiff(Sha1 sha)
 {
     return _api.Get().GetAll<Diff>(_repoPath + "/commits/" + sha + "/diff");
 }
Esempio n. 37
0
 public void GetCommitBySha1()
 {
     var sha1 = new Sha1("8c89dcaf09dfad151e182b81918e0530b9019ac4");
     Assert.AreEqual(sha1, _repo.GetCommit(sha1).Id);
 }