コード例 #1
0
        private void InitCipher()
        {
            this.aadLength = 0;

            poly.Reset();
            chacha20.Reset();
            chacha20.AddOne();
            data.SetLength(0);

            if (initialAssociatedText != null)
            {
                ProcessAadBytes(initialAssociatedText, 0, initialAssociatedText.Length);
            }
        }
コード例 #2
0
        private void InitCipher()
        {
            _aadLength = 0;

            _poly.Reset();
            _chacha20.Reset();
            _chacha20.AddOne();
            _data.SetLength(0);

            if (_initialAssociatedText != null)
            {
                ProcessAadBytes(_initialAssociatedText, 0, _initialAssociatedText.Length);
            }
        }
コード例 #3
0
        private void testReset()
        {
            CipherKeyGenerator gen = new Poly1305KeyGenerator();

            gen.Init(new KeyGenerationParameters(new SecureRandom(), 256));
            byte[] k = gen.GenerateKey();

            byte[] m      = new byte[10000];
            byte[] check  = new byte[16];
            byte[] output = new byte[16];

            // Generate baseline
            IMac poly = new Poly1305(new AesFastEngine());

            poly.Init(new ParametersWithIV(new KeyParameter(k), new byte[16]));

            poly.BlockUpdate(m, 0, m.Length);
            poly.DoFinal(check, 0);

            // Check reset after doFinal
            poly.BlockUpdate(m, 0, m.Length);
            poly.DoFinal(output, 0);

            if (!Arrays.AreEqual(check, output))
            {
                Fail("Mac not reset after doFinal");
            }

            // Check reset
            poly.Update((byte)1);
            poly.Update((byte)2);
            poly.Reset();
            poly.BlockUpdate(m, 0, m.Length);
            poly.DoFinal(output, 0);

            if (!Arrays.AreEqual(check, output))
            {
                Fail("Mac not reset after doFinal");
            }

            // Check init resets
            poly.Update((byte)1);
            poly.Update((byte)2);
            poly.Init(new ParametersWithIV(new KeyParameter(k), new byte[16]));
            poly.BlockUpdate(m, 0, m.Length);
            poly.DoFinal(output, 0);

            if (!Arrays.AreEqual(check, output))
            {
                Fail("Mac not reset after doFinal");
            }
        }