0% found this document useful (0 votes)
73 views

Exp2 Write a Program to Implement RSA Algorithm and Digital Signature Scheme Using RSA ElGamal

Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Exp2 Write a Program to Implement RSA Algorithm and Digital Signature Scheme Using RSA ElGamal

Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Terna Engineering College

Computer Engineering Department

Class: TE Sem.: VI

Course: System Security Lab

PART A
(PART A : TO BE REFFERED BY STUDENTS)

Experiment No.02
A.1 Aim:
Write a program to implement RSA algorithm and Digital Signature scheme using RSA /
ElGamal.
A.2 Prerequisite:
1. Basic Knowledge of Asymmetric Key Cryptography.

A.3 Outcome:
After successful completion of this experiment students will be able to;
1. Analyze the various public key cryptographic techniques and their applications.

A.4 Theory:
A. RSA Algorithm:

 RSA (Rivest–Shamir–Adleman) is one of the first public-key cryptosystems and is


widely used for secure data transmission. In such a cryptosystem, the encryption key
is public and it is different from the decryption key which is kept secret (private). In
RSA, this asymmetry is based on the practical difficulty of the factorization of the
product of two large prime numbers, the "factoring problem". The acronym RSA is
made of the initial letters of the surnames of Ron Rivest, Adi Shamir, and Leonard
Adleman, who first publicly described the algorithm in 1978. Clifford Cocks, an
English mathematician working for the British intelligence agency Government
Communications Headquarters (GCHQ), had developed an equivalent system in
1973, but this was not declassified until 1997.

 A user of RSA creates and then publishes a public key based on two large prime
numbers, along with an auxiliary value. The prime numbers must be kept secret.
Anyone can use the public key to encrypt a message, but with currently published
methods, and if the public key is large enough, only someone with knowledge of the
prime numbers can decode the message feasibly.[2] Breaking RSA encryption is
known as the RSA problem. Whether it is as difficult as the factoring problem
remains an open question.

 RSA is a relatively slow algorithm, and because of this, it is less commonly used to
directly encrypt user data. More often, RSA passes encrypted shared keys for
symmetric key cryptography which in turn can perform bulk encryption-decryption
operations at much higher speed.

 ALGORITHM:

1. Accept two prime numbers from user (say p and q).


2. Calculate n = p * q.
3. Calculate Φ(n) as
Φ (n) = (p - 1) * (q – 1).
4. Considering e * d = Φ(n) + 1, determine e and d where e and d are prime numbers.
5. So display information at sender as (e, n) and information at receiver as (d , n).
6. Check whether user is sender or receiver.
7. If user is sender
a. Get message M from user.
b. C = Me mod n.
c. Send cipher text C to receiver.
d. Go to stop.
8. If user is receiver
a. Get cipher text C from user.
b. M = Cd mod n.
c. Display plain text M to receiver.
d. Go to stop.
9. Ask whether user wants to continue (yes or no?)
If yes, go to step 7.
Else go to stop.
 EXAMPLE:
 Choose p = 3 and q = 11
 Compute n = p * q = 3 * 11 = 33
 Compute φ(n) = (p - 1) * (q - 1) = 2 * 10 = 20
 Choose e such that 1 < e < φ(n) and e and n are co-prime. Let e = 7
 Compute a value for d such that (d * e) % φ(n) = 1. One solution is d = 3 [(3 * 7) %
20 = 1]
 Public key is (e, n) => (7, 33)
 Private key is (d, n) => (3, 33)
 The encryption of m = 2 is c = 27 % 33 = 29
 The decryption of c = 29 is m = 293 % 33 = 2

B. Digital Signature RSA :

Traditionally signature with a message is used to give evidence of identity and intention with regard
to that message. For years people have been using various types of signature to associate their identity and
intention to the messages. Wax imprint, seal, and handwritten signature are the common examples. But when
someone need to sign a digital message, things turn different. In case of signing a digital document one
cannot use any classical approach of signing, because it can be forged easily. Forger just need to cut the
signature and paste it with any other message. For signing a digital document one uses digital signature.

Therefore, digital signature are required not to be separated from the message and attached to another. That is a
digital signature is required to be both message and signer dependent. For validating the signature anyone can
verify the signature, so digital signature is supposed to be verified easily.

A digital signature scheme typically consists of three distinct steps:

1. Key generation:- User compute their public key and corresponding private key.
2. Signing:- In this step user sign a given message with his/her private key.

3. Verification:- In this step user verify a signature for given message and public key.

So the functionality provided by digital signature can be stated as follows:

