in

RSA Algorithm, Hacker News

RSA Algorithm, Hacker News
      

Introduction

RSA (Rivest – Shamir – Adleman) algorithm is an asymmetric cryptographic algorithm that is widely used in the modern public-key cryptosystems . We have been hearing RSA algorithm all the time, but some of us actually did not know what it really is and how it works.

In this article, I will systematically discuss the theory behind the RSA algorithm. The theory guarantees that the cryptosystems built on the top of the RSA algorithm are relatively safe and hard to crack, which is fundamentally interesting.

Prerequisites

Euler’s Totient Function

In number theory, Euler’s totient function, also called Euler’s phi function, denoted as $ varphi (n) $, counts the positive integers up to a given integer n that are relatively prime to $ n $. In other words, it is the number of integers $ k $ in the range $ 1 leq k leq n $ for which the greatest common divisor $ gcd (n, k) $ is equal to 1.

Euler’s totient function is a multiplicative function, meaning that if two numbers $ m $ and $ n $ are relatively prime, then,

If $ k $ numbers, $ {m_1, m_2, cdots, m_k } $, are pairwise relatively prime, then

A concrete proof of this property could be found here , which requires to use the Chinese remainder theorem.

When $ n $ is prime number, according to the definition of prime, $ varphi (n)=n-1 $. If $ m $ and $ n $ are different prime numbers, because $ m $ and $ n $ are relatively prime, we have

Euler’s Theorem

If $ m $ and $ n $ are relatively prime, then,

where $ varphi (n) $ is Euler’s totient function. This theorem is very famous, and there a couple of different proofs to it. One of the proofs could be found here .

Multiplicative Inverse Theorem

Let $ n $ and $ x $ be positive integers. Then $ x $ has a multiplicative inverse modulo $ n $ if and only if $ gcd (n, x)=1 $. Moreover, if it exists, then the multiplicative inverse is unique.

Equivalently, that is to say, let $ n $ and $ x $ be positive integers,

$ y bmod n $ exists if and only if $ gcd (n, x)=1 $, and $ y bmod n $ is unique.

Note that as long as the multiplicative inverse $ y bmod n $ exists, all the integers that has the same $ y bmod n $ satisfy $ xy equiv 1 pmod n $. But there is only one such integer that is $ 0 leq y leq n-1 $. For instance, if there is a $ y ^ ast $ such that $ xy ^ ast equiv 1 pmod n $, then $ xy ^ ast – 1=kn $ for some integer $ k $. Any other $ y $ where $ y=y ^ ast tn $, for any integer $ t $, also satisfies $ xy – 1=k ^ prime n $ for some integer $ k ^ prime $ (This is easy to show). Therefore, we also have $ xy equiv 1 pmod n $. Because there could be infinite number of $ y $ which satisfies $ xy equiv 1 pmod n $, we consider the multiplicative inverse to be $ y bmod n $ which is unique if it exists.

Proof

To prove for the sufficient condition and the uniqueness. There are $ n $ possibilities of $ y pmod n $, $ 0, 1, 2, cdots, n-1 $. Then the value of $ xy $ could be $ 0x, 1x, 2x, cdots, (n-1) x $. We are going to show that $ 0x bmod n, 1x bmod n, 2x bmod n, cdots, (n-1) x bmod n $ are distinct if $ gcd (n, x)=1 $. Suppose there are two distinct integer $ a, b $, $ 0 leq a, b leq n-1 $, and $ ax equiv bx pmod n $. Then $ (a-b) x=kn $ for some integer $ k $. Because $ gcd (n, x)=1 $, $ a-b=hn $ for some integer $ h $. However, since $ a-b $ is in a range of $ [-n 1, n-1] $ and $ a-b neq 0 $ because $ a $ and $ b $ are distinct, there is no integer $ h $ which could satisfy $ a-b=hn $. Thus, $ 0x bmod n, 1x bmod n, 2x bmod n, cdots, (n-1) x bmod n $ have to be distinct if $ gcd (n, x)=1 $. Since there are $ n $ possible values ​​for $ 0x bmod n, 1x bmod n, 2x bmod n, cdots, (n-1) x bmod n $ which are distinct, there is only one of them which must 1. Therefore, $ y bmod n $ exists if $ gcd (n, x)=1 $ and $ y bmod n $ is unique.

To prove for the necessary condition. Given non-negative integer $ y $ such that $ xy equiv 1 pmod n $, we have $ xy – 1=kn $ for some integer $ k $. Suppose $ gcd (n, x)> 1 $, we divide $ gcd (n, x) $ at both sides of the equation.

Because $ frac {xy} { gcd (n, x)} $ and $ frac {kn} { gcd (n, x)} $ are integers, but $ frac {1 } { gcd (n, x)} $ is not an integer because $ gcd (n, x)> 1 $, there is no way for the equivalence. This raises a contradiction. Therefore, $ gcd (n, x)=1 $ if $ y bmod n $ exists.

This concludes the proof. $ square $

Lemma 1

If $ m $ and $ n $ are relatively prime, then,

where $ varphi (n) $ is Euler’s totient function, and $ k $ is any integer.

Proof

Using the compatibility with scaling in

modular arithmetic properties , we multiply $ m $ at the both sides of $ m ^ { varphi (n)} equiv 1 pmod n $ from Euler’s theorem, we have

We further multiply $ m ^ { varphi (n)} $ at the both sides of $ m ^ { varphi (n) 1} equiv m pmod n $, we have

By induction, we could show that

for any non-negative integer $ k $.

Similarly, we multiply $ m ^ {- varphi (n)} $ at the both sides of $ m ^ { varphi (n) 1} equiv m pmod n $, we have

By induction, we could show that

for any negative integer $ -k $.

This concludes the proof that the congruence is valid for any integer $ k $. $ square $

RSA Algorithm

Basic Features of Public-Key Cryptosystems

The RSA algorithm is used as a typical public-key cryptosystem. Therefore, it has to match the four basic features for public-key cryptosystems. I am copying the descriptions for the features for the completeness of this article.

The encryption and decryption functions using public key and private key in the RSA algorithm are denoted by $ E $ and $ D $, respectively. $ M $ is used to represent the message to be encrypted and sent. The four basic features of a public-key cryptosystem as well as the RSA algorithm are:

  • (Read More )

    What do you think?

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    GIPHY App Key not set. Please check settings

    Data USA, Hacker News

    Data USA, Hacker News

    Signal is finally bringing its secure messaging to the masses, Ars Technica

    Signal is finally bringing its secure messaging to the masses, Ars Technica