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

DilithiumSigner

using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; using System; namespace Org.BouncyCastle.Pqc.Crypto.Crystals.Dilithium { [Obsolete("Use ML-DSA instead")] public class DilithiumSigner : IMessageSigner { private DilithiumPrivateKeyParameters privKey; private DilithiumPublicKeyParameters pubKey; private SecureRandom random; public void Init(bool forSigning, ICipherParameters param) { if (forSigning) { ParametersWithRandom parametersWithRandom = param as ParametersWithRandom; if (parametersWithRandom != null) { privKey = (DilithiumPrivateKeyParameters)parametersWithRandom.Parameters; random = parametersWithRandom.Random; } else { privKey = (DilithiumPrivateKeyParameters)param; random = null; } } else { pubKey = (DilithiumPublicKeyParameters)param; random = null; } } public byte[] GenerateSignature(byte[] message) { DilithiumEngine engine = privKey.Parameters.GetEngine(random); byte[] array = new byte[engine.CryptoBytes]; engine.Sign(array, array.Length, message, 0, message.Length, privKey.m_rho, privKey.m_k, privKey.m_tr, privKey.m_t0, privKey.m_s1, privKey.m_s2, true); return array; } public bool VerifySignature(byte[] message, byte[] signature) { return pubKey.Parameters.GetEngine(random).VerifyInternal(tr: DilithiumEngine.CalculatePublicKeyHash(pubKey.m_rho, pubKey.m_t1), sig: signature, siglen: signature.Length, msg: message, msgOff: 0, msgLen: message.Length, rho: pubKey.m_rho, encT1: pubKey.m_t1); } } }