Example #1
0
        private static void Test4(IBlockCrypto crypto, string hex1, string hex2)
        {
            Assert.AreEqual(@"AES-CBC", crypto.Name);
            Assert.AreEqual(16, crypto.BlockSize);

            Span <byte> h1 = hex1.FromHex();
            Span <byte> h2 = hex2.FromHex();
            Span <byte> o1 = stackalloc byte[64];

            crypto.Encrypt4(h1, o1);
            Assert.IsTrue(o1.SequenceEqual(h2));

            crypto.Reset();

            crypto.Encrypt4(h1, o1);
            Assert.IsTrue(o1.SequenceEqual(h2));

            crypto.Reset();

            crypto.Decrypt(h2, o1);
            crypto.Decrypt(h2.Slice(16), o1.Slice(16));
            crypto.Decrypt(h2.Slice(32), o1.Slice(32));
            crypto.Decrypt(h2.Slice(48), o1.Slice(48));

            Assert.IsTrue(o1.SequenceEqual(h1));

            crypto.Dispose();
        }
Example #2
0
 public void Increment()
 {
     for (var i = 0; i < Max; ++i)
     {
         _randombytes.Increment();
         _aes.Encrypt(_randombytes16, _buffer.Span);
         _randombytes.Increment();
         _aes.Decrypt(_randombytes16, _buffer.Span);
     }
 }
Example #3
0
    private static void Test(IBlockCrypto crypto, string hex1, string hex2, string hex3)
    {
        Assert.AreEqual(@"SM4", crypto.Name);
        Assert.AreEqual(16, crypto.BlockSize);

        Span <byte> h1 = hex1.FromHex();
        Span <byte> h2 = hex2.FromHex();
        Span <byte> h3 = hex3.FromHex();
        Span <byte> o1 = new byte[crypto.BlockSize];

        crypto.Encrypt(h1, o1);
        Assert.IsTrue(o1.SequenceEqual(h2));

        crypto.Encrypt(h1, o1);
        Assert.IsTrue(o1.SequenceEqual(h2));

        Span <byte> t = h1;

        for (int i = 0; i < 1000000; ++i)
        {
            crypto.Encrypt(t, o1);
            t = o1;
        }

        Assert.IsTrue(t.SequenceEqual(h3));

        crypto.Decrypt(h2, o1);
        Assert.IsTrue(o1.SequenceEqual(h1));

        crypto.Decrypt(h2, o1);
        Assert.IsTrue(o1.SequenceEqual(h1));

        t = h3;
        for (int i = 0; i < 1000000; ++i)
        {
            crypto.Decrypt(t, o1);
            t = o1;
        }
        Assert.IsTrue(t.SequenceEqual(h1));

        crypto.Dispose();
    }
Example #4
0
        private void TestDecrypt(IBlockCrypto crypto, Span <byte> origin)
        {
            Span <byte> o = stackalloc byte[origin.Length];

            for (var i = 0; i < Max; ++i)
            {
                crypto.Decrypt(origin, o);
            }

            crypto.Dispose();
        }
Example #5
0
    private static void Test(IBlockCrypto crypto, string hex1, string hex2)
    {
        Assert.AreEqual(@"AES", crypto.Name);
        Assert.AreEqual(16, crypto.BlockSize);

        Span <byte> h1 = hex1.FromHex();
        Span <byte> h2 = hex2.FromHex();
        Span <byte> o1 = stackalloc byte[crypto.BlockSize];

        crypto.Encrypt(h1, o1);
        Assert.IsTrue(o1.SequenceEqual(h2));

        crypto.Encrypt(h1, o1);
        Assert.IsTrue(o1.SequenceEqual(h2));

        crypto.Decrypt(h2, o1);
        Assert.IsTrue(o1.SequenceEqual(h1));

        crypto.Decrypt(h2, o1);
        Assert.IsTrue(o1.SequenceEqual(h1));

        crypto.Dispose();
    }