public void hashFugue() { string paramIn = "73ed6f3bd1805c003de63ae11f76630d35602c1a1b9504ba3f42233176425213622c9c630c830175b4f8a81f633e8bb98c663e142bcc88b0baaa7dd9e73a6907"; string paramOut = "af72d939050259913e440b23bee62e3b9604129ec8424d265a6ee4916e060000e51eead6ded2b584283ac0e04c1ea582e1a757245b5e8c408520216139e17848"; HashResult result = HashFactory.Crypto.SHA3.CreateFugue512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public static byte[] SH224(string str) { IHash hash = HashFactory.Crypto.CreateSHA224(); HashResult r = hash.ComputeString(str, System.Text.Encoding.UTF8); return(r.GetBytes()); }
public void hashSkeinCustom() { string paramIn = "317024467e25cb6f1014f1b7a98c63b2ccc925b05a72180b0cdf23f42fabe653ddf51d11ce471dca48282b22261bbc7f5a729189c52554443a635889c7d47db6"; string paramOut = "a4d126f16372bd2df3e22bc95f61e696a72a1bee32e62ca90fedc24e94dbdf314446dc00a5e6bc2907d73c7210e6cb780be00b49b26b7a6f2db29249f2bd884b"; HashResult result = HashFactory.Crypto.SHA3.CreateSkein512_Custom().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashBlueMidnightWish() { string paramIn = "042733333794f07574f6ca059eef16bacbfc5d563e5342d64fded94c6f6fbd139db7ebe1d48b962156391383ccb7f6064fe4583c64df954e5418b9a08908a082"; string paramOut = "b2e1d72db8a3807d6d929a0e1349250cae0e99475d94bd869d0163755574a89078e08f604ff32833585dc45d28a69c0b269abb3fcd5c4ee09afc8ca32fa7e40d"; HashResult result = HashFactory.Crypto.SHA3.CreateBlueMidnightWish512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashGroestl() { string paramIn = "b2e1d72db8a3807d6d929a0e1349250cae0e99475d94bd869d0163755574a89078e08f604ff32833585dc45d28a69c0b269abb3fcd5c4ee09afc8ca32fa7e40d"; string paramOut = "317024467e25cb6f1014f1b7a98c63b2ccc925b05a72180b0cdf23f42fabe653ddf51d11ce471dca48282b22261bbc7f5a729189c52554443a635889c7d47db6"; HashResult result = HashFactory.Crypto.SHA3.CreateGroestl512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public byte[] CalculateHash(byte[] input) { lock (_hash) { HashResult hashRes = _hash.ComputeBytes(input); return(hashRes.GetBytes()); } }
public static byte[] Hash(byte[] message, int offset, int lenght, IHash algorithm) { algorithm.Initialize(); algorithm.TransformBytes(message, offset, lenght); HashResult result = algorithm.TransformFinal(); return(result.GetBytes()); }
public void hashEcho() { string paramIn = "921ca1f5fc388ff8217e5bc787acb7e5b462063c12dca18b56b8bff0791d5c338b6604b74cd2c77ed7ac3a5a3843deb27e82f077c71a11a7308fc90864a0bd89"; string paramOut = "ad8f8a4b105ffb83bb7546da799e29caa5bc9f2d0b584bdbf7d3275c65bdaae849e277187321d7d323e827c901530f6073bb967a198f3e3ba52c3a01716a442b"; HashResult result = HashFactory.Crypto.SHA3.CreateEcho512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashHamsi() { string paramIn = "ad8f8a4b105ffb83bb7546da799e29caa5bc9f2d0b584bdbf7d3275c65bdaae849e277187321d7d323e827c901530f6073bb967a198f3e3ba52c3a01716a442b"; string paramOut = "73ed6f3bd1805c003de63ae11f76630d35602c1a1b9504ba3f42233176425213622c9c630c830175b4f8a81f633e8bb98c663e142bcc88b0baaa7dd9e73a6907"; HashResult result = HashFactory.Crypto.SHA3.CreateHamsi512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashSHAvite3Custom() { string paramIn = "50ddc199803de46305083d0852bc4005fc473ed05ec56347ae65e9875c0571da7375bb227678805e7ef868015bd4bf714bae038937538dd7819cc58b6d03ca7b"; string paramOut = "0bb309f45b7ec5b115a3318f0b2f0e431c8e415a3d6848087e7905e4e47c52874b79947e4bdee71668d1b1487716da57ac1f8d87e149ce1eee9080d6cc2827df"; HashResult result = HashFactory.Crypto.SHA3.CreateSHAvite3_512_Custom().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashSIMD() { string paramIn = "0bb309f45b7ec5b115a3318f0b2f0e431c8e415a3d6848087e7905e4e47c52874b79947e4bdee71668d1b1487716da57ac1f8d87e149ce1eee9080d6cc2827df"; string paramOut = "921ca1f5fc388ff8217e5bc787acb7e5b462063c12dca18b56b8bff0791d5c338b6604b74cd2c77ed7ac3a5a3843deb27e82f077c71a11a7308fc90864a0bd89"; HashResult result = HashFactory.Crypto.SHA3.CreateSIMD512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashCubeHash() { string paramIn = "8bc3589bea395cdd461226ccbea9cfa463edc5d556ff8c60f8053502135781747ae56b521ced7208fcf6c30dc6f9169b51f5452021b6951fa3d8240f3972d740"; string paramOut = "50ddc199803de46305083d0852bc4005fc473ed05ec56347ae65e9875c0571da7375bb227678805e7ef868015bd4bf714bae038937538dd7819cc58b6d03ca7b"; HashResult result = HashFactory.Crypto.SHA3.CreateCubeHash512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashLuffa() { string paramIn = "c4f7a14f01cab51c317b7b0064932004ac72a85d8686a9165e1f8b8a968113cd7a3398554ef1c92a3c296c192f9314a2365bc0f7775d4e478787055a9b2ce897"; string paramOut = "8bc3589bea395cdd461226ccbea9cfa463edc5d556ff8c60f8053502135781747ae56b521ced7208fcf6c30dc6f9169b51f5452021b6951fa3d8240f3972d740"; HashResult result = HashFactory.Crypto.SHA3.CreateLuffa512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashKeccak() { string paramIn = "c295dd0155177a9104a80ec27b245600f0de17db4aee4a16a1cf386db29b6a8e5ea74c32bb6c317f388f6585d4b338e53959399e75fcaa16045a4094da19cb6d"; string paramOut = "c4f7a14f01cab51c317b7b0064932004ac72a85d8686a9165e1f8b8a968113cd7a3398554ef1c92a3c296c192f9314a2365bc0f7775d4e478787055a9b2ce897"; HashResult result = HashFactory.Crypto.SHA3.CreateKeccak512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashJH() { string paramIn = "a4d126f16372bd2df3e22bc95f61e696a72a1bee32e62ca90fedc24e94dbdf314446dc00a5e6bc2907d73c7210e6cb780be00b49b26b7a6f2db29249f2bd884b"; string paramOut = "c295dd0155177a9104a80ec27b245600f0de17db4aee4a16a1cf386db29b6a8e5ea74c32bb6c317f388f6585d4b338e53959399e75fcaa16045a4094da19cb6d"; HashResult result = HashFactory.Crypto.SHA3.CreateJH512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void hashBlake() { string paramIn = "01000000000000000000000000000000000000000000000000000000000000000000000018157f44917c2514c1f339346200f8b27d8ffaae9d8205bfae51030bc26ba265b88ba557ffff0f1eddf21b00"; string paramOut = "042733333794f07574f6ca059eef16bacbfc5d563e5342d64fded94c6f6fbd139db7ebe1d48b962156391383ccb7f6064fe4583c64df954e5418b9a08908a082"; HashResult result = HashFactory.Crypto.SHA3.CreateBlake512().ComputeBytes(Encoders.Hex.DecodeData(paramIn)); Assert.Equal(paramOut, Encoders.Hex.EncodeData(result.GetBytes())); }
public void HashResult() { for (int i = 0; i < 14; i++) { HashResult h1 = new HashResult(m_random.NextBytes(i)); try { uint h2 = h1.GetUInt(); if (i != 4) { Assert.Fail(i.ToString()); } Assert.IsTrue(Converters.ConvertBytesToUInts(h1.GetBytes())[0] == h2, i.ToString()); } catch { if (i == 4) { Assert.Fail(i.ToString()); } } try { ulong h3 = h1.GetULong(); if (i != 8) { Assert.Fail(i.ToString()); } Assert.IsTrue(Converters.ConvertBytesToULongs(h1.GetBytes())[0] == h3, i.ToString()); } catch { if (i == 8) { Assert.Fail(i.ToString()); } } } }
protected void TestHashResult(IHash a_hash) { a_hash.Initialize(); a_hash.TransformBytes(m_random.NextBytes(64)); HashResult r1 = a_hash.TransformFinal(); byte[] r2 = (byte[])r1.GetBytes().Clone(); HashResult r3 = a_hash.ComputeBytes(m_random.NextBytes(64)); byte[] r4 = (byte[])r3.GetBytes().Clone(); Assert.AreNotSame(r1, r2); Assert.AreNotSame(r1.GetBytes(), r3.GetBytes()); CollectionAssert.AreEqual(r1.GetBytes(), r2); CollectionAssert.AreEqual(r3.GetBytes(), r4); Assert.AreNotEqual(r1, r3); CollectionAssert.AreNotEqual(r2, r4); CollectionAssert.AreNotEqual(r1.GetBytes(), r3.GetBytes()); Assert.AreEqual(Converters.ConvertBytesToHexString(Converters.ConvertHexStringToBytes("A1B1C2D34567890F")), "A1B1C2D3-4567890F"); }
public byte[] CalculateHash(Memory <byte> input) { lock (_hash) { if (MemoryMarshal.TryGetArray(input, out ArraySegment <byte> byteArray)) { HashResult hashRes = _hash.ComputeBytes(byteArray.Array); return(hashRes.GetBytes()); } throw new FailedToMarshalToByteArrayException(nameof(input)); } }
private void ChangePassword(HttpContext context) { string pass = context.Request.Params["pass"]; if (!string.IsNullOrEmpty(pass)) { Data.dbml.AppUsers u = this.GetDataContext2.AppUsers.First(o => o.ID == Common.UserID); IHash hash = Common.Hash; HashResult res = hash.ComputeString(pass); u.Password = Common.GetString(res.GetBytes()); GetDataContext2.SubmitChanges(); context.Response.Write(strings.Pass_Updated); } }
private void ChangePassword(HttpContext context) { string pass = context.Request.Params["pass"]; if (!string.IsNullOrEmpty(pass)) { Nails.edmx.AppUsers u = this.GetNailsProdContext.AppUsers.First(o => o.ID == Common.UserID); IHash hash = Common.Hash; HashResult res = hash.ComputeString(pass); u.Password = Common.GetString(res.GetBytes()); this.GetNailsProdContext.SaveChanges(); context.Response.Write("Password has been updated"); } }
protected void TestExtremelyLong() { const int SLEEP_TIME_MS = 10; int THREADS = System.Environment.ProcessorCount; const float TARGET_CPU_LOAD = 0.4f; Assert.IsTrue(THREADS <= System.Environment.ProcessorCount); ProgressIndicator pi = new ProgressIndicator("Crypto +4GB Test"); pi.AddLine(String.Format("Configuration: {0} threads, CPU Load: {1}%", THREADS, TARGET_CPU_LOAD * 100)); CancellationTokenSource src = new CancellationTokenSource(); Task regulator = Task.Factory.StartNew(token => { PerformanceCounter pc = new PerformanceCounter("Processor", "% Processor Time", "_Total"); List <float> cpu_load = new List <float>(); for (;;) { const int PROBE_DELTA_MS = 200; const int PROBE_COUNT = 30; const int REGULATE_COUNT = 10; for (int i = 0; i < REGULATE_COUNT; i++) { System.Threading.Thread.Sleep(PROBE_DELTA_MS); cpu_load.Add(pc.NextValue() / 100); if (src.IsCancellationRequested) { break; } } while (cpu_load.Count > PROBE_COUNT) { cpu_load.RemoveFirst(); } int old_transform_rounds = transform_rounds; float avg_cpu_load = cpu_load.Average(); if (avg_cpu_load >= TARGET_CPU_LOAD) { transform_rounds = (int)Math.Round(transform_rounds * 0.9); if (old_transform_rounds == transform_rounds) { transform_rounds--; } } else { transform_rounds = (int)Math.Round(transform_rounds * 1.1); if (old_transform_rounds == transform_rounds) { transform_rounds++; } } if (transform_rounds == 0) { transform_rounds = 1; } if (src.IsCancellationRequested) { break; } } }, src.Token); var partitioner = Partitioner.Create(Hashes.CryptoAll, EnumerablePartitionerOptions.None); Parallel.ForEach(partitioner, new ParallelOptions() { MaxDegreeOfParallelism = THREADS }, ht => { IHash hash = (IHash)Activator.CreateInstance(ht); pi.AddLine(String.Format("{0} / {1} - {2} - {3}%", Hashes.CryptoAll.IndexOf(ht) + 1, Hashes.CryptoAll.Count, hash.Name, 0)); TestData test_data = TestData.Load(hash); int test_data_index = 0; for (int i = 0; i < test_data.Count; i++) { if (test_data.GetRepeat(i) == 1) { continue; } test_data_index++; ulong repeats = (ulong)test_data.GetRepeat(i); byte[] data = test_data.GetData(i); string expected_result = Converters.ConvertBytesToHexString(test_data.GetHash(i)); hash.Initialize(); int transform_counter = transform_rounds; DateTime progress = DateTime.Now; for (ulong j = 0; j < repeats; j++) { hash.TransformBytes(data); transform_counter--; if (transform_counter == 0) { System.Threading.Thread.Sleep(SLEEP_TIME_MS); transform_counter = transform_rounds; } if (DateTime.Now - progress > TimeSpan.FromSeconds(5)) { pi.AddLine(String.Format("{0} / {1} / {2} - {3} - {4}%", Hashes.CryptoAll.IndexOf(ht) + 1, test_data_index, Hashes.CryptoAll.Count, hash.Name, j * 100 / repeats)); progress = DateTime.Now; } } HashResult result = hash.TransformFinal(); Assert.AreEqual(expected_result, Converters.ConvertBytesToHexString(result.GetBytes()), hash.ToString()); pi.AddLine(String.Format("{0} / {1} / {2} - {3} - {4}", Hashes.CryptoAll.IndexOf(ht) + 1, test_data_index, Hashes.CryptoAll.Count, hash.Name, "OK")); } }); src.Cancel(); regulator.Wait(); }