/// <summary>To execute a selftest.</summary> /// <remarks>Call this method to make sure that the implemenation is able to produce /// valid output according to the specification. This should usually be done at process /// startup time, before the usage of this class and its inherited variants.</remarks> /// <returns>True if the selftest passed or false is it failed. In such a case you must /// not use the cipher to avoid data corruption!</returns> public static bool RunSelfTest() { uint hi = TEST_VECTOR_PLAIN[0]; uint lo = TEST_VECTOR_PLAIN[1]; BlowfishECB bfe = new BlowfishECB(TEST_KEY, 0, TEST_KEY.Length); bfe.EncryptBlock(hi, lo, out hi, out lo); if ((TEST_VECTOR_CIPHER[0] != hi) || (TEST_VECTOR_CIPHER[1] != lo)) { return(false); } bfe.DecryptBlock(hi, lo, out hi, out lo); if ((TEST_VECTOR_PLAIN[0] != hi) || (TEST_VECTOR_PLAIN[1] != lo)) { return(false); } return(true); }
/// <summary>To execute a selftest.</summary> /// <remarks>Call this method to make sure that the implemenation is able to produce /// valid output according to the specification. This should usually be done at process /// startup time, before the usage of this class and its inherited variants.</remarks> /// <returns>True if the selftest passed or false is it failed. In such a case you must /// not use the cipher to avoid data corruption!</returns> public static bool RunSelfTest() { uint hi = TEST_VECTOR_PLAIN[0]; uint lo = TEST_VECTOR_PLAIN[1]; BlowfishECB bfe = new BlowfishECB(TEST_KEY, 0, TEST_KEY.Length); bfe.EncryptBlock(hi, lo, out hi, out lo); if ((TEST_VECTOR_CIPHER[0] != hi) || (TEST_VECTOR_CIPHER[1] != lo)) { return false; } bfe.DecryptBlock(hi, lo, out hi, out lo); if ((TEST_VECTOR_PLAIN[0] != hi) || (TEST_VECTOR_PLAIN[1] != lo)) { return false; } return true; }