Asymmetric encryption algorithms -RSA

  Into the encryption algorithm and a symmetric encryption algorithm asymmetric encryption algorithm, wherein the asymmetric encryption algorithm as the cornerstone of computer communications security, plays an important role in ensuring data security. With respect to a symmetric encryption algorithm comprehensibility, there are some difficulties asymmetric encryption algorithm. Through the analysis of the following RSA algorithm, allowing us to better understand the principle of asymmetric encryption algorithms.

A symmetric encryption algorithms and asymmetric encryption algorithm

1, symmetric encryption algorithm

  Symmetric encryption algorithms: encryption and decryption algorithms use the same rules (key).

  (1), A to select one of the rule information is encrypted;

  (2), B use the same rule (rule inverse) decrypts the message;

2, asymmetric encryption algorithm

  Asymmetric encryption algorithms: encryption and decryption may use different rules, so long as the presence of some kind between the two rules can be correspondence relationship.

  (. 1), two B according to an algorithm to generate a key (public and private), wherein the private key is kept secret, the public key is disclosed to be used for communication with other human B;

  (2), A obtains the public key from B, the and use it to encrypt;

  (3), B A is obtained encrypted information, decrypt with the private key, completion of the communication;

Second, the mathematical basis of the RSA algorithm

1, the relationship coprime

  Also known as prime relatively prime, or two or more if the greatest common divisor of two integers is 1, they are called coprime. For example, 7 and 10, their greatest common divisor is 1, so they are relatively prime. 8 and 10 of the largest common divisor is 2, so they are not relatively prime. Not only to the formation of two prime numbers relatively prime.
  The prime relation, the following conclusions (Euler function will be used later):

  • Two different prime numbers must prime. For example, 2 and 7, 13 and 19.
  • A prime number, the other is not a multiple of it, these two prime numbers. For example, 3 and 10, 5 and 26.
  • And 1 are any natural numbers relatively prime. The 1 and 9908.
  • Any power of 2 and a are odd prime. The 32 and 315 and 75,256.
  • Two adjacent relatively prime natural numbers. The 15 and 16.
  • Two adjacent odd prime. The 49 and 51.

2, Euler function

  Euler function refers to the number of positive integer number n a positive integer, less than or equal to n seek with prime to n, denoted by φ (n). For example 1 to 10, and 10 is formed with a prime relationship 1,3,7,9, so φ (10) = 4.
  Euler function as general formula (n = 1 except outside, [Phi] (. 1) =. 1): \
[[Phi] (n-) = n-(l- \ FRAC. 1 {{}} P_1) (l- \ FRAC. 1 {{} p_2}) ...... (1- \ frac {1} {p_r}) \\ n = {p_1} ^ {k_1} * {p_2} ^ {k_2} ...... {p_r} ^ {k_r}, wherein p_1, p_2 ...... p_r prime numbers \]
  such φ (20) = 8 is calculated as follows:
\ [[Phi] (20 is) = [Phi] (2 ^ 2 \ times5) = 20 is (l- \ frac {1} {2}
) (1- \ frac {1} {5}) = 8 \]   Euler function is proved as follows:

  • When n = 1, φ (1) = 1

   Because any number of 1 constitutes a prime relation, φ (1) = 1.

  • When n is a prime number, φ (n) = n-1

   Since the number is less than its quality and every number, constitute prime relation, φ (n) = n-1. As φ (5) = 5-1 = 4.

  • When n is a power of a prime number, the following formula, wherein p is a prime number, k is an integer greater than 1
    \ [φ (p ^ k)
    = p ^ k (1- \ frac {1} {p}) \] because of a power of a prime number and is formed in addition to a multiple of a prime number of prime relation, and multiples of prime numbers 1 * p, 2 * p, 3 * p, ......, p ^ (k-1) * p, i.e., there p ^ (k-1) th, then
    \ [φ (p ^ k) = p ^ kp ^ {k-1} = p ^ k (1- \ frac {1} {p}), as φ (5 ^ 3) = 5 ^ 3 ( 1- \ frac {1} {5}) = 100. \]

  • When n can be decomposed into the product of two prime integers,
    \ [[Phi] (P_1 {} \ {P_2 Times}) = [Phi] (P_1) [Phi] (P_2) \]
    The Chinese Remainder Theorem Theorem can be used to prove the specific process may refer to other documents. As φ (15) = φ (3 * 5) = φ (3) φ (5) = 2 * 4 = 8.
    Based on the above reasoning, because a positive integer of 1 to any greater than, can be written as a series of product of primes can be deduced that when n is an integer greater than 1:
    \ [n = {P_1} ^ {k_1} {P_2} ^ { k_2} ... {p_r} ^ { k_r} \]

    \[ φ(n)=φ({p_1}^{k_1}{p_2}^{k_2}...{p_r}^{k_r}) \]

    \ [Phi (n) = z ({p_1} ^ {k_1}) f ({p_2} ^ {k_2}) ... z ({p_r} ^ {k_r}) \]

    \[ φ(n)={p_1}^{k_1}(1-\frac{1}{p_1}){p_2}^{k_2}(1-\frac{1}{p_2})...{p_r}^{k_r}(1-\frac{1}{p_r}) \]

    \[ φ(n)={p_1}^{k_1}{p_2}^{k_2}...{p_r}^{k_r}(1-\frac{1}{p_1})(1-\frac{1}{p_2})(1-\frac{1}{p_r}) \]

    \[ φ(n)=n(1-\frac{1}{p_1})(1-\frac{1}{p_2})...(1-\frac{1}{p_r}) \]

    The above general formula is the Euler function.

