Inheritance: IBlockCipher
示例#1
0
		public override void PerformTest()
		{
			base.PerformTest();

			IBlockCipher engine = new NullEngine();

			engine.Init(true, null);

			byte[] buf = new byte[1];

			engine.ProcessBlock(buf, 0, buf, 0);

			if (buf[0] != 0)
			{
				Fail("NullCipher changed data!");
			}

			byte[] shortBuf = new byte[0];

			try
			{
				engine.ProcessBlock(shortBuf, 0, buf, 0);

				Fail("failed short input check");
			}
			catch (DataLengthException)
			{
				// expected
			}

			try
			{
				engine.ProcessBlock(buf, 0, shortBuf, 0);

				Fail("failed short output check");
			}
			catch (DataLengthException)
			{
				// expected
			}
		}
示例#2
0
文件: AWiz.cs 项目: burstas/rmps
        private BufferedBlockCipher CreateScryptoEngine()
        {
            IBlockCipher engine;
            switch (_MSec.Algorithm)
            {
                case ESec.SCRYPTO_AES:
                    engine = new AesEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_AESFAST:
                    engine = new AesFastEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_AESLIGHT:
                    engine = new AesLightEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_BLOWFISH:
                    engine = new BlowfishEngine();
                    _MSec.KeySize = 56;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_CAMELLIA:
                    engine = new CamelliaEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_CAMELLIALIGHT:
                    engine = new CamelliaLightEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_CAST5:
                    engine = new Cast5Engine();
                    _MSec.KeySize = 16;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_CAST6:
                    engine = new Cast6Engine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_DES:
                    engine = new DesEngine();
                    _MSec.KeySize = 8;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_DESEDE:
                    engine = new DesEdeEngine();
                    _MSec.KeySize = 24;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_GOST28147:
                    engine = new Gost28147Engine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_NOEKEON:
                    engine = new NoekeonEngine();
                    _MSec.KeySize = 16;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_NULL:
                    engine = new NullEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 16;
                    break;
                case ESec.SCRYPTO_RC2:
                    engine = new RC2Engine();
                    _MSec.KeySize = 128;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_RC532:
                    engine = new RC532Engine();
                    _MSec.KeySize = 16;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_RC564:
                    engine = new RC564Engine();
                    _MSec.KeySize = 16;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_RC6:
                    engine = new RC6Engine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_RIJNDAEL:
                    engine = new RijndaelEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_SEED:
                    engine = new SeedEngine();
                    _MSec.KeySize = 16;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_SERPENT:
                    engine = new SerpentEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_SKIPJACK:
                    engine = new SkipjackEngine();
                    _MSec.KeySize = 16;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_TEA:
                    engine = new TeaEngine();
                    _MSec.KeySize = 16;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_TWOFISH:
                    engine = new TwofishEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
                case ESec.SCRYPTO_XTEA:
                    engine = new XteaEngine();
                    _MSec.KeySize = 16;
                    _MSec.IVSize = 0;
                    break;
                default:
                    engine = new AesEngine();
                    _MSec.KeySize = 32;
                    _MSec.IVSize = 0;
                    break;
            }

            switch (_MSec.Mode)
            {
                case ESec.MODE_CBC:
                    engine = new CbcBlockCipher(engine);
                    break;
                case ESec.MODE_CFB:
                    engine = new CfbBlockCipher(engine, 8);
                    break;
                case ESec.MODE_GOFB:
                    engine = new GOfbBlockCipher(engine);
                    break;
                case ESec.MODE_OFB:
                    engine = new OfbBlockCipher(engine, 8);
                    break;
                case ESec.MODE_OPENPGPCFB:
                    engine = new OpenPgpCfbBlockCipher(engine);
                    break;
                case ESec.MODE_SIC:
                    engine = new SicBlockCipher(engine);
                    break;
                default:
                    engine = new CbcBlockCipher(engine);
                    break;
            }

            IBlockCipherPadding padding = null;
            switch (_MSec.Padding)
            {
                case ESec.PADDING_ISO10126d2:
                    padding = new ISO10126d2Padding();
                    break;
                case ESec.PADDING_ISO7816d4:
                    padding = new ISO7816d4Padding();
                    break;
                case ESec.PADDING_PKCS7:
                    padding = new Pkcs7Padding();
                    break;
                case ESec.PADDING_TBC:
                    padding = new TbcPadding();
                    break;
                case ESec.PADDING_X923:
                    padding = new X923Padding();
                    break;
                case ESec.PADDING_ZEROBYTE:
                    padding = new ZeroBytePadding();
                    break;
                default:
                    padding = new Pkcs7Padding();
                    break;
            }

            return new PaddedBufferedBlockCipher(engine, padding);
        }