SlideShare a Scribd company logo
A Fast Implementation of RSA
using GNU MP Library
[Student Paper]
Rajorshi Biswas, Shibdas Bandyopadhyay
Anirban Banerjee
Indian Institute of Information Technology Calcutta
rajorshi_biswas@rediffmail.com
shibdas@rediffmail.com
anir_iiit@yahoo.co.uk
Synopsis
 RSA is the most popular Public Key
Encryption Technique in use today.
 Large numbers are needed for encryption,
hence the need for handling those numbers
efficiently.
 GNU MP is a library designed from scratch
to handle numbers of arbitrary precision.
So, we have used it for implementing RSA.
Keywords
Cryotography, RSA, PKI, GMP
Introduction
 Data protection is becoming more and
more important as the data communication
increases exponentially.
 One way is to encrypt the data stream with
one key which is also used for decryption
(Private key approach). The entire
communication can be decrypted if the key
is known.
Introduction…
 Improvement over this system is Public Key
Infrastructure where one key ( Public Key) is used
to encrypt the data while another key (Private Key)
is used to decrypt it. So, private key is never
exposed.
 RSA is most widely used public key system. RSA
(named after its authors Rivest, Shamir and
Adleman) relies on the factorization problem that
indicates it is quite difficult in today’s aspect to find
two prime numbers whose product is a given large
number.
Introduction…
 As we increase the given number the
possibility for factoring the number
decreases.
 We have used GNU MP arbitrary
precision library to implement RSA
and done a performance analysis by
varying the number of characters
processed together.
RSA Algorithm
 Generate two large distinct primes p
and q randomly
 Calculate n = pq and x = (p-1)(q-1)
 Select a random integer e (1<e<x)
such that gcd(e,x) = 1
 Calculate the unique d such that ed =
1(mod x)
 Public key pair : (e,n), Private key
pair : (d,n)
Implementation
 We have implemented the RSA
cryptosystem in two forms : a console
mode implementation, as well as a user
friendly GUI implementation.
 The console application uses a 1024 bit
modulus RSA implementation, which is
adequate for non-critical applications. By a
simple modification of the source code,
higher bit-strengths may be easily
achieved, with a slight performance hit.
Large numbers & GMP Library
 Any practical implementation of the RSA
cryptosystem would involve working with large
integers (in our case, of 1024 bits or more in
size).
 The GMP library aims to provide the fastest
possible arithmetic for applications that need a
higher precision than the ones directly
supported under C/C++ by using highly
optimized assembly code. Further the GMP
library is a cross-platform library, implying that
our application should work across platforms
with minimal modifications.
Application Overview
 The program is meant for use on a per user
basis where each user's home directory stores
files containing the private and public keys for
the particular user. The application stores the
private and public keys for a user in the files
$HOME/.rsaprivate and $HOME/.rsapublic
respectively.
 The application will generate the keys if they
are not present using random number and
current time as seed.
RSA Key Generation
 The application maintains a constant named
'BITSTRENGTH' which is the size of the RSA
modulus (n) in bits. Two random arrays p and q
are generated.
 At the end of this process, we have strings
containing binary representations of the
numbers p and q, but they are not prime yet.
To achieve that, two gmp integers are first
initialized with the contents of these strings
and mpz_nextprime() is called which changes p
and to the next possible primes.
RSA Key Generation…
 Now that we have the two 512-bit primes p
and q, calculating the values of n (=pq) and x
(=(p-1)*(q-1)) is a simple matter of invoking
mpz_mul() with the proper arguments.
 We then determined ‘e’ such that gcd(e,x)=1
starting from e=65537. Now there exists a
procedure in the gmp library with the prototype
int mpz_invert(mpz_t ROP, mpz_t OP1, mpz_t
OP2) which computes the multiplicative inverse
of OP1 modulo OP2 and puts the result in
ROP. ). In this way, we obtain the value of ‘d’.
RSA Encryption
 The entire file to encrypt is processed as a
group of strings each containing the specified
number of characters (except possibly the last
such string). Each character in such a string is
converted to ASCII code, and the entire
resulting numeric string is our message m.
 Encrypting it is achieved by computing m ^ e
