comparison genrsa.c @ 299:740e782679be ucc-axis-hack

Various changes to compile+kind of run on UCC's axis board. Note that fprintf(stdin -> printf( accounts for many of the changes
author Matt Johnston <matt@ucc.asn.au>
date Sat, 25 Mar 2006 12:57:09 +0000
parents c9483550701b
children
comparison
equal deleted inserted replaced
266:e37b160c414c 299:740e782679be
56 &pminus, &lcm, &qminus, NULL); 56 &pminus, &lcm, &qminus, NULL);
57 57
58 seedrandom(); 58 seedrandom();
59 59
60 if (mp_set_int(key->e, RSA_E) != MP_OKAY) { 60 if (mp_set_int(key->e, RSA_E) != MP_OKAY) {
61 fprintf(stderr, "rsa generation failed\n"); 61 printf( "rsa generation failed\n");
62 exit(1); 62 exit(1);
63 } 63 }
64 64
65 /* PuTTY doesn't like it if the modulus isn't a multiple of 8 bits, 65 /* PuTTY doesn't like it if the modulus isn't a multiple of 8 bits,
66 * so we just generate them until we get one which is OK */ 66 * so we just generate them until we get one which is OK */
67 getrsaprime(key->p, &pminus, key->e, size/2); 67 getrsaprime(key->p, &pminus, key->e, size/2);
68 do { 68 do {
69 getrsaprime(key->q, &qminus, key->e, size/2); 69 getrsaprime(key->q, &qminus, key->e, size/2);
70 70
71 if (mp_mul(key->p, key->q, key->n) != MP_OKAY) { 71 if (mp_mul(key->p, key->q, key->n) != MP_OKAY) {
72 fprintf(stderr, "rsa generation failed\n"); 72 printf( "rsa generation failed\n");
73 exit(1); 73 exit(1);
74 } 74 }
75 } while (mp_count_bits(key->n) % 8 != 0); 75 } while (mp_count_bits(key->n) % 8 != 0);
76 76
77 /* lcm(p-1, q-1) */ 77 /* lcm(p-1, q-1) */
78 if (mp_lcm(&pminus, &qminus, &lcm) != MP_OKAY) { 78 if (mp_lcm(&pminus, &qminus, &lcm) != MP_OKAY) {
79 fprintf(stderr, "rsa generation failed\n"); 79 printf( "rsa generation failed\n");
80 exit(1); 80 exit(1);
81 } 81 }
82 82
83 /* de = 1 mod lcm(p-1,q-1) */ 83 /* de = 1 mod lcm(p-1,q-1) */
84 /* therefore d = (e^-1) mod lcm(p-1,q-1) */ 84 /* therefore d = (e^-1) mod lcm(p-1,q-1) */
85 if (mp_invmod(key->e, &lcm, key->d) != MP_OKAY) { 85 if (mp_invmod(key->e, &lcm, key->d) != MP_OKAY) {
86 fprintf(stderr, "rsa generation failed\n"); 86 printf( "rsa generation failed\n");
87 exit(1); 87 exit(1);
88 } 88 }
89 89
90 mp_clear_multi(&pminus, &qminus, &lcm, NULL); 90 mp_clear_multi(&pminus, &qminus, &lcm, NULL);
91 91
110 110
111 bytes_to_mp(prime, buf, size+1); 111 bytes_to_mp(prime, buf, size+1);
112 112
113 /* find the next integer which is prime, 8 round of miller-rabin */ 113 /* find the next integer which is prime, 8 round of miller-rabin */
114 if (mp_prime_next_prime(prime, 8, 0) != MP_OKAY) { 114 if (mp_prime_next_prime(prime, 8, 0) != MP_OKAY) {
115 fprintf(stderr, "rsa generation failed\n"); 115 printf( "rsa generation failed\n");
116 exit(1); 116 exit(1);
117 } 117 }
118 118
119 /* subtract one to get p-1 */ 119 /* subtract one to get p-1 */
120 if (mp_sub_d(prime, 1, primeminus) != MP_OKAY) { 120 if (mp_sub_d(prime, 1, primeminus) != MP_OKAY) {
121 fprintf(stderr, "rsa generation failed\n"); 121 printf( "rsa generation failed\n");
122 exit(1); 122 exit(1);
123 } 123 }
124 /* check relative primality to e */ 124 /* check relative primality to e */
125 if (mp_gcd(primeminus, rsa_e, &temp_gcd) != MP_OKAY) { 125 if (mp_gcd(primeminus, rsa_e, &temp_gcd) != MP_OKAY) {
126 fprintf(stderr, "rsa generation failed\n"); 126 printf( "rsa generation failed\n");
127 exit(1); 127 exit(1);
128 } 128 }
129 } while (mp_cmp_d(&temp_gcd, 1) != MP_EQ); /* while gcd(p-1, e) != 1 */ 129 } while (mp_cmp_d(&temp_gcd, 1) != MP_EQ); /* while gcd(p-1, e) != 1 */
130 130
131 /* now we have a good value for result */ 131 /* now we have a good value for result */