Skip to content

Commit f72b379

Browse files
committed
Add support for sntrup761x25519Sha512 key exchange method (sshnet#1562)
1 parent 2e68828 commit f72b379

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

src/Renci.SshNet/ConnectionInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy
349349

350350
KeyExchangeAlgorithms = new Dictionary<string, Func<IKeyExchange>>
351351
{
352+
{ "mlkem768x25519-sha256", () => new KeyExchangeMLKem768X25519Sha256() },
352353
{ "sntrup761x25519-sha512", () => new KeyExchangeSNtruP761X25519Sha512() },
353354
{ "[email protected]", () => new KeyExchangeSNtruP761X25519Sha512() },
354355
{ "curve25519-sha256", () => new KeyExchangeECCurve25519() },

src/Renci.SshNet/Security/KeyExchangeSNtruP761X25519Sha512.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ private void HandleServerEcdhReply(byte[] hostKey, byte[] serverExchangeValue, b
114114
_hostKey = hostKey;
115115
_signature = signature;
116116

117+
<<<<<<<< HEAD:src/Renci.SshNet/Security/KeyExchangeSNtruP761X25519Sha512.cs
117118
if (serverExchangeValue.Length != _sntrup761Extractor.EncapsulationLength + X25519PublicKeyParameters.KeySize)
119+
========
120+
if (serverExchangeValue.Length != _mlkemDecapsulator.EncapsulationLength + X25519PublicKeyParameters.KeySize)
121+
>>>>>>>> 9f21a396 (Add support for sntrup761x25519Sha512 key exchange method (#1562)):src/Renci.SshNet/Security/KeyExchangeMLKem768X25519Sha256.cs
118122
{
119123
throw new SshConnectionException(
120124
string.Format(CultureInfo.CurrentCulture, "Bad Q_S length: {0}.", serverExchangeValue.Length),

test/Renci.SshNet.IntegrationTests/KeyExchangeAlgorithmTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,37 @@ public void SNtruP761X25519Sha512OpenSsh()
5353
}
5454
}
5555

56+
[TestMethod]
57+
[Ignore]
58+
public void SNtruP761X25519Sha512()
59+
{
60+
_remoteSshdConfig.ClearKeyExchangeAlgorithms()
61+
.AddKeyExchangeAlgorithm(KeyExchangeAlgorithm.SNtruP761X25519Sha512)
62+
.Update()
63+
.Restart();
64+
65+
using (var client = new SshClient(_connectionInfoFactory.Create()))
66+
{
67+
client.Connect();
68+
client.Disconnect();
69+
}
70+
}
71+
72+
[TestMethod]
73+
public void SNtruP761X25519Sha512OpenSsh()
74+
{
75+
_remoteSshdConfig.ClearKeyExchangeAlgorithms()
76+
.AddKeyExchangeAlgorithm(KeyExchangeAlgorithm.SNtruP761X25519Sha512OpenSsh)
77+
.Update()
78+
.Restart();
79+
80+
using (var client = new SshClient(_connectionInfoFactory.Create()))
81+
{
82+
client.Connect();
83+
client.Disconnect();
84+
}
85+
}
86+
5687
[TestMethod]
5788
public void Curve25519Sha256()
5889
{

test/Renci.SshNet.TestTools.OpenSSH/KeyExchangeAlgorithm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public sealed class KeyExchangeAlgorithm
1616
public static readonly KeyExchangeAlgorithm Curve25519Sha256Libssh = new KeyExchangeAlgorithm("[email protected]");
1717
public static readonly KeyExchangeAlgorithm SNtruP761X25519Sha512 = new KeyExchangeAlgorithm("sntrup761x25519-sha512");
1818
public static readonly KeyExchangeAlgorithm SNtruP761X25519Sha512OpenSsh = new KeyExchangeAlgorithm("[email protected]");
19+
public static readonly KeyExchangeAlgorithm MLKem768X25519Sha256 = new KeyExchangeAlgorithm("mlkem768x25519-sha256");
1920

2021
public KeyExchangeAlgorithm(string name)
2122
{

0 commit comments

Comments
 (0)