Cryptography ALGAMAL System PFE Copy - 3
Cryptography ALGAMAL System PFE Copy - 3
Houari Boumediene
(USTHB)
Bachelor Project
Supervised by
6 September 2020
Declaration
I hereby certify that the material, which I now submit for assessment on the
programs of study leading to the award of Bachelor of Algebra and Cryptography
, is entirely my own work and has not been taken from the work of others except
to the extent that such work has been cited and acknowledged within the text of
my own work. No portion of the work contained in this thesis has been submitted
in support of an application for another degree or qualification to this or any other
institution.
———————————–
BOUSBIAT Fatma Zohra
6 September 2020
2
Acknowledgements
I would first like to thank my thesis advisor Dr Bennini of the Algebra and crypto-
graphy departement at university of science and technology Houari Boumedienne.
The door to Prof. Mr Bennini was always open whenever I ran into a trouble spot
or had a question about my research or writing. He consistently allowed this paper
to be my own work, but steered me in the right direction whenever he thought I
needed it, and I am gratefully indebted to him for his very valuable comments on
this thesis.
3
List of Figures
1 Symmetric encryption . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 Asymmetric encryption . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 block diagram of the introduced cryptosystem . . . . . . . . . . . . 15
4 Different values of g . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5 Encryption/Decryption Algorithm in Python . . . . . . . . . . . . . 18
6 Encryption/Decryption Algorithm in Python(following) . . . . . . . 19
7 El Gamal signing in python . . . . . . . . . . . . . . . . . . . . . . 20
8 El Gamal signing in python(followig) . . . . . . . . . . . . . . . . . 21
4
Contents
1 Introduction 7
2 Literature review 8
2.1 What cryptography is? . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Different types of cryptography . . . . . . . . . . . . . . . . . . . . 8
2.2.1 Symmetric Cryptography: . . . . . . . . . . . . . . . . . . . 8
2.2.2 Asymmetric Cryptography (Public Key Cryptography): . . . 9
2.3 How Diffie-Hellman protocol appeared ? . . . . . . . . . . . . . . . 10
2.4 The difference between Diffie-Hellman and El Gamal protocol . . . 10
2.5 ElGAMAL protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5.1 The Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5.2 Practical examples . . . . . . . . . . . . . . . . . . . . . . . 12
2.5.3 Advantage and Disadvantages of El-GAMAL . . . . . . . . . 14
3 Implementation 15
3.1 The introduced cryptosystem . . . . . . . . . . . . . . . . . . . . . 15
3.2 Picking g value in ElGamal and discrete logarithms . . . . . . . . . 16
3.3 ElGamal Encryption/Decryption: . . . . . . . . . . . . . . . . . . . 17
3.4 ElGamal signature . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5 Conclusions 22
5
Abstract
In the applications of Internet and wireless communication network, information
security is one of the most challenging aspects. Cryptography is the best solution
that offers the requisite protection from unintended persons. By using encryption
and decryption mechanisms, cryptography can convert the data from its readable
form to unreadable one so that only the intended receiver can read the message and
alter it. By this way, one can ensure that message can be sent or stored without
any modification. The presented work is concerned with a particular type of
asymmetric key cryptography called El-Gamal algorithm to be used for encryption
and decryption. The cryptosystem performance is evaluated via different quality
measures for encryption/decryption . The given results confirm the effectiveness
of the presented scheme .
6
1 Introduction
Information security is the protection of information and its critical elements, in-
cluding the systems and hardware that use, store, and transmit that information.
It includes the broad areas of information security management, computer, data
integrity1 and network security. It is based on the three characteristics of informa-
tion that gives it value to organizations: confidentiality, integrity, and availability.
The security of these three characteristics of information is as important today as it
has always been. for example, Access to sensitive military locations was controlled
by means of badges, keys, and the facial recognition of authorized personnel by
security guards.During these early years, information security was a straightfor-
ward process composed predominantly of physical security and simple document
classification schemes. but the growing need to maintain national security eventu-
ally led to more complex and more technologically sophisticated computer security
safeguards. Multiple levels of security were implemented to protect these main-
frames and maintain the integrity of the data.One of encryption systems that helps
to increase the level of security is The ElGamal encryption scheme, it has been
proposed several years ago and is one of the few probabilistic encryption schemes.
The following project is made up of two parts.In the first part, we are going to
start talking about information security and its importance nowadays. Then, we
will move further to define what cryptography is and cite its two different types.
Since The ElGamal protocol is based on the Diffie-Hellman protocol, we won’t
start talking about El-Gamal before mentioning how Diffie-Hellman protocol ap-
peared and the difference between the two schemes. After that, we will look at the
ElGamal scheme and its overall algorithms: Signature, encryption and decryption
algorithms. To clarify more, we will give some examples. Also, we will discuss ad-
vantages and disadvantages of ElGamal algorithms. When it comes to the second
part, an implementation will have place. Firstly, We are going to present the in-
troduced cryptosystem. Secondly, an implemantation of ElGamal algorithms in
Python will be included . Thirdly, we will talk about the security of the introduced
algorithm and finally comes the conclusion.
1
Ensuring that information has not been tampered with
7
2 Literature review
2.1 What cryptography is?
As we move further into an information society, the technological means for global
surveillance of millions of individual people are becoming available to major gov-
ernments. Cryptography has become one of the main tools for privacy, trust,
access control, electronic payments, corporate security, and countless other fields.
Cryptography is the art or science of keeping messages secret. People mean dif-
ferent things when they talk about cryptography. However, it contains the real
security which is the kind of security that can be used to protect information
of real value against organized criminals, multinational corporations, and major
governments. And strong encryption that is used to be only in the military do-
main; however, in the information society it has become one of the central tools
for maintaining privacy and confidentiality
Two parties agree on a secret key (private key)2 and use the same key for en-
cryption, and can at a later point use this secret key to decrypt a message. The
problem with this approach was that this method does not scale. If you wanted
to communicate privately with somebody, you would need to physically meet and
2
A secret random number generated by the user. It should be kept secret
8
agree on the secret key. In the world of modern communications, where we need
to coordinate with many actors, such methods would not be feasible.
Asymmetric cryptography uses key pairs for encryption where each party generates
their own public-private key pair. Private keys should be kept secret and a public
key 3 could be freely distributed among parties. In an asymmetric encryption
scenario, two parties would distribute their public keys and allow anyone to encrypt
messages using their public keys. Because of how a key pair mathematically works
it is impossible to decrypt a message which got encrypted with a public key. This
message can travel securely to the owner of the private key and only he/she would
be able to decrypt the message using the private key which is associated with the
public key .This method works the other way around. Any message encrypted
with a private key can only be decrypted with the corresponding public key. This
method is also referred as a Digital Signature. Public key cryptography has been
around since the 1970s and used in computer and communication security since
then. The first publicly available asymmetric key scheme was produced by the
cryptographers Ron Rivest, Adi Shamir and Leonard Adleman. The algorithm
was called RSA and it is still one of the most widely used algorithms as of today.
3
A public key is mathematically derived from the private key. It is made available to
everyone.
9
2.3 How Diffie-Hellman protocol appeared ?
Perhaps the most striking development in the history of cryptography came in
1976 when Whitfield Diffie and Martin Hellman published new directions in Cryp-
tography [Diffie and Hellman 1976] . Their work introduced the concept of public-
key cryptography and provided a new method for key exchange. This method is
based on the intractability of discrete logarithm problems. Although the authors
had no practical realization of a public-key encryption scheme at the time, the
idea was clear and it generated extensive interests and activities in the world of
cryptography. Diffie-Hellman Key Exchange is an asymmetric cryptographic pro-
tocol for key exchange and its security is based on the computational hardness of
solving a discrete logarithm problem.
10
2.5 ElGAMAL protocol
One of the powerful and practical public-key schemes ,was produced by ElGamal
in 1985 (ElGamal, 1985).ElGamal is based on the Diffie-Hellman Key Exchange
method. It uses the same domain parameters (p,q,g) and private/public key pair
(b,B = g b ≡ p) for a recipient B. The plaintext message to be encrypted needs to
be encoded as an integer m in the range [1,p−2].
Signature algorithm
The security of the ElGamal signature scheme is based on the discrete logarithm
problem (DLP). given a cyclic group, a generator g, and an element h, it is hard
to find an integer x such that gx = h.
The group is the largest multiplicative sub-group of the integers modulo p, with
p prime.
The signer holds a value x (0< x <p-1) as private key, and its public key y (where
y=gx ≡ p) is distributed.
11
ElGamal Encryption
2. Compute c1 = g k ≡ p
3. Compute c2 = mB k ≡ p
The ciphertext is the pair (c1,c2), which are both about p bits long.
ElGamal Decryption
1. Compute m = cp−b−1
1 c2 ≡ p
2. Return m.
ElGamal is a public key method that is used in both encryption and digital signing.
It is used in many applications and uses discrete logarithms. At the root is the
generation of P which is a prime number and G (which is a value between 1 and
P-1) [ Flonta and Miclea 2008]
Say the receiver chooses prime p = 71, and g=33 (We can check that 33 is a
∗
generator of Z71 ), and secret exponent x=62. Then h = gx ≡ 71 = 10. The
receiver would publish the public key (p=71, g=33, h=10).
Say a sender wants to send the message m=15. It chooses random exponent r=31,
say, computes the ciphertext (g r , hr m) = (62, 18), and sends this to the receiver.
12
To decrypt the ciphertext (62, 18), the receiver needs to compute 18/62x =
18/6262 . Recall that dividing by 62 modulo 71 really means to multiply by
62−1 ≡ 71. We can verify that 62−1 = 63 ≡ 71 because 62 · 63 = 1 ≡ 71.
Thus, the receiver will compute 18 · (62−1 )62 = 18 · 6362 ≡ 71 = 15. Of course, this
was exactly the message sent by the sender.
=101
13
2.5.3 Advantage and Disadvantages of El-GAMAL
ElGamal can also be made additively homomorphic for polynomial sized message
spaces (since decrypting involves computing discrete logarithms). It can be used
to construct a threshold cryptosystem, which means there are n parties holding
shares of the secret decryption key and a ciphertext can only be decrypted if at
least k of these n parties are involved in the decryption process but fewer then t
parties will fail in decrypting.
El-Gamal encryption is used in the free GNU6 privacy Guard Software,recent ver-
sions of PGP7 ,and other cryptosystems.
6
GNU is the name of a computer operating system
7
Pretty Good Privacy is an encryption program that provides cryptographic privacy and
authentication for data communication.
14
3 Implementation
3.1 The introduced cryptosystem
Two major parts are involved in the introduced cryptosystem: information en-
cryption and information decryption based on El-Gamal algorithm. First, the
public and private keys are generated, then the public key is used to encrypt the
acquired message at the sender side. Second, the ciphered or encrypted message
will be transmitted over a secure channel to the receiver sequentially. Third, the
encrypted information will be decrypted according to the private key at the recip-
ient side to reconstruct the original message. Figure 3 explains the block diagram
of the introduced cryptosystem.
15
3.2 Picking g value in ElGamal and discrete logarithms
In reading about cryptography, We often come across the term of a cyclic group
G of order p and a generator g.
The world of public key encryption is currently dominated by two things: discrete
logarithms and elliptic curve methods. RSA is becoming a thing of the past for
new applications, but it is only hanging on as it has such a monopoly in digital
certificates. And so with discrete logarithms and the Diffie-Hellman method we
end up with:
Y = gx ≡ p
where we have a generator value (g) and a prime number p. The challenge is that
even though we know Y, g and p, it is extremely difficult to determine the x value
if we use a large prime number.
So we can not use any value of g, and it should not be as large as possible. If select
a prime number of 7, and then select g values of 2, 3, 4 . . . 9, and then calculate
the results we get :
16
If we look when g=2, we get an output of 2, 4, 1, 2, 4 . . . for the sequence values
of 1, 2, . . . This means that we do not get a unique output for the values from
1 to 6 (where the maximum value will be six as we take the modulus of 7). But
when g = 3, we get 3 (31 ≡ 7), 2 (32 ≡ 7), 6 (33 ≡ 7), 4 (34 ≡ 7), 5 (35 ≡ 7), and
1 (36 ≡ 7), which means that we get a unique value for all the possible outputs
from 1 to 6, and which then repeats. For a prime number of 7, the valid values of
g are 3 and 5.
Initially Bob creates his public key by selecting a g value and a prime number p
and then selecting a private key (x). He then computes Y which is:
Y = gx ≡ p
His public key is (Y,g,p) and he will send this to Alice. Alice then creates a
message (M) and selects a random value (k). She then computes a and b:
a = gk ≡ p b = yk M ≡ p
17
Figure 5: Encryption/Decryption Algorithm in Python
18
Figure 6: Encryption/Decryption Algorithm in Python(following)
v = gs ≡ p
To sign a document (D), we create an ephemeral key (e). Next we calculate two
signature values:
S1 = g e ≡ p
19
S2 = (D − eS1 )e−1 ≡ p − 1
v1 = v S1 S1S2 ≡ p
v2 = g D ≡ p
The public verification part of the signature is g,v,p and the signature is S1,S2.
The secret is s.
20
Figure 8: El Gamal signing in python(followig)
ElGamal encryption, when the paramters are chosen in the right way achieves the
weaker notion of indistinguishability under chosen plaintext attacks. its security
has been concretely proven on multiple levels. [Tsiounis and Yung 1998]
21
5 Conclusions
The developments of hardware are significantly ameliorated and the cryptographic
calculations can be performed rapidly in the present day. Furthermore, the attacks
of hackers on the cryptographic algorithms can be also developed rapidly. Hence,
rapid security serving will be required. Thus, the best solution to manage the key
is public key cryptography. In public key cryptography, each user is responsible of
protecting his private key. Predominantly, this feature is called non-repudiation
which is missing in symmetric algorithms. Asymmetric key cryptography is the
basis for secure exchange of data by users through the networks. El-Gamal al-
gorithm is special type of public key technology that used in this article for en-
cryption/decryption. The security of this cryptosystem is based on the difficulty of
calculating discrete logs modulus of a large prime. Breaking El-Gamal cryptosys-
tem is based on resolving the problem of discrete logarithm to obtain the private
key x and finding c1 .
Thus, this system is applied in order to perform secrecy, confidently and security
of important information. The performance analysis of the presented cryptosys-
tem in terms of different encryption and decryption scheme measures indicates a
satisfactory level of security .
22
References
Diffie, Whitfield and Martin Hellman (1976). ‘New directions in cryptography’. In:
IEEE transactions on Information Theory 22.6, pp. 644–654.
Flonta, Stelian and Liviu Miclea (2008). ‘An extension of the El Gamal encryption
algorithm’. In: 2008 IEEE International Conference on Automation, Quality and
Testing, Robotics. Vol. 3. IEEE, pp. 444–446.
Grewal, Jaspreet Kaur (2015). ‘ElGamal: Public-Key Cryptosystem’. In: Master
of Science to the Math and Computer Science Department Indiana State Uni-
versity.
Tsiounis, Yiannis and Moti Yung (1998). ‘On the security of ElGamal based en-
cryption’. In: International Workshop on Public Key Cryptography. Springer,
pp. 117–134.
23