Skip to content

Commit 4cdedf6

Browse files
committed
Use cryptographically secure random number generator.
Fixes CVE-2022-29245.
1 parent acda143 commit 4cdedf6

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/Renci.SshNet/Security/KeyExchangeECCurve25519.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using Renci.SshNet.Abstractions;
1+
using Renci.SshNet.Abstractions;
32
using Renci.SshNet.Common;
43
using Renci.SshNet.Messages.Transport;
54
using Renci.SshNet.Security.Chaos.NaCl;
@@ -46,9 +45,7 @@ public override void Start(Session session, KeyExchangeInitMessage message)
4645
var basepoint = new byte[MontgomeryCurve25519.PublicKeySizeInBytes];
4746
basepoint[0] = 9;
4847

49-
var rnd = new Random();
50-
_privateKey = new byte[MontgomeryCurve25519.PrivateKeySizeInBytes];
51-
rnd.NextBytes(_privateKey);
48+
_privateKey = CryptoAbstraction.GenerateRandom(MontgomeryCurve25519.PrivateKeySizeInBytes);
5249

5350
_clientExchangeValue = new byte[MontgomeryCurve25519.PublicKeySizeInBytes];
5451
MontgomeryOperations.scalarmult(_clientExchangeValue, 0, _privateKey, 0, basepoint, 0);

0 commit comments

Comments
 (0)