Method for the modular reduction of numbers

Abstract: In cryptographic techniques which are based on the discrete logarithm problem, use is made of exponentiation modulo large number. If, in this method, the exponentiation is first carried out completely and the modular reduction is only carried out thereafter, this requires very considerable computation time and a very large memory capacity. It is known that the exponentiation can be accelerated by iteratively multiplying and squaring, with a modular reduction after each step. The invention provides a method of also accelerating the modular reduction at the same time, as a result of which the exponentiation modulo large number can be further accelerated. For this purpose, the invention describes a protocol for a modular reduction of a 2n-digit number x in a number system with base b to obtain an n-digit remainder, in which use is made of a specific modulus p which satisfies p = b n - a , where 0 < a < b. The method according to the invention does not reduce the security of the cryptographic system for which the modular exponentiation is carried out.

Description: The invention relates to a method for the modular reduction of a not more than 2n-digit number x to obtain a not more than n-digit remainder in accordance with the formula r ≡ x (mod p), where p is the chosen modulus, for the purpose of cryptographic calculations which are based on the general discrete logarithm problem in a number system with base b. In cryptographic techniques, use may be made of exponentiation modulo large prime number. An example of this is a cryptographic technique which is based on the discrete logarithm problem which is described by w. Diffie and M.E. Hellman in the paper entitled "New directions in Cryptography" in IEEE Trans. on Information Theory, vol. IT-22, pages 644-654, 1976. This paper describes a discrete exponentiation modulo prime number p for use in a public key distribution system. This so-called DH system makes use of publicly known messages in the following way in order to construct a secret common key. Choose a prime number p for which it is true that p - 1 has at least one large prime factor, and an integer z from the set {2,3,.....,p - 1}. These two numbers are made public. Every user now arbitrarily chooses a number x from the set {2,3,......,p - 2}, keeps it secret and calculates the number y = z x (mod p). Two users a and b send their numbers y, i.e. y a and y b , respectively, to each other. With the aid of his own value of x, x a , and the y b received, user a can calculate a secret key k a in accordance with k a = y b Xa ≡ z XaXb (mod p). With the aid of his own value of x, x b , and the y a received, user b can calculate a secret key inaccordance with: k b = y a Xb ≡ z XbXa (mod p). It will be clear that k a = k b = k and that the users have constructed a common secret key in this way. Because the taking of the discrete logarithm has hitherto been regarded as virtually impossible, it is also virtually impossible to calculate the integers x a and x b or the key k starting from the numbers y a and y b . Methods other than that of taking the discrete logarithm to calculate these values have hitherto not been known. Exponentiation modulo large prime number, the exponentiation being carried out first and the result thereby obtained then being reduced results quite quickly in unacceptably long computation times, while the memory capacity required in that case becomes very large. See also US-A-4 405 829 of Rivest, Shamir and Adleman concerning the RSA system. In "The Art of Computer Programming", Vol. 2: Seminumerical Algorithms, 2nd edition, Addison Wesley, 1981, D.E. Knuth describes how an exponentiation can be imagined as built up of repeated multiplication and squaring. He also describes how modular exponentiation can be simplified by making use of modular reduction in every multiplication step and squaring step. Said modular reduction generally takes place by making use of a division algorithm. If the modulus p is the divisor and the number to be reduced is x, the remainder obtained after division gives the desired results; or: x = q.p + r, where q is the quotient, this being written in the present description as r ≡ x(mod p). If the opportunity is seen of accelerating the modular reduction, the exponentiation can also be accelerated and the object of the invention is therefore to provide a method for the rapid modular reduction of a large number from a number system with base b by means of an iterative division algorithm. Such division algorithms are known per se from, for example, the paper entitled "Fast algorithms for implementing RSA public key cryptosystem" by S.B. Mohan and B.S. Adiga in Electronics Letters, vol. 21, no. 17, August 1985, which describes an iterative division algorithm for use in the RSA system, which algorithm has been developed exclusively for the binary system and for a composite modulus which is made up of the product of two large prime numbers and a number of smaller prime numbers. The paper entitled "A practical fast exponentiation algorithm for public key" by H.R. Chivers, International Conference on Secure Communications Systems, London, 22-23 February 1984, furthermore describes an accelerated division algorithm for use in encoding system of Diffie and Hellman. In this case, however, it is proposed to make use of remainder tables, and this is often undesirable in view of the memory space required for such tables. Still another method of modulo reduction is disclosed in EP-A-0 350 278. The object of the invention is, more particularly, to provide a method for fast modular reduction which is efficient to implement in software, preferably with a minimum of program lines, which is of great importance, in particular, if said program is present in the processor present on a so-called smart card. This object must at the same time be fulfilled without diminishing the safety of the cryptographic protocol, for the purpose of which the modular reduction is carried out. For a general description of the way in which a cryptographic system can be used in combination with a smart card, reference is made to the paper entitled "The Smart Card: A high security tool in EDP" by R.C. Ferreira in Philips Telecommunication and Data Review, PTR, Volume 47, no. 3, September 1989, pages 1 - 19. However, said paper describes the use in cryptographic systems in which the discrete logarithm problem does not occur. In order to fulfil the objects described, the invention provides a method of the abovementioned type in which it holds true for the modulus p that p = b n - a, where 0 < a < b. More particularly, the invention is characterised in that the 2n-digit number x is always split into two n-digit numbers x H and x L in accordance with the formula x = (x H · b n ) + x L , where in that the remainder r is determined by first calculating: r temp = x L + a·x H ; in that it is then determined whether the following is fulfilled: r temp < b n ; in that, if this is the case, it holds true that: r = r temp ; in that, if this is not the case, an integer c is calculated which is determined by the value of r temp /b n rounded downwards to the nearest integer and r temp is calculated in accordance with: r temp = r temp - c·b n and in that this step is repeated until the following is fulfilled: r temp < b n , whereafter it holds true that: r = r temp . The invention can be explained in greater detail in the following manner. Suppose that x, the number to be reduced, and r, the remainder, are positive integers and that their representation in the system with base b is given by: For the modulus p it holds true that The modular reduction can now be carried out as follows: (r) b ≡ (x) b (mod (p) b ) = (x) b - ((k) b ·(p) b ) = (X) b - (k) b ·b n + (k) b ·a, where (k) b is so chosen that this equation is fulfilled. If it is assumed that use is made of registers having a length of n digits, the number (x) b can be reproduced by two n-digit registers (x H ) b and (x L ) b as: (x) b = ((x H ) b | 1(x L ) b = (x H ) b ·b n + (x L ) b , with From this it follows that if (x H ) b = (k) b is chosen, the reduced (x) b can be obtained by adding the number a· (x H ) b to (x L ) b and by continuing to do this with the (x H ) b produced after the addition until (x H ) b = 0 and therefore (x) b < b n . The flow diagram shown in the drawing reproduces the method according to the invention in more detail for a number in the system with base b. If it is true for a number w in the system with base b that: w = y·b + x, the functions low ( ) and high ( ) are defined as: low(w) = x and high(w) = y. The length n = L b (s) of a number (s) b in the system with base b follows from: L b (s) = max{i|(s) b ≧ b i } + 1. The modular reduction (r) b ≡ (x) b (mod(b n - a) b ) then proceeds in the way shown in the flow diagram. Block 1 shows that, at the beginning of the modular reduction of a number (x) b , the loop variable i and the variable CARRY are equal to 0 and the remainder values (r) b and (r') b are equal to (0) b , n and a being predetermined constants which determine the modulus. For (x) b and for (r) b , the formulae already given above apply: In block 2, whether the length of (x) b , i.e. L b (x), minus n is greater than i is determined. If that is the case, a temporary number TEMP is determined in block 3 in accordance with TEMP = x i + a·x i+n + CARRY, r i then becoming equal to low(TEMP) and the variable CARRY equal to high(TEMP). Then the loop variable i in block 4 is increased by 1 so that it becomes equal to i + 1, and block 2 is reverted to. When, at a certain instant, it is the case in block 2 that L b (x) - n ≦ i, the modular reduction is continued in block 5 by determining whether CARRY is greater than 0, and if this is not the case, the remainder (r) b is known in principle. If CARRY is in fact greater than 0, a determination is first made in block 6 of whether i is equal to n. If this is the case, the loop variable i is again put equal to 0 in block 7 and the variable CARRY is multiplied by the constant a, after which block 8 is proceeded to. If it is found in block 6 that i is not equal to n, block 8 is also proceeded to. In block 8, TEMP is put equal to TEMP = r i + CARRY, r i then becoming equal to low(TEMP) and the variable CARRY becomes equal to high(TEMP). Then the loop variable i is increased by 1 in block 9 so that it becomes equal to i + 1, and the loop is run through again, starting at block 5 until it is finally true that CARRY ≦ 0, which in principle determines the remainder. Once the remainder (r) b has been determined in block 5, there is the possibility that the remainder (r) b is nevertheless greater than the modulus p, the chance of this being a/b n . For this reason an auxiliary remainder (r') b = (r) b + a is calculated in block 10 and in block 11 a check is made on whether the length of (r') b , i.e. L b (r'), is in fact greater than n and if this is not the case, the calculated remainder (r) b is already the true remainder. However, if L b (r') is in fact greater than n, the true remainder (r) b is calculated in block 12 by taking the last n digits (r') b . Block 13 indicates the end of the calculation of the remainder r b . As will be explained further below, the steps according to the blocks 10, 11 and 12 are in many cases superfluous because if it is found in block 5 that the CARRY is not greater than 0, an n-digit remainder has already been calculated, and this is in principle the object of the method according to the invention. With the method according to the invention as explained above, a modular reduction is possible with the aid of a limited number of multiplications if a > 1 and even no multiplication at all if a = 1. If a = 1, the loop formed in the flow diagram formed by the blocks 2, 3 and 4 is executed not more than n times, without multiplications having to be carried out and block 7 is executed not more than once, also without multiplications being necessary. If a > 1, the loop formed by the blocks 2, 3 and 4 in the flow diagram is executed not more than n times, not more than n multiplications having to be carried out in block 3 and block 7 is executed not more than twice, not more than 2 multiplications being necessary, so that if a > 1, the maximum number of multiplications needed is n + 2. The flow diagram described above provides an explanation of the method according to the invention for a calculation in software, the entire calculation of the n-digit remainder (r) b of the 2n-digit number (x) b in the system with base b being carried out digit by digit. However, it will be immediately obvious to those skilled in the art that the method according to the invention can also be implemented in an extremely efficient way in hardware, in which case multiplications by n-digit numbers are carried out directly. The invention will be illustrated further with reference to two numerical examples in the decimal system, use being made of such multiplications by n-digit numbers for the sake of simplicity. In the decimal system, b = 10. Furthermore, the number 9991 is chosen for the modulus (p) ₁₀ , so that n = 4 and a = b n - (p) ₁₀ = 10 ⁴ - 9991 = 0009. In the first example, the remainder of the number 99980001 is sought. According to the first step of the algorithm it is calculated that: (x H ) ₁₀ ·a + (x L ) ₁₀ = 9998 x 0009 + 0001 = 00089983. The carry, the newly-formed (x H ) ₁₀ , is thus found to be equal to 0008 and (x L ) ₁₀ = 9983, and because the carry is greater than zero, the following calculation is carried out: carry x a + (x L ) ₁₀ = 0008 x 0009 + 9983 = 00010055. Again the carry, the newly-formed (x H ) ₁₀ is greater than zero so that a calculation is again carried out: carry x a + (x L ) ₁₀ = 0001 x 0009 + 55 = 0064. The carry is now equal to zero and the remainder is therefore known in principle and is equal to the last (x L ) ₁₀ calculated = 0064. As has already been noted above in the description of the flow diagram, there is a slight chance that the calculated remainder (r) ₁₀ is greater than (p) ₁₀ . However, because the invention is in principle aimed at the fast modular reduction of a 2n-digit number to an n-digit number, it is of less importance whether the n-digit remainder found is also the true remainder or whether it yet again contains more than the modulus. In the first example given above, it is clear that (r) ₁₀ < (p) ₁₀ , so that an explanation of the steps according to the blocks 10 - 12 in the flow diagram is of little interest for this example. However, by adding the value of a to the n-digit remainder found and determining whether the length of the auxiliary remainder (r') ₁₀ thereby calculated is greater than n, the true remainder can always be determined, as will be illustrated by reference to the following example. In the second example, the remainder of 19987 is sought. According to the first step of the algorithm, the following calculation is carried out: (x H ) ₁₀ ·a + (x L ) ₁₀ = 0001 x 0009 + 9987 = 9996. The carry is now equal to zero and the remainder (r) ₁₀ is therefore known in principle, but it is not known, however, if this is the true remainder. For this reason, the following calculation is furthermore first carried out: (r') ₁₀ = (r) ₁₀ + a = 9996 + 0009 = 10005. The value of (r') ₁₀ is found to be greater than n and the true remainder (r) ₁₀ is therefore determined by taking the last 4 digits of (r')₁₀, so that (r) ₁₀ is found to be = 0005. The modular reduction described above is of importance in order to be able to carry out cryptographic methods efficiently and rapidly, with use being made of exponentiation modulo large prime number such as the DH system described above. A number of other types of these cryptographic methods will be briefly discussed below. A secret m can be exchanged by the so-called Three-Pass protocol with the aid of discrete exponentiation modulo known prime number p, possibly made public. This is done in the following way: As in the DH system, the users a and b both choose a secret arbitrary number x, x a and x b respectively, but they now both calculate a secret x ⁻¹ which satisfies the relationship: x·x ⁻¹ ≡ 1 (mod p - 1). If user a wishes to send the secret message m to user b, he calculates y ≡ m Xa (mod p) and sends it to b. User b now calculates: Z = y Xb ≡ m Xa.Xb (mod p) and sends it back to a. User a now calculates: Z Xa -1 = m Xa·Xb·Xa -1 ≡ m Xb (mod p) and sends it back to b. From this, user b can calculate the secret message via: (m Xb ) Xb -1 = m Xb·Xb -1 ≡ m (mod p) . A third cryptographic system is known from US-A- 4 424 414 under the name of the Pohlig-Hellman (PH) system, and here again, use is made of a prime number p for which it holds true that p - 1 has at least one large prime factor. In the PH system, the users a and b choose secret numbers x a and x b so that it holds true that x a x b ≡ 1 (mod p - 1). A secret message m can now therefore be exchanged between a and b with the aid of the following two functions: The encoding function E a for a and the decoding function D b for b is given by: E a (y) = D b (y) ≡ y Xa (mod p). The decoding function D a for a and the encoding function E b for b is given by: D a (y) = E b (y) ≡ y Xb (mod p).

Claims: Method for the modular reduction of a not more than 2n-digit number x to obtain a not more than n-digit remainder r in accordance with the formula r ≡ x (mod p), where p is the chosen modulus, for the purpose of cryptographic calculations which are based on the general discrete logarithm problem in a number system with base b, in which method p is a n-digit number for which it holds true that p = b n - a, where 0 < a < b. Method according to claim 1, characterized in that the 2n-digit number is always split into two n-digit numbers x H and x L in accordance with the formula x = (x H ·b n ) + x L , where in that the remainder r is determined by first calculating: r temp = x L + a·x H ; in that it is then determined whether the following is fulfilled: r temp < b n ; in that, if this is the case, it holds true that: r = r temp ; in that, if this is not the case, an integer c is calculated which is determined by the value of r temp /b n rounded downwards to the nearest integer and r temp is calculated in accordance with: r temp = r temp - c·b n and in that this step is repeated until the following is fulfilled: r temp < b n , whereafter it holds true that: r = r temp . Method according to claim 2, characterised in that r' = r + a is calculated, after which the true remainder is equal to the last n digits of r' if r' > b n and is equal to r if r' < b n .

Applicants: NEDERLAND PTT, KONINKLIJKE PTT NEDERLAND N.V.
Application year: 1991
Main classification: G09C1
IPC codes: G06F7, G09C1, G09C5, H04L9