public void FIPSCompliance_Test3() { SHA224 sha = (SHA224)hash; // Third test, we hash 1,000,000 times the character "a" FIPS186_Test3(sha); }
public void FIPSCompliance_Test2() { SHA224 sha = (SHA224)hash; // Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" FIPS186_Test2(sha); }
public void FIPSCompliance_Test1() { SHA224 sha = (SHA224)hash; // First test, we hash the string "abc" FIPS186_Test1(sha); }
/// Encodes the specified string. /// @param text The string to encode. /// @returns The encoded string. public string Encode(string text) { var buffer = Encoding.Default.GetBytes(text); var hash = SHA224.Create().ComputeHash(buffer); return(HexCodec.GetString(hash)); }
public void FIPS186_b(string testName, SHA224 hash, byte[] input, byte[] result) { byte[] output = hash.ComputeHash(input, 0, input.Length); AssertEquals(testName + ".b.1", result, output); AssertEquals(testName + ".b.2", result, hash.Hash); // required or next operation will still return old hash hash.Initialize(); }
public void FIPS186_d(string testName, SHA224 hash, byte[] input, byte[] result) { hash.TransformFinalBlock(input, 0, input.Length); // Note: TransformFinalBlock doesn't return HashValue ! // AssertEquals( testName + ".d.1", result, output ); AssertEquals(testName + ".d", result, hash.Hash); // required or next operation will still return old hash hash.Initialize(); }
public void FIPS186_c(string testName, SHA224 hash, byte[] input, byte[] result) { MemoryStream ms = new MemoryStream(input); byte[] output = hash.ComputeHash(ms); AssertEquals(testName + ".c.1", result, output); AssertEquals(testName + ".c.2", result, hash.Hash); // required or next operation will still return old hash hash.Initialize(); }
public void FIPS186_e(string testName, SHA224 hash, byte[] input, byte[] result) { byte[] copy = new byte [input.Length]; for (int i = 0; i < input.Length - 1; i++) { hash.TransformBlock(input, i, 1, copy, i); } hash.TransformFinalBlock(input, input.Length - 1, 1); // Note: TransformFinalBlock doesn't return HashValue ! // AssertEquals (testName + ".e.1", result, output); AssertEquals(testName + ".e", result, hash.Hash); // required or next operation will still return old hash hash.Initialize(); }
public void FIPS186_Test2(SHA224 hash) { string className = hash.ToString(); byte[] result = { 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC, 0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50, 0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19, 0x52, 0x52, 0x25, 0x25 }; byte[] input = Encoding.Default.GetBytes(input2); string testName = className + " 2"; FIPS186_a(testName, hash, input, result); FIPS186_b(testName, hash, input, result); FIPS186_c(testName, hash, input, result); FIPS186_d(testName, hash, input, result); FIPS186_e(testName, hash, input, result); }
public void FIPS186_Test1(SHA224 hash) { string className = hash.ToString(); byte[] result = { 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22, 0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3, 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7, 0xE3, 0x6C, 0x9D, 0xA7 }; byte[] input = Encoding.Default.GetBytes(input1); string testName = className + " 1"; FIPS186_a(testName, hash, input, result); FIPS186_b(testName, hash, input, result); FIPS186_c(testName, hash, input, result); FIPS186_d(testName, hash, input, result); FIPS186_e(testName, hash, input, result); }
public virtual void Create() { // Note: These tests will only be valid without a "machine.config" file // or a "machine.config" file that do not modify the default algorithm // configuration. // FIXME: Change namespace when (or if) classes are moved into corlib const string defaultSHA224 = "Mono.Security.Cryptography.SHA224Managed"; // try to build the default implementation SHA224 hash = SHA224.Create(); Assert.AreEqual(hash.ToString(), defaultSHA224, "SHA224.Create()"); // try to build, in every way, a SHA224 implementation hash = SHA224.Create("SHA224"); Assert.AreEqual(hash.ToString(), defaultSHA224, "SHA224.Create('SHA224')"); hash = SHA224.Create("SHA-224"); Assert.AreEqual(hash.ToString(), defaultSHA224, "SHA224.Create('SHA-224')"); }
public void FIPS186_Test3(SHA224 hash) { string className = hash.ToString(); byte [] result = { 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8, 0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B, 0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE, 0x4E, 0xE7, 0xAD, 0x67 }; byte[] input = new byte [1000000]; for (int i = 0; i < 1000000; i++) { input[i] = 0x61; // a } string testName = className + " 3"; FIPS186_a(testName, hash, input, result); FIPS186_b(testName, hash, input, result); FIPS186_c(testName, hash, input, result); FIPS186_d(testName, hash, input, result); FIPS186_e(testName, hash, input, result); }
public virtual void SetUp() { hash = SHA224.Create(); }
public void CreateNull() { // try to build null implementation hash = SHA224.Create(null); }
public void CreateIncorrect() { // try to build an incorrect hash algorithms hash = SHA224.Create("MD5"); }