-
-
Notifications
You must be signed in to change notification settings - Fork 979
Expand file tree
/
Copy pathKeyExchangeMLKem768X25519Sha256.BclImpl.cs
More file actions
36 lines (31 loc) · 1.06 KB
/
KeyExchangeMLKem768X25519Sha256.BclImpl.cs
File metadata and controls
36 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Security.Cryptography;
namespace Renci.SshNet.Security
{
internal sealed partial class KeyExchangeMLKem768X25519Sha256
{
private sealed class MLKemBclImpl : Impl
{
private MLKem _mlkem;
public override byte[] GenerateClientPublicKey()
{
_mlkem = MLKem.GenerateKey(MLKemAlgorithm.MLKem768);
return _mlkem.ExportEncapsulationKey();
}
public override byte[] CalculateAgreement(byte[] serverPublicKey)
{
var mlkemSecret = new byte[MLKemAlgorithm.MLKem768.SharedSecretSizeInBytes];
_mlkem.Decapsulate(serverPublicKey.AsSpan(0, MLKemAlgorithm.MLKem768.CiphertextSizeInBytes), mlkemSecret);
return mlkemSecret;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_mlkem?.Dispose();
}
base.Dispose(disposing);
}
}
}
}