GenerateSafePrimes() static private method

static private GenerateSafePrimes ( int size, int certainty, SecureRandom random ) : Org.BouncyCastle.Math.BigInteger[]
size int
certainty int
random Org.BouncyCastle.Security.SecureRandom
return Org.BouncyCastle.Math.BigInteger[]
Exemplo n.º 1
0
        /**
         * which Generates the p and g values from the given parameters,
         * returning the ElGamalParameters object.
         * <p>
         * Note: can take a while...
         */
        public ElGamalParameters GenerateParameters()
        {
            //
            // find a safe prime p where p = 2*q + 1, where p and q are prime.
            //
            BigInteger[] safePrimes = DHParametersHelper.GenerateSafePrimes(size, certainty, random);

            BigInteger p = safePrimes[0];
            BigInteger q = safePrimes[1];

            BigInteger g;
            int        qLength = size - 1;

            //
            // calculate the generator g - the advantage of using the 2q+1
            // approach is that we know the prime factorisation of (p - 1)...
            //
            do
            {
                g = new BigInteger(qLength, random);
            }while (g.ModPow(BigInteger.Two, p).Equals(BigInteger.One) ||
                    g.ModPow(q, p).Equals(BigInteger.One));

            return(new ElGamalParameters(p, g));
        }
        public virtual DHParameters GenerateParameters()
        {
            BigInteger[] array = DHParametersHelper.GenerateSafePrimes(size, certainty, random);
            BigInteger   p     = array[0];
            BigInteger   q     = array[1];
            BigInteger   g     = DHParametersHelper.SelectGenerator(p, q, random);

            return(new DHParameters(p, g, q, BigInteger.Two, null));
        }
Exemplo n.º 3
0
        public ElGamalParameters GenerateParameters()
        {
            BigInteger[] array = DHParametersHelper.GenerateSafePrimes(this.size, this.certainty, this.random);
            BigInteger   p     = array[0];
            BigInteger   q     = array[1];
            BigInteger   g     = DHParametersHelper.SelectGenerator(p, q, this.random);

            return(new ElGamalParameters(p, g));
        }
        /**
         * which Generates the p and g values from the given parameters,
         * returning the ElGamalParameters object.
         * <p>
         * Note: can take a while...
         * </p>
         */
        public ElGamalParameters GenerateParameters()
        {
            //
            // find a safe prime p where p = 2*q + 1, where p and q are prime.
            //
            BigInteger[] safePrimes = DHParametersHelper.GenerateSafePrimes(size, certainty, random);

            BigInteger p = safePrimes[0];
            BigInteger q = safePrimes[1];
            BigInteger g = DHParametersHelper.SelectGenerator(p, q, random);

            return(new ElGamalParameters(p, g));
        }
Exemplo n.º 5
0
        /**
         * which Generates the p and g values from the given parameters,
         * returning the DHParameters object.
         * <p>
         * Note: can take a while...</p>
         */
        public virtual DHParameters GenerateParameters()
        {
            //
            // find a safe prime p where p = 2*q + 1, where p and q are prime.
            //
            IBigInteger[] safePrimes = DHParametersHelper.GenerateSafePrimes(size, certainty, random);

            IBigInteger p = safePrimes[0];
            IBigInteger q = safePrimes[1];
            IBigInteger g = DHParametersHelper.SelectGenerator(p, q, random);

            return(new DHParameters(p, g, q, BigInteger.Two, null));
        }