🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 10.7 The RSA Public-Key Cryptosystem Recall the situation discussed at the beginning of this chapter concerning Bob wanting to send Alice a secret love note over the Internet. We noted that if he could encode the message so that it appears as gibberish and only Alice could decode the gibberish back to the original message, he would not need to fear his friends intercepting the message. Public-key cryptosystem enable Bob to do this. After describing such systems, we present the RSA public-key cryptosystem. ### 10.7.1 Public-Key Cryptosystems A ***public-key cryptosystem*** consists of a set of permissible messages, a set of participants such that each participant has a ***public key*** and a ***secret key***, and a network for sending messages among he participants. The set of permissible messages might include all character sequences of some given length or less. If we let ![](https://box.kancloud.cn/ce1c7d6c523aadfe89efda65c513df2f_268x21.jpg) then each participant *x*'s public key *pkeyx* and secret key *skeyx* determine functions *pubx* and *secx*, respectively, form *M* to *M*, which are inverses of each other. That is, for each *b* ∊ *M* ![](https://box.kancloud.cn/bae51a4a3554431f59218fe991912cda_150x82.jpg) Now the public keys of all participants are known to all the participants, but the secret key of *x* is known only to *x*. So, for example, if Bob wants to send Alice a secret love note *b*, he and Alice do the following: 1. Bob computes *c* = *pubAlice*(*b*) using Alice's public key, *pkeyAlice*. The message *c* is called ***ciphertext***. It is unreadable. 2. Bob sends ciphertext *c* to Alice. 3. Alice computes *b* = *secAlice*(*c*) using her secret key *skeyAlice*. Example 10.66**![Start example](https://box.kancloud.cn/e95df9d604ab2d89febe370ae4d88fb1_1x1.gif)**Suppose Bob wants to send Alice the message ‘I love you.’ The steps are as follows: **![End example](https://box.kancloud.cn/e95df9d604ab2d89febe370ae4d88fb1_1x1.gif)** 1. Bob computes ![](https://box.kancloud.cn/3fd279596b0829e063fa65342f484ed2_170x22.jpg) Suppose the result is ‘@!##%\* (!’. 2. Bob sends this message to Alice. Bob's friends see ‘@!##%\* (!’. 3. Alice computes ![](https://box.kancloud.cn/b6da09166744615a358d33ce46c63afe_283x22.jpg) The application of *pubAlice* in Step 1 is called ***encryption***, while the application of *secAlice* in Step 3 is called ***decryption.*** These steps are illustrated in [Figure 10.1](#ch10fig01). Note that since only Alice knows *secAlice*, only she can decode the ciphertext *c* back to the original message *b*. So Bob's friends see only the ciphertext. [![Click To expand](https://box.kancloud.cn/22d3e596d1873dc6519f584c3677a195_350x73.jpg)](fig10-1_0.jpg) Figure 10.1: Bob encrypts his message *b* using Alice's public key, and Alice decrypts it using her secret key. Bob's friends see only he ciphertext *c*. This method will work as long as it is not possible (or at least it is very difficult) to determine *skeyx* from *pkeyx.* Next we show a system that makes it very difficult to do so. ### 10.7.2 The RSA Cryptosystem The RSA cryptosystem relies on the facts that we can find large primes fairly readily, but we have no efficient method for factoring a large number. After presenting the method, we discuss these facts further. ### The System In the ***RSA public-key cryptosystem,*** each participant creates his public key and secret key according to the following steps: 1. Select two very large prime number *p* and *q.* The number of bits needed to represent *p* and *q* might be 1024. 2. Compute ![](https://box.kancloud.cn/a1c645a6ae2ebf03a4b59b1a7e19b381_175x44.jpg) The formula for φ(n) is owing to [Theorem 10.17](LiB0083.html#1080). 3. Select a small prime number *g* that is relatively prime to φ(n). 4. Using [Algorithm 10.3](LiB0084.html#1128), compute the multiplicative inverse \[*h*\]φ(*n*) of \[*g*\]φ(*n*). That is, ![](https://box.kancloud.cn/12d30e18e60d26fc90d89a107683002c_185x26.jpg) Owing to [Corollary 10.8](LiB0084.html#1117), this inverse exists and is unique. 5. Let *pkey* = (*n,g*) by the public key, and *skey* = (*n,h*) be the secret key. The set of permissible messages in **Z***n*. The function corresponding to the public key *pkey* = (*n,g*) is ![](https://box.kancloud.cn/4d690ea7ddcae9ce7ce5aec58fba83d3_358x22.jpg) where *b* ∊ **Z***n*, and the function corresponding to the secret key *skey* = (*n,h*) is ![](https://box.kancloud.cn/911d15e48233e14d7b3381aa353d1ec4_354x23.jpg) The values of these functions can be computed using [Algorithm 10.5](LiB0086.html#1167). For this system to be correct, the functions corresponding to the public and secret keys must be inverses of each other. Next we prove this is the case. Theorem 10.33**![Start example](https://box.kancloud.cn/e95df9d604ab2d89febe370ae4d88fb1_1x1.gif)**![](https://box.kancloud.cn/485bc67a7beadb016ac9d44f235f6e03_27x27.jpg) The functions in Equalities 10.29 and 10.30 are inverses of each other. **![End example](https://box.kancloud.cn/e95df9d604ab2d89febe370ae4d88fb1_1x1.gif)** Proof: Owing to Equalities 10.29 and 10.30, for any *b* ∊ **Z***n* ![](https://box.kancloud.cn/9c2082e03fa02e5a4da992e5dbab56cf_254x24.jpg) So we need to show only that ![](https://box.kancloud.cn/d4de6ed03cc42e7f6ed07fa650bb4db4_65x20.jpg) To that end, let *m* ∊ *b*.(Recall *b* ∊ **Z***n*.) Then *mgh* ∊ *bgh*. We will show ![](https://box.kancloud.cn/371e0388c32fcfac9f2544d70be05797_364x28.jpg) Since *g* and *h* are multiplicative inverses modulo φ(n)=(p-1)(q-1), ![](https://box.kancloud.cn/3b9600da588abf14012e97d4afb706bd_230x27.jpg) which means there is an integer *k* such that ![](https://box.kancloud.cn/efd7de13759bcdc94283b574b36a590f_199x21.jpg) There are two cases. **Case 1:** Assume \[m\]p≠\[0\]p. We than have ![](https://box.kancloud.cn/3328594b73cab7cffcdbf9acd969a7a1_244x131.jpg) The third equality above is due to [Theorem 10.22](LiB0083.html#1106). **Case 2:** If \[m\]p=\[0\]p, ![](https://box.kancloud.cn/256ce5abf1d88ab21313854f906ed664_293x28.jpg) So we've established Equality 10.31. Similarly, ![](https://box.kancloud.cn/caccc5e9565e06e44b104b54edca7bf7_364x28.jpg) Owing to Equalities 10.31 and 10.32, ![](https://box.kancloud.cn/aca32a7dceb38615437485eaafa1f8ab_126x23.jpg) and ![](https://box.kancloud.cn/aaeec21855783f619f00a4cde34cdfa8_129x24.jpg) Due to [Theorem 10.13](LiB0083.html#1062), we therefore have ![](https://box.kancloud.cn/b18e5cc0ea57697963a39123d1d8383b_131x24.jpg) which means ![](https://box.kancloud.cn/a5fd299c47a740e1c80b8df1d4f06f00_65x21.jpg) This completes the proof. ### Discussion As mentioned previously, the success of the RSA cryptosystem relies on the facts that we can find large primes fairly readily, but we have no efficient method for factoring a large number. That is, we can find a large prime as follows. First, we randomly choose integers of the appropriate size. As discussed at the beginning of [Section 10.6](#ch10lev1sec7), it should not take very long even to find a fairly large prime. For each integer chosen, we can then use [Algorithm 10.5](LiB0086.html#1167), which is polynomial-time, to check whether the number is prime. We do this until we find two large primes. As discussed in [Section 10.6](#ch10lev1sec7), even before [Algorithm 10.5](LiB0086.html#1167) was developed, the Miller-Rabin Randomized Primality Test was used to efficiently check with a very low error rate whether a number was prime. Indeed, the Miller-Rabin Randomized Primality Test may still be the algorithm of choice for prime checking since its time complexity is in *O*(*es*3), where *s* is the number of bits it takes to encode the input, and *e* is an integer chosen such that the probability the algorithm makes an error is no greater than 2-e. So if we choose *e* to be only 40, the probability of an error is no greater than 2-40 = 9.0949 × 10-13. On the other hand, no one has ever found a polynomial-time algorithm for factoring a number. The possibility exists that one could find the value of *h* in the secret key *skey* = (*n,h*) without factoring *n*. However, no one has found an efficient way to do this either. Currently we can achieve security with the RSA cryptosystem if integers containing around 1024 or more bits are used.