Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 //[Theory, MemberData(nameof(DecryptTestVectors_Individual))]
 public static void Decrypt_Individual(EncryptionTestVector tv)
 {
     Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateEcbDecryptor(tv.Key, true));
 }
Ejemplo n.º 3
0
 public static void Decrypt()
 {
     Common.DecryptCipherTest(DecryptTestVectors, (key, iv) => Aes.CreateEcbDecryptor(key, true));
 }
Ejemplo n.º 4
0
 public static void DecryptMultiIntrinsics()
 {
     Common.DecryptCipherTest(DecryptMultiTestVectors, (key, iv) => Aes.CreateEcbDecryptor(key));
 }
Ejemplo n.º 5
0
 public static void DecryptMultiIntrinsics(EncryptionTestVector tv)
 {
     Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateEcbDecryptor(tv.Key));
 }