Jorrit's Technobabble
HomeAboutContact

Mathematics Behind RSA Cryptography

By Jorrit Klein Bramel
Published in Technology
April 16, 2023
6 min read
Mathematics Behind RSA Cryptography

Table Of Contents

01
Introduction
02
Basic Mathematical Principles
03
RSA Key Generation
04
Encryption and Decryption
05
Security of RSA Cryptography
06
Conclusion
07
Additional Resources

Introduction

In the first part of this series, we delved into RSA cryptography, its history, applications, and relevance in today’s world1. As we learned, RSA cryptography is a powerful tool widely used to secure digital communication and information. However, its strength and effectiveness do not come from thin air. Profound mathematical principles and concepts underpin RSA cryptography.

In this second part of the series, our goal is to unravel the mathematics behind RSA cryptography. We aim to explain the fundamental mathematical principles used in RSA, including prime numbers, modular arithmetic, and Euler’s totient function. Further, we will illuminate how these principles are applied in generating RSA keys and the encryption and decryption processes.

We will also shed light on how these mathematical principles contribute to the security of RSA and why despite potential weaknesses, RSA remains a vital tool in securing digital information. We will use formulas and provide examples to illustrate these concepts to assist in understanding.

Basic Mathematical Principles

Explanation of Prime Numbers

A prime number is a natural number greater than 1 that has no positive integer divisors other than 1 and itself. For example, the first six prime numbers are 2,3,5,7,11,2, 3, 5, 7, 11, and 13132. The fundamental role of prime numbers in RSA cryptography cannot be overstated. It is the difficulty in factoring large prime numbers that provides the security backbone of RSA3.

Concept of Modular Arithmetic

Modular arithmetic, also known as “clock arithmetic”, is a system of arithmetic for integers, where numbers “wrap around” after they reach a certain value, referred to as the modulus4. If we denote the modulus by nn, the result of a modular operation can be written as:

abmodna \equiv b \mod n

This means that aa and bb leave the same remainder when divided by nn. In the context of RSA, modular arithmetic allows computations to be managed with large numbers by transforming them into equivalent, smaller numbers3.

Understanding of Euler’s Totient Function

Euler’s totient function, often denoted by ϕ(n)\phi(n), is an important mathematical function used in RSA. It is used to determine the number of integers that are relatively prime to a given number, nn (i.e., numbers that do not share any factor with nn except 1)5. For a prime number pp, ϕ(p)\phi(p) is simply p1p-1.

In the context of RSA, where the modulus nn is the product of two prime numbers pp and qq, Euler’s totient function can be calculated using the formula:

ϕ(n)=(p1)(q1)\phi(n) = (p-1)(q-1)

This totient function plays a pivotal role in the generation of the RSA public and private keys3.

RSA Key Generation

The process of generating an RSA key pair involves the following steps1:

Selection of Prime Numbers

First, we need to select two distinct prime numbers, pp and qq. These primes should be chosen randomly and be of similar bit-length to ensure the security of the key6. The larger these prime numbers are, the more secure the RSA key will be, but it will also make the computations slower.

Computation of Modulus

The modulus nn is calculated by multiplying the two prime numbers. The modulus is a part of both the public and private keys, and it is used in both the encryption and decryption processes.

n=pqn = p \cdot q

Calculation of Euler’s Totient Function

Next, Euler’s totient function, ϕ(n)\phi(n), is calculated. As mentioned earlier, for a modulus nn that is a product of two primes pp and qq, Euler’s totient function can be computed using the formula:

ϕ(n)=(p1)(q1)\phi(n) = (p-1) \cdot (q-1)

Determination of Public Key Exponent

The public key exponent, typically denoted by ee, is a number that should be relatively prime to ϕ(n)\phi(n) and 1<e<ϕ(n)1 < e < \phi(n). In practice, common choices for ee are 33, 1717, or 6553765537 (which is 216+12^{16}+1)7.

Calculation of Private Key Exponent

The private key exponent, typically denoted by dd, is calculated such that it is the multiplicative inverse of ee modulo ϕ(n)\phi(n). In other words, we need to find a dd that satisfies the following condition:

ed1modϕ(n)e \cdot d \equiv 1 \mod \phi(n)

This means that when ede \cdot d is divided by ϕ(n)\phi(n), the remainder is 11.

The Extended Euclidean Algorithm is often used to calculate dd, and the result is kept private8.

Once we have computed n,e,n, e, and dd, the public key consists of (n,e)(n, e), and the private key consists of (n,d)(n, d).

Encryption and Decryption

Encryption

The encryption process in RSA cryptography involves taking a plaintext message, mm, and raising it to the power of the public key exponent, ee, then taking the modulus by nn. This results in the ciphertext, cc, which can be represented by the following formula1:

c=memodnc = m^e \mod n

As a result of the modulus operation, the ciphertext cc will be a number in the range 00 to n1n - 1. In practical scenarios, the plaintext message is often transformed into a numerical form before applying the encryption process6.

Decryption

Decryption is performed by taking the ciphertext, cc, and raising it to the power of the private key exponent, dd, then taking the modulus by nn. This returns us to the original plaintext message, mm, and can be represented by the following formula1:

m=cdmodnm = c^d \mod n

The operations for encryption and decryption in RSA are symmetric, except for the use of different exponents. This symmetry comes from the relationship between the public and private keys, specifically, the way that dd is calculated to be the multiplicative inverse of ee modulo ϕ(n)\phi(n)7.

This encryption and decryption process is what makes RSA a Public Key Cryptosystem - anyone can encrypt a message using the public key, but only the holder of the private key can decrypt it. This makes RSA valuable for ensuring the confidentiality and integrity of data8.

