04.11.2012 Views

1 Montgomery Modular Multiplication in Hard- ware

1 Montgomery Modular Multiplication in Hard- ware

1 Montgomery Modular Multiplication in Hard- ware

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FEI KEMT<br />

Algorithm 4 – 1 Modified MWR2MM algorithm<br />

1: S ⇐ 0<br />

2: for i = 0 to n − 1 do<br />

3: qi ⇐ xiY (0)<br />

0<br />

4: if qi = 1 then<br />

+ S (0)<br />

0<br />

5: for j = 0 to e do<br />

6: (Ca, S (j) ) ⇐ Ca + xiY (j) + M (j)<br />

7: (Cb, S (j) ) ⇐ Cb + S (j)<br />

8: S (j−1) ⇐ (S (j)<br />

0 , S (j−1)<br />

w−1..1)<br />

9: end for<br />

10: else<br />

11: for j = 0 to e do<br />

12: (Ca, S (j) ) ⇐ Ca + xiY (j)<br />

13: (Cb, S (j) ) ⇐ Cb + S (j)<br />

14: S (j−1) ⇐ (S (j)<br />

0 , S (j−1)<br />

w−1..1)<br />

15: end for<br />

16: end if<br />

17: S (e) ⇐ 0<br />

18: end for<br />

rather than an addition (see Figure 4 – 3). All operations are done modulo 2n.<br />

Algorithms 4 – 2 and 4 – 3 show the elementary steps of a modular addition and<br />

subtraction, respectively.<br />

If x + y ≥ 2n a reduction can be applied by simple subtraction of 2n. A variable<br />

z conta<strong>in</strong>s the result and T is a (temporary) register. A comparison z < 2n takes<br />

the same amount of time as a subtraction T = z − 2n. Thus, we compute the<br />

subtraction <strong>in</strong> all cases and decide by the sign of the values, which one to take as<br />

the result (z or T ). If T is the correct result, the content of T has to be copied to<br />

the register z.<br />

For a modular addition, we need at most<br />

Tadd = 3(e + 1) (4.2)<br />

clock cycles, where e is the number of words (for implemented non-redundant form<br />

of operands e = � N+1<br />

w<br />

�<br />

). On average, we would only have to reduce every second<br />

time. However, s<strong>in</strong>ce the control of phase 1 and phase 2 is parallelised for many<br />

units, we have to assume the worst case runn<strong>in</strong>g time which is given by Equation 4.2.<br />

62

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!