KeyExchangeDhGroupExchangeGroup.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using Renci.SshNet.Common;
  3. namespace Renci.SshNet.Messages.Transport
  4. {
  5. /// <summary>
  6. /// Represents SSH_MSG_KEX_DH_GEX_GROUP message.
  7. /// </summary>
  8. [Message("SSH_MSG_KEX_DH_GEX_GROUP", MessageNumber)]
  9. public class KeyExchangeDhGroupExchangeGroup : Message
  10. {
  11. internal const byte MessageNumber = 31;
  12. #if TUNING
  13. private byte[] _safePrime;
  14. private byte[] _subGroup;
  15. #endif
  16. /// <summary>
  17. /// Gets or sets the safe prime.
  18. /// </summary>
  19. /// <value>
  20. /// The safe prime.
  21. /// </value>
  22. #if TUNING
  23. public BigInteger SafePrime
  24. {
  25. get { return _safePrime.ToBigInteger(); }
  26. }
  27. #else
  28. public BigInteger SafePrime { get; private set; }
  29. #endif
  30. /// <summary>
  31. /// Gets or sets the generator for subgroup in GF(p).
  32. /// </summary>
  33. /// <value>
  34. /// The sub group.
  35. /// </value>
  36. #if TUNING
  37. public BigInteger SubGroup
  38. {
  39. get { return _subGroup.ToBigInteger(); }
  40. }
  41. #else
  42. public BigInteger SubGroup { get; private set; }
  43. #endif
  44. #if TUNING
  45. /// <summary>
  46. /// Gets the size of the message in bytes.
  47. /// </summary>
  48. /// <value>
  49. /// The size of the messages in bytes.
  50. /// </value>
  51. protected override int BufferCapacity
  52. {
  53. get
  54. {
  55. var capacity = base.BufferCapacity;
  56. capacity += 4; // SafePrime length
  57. capacity += _safePrime.Length; // SafePrime
  58. capacity += 4; // SubGroup length
  59. capacity += _subGroup.Length; // SubGroup
  60. return capacity;
  61. }
  62. }
  63. #endif
  64. /// <summary>
  65. /// Called when type specific data need to be loaded.
  66. /// </summary>
  67. protected override void LoadData()
  68. {
  69. #if TUNING
  70. _safePrime = ReadBinary();
  71. _subGroup = ReadBinary();
  72. #else
  73. SafePrime = ReadBigInt();
  74. SubGroup = ReadBigInt();
  75. #endif
  76. }
  77. /// <summary>
  78. /// Called when type specific data need to be saved.
  79. /// </summary>
  80. protected override void SaveData()
  81. {
  82. #if TUNING
  83. WriteBinaryString(_safePrime);
  84. WriteBinaryString(_subGroup);
  85. #else
  86. Write(SafePrime);
  87. Write(SubGroup);
  88. #endif
  89. }
  90. }
  91. }