From 79c0f90db3038e7530bf80cfca729b6cce87097d Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Tue, 26 Sep 2017 21:57:37 +0200 Subject: [PATCH] Modify our DH kex to generate a private component that is twice the size of the hash that a given algorithm produces, with a minimum of 1024 bits. Fixes issue #304. Avoid using TryParse in diffie-hellman-group1-sha1 and diffie-hellman-group14-sha1. Improve test coverage. --- ...KeyExchangeDiffieHellmanGroup14Sha1Test.cs | 53 +++++++++++++++- .../KeyExchangeDiffieHellmanGroup1Sha1Test.cs | 61 +++++++++---------- src/Renci.SshNet/Renci.SshNet.csproj | 1 + .../Security/KeyExchangeDiffieHellman.cs | 26 +++++--- .../KeyExchangeDiffieHellmanGroup14Sha1.cs | 37 +++++++++-- .../KeyExchangeDiffieHellmanGroup1Sha1.cs | 23 +++++-- ...yExchangeDiffieHellmanGroupExchangeSha1.cs | 13 +++- ...xchangeDiffieHellmanGroupExchangeSha256.cs | 13 +++- ...changeDiffieHellmanGroupExchangeShaBase.cs | 5 +- .../KeyExchangeDiffieHellmanGroupSha1.cs | 14 ++++- 10 files changed, 185 insertions(+), 61 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs index f4fcb91f..4f0ef37a 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs @@ -1,13 +1,60 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Security; using Renci.SshNet.Tests.Common; namespace Renci.SshNet.Tests.Classes.Security { - /// - /// Represents "diffie-hellman-group14-sha1" algorithm implementation. - /// [TestClass] public class KeyExchangeDiffieHellmanGroup14Sha1Test : TestBase { + private static readonly byte[] SecondOkleyGroup = + { + 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, + 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, + 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, 0xcc, 0x74, 0x02, 0x0b, 0xbe, 0xa6, + 0x3b, 0x13, 0x9b, 0x22, 0x51, 0x4a, 0x08, 0x79, 0x8e, 0x34, 0x04, 0xdd, + 0xef, 0x95, 0x19, 0xb3, 0xcd, 0x3a, 0x43, 0x1b, 0x30, 0x2b, 0x0a, 0x6d, + 0xf2, 0x5f, 0x14, 0x37, 0x4f, 0xe1, 0x35, 0x6d, 0x6d, 0x51, 0xc2, 0x45, + 0xe4, 0x85, 0xb5, 0x76, 0x62, 0x5e, 0x7e, 0xc6, 0xf4, 0x4c, 0x42, 0xe9, + 0xa6, 0x37, 0xed, 0x6b, 0x0b, 0xff, 0x5c, 0xb6, 0xf4, 0x06, 0xb7, 0xed, + 0xee, 0x38, 0x6b, 0xfb, 0x5a, 0x89, 0x9f, 0xa5, 0xae, 0x9f, 0x24, 0x11, + 0x7c, 0x4b, 0x1f, 0xe6, 0x49, 0x28, 0x66, 0x51, 0xec, 0xe4, 0x5b, 0x3d, + 0xc2, 0x00, 0x7c, 0xb8, 0xa1, 0x63, 0xbf, 0x05, 0x98, 0xda, 0x48, 0x36, + 0x1c, 0x55, 0xd3, 0x9a, 0x69, 0x16, 0x3f, 0xa8, 0xfd, 0x24, 0xcf, 0x5f, + 0x83, 0x65, 0x5d, 0x23, 0xdc, 0xa3, 0xad, 0x96, 0x1c, 0x62, 0xf3, 0x56, + 0x20, 0x85, 0x52, 0xbb, 0x9e, 0xd5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6d, + 0x67, 0x0c, 0x35, 0x4e, 0x4a, 0xbc, 0x98, 0x04, 0xf1, 0x74, 0x6c, 0x08, + 0xca, 0x18, 0x21, 0x7c, 0x32, 0x90, 0x5e, 0x46, 0x2e, 0x36, 0xce, 0x3b, + 0xe3, 0x9e, 0x77, 0x2c, 0x18, 0x0e, 0x86, 0x03, 0x9b, 0x27, 0x83, 0xa2, + 0xec, 0x07, 0xa2, 0x8f, 0xb5, 0xc5, 0x5d, 0xf0, 0x6f, 0x4c, 0x52, 0xc9, + 0xde, 0x2b, 0xcb, 0xf6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7c, + 0xea, 0x95, 0x6a, 0xe5, 0x15, 0xd2, 0x26, 0x18, 0x98, 0xfa, 0x05, 0x10, + 0x15, 0x72, 0x8e, 0x5a, 0x8a, 0xac, 0xaa, 0x68, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff + }; + + private KeyExchangeDiffieHellmanGroup14Sha1 _group14; + + protected override void OnInit() + { + base.OnInit(); + + _group14 = new KeyExchangeDiffieHellmanGroup14Sha1(); + } + + [TestMethod] + public void GroupPrimeShouldBeSecondOakleyGroup() + { + var bytes = _group14.GroupPrime.ToByteArray().Reverse(); + Assert.IsTrue(SecondOkleyGroup.IsEqualTo(bytes)); + } + + [TestMethod] + public void NameShouldBeDiffieHellmanGroup14Sha1() + { + Assert.AreEqual("diffie-hellman-group14-sha1", _group14.Name); + } } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs index 150f27c8..9cbaaba2 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs @@ -5,48 +5,47 @@ using Renci.SshNet.Tests.Common; namespace Renci.SshNet.Tests.Classes.Security { - /// - ///This is a test class for KeyExchangeDiffieHellmanGroup1Sha1Test and is intended - ///to contain all KeyExchangeDiffieHellmanGroup1Sha1Test Unit Tests - /// [TestClass] public class KeyExchangeDiffieHellmanGroup1Sha1Test : TestBase { - /// - ///A test for KeyExchangeDiffieHellmanGroup1Sha1 Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyExchangeDiffieHellmanGroup1Sha1ConstructorTest() + private static readonly byte[] SecondOkleyGroup = + { + 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, + 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, + 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, 0xcc, 0x74, 0x02, 0x0b, 0xbe, 0xa6, + 0x3b, 0x13, 0x9b, 0x22, 0x51, 0x4a, 0x08, 0x79, 0x8e, 0x34, 0x04, 0xdd, + 0xef, 0x95, 0x19, 0xb3, 0xcd, 0x3a, 0x43, 0x1b, 0x30, 0x2b, 0x0a, 0x6d, + 0xf2, 0x5f, 0x14, 0x37, 0x4f, 0xe1, 0x35, 0x6d, 0x6d, 0x51, 0xc2, 0x45, + 0xe4, 0x85, 0xb5, 0x76, 0x62, 0x5e, 0x7e, 0xc6, 0xf4, 0x4c, 0x42, 0xe9, + 0xa6, 0x37, 0xed, 0x6b, 0x0b, 0xff, 0x5c, 0xb6, 0xf4, 0x06, 0xb7, 0xed, + 0xee, 0x38, 0x6b, 0xfb, 0x5a, 0x89, 0x9f, 0xa5, 0xae, 0x9f, 0x24, 0x11, + 0x7c, 0x4b, 0x1f, 0xe6, 0x49, 0x28, 0x66, 0x51, 0xec, 0xe6, 0x53, 0x81, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff + }; + + private KeyExchangeDiffieHellmanGroup1Sha1 _group1; + + protected override void OnInit() { - KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); - Assert.Inconclusive("TODO: Implement code to verify target"); + base.OnInit(); + + _group1 = new KeyExchangeDiffieHellmanGroup1Sha1(); } - /// - ///A test for GroupPrime - /// [TestMethod] - [Ignore] // placeholder for actual test - public void GroupPrimeTest() + public void GroupPrimeShouldBeSecondOakleyGroup() { - KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.GroupPrime; - Assert.Inconclusive("Verify the correctness of this test method."); + var bytes = _group1.GroupPrime.ToByteArray().Reverse(); + Assert.IsTrue(SecondOkleyGroup.IsEqualTo(bytes)); + + SecondOkleyGroup.Reverse().DebugPrint(); } - /// - ///A test for Name - /// [TestMethod] - [Ignore] // placeholder for actual test - public void NameTest() + public void NameShouldBeDiffieHellmanGroup1Sha1() { - KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); + Assert.AreEqual("diffie-hellman-group1-sha1", _group1.Name); } } -} +} \ No newline at end of file diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 7dd4c67f..0598d18c 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -47,6 +47,7 @@ + diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellman.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellman.cs index 7ade9379..fa53d36a 100644 --- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellman.cs +++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellman.cs @@ -8,7 +8,7 @@ namespace Renci.SshNet.Security /// /// Represents base class for Diffie Hellman key exchange algorithm /// - public abstract class KeyExchangeDiffieHellman : KeyExchange + internal abstract class KeyExchangeDiffieHellman : KeyExchange { /// /// Specifies key exchange group number. @@ -43,7 +43,7 @@ namespace Renci.SshNet.Security /// /// Specifies random generated number. /// - protected BigInteger _randomValue; + protected BigInteger _privateExponent; /// /// Specifies host key data. @@ -55,6 +55,14 @@ namespace Renci.SshNet.Security /// protected byte[] _signature; + /// + /// Gets the size, in bits, of the computed hash code. + /// + /// + /// The size, in bits, of the computed hash code. + /// + protected abstract int HashSize { get; } + /// /// Validates the exchange hash. /// @@ -102,14 +110,16 @@ namespace Renci.SshNet.Security if (_prime.IsZero) throw new ArgumentNullException("_prime"); - var bitLength = _prime.BitLength; + // generate private component that is twice the hash size (RFC 4419) with a minimum + // of 1024 bits (whatever is less) + var privateComponentSize = Math.Max(HashSize * 2, 1024); do { - _randomValue = BigInteger.Random(bitLength); - - _clientExchangeValue = BigInteger.ModPow(_group, _randomValue, _prime); - + // create private component + _privateExponent = BigInteger.Random(privateComponentSize); + // generate public component + _clientExchangeValue = BigInteger.ModPow(_group, _privateExponent, _prime); } while (_clientExchangeValue < 1 || _clientExchangeValue > (_prime - 1)); } @@ -123,7 +133,7 @@ namespace Renci.SshNet.Security { _serverExchangeValue = serverExchangeValue; _hostKey = hostKey; - SharedKey = BigInteger.ModPow(serverExchangeValue, _randomValue, _prime); + SharedKey = BigInteger.ModPow(serverExchangeValue, _privateExponent, _prime); _signature = signature; } } diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup14Sha1.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup14Sha1.cs index ad714f30..ec7a237d 100644 --- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup14Sha1.cs +++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup14Sha1.cs @@ -1,5 +1,4 @@ using Renci.SshNet.Common; -using System.Globalization; namespace Renci.SshNet.Security { @@ -8,7 +7,35 @@ namespace Renci.SshNet.Security /// internal class KeyExchangeDiffieHellmanGroup14Sha1 : KeyExchangeDiffieHellmanGroupSha1 { - private const string SecondOkleyGroup = "00FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF"; + /// + /// https://tools.ietf.org/html/rfc2409#section-6.2 + /// + private static readonly byte[] SecondOkleyGroupReversed = + { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x68, 0xaa, 0xac, 0x8a, + 0x5a, 0x8e, 0x72, 0x15, 0x10, 0x05, 0xfa, 0x98, 0x18, 0x26, 0xd2, 0x15, + 0xe5, 0x6a, 0x95, 0xea, 0x7c, 0x49, 0x95, 0x39, 0x18, 0x17, 0x58, 0x95, + 0xf6, 0xcb, 0x2b, 0xde, 0xc9, 0x52, 0x4c, 0x6f, 0xf0, 0x5d, 0xc5, 0xb5, + 0x8f, 0xa2, 0x07, 0xec, 0xa2, 0x83, 0x27, 0x9b, 0x03, 0x86, 0x0e, 0x18, + 0x2c, 0x77, 0x9e, 0xe3, 0x3b, 0xce, 0x36, 0x2e, 0x46, 0x5e, 0x90, 0x32, + 0x7c, 0x21, 0x18, 0xca, 0x08, 0x6c, 0x74, 0xf1, 0x04, 0x98, 0xbc, 0x4a, + 0x4e, 0x35, 0x0c, 0x67, 0x6d, 0x96, 0x96, 0x70, 0x07, 0x29, 0xd5, 0x9e, + 0xbb, 0x52, 0x85, 0x20, 0x56, 0xf3, 0x62, 0x1c, 0x96, 0xad, 0xa3, 0xdc, + 0x23, 0x5d, 0x65, 0x83, 0x5f, 0xcf, 0x24, 0xfd, 0xa8, 0x3f, 0x16, 0x69, + 0x9a, 0xd3, 0x55, 0x1c, 0x36, 0x48, 0xda, 0x98, 0x05, 0xbf, 0x63, 0xa1, + 0xb8, 0x7c, 0x00, 0xc2, 0x3d, 0x5b, 0xe4, 0xec, 0x51, 0x66, 0x28, 0x49, + 0xe6, 0x1f, 0x4b, 0x7c, 0x11, 0x24, 0x9f, 0xae, 0xa5, 0x9f, 0x89, 0x5a, + 0xfb, 0x6b, 0x38, 0xee, 0xed, 0xb7, 0x06, 0xf4, 0xb6, 0x5c, 0xff, 0x0b, + 0x6b, 0xed, 0x37, 0xa6, 0xe9, 0x42, 0x4c, 0xf4, 0xc6, 0x7e, 0x5e, 0x62, + 0x76, 0xb5, 0x85, 0xe4, 0x45, 0xc2, 0x51, 0x6d, 0x6d, 0x35, 0xe1, 0x4f, + 0x37, 0x14, 0x5f, 0xf2, 0x6d, 0x0a, 0x2b, 0x30, 0x1b, 0x43, 0x3a, 0xcd, + 0xb3, 0x19, 0x95, 0xef, 0xdd, 0x04, 0x34, 0x8e, 0x79, 0x08, 0x4a, 0x51, + 0x22, 0x9b, 0x13, 0x3b, 0xa6, 0xbe, 0x0b, 0x02, 0x74, 0xcc, 0x67, 0x8a, + 0x08, 0x4e, 0x02, 0x29, 0xd1, 0x1c, 0xdc, 0x80, 0x8b, 0x62, 0xc6, 0xc4, + 0x34, 0xc2, 0x68, 0x21, 0xa2, 0xda, 0x0f, 0xc9, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0x00 + }; /// /// Gets algorithm name. @@ -28,10 +55,8 @@ namespace Renci.SshNet.Security { get { - BigInteger prime; - BigInteger.TryParse(SecondOkleyGroup, NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out prime); - return prime; + return new BigInteger(SecondOkleyGroupReversed); } } } -} +} \ No newline at end of file diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup1Sha1.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup1Sha1.cs index 65e05ad1..3a8de7f4 100644 --- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup1Sha1.cs +++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup1Sha1.cs @@ -1,14 +1,27 @@ using Renci.SshNet.Common; -using System.Globalization; namespace Renci.SshNet.Security { /// /// Represents "diffie-hellman-group1-sha1" algorithm implementation. /// - public class KeyExchangeDiffieHellmanGroup1Sha1 : KeyExchangeDiffieHellmanGroupSha1 + internal class KeyExchangeDiffieHellmanGroup1Sha1 : KeyExchangeDiffieHellmanGroupSha1 { - private const string SecondOkleyGroup = @"00FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF"; + private static readonly byte[] SecondOkleyGroupReversed = + { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0x53, 0xe6, 0xec, + 0x51, 0x66, 0x28, 0x49, 0xe6, 0x1f, 0x4b, 0x7c, 0x11, 0x24, 0x9f, 0xae, + 0xa5, 0x9f, 0x89, 0x5a, 0xfb, 0x6b, 0x38, 0xee, 0xed, 0xb7, 0x06, 0xf4, + 0xb6, 0x5c, 0xff, 0x0b, 0x6b, 0xed, 0x37, 0xa6, 0xe9, 0x42, 0x4c, 0xf4, + 0xc6, 0x7e, 0x5e, 0x62, 0x76, 0xb5, 0x85, 0xe4, 0x45, 0xc2, 0x51, 0x6d, + 0x6d, 0x35, 0xe1, 0x4f, 0x37, 0x14, 0x5f, 0xf2, 0x6d, 0x0a, 0x2b, 0x30, + 0x1b, 0x43, 0x3a, 0xcd, 0xb3, 0x19, 0x95, 0xef, 0xdd, 0x04, 0x34, 0x8e, + 0x79, 0x08, 0x4a, 0x51, 0x22, 0x9b, 0x13, 0x3b, 0xa6, 0xbe, 0x0b, 0x02, + 0x74, 0xcc, 0x67, 0x8a, 0x08, 0x4e, 0x02, 0x29, 0xd1, 0x1c, 0xdc, 0x80, + 0x8b, 0x62, 0xc6, 0xc4, 0x34, 0xc2, 0x68, 0x21, 0xa2, 0xda, 0x0f, 0xc9, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00 + }; /// /// Gets algorithm name. @@ -28,9 +41,7 @@ namespace Renci.SshNet.Security { get { - BigInteger prime; - BigInteger.TryParse(SecondOkleyGroup, NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out prime); - return prime; + return new BigInteger(SecondOkleyGroupReversed); } } } diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeSha1.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeSha1.cs index d7bcff03..fc1a18a6 100644 --- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeSha1.cs +++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeSha1.cs @@ -3,7 +3,7 @@ /// /// Represents "diffie-hellman-group-exchange-sha1" algorithm implementation. /// - public class KeyExchangeDiffieHellmanGroupExchangeSha1 : KeyExchangeDiffieHellmanGroupExchangeShaBase + internal class KeyExchangeDiffieHellmanGroupExchangeSha1 : KeyExchangeDiffieHellmanGroupExchangeShaBase { /// /// Gets algorithm name. @@ -12,5 +12,16 @@ { get { return "diffie-hellman-group-exchange-sha1"; } } + + /// + /// Gets the size, in bits, of the computed hash code. + /// + /// + /// The size, in bits, of the computed hash code. + /// + protected override int HashSize + { + get { return 160; } + } } } diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeSha256.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeSha256.cs index 0792e397..dca2de71 100644 --- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeSha256.cs +++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeSha256.cs @@ -5,7 +5,7 @@ namespace Renci.SshNet.Security /// /// Represents "diffie-hellman-group-exchange-sha256" algorithm implementation. /// - public class KeyExchangeDiffieHellmanGroupExchangeSha256 : KeyExchangeDiffieHellmanGroupExchangeShaBase + internal class KeyExchangeDiffieHellmanGroupExchangeSha256 : KeyExchangeDiffieHellmanGroupExchangeShaBase { /// /// Gets algorithm name. @@ -15,6 +15,17 @@ namespace Renci.SshNet.Security get { return "diffie-hellman-group-exchange-sha256"; } } + /// + /// Gets the size, in bits, of the computed hash code. + /// + /// + /// The size, in bits, of the computed hash code. + /// + protected override int HashSize + { + get { return 256; } + } + /// /// Hashes the specified data bytes. /// diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeShaBase.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeShaBase.cs index 6b77c2d9..2ccdf731 100644 --- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeShaBase.cs +++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchangeShaBase.cs @@ -1,12 +1,11 @@ -using Renci.SshNet.Messages; -using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Messages.Transport; namespace Renci.SshNet.Security { /// /// Base class for "diffie-hellman-group-exchange" algorithms. /// - public abstract class KeyExchangeDiffieHellmanGroupExchangeShaBase : KeyExchangeDiffieHellman + internal abstract class KeyExchangeDiffieHellmanGroupExchangeShaBase : KeyExchangeDiffieHellman { private const int MinimumGroupSize = 1024; private const int PreferredGroupSize = 1024; diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupSha1.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupSha1.cs index 638c44bd..eb2a0cb1 100644 --- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupSha1.cs +++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupSha1.cs @@ -1,6 +1,5 @@ using System; using Renci.SshNet.Common; -using Renci.SshNet.Messages; using Renci.SshNet.Messages.Transport; namespace Renci.SshNet.Security @@ -8,7 +7,7 @@ namespace Renci.SshNet.Security /// /// Represents "diffie-hellman-group1-sha1" algorithm implementation. /// - public abstract class KeyExchangeDiffieHellmanGroupSha1 : KeyExchangeDiffieHellman + internal abstract class KeyExchangeDiffieHellmanGroupSha1 : KeyExchangeDiffieHellman { /// /// Gets the group prime. @@ -18,6 +17,17 @@ namespace Renci.SshNet.Security /// public abstract BigInteger GroupPrime { get; } + /// + /// Gets the size, in bits, of the computed hash code. + /// + /// + /// The size, in bits, of the computed hash code. + /// + protected override int HashSize + { + get { return 160; } + } + /// /// Calculates key exchange hash value. ///