HashInfo.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Security.Cryptography;
  3. using Renci.SshNet.Common;
  4. namespace Renci.SshNet
  5. {
  6. /// <summary>
  7. /// Holds information about key size and cipher to use.
  8. /// </summary>
  9. public class HashInfo
  10. {
  11. /// <summary>
  12. /// Gets the size of the key.
  13. /// </summary>
  14. /// <value>
  15. /// The size of the key.
  16. /// </value>
  17. public int KeySize { get; private set; }
  18. /// <summary>
  19. /// Gets a value indicating whether the MAC algorithm will use encrypt-then-MAC ordering.
  20. /// </summary>
  21. /// <value>
  22. /// <see langword="true"/> to enable encrypt-then-MAC, <see langword="false"/> to use encrypt-and-MAC.
  23. /// </value>
  24. public bool IsEncryptThenMAC { get; private set; }
  25. /// <summary>
  26. /// Gets the method for creating a <see cref="System.Security.Cryptography.HashAlgorithm"/> instance
  27. /// given a key.
  28. /// </summary>
  29. public Func<byte[], HashAlgorithm> HashAlgorithm { get; private set; }
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref="HashInfo"/> class.
  32. /// </summary>
  33. /// <param name="keySize">Size of the key.</param>
  34. /// <param name="hash">The hash algorithm to use for a given key.</param>
  35. /// <param name="isEncryptThenMAC"><see langword="true"/> to enable encrypt-then-MAC, <see langword="false"/> to use encrypt-and-MAC.</param>
  36. public HashInfo(int keySize, Func<byte[], HashAlgorithm> hash, bool isEncryptThenMAC = false)
  37. {
  38. KeySize = keySize;
  39. HashAlgorithm = key => hash(key.Take(KeySize / 8));
  40. IsEncryptThenMAC = isEncryptThenMAC;
  41. }
  42. }
  43. }