blob: 0919b4dea86f6ec90e22df65d8cb68ee1a279374 (
plain) (
blame)
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
|
using System;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Pqc.Crypto.Utilities;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Pqc.Crypto.Saber
{
public class SaberKemGenerator
: IEncapsulatedSecretGenerator
{
// the source of randomness
private SecureRandom sr;
public SaberKemGenerator(SecureRandom random)
{
this.sr = random;
}
public ISecretWithEncapsulation GenerateEncapsulated(AsymmetricKeyParameter recipientKey)
{
SaberPublicKeyParameters key = (SaberPublicKeyParameters) recipientKey;
SABEREngine engine = key.GetParameters().GetEngine();
byte[] cipher_text = new byte[engine.GetCipherTextSize()];
byte[] sessionKey = new byte[engine.GetSessionKeySize()];
engine.crypto_kem_enc(cipher_text, sessionKey, key.PublicKey, sr);
return new SecretWithEncapsulationImpl(sessionKey, cipher_text);
}
}
}
|