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

Org.BouncyCastle.Math.Raw.Mod

static class Mod
Modular inversion as implemented in this class is based on the paper "Fast constant-time gcd computation and modular inversion" by Daniel J. Bernstein and Bo-Yin Yang.
namespace Org.BouncyCastle.Math.Raw { internal static class Mod { public static void CheckedModOddInverse(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x, Span<uint> z); public static void CheckedModOddInverseVar(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x, Span<uint> z); public static uint Inverse32(uint d); public static ulong Inverse64(ulong d); public static uint ModOddInverse(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x, Span<uint> z); public static bool ModOddInverseVar(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x, Span<uint> z); public static uint ModOddIsCoprime(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x); public static bool ModOddIsCoprimeVar(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x); public static uint[] Random(SecureRandom random, uint[] p); public static void Random(SecureRandom random, ReadOnlySpan<uint> p, Span<uint> z); } }