Documente Academic
Documente Profesional
Documente Cultură
Aritmtica Computacional
Modular Exponentiation
We do NOT compute C := Me mod n By first computing Me And then computing C := (Me) mod n Temporary results must be reduced modulo n at each step of the exponentiation.
Aritmtica Computacional
Modular Exponentiation
M15 How many multiplications are needed?? Nave Answer (requires 14 multiplications): M M2 M3 M4 M5 M15 Binary Method (requires 6 multiplications): M M2 M3 M6 M7 M14 M15
Aritmtica Computacional
Francisco Rodrguez Henrquez
Input: M, e, n.
k %1
for ei # { ,1} 0 Output: C := Me mod n 1. If ek-1 = 1 then C := M else C := 1; 2. For i = k-2 downto 0 3. C := C2 mod n 4. If ei = 1 then C := CM mod n 5. Return C;
Aritmtica Computacional
Francisco Rodrguez Henrquez
ei 1 1 1 1 1 0 1 0
Step 2a M (M)2 = M2 (M3)2 = M6 (M7)2 = M14 (M15)2 = M30 (M31)2 = M62 (M62)2 = M124 (M125)2 = M250
Step 2b M M2M = M3 M6M = M7 M14M = M15 M30M = M31 M62 M124M = M125 M250
The total number of multiplications: Maximum: (k-1) + (k-1) = 2(k-1) Minimum: (k-1) + 0 = k-1 Average: (k-1) + 1/2 (k-1) = 1.5(k-1)
Francisco Rodrguez Henrquez
Aritmtica Computacional
Modular Exponentiation
By scanning the bits of e 2 at a time: quaternary method 3 at a time: octal method Etc. m at a time: m-ary method. Consider the quaternary method: 250 = 11 11 10 10 Some preprocessing required. At each step 2 squaring performed.
Aritmtica Computacional
Francisco Rodrguez Henrquez
Aritmtica Computacional
j 0 1 2 3 4 5 6 7
Mj 1 M MM =M2 M2M =M3 M3M =M4 M4M =M5 M5M =M6 M6M =M7
Francisco Rodrguez Henrquez
The number of multiplications: 6+6+2 = 14 (compute only M2 and M7: 4+6+2 = 12)
Aritmtica Computacional
Francisco Rodrguez Henrquez
Aritmtica Computacional
Aritmtica Computacional
j 1 2 3 5 7
Aritmtica Computacional
Aritmtica Computacional
Aritmtica Computacional
Aritmtica Computacional
Aritmtica Computacional
Aritmtica Computacional
4 6 9 18 20 12 24
8 16 17 32
Aritmtica Computacional
Aritmtica Computacional
Addition Chains
Consider a sequence of integers a0, a1, a2, , ar With a0 = 1 and ar = e. The sequence is constructed in such a way that for all k there exist indices i, j k such that, ak = ai + aj. The length of the chain is r. A short chain for a given e implies an efficient algorithm for computing Me. Example: e = 55 BM: 1 2 3 6 12 13 26 27 54 55 QM: 1 2 3 6 12 13 26 52 55 FM: 1 2 4 5 10 20 40 50 55 PTM: 1 2 3 5 10 11 22 44 55
Aritmtica Computacional
Francisco Rodrguez Henrquez
Addition Chains
Finding the shortest addition chain is NP-complete. Upper-bound is given by binary method:
!log 2 e" + H (e )# 1
Where H(e) is the Hamming weight of e. Lower-bound given by Schnhage:
Addition-Subtraction Chains
Convert the binary number to a signed-digit representation using the digits {0, 1, -1}. These techniques use the identity: 2i+j-1 + 2i+j-2 ++2i = 2i+j - 2i To collapse a block of 1s in order to obtain a sparse representation of the exponent. Example: (011110) = 24 + 23 + 22 + 21 (100010) = 25 - 21 These methods require that M-1 mod n be supplied along with M.
Aritmtica Computacional
Francisco Rodrguez Henrquez
This algorithm is especially useful For ECC since the Inverse is available At no cost.
7. Return C;
Aritmtica Computacional
Francisco Rodrguez Henrquez
Aritmtica Computacional
The time or the power to execute c2 and c*a are different (side channel information).
Algorithm Corons exponentiation Input: a in G, exponent d = (dk,dk-1,,dl0) Output: c = ad in G 1. c[0] = 1; 2. For i = k-1 down to 0; 3. c[0] = c[0]2; 4. c[1] = c[0]*a; 5. c[0] = c[di]; 6. Return c[0];
Francisco Rodrguez Henrquez
Aritmtica Computacional
Input: M, e, n.
k %1
for ei # { ,1} 0 Output: C := Me mod n 1. R:= 1; C := M; 2. For i = 0 to n-1 3. If ei = 1 then R := RC mod n 4. C := C2 mod n 5. Return R;
Aritmtica Computacional
Francisco Rodrguez Henrquez
ei 0 1 0 1 1 1 1 1
Step 3 (R) 1 1*(M)2 = M2 M2 M2 * M8= M10 M10 * M16= M26 M26 * M32= M58 M58 * M64= M122 M122 * M128= M250
Step 4 (C) M2 (M2)2 = M4 (M4)2 = M8 (M8)2 = M16 (M16)2 = M32 (M32)2 = M64 (M64)2 = M128 (M128)2 = M256
Aritmtica Computacional
Aritmtica Computacional
Ejemplo
C !163 A!16 2 F !161 E !160
CAFE
=M
0xCAFE = 1100 1010 1111 1110 BM: 10 Mult. + 15 Sqr. Q-ary : 3 Mult + 47 sqr + 7 Symb. Q-ary+PC: 3 Mult. + 3sqr. + 28 Symb
Aritmtica Computacional
Aritmtica Computacional
Desarrollo (Anlisis)
Tamao de memoria y tiempo de ejecucin del precmputo W. Nmero de multiplicaciones y elevaciones al cuadrado para mtodo qario.
Aritmtica Computacional
Aritmtica Computacional
Tamao de Memoria
Aritmtica Computacional