comparison gendss.c @ 586:b50f0107e505

Rename rsa_key to dropbear_rsa_key (and same for dss too) so we don't conflict with libtomcrypt.
author Matt Johnston <matt@ucc.asn.au>
date Wed, 21 Jul 2010 12:55:25 +0000
parents c9483550701b
children a98a2138364a
comparison
equal deleted inserted replaced
585:d194db6f9453 586:b50f0107e505
35 35
36 /* This is just a test */ 36 /* This is just a test */
37 37
38 #ifdef DROPBEAR_DSS 38 #ifdef DROPBEAR_DSS
39 39
40 static void getq(dss_key *key); 40 static void getq(dropbear_dss_key *key);
41 static void getp(dss_key *key, unsigned int size); 41 static void getp(dropbear_dss_key *key, unsigned int size);
42 static void getg(dss_key *key); 42 static void getg(dropbear_dss_key *key);
43 static void getx(dss_key *key); 43 static void getx(dropbear_dss_key *key);
44 static void gety(dss_key *key); 44 static void gety(dropbear_dss_key *key);
45 45
46 dss_key * gen_dss_priv_key(unsigned int size) { 46 dropbear_dss_key * gen_dss_priv_key(unsigned int size) {
47 47
48 dss_key *key; 48 dropbear_dss_key *key;
49 49
50 key = (dss_key*)m_malloc(sizeof(dss_key)); 50 key = m_malloc(sizeof(*key));
51 51
52 key->p = (mp_int*)m_malloc(sizeof(mp_int)); 52 key->p = (mp_int*)m_malloc(sizeof(mp_int));
53 key->q = (mp_int*)m_malloc(sizeof(mp_int)); 53 key->q = (mp_int*)m_malloc(sizeof(mp_int));
54 key->g = (mp_int*)m_malloc(sizeof(mp_int)); 54 key->g = (mp_int*)m_malloc(sizeof(mp_int));
55 key->y = (mp_int*)m_malloc(sizeof(mp_int)); 55 key->y = (mp_int*)m_malloc(sizeof(mp_int));
66 66
67 return key; 67 return key;
68 68
69 } 69 }
70 70
71 static void getq(dss_key *key) { 71 static void getq(dropbear_dss_key *key) {
72 72
73 char buf[QSIZE]; 73 char buf[QSIZE];
74 74
75 /* 160 bit prime */ 75 /* 160 bit prime */
76 genrandom(buf, QSIZE); 76 genrandom(buf, QSIZE);
84 fprintf(stderr, "dss key generation failed\n"); 84 fprintf(stderr, "dss key generation failed\n");
85 exit(1); 85 exit(1);
86 } 86 }
87 } 87 }
88 88
89 static void getp(dss_key *key, unsigned int size) { 89 static void getp(dropbear_dss_key *key, unsigned int size) {
90 90
91 DEF_MP_INT(tempX); 91 DEF_MP_INT(tempX);
92 DEF_MP_INT(tempC); 92 DEF_MP_INT(tempC);
93 DEF_MP_INT(tempP); 93 DEF_MP_INT(tempP);
94 DEF_MP_INT(temp2q); 94 DEF_MP_INT(temp2q);
143 mp_clear_multi(&tempX, &tempC, &tempP, &temp2q, NULL); 143 mp_clear_multi(&tempX, &tempC, &tempP, &temp2q, NULL);
144 m_burn(buf, size); 144 m_burn(buf, size);
145 m_free(buf); 145 m_free(buf);
146 } 146 }
147 147
148 static void getg(dss_key * key) { 148 static void getg(dropbear_dss_key * key) {
149 149
150 DEF_MP_INT(div); 150 DEF_MP_INT(div);
151 DEF_MP_INT(h); 151 DEF_MP_INT(h);
152 DEF_MP_INT(val); 152 DEF_MP_INT(val);
153 153
180 } while (mp_cmp_d(key->g, 1) != MP_GT); 180 } while (mp_cmp_d(key->g, 1) != MP_GT);
181 181
182 mp_clear_multi(&div, &h, &val, NULL); 182 mp_clear_multi(&div, &h, &val, NULL);
183 } 183 }
184 184
185 static void getx(dss_key *key) { 185 static void getx(dropbear_dss_key *key) {
186 186
187 gen_random_mpint(key->q, key->x); 187 gen_random_mpint(key->q, key->x);
188 } 188 }
189 189
190 static void gety(dss_key *key) { 190 static void gety(dropbear_dss_key *key) {
191 191
192 if (mp_exptmod(key->g, key->x, key->p, key->y) != MP_OKAY) { 192 if (mp_exptmod(key->g, key->x, key->p, key->y) != MP_OKAY) {
193 fprintf(stderr, "dss key generation failed\n"); 193 fprintf(stderr, "dss key generation failed\n");
194 exit(1); 194 exit(1);
195 } 195 }