Montgomery modular multiplication

From Wikipedia, the free encyclopedia
(Redirected from Montgomery multiplication)
Jump to navigation Jump to search

Template:Short description In modular arithmetic computation, Montgomery modular multiplication, more commonly referred to as Montgomery multiplication, is a method for performing fast modular multiplication. It was introduced in 1985 by the American mathematician Peter L. Montgomery.[1][2]

Montgomery modular multiplication relies on a special representation of numbers called Montgomery form. The algorithm uses the Montgomery forms of Template:Mvar and Template:Mvar to efficiently compute the Montgomery form of ab mod NScript error: No such module "Check for unknown parameters".. The efficiency comes from avoiding expensive division operations. Classical modular multiplication reduces the double-width product abScript error: No such module "Check for unknown parameters". using division by Template:Mvar and keeping only the remainder. This division requires quotient digit estimation and correction. The Montgomery form, in contrast, depends on a constant Template:Mvar which is coprime to Template:Mvar, and the only division necessary in Montgomery multiplication is division by Template:Mvar. The constant Template:Mvar can be chosen so that division by Template:Mvar is easy, significantly improving the speed of the algorithm. In binary computers, Template:Mvar is always a power of two, since division by powers of two can be implemented by bit shifting.

The need to convert Template:Mvar and Template:Mvar into Montgomery form and their product out of Montgomery form means that computing a single product by Montgomery multiplication is slower than the conventional or Barrett reduction algorithms. However, when performing many multiplications in a row, as in modular exponentiation, intermediate results can be left in Montgomery form. Then the initial and final conversions become a negligible fraction of the overall computation. Many important cryptosystems such as RSA and Diffie–Hellman key exchange are based on arithmetic operations modulo a large odd number, and for these cryptosystems, computations using Montgomery multiplication with Template:Mvar a power of two are faster than the available alternatives.[3]

Modular arithmetic

Let Template:Mvar denote a positive integer modulus. The quotient ring Z/NZScript error: No such module "Check for unknown parameters". consists of residue classes modulo Template:Mvar, that is, its elements are sets of the form

{a+kN:k𝐙},

