Example #1
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);
            }
        }
Example #2
0
 //[Theory, MemberData(nameof(EncryptMultiTestVectors_Individual))]
 public static void EncryptMulti_Individual(EncryptionTestVector tv)
 {
     Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv, true));
 }
Example #3
0
 public static void Encrypt()
 {
     Common.EncryptCipherTest(EncryptTestVectors, (key, iv) => Aes.CreateCbcEncryptor(key, iv, true));
 }
Example #4
0
 public static void EncryptMultiIntrinsics()
 {
     Common.EncryptCipherTest(EncryptMultiTestVectors, (key, iv) => Aes.CreateCbcEncryptor(key, iv));
 }
Example #5
0
 public static void EncryptMultiIntrinsics(EncryptionTestVector tv)
 {
     Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv));
 }