• No results found

Rabin Cryptography and Implementation using C programming language

N/A
N/A
Protected

Academic year: 2021

Share "Rabin Cryptography and Implementation using C programming language"

Copied!
19
0
0

Loading.... (view fulltext now)

Full text

(1)

Jagannath University

Department of Computer Science and Engineering M.Sc in Computer Science and Engineering (Evening) Program

Submitted To: Aminul Islam Submitted By: Al-Amin Shohag

Section: A Student ID: M160305504

(2)

Chapter 1. Introduction 1.1 Public key cryptosystem

1.1.1 RSA Cryptosystem

1.1.2 Brief Introduction toRabin Cryptosystem Chapter 2. Introduction to CryptographicMathematics

2.1 Integer

2.1.1 Integerrepresentations 2.1.2 Greatest Common Division 2.1.3 Primes 2.1.3.1 Relative Primes 2.1.3.2 Generating Primes 2.2 ModularArithmetic 2.2.1Congruence 2.2.2 Multiplicative Inverse 2.3 Chinese Remainder Theorem

Chapter 3. Introduction to Rabin Cryptosystem 3.1 Rabin Cryptosystem

3.1.1 Key Generation Algorithm 3.1.2 Encryption Algorithm

(3)

3.1.3 Decryption Algorithm 3.2 Security and Attacks

Chapter 4. Implementing CRT and Rabin Decryption Algorithm Using C Programming Language 4.1CRT and Rabin Decryption Program in C

4.2 Limitations in Implementing CRT and Rabin Decryption Algorithm in C 4.3 Assumptions

Future Intend Reference

(4)

Chapter 1

Introduction to Public Key Cryptosystem 1.1 Introduction

Public key cryptosystem which is also known as asymmetric key cryptography was introduced in the year 1970 to avoid the need for keys sharing by every pair of parties that wish to communicate securely. Such system allows all the parties to encrypt messages using a key that is known to all but the decryption is allowed only to the intended party of those messages. The recipient of a message uses a key to decrypt it. The key that is used by all parties is known as public key and the key used by the recipient to decrypt the message is known as private key or secret key. The encrypted message sent by a party is called cipher text. And the message is called plaintext. The plaintext and cipher text are treated as integers in this system.

The cipher text which is denoted as C=f(public key, plaintext). The plaintext which is denoted as P=f(private key, cipher text).

Public key cryptosystem is normally used for to encrypt or decrypt small pieces of information, such as the cipher key for a symmetric key cryptosystem. It is a system used for auxiliary goal instead of message encipherment.

1.1.1 RSA Cryptosystem

The most common public key cryptosystem is the RSA cryptosystem named after the inventors Rivest, Adi Shamir and Leonard Adleman. It was invented in 1976 by these three researchers at Massachusettes Institute of Technology(MIT). The system uses two exponent e and d where e is public and d is private. The encryption of the plaintext p is done by using e , n and modular arithmetic which produces cipher text c and decryption is done using d ,n and modular arithmetic to get the plaintext from the cipher text c. The n is generated through key generation algorithm of RSA cryptosystem.

(5)

Encryption:

c= p

e

modn

Decryption:

p=c

d

modn

Key generation: select two large primes p ,q. Then the following steps are followed.

1. Calculate:

n=p × q

2. Calculate : (n)=(p-1)(q-1)ɸ

3. Select : e such that 1<e< (n) and e is a relative prime to (n).ɸ ɸ 4. Calculate:

d=e

−1

mod Φ(n)

Although RSA can be used to encrypt and decrypt actual message, it is very slow if the message is long. RSA, therefore is useful for short messages.

1.1.2 Brief Introduction to Rabin Cryptosystem

