comparison rsa.c @ 118:5312ca05ed48 private-rez

propagate of 717950f4061f1123659ee87c7c168805af920ab7 and 839f98f136788cc1466e4641bf796f96040a085d from branch 'matt.dbclient.authpam' to 'matt.dbclient.rez'
author Matt Johnston <matt@ucc.asn.au>
date Sun, 12 Sep 2004 04:56:50 +0000
parents 29a5c7c62350
children 0cfba3034be5
comparison
equal deleted inserted replaced
57:3b2a5a1c4347 118:5312ca05ed48
199 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 199 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
200 int buf_rsa_verify(buffer * buf, rsa_key *key, const unsigned char* data, 200 int buf_rsa_verify(buffer * buf, rsa_key *key, const unsigned char* data,
201 unsigned int len) { 201 unsigned int len) {
202 202
203 unsigned int slen; 203 unsigned int slen;
204 mp_int rsa_s, rsa_mdash; 204 DEF_MP_INT(rsa_s);
205 DEF_MP_INT(rsa_mdash);
205 mp_int *rsa_em = NULL; 206 mp_int *rsa_em = NULL;
206 int ret = DROPBEAR_FAILURE; 207 int ret = DROPBEAR_FAILURE;
207 208
208 TRACE(("enter buf_rsa_verify")); 209 TRACE(("enter buf_rsa_verify"));
209 210
242 TRACE(("success!")); 243 TRACE(("success!"));
243 ret = DROPBEAR_SUCCESS; 244 ret = DROPBEAR_SUCCESS;
244 } 245 }
245 246
246 out: 247 out:
247 mp_clear_multi(rsa_em, &rsa_mdash, &rsa_s, NULL); 248 if (rsa_em) {
248 m_free(rsa_em); 249 mp_clear(rsa_em);
250 m_free(rsa_em);
251 }
252 mp_clear_multi(&rsa_mdash, &rsa_s, NULL);
249 TRACE(("leave buf_rsa_verify: ret %d", ret)); 253 TRACE(("leave buf_rsa_verify: ret %d", ret));
250 return ret; 254 return ret;
251 255
252 } 256 }
253 #endif /* DROPBEAR_SIGNKEY_VERIFY */ 257 #endif /* DROPBEAR_SIGNKEY_VERIFY */
257 void buf_put_rsa_sign(buffer* buf, rsa_key *key, const unsigned char* data, 261 void buf_put_rsa_sign(buffer* buf, rsa_key *key, const unsigned char* data,
258 unsigned int len) { 262 unsigned int len) {
259 263
260 unsigned int nsize, ssize; 264 unsigned int nsize, ssize;
261 unsigned int i; 265 unsigned int i;
262 mp_int rsa_s; 266 DEF_MP_INT(rsa_s);
263 mp_int *rsa_em; 267 mp_int *rsa_em = NULL;
264 268
265 TRACE(("enter buf_put_rsa_sign")); 269 TRACE(("enter buf_put_rsa_sign"));
266 assert(key != NULL); 270 assert(key != NULL);
267 271
268 rsa_em = rsa_pad_em(key, data, len); 272 rsa_em = rsa_pad_em(key, data, len);
269 273
274 m_mp_init(&rsa_s);
275
270 /* the actual signing of the padded data */ 276 /* the actual signing of the padded data */
271 m_mp_init(&rsa_s);
272 /* s = em^d mod n */ 277 /* s = em^d mod n */
273 if (mp_exptmod(rsa_em, key->d, key->n, &rsa_s) != MP_OKAY) { 278 if (mp_exptmod(rsa_em, key->d, key->n, &rsa_s) != MP_OKAY) {
274 dropbear_exit("rsa error"); 279 dropbear_exit("rsa error");
275 } 280 }
276 mp_clear(rsa_em); 281 mp_clear(rsa_em);
320 /* ASN1 designator (including the 0x00 preceding) */ 325 /* ASN1 designator (including the 0x00 preceding) */
321 const char rsa_asn1_magic[] = 326 const char rsa_asn1_magic[] =
322 {0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 327 {0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b,
323 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14}; 328 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14};
324 #define RSA_ASN1_MAGIC_LEN 16 329 #define RSA_ASN1_MAGIC_LEN 16
325 buffer * rsa_EM; 330 buffer * rsa_EM = NULL;
326 hash_state hs; 331 hash_state hs;
327 unsigned int nsize; 332 unsigned int nsize;
328 mp_int * rsa_em; 333 mp_int * rsa_em = NULL;
329 334
330 assert(key != NULL); 335 assert(key != NULL);
331 assert(data != NULL); 336 assert(data != NULL);
332 nsize = mp_unsigned_bin_size(key->n); 337 nsize = mp_unsigned_bin_size(key->n);
333 338