mod n. There is a gmp routine specifically for
such a computation having the prototype void
mpz_powm (mpz_t ROP, mpz_t BASE, mpz_t
EXP, mpz_t MOD) which sets ROP to (BASE
raised to EXP) modulo MOD.
RSA Decryption
 The operation of this routine is really quite
straightforward. From the file to decrypt (the
path to which is input from the user),the
function processes each encrypted integer. It
does so by computing the value of c ^ d mod n
by invoking gmp_powm(m,c,d,n) and stores
the decrypted part in m.
 Here m however contains the integer
representation of the message where each 3
integer sequence signifies the ASCII code of a
particular character. An inverse mapping to the
relevant character is carried out.
Time Analysis
Time Analysis
0
100
200
300
1 25 50 75 100
No. of characters encrypted together
Encryption Time Decryption Time
Overall Analysis
 We have noticed the speed improvements in
key generation and encryption/decryption while
using keys of lower strength.
 Encryption and decryption times decrease
considerably when number of characters
encrypted together increases.
 So, a balance is to be made considering both.
We found out 1024 bit RSA with 100 characters
encrypted together is very efficient in terms of
speed and security.
GUI Implementation
 The GUI application was developed using
KDE/Qt libraries on Red Hat Linux 8.0. We used
KDevelop 2.1 as our integrated development
environment.
 Our application consists of three C++ classes,
of which the class named RSA is the most
important. It provides slots (signal handlers)
for encrypting files, decrypting files, mailing the
encrypted file to another user, loading the
values of the RSA keys from the key-files,
saving encrypted/decrypted files and so on.
Screenshots
 This is the main
dialog of the
RSA GUI.
Screenshots…
 This is the window
showing the keys
generated by the
application.
Screenshots…
 This is the screen
showed for
encryption.
Screenshots…
 User can also mail
the encrypted file.
Screenshots…
 User can decrypt
the encrypted file
using his private
key.
Conclusion
 In this paper an efficient implementation of RSA
is shown by using various functions of the GMP
library. Feasibility analysis is done by comparing
the time taken for encryption and decryption. It
shows that when we increase the number of bits
of information to be encrypted together the total
time including encryption and decryption steadily
decreases. It must always be kept in mind that
the integer representation of the message to be
encrypted should lie within the range specified by
the modulus (that is, m lies in the range [0,n-
1]), which poses a limitation on the maximum
number of characters that can be encrypted at a
single time.
References
 [1] Paul Syversion and Illiano Cervesato, The logic of authentication protocols,
FOSAD’00, Bertinoro, Italy, 2000.
 [2] Dario Catalano, Rosario Gennaro and Shai Halevi, Computing inverse over a
shared secret modulus, IBM T. J. Watson Research center, NY, USA, 1999.
 [3] Don coppersmith, Markus Jakobsson, Almost optimal hash sequence traversal,
RSA Laboratories, NY, 2001.
 [4] Elichiro Fujisaki, Tatsuaki Okamoto, David Pointcheval and Jacques Stern, RSA-
OAEP is secure under the RSA assumption, Journal of Cryptology, 2002.
 [5] Daniel M. Gordon, A survey of fast exponentiation methods, Journal of
algorithms, 27, 1998, 126-146.
 [6] Adrian Perrig, Robet Szewczyk, Victor Wen, David Culler and J.D. Tygar,
SPINS: Security protocols for sensor networks, Mobile Computing and Networking,
Rome, Italy, 2001.
 [7] David Pointcheval and Jacques Stern, Security proofs for signature schemes,
EUROCRYPT ’96, Zaragoza, Spain, 1996.
 [8] Giuseppe Ateniese, Michael Steiner, and Gene Tsudik, New multiparty
authentication services and key agreement protocols, IEEE Journal of Selected Areas
in Communication, 18(4), 2000.
 [9] Cetin Kaya Koc, High speed RSA implementation, RSA Laboratories, CA, 1994.
 [10] Anand Krishnamurthy, Yiyan Tang, Cathy Xu and Yuke Wang, An efficient
implementation of multi-prime RSA on DSP processor, University of Texas,
Texas, USA,2002.
 [11] Handbook of Applied Cryptography, A. Menezes, P. Van Oorschot, S. Vanstone,
CRC Press, 1996 ( www.cacr.math.uwaterloo.ca/hac )

