Mercurial > dropbear
comparison signkey.c @ 760:f336d232fc63 ecc
Make _sign and _verify functions take a buffer* rather than void* and int
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 06 Apr 2013 16:00:37 +0800 |
parents | a48a1f6ab43e |
children | 70625eed40c9 |
comparison
equal
deleted
inserted
replaced
759:76fba0856749 | 760:f336d232fc63 |
---|---|
216 #endif | 216 #endif |
217 if (pubkeys->len == 0) { | 217 if (pubkeys->len == 0) { |
218 dropbear_exit("Bad key types in buf_put_pub_key"); | 218 dropbear_exit("Bad key types in buf_put_pub_key"); |
219 } | 219 } |
220 | 220 |
221 buf_setpos(pubkeys, 0); | 221 buf_putbufstring(buf, pubkeys); |
222 buf_putstring(buf, buf_getptr(pubkeys, pubkeys->len), | |
223 pubkeys->len); | |
224 | |
225 buf_free(pubkeys); | 222 buf_free(pubkeys); |
226 TRACE(("leave buf_put_pub_key")) | 223 TRACE(("leave buf_put_pub_key")) |
227 } | 224 } |
228 | 225 |
229 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */ | 226 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */ |
362 return sign_key_sha1_fingerprint(keyblob, keybloblen); | 359 return sign_key_sha1_fingerprint(keyblob, keybloblen); |
363 #endif | 360 #endif |
364 } | 361 } |
365 | 362 |
366 void buf_put_sign(buffer* buf, sign_key *key, int type, | 363 void buf_put_sign(buffer* buf, sign_key *key, int type, |
367 const unsigned char *data, unsigned int len) { | 364 buffer *data_buf) { |
368 | |
369 buffer *sigblob; | 365 buffer *sigblob; |
370 sigblob = buf_new(MAX_PUBKEY_SIZE); | 366 sigblob = buf_new(MAX_PUBKEY_SIZE); |
371 | 367 |
372 #ifdef DROPBEAR_DSS | 368 #ifdef DROPBEAR_DSS |
373 if (type == DROPBEAR_SIGNKEY_DSS) { | 369 if (type == DROPBEAR_SIGNKEY_DSS) { |
374 buf_put_dss_sign(sigblob, key->dsskey, data, len); | 370 buf_put_dss_sign(sigblob, key->dsskey, data_buf); |
375 } | 371 } |
376 #endif | 372 #endif |
377 #ifdef DROPBEAR_RSA | 373 #ifdef DROPBEAR_RSA |
378 if (type == DROPBEAR_SIGNKEY_RSA) { | 374 if (type == DROPBEAR_SIGNKEY_RSA) { |
379 buf_put_rsa_sign(sigblob, key->rsakey, data, len); | 375 buf_put_rsa_sign(sigblob, key->rsakey, data_buf); |
380 } | 376 } |
381 #endif | 377 #endif |
382 if (sigblob->len == 0) { | 378 if (sigblob->len == 0) { |
383 dropbear_exit("Non-matching signing type"); | 379 dropbear_exit("Non-matching signing type"); |
384 } | 380 } |
385 buf_setpos(sigblob, 0); | 381 buf_putbufstring(buf, sigblob); |
386 buf_putstring(buf, buf_getptr(sigblob, sigblob->len), | |
387 sigblob->len); | |
388 | |
389 buf_free(sigblob); | 382 buf_free(sigblob); |
390 | 383 |
391 } | 384 } |
392 | 385 |
393 #ifdef DROPBEAR_SIGNKEY_VERIFY | 386 #ifdef DROPBEAR_SIGNKEY_VERIFY |
394 /* Return DROPBEAR_SUCCESS or DROPBEAR_FAILURE. | 387 /* Return DROPBEAR_SUCCESS or DROPBEAR_FAILURE. |
395 * If FAILURE is returned, the position of | 388 * If FAILURE is returned, the position of |
396 * buf is undefined. If SUCCESS is returned, buf will be positioned after the | 389 * buf is undefined. If SUCCESS is returned, buf will be positioned after the |
397 * signature blob */ | 390 * signature blob */ |
398 int buf_verify(buffer * buf, sign_key *key, const unsigned char *data, | 391 int buf_verify(buffer * buf, sign_key *key, buffer *data_buf) { |
399 unsigned int len) { | |
400 | 392 |
401 unsigned int bloblen; | 393 unsigned int bloblen; |
402 unsigned char * ident = NULL; | 394 unsigned char * ident = NULL; |
403 unsigned int identlen = 0; | 395 unsigned int identlen = 0; |
404 | 396 |
412 memcmp(ident, SSH_SIGNKEY_DSS, identlen) == 0) { | 404 memcmp(ident, SSH_SIGNKEY_DSS, identlen) == 0) { |
413 m_free(ident); | 405 m_free(ident); |
414 if (key->dsskey == NULL) { | 406 if (key->dsskey == NULL) { |
415 dropbear_exit("No DSS key to verify signature"); | 407 dropbear_exit("No DSS key to verify signature"); |
416 } | 408 } |
417 return buf_dss_verify(buf, key->dsskey, data, len); | 409 return buf_dss_verify(buf, key->dsskey, data_buf); |
418 } | 410 } |
419 #endif | 411 #endif |
420 | 412 |
421 #ifdef DROPBEAR_RSA | 413 #ifdef DROPBEAR_RSA |
422 if (memcmp(ident, SSH_SIGNKEY_RSA, identlen) == 0) { | 414 if (memcmp(ident, SSH_SIGNKEY_RSA, identlen) == 0) { |
423 m_free(ident); | 415 m_free(ident); |
424 if (key->rsakey == NULL) { | 416 if (key->rsakey == NULL) { |
425 dropbear_exit("No RSA key to verify signature"); | 417 dropbear_exit("No RSA key to verify signature"); |
426 } | 418 } |
427 return buf_rsa_verify(buf, key->rsakey, data, len); | 419 return buf_rsa_verify(buf, key->rsakey, data_buf); |
428 } | 420 } |
429 #endif | 421 #endif |
430 | 422 |
431 m_free(ident); | 423 m_free(ident); |
432 dropbear_exit("Non-matching signing type"); | 424 dropbear_exit("Non-matching signing type"); |