The Rabin cryptosystem invented by M. Rabin is considered as a variation of the RSA cryptosystem though it has the quality to claim itself as a distinct public cryptosystem. RSA is based on the exponent congruence whereas Rabin is based on quadric congruence. The Rabin Cryptosystem can be considered as RSA cryptosystem in which the value of e and d are fixed. That is e=2 and d=1/2. Key generation, encryption and decryption will be discussed later in chapter 3.

(6)

Chapter 2

Introduction to Cryptographic Mathematics 2.1 Integers

In integer arithmetic, we use a set which is mostly denoted as Z such that Z={….,-2,- 1,0,1,2….}. In cryptosystem we use many subsets of Z such as subset of positive integers, prime integers, subsetof integers without 0.

2.1.1 Integer representations

In cryptography only positive integers are used. The set of positive integers are denoted as

Z

n = {0, 1, 2….}. Another form of Z

is the multiplicative group which derived from

Z

n ¿

= {1, 2, 3…}. Another form of

Z

n is prime number group which denoted as

Z

¿p

= {1, 2 …….} which follows the rule that is

gcd

(

a , p

)

=1

.

2.1.2 Greatest Common Divisor

The greatest common divisor of two positive integers is the largest integers that can divide both integers. There two ways of calculating greatest common divisor. One is Euclidean Algorithm (EA) and the other is Extended Euclidean Algorithm (EEA). If a and b are two numbers then

gcd (a , o )=0

And

(7)

gcd (a , b )=gcd (b ,r)

Where r is the remainder of dividing a by b.

EA is used for finding relative prime. EEA is in RSA cryptosystem for calculating multiplicative inverse.

2.1.3 Primes

Public key cryptography uses primes extensively. The definition of prime states, A positive integer is a prime if and only if it is exactly divisible by two integers that is by 1 and itself.

2.1.3.1 Relative Primes

Two positive integers a and b are relatively prime if

gcd (a , b )=1

. Relative prime is used in Rabin Cryptosystem for selecting large prime.

2.1.3.2 Generating Primes

There have many prime generating functions for prime numbers. Such as Mersenne prime generating function, Farmat prime generating function. Mersenne Prime:

M

p

=2

p

−1

Farmat Prime:

F

n

=2

n 2

−1

2.1.3.3 Primility Test

There have deterministic and probabilistic Primility test algorithm. Divisibility test, AKS (Agrawal, Kayal, Saxena) test are deterministic test. And Square root test, Miller Rabin test, Farmat test are common probabilistic test.

(8)

If a and b are integers and m is apoistive integers, then a is congruent to b modulo m if m divides a-b. We use the notation

a ≡bmodm

to indicate that a is congreunt to b modm. We say that a

a ≡bmodm

is a congruence and that m is the modulus. It is important to know that

a ≡bmodm is actually amodm=bmodm

2.2.1 Congruence

A congruence of the form

ax ≡ modm

. Where m is a positive integer a and b are integers and x is a variable is called a linear congruence.

2.2.2 Multiplicative Inverse

Multiplicative inverse of x exist if only if there is a y for which

x × y ≡1 modm

2.3 Chinese Remainder Theorem

The Chinese Remainder Theorem is used to solve a set of congruent equations with one variable but different moduli, which are relatively prime. According to definition

(9)

x ≡ a

1

mod m

1

x ≡ a

2

mod m

2 ………. ……….

x ≡ a

k

mod m

k

Now this is a system oflinearequation. To solve the problem we have to follow the following steps:

1. Calculate:

M=m

1

× m

2

× … … … ….. × m

k 2. Calculate:

M

1

=

M

m

1

, M

2

=

M

m

2

… …… .. M

k

=

M

m

k

3. Calculate: Multiplicative inverse of

M

1

, M

2

, M

3

,… … … … M

k . We call them as

M

−1

, M

−2

, … … … … M

k .

4. The solution will be:

x=

(

a

1

× M

1

× M

−1

+

… … … … .+a

k

× M

k

× M

k

)

modM

(10)

Chapter 3

Introduction to Rabin Cryptosystem