3, Euler's theorem

  Euler's theorem, also known as Fermat - Euler's theorem, means: if two positive integers a and n are relatively prime, then n Euler function φ (n) can make the following equation holds.
\ [A ^ {φ (n
)} = 1 (mod \ n) \]   i.e. in a [Phi] (n) is n th addition remainder is 1, or a is [Phi] (n) th power minus 1, to It is divisible by n. 5 and 7 as prime
\ [7 ^ {φ (5 )} - 1 = 7 ^ 4-1 = 2401-1 = 2400, may be divisible by 5 \]

4, modular multiplicative inverse

  If the two positive integers a and n are relatively prime, then we can find the integer B, such that n is divisible by 1-ab, ab or remainder of the division by n is the number 1. In this case, b is called a modular multiplicative inverse. Be demonstrated as follows:
\ [a ^ {[Phi] (n-)} = a \ Times a ^ {φ (n-1 )} =. 1 (MOD \ n-), where a ^ {φ (n-1 )} is a mold anti element \]

Three, RSA algorithm process

1, generate a key pair (public and private)

  • Get two random prime numbers a and b (a and b, the more secure the greater), and calculates their product n

    For example a = 5, b = 11. Calculate their product n = 5 * 11 = 55, converted into binary to 110111, the six is ​​the encryption algorithm. This example is for convenience of calculation, it takes a relatively small number, the actual algorithm is a 1024 or 2048, the longer the number of bits, the harder it is to break the algorithm.

  • N calculated Euler function m = φ (n)

    According to the formula m = φ (55) = φ (5) φ (11) = (5-1) (11-1) = 40

  • Select a random integer e, with the proviso that 1 <e <m, and m coprime with e

    We randomly selected e = 17

  • E calculated for molding φ (n) (i.e., m) inverse element d

    That is to find an integer d, such that (e * d)% m = 1. Equivalent to e * d - 1 = y * m (y is an integer) to find d, essence solving the following linear equations. e * x - m * y = 1. Wherein e = 17, m = 40,17x - 40y = 1 This equation can be "extended Euclidean algorithm" to solve. DETAILED slightly solving process, a solution of the calculated set of integers (x, y) = (33,14), i.e. d = 33. This key pair generation is completed. Different generate different e d, it is possible to generate a plurality of key pair.

  In the present embodiment public key (n, e) = (55, 17), private key (n, d) = (55, 33), only the (n, e) = (55, 17) are open, the remaining figures are not public. If only you can imagine and n e, how to derive d, can only rely on brute force, the longer the median, the longer the brute force of time.

2, generates a ciphertext encrypted

  Z plain text using the public key (n, e) is encrypted, wherein the plaintext must be converted to digital, and must be less than n. Encryption formula is as follows:
\ [e ^ z = c (MOD \ n-) \]
  where z is the plaintext, n, and the public key e, c is the encrypted ciphertext, it can be converted to c:
\ [c = z ^ e \% n \]
  If the plain text 15, the public key (n, e) = (55 , 17), the encrypted ciphertext c is:
\ [c = 15. 17 ^ {} \ = 55. 5% \ ]

3, generates a decrypted plaintext

  Ciphertext c using the public key (n-, d) decrypt the decrypted public follows:
\ [Z = c ^ d (MOD \ n-) \]
  where c is the ciphertext, n and d is the private key, z is decrypt after plaintext, it can be converted to z:
\ [D z = c ^ \ n-% \]
  according to the above-described conditions, the ciphertext c is 5, the private key (n, d) = (55 , 33), after decryption z is expressly:
