10.1.1.3.433

Upload: waldemarvillamayor-venialbo

Post on 03-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 10.1.1.3.433

    1/5

    Constructive Methods for the Generation of

    Prime Numbers

    ( Submission to NESSIE )

    [Published in S. Murphy, Ed., Proc. of 2nd Open NESSIE Workshop, Egham,

    UK, September 1213, 2001.]

    Marc Joye1 and Pascal Paillier2

    1 Gemplus Card InternationalParc dActivites de Gemenos, 13881 Gemenos Cedex, France

    [email protected] http://www.geocities.com/MarcJoye/2

    Gemplus Card International34 rue Guynemer, 92447 Issy-les-Moulineaux, [email protected]

    http://www.gemplus.com/smart/

    Abstract. Public-key cryptography is rapidly becoming ubiquitous inmany aspects of electronic life. It is used to provide various securityservices such as data integrity, confidentiality, authentication and non-repudiation. Most public-key cryptographic methods require the gener-ation of random prime numbers. A naive solution to obtain a primenumber consists in randomly choosing a number and testing it for pri-mality. Such a solution is however not satisfactory in all respects as it isnot efficient. This note is aimed at making strides towards the provisionof practical (i.e., efficient) solutions for generating prime numbers.

    Keywords. Prime numbers, prime generation, RSA, DSA, public-key cryp-tography.

    1 Introduction

    When efficiency is not a concern, the best way to generate a random primenumber is to select a random number q and test it for primality; if the test isunsuccessful then it is reiterated with q q+ 1. Noting that all prime numbers(except 2) are odd, a straightforward improvement is to choose q odd and toupdate candidate q as q q+ 2. This note specifies a technique which choosesa candidate constructively coprime to lots of small primes and updates it in away that it still remains coprime with those factors. A method for producingcoprime candidates is also specified.

    Current standards do not really consider how to generate random primesbut rather propose methods to test the primality of a random number. For

  • 7/28/2019 10.1.1.3.433

    2/5

    2 Marc Joye and Pascal Paillier

    example, the IEEE P1363 standard for public-key cryptography simply suggeststo choose a random odd number and to check its primality [1, A.15.5]. Moreefficient constructive techniques for prime generation are only addressed in arecent ISO/IEC working draft [2] where the aforementioned sieving method isdescribed (cf. [2, Section 6]). However, no practical implementation is given. Thepurpose of this note is to fill the gap by providing a very efficient sieving method.

    2 Two Useful Propositions

    Let Zm be the ring of integers modulo m and let Zm be its group of units (i.e.,

    the set of invertible elements modulo m). We further denote the Carmichaelfunction defined, for m =

    i pi

    i , as (m) = lcm[(pii )]i, and (pii ) = (p

    ii ) =

    pi1i (pi1) for an odd prime pi, (2) = 1, (4) = 2 and (2i) = 12(2i) = 2i2for i

    3.

    Proposition 1. For all k Zm, k Zm if and only if k(m) 1 (mod m).

    Proof. We have k Zm if and only if, for all primes pi | m, gcd(k, pi) = 1 kpi1 1 (mod pi) so that k(m) 1 (mod m) by Chinese remaindering.

    Proposition 2. For all k and r Zm s.t. gcd(r,k,m) = 1, we have

    [k + r(1 k(m))] Zm .

    Proof. Let

    i pii denote the prime factorization of m. Define Kr := [k + r(1

    k(m))] Zm. Let pi be a prime factor ofm. Suppose that pi | k then Kr r 0(mod pi) since gcd(r, pi) divides gcd(r, gcd(k, m)) = gcd(r,k,m) = 1. Supposenow that pi k then k(m) 1 (mod pi) and so Kr k 0 (mod pi). Thereforefor all primes pi | m, we have Kr 0 (mod pi) and thus Kr 0 (mod pii),which, by Chinese remaindering, concludes the proof.

    Remark 1. Note that Bm(k) := {r Zm : gcd(r,k,m) = 1} Zm.

    3 Generating Random Primes

    3.1 Scope

    The goal is to generate a prime number q within the interval [qmin, qmax] incompliance with the ISO/IEC standard ([2]). In most cases, one has qmax =2n1, and qmin = 2n1+1 when generating n-bit primes or qmin = 22n1 + 1when generating 2n-bit RSA moduli of the form N = pq with p, q prime.

    Our proposal consists in a pair of algorithms: the prime generation algorithmitself and an algorithm for generating invertible elements. We assume that arandom number generator is at disposal along with a primality testing oracle.

  • 7/28/2019 10.1.1.3.433

    3/5

    Constructive Methods for the Generation of Prime Numbers 3

    3.2 Prime generation

    Let 0 < 1 denote a quality parameter (a typical value for is 103

    ). Thesetup phase requires a product of primes =

    i pi such that there exist integerst,v,w satisfying

    (P1) 1 < w 1qmax qmin 1;

    (P2) v + t qmin;(P3) (v + w) + t 1 qmax; and(P4) the ratio ()/ is as small as possible.

    qmin qmax

    (v + w) + t 1v + t w 1

    Fig. 1. Targeted Interval.

    The primes output by our algorithm lie, in fact, in the sub-interval [v +t, (v + w) + t 1] [qmin, qmax]. The error in the approximation is captured bythe value of: a smaller gives better results (cf. Property (P1)). The minimalityof the ratio ()/ in Property (P4) ensures that contains a maximum numberof primes.

    Input: parameters l = v, m = w, t, and a m

    Output: a prime q [qmin, qmax]

    1. Randomly choose k m

    2. Set q [(k t) mod m] + t + l3. If (q not prime) then

    (a) Set k ak (mod m)(b) Go to Step 2

    4. Output q

    Fig. 2.Prime Generation Algorithm.

    It is worthwhile noticing that if a, k Zm so does their product, ak, sinceZm

    is a (multiplicative) group. Therefore, throughout the algorithm, k remainscoprime to m and thus to (remember that contains a large number of primefactors by (P4)). This, in turn, implies that q is coprime to as q [(k

  • 7/28/2019 10.1.1.3.433

    4/5

    4 Marc Joye and Pascal Paillier

    t) mod m] + t + l k (mod ) and k Z. Consequently, the probability thatcandidate q is prime at Step 3 is high.

    We now specialize the previous algorithm to make it as fast as possible. Theoptimal value for t is t = 0. Moreover, it is advantageous to choose a so thatmultiplication by a modulo m is not very costly. The best possible value is a = 2.Unfortunately, 2 must belong to Zm

    and owing to Condition (P4), 2 is a factorof and so ofm, a contradiction. Our idea is to choose m odd (so that 2 Zm)and to slightly modify the previous algorithm in order to ensure that primecandidate q is always odd. We require =

    i pi (with pi = 2) and integers v

    and w (odd) satisfying:

    (P2) v + 1 qmin;(P3) (v + w) 1 qmax.

    Input: parameters l = v and m = w (m odd)Output: a prime q [qmin, qmax]

    1. Randomly choose k m

    2. Set q k + l3. If (q even) then qm k + l4. If (q not prime) then

    (a) Set k 2k (mod m)(b) Go to Step 2

    5. Output q

    Fig. 3. Faster Prime Generation Algorithm.

    Note that ifk + l is even then mk + l is odd since mk + l m + (k + l) m 1 (mod 2). Hence, as before, a so-generated q is prime to 2: gcd(q, 2) = 1as q is odd; and gcd(q, ) = 1 as q k (mod ) and k Z.

    3.3 Unit generation

    The prime generation algorithms given in Figs. 2 and 3 require a random elementofZm

    . This section provides an algorithm to efficiently produce such an element.The correctness of the algorithm follows from Proposition 1.

  • 7/28/2019 10.1.1.3.433

    5/5

    Constructive Methods for the Generation of Prime Numbers 5

    Input: parameter m

    Output: a unit k m

    1. Randomly choose k [1,m)2. Set U (1 k(m)) mod m3. If (U= 0) then

    (a) Choose a random r [1, m)(b) Set k k + rU (mod m)(c) Go to Step 2

    4. Output k

    Fig. 4. Unit Generation Algorithm.

    This algorithm presents the advantage of being self-correcting. As soon as kis relatively prime to some factor of m, it remains prime to this factor after theupdating step k k + rU (see Proposition 2).

    4 Generating Constrained Random Primes

    Some applications require that the primes found by our algorithm satisfy addi-tional properties such as being strong or compliant with the ANSI X9.31 stan-dard. We refer the reader to [3] for a collection of techniques allowing to producesuch primes.

    Acknowledgements

    The authors are grateful to Walter Fumy for sending a copy of [2].

    References

    1. IEEE Std 1363-2000. IEEE Standard Specifications for Public-Key Cryptography.IEEE Computer Society, August 29, 2000.

    2. ISO/IEC WD 18032. Prime number generation. Working draft, April 18, 2001.3. Marc Joye, Pascal Paillier, and Serge Vaudenay. Efficient generation of prime num-

    bers. In C. K. Koc and C. Paar, Eds., Cryptographic Hardware and Embedded Sys-tems CHES 2000, vol. 1965 of Lecture Notes in Computer Science, pp. 340354,Springer-Verlag, 2000.