<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.1" />

MLKemKeyPairGenerator

using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; namespace Org.BouncyCastle.Crypto.Generators { public class MLKemKeyPairGenerator : IAsymmetricCipherKeyPairGenerator { private SecureRandom m_random; private MLKemParameters m_parameters; public void Init(KeyGenerationParameters parameters) { m_random = parameters.Random; m_parameters = ((MLKemKeyGenerationParameters)parameters).Parameters; } public AsymmetricCipherKeyPair GenerateKeyPair() { m_parameters.ParameterSet.GetEngine(m_random).GenerateKemKeyPair(out byte[] t, out byte[] rho, out byte[] s, out byte[] hpk, out byte[] nonce, out byte[] seed); MLKemPublicKeyParameters publicParameter = new MLKemPublicKeyParameters(m_parameters, t, rho); MLKemPrivateKeyParameters privateParameter = new MLKemPrivateKeyParameters(m_parameters, s, hpk, nonce, t, rho, seed); return new AsymmetricCipherKeyPair(publicParameter, privateParameter); } internal AsymmetricCipherKeyPair InternalGenerateKeyPair(byte[] d, byte[] z) { m_parameters.ParameterSet.GetEngine(null).GenerateKemKeyPairInternal(d, z, out byte[] t, out byte[] rho, out byte[] s, out byte[] hpk, out byte[] nonce, out byte[] seed); MLKemPublicKeyParameters publicParameter = new MLKemPublicKeyParameters(m_parameters, t, rho); MLKemPrivateKeyParameters privateParameter = new MLKemPrivateKeyParameters(m_parameters, s, hpk, nonce, t, rho, seed); return new AsymmetricCipherKeyPair(publicParameter, privateParameter); } } }