/// <summary> /// executes a selftest /// </summary> /// <remarks> /// Call this method to make sure that the instance is able to produce /// valid output according to the specification. /// </remarks> /// <returns> /// true: selftest passed / false: selftest failed /// </returns> public static bool SelfTest() { uint unHi = TEST_VECTOR_PLAIN[0]; uint unLo = TEST_VECTOR_PLAIN[1]; Blowfish bf = new Blowfish(TEST_KEY); bf.Encrypt(ref unHi, ref unLo); if ((unHi != TEST_VECTOR_CIPHER[0]) || (unLo != TEST_VECTOR_CIPHER[1])) { return(false); } bf.Decrypt(ref unHi, ref unLo); if ((unHi != TEST_VECTOR_PLAIN[0]) || (unLo != TEST_VECTOR_PLAIN[1])) { return(false); } return(true); }
public int TransformBlock ( byte[] bufIn, int nOfsIn, int nCount, byte[] bufOut, int nOfsOut ) { // NOTE: we assume that the caller understands the meaning of // this method and that only even byte boundaries are // given, thus we do not cache any data left internally int nResult = 0; if (null != m_bfc) { if (m_blIsEncryptor) { nResult = m_bfc.Encrypt(bufIn, bufOut, nOfsIn, nOfsOut, nCount); } else { nResult = m_bfc.Decrypt(bufIn, bufOut, nOfsIn, nOfsOut, nCount); } } else if (null != m_bf) { if (m_blIsEncryptor) { nResult = m_bf.Encrypt(bufIn, bufOut, nOfsIn, nOfsOut, nCount); } else { nResult = m_bf.Decrypt(bufIn, bufOut, nOfsIn, nOfsOut, nCount); } } else { nResult = 0; } return(nResult * Blowfish.BLOCKSIZE); }