comparison rsa.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 a124aff0cbf1
children a98a2138364a
comparison
equal deleted inserted replaced
585:d194db6f9453 586:b50f0107e505
36 #include "ssh.h" 36 #include "ssh.h"
37 #include "random.h" 37 #include "random.h"
38 38
39 #ifdef DROPBEAR_RSA 39 #ifdef DROPBEAR_RSA
40 40
41 static void rsa_pad_em(rsa_key * key, 41 static void rsa_pad_em(dropbear_rsa_key * key,
42 const unsigned char * data, unsigned int len, 42 const unsigned char * data, unsigned int len,
43 mp_int * rsa_em); 43 mp_int * rsa_em);
44 44
45 /* Load a public rsa key from a buffer, initialising the values. 45 /* Load a public rsa key from a buffer, initialising the values.
46 * The key will have the same format as buf_put_rsa_key. 46 * The key will have the same format as buf_put_rsa_key.
47 * These should be freed with rsa_key_free. 47 * These should be freed with rsa_key_free.
48 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 48 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
49 int buf_get_rsa_pub_key(buffer* buf, rsa_key *key) { 49 int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) {
50 50
51 int ret = DROPBEAR_FAILURE; 51 int ret = DROPBEAR_FAILURE;
52 TRACE(("enter buf_get_rsa_pub_key")) 52 TRACE(("enter buf_get_rsa_pub_key"))
53 dropbear_assert(key != NULL); 53 dropbear_assert(key != NULL);
54 key->e = m_malloc(sizeof(mp_int)); 54 key->e = m_malloc(sizeof(mp_int));
82 } 82 }
83 83
84 /* Same as buf_get_rsa_pub_key, but reads private bits at the end. 84 /* Same as buf_get_rsa_pub_key, but reads private bits at the end.
85 * Loads a private rsa key from a buffer 85 * Loads a private rsa key from a buffer
86 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 86 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
87 int buf_get_rsa_priv_key(buffer* buf, rsa_key *key) { 87 int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) {
88 int ret = DROPBEAR_FAILURE; 88 int ret = DROPBEAR_FAILURE;
89 89
90 TRACE(("enter buf_get_rsa_priv_key")) 90 TRACE(("enter buf_get_rsa_priv_key"))
91 dropbear_assert(key != NULL); 91 dropbear_assert(key != NULL);
92 92
135 return ret; 135 return ret;
136 } 136 }
137 137
138 138
139 /* Clear and free the memory used by a public or private key */ 139 /* Clear and free the memory used by a public or private key */
140 void rsa_key_free(rsa_key *key) { 140 void rsa_key_free(dropbear_rsa_key *key) {
141 141
142 TRACE(("enter rsa_key_free")) 142 TRACE(("enter rsa_key_free"))
143 143
144 if (key == NULL) { 144 if (key == NULL) {
145 TRACE(("leave rsa_key_free: key == NULL")) 145 TRACE(("leave rsa_key_free: key == NULL"))
173 * 173 *
174 * string "ssh-rsa" 174 * string "ssh-rsa"
175 * mp_int e 175 * mp_int e
176 * mp_int n 176 * mp_int n
177 */ 177 */
178 void buf_put_rsa_pub_key(buffer* buf, rsa_key *key) { 178 void buf_put_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) {
179 179
180 TRACE(("enter buf_put_rsa_pub_key")) 180 TRACE(("enter buf_put_rsa_pub_key"))
181 dropbear_assert(key != NULL); 181 dropbear_assert(key != NULL);
182 182
183 buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN); 183 buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN);
187 TRACE(("leave buf_put_rsa_pub_key")) 187 TRACE(("leave buf_put_rsa_pub_key"))
188 188
189 } 189 }
190 190
191 /* Same as buf_put_rsa_pub_key, but with the private "x" key appended */ 191 /* Same as buf_put_rsa_pub_key, but with the private "x" key appended */
192 void buf_put_rsa_priv_key(buffer* buf, rsa_key *key) { 192 void buf_put_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) {
193 193
194 TRACE(("enter buf_put_rsa_priv_key")) 194 TRACE(("enter buf_put_rsa_priv_key"))
195 195
196 dropbear_assert(key != NULL); 196 dropbear_assert(key != NULL);
197 buf_put_rsa_pub_key(buf, key); 197 buf_put_rsa_pub_key(buf, key);
211 } 211 }
212 212
213 #ifdef DROPBEAR_SIGNKEY_VERIFY 213 #ifdef DROPBEAR_SIGNKEY_VERIFY
214 /* Verify a signature in buf, made on data by the key given. 214 /* Verify a signature in buf, made on data by the key given.
215 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 215 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
216 int buf_rsa_verify(buffer * buf, rsa_key *key, const unsigned char* data, 216 int buf_rsa_verify(buffer * buf, dropbear_rsa_key *key, const unsigned char* data,
217 unsigned int len) { 217 unsigned int len) {
218 218
219 unsigned int slen; 219 unsigned int slen;
220 DEF_MP_INT(rsa_s); 220 DEF_MP_INT(rsa_s);
221 DEF_MP_INT(rsa_mdash); 221 DEF_MP_INT(rsa_mdash);
268 268
269 #endif /* DROPBEAR_SIGNKEY_VERIFY */ 269 #endif /* DROPBEAR_SIGNKEY_VERIFY */
270 270
271 /* Sign the data presented with key, writing the signature contents 271 /* Sign the data presented with key, writing the signature contents
272 * to the buffer */ 272 * to the buffer */
273 void buf_put_rsa_sign(buffer* buf, rsa_key *key, const unsigned char* data, 273 void buf_put_rsa_sign(buffer* buf, dropbear_rsa_key *key, const unsigned char* data,
274 unsigned int len) { 274 unsigned int len) {
275 275
276 unsigned int nsize, ssize; 276 unsigned int nsize, ssize;
277 unsigned int i; 277 unsigned int i;
278 DEF_MP_INT(rsa_s); 278 DEF_MP_INT(rsa_s);
374 * prefix is the ASN1 designator prefix, 374 * prefix is the ASN1 designator prefix,
375 * hex 30 21 30 09 06 05 2B 0E 03 02 1A 05 00 04 14 375 * hex 30 21 30 09 06 05 2B 0E 03 02 1A 05 00 04 14
376 * 376 *
377 * rsa_em must be a pointer to an initialised mp_int. 377 * rsa_em must be a pointer to an initialised mp_int.
378 */ 378 */
379 static void rsa_pad_em(rsa_key * key, 379 static void rsa_pad_em(dropbear_rsa_key * key,
380 const unsigned char * data, unsigned int len, 380 const unsigned char * data, unsigned int len,
381 mp_int * rsa_em) { 381 mp_int * rsa_em) {
382 382
383 /* ASN1 designator (including the 0x00 preceding) */ 383 /* ASN1 designator (including the 0x00 preceding) */
384 const unsigned char rsa_asn1_magic[] = 384 const unsigned char rsa_asn1_magic[] =