3.1 Rabin Cryptosystem

A desirable property of any cryptosystem is a proof that breaking it is as difficult as solving a computational problem that is widely believed to be difficult such as integer factorization or discrete algorithm problem. The Rabin Cryptosystem was first of a provably secure public key cryptosystem where the problem faced by an attacker is of recovering plaintext from some given cipher text is computationally equivalent to factoring. In chapter 1 we discussed briefly about Rabin Cryptosystem. Now to achieve such cryptosystem we have to follow a procedure of three algorithm namely key generation algorithm, encryption algorithm and decryption algorithm.

3.1.1 Key Generation Algorithm

Key generation for Rabin cryptosystem follows steps below:

1. Chose two large primes p and q in the form

4 k +3 andp ≠ q

2. Calculate:

n=p × q where n is public key

3. Send: public key n with private key q

3.1.2 Encryption Algorithm

Steps encrypting a message p using encryption algorithm as follows: 1. Receive: Public key n with private key q

(11)

3. Send: Cipher text c

3.1.2 Decryption Algorithm

For decrypting c to get p decryption algorithm follows steps below:

1. Calculate:

a

1

=

c

(p+1) 4

modp

a

2

=−

c

(p+1) 4

modp

b

2

=

c

q+1 4

modq

b

2

=−

c

(q+1) 4

modq

2. Calculate:

p

1

← ChineseRemainder

(

a

1

, b

2

, p , q

)

p

2

← ChineseRemainder (a

1

, b

2

, p . q)

P

3

← ChineseRemainder(a

2

, b

1

, p , q)

p

4

←ChineseRemainder (a

2

, b

2

, p , q)

(12)

3.1 Security and Attacks

The Rabin cryptosystem is secure as long as p and q are large numbers. The complexity of the Rabin system is at the same level as factoring a large number n into its two prime factors p and q. In other words, the Rabin system is as secure as RSA. Chosen cipher text attack is one of the main attacks against Rabin cryptosystem.

CHAPTER 4

Implementing CRT and Rabin Decryption Algorithm In C Programming Language

4.1 CRT and Rabin decryption algorithm implementation using C programming: #include<stdio.h>

#include<conio.h>

int CRT(int* a, int* b,intp,int q) {

intmul, division_1, division_2, invrs_1, invrs_2, plaintext; intf,g,d,e,k,l; f= *a; g= *b; printf("F=%d\n",f); printf("G=%d\n",g); mul=p*q; printf("MUL=%d\n",mul);

(13)

division_1=mul/p; printf("DIVISION_1=%d\n",division_1); division_2=mul/q; printf("DIVISION=%d\n",division_2); for(invrs_1=1;invrs_1<=10;invrs_1++) { d= (division_1 *invrs_1)%p; printf("D=%d\n",d); if(d==1) { k=invrs_1; printf("K=%d\n",k); } }

(14)

for(invrs_2=1;invrs_2<=10; invrs_2++) { e=(division_2*invrs_2)%q; printf("E=%d\n",e); if(e==1) { l=invrs_2; printf("L=%d\n",l); } }

plaintext=((f* division_1* k)+(g* division_2 * l))%mul; return plaintext;

}

int main(void) { intp,q, z,y;

unsigned long int c,r,s,w,c_1;

int a_1,a_2,b_1,b_2,p_1,p_2,p_3,p_4,i,j; intk,l;

(15)

scanf("%d",&c);

printf("Take prime numbers p as input:\n"); scanf("%d",&p);

printf("Take Prime number q as input:\n"); scanf("%d",&q); z=(p+1)/4; printf("Z=%d\n",z); y=(q+1)/4; printf("Y=%d\n",y); w=c; for(i=1;i<z;i++) { r= w*c ; c = r; printf("C=%d\n",c); } a_1=c%p; printf("a_1=%d\n",a_1); a_2= -(c%p)+p;

(16)

printf("a_2=%d\n",a_2); c_1=w; for(j=1;j<y;j++) { s= c_1* w ; w = s; printf("W=%d\n",w); } b_1=w%q; printf("b_1=%d\n",b_1); b_2=-(w%q)+q; printf("b_2=%d\n",b_2); p_1=CRT(&a_1,&b_1,p,q); printf("P1=%d\n",p_1); p_2=CRT(&a_1,&b_2,p,q);

(17)

printf("P2=%d\n",p_2); p_3=CRT(&a_2,&b_1,p,q); printf("P3=%d\n",p_3); p_4=CRT(&a_2,&b_2,p,q); printf("P4=%d",p_4); getch(); }

