Even if they want to develop their own tool for a digital signature, they give up ... Further, there is a need for the skilled people who are able to implement that ...
IJTPC(ISSN: 2322-3138), Vol. 2, March 2013.
Preparing for a (RSA) Digital Signature 1
1
2
Dragan Vidakovic , Jelena Kaljevic and Dusko Parezanovic Faculty of Business Valjevo, Singidunum University Belgrade, Serbia 2 Club of young mathematicians and computer scientists INFOMAT Ivanjica, Serbia 1
ABSTRACT Many people know the general story about RSA and large (probably) prime numbers, without having an idea of how to perform arithmetic operations with the numbers of thousands of bits. Even if they want to develop their own tool for a digital signature, they give up because they think that special hardware-software offers are required for that. In this paper we want to show that even by using a very simple console application, the tools for signature can be developed. Those tools are not as powerful and functional as the products of renowned companies, but they are sufficient to stimulate the interest in cryptography (and the coding of known algorithms is the best way for that), and that is our overriding and permanent goal[3]. Keywords Cryptography, Digital Signature, Some elements, Examples. 1. INTRODUCTION There is no doubt that the best protection is the protection with our own code. Even the thought of protecting data privacy using somebody else’s tools seems illogical. Developing your own tools is a process that requires a lot of knowledge, skills, patience and a great responsibility [4]. Further, there is a need for the skilled people who are able to implement that, and those people can be selected only in a case of growing interest in cryptography. Unfortunately or necessarily, cryptography itself seems very cryptic and discouraging. Our goal is to show that this need not be so, and in this paper, we will present the code for the basic arithmetic operations of large numbers (by setting of constants nn and nn1 in unit3, it would be possible to operate with arbitrarily large binary numbers) and the code for SHA-1. 2. THE RSA SIGNATURE SCHEME Algorithm Key generation for the RSA signature scheme [1] SUMMARY: each entity creates an RSA public key and a corresponding private key. Each entity A should do the following: 1. Generate two large distinct random primes p and q, each roughly the same size (see x11.3.2). 2. Compute n = pq and φ= (p − 1)(q − 1). 3. Select a random integer e, 1 < e < φ such that gcd(e, φ) = 1. 4. Use the extended Euclidean algorithm ([2]) to compute the unique integer d, 1 < d < φ, such that ed ≡1 (mod φ) 5. A’s public key is (n; e); A’s private key is d Algorithm RSA signature generation and verification SUMMARY: entity A signs a message m∈ ∈ . Any entity B can verify A’s signature and
www.IJTPC.org
recover the message m from the signature. 1. Signature generation. Entity A should do the following: (a) Compute m’ = R(m), an integer in the range [0; n − 1]. d (b) Compute s = (m’) mod n. (c) A’s signature for m is s. 2. Verification. To verify A’s signature s and recover the message m, B should: (a) Obtain A’s authentic public key (n; e). e (b) Compute m’= s mod n. (c) Verify that m’∈ R; if not, reject the signature. (d) Recover m = R−1(m’). 3.
ADDITION, SUBRTACTION and MULTIPLICATION ALGORITHMS
Algorithms for the operations that we want to encode can be found in [1]. 3.1 Addition INPUT: posiDve integers x and y, each having n + 1 base b digits. OUTPUT: the sum x + y = (wn+1wn …w1w0)b in radix b representation. 1. c 0 (c is the carry digit). 2. For i from 0 to n do the following: 2.1 wi (xi + yi + c) mod b. 2.2 If (xi + yi + c) < b then c 0; otherwise c - 1. 3. wn+1 c. 4. Return((wn+1wn …w1w0)). 3.2 Subtraction INPUT: positive integers x and y, each having n + 1 base b digits, with x≥ ≥ y. OUTPUT: the difference x − y = (wnwn−1…w1w0)b in radix b representation. 1. c 0.
6
IJTPC(ISSN: 2322-3138), Vol. 2, March 2013. 2. For i from 0 to n do the following: 2.1 wi (xi − yi + c) mod b. 2.2 If (xi − yi + c) ≥0 then c 0; otherwise c −1. 3. Return((wnwn−1 …w1w0)). 3.3 Multiplication INPUT: posiDve integers x and y having n + 1 and t + 1 base b digits, respectively. OUTPUT: the product x y = (wn+t+1 …w1w0)b in radix b representation. 1. For i from 0 to (n + t + 1) do: wi 0. 2. For i from 0 to t do the following: 2.1 c 0. 2.2 For j from 0 to n do the following: Compute (uv)b = wi+j + xj yi + c, and set wi+j v, c u. 2.3 wi+n+1 =u. 3. Return((wn+t+1…w1w0)). 4. CONSOLE APPLICATION- DELPHI 7 The program that calculates the sum, subtraction and product of two arbitrarily large numbers written in the binary number system will be presented in this paragraph. Program arithmetics; {$APPTYPE CONSOLE} Uses SysUDls, Unit3_fiz; var a,b,c:array[0..nn] of integer; var i,s:integer; begin writeln('Input numbers a and b to 128 bits- Example 2'); writeln; {example 1} {a[127]:=1; a[100]:=1;a[50]:=1;a[5]:=1; b[127]:=1; b[70]:=1; b[60]:=1;b[20]:=1;b[10]:=1;b[1]:=1; } {examlpe 2} a[6]:=1;a[0]:=1; b[5]:=1;b[4]:=1; saberi(a,b,c); writeln('number a:'); for i:=127 downto 0 do write(a[i]);writeln; writeln; Writeln('number b:'); for i:=127 downto 0 do write(b[i]);writeln; writeln; writeln('a+b='); dokle(c,s); for i:=s downto 0 do write(c[i]); writeln; oduzmi(a,b,c); dokle(c,s); writeln; Writeln('a-b='); for i:=s downto 0 do write(c[i]); writeln; mnozi(a,b,c); dokle(c,s); writeln; Writeln('a*b='); for i:=s downto 0 do write(c[i]); writeln; readln; end. 4. 1 Unit for Console Application The unit that serves arithmeDcs program in [4] is cited in this paragraph. unit Unit3_fiz;
www.IJTPC.org
interface const nn=258; const nn1=258; procedure saberi(x,y:array of integer;var w:array of integer); procedure oduzmi(x,y:array of integer;var w:array of integer); procedure veci1(var x:array of integer;var s:integer); procedure mnozi(r,rr:array of integer;var w1:array of integer); procedure sab(x,y,z:integer;var k,l:integer); procedure dokle(var a:array of integer;var s1:integer); implementation procedure saberi(x,y:array of integer;var w:array of integer); var c1,i1,s1,s2:integer; begin s1:=0;s2:=0;veci1(x,s1);veci1(y,s2); if ((s1>=0) and (s2>=0)) then begin c1:=0; for i1:=0 to nn1 do begin w[i1]:=(x[i1]+y[i1]+c1) mod 2; if (x[i1]+y[i1]+c1)=0) and (s2=0 then c1:=0 else c1:=-1; end; if k=1 then c1:=0; if c1=-1 then begin for i1:=0 to nn do x[i1]:=0; for i1:=0 to nn do y[i1]:=w[i1]; c1:=0;k:=1;goto 1;end; if k=1 then for i1:=0 to nn do w[i1]:=-w[i1];end else if ((s1>=0) and (s2