| Author | abductor |
| Target | Project Cryptology. Essay #2: RSA Algorithm |
| Public Release | 27/02/2001 |
Disclaimer:
Please note, the information herein is copyright to Hellforge. No portion of
this text may be duplicated. Furthermore, damage or problems arising after
reading this text is left to the users disposal. Neither Hellforge, nor its
members can be held responsible for any direct or indirect result of following
this text. The full liability of following this text is on the reader (YOU). The
information is provided for educational purposes, misuse of this information is
strictly prohibited. If you do not agree with this agreement, then please hit
the "back" button on your browser, and go to hell. -
Mercution.
RSA Algorithm
Contents:
1) Small
Introduction
2) Algorithm
3) A bit of Number Theory {it would be easier to understand if you had a course before}
4) Example
5) Homework
|
|
RSA is the second public-key algorithm from my list I wanted
to explain to you. It is an encryption algorithm that uses very large prime numbers to generate the public key and the private key. This crypto system is usually used with DES. While DES encrypts whole message using one key, people use RSA to encrypt the DES secret key. This crypto system is widely used in many applications (El-Gamal is popular too, but this will be our separate discussion). Although there are very good factoring algorithms (See Below
Factoring Methods
) it is infeasible to find factors of very big numbers, even connecting large number of PCs in a network. To describe RSA algorithm, following quantities are required:
The idea is as follows:
ALGORITHM
Now, I wanted to stop on the 3rd quantity we have defined. It is important concept in this system. This equation determines how many of the number are relatively prime to n.
The RSA algorithm is based on an extension of Euler's theorem, which says that
aÔ(n) = 1 (mod n)
whereFor example, the composite number 10 = 2 * 5. It has two prime factors; 2 and 5. So there must be Ô(10) = 10 * (1-1/2)*(1-1/5) = 4 integers that are relatively prime to 10 {i.e., which have neither 2 or 5 as a factor}. They are: 1, 3, 7, 9 To obtain mathematical relationship between Private Key - e { from now one PK } and secret key - d{ SK }, Euler's theorem must be extended, but I will skip this part, because to understand this you must be familiar with Number Theory, at least you could take one course.
To make the protection more secure users must choose "good" prime numbers. When I say "good" it means that they must be very large, and their difference in length must not be very big. Their product n will be made public, keeping p and q secret.
The user selects these prime numbers, p and q, where they should not be equal. If you make them equal it will be easy to factorise it by taking square root of publicly known n.
Their difference must be unpredictable, since otherwise p and q could be determined from n using this way. ( p + q ) is the square root of ( p - q )2 + 4n, and q will be half the difference of ( p + q ) - ( p - q )
That would be encryption and decryption.
The message that one want to remain unknown for strangers is encrypted using e. Let's assume that our message is X, so convert is to the ciphertext we must perform this: Y = Xe ( mod n )
As you can see, if we take both sides, of this equation, to the power of d we will get: Yd = Xe*d ( mod n) ; and from about as it was said previously e*d ( mod n ) = 1, so we end up with original message that was encrypted.
X = Yd ( mod n )
So, if people want to encrypt something with RSA, they take X to the power e, and to decrypt they have to take cyphertext to the power of d. It, actually, does not matter in what order people use this keys. It can be done in any order and there will be no difference.
Let's take p = 47 and q = 61. Thus 47 * 61 = 2867 and Ô(n) = (p - 1)*(q - 1) = 2760
The method I will use to determine the GCD of two numbers, and therefore whether they are relatively prime or not is called Euclidian algorithm. This algorithm is based on the theorem that states that is a = b*m + c, then GCD(a,b) is equal to GCD(b,c). To illustrate this algorithm let's us find the GCD(38,26)
The bolded one is the GCD of these two numbers, and it is 1; therefore, they are relatively prime.
After we proved that they are relatively prime, we can assign: SK = 167
You can see the source code
here . It was coded using MIRACL, to find GCD of two big numbers.
To find multiplicative inverse of a number, you can use a program i prepared. It is not very fast dealing with big numbers, to generate inverse of our SK it took my program almost a second to compute this. It is using brute force method to determine what is the inverse. The source can be found
here . I will keep this one until I code another program that {as I was told} should calculate it faster.
If you have a small number, a variation of Euclid's Algorithm is used to calculate the multiplicative inverse of this number. In my previous essay I showed how to do this. The idea is to rewrite all your equations, starting from the one before last and going to the first, in the form:
(factor1 * SK) + (factor2 * Ô(n)) = 1
where factor1 will be our PK. This equation is also equal to SK * PK = 1 (mod Ô(n)), because when you take both sides (mod Ô(n)) you will see that (factor2 * Ô(n)) mod Ô(n) will be equal to 0 and you got the 2nd equation.
To get PK you rewrite one before pre-last step like this:
Now, we have transformed it into the form: (factor1 * SK) + (factor2 * Ô(n)) = 1 where it was said that factor1 is equal to our PK, so PK = 1223 , which is multiplicative inverse of SK modulo n.
Let's assume that we want to encrypt Number:= 783
I will use e to do that. Recalling that Y = Xe (mod n) we have Y = Numbere (mod n). If we substitute all known values we would have: Y = 783167 (mod 2867). And it will be equal to Y = 2865. I used this program to do this.
To decrypt it, using d we got: X = 28651223 = 783 which is our original message.
Since, PK is 1223d = 4C7h = 0100 1100 0111 that can be written as 0*211 + 1*210 + 0*29 + 0*28 + 1*27 + 1*26 + 0*25 + 0*24 + 0*23 + 1*22 + 1*21 + 1*20 = 1223
1223 = 1024 + 128 + 64 + 4 + 2 + 1 => 7831223 = 7831024 * 783128 * 78364 * 7834 * 7834 * 7832 * 7831 You might find this easier to compute
|
|
NOTE: People, who are in the list will receive homework next week. The assignment will consist of a simple and moderate problems. The crackme will be coded to test your abilities breaking this crypto-system. I will try to find a program that uses it.
Next essay will be released next weekend. The DES algorithm will be explained.
By the end of this month DES essay will be released too. Next month 2 more essays coming up.
Take care.
|
|
Eclipse, DAMN, CORE
|
|