Ejemplo n.º 1
0
        /********EXTERNAL OBJECT PUBLIC METHODS  - END ********/



        /// <summary>
        /// Buils the StreamCipher
        /// </summary>
        /// <param name="algorithm">SymmetrcStreamAlgorithm enum, algorithm name</param>
        /// <returns>IStreamCipher with the algorithm Stream Engine</returns>
        private IStreamCipher getCipherEngine(SymmetricStreamAlgorithm algorithm)
        {
            IStreamCipher engine = null;

            switch (algorithm)
            {
            case SymmetricStreamAlgorithm.RC4:
                engine = new RC4Engine();
                break;

            case SymmetricStreamAlgorithm.HC128:
                engine = new HC128Engine();
                break;

            case SymmetricStreamAlgorithm.HC256:
                engine = new HC256Engine();
                break;

            case SymmetricStreamAlgorithm.SALSA20:
                engine = new Salsa20Engine();
                break;

            case SymmetricStreamAlgorithm.CHACHA20:
                engine = new ChaChaEngine();
                break;

            case SymmetricStreamAlgorithm.XSALSA20:
                engine = new XSalsa20Engine();
                break;

            case SymmetricStreamAlgorithm.ISAAC:
                engine = new IsaacEngine();
                break;

            case SymmetricStreamAlgorithm.VMPC:
                engine = new VmpcEngine();
                break;

            default:
                this.GetError().setError("SS005", "Cipher " + algorithm + " not recognised.");
                break;
            }
            return(engine);
        }
Ejemplo n.º 2
0
 private void doTest(
     IsaacEngine engine,
     byte[]          key,
     byte[]          output)
 {
     byte[] input = new byte[output.Length];
     byte[] enc   = new byte[output.Length];
     engine.Init(true, new KeyParameter(key));
     engine.ProcessBytes(input, 0, input.Length, enc, 0);
     if (!AreEqual(enc, output))
     {
         Fail("ciphertext mismatch");
     }
     engine.Init(false, new KeyParameter(key));
     engine.ProcessBytes(enc, 0, enc.Length, enc, 0);
     if (!AreEqual(enc, input))
     {
         Fail("plaintext mismatch");
     }
 }
Ejemplo n.º 3
0
        public override void PerformTest()
        {
            IsaacEngine engine = new IsaacEngine();

            doTest(engine, Hex.Decode("00000000"), outBase);
            doTest(engine, Hex.Decode("ffffffff"), outFFFFFFFF);

            byte[] k = new byte[256 * 4];
            for (int i = 0; i != k.Length; i++)
            {
                k[i] = (byte)((i % 4 == 0 || i % 4 == 1) ? 0xff : 0x00);
            }
            doTest(engine, k, outFFFF0000);
            k = new byte[256 * 4];
            for (int i = 0; i != k.Length; i++)
            {
                k[i] = (byte)((i % 4 == 2 || i % 4 == 3) ? 0xff : 0x00);
            }
            doTest(engine, k, out0000FFFF);
        }