\ [^ {z = 33 is. 5} \ 55 = 15% \]

Four, RSA algorithm to prove the effectiveness of

1. validity

  According to the above-described exemplary algorithm RSA, the RSA algorithm to verify the effectiveness, i.e., the encrypted authentication according to the formula:
\ [Z ^ E = C (MOD \ n-) \]
  can be deduced, the decryption formula is valid:
\ [^ D = C z (mod \ n) \]

2, proof

  The encryption rules can be deduced:
\ [C ^ E = Z - KN \]
  The progeny of the above formula into formula decrypted, i.e., verify it follows:
\ [(Z ^ E-KN) = Z ^ D (MOD \ n) \]

\ [Z ^ {ed} = z (mod \ n) \]

  • When z is prime to n

    The Euler's theorem
    \ [z ^ {φ (n
    )} = 1 (mod \ n) \] can Release
    \ [z \ times {(z ^ {φ (n)})} ^ p = z (mod \ n) \]

    \[ z^{1+pφ(n)}=z(mod\ n) \]

    Because of
    \ [ed = 1 (mod \ φ (n)) \]

    \[ ed = 1+pφ(n) \]

    Can be deduced
    \ [z ^ {ed} = z (mod \ n) \]

  • When z is not coprime with n

    Since n = a * b, where a and b are prime numbers. Since z and n is not prime, then n and z must have a common divisor, since n is the product of two prime numbers a and b, then z must be a multiple of a or b, or referred to as ka kb.

    Assuming z = ka (a = kb empathy). Since b is a prime number, if k is b multiples, i.e., k = hb, then z = hab, where h is a positive integer, the deduced z is greater than n, but according to the conditions of the encrypted plaintext must be less than n, it can be deduced k is not a multiple of b, because b is a prime number, it can be inferred k and b are coprime, similarly derived ka and b are coprime, i.e., z and b are relatively prime.

    Euler's theorem, the following equation was established found:
    \ [^ {[Phi] Z (B)} ≡1 (MOD \ B) \]
    can be derived:
    \ [^ {[Phi] Z (B)} = (KA) ^ { φ (b)} = (ka
    ) ^ {b-1} ≡1 (mod \ b) \] for the result of a modulo number 1, then its n-th power, also a remainder. According to this theorem, can be deduced:
    \ [{[(KA). 1-B ^ {}]} {H ^ (. 1-A)} ≡1 (MOD \ B) \]

    \ [{[(A) '{b-1}]} * {h (a-1)} \ times ka≡ka (mod \ b) \]

    \ [{(A)} ^ {ed} ≡ka (mod \ B) \]

    \ [{(At)} ^ {ed} = + in ob \]

    Since the two equations hold, and a and b are relatively prime, may be derived as a certain multiple of o, i.e. 0 = ja, can be deduced:
    \ [{(KA)} ^ {} = ED = KA KA + OB + jab \]
    as z = ka, n = ab, you can exit:
    \ [^ {Z} ≡z ED (Mon \ n-) \]

Fifth, the security of the RSA algorithm

  Security RSA algorithm is based on the current conditions in space and time, it can not be effectively solved.

  According to the above derivation, RSA algorithms use a, b, n, m, e, d six numbers. Wherein the public key (n, e) is disclosed, the remaining four digits are confidential. Where d is the core of the key algorithm.

  • e * d ≡ 1 (mod m). Where e is the public, it needs to know m, can be calculated by d.
  • According to the formula φ (n) = (a-1) (b-1) = m, to calculate the m, to know a and b.
  • n = ab. Only n-factorization, to work out a and b.

  At present, for large numbers of decomposition factor, in addition to brute force, there is no better way. Existing computing resources and capabilities, currently the longest RSA keys can be cracked is 768, so long as RSA key is 1024 and above, you can ensure the security of the algorithm.

VI Summary

1, RSA algorithm flow

2, RSA algorithm security

  At present, for large numbers of decomposition factor, in addition to brute force, there is no better way. Existing computing resources and capabilities, currently the longest RSA keys can be cracked is 768, so long as RSA key is 1024 and above, you can ensure the security of the algorithm.

3, RSA algorithm

  在RSA算法中,公钥(n,e) 只能加密小于n的整数。对于大于n的整数,可以采用两种方法。一是把长信息分割成若干段短消息,每段分别加密;另一种是先选择一种对称性加密算法加密信息,再用RSA公钥加密对称性加密算法的密钥。

  另外,由于RSA算法性能问题,通常加解密都比较慢,所以通常和对称性加密算法一起配合使用。

Guess you like

Origin www.cnblogs.com/xtiger/p/10972373.html