where Template:Mvar ranges across the integers. Each residue class is a set of integers such that the difference of any two integers in the set is divisible by Template:Mvar (and the residue class is maximal with respect to that property; integers aren't left out of the residue class unless they would violate the divisibility condition). The residue class corresponding to Template:Mvar is denoted aScript error: No such module "Check for unknown parameters".. Equality of residue classes is called congruence and is denoted

a¯b¯(modN).

Storing an entire residue class on a computer is impossible because the residue class has infinitely many elements. Instead, residue classes are stored as representatives. Conventionally, these representatives are the integers Template:Mvar for which 0 ≤ aN − 1Script error: No such module "Check for unknown parameters".. If Template:Mvar is an integer, then the representative of aScript error: No such module "Check for unknown parameters". is written a mod NScript error: No such module "Check for unknown parameters".. When writing congruences, it is common to identify an integer with the residue class it represents. With this convention, the above equality is written ab mod NScript error: No such module "Check for unknown parameters"..

Arithmetic on residue classes is done by first performing integer arithmetic on their representatives. The output of the integer operation determines a residue class, and the output of the modular operation is determined by computing the residue class's representative. For example, if N = 17Script error: No such module "Check for unknown parameters"., then the sum of the residue classes 7Script error: No such module "Check for unknown parameters". and 15Script error: No such module "Check for unknown parameters". is computed by finding the integer sum 7 + 15 = 22Script error: No such module "Check for unknown parameters"., then determining 22 mod 17Script error: No such module "Check for unknown parameters"., the integer between 0 and 16 whose difference with 22 is a multiple of 17. In this case, that integer is 5, so 7 + 155 mod 17Script error: No such module "Check for unknown parameters"..

Montgomery form

If Template:Mvar and Template:Mvar are integers in the range [0, N − 1]Script error: No such module "Check for unknown parameters"., then their sum is in the range [0, 2N − 2]Script error: No such module "Check for unknown parameters". and their difference is in the range [−N + 1, N − 1]Script error: No such module "Check for unknown parameters"., so determining the representative in [0, N − 1]Script error: No such module "Check for unknown parameters". requires at most one subtraction or addition (respectively) of Template:Mvar. However, the product abScript error: No such module "Check for unknown parameters". is in the range [0, N2 − 2N + 1]Script error: No such module "Check for unknown parameters".. Storing the intermediate integer product abScript error: No such module "Check for unknown parameters". requires twice as many bits as either Template:Mvar or Template:Mvar, and efficiently determining the representative in [0, N − 1]Script error: No such module "Check for unknown parameters". requires division. Mathematically, the integer between 0 and N − 1Script error: No such module "Check for unknown parameters". that is congruent to abScript error: No such module "Check for unknown parameters". can be expressed by applying the Euclidean division theorem:

ab=qN+r,

where Template:Mvar is the quotient ab/N and Template:Mvar, the remainder, is in the interval [0, N − 1]Script error: No such module "Check for unknown parameters".. The remainder Template:Mvar is ab mod NScript error: No such module "Check for unknown parameters".. Determining Template:Mvar can be done by computing Template:Mvar, then subtracting qNScript error: No such module "Check for unknown parameters". from abScript error: No such module "Check for unknown parameters".. For example, again with N=17, the product 715Script error: No such module "Check for unknown parameters". is determined by computing 715=105, dividing 105/17=6, and subtracting 105617=105102=3.

Because the computation of Template:Mvar requires division, it is undesirably expensive on most computer hardware. Montgomery form is a different way of expressing the elements of the ring in which modular products can be computed without expensive divisions. While divisions are still necessary, they can be done with respect to a different divisor Template:Mvar. This divisor can be chosen to be a power of two, for which division can be replaced by shifting, or a whole number of machine words, for which division can be replaced by omitting words. These divisions are fast, so most of the cost of computing modular products using Montgomery form is the cost of computing ordinary products.

The auxiliary modulus Template:Mvar must be a positive integer such that gcd(R, N) = 1Script error: No such module "Check for unknown parameters".. For computational purposes it is also necessary that division and reduction modulo Template:Mvar are inexpensive, and the modulus is not useful for modular multiplication unless R > NScript error: No such module "Check for unknown parameters".. The Montgomery form of the residue class aScript error: No such module "Check for unknown parameters". with respect to Template:Mvar is aR mod NScript error: No such module "Check for unknown parameters"., that is, it is the representative of the residue class aRScript error: No such module "Check for unknown parameters".. For example, suppose that N = 17Script error: No such module "Check for unknown parameters". and that R = 100Script error: No such module "Check for unknown parameters".. The Montgomery forms of 3, 5, 7, and 15 are 300 mod 17 = 11Script error: No such module "Check for unknown parameters"., 500 mod 17 = 7Script error: No such module "Check for unknown parameters"., 700 mod 17 = 3Script error: No such module "Check for unknown parameters"., and 1500 mod 17 = 4Script error: No such module "Check for unknown parameters"..

Addition and subtraction in Montgomery form are the same as ordinary modular addition and subtraction because of the distributive law:

aR+bR=(a+b)R,
aRbR=(ab)R.

Note that doing the operation in Montgomery form does not lose information compared to doing it in the quotient ring Z/NZScript error: No such module "Check for unknown parameters".. This is a consequence of the fact that, because gcd(R, N) = 1Script error: No such module "Check for unknown parameters"., multiplication by Template:Mvar is an isomorphism on the additive group Z/NZScript error: No such module "Check for unknown parameters".. For example, (7 + 15) mod 17 = 5Script error: No such module "Check for unknown parameters"., which in Montgomery form becomes (3 + 4) mod 17 = 7Script error: No such module "Check for unknown parameters"..

Multiplication in Montgomery form, however, is seemingly more complicated. The usual product of aRScript error: No such module "Check for unknown parameters". and bRScript error: No such module "Check for unknown parameters". does not represent the product of Template:Mvar and Template:Mvar because it has an extra factor of Template:Mvar:

(aRmodN)(bRmodN)modN=(abR)RmodN.

Computing products in Montgomery form requires removing the extra factor of Template:Mvar. While division by Template:Mvar is cheap, the intermediate product (aR mod N)(bR mod N)Script error: No such module "Check for unknown parameters". is not divisible by Template:Mvar because the modulo operation has destroyed that property. So for instance, the product of the Montgomery forms of 7 and 15 modulo 17, with R = 100Script error: No such module "Check for unknown parameters"., is the product of 3 and 4, which is 12. Since 12 is not divisible by 100, additional effort is required to remove the extra factor of Template:Mvar.

Removing the extra factor of Template:Mvar can be done by multiplying by an integer RScript error: No such module "Check for unknown parameters". such that RR′ ≡ 1 (mod N)Script error: No such module "Check for unknown parameters"., that is, by an RScript error: No such module "Check for unknown parameters". whose residue class is the modular inverse of Template:Mvar mod Template:Mvar. Then, working modulo Template:Mvar,

(aRmodN)(bRmodN)R(aR)(bR)R1(ab)R(modN).

The integer RScript error: No such module "Check for unknown parameters". exists because of the assumption that Template:Mvar and Template:Mvar are coprime. It can be constructed using the extended Euclidean algorithm. The extended Euclidean algorithm efficiently determines integers RScript error: No such module "Check for unknown parameters". and NScript error: No such module "Check for unknown parameters". that satisfy Bézout's identity: 0 < R′ < NScript error: No such module "Check for unknown parameters"., 0 < N′ < RScript error: No such module "Check for unknown parameters"., and:

RRNN=1.

This shows that it is possible to do multiplication in Montgomery form. A straightforward algorithm to multiply numbers in Montgomery form is therefore to multiply aR mod NScript error: No such module "Check for unknown parameters"., bR mod NScript error: No such module "Check for unknown parameters"., and RScript error: No such module "Check for unknown parameters". as integers and reduce modulo Template:Mvar.

For example, to multiply 7 and 15 modulo 17 in Montgomery form, again with R = 100Script error: No such module "Check for unknown parameters"., compute the product of 3 and 4 to get 12 as above. The extended Euclidean algorithm implies that 8⋅100 − 47⋅17 = 1Script error: No such module "Check for unknown parameters"., so R′ = 8Script error: No such module "Check for unknown parameters".. Multiply 12 by 8 to get 96 and reduce modulo 17 to get 11. This is the Montgomery form of 3, as expected.

The REDC algorithm

While the above algorithm is correct, it is slower than multiplication in the standard representation because of the need to multiply by RScript error: No such module "Check for unknown parameters". and divide by Template:Mvar. Montgomery reduction, also known as REDC, is an algorithm that simultaneously computes the product by RScript error: No such module "Check for unknown parameters". and reduces modulo Template:Mvar more quickly than the naïve method. Unlike conventional modular reduction, which focuses on making the number smaller than Template:Mvar, Montgomery reduction focuses on making the number more divisible by Template:Mvar. It does this by adding a small multiple of Template:Mvar which is sophisticatedly chosen to cancel the residue modulo Template:Mvar. Dividing the result by Template:Mvar yields a much smaller number. This number is so much smaller that it is nearly the reduction modulo Template:Mvar, and computing the reduction modulo Template:Mvar requires only a final conditional subtraction. Because all computations are done using only reduction and divisions with respect to Template:Mvar, not Template:Mvar, the algorithm runs faster than a straightforward modular reduction by division.

function REDC is
    input: Integers R and N with gcd(R, N) = 1,
           Integer N′ in [0, R − 1] such that NN′ ≡ −1 mod R,
           Integer T in the range [0, RN − 1].
    output: Integer S in the range [0, N − 1] such that STR−1 mod N

    m ← ((T mod R)N′) mod R
    t ← (T + mN) / R
    if tN then
        return tN
    else
        return t
    end if
end function

To see that this algorithm is correct, first observe that Template:Mvar is chosen precisely so that T + mNScript error: No such module "Check for unknown parameters". is divisible by Template:Mvar. A number is divisible by Template:Mvar if and only if it is congruent to zero mod Template:Mvar, and we have:

T+mNT+(((TmodR)N)modR)NT+TNNTT0(modR).

Therefore, Template:Mvar is an integer. Second, the output is either Template:Mvar or tNScript error: No such module "Check for unknown parameters"., both of which are congruent to t mod NScript error: No such module "Check for unknown parameters"., so to prove that the output is congruent to TR−1 mod NScript error: No such module "Check for unknown parameters"., it suffices to prove that Template:Mvar is TR−1 mod NScript error: No such module "Check for unknown parameters"., Template:Mvar satisfies:

t(T+mN)R1TR1+(mR1)NTR1(modN).

Therefore, the output has the correct residue class. Third, Template:Mvar is in [0, R − 1]Script error: No such module "Check for unknown parameters"., and therefore T + mNScript error: No such module "Check for unknown parameters". is between 0 and (RN − 1) + (R − 1)N < 2RNScript error: No such module "Check for unknown parameters".. Hence Template:Mvar is less than 2NScript error: No such module "Check for unknown parameters"., and because it's an integer, this puts Template:Mvar in the range [0, 2N − 1]Script error: No such module "Check for unknown parameters".. Therefore, reducing Template:Mvar into the desired range requires at most a single subtraction, so the algorithm's output lies in the correct range.

To use REDC to compute the product of 7 and 15 modulo 17, first convert to Montgomery form and multiply as integers to get 12 as above. Then apply REDC with R = 100Script error: No such module "Check for unknown parameters"., N = 17Script error: No such module "Check for unknown parameters"., N′ = 47Script error: No such module "Check for unknown parameters"., and T = 12Script error: No such module "Check for unknown parameters".. The first step sets Template:Mvar to 12 ⋅ 47 mod 100 = 64Script error: No such module "Check for unknown parameters".. The second step sets Template:Mvar to (12 + 64 ⋅ 17) / 100Script error: No such module "Check for unknown parameters".. Notice that 12 + 64 ⋅ 17Script error: No such module "Check for unknown parameters". is 1100, a multiple of 100 as expected. Template:Mvar is set to 11, which is less than 17, so the final result is 11, which agrees with the computation of the previous section.

As another example, consider the product 7 ⋅ 15 mod 17Script error: No such module "Check for unknown parameters". but with R = 10Script error: No such module "Check for unknown parameters".. Using the extended Euclidean algorithm, compute −5 ⋅ 10 + 3 ⋅ 17 = 1Script error: No such module "Check for unknown parameters"., so NScript error: No such module "Check for unknown parameters". will be −3 mod 10 = 7Script error: No such module "Check for unknown parameters".. The Montgomery forms of 7 and 15 are 70 mod 17 = 2Script error: No such module "Check for unknown parameters". and 150 mod 17 = 14Script error: No such module "Check for unknown parameters"., respectively. Their product 28 is the input Template:Mvar to REDC, and since 28 < RN = 170Script error: No such module "Check for unknown parameters"., the assumptions of REDC are satisfied. To run REDC, set Template:Mvar to (28 mod 10) ⋅ 7 mod 10 = 196 mod 10 = 6Script error: No such module "Check for unknown parameters".. Then 28 + 6 ⋅ 17 = 130Script error: No such module "Check for unknown parameters"., so t = 13Script error: No such module "Check for unknown parameters".. Because 30 mod 17 = 13Script error: No such module "Check for unknown parameters"., this is the Montgomery form of 3 = 7 ⋅ 15 mod 17Script error: No such module "Check for unknown parameters"..

Interpretation via the Chinese Remainder Theorem

Source:[4]

Given the modulus Template:Mvar and the Montgomery radix Template:Mvar used in a Montgomery reduction, consider the residue ring

/(NR)/N×/R,

an isomorphism that follows from the Chinese Remainder Theorem (CRT).

CRT reconstruction for an intermediate product

For an integer T with 0T<NR (as is typical when T arises from multiplying two residues), take its reductions

TN=TmodN,TR=TmodR.

The CRT gives the explicit reconstruction formula

TTN(R1modN)R+TR(N1modR)N(modNR).

Because the right-hand side is already taken modulo NR, this may also be written as

T(TNR1modN)R+(TRN1modR)N(modNR).

Both summands lie in the half‑open interval [0,NR):

0(TNR1modN)R<NR,0(TRN1modR)N<NR.

Hence, as integer equations (not merely congruences) we have

T=(TNR1modN)R+(TRN1modR)N,

or,

T+NR=(TNR1modN)R+(TRN1modR)N.

Isolating the term containing T mod N

To solve for TN, isolate the first summand:

(TNR1modN)R={T(TRN1modR)N,T+NR(TRN1modR)N.

Every quantity above is an integer, and the left‑hand side is a multiple of R; therefore each right‑hand side is divisible by R. Dividing by R yields

TNR1modN={T(TRN1modR)NR,T+NR(TRN1modR)NR=T(TRN1modR)NR+N.

Resulting relations

Consequently,

T(TRN1modR)NR={TNR1modN,TNR1modN+N.

This gives two key facts:

  • Congruence

T(TRN1modR)NRTNR1(modN).

  • Numeric bound

0T(TRN1modR)NR<2N.

Therefore, by reducing

T(TRN1modR)NR

once more modulo Template:Mvar, one obtains the non‑negative residue representing TNR1modN.

Arithmetic in Montgomery form

Many operations of interest modulo Template:Mvar can be expressed equally well in Montgomery form. Addition, subtraction, negation, comparison for equality, multiplication by an integer not in Montgomery form, and greatest common divisors with Template:Mvar may all be done with the standard algorithms. The Jacobi symbol can be calculated as (aN)=(aRN)/(RN) as long as (RN) is stored.

When R > NScript error: No such module "Check for unknown parameters"., most other arithmetic operations can be expressed in terms of REDC. This assumption implies that the product of two representatives mod Template:Mvar is less than Template:Mvar, the exact hypothesis necessary for REDC to generate correct output. In particular, the product of aR mod NScript error: No such module "Check for unknown parameters". and bR mod NScript error: No such module "Check for unknown parameters". is REDC((aR mod N)(bR mod N))Script error: No such module "Check for unknown parameters".. The combined operation of multiplication and REDC is often called Montgomery multiplication.

Conversion into Montgomery form is done by computing REDC((a mod N)(R2 mod N))Script error: No such module "Check for unknown parameters".. Conversion out of Montgomery form is done by computing REDC(aR mod N)Script error: No such module "Check for unknown parameters".. The modular inverse of aR mod NScript error: No such module "Check for unknown parameters". is REDC((aR mod N)−1(R3 mod N))Script error: No such module "Check for unknown parameters".. Modular exponentiation can be done using exponentiation by squaring by initializing the initial product to the Montgomery representation of 1, that is, to R mod NScript error: No such module "Check for unknown parameters"., and by replacing the multiply and square steps by Montgomery multiplies.

Performing these operations requires knowing at least NScript error: No such module "Check for unknown parameters". and R2 mod NScript error: No such module "Check for unknown parameters".. When Template:Mvar is a power of a small positive integer Template:Mvar, NScript error: No such module "Check for unknown parameters". can be computed by Hensel's lemma: The inverse of Template:Mvar modulo Template:Mvar is computed by a naïve algorithm (for instance, if b = 2Script error: No such module "Check for unknown parameters". then the inverse is 1), and Hensel's lemma is used repeatedly to find the inverse modulo higher and higher powers of Template:Mvar, stopping when the inverse modulo Template:Mvar is known; NScript error: No such module "Check for unknown parameters". is the negation of this inverse. The constants R mod NScript error: No such module "Check for unknown parameters". and R3 mod NScript error: No such module "Check for unknown parameters". can be generated as REDC(R2 mod N)Script error: No such module "Check for unknown parameters". and as REDC((R2 mod N)(R2 mod N))Script error: No such module "Check for unknown parameters".. The fundamental operation is to compute REDC of a product. When standalone REDC is needed, it can be computed as REDC of a product with 1 mod NScript error: No such module "Check for unknown parameters".. The only place where a direct reduction modulo Template:Mvar is necessary is in the precomputation of R2 mod NScript error: No such module "Check for unknown parameters"..

Montgomery arithmetic on multiprecision integers

Most cryptographic applications require numbers that are hundreds or even thousands of bits long. Such numbers are too large to be stored in a single machine word. Typically, the hardware performs multiplication mod some base Template:Mvar, so performing larger multiplications requires combining several small multiplications. The base Template:Mvar is typically 2 for microelectronic applications, 28 for 8-bit firmware,[5] or 232 or 264 for software applications.

The REDC algorithm requires products modulo Template:Mvar, and typically R > NScript error: No such module "Check for unknown parameters". so that REDC can be used to compute products. However, when Template:Mvar is a power of Template:Mvar, there is a variant of REDC which requires products only of machine word sized integers. Suppose that positive multi-precision integers are stored little endian, that is, Template:Mvar is stored as an array x[0], ..., x[ℓ - 1]Script error: No such module "Check for unknown parameters". such that 0 ≤ x[i] < BScript error: No such module "Check for unknown parameters". for all Template:Mvar and x = ∑ x[i] BiScript error: No such module "Check for unknown parameters".. The algorithm begins with a multiprecision integer Template:Mvar and reduces it one word at a time. First an appropriate multiple of Template:Mvar is added to make Template:Mvar divisible by Template:Mvar. Then a multiple of Template:Mvar is added to make Template:Mvar divisible by B2Script error: No such module "Check for unknown parameters"., and so on. Eventually Template:Mvar is divisible by Template:Mvar, and after division by Template:Mvar the algorithm is in the same place as REDC was after the computation of Template:Mvar.

function MultiPrecisionREDC is
    Input: Integer N with gcd(B, N) = 1, stored as an array of p words,
           Integer R = Br,     --thus, r = logB R
           Integer N′ in [0, B − 1] such that NN′ ≡ −1 (mod B),
           Integer T in the range 0 ≤ T < RN, stored as an array of r + p words.

    Output: Integer S in [0, N − 1] such that TR−1S (mod N), stored as an array of p words.

    Set T[r + p] = 0  (extra carry word)
    for 0 ≤ i < r do
        --loop1- Make T divisible by Bi+1

        c ← 0
        mT[i] ⋅ N′ mod B
        for 0 ≤ j < p do
            --loop2- Add the m ⋅ N[j] and the carry from earlier, and find the new carry

            xT[i + j] + mN[j] + c
            T[i + j] ← x mod B
            cx / B
        end for
        for pjr + pi do
            --loop3- Continue carrying

            xT[i + j] + c
            T[i + j] ← x mod B
            cx / B
        end for
    end for

    for 0 ≤ ip do
        S[i] ← T[i + r]
    end for

    if SN then
        return SN
    else
        return Template:Var
    end if
end function

The final comparison and subtraction is done by the standard algorithms.

The above algorithm is correct for essentially the same reasons that REDC is correct. Each time through the Template:Mvar loop, Template:Mvar is chosen so that T[i] + mN[0]Script error: No such module "Check for unknown parameters". is divisible by Template:Mvar. Then Template:Mvar is added to Template:Mvar. Because this quantity is zero mod Template:Mvar, adding it does not affect the value of T mod NScript error: No such module "Check for unknown parameters".. If Template:Mvar denotes the value of Template:Mvar computed in the Template:Mvarth iteration of the loop, then the algorithm sets Template:Mvar to T + (∑ mi Bi)NScript error: No such module "Check for unknown parameters".. Because MultiPrecisionREDC and REDC produce the same output, this sum is the same as the choice of Template:Mvar that the REDC algorithm would make.

The last word of Template:Mvar, T[r + p]Script error: No such module "Check for unknown parameters". (and consequently S[p]Script error: No such module "Check for unknown parameters".), is used only to hold a carry, as the initial reduction result is bound to a result in the range of 0 ≤ S < 2NScript error: No such module "Check for unknown parameters".. It follows that this extra carry word can be avoided completely if it is known in advance that R2NScript error: No such module "Check for unknown parameters".. On a typical binary implementation, this is equivalent to saying that this carry word can be avoided if the number of bits of Template:Mvar is smaller than the number of bits of Template:Mvar. Otherwise, the carry will be either zero or one. Depending upon the processor, it may be possible to store this word as a carry flag instead of a full-sized word.

It is possible to combine multiprecision multiplication and REDC into a single algorithm. This combined algorithm is usually called Montgomery multiplication. Several different implementations are described by Koç, Acar, and Kaliski.[6] The algorithm may use as little as p + 2Script error: No such module "Check for unknown parameters". words of storage (plus a carry bit).

As an example, let B = 10Script error: No such module "Check for unknown parameters"., N = 997Script error: No such module "Check for unknown parameters"., and R = 1000Script error: No such module "Check for unknown parameters".. Suppose that a = 314Script error: No such module "Check for unknown parameters". and b = 271Script error: No such module "Check for unknown parameters".. The Montgomery representations of Template:Mvar and Template:Mvar are 314000 mod 997 = 942Script error: No such module "Check for unknown parameters". and 271000 mod 997 = 813Script error: No such module "Check for unknown parameters".. Compute 942 ⋅ 813 = 765846Script error: No such module "Check for unknown parameters".. The initial input Template:Mvar to MultiPrecisionREDC will be [6, 4, 8, 5, 6, 7]. The number Template:Mvar will be represented as [7, 9, 9]. The extended Euclidean algorithm says that −299 ⋅ 10 + 3 ⋅ 997 = 1Script error: No such module "Check for unknown parameters"., so NScript error: No such module "Check for unknown parameters". will be 7.

i ← 0
m ← 6 ⋅ 7 mod 10 = 2

j T       c
- ------- -
0 0485670 2    (After first iteration of first loop)
1 0485670 2
2 0485670 2
3 0487670 0    (After first iteration of second loop)
4 0487670 0
5 0487670 0
6 0487670 0

i ← 1
m ← 4 ⋅ 7 mod 10 = 8

j T       c
- ------- -
0 0087670 6    (After first iteration of first loop)
1 0067670 8
2 0067670 8
3 0067470 1    (After first iteration of second loop)
4 0067480 0
5 0067480 0

i ← 2
m ← 6 ⋅ 7 mod 10 = 2

j T       c
- ------- -
0 0007480 2    (After first iteration of first loop)
1 0007480 2
2 0007480 2
3 0007400 1    (After first iteration of second loop)
4 0007401 0

Therefore, before the final comparison and subtraction, S = 1047Script error: No such module "Check for unknown parameters".. The final subtraction yields the number 50. Since the Montgomery representation of 314 ⋅ 271 mod 997 = 349Script error: No such module "Check for unknown parameters". is 349000 mod 997 = 50Script error: No such module "Check for unknown parameters"., this is the expected result.

When working in base 2, determining the correct Template:Mvar at each stage is particularly easy: If the current working bit is even, then Template:Mvar is zero and if it's odd, then Template:Mvar is one. Furthermore, because each step of MultiPrecisionREDC requires knowing only the lowest bit, Montgomery multiplication can be easily combined with a carry-save adder.

Side-channel attacks

Because Montgomery reduction avoids the correction steps required in conventional division when quotient digit estimates are inaccurate, it is mostly free of the conditional branches which are the primary targets of timing and power side-channel attacks; the sequence of instructions executed is independent of the input operand values. The only exception is the final conditional subtraction of the modulus, but it is easily modified (to always subtract something, either the modulus or zero) to make it resistant.[5] It is of course necessary to ensure that the exponentiation algorithm built around the multiplication primitive is also resistant.Template:R[7]

See also

References

<templatestyles src="Reflist/styles.css" />

  1. Script error: No such module "Citation/CS1".
  2. Martin Kochanski, "Montgomery Multiplication" Template:Webarchive a colloquial explanation.
  3. Alfred J. Menezes, Paul C. van Oorschot, and Scott A. Vanstone. Handbook of Applied Cryptography. CRC Press, 1996. Template:Isbn, chapter 14.
  4. Script error: No such module "citation/CS1".
  5. a b Script error: No such module "citation/CS1". (Presentation slides.)
  6. Script error: No such module "Citation/CS1".
  7. Marc Joye and Sung-Ming Yen. "The Montgomery Powering Ladder". 2002.

Script error: No such module "Check for unknown parameters".

External links