AesCipherBenchmarks.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using BenchmarkDotNet.Attributes;
  2. using Renci.SshNet.Security.Cryptography.Ciphers;
  3. using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
  4. namespace Renci.SshNet.Benchmarks.Security.Cryptography.Ciphers
  5. {
  6. [MemoryDiagnoser]
  7. public class AesCipherBenchmarks
  8. {
  9. private readonly byte[] _key;
  10. private readonly byte[] _iv;
  11. private readonly byte[] _data;
  12. public AesCipherBenchmarks()
  13. {
  14. _key = new byte[32];
  15. _iv = new byte[16];
  16. _data = new byte[256];
  17. Random random = new(Seed: 12345);
  18. random.NextBytes(_key);
  19. random.NextBytes(_iv);
  20. random.NextBytes(_data);
  21. }
  22. [Benchmark]
  23. public byte[] Encrypt_CBC()
  24. {
  25. return new AesCipher(_key, new CbcCipherMode(_iv), null).Encrypt(_data);
  26. }
  27. [Benchmark]
  28. public byte[] Decrypt_CBC()
  29. {
  30. return new AesCipher(_key, new CbcCipherMode(_iv), null).Decrypt(_data);
  31. }
  32. }
  33. }