4.2 Limitations of Chinese remainder algorithm in calculating plaintext fromcipher text using C programming language: 1. We cannot use built in exponent function of C because it uses double type data.

2. For unsigned long integer type data, “C” allocates 32 bits by which we can represent numbers from 0-42949677295.

Which limits our attempts for decrypting cipher text beyond 9745 by Rabin decryption algorithm using C programming language because it uses prime numbers that is generated such that

(

p , q)=( 4 k +3 )mod 4

.

Though It has two data types to represent floating point number. One is float data type and other is double data type which uses 4 bytes and 8 bytes respectively. And these 32 bits of float and 64 bits for double are also divided into exponent and mentisa. Again bit limits are there and not to mention Rabin Cryptography system uses positive integers for encryption and decryption

(18)

4.3 Assumptions

For unsigned long integer inC programming we can calculate:  Exponent up to 32 for the number 2

 Exponent up to 20 for the number 3  Exponent up to 16 for the number 4  Exponent up to 13 for the number 5  Exponent up to 12 for the number 6  Exponent up to 11 for the number 7  Exponent up to 10 for the numbers 8-11  Exponent up to 8 for the numbers 12-16  Exponent up to 7 for the numbers 17-23  Exponent up to 6 for the numbers from 24-39.  Exponent up to 5 for the numbers from 40-175  Exponent up to 4 for the numbers from 176-456  Exponent up to 3 for the numbers from 457-1625  Exponent up to 2 for the rest of numbers

Future Intend

1. To look for better way of implementing CRT and Rabin Decryption algorithm using programming language. 2. To design a processor for Rabin Cryptosystem and hardware implementation of the system.

(19)

Reference

[1].Cryptography & Network Security byBehrouz A. Forouzan

[2]. Hand book of Applied Cryptography by Alfred J Menezes, Paul C. Van Oorschot and Scott A. Vanstone [3]. Discrete Mathematics and Its Application by Kenneth H. Rosen

[4]. An Introduction to Cryptography by Kenneth H. Rosen [5]. C Computer Programming Language by Kamruzzaman Niton [6]. Internet and Wikipedia

References

Related documents

Keywords: economic model predictive control; nonlinear constraint relaxation; periodic operation; difference-algebraic equations; water distribution

simultaneity, fragmentation, contamination and constraint predict greater negative work- to-family spillover; in other words, the temporal conditions that have emerged in today’s

To evaluate the relationship between teams’ co-location and project performance, this paper uses a parallel between project performance parameters proposed by Clark

„ Wang AIDS 2005, Wines Drug Alcohol Depend 2007 Sporer 2006,. http://www.whitehousedrugpolicy.gov/news/fentnyl%5Fheroin%5Fforum ,

Functions in the C programming Language ie in function call Void Function Definition Using Value Parameters Example C requires variable declarations at?. Thus in cipher

The development of this architecture is based on several programming language as it involves algorithm implementation on C, parallelization using Parallel Virtual

&gt; Make use of computerized software for hydraulic design calculations &gt; Chiller plant must be balanced to avoid uneven distribution of flow &gt; Proper bypass valve sizing

Although our example below of how to programmatically control BarTender uses C# as the programming language, when you are using C# or VB.NET, it is much easier to use the