Filip Filipovic
Filip Filipovic

Reputation: 149

DSA: generate p

I want to generate p for DSA algorithm. I found a 160-bit prime q and now i need to find p where q is a divisor of p-1. I did read answer here on similar question but i am not sure how to implement that algorithm (DSA: How to generate the subprime?), 6. step is confusing me. I did use this code, but its to slow when p is 2048-bits long.

public BigInteger GenerateP(BigInteger q)
    {
        Random random = new Random();
        BigInteger p = BigInteger.Zero;

        do
        {
            BigInteger T = GenerateQ(108); //228
            p = q * T;
            Console.WriteLine(T.ToByteArray().Length);
            Console.WriteLine(p.ToByteArray().Length);
        } while (!p.IsEven);

        p = p + BigInteger.One;

        if (MillerRabinTest(10, p) != true)
        {
            p = GetNearestPrimeP(p, q);
        }

        return p;
    }

public BigInteger GetNearestPrimeP(BigInteger p, BigInteger q)
    {
        while (MillerRabinTest(10, p) == false)
        {
            p += q * 2;
        }
        return p;
    }

Upvotes: 1

Views: 168

Answers (0)

Related Questions