From 4cdedf65247a0e720f0723bcd9edb773b3f2223f Mon Sep 17 00:00:00 2001 From: drieseng Date: Sun, 29 May 2022 16:59:38 +0200 Subject: [PATCH] Use cryptographically secure random number generator. Fixes CVE-2022-29245. --- src/Renci.SshNet/Security/KeyExchangeECCurve25519.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Renci.SshNet/Security/KeyExchangeECCurve25519.cs b/src/Renci.SshNet/Security/KeyExchangeECCurve25519.cs index 9de7af8fb..b7a318bb9 100644 --- a/src/Renci.SshNet/Security/KeyExchangeECCurve25519.cs +++ b/src/Renci.SshNet/Security/KeyExchangeECCurve25519.cs @@ -1,5 +1,4 @@ -using System; -using Renci.SshNet.Abstractions; +using Renci.SshNet.Abstractions; using Renci.SshNet.Common; using Renci.SshNet.Messages.Transport; using Renci.SshNet.Security.Chaos.NaCl; @@ -46,9 +45,7 @@ public override void Start(Session session, KeyExchangeInitMessage message) var basepoint = new byte[MontgomeryCurve25519.PublicKeySizeInBytes]; basepoint[0] = 9; - var rnd = new Random(); - _privateKey = new byte[MontgomeryCurve25519.PrivateKeySizeInBytes]; - rnd.NextBytes(_privateKey); + _privateKey = CryptoAbstraction.GenerateRandom(MontgomeryCurve25519.PrivateKeySizeInBytes); _clientExchangeValue = new byte[MontgomeryCurve25519.PublicKeySizeInBytes]; MontgomeryOperations.scalarmult(_clientExchangeValue, 0, _privateKey, 0, basepoint, 0);