Security of RSA Cryptography

The security of RSA cryptography hinges on the assumption that factoring large composite numbers is computationally difficult. This is often referred to as the RSA assumption1.

The RSA Assumption

The RSA assumption postulates that, given a large composite number nn (the product of two large primes pp and qq), it is computationally infeasible to find the prime factors pp and qq of nn1. If someone could efficiently factor nn, they could compute ϕ(n)\phi(n) and subsequently calculate the private key dd from the public key ee8.

Computational Difficulty

The computational complexity of factoring large composite numbers is what provides RSA’s security. At the time of writing, the most efficient classical factoring algorithm is the General Number Field Sieve (GNFS), which operates in sub-exponential time9. However, even with GNFS, factoring a large composite number formed from two large prime numbers (200+ digits each) is beyond the reach of current computational resources6.

Quantum Computing and RSA’s Security

While RSA cryptography is considered secure against classical computers, the advent of quantum computers could potentially pose a threat. If run on a sufficiently powerful quantum computer, Shor’s algorithm could theoretically factor large composite numbers in polynomial time, thereby breaking RSA10.

Conclusion

The RSA algorithm has stood the test of time as a fundamental tool in public-key cryptography. By harnessing the mathematical principles of number theory, including modular arithmetic, primality, and the difficulty of factoring large composite numbers, RSA provides a secure and reliable method for encryption and decryption1.

Throughout this post, we’ve delved into the mathematical underpinnings of RSA, understanding how keys are generated and how the encryption and decryption processes work. We’ve also discussed the security of RSA, underlining the importance of the RSA assumption and the computational difficulty of factoring large composite numbers8.

However, we must be mindful of the evolving landscape of computation. With the rise of quantum computing, the RSA assumption could potentially be challenged by quantum algorithms such as Shor’s 10. While this is still a theoretical concern as of 2021, it underscores the necessity of ongoing research and development in the field of cryptography to keep pace with such technological advancements.

In conclusion, while RSA cryptography might face challenges in the future, it remains a cornerstone of secure data transmission, demonstrating the profound impact of mathematical concepts when applied to real-world issues of security and privacy6.

Additional Resources

Each of the following resources provides unique and comprehensive insights into the mathematical and practical aspects of RSA cryptography, offering a more in-depth understanding of this essential cryptographic algorithm.

  • [1] J. Katz and Y. Lindell, ‘Introduction to Modern Cryptography’, 2007.
    • This book provides an excellent overview of the principles of modern cryptography, including a comprehensive section on RSA and public-key cryptography.
  • [2] D. Boneh and V. Shoup, ‘A Graduate Course in Applied Cryptography’, 2017.
    • This is a more advanced book, which covers RSA and other cryptographic protocols in great detail.
  • [3] P. W. Shor, ‘Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer’, 1997.
    • This is a seminal paper that introduced Shor’s algorithm, which has implications for the security of RSA in the face of quantum computing.
  • [4] R. E. Crandall and C. Pomerance, ‘Prime Numbers: A Computational Perspective’, 2005.
    • This book offers a deep dive into the computational and number-theoretical aspects related to prime numbers, which are a key aspect of RSA.
  • [5] C. Pomerance, ‘A Tale of Two Sieves’, in Biscuits of Number Theory, 2009.
    • This is a great paper to understand the importance of factoring large numbers in RSA and how the difficulty of this task contributes to RSA’s security.

  1. R. L. Rivest, A. Shamir, and L. Adleman, ‘A Method for Obtaining Digital Signatures and Public-Key Cryptosystems’, 1977.
  2. K. H. Rosen, Elementary Number Theory and Its Applications. 1984.
  3. D. Boneh and V. Shoup, ‘A Graduate Course in Applied Cryptography’, 2017.
  4. T. H. Cormen, Ed., Introduction to Algorithms, 3rd ed. Cambridge, Mass: MIT Press, 2009.
  5. W. Stein, Elementary Number Theory: Primes, Congruences, and Secrets: A Computational Approach. Springer New York, 2009. doi: 10.1007/b13279.
  6. B. Schneier, Applied Cryptography: Protocols, Algorithms, and Source Code in C, 20th anniversary edition. Indianapolis, IN: Wiley, 2015.
  7. A. J. Menezes, P. C. Van Oorschot, and S. A. Vanstone, Handbook of Applied Cryptography. Boca Raton: CRC Press, 1997.
  8. D. R. Stinson and M. B. Paterson, Cryptography: Theory and Practice, Fourth edition. Boca Raton: CRC Press, Taylor & Francis Group, 2019.
  9. C. Pomerance, ‘A Tale of Two Sieves’, in Biscuits of Number Theory, A. Benjamin and E. Brown, Eds., Providence, Rhode Island: American Mathematical Society, 2009, pp. 85–104. doi: 10.1090/dol/034/15.
  10. P. W. Shor, ‘Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer’, 1997.

Tags

#rsa#cryptography#encryption

Share

Previous Article
Introduction to RSA Cryptography
Jorrit Klein Bramel

Jorrit Klein Bramel

Software and Data Engineer

I caught on fire once while coding. Software, technology and data science enthusiast who unites his passions to build elegant and effective solutions for modern-day business challenges.

Expertise

Programming
Linux
Big Data
Dyslexia

Social Media

githublinkedin

Related Posts

Introduction to RSA Cryptography
Introduction to RSA Cryptography
March 19, 2023
5 min
© 2024, All Rights Reserved.
Crafted with by Jorrit

Quick Links

About UsContact Us

Social Media