Rabin Cryptography and Implementation Using C Programming Language
Rabin Cryptography and Implementation Using C Programming Language
Section: A
Session: Winter-2016
1
Chapter 1. Introduction
2.1 Integer
2.1.1 Integerrepresentations
2.1.3 Primes
2.2 ModularArithmetic
2.2.1Congruence
2
3.1.3 Decryption Algorithm
Chapter 4. Implementing CRT and Rabin Decryption Algorithm Using C Programming Language
4.3 Assumptions
Future Intend
Reference
3
Chapter 1
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.
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.
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.
4
e
Encryption: c= p modn
d
Decryption: p=c 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).
1
4. Calculate: d=e 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.
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.
5
Chapter 2
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.
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 .
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
6
gcd ( a , b )=gcd ( b ,r )
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.
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.
There have many prime generating functions for prime numbers. Such as Mersenne prime generating function, Farmat prime
generating function.
p
Mersenne Prime: M p=2 1
n
2
Farmat Prime: Fn =2 1
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.
7
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
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.
x y 1 modm
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
8
x a1 mod m1
x a2 mod m2
x ak mod mk
Now this is a system oflinearequation. To solve the problem we have to follow the following steps:
1. Calculate:
M =m1 m2 .. mk
M M M
M 1= , M 2= .. M k =
2. Calculate: m1 m2 mk
Rabin Cryptosystem uses this algorithm to decrypt the cipher text which we will see in chapter 3.
9
Chapter 3
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.
10
3. Send: Cipher text c
( p+1 )
4
1. Calculate: a1=c modp
( p+1)
4
a2=c modp
q+1
4
b2=c modq
(q+1)
4
b2=c modq
2. Calculate:
p1 ChineseRemainder ( a1 , b2 , p , q )
p2 ChineseRemainder (a 1 , b2 , p . q)
P3 ChineseRemainder (a2 , b 1 , p , q)
p4 ChineseRemainder (a2 , b2 , p , q)
11
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
#include<stdio.h>
#include<conio.h>
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);
12
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);
13
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);
return plaintext;
int main(void)
{ intp,q, z,y;
int a_1,a_2,b_1,b_2,p_1,p_2,p_3,p_4,i,j;
intk,l;
14
scanf("%d",&c);
scanf("%d",&p);
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;
15
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);
16
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
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
17
4.3 Assumptions
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.
3. To create a software demo of the system with graphical user interface.
18
Reference
[2]. Hand book of Applied Cryptography by Alfred J Menezes, Paul C. Van Oorschot and Scott A. Vanstone
19