public void HashToPoint_Should_GeneratePointOnCurve_When_RandomHashesArePassed2() { var phe = new PheCrypto(); var swu = new Swu(phe.Curve.Q, phe.Curve.B.ToBigInteger()); var sha512 = new SHA512Helper(); var data = new byte[] { 0x80, 0x39, 0x05, 0x35, 0x49, 0x44, 0x70, 0xbe, 0x0b, 0x29, 0x65, 0x01, 0x58, 0x6b, 0xfc, 0xd9, 0xe1, 0x31, 0xc3, 0x9e, 0x2d, 0xec, 0xc7, 0x53, 0xd4, 0xf2, 0x5f, 0xdd, 0xd2, 0x28, 0x1e, 0xe3, }; var hash = sha512.ComputeHash(null, data); for (int i = 0; i <= 15000; i++) { var(x, y) = swu.DataToPoint(hash); Assert.True(phe.Curve.CreatePoint(x, y).IsValid()); hash = sha512.ComputeHash(null, hash); } }
public void TupleHashCompute_Should_GenerateExpectedHash() { var expectedHash = "3696FB515910C43033D7BE0DD1ABFA4F3F8D8354EEC017D41F9" + "3A344C9AAB02C006771824DC09C5040BEC8CE9C5FD3833D1301B62750726160098E9A1ED440E4"; var arr1 = new byte[] { 0x00, 0x01, 0x02 }; var arr2 = new byte[] { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15 }; var arr3 = new byte[] { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28 }; var domain = Bytes.FromString("My Tuple App"); var tupleHash = new SHA512Helper(); var hash = tupleHash.ComputeHash(domain, arr1, arr2, arr3); Assert.Equal(expectedHash, Bytes.ToString(hash, StringEncoding.HEX).ToUpper()); }
public void HashToPoint_Should_GeneratePointOnCurve_When_RandomHashesArePassed() { var phe = new PheCrypto(); var swu = new Swu(phe.Curve.Q, phe.Curve.B.ToBigInteger()); var rng = new SecureRandom(); var sha512 = new SHA512Helper(); var random = new byte[32]; for (int i = 0; i <= 15000; i++) { rng.NextBytes(random); var hash = sha512.ComputeHash(null, random); var(x, y) = swu.DataToPoint(hash); Assert.True(phe.Curve.CreatePoint(x, y).IsValid()); } }
private static byte[] ComputeHash(byte[] content, string algorithm) { switch (algorithm.ToUpper()) { case "MD5": return(MD5Helper.ComputeHash(content)); case "SHA256": return(SHA256Helper.ComputeHash(content)); case "SHA384": return(SHA384Helper.ComputeHash(content)); case "SHA512": return(SHA512Helper.ComputeHash(content)); default: return(SHA1Helper.ComputeHash(content)); } }
public void HkdfGenerateBytes_Should_GenerateExpectedValue() { var expectedValue = "0F097707AAB66A4CD5FCC79CEB96FB4B99DE2E73DF09295E" + "CFF6F6CC7C1DCF169D51B62999BC206487800E8DD451518FA6C50F5C053B8B780208BE7164D3A7F2"; var arr1 = new byte[] { 0x00, 0x01, 0x02 }; var arr2 = new byte[] { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15 }; var arr3 = new byte[] { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28 }; var domain = Bytes.FromString("My Tuple App"); var sha512 = new SHA512Helper(); var key = sha512.ComputeHash(null, arr1, arr2, arr3); var hkdf = new HkdfBytesGenerator(new Sha512Digest()); var phe = new PheCrypto(); hkdf.Init(new HkdfParameters(key, domain, Domains.KdfInfoZ)); var resultValue = new byte[64]; hkdf.GenerateBytes(resultValue, 0, resultValue.Length); Assert.Equal(expectedValue, Bytes.ToString(resultValue, StringEncoding.HEX).ToUpper()); }