More Related Content

PDF
Modern Cryptography
PPTX
Encryption/Decryption Algorithm for Devanagri Script(Affine Cipher)
PDF
A Review on Various Most Common Symmetric Encryptions Algorithms
PDF
Implementation of-hybrid-cryptography-algorithm
PDF
RSA and RC4 Cryptosystem Performance Evaluation Using Image and Text
PDF
Paper id 312201534
PPTX
RSA & MD5 algorithm
PDF
D017433134
Modern Cryptography
Encryption/Decryption Algorithm for Devanagri Script(Affine Cipher)
A Review on Various Most Common Symmetric Encryptions Algorithms
Implementation of-hybrid-cryptography-algorithm
RSA and RC4 Cryptosystem Performance Evaluation Using Image and Text
Paper id 312201534
RSA & MD5 algorithm
D017433134

What's hot (16)

PDF
Ch34508510
PDF
A Comparative Study between RSA and MD5 algorithms
PDF
encrption.PDF
PPT
Digital Signature Recognition using RSA Algorithm
PDF
Advanced Encryption Standard (AES) Implementaion using Java
PDF
Survey of Hybrid Encryption Algorithm for Mobile Communication
PDF
Ijetcas14 355
PPT
Pgp smime
PPT
Is case study
PDF
An Enhanced Encryption Technique using BCD and Bit Complementation
PPT
Hash crypto
PDF
Hybrid AES DES
PPT
PPT
Network Security and Cryptography
PPTX
Hybrid encryption
PPT
Hash Function & Analysis
Ch34508510
A Comparative Study between RSA and MD5 algorithms
encrption.PDF
Digital Signature Recognition using RSA Algorithm
Advanced Encryption Standard (AES) Implementaion using Java
Survey of Hybrid Encryption Algorithm for Mobile Communication
Ijetcas14 355
Pgp smime
Is case study
An Enhanced Encryption Technique using BCD and Bit Complementation
Hash crypto
Hybrid AES DES
Network Security and Cryptography
Hybrid encryption
Hash Function & Analysis
Ad

Viewers also liked (18)

PPT
It strategy cfc company -hungtq v1.0
PDF
Loyax Consolidated Loyalty Platform General Presentation
PDF
PPS
Live A Life That Matters
PPTX
Vulnerability of PWID
DOC
Bm assaigm jan 2014
PDF
Loyax shopping centers
PPT
Paragraphwriitngchinhqui 120517213551-phpapp01
DOCX
Ipa sem 2 kls 7 (religia)
DOCX
Sistem ekskresi
DOCX
Latihan mid semester gasal kelas viii
PPTX
Wi max and military applications
PPT
Paragraphwriitngchinhqui 120517213551-phpapp01
PPTX
Issues of Wireless Sensor Networks
DOCX
Evaluasi cahaya dan alat optik kelas 8
DOCX
Materi fisika ix listrik
PPTX
Metro rail in india
It strategy cfc company -hungtq v1.0
Loyax Consolidated Loyalty Platform General Presentation
Live A Life That Matters
Vulnerability of PWID
Bm assaigm jan 2014
Loyax shopping centers
Paragraphwriitngchinhqui 120517213551-phpapp01
Ipa sem 2 kls 7 (religia)
Sistem ekskresi
Latihan mid semester gasal kelas viii
Wi max and military applications
Paragraphwriitngchinhqui 120517213551-phpapp01
Issues of Wireless Sensor Networks
Evaluasi cahaya dan alat optik kelas 8
Materi fisika ix listrik
Metro rail in india
Ad

Similar to Nwc rsa (20)

PDF
State of the art parallel approaches for
PDF
A New Design of Algorithm for Enhancing Security in Bluetooth Communication w...
PDF
Chaotic Rivest-Shamir-Adlerman Algorithm with Data Encryption Standard Schedu...
PDF
Improving Network Security by Modifying RSA Algorithm
PDF
Analysis of Cryptographic Algorithms
PDF
A Modified Technique For Performing Data Encryption & Data Decryption
PDF
H42054550
PDF
A Survey on Generation and Evolution of Various Cryptographic Techniques
PDF
Analysis of rsa algorithm using gpu
PDF
ANALYSIS OF RSA ALGORITHM USING GPU PROGRAMMING
PPTX
A NETWORK SECURITY APPROACH USING RSA.
DOCX
APPLICATION LAYER Networking refers to the practice of connecting computers, ...
PPT
PPTX
Data security using rsa
PDF
Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...
PDF
Dnssec tutorial-crypto-defs
PDF
ENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATION
PPTX
DESIGN AND IMPLEMENTATION OF DATA ENCRYPTION SOFTWARE
PDF
A cloud security approach for data at rest
PDF
A Cloud Security Approach for Data at Rest Using FPE
State of the art parallel approaches for
A New Design of Algorithm for Enhancing Security in Bluetooth Communication w...
Chaotic Rivest-Shamir-Adlerman Algorithm with Data Encryption Standard Schedu...
Improving Network Security by Modifying RSA Algorithm
Analysis of Cryptographic Algorithms
A Modified Technique For Performing Data Encryption & Data Decryption
H42054550
A Survey on Generation and Evolution of Various Cryptographic Techniques
Analysis of rsa algorithm using gpu
ANALYSIS OF RSA ALGORITHM USING GPU PROGRAMMING
A NETWORK SECURITY APPROACH USING RSA.
APPLICATION LAYER Networking refers to the practice of connecting computers, ...
Data security using rsa
Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...
Dnssec tutorial-crypto-defs
ENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATION
DESIGN AND IMPLEMENTATION OF DATA ENCRYPTION SOFTWARE
A cloud security approach for data at rest
A Cloud Security Approach for Data at Rest Using FPE

Recently uploaded (20)

PPTX
Slideham presentation for the students a
PPTX
Digital Education Presentation for students.
PPTX
Your Guide to a Winning Interview Aug 2025.
PPTX
Overview Planner of Soft Skills in a single ppt
PPT
NO000387 (1).pptsbsnsnsnsnsnsnsmsnnsnsnsjsnnsnsnsnnsnnansnwjwnshshshs
PPTX
Definition and Relation of Food Science( Lecture1).pptx
PPTX
Principles of Inheritance and variation class 12.pptx
PPTX
STS CHAP 4 human development as reflected
PDF
iTop VPN Crack Latest Version 2025 Free Download With Keygen
PPTX
FINAL PPT.pptx cfyufuyfuyuy8ioyoiuvy ituyc utdfm v
PPT
ALLIED MATHEMATICS -I UNIT III MATRICES.ppt
PDF
Parts of Speech Quiz Presentation in Orange Blue Illustrative Style.pdf.pdf
PPTX
GPAT Presentation PPT and details about imp topics.pptx
PPTX
PE3-WEEK-3sdsadsadasdadadwadwdsdddddd.pptx
PPTX
employee on boarding for jobs for freshers try it
PPT
Gsisgdkddkvdgjsjdvdbdbdbdghjkhgcvvkkfcxxfg
PPTX
AREAS OF SPECIALIZATION AND CAREER OPPORTUNITIES FOR COMMUNICATORS AND JOURNA...
PPTX
Prokaryotes v Eukaryotes PowerPoint.pptx
PPTX
ChandigarhUniversityinformationcareer.pptx
PPTX
A slide for students with the advantagea
Slideham presentation for the students a
Digital Education Presentation for students.
Your Guide to a Winning Interview Aug 2025.
Overview Planner of Soft Skills in a single ppt
NO000387 (1).pptsbsnsnsnsnsnsnsmsnnsnsnsjsnnsnsnsnnsnnansnwjwnshshshs
Definition and Relation of Food Science( Lecture1).pptx
Principles of Inheritance and variation class 12.pptx
STS CHAP 4 human development as reflected
iTop VPN Crack Latest Version 2025 Free Download With Keygen
FINAL PPT.pptx cfyufuyfuyuy8ioyoiuvy ituyc utdfm v
ALLIED MATHEMATICS -I UNIT III MATRICES.ppt
Parts of Speech Quiz Presentation in Orange Blue Illustrative Style.pdf.pdf
GPAT Presentation PPT and details about imp topics.pptx
PE3-WEEK-3sdsadsadasdadadwadwdsdddddd.pptx
employee on boarding for jobs for freshers try it
Gsisgdkddkvdgjsjdvdbdbdbdghjkhgcvvkkfcxxfg
AREAS OF SPECIALIZATION AND CAREER OPPORTUNITIES FOR COMMUNICATORS AND JOURNA...
Prokaryotes v Eukaryotes PowerPoint.pptx
ChandigarhUniversityinformationcareer.pptx
A slide for students with the advantagea

Nwc rsa

  • 1. A Fast Implementation of RSA using GNU MP Library [Student Paper] Rajorshi Biswas, Shibdas Bandyopadhyay Anirban Banerjee Indian Institute of Information Technology Calcutta rajorshi_biswas@rediffmail.com shibdas@rediffmail.com anir_iiit@yahoo.co.uk
  • 2. Synopsis  RSA is the most popular Public Key Encryption Technique in use today.  Large numbers are needed for encryption, hence the need for handling those numbers efficiently.  GNU MP is a library designed from scratch to handle numbers of arbitrary precision. So, we have used it for implementing RSA.
  • 4. Introduction  Data protection is becoming more and more important as the data communication increases exponentially.  One way is to encrypt the data stream with one key which is also used for decryption (Private key approach). The entire communication can be decrypted if the key is known.
  • 5. Introduction…  Improvement over this system is Public Key Infrastructure where one key ( Public Key) is used to encrypt the data while another key (Private Key) is used to decrypt it. So, private key is never exposed.  RSA is most widely used public key system. RSA (named after its authors Rivest, Shamir and Adleman) relies on the factorization problem that indicates it is quite difficult in today’s aspect to find two prime numbers whose product is a given large number.
  • 6. Introduction…  As we increase the given number the possibility for factoring the number decreases.  We have used GNU MP arbitrary precision library to implement RSA and done a performance analysis by varying the number of characters processed together.
  • 7. RSA Algorithm  Generate two large distinct primes p and q randomly  Calculate n = pq and x = (p-1)(q-1)  Select a random integer e (1<e<x) such that gcd(e,x) = 1  Calculate the unique d such that ed = 1(mod x)  Public key pair : (e,n), Private key pair : (d,n)
  • 8. Implementation  We have implemented the RSA cryptosystem in two forms : a console mode implementation, as well as a user friendly GUI implementation.  The console application uses a 1024 bit modulus RSA implementation, which is adequate for non-critical applications. By a simple modification of the source code, higher bit-strengths may be easily achieved, with a slight performance hit.
  • 9. Large numbers & GMP Library  Any practical implementation of the RSA cryptosystem would involve working with large integers (in our case, of 1024 bits or more in size).  The GMP library aims to provide the fastest possible arithmetic for applications that need a higher precision than the ones directly supported under C/C++ by using highly optimized assembly code. Further the GMP library is a cross-platform library, implying that our application should work across platforms with minimal modifications.
  • 10. Application Overview  The program is meant for use on a per user basis where each user's home directory stores files containing the private and public keys for the particular user. The application stores the private and public keys for a user in the files $HOME/.rsaprivate and $HOME/.rsapublic respectively.  The application will generate the keys if they are not present using random number and current time as seed.
  • 11. RSA Key Generation  The application maintains a constant named 'BITSTRENGTH' which is the size of the RSA modulus (n) in bits. Two random arrays p and q are generated.  At the end of this process, we have strings containing binary representations of the numbers p and q, but they are not prime yet. To achieve that, two gmp integers are first initialized with the contents of these strings and mpz_nextprime() is called which changes p and to the next possible primes.
  • 12. RSA Key Generation…  Now that we have the two 512-bit primes p and q, calculating the values of n (=pq) and x (=(p-1)*(q-1)) is a simple matter of invoking mpz_mul() with the proper arguments.  We then determined ‘e’ such that gcd(e,x)=1 starting from e=65537. Now there exists a procedure in the gmp library with the prototype int mpz_invert(mpz_t ROP, mpz_t OP1, mpz_t OP2) which computes the multiplicative inverse of OP1 modulo OP2 and puts the result in ROP. ). In this way, we obtain the value of ‘d’.
  • 13. RSA Encryption  The entire file to encrypt is processed as a group of strings each containing the specified number of characters (except possibly the last such string). Each character in such a string is converted to ASCII code, and the entire resulting numeric string is our message m.  Encrypting it is achieved by computing m ^ e mod n. There is a gmp routine specifically for such a computation having the prototype void mpz_powm (mpz_t ROP, mpz_t BASE, mpz_t EXP, mpz_t MOD) which sets ROP to (BASE raised to EXP) modulo MOD.
  • 14. RSA Decryption  The operation of this routine is really quite straightforward. From the file to decrypt (the path to which is input from the user),the function processes each encrypted integer. It does so by computing the value of c ^ d mod n by invoking gmp_powm(m,c,d,n) and stores the decrypted part in m.  Here m however contains the integer representation of the message where each 3 integer sequence signifies the ASCII code of a particular character. An inverse mapping to the relevant character is carried out.
  • 15. Time Analysis Time Analysis 0 100 200 300 1 25 50 75 100 No. of characters encrypted together Encryption Time Decryption Time
  • 16. Overall Analysis  We have noticed the speed improvements in key generation and encryption/decryption while using keys of lower strength.  Encryption and decryption times decrease considerably when number of characters encrypted together increases.  So, a balance is to be made considering both. We found out 1024 bit RSA with 100 characters encrypted together is very efficient in terms of speed and security.
  • 17. GUI Implementation  The GUI application was developed using KDE/Qt libraries on Red Hat Linux 8.0. We used KDevelop 2.1 as our integrated development environment.  Our application consists of three C++ classes, of which the class named RSA is the most important. It provides slots (signal handlers) for encrypting files, decrypting files, mailing the encrypted file to another user, loading the values of the RSA keys from the key-files, saving encrypted/decrypted files and so on.
  • 18. Screenshots  This is the main dialog of the RSA GUI.
  • 19. Screenshots…  This is the window showing the keys generated by the application.
  • 20. Screenshots…  This is the screen showed for encryption.
  • 21. Screenshots…  User can also mail the encrypted file.
  • 22. Screenshots…  User can decrypt the encrypted file using his private key.
  • 23. Conclusion  In this paper an efficient implementation of RSA is shown by using various functions of the GMP library. Feasibility analysis is done by comparing the time taken for encryption and decryption. It shows that when we increase the number of bits of information to be encrypted together the total time including encryption and decryption steadily decreases. It must always be kept in mind that the integer representation of the message to be encrypted should lie within the range specified by the modulus (that is, m lies in the range [0,n- 1]), which poses a limitation on the maximum number of characters that can be encrypted at a single time.
  • 24. References  [1] Paul Syversion and Illiano Cervesato, The logic of authentication protocols, FOSAD’00, Bertinoro, Italy, 2000.  [2] Dario Catalano, Rosario Gennaro and Shai Halevi, Computing inverse over a shared secret modulus, IBM T. J. Watson Research center, NY, USA, 1999.  [3] Don coppersmith, Markus Jakobsson, Almost optimal hash sequence traversal, RSA Laboratories, NY, 2001.  [4] Elichiro Fujisaki, Tatsuaki Okamoto, David Pointcheval and Jacques Stern, RSA- OAEP is secure under the RSA assumption, Journal of Cryptology, 2002.  [5] Daniel M. Gordon, A survey of fast exponentiation methods, Journal of algorithms, 27, 1998, 126-146.  [6] Adrian Perrig, Robet Szewczyk, Victor Wen, David Culler and J.D. Tygar, SPINS: Security protocols for sensor networks, Mobile Computing and Networking, Rome, Italy, 2001.  [7] David Pointcheval and Jacques Stern, Security proofs for signature schemes, EUROCRYPT ’96, Zaragoza, Spain, 1996.  [8] Giuseppe Ateniese, Michael Steiner, and Gene Tsudik, New multiparty authentication services and key agreement protocols, IEEE Journal of Selected Areas in Communication, 18(4), 2000.  [9] Cetin Kaya Koc, High speed RSA implementation, RSA Laboratories, CA, 1994.  [10] Anand Krishnamurthy, Yiyan Tang, Cathy Xu and Yuke Wang, An efficient implementation of multi-prime RSA on DSP processor, University of Texas, Texas, USA,2002.  [11] Handbook of Applied Cryptography, A. Menezes, P. Van Oorschot, S. Vanstone, CRC Press, 1996 ( www.cacr.math.uwaterloo.ca/hac )