ED25519DigitalSignatureBenchmarks.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using BenchmarkDotNet.Attributes;
  2. using Renci.SshNet.Security;
  3. using Renci.SshNet.Security.Cryptography;
  4. namespace Renci.SshNet.Benchmarks.Security.Cryptography
  5. {
  6. [MemoryDiagnoser]
  7. public class ED25519DigitalSignatureBenchmarks
  8. {
  9. private readonly ED25519Key _key;
  10. private readonly byte[] _data;
  11. private readonly byte[] _signature;
  12. public ED25519DigitalSignatureBenchmarks()
  13. {
  14. _data = new byte[128];
  15. Random random = new(Seed: 12345);
  16. random.NextBytes(_data);
  17. using (var s = typeof(ED25519DigitalSignatureBenchmarks).Assembly.GetManifestResourceStream("Renci.SshNet.Benchmarks.Data.Key.OPENSSH.ED25519.txt"))
  18. {
  19. _key = (ED25519Key)new PrivateKeyFile(s!).Key;
  20. }
  21. _signature = new ED25519DigitalSignature(_key).Sign(_data);
  22. }
  23. [Benchmark]
  24. public byte[] Sign()
  25. {
  26. return new ED25519DigitalSignature(_key).Sign(_data);
  27. }
  28. [Benchmark]
  29. public bool Verify()
  30. {
  31. return new ED25519DigitalSignature(_key).Verify(_data, _signature);
  32. }
  33. }
  34. }