blob: 1407f74a331fac43fc5b87cc173c5c4e2aa25d9f (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
namespace Org.BouncyCastle.Pqc.Crypto.Saber
{
public class SaberKeyPairGenerator
: IAsymmetricCipherKeyPairGenerator
{
private SaberKeyGenerationParameters saberParams;
private int l;
private SecureRandom random;
private void Initialize(
KeyGenerationParameters param)
{
this.saberParams = (SaberKeyGenerationParameters)param;
this.random = param.Random;
this.l = this.saberParams.Parameters.L;
}
private AsymmetricCipherKeyPair GenKeyPair()
{
SaberEngine engine = saberParams.Parameters.Engine;
byte[] sk = new byte[engine.GetPrivateKeySize()];
byte[] pk = new byte[engine.GetPublicKeySize()];
engine.crypto_kem_keypair(pk, sk, random);
SaberPublicKeyParameters pubKey = new SaberPublicKeyParameters(saberParams.Parameters, pk);
SaberPrivateKeyParameters privKey = new SaberPrivateKeyParameters(saberParams.Parameters, sk);
return new AsymmetricCipherKeyPair(pubKey, privKey);
}
public void Init(KeyGenerationParameters param)
{
this.Initialize(param);
}
public AsymmetricCipherKeyPair GenerateKeyPair()
{
return GenKeyPair();
}
}
}
|