private bool isValidAlgorithm(string algorithm) { SymmetricBlockAlgorithm symmetricBlockAlgorithm = SymmetricBlockAlgorithmUtils.getSymmetricBlockAlgorithm(algorithm, this.error); int blockSize = SymmetricBlockAlgorithmUtils.getBlockSize(symmetricBlockAlgorithm, this.error); if (this.HasError()) { return(false); } if (blockSize != 64 && blockSize != 128) { return(false); } return(true); }
/// <summary> /// Build the engine /// </summary> /// <param name="algorithm">SymmetricBlockAlgorithm enum, algorithm name</param> /// <returns>IBlockCipher with the algorithm Engine</returns> internal IBlockCipher getCipherEngine(SymmetricBlockAlgorithm algorithm) { IBlockCipher engine = null; switch (algorithm) { case SymmetricBlockAlgorithm.AES: engine = new AesEngine(); break; case SymmetricBlockAlgorithm.BLOWFISH: engine = new BlowfishEngine(); break; case SymmetricBlockAlgorithm.CAMELLIA: engine = new CamelliaEngine(); break; case SymmetricBlockAlgorithm.CAST5: engine = new Cast5Engine(); break; case SymmetricBlockAlgorithm.CAST6: engine = new Cast6Engine(); break; case SymmetricBlockAlgorithm.DES: engine = new DesEngine(); break; case SymmetricBlockAlgorithm.TRIPLEDES: engine = new DesEdeEngine(); break; case SymmetricBlockAlgorithm.DSTU7624_128: engine = new Dstu7624Engine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.DSTU7624_128, this.error)); break; case SymmetricBlockAlgorithm.DSTU7624_256: engine = new Dstu7624Engine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.DSTU7624_256, this.error)); break; case SymmetricBlockAlgorithm.DSTU7624_512: engine = new Dstu7624Engine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.DSTU7624_512, this.error)); break; case SymmetricBlockAlgorithm.GOST28147: engine = new Gost28147Engine(); break; case SymmetricBlockAlgorithm.NOEKEON: engine = new NoekeonEngine(); break; case SymmetricBlockAlgorithm.RC2: engine = new RC2Engine(); break; case SymmetricBlockAlgorithm.RC532: engine = new RC532Engine(); break; case SymmetricBlockAlgorithm.RC564: engine = new RC564Engine(); break; case SymmetricBlockAlgorithm.RC6: engine = new RC6Engine(); break; case SymmetricBlockAlgorithm.RIJNDAEL_128: engine = new RijndaelEngine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.RIJNDAEL_128, this.error)); break; case SymmetricBlockAlgorithm.RIJNDAEL_160: engine = new RijndaelEngine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.RIJNDAEL_160, this.error)); break; case SymmetricBlockAlgorithm.RIJNDAEL_192: engine = new RijndaelEngine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.RIJNDAEL_192, this.error)); break; case SymmetricBlockAlgorithm.RIJNDAEL_224: engine = new RijndaelEngine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.RIJNDAEL_224, this.error)); break; case SymmetricBlockAlgorithm.RIJNDAEL_256: engine = new RijndaelEngine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.RIJNDAEL_256, this.error)); break; case SymmetricBlockAlgorithm.SEED: engine = new SeedEngine(); break; case SymmetricBlockAlgorithm.SERPENT: engine = new SerpentEngine(); break; case SymmetricBlockAlgorithm.SKIPJACK: engine = new SkipjackEngine(); break; case SymmetricBlockAlgorithm.SM4: engine = new SM4Engine(); break; case SymmetricBlockAlgorithm.TEA: engine = new TeaEngine(); break; case SymmetricBlockAlgorithm.THREEFISH_256: engine = new ThreefishEngine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.THREEFISH_256, this.error)); break; case SymmetricBlockAlgorithm.THREEFISH_512: engine = new ThreefishEngine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.THREEFISH_512, this.error)); break; case SymmetricBlockAlgorithm.THREEFISH_1024: engine = new ThreefishEngine(SymmetricBlockAlgorithmUtils.getBlockSize(SymmetricBlockAlgorithm.THREEFISH_1024, this.error)); break; case SymmetricBlockAlgorithm.TWOFISH: engine = new TwofishEngine(); break; case SymmetricBlockAlgorithm.XTEA: engine = new XteaEngine(); break; default: this.error.setError("SB020", "Cipher " + algorithm + " not recognised."); break; } return(engine); }