Ejemplo n.º 1
0
        //[Theory, MemberData(nameof(EncryptTestVectors_Individual))]
        public static void Encrypt_Individual(EncryptionTestVector tv)
        {
            Span <byte> key1 = tv.Key.AsSpan(0, 0x10);
            Span <byte> key2 = tv.Key.AsSpan(0x10, 0x10);

            Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateXtsEncryptor(key1, key2, tv.Iv, true));
        }
Ejemplo n.º 2
0
        private static void RegisterAesSequentialBenchmarks(MultiBenchmark bench)
        {
            var input  = new byte[BatchCipherBenchSize];
            var output = new byte[BatchCipherBenchSize];

            Func <double, string> resultPrinter = time => GetPerformanceString(time, BatchCipherBenchSize);

            // Skip the first benchmark set if we don't have AES-NI intrinsics
            for (int i = Aes.IsAesNiSupported() ? 0 : 1; i < 2; i++)
            {
                // Prefer .NET crypto on the second set
                string nameSuffix       = i == 1 ? "built-in " : string.Empty;
                bool   preferDotNetImpl = i == 1;

                RegisterCipher($"AES-ECB {nameSuffix}encrypt",
                               () => Aes.CreateEcbEncryptor(new byte[0x10], preferDotNetImpl));

                RegisterCipher($"AES-ECB {nameSuffix}decrypt",
                               () => Aes.CreateEcbDecryptor(new byte[0x10], preferDotNetImpl));

                RegisterCipher($"AES-CBC {nameSuffix}encrypt",
                               () => Aes.CreateCbcEncryptor(new byte[0x10], new byte[0x10], preferDotNetImpl));

                RegisterCipher($"AES-CBC {nameSuffix}decrypt",
                               () => Aes.CreateCbcDecryptor(new byte[0x10], new byte[0x10], preferDotNetImpl));

                RegisterCipher($"AES-CTR {nameSuffix}decrypt",
                               () => Aes.CreateCtrDecryptor(new byte[0x10], new byte[0x10], preferDotNetImpl));

                RegisterCipher($"AES-XTS {nameSuffix}encrypt",
                               () => Aes.CreateXtsEncryptor(new byte[0x10], new byte[0x10], new byte[0x10], preferDotNetImpl));

                RegisterCipher($"AES-XTS {nameSuffix}decrypt",
                               () => Aes.CreateXtsDecryptor(new byte[0x10], new byte[0x10], new byte[0x10], preferDotNetImpl));
            }

            void RegisterCipher(string name, Func <ICipher> cipherGenerator)
            {
                ICipher cipher = null;

                Action setup  = () => cipher = cipherGenerator();
                Action action = () => cipher.Transform(input, output);

                bench.Register(name, setup, action, resultPrinter);
            }
        }
Ejemplo n.º 3
0
 public static void EncryptIntrinsics()
 {
     Common.EncryptCipherTest(EncryptTestVectors,
                              (key, iv) => Aes.CreateXtsEncryptor(key.AsSpan(0, 0x10), key.AsSpan(0x10, 0x10), iv));
 }