comparison genrsa.c @ 641:2b1bb792cd4d dropbear-tfm

- Update tfm changes to current default tip
author Matt Johnston <matt@ucc.asn.au>
date Mon, 21 Nov 2011 19:52:28 +0800
parents 76097ec1a29a a98a2138364a
children
comparison
equal deleted inserted replaced
640:76097ec1a29a 641:2b1bb792cd4d
35 35
36 static void getrsaprime(fp_int* prime, fp_int *primeminus, 36 static void getrsaprime(fp_int* prime, fp_int *primeminus,
37 fp_int* rsa_e, unsigned int size); 37 fp_int* rsa_e, unsigned int size);
38 38
39 /* mostly taken from libtomcrypt's rsa key generation routine */ 39 /* mostly taken from libtomcrypt's rsa key generation routine */
40 rsa_key * gen_rsa_priv_key(unsigned int size) { 40 dropbear_rsa_key * gen_rsa_priv_key(unsigned int size) {
41 41
42 rsa_key * key; 42 dropbear_rsa_key * key;
43 DEF_FP_INT(pminus); 43 DEF_FP_INT(pminus);
44 DEF_FP_INT(qminus); 44 DEF_FP_INT(qminus);
45 DEF_FP_INT(lcm); 45 DEF_FP_INT(lcm);
46 46
47 key = (rsa_key*)m_malloc(sizeof(rsa_key)); 47 key = m_malloc(sizeof(*key));
48 48
49 key->e = (fp_int*)m_malloc(sizeof(fp_int)); 49 key->e = (fp_int*)m_malloc(sizeof(fp_int));
50 key->n = (fp_int*)m_malloc(sizeof(fp_int)); 50 key->n = (fp_int*)m_malloc(sizeof(fp_int));
51 key->d = (fp_int*)m_malloc(sizeof(fp_int)); 51 key->d = (fp_int*)m_malloc(sizeof(fp_int));
52 key->p = (fp_int*)m_malloc(sizeof(fp_int)); 52 key->p = (fp_int*)m_malloc(sizeof(fp_int));
97 97
98 bytes_to_fp(prime, buf, size+1); 98 bytes_to_fp(prime, buf, size+1);
99 99
100 /* find the next integer which is prime, 8 round of miller-rabin */ 100 /* find the next integer which is prime, 8 round of miller-rabin */
101 if (fp_prime_next_prime(prime, 8, 0) != FP_OKAY) { 101 if (fp_prime_next_prime(prime, 8, 0) != FP_OKAY) {
102 fprintf(stderr, "rsa generation failed\n"); 102 fprintf(stderr, "RSA generation failed\n");
103 exit(1); 103 exit(1);
104 } 104 }
105 105
106 /* subtract one to get p-1 */ 106 /* subtract one to get p-1 */
107 fp_sub_d(prime, 1, primeminus); 107 fp_sub_d(prime, 1, primeminus);
108
109 /* check relative primality to e */ 108 /* check relative primality to e */
110 fp_gcd(primeminus, rsa_e, &temp_gcd); 109 fp_gcd(primeminus, rsa_e, &temp_gcd);
111 } while (fp_cmp_d(&temp_gcd, 1) != FP_EQ); /* while gcd(p-1, e) != 1 */ 110 } while (fp_cmp_d(&temp_gcd, 1) != FP_EQ); /* while gcd(p-1, e) != 1 */
112 111
113 /* now we have a good value for result */ 112 /* now we have a good value for result */