Authentication:- Digital signature provides authentication of the source of the messages as a message is
signed by the private key of the sender which is only known to him/her. Authentication is highly desirable in
many applications.

Integrity:- Digital signature provides integrity as digital signature uniquely associate with corresponding
message. i.e. After signing a message a message cannot be altered if someone do it will invalidate the
signature. There is no efficient method to change message and its signature to produce a new message and
valid signature without having private key. So both sender and receiver don’t have to worry about in transit
alteration.

Non- repudiation:- For a valid signature sender of message cannot deny having signed it.

RSA digital signature scheme


Suppose Alice want to send a message(m) to Bob. She can generate digital signature using RSA digital
signature scheme [4] as follow:

Key Generation:-
She can generate key for RSA signature scheme:

1. Choose two distinct large prime numbers p and q.


2. Compute n = pq.

3. n is used as the modulus for both the public and private keys.

4. Compute φ(n) = (p − 1)(q − 1), where φ is Euler’s totient function.

5. Choose an integer e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1.

6. Compute d = e−1 modφ(n).

Then the public key and private key of user will be (e, n) and (d, n) respectively.
Now she have her public and private key. Now she can generate the signature of a message by encrypting it by
her private key.
So she can generate signature corresponding to message(m) as follow:

Signing: -

1. Represent the message m as an integer between 0 and n − 1.


2. Sign message by raising it to the dth power modulo n.

S ≡ md (mod n)

So S is the signature corresponding to message m. Now she can send message m along with the signature S to
Bob.

Upon receiving the message and signature (m, S), Bob can verify the signature by decrypting it by Alice public
key as follow:

Verification:-

1. Verify signature by raising it to the eth power modulo n.

m' ≡ Se (mod n)

2. If m' = m (mod n) then signature is valid otherwise not.

For a valid signature both m and m' will be equal because:


S ≡ md (mod n)
m' ≡ mde(mod n)
and
e is inverse of d, i.e. ed ≡ 1(mod Φ(n)).

So, by using above algorithm Alice can generate a valid signature S for her message m, but there is a problem
in above define scheme that is the length of the signature is equal to the length of the message. This is a
disadvantage when message is long.

Additional instructions for RSA signature algorithm is as follows:

An RSA digital signature key pair consists of an RSA private key, which is used to compute a digital signature,
and an RSA public key, which is used to verify a digital signature. An RSA digital signature key pair shall not
be used for other purposes (e.g. key establishment).

An RSA public key consists of a modulus n, which is the product of two positive prime integers pand q (i.e., n
= pq), and a public key exponent e. Thus, the RSA public key is the pair of values (n, e) and is used to verify
digital signatures. The size of an RSA key pair is commonly considered to be the length of the modulus n in
bits (nlen). The corresponding RSA private key consists of the same modulus n and a private key
exponent d that depends on n and the public key exponent e. Thus, the RSA private key is the pair of
values (n, d) and is used to generate digital signatures. In order to provide security for the digital signature
process, the two integers p and q, and the private key exponent d shall be kept secret. The modulus n and the
public key exponent e may be made known to anyone.

The Standard specifies three choices for the length of the modulus (i.e., nlen): 1024, 2048 and 3072 bits.

An approved hash function, shall be used during the generation of key pairs and digital signatures. When used
during the generation of an RSA key pair, the length in bits of the hash function output block shall meet or
exceed the security strength associated with the bit length of the modulus n. The security strength associated
with the RSA digital signature process is no greater than the minimum of the security strength associated with
the bit length of the modulus and the security strength of the hash function that is employed. Both the security
strength of the hash function used and the security strength associated with the bit length of the
modulus n shall meet or exceed the security strength required for the digital signature process.
PART B
(PART B : TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per following segments within two hours of the practical. The
soft copy must be uploaded on the Blackboard or emailed to the concerned lab in charge faculties at
the end of the practical in case the there is no Black board access available)

Roll No. Name:


Class : Batch :
Date of Experiment: Date of Submission
Grade :

B.1 Output of RSA Algorithm with Digital Signature :


(add snapshot of output of RSA Algorithm with Digital Signature)

B.2. Source Code of RSA Algorithm with Digital Signature:


(Add source code of RSA Algorithm with Digital Signature)

B.3 Question of Curiosity:


1. What is asymmetric key encryption?
2. Differentiate between symmetric and asymmetric encryption algorithms.
3. Explain different uses of RSA algorithm.
4. List and explain different possible attacks on RSA.
5. Explain the digital signature scheme DSS

B.4 Conclusion:
(Write appropriate conclusion.)

You might also like