Switch to edit mode.
Name(s): RSA_key_pair1: "Thanks to JS (#7214) for porting this code. The export of this code from the US or Canada is STRICTLY prohibited. This said, please keep it unreadable (!r)."
2: ""
3: ":RSA_key_pair() => {private, public, modulus, ctr}"
4: " private: private RSA key exponent"
5: " public: public RSA key exponent"
6: " modulus: RSA key modulus"
7: " ctr: Number of private and public verified (for interest only)"
8: ""
9: " :make_key_pair tests for the relative primality of the numbers, and spits out randomly generated key pairs that (should) work. It's a good idea to test them using $encrypt_utils:RSA() before using."
10: " Further, your RSA private key is {private, modulus}, while your RSA public key is {public, modulus}. Do not allow your private key out of your safe keeping."
11: $tcm && raise(E_QUOTA, "Unavailable while TCM is active! (`?tcm' for more info)")
12: "Inserted a timeout mechanism to deal with cases where it just isn't working."
13: start_time = time()
14: "First, pick two numbers, p & q. Multiply them together to get n."
15: {p, q, n} = {p = random(this.RSA_max_pq), q = random(this.RSA_max_pq), p * q}
16: "Next, we need to define two numbers d and e, such that (de - 1) and (p - 1) and (de - 1) and (q - 1) are relatively prime."
17: {d, e} = {random(this.RSA_max_de), random(this.RSA_max_de)}
18: ctr = 1
19: l = d * e - 1
20: while (l % (p - 1) != 0 || l % (q - 1) != 0 || d == e || d == 1 || e == 1)
21: "Okay, so that choice didn't work out: try again. Sooner or later, we'll hit a good combo."
22: "And yes, this _may_ take a while."
23: {d, e} = {random(this.RSA_max_de), random(this.RSA_max_de)}
24: l = d * e - 1
25: ticks_left() < 4000 || seconds_left() < 2 ? suspend(0) | 0
26: if (time() - start_time > 10)
27: return E_NONE
28: endif
29: "Just for our interest, keep a tally of how many tries it takes."
30: ctr = ctr + 1
31: endwhile
32: "Bingo! Got values of d & e such that the relative primality stuff checks out."
33: return {d, e, n, ctr}
34: "Last modified by Raptor (#6319) on Mon Jan 11 10:31:10 1999 MST."