comparison rsa.c @ 70:b0316ce64e4b

Merging in the changes from 0.41-0.43 main Dropbear tree
author Matt Johnston <matt@ucc.asn.au>
date Thu, 12 Aug 2004 16:41:58 +0000
parents e2a1eaa19f22
children 29a5c7c62350
comparison
equal deleted inserted replaced
69:59d16db56e9f 70:b0316ce64e4b
242 TRACE(("success!")); 242 TRACE(("success!"));
243 ret = DROPBEAR_SUCCESS; 243 ret = DROPBEAR_SUCCESS;
244 } 244 }
245 245
246 out: 246 out:
247 mp_clear_multi(rsa_em, &rsa_mdash, &rsa_s, NULL); 247 if (rsa_em) {
248 m_free(rsa_em); 248 mp_clear(rsa_em);
249 m_free(rsa_em);
250 }
251 mp_clear_multi(&rsa_mdash, &rsa_s, NULL);
249 TRACE(("leave buf_rsa_verify: ret %d", ret)); 252 TRACE(("leave buf_rsa_verify: ret %d", ret));
250 return ret; 253 return ret;
251 254
252 } 255 }
253 #endif /* DROPBEAR_SIGNKEY_VERIFY */ 256 #endif /* DROPBEAR_SIGNKEY_VERIFY */
258 unsigned int len) { 261 unsigned int len) {
259 262
260 unsigned int nsize, ssize; 263 unsigned int nsize, ssize;
261 unsigned int i; 264 unsigned int i;
262 mp_int rsa_s; 265 mp_int rsa_s;
263 mp_int *rsa_em; 266 mp_int *rsa_em = NULL;
264 267
265 TRACE(("enter buf_put_rsa_sign")); 268 TRACE(("enter buf_put_rsa_sign"));
266 assert(key != NULL); 269 assert(key != NULL);
267 270
268 rsa_em = rsa_pad_em(key, data, len); 271 rsa_em = rsa_pad_em(key, data, len);
269 272
273 m_mp_init(&rsa_s);
274
270 /* the actual signing of the padded data */ 275 /* the actual signing of the padded data */
271 m_mp_init(&rsa_s);
272 /* s = em^d mod n */ 276 /* s = em^d mod n */
273 if (mp_exptmod(rsa_em, key->d, key->n, &rsa_s) != MP_OKAY) { 277 if (mp_exptmod(rsa_em, key->d, key->n, &rsa_s) != MP_OKAY) {
274 dropbear_exit("rsa error"); 278 dropbear_exit("rsa error");
275 } 279 }
276 mp_clear(rsa_em); 280 mp_clear(rsa_em);
320 /* ASN1 designator (including the 0x00 preceding) */ 324 /* ASN1 designator (including the 0x00 preceding) */
321 const char rsa_asn1_magic[] = 325 const char rsa_asn1_magic[] =
322 {0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 326 {0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b,
323 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14}; 327 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14};
324 #define RSA_ASN1_MAGIC_LEN 16 328 #define RSA_ASN1_MAGIC_LEN 16
325 buffer * rsa_EM; 329 buffer * rsa_EM = NULL;
326 hash_state hs; 330 hash_state hs;
327 unsigned int nsize; 331 unsigned int nsize;
328 mp_int * rsa_em; 332 mp_int * rsa_em = NULL;
329 333
330 assert(key != NULL); 334 assert(key != NULL);
331 assert(data != NULL); 335 assert(data != NULL);
332 nsize = mp_unsigned_bin_size(key->n); 336 nsize = mp_unsigned_bin_size(key->n);
333 337