diff options
Diffstat (limited to 'src/util/crypto_rsa.c')
-rw-r--r-- | src/util/crypto_rsa.c | 153 |
1 files changed, 73 insertions, 80 deletions
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 6be2f53c0..3607998e4 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -108,10 +108,10 @@ GNUNET_CRYPTO_rsa_key_create () | |||
108 | gcry_sexp_t s_key; | 108 | gcry_sexp_t s_key; |
109 | gcry_sexp_t s_keyparam; | 109 | gcry_sexp_t s_keyparam; |
110 | 110 | ||
111 | GNUNET_assert (0 == gcry_sexp_build (&s_keyparam, | 111 | GNUNET_assert (0 == |
112 | NULL, | 112 | gcry_sexp_build (&s_keyparam, NULL, |
113 | "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))", | 113 | "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))", |
114 | HOSTKEY_LEN)); | 114 | HOSTKEY_LEN)); |
115 | GNUNET_assert (0 == gcry_pk_genkey (&s_key, s_keyparam)); | 115 | GNUNET_assert (0 == gcry_pk_genkey (&s_key, s_keyparam)); |
116 | gcry_sexp_release (s_keyparam); | 116 | gcry_sexp_release (s_keyparam); |
117 | #if EXTRA_CHECKS | 117 | #if EXTRA_CHECKS |
@@ -133,8 +133,8 @@ GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) | |||
133 | } | 133 | } |
134 | 134 | ||
135 | static int | 135 | static int |
136 | key_from_sexp (gcry_mpi_t * array, | 136 | key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname, |
137 | gcry_sexp_t sexp, const char *topname, const char *elems) | 137 | const char *elems) |
138 | { | 138 | { |
139 | gcry_sexp_t list, l2; | 139 | gcry_sexp_t list, l2; |
140 | const char *s; | 140 | const char *s; |
@@ -192,8 +192,8 @@ key_from_sexp (gcry_mpi_t * array, | |||
192 | void | 192 | void |
193 | GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey | 193 | GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey |
194 | *priv, | 194 | *priv, |
195 | struct | 195 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
196 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub) | 196 | *pub) |
197 | { | 197 | { |
198 | gcry_mpi_t skey[2]; | 198 | gcry_mpi_t skey[2]; |
199 | size_t size; | 199 | size_t size; |
@@ -211,14 +211,15 @@ GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey | |||
211 | pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); | 211 | pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); |
212 | pub->padding = 0; | 212 | pub->padding = 0; |
213 | size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; | 213 | size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; |
214 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, | 214 | GNUNET_assert (0 == |
215 | &pub->key[0], size, &size, skey[0])); | 215 | gcry_mpi_print (GCRYMPI_FMT_USG, &pub->key[0], size, &size, |
216 | skey[0])); | ||
216 | adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); | 217 | adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); |
217 | size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; | 218 | size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; |
218 | GNUNET_assert (0 == | 219 | GNUNET_assert (0 == |
219 | gcry_mpi_print (GCRYMPI_FMT_USG, | 220 | gcry_mpi_print (GCRYMPI_FMT_USG, |
220 | &pub->key | 221 | &pub-> |
221 | [GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], | 222 | key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], |
222 | size, &size, skey[1])); | 223 | size, &size, skey[1])); |
223 | adjust (&pub->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size, | 224 | adjust (&pub->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size, |
224 | GNUNET_CRYPTO_RSA_KEY_LENGTH - | 225 | GNUNET_CRYPTO_RSA_KEY_LENGTH - |
@@ -271,8 +272,8 @@ public2PrivateKey (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | |||
271 | gcry_mpi_release (n); | 272 | gcry_mpi_release (n); |
272 | return NULL; | 273 | return NULL; |
273 | } | 274 | } |
274 | rc = gcry_sexp_build (&result, | 275 | rc = gcry_sexp_build (&result, &erroff, "(public-key(rsa(n %m)(e %m)))", n, |
275 | &erroff, "(public-key(rsa(n %m)(e %m)))", n, e); | 276 | e); |
276 | gcry_mpi_release (n); | 277 | gcry_mpi_release (n); |
277 | gcry_mpi_release (e); | 278 | gcry_mpi_release (e); |
278 | if (rc) | 279 | if (rc) |
@@ -329,9 +330,10 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) | |||
329 | { | 330 | { |
330 | if (pkv[i] != NULL) | 331 | if (pkv[i] != NULL) |
331 | { | 332 | { |
332 | GNUNET_assert (0 == gcry_mpi_aprint (GCRYMPI_FMT_USG, | 333 | GNUNET_assert (0 == |
333 | (unsigned char **) &pbu[i], | 334 | gcry_mpi_aprint (GCRYMPI_FMT_USG, |
334 | &sizes[i], pkv[i])); | 335 | (unsigned char **) &pbu[i], &sizes[i], |
336 | pkv[i])); | ||
335 | size += sizes[i]; | 337 | size += sizes[i]; |
336 | } | 338 | } |
337 | else | 339 | else |
@@ -399,10 +401,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
399 | 401 | ||
400 | pos = 0; | 402 | pos = 0; |
401 | size = ntohs (encoding->sizen); | 403 | size = ntohs (encoding->sizen); |
402 | rc = gcry_mpi_scan (&n, | 404 | rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, |
403 | GCRYMPI_FMT_USG, | 405 | &((const unsigned char *) (&encoding[1]))[pos], size, |
404 | &((const unsigned char *) (&encoding[1]))[pos], | 406 | &size); |
405 | size, &size); | ||
406 | pos += ntohs (encoding->sizen); | 407 | pos += ntohs (encoding->sizen); |
407 | if (rc) | 408 | if (rc) |
408 | { | 409 | { |
@@ -410,10 +411,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
410 | return NULL; | 411 | return NULL; |
411 | } | 412 | } |
412 | size = ntohs (encoding->sizee); | 413 | size = ntohs (encoding->sizee); |
413 | rc = gcry_mpi_scan (&e, | 414 | rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG, |
414 | GCRYMPI_FMT_USG, | 415 | &((const unsigned char *) (&encoding[1]))[pos], size, |
415 | &((const unsigned char *) (&encoding[1]))[pos], | 416 | &size); |
416 | size, &size); | ||
417 | pos += ntohs (encoding->sizee); | 417 | pos += ntohs (encoding->sizee); |
418 | if (rc) | 418 | if (rc) |
419 | { | 419 | { |
@@ -422,10 +422,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
422 | return NULL; | 422 | return NULL; |
423 | } | 423 | } |
424 | size = ntohs (encoding->sized); | 424 | size = ntohs (encoding->sized); |
425 | rc = gcry_mpi_scan (&d, | 425 | rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG, |
426 | GCRYMPI_FMT_USG, | 426 | &((const unsigned char *) (&encoding[1]))[pos], size, |
427 | &((const unsigned char *) (&encoding[1]))[pos], | 427 | &size); |
428 | size, &size); | ||
429 | pos += ntohs (encoding->sized); | 428 | pos += ntohs (encoding->sized); |
430 | if (rc) | 429 | if (rc) |
431 | { | 430 | { |
@@ -438,10 +437,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
438 | size = ntohs (encoding->sizep); | 437 | size = ntohs (encoding->sizep); |
439 | if (size > 0) | 438 | if (size > 0) |
440 | { | 439 | { |
441 | rc = gcry_mpi_scan (&q, | 440 | rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG, |
442 | GCRYMPI_FMT_USG, | 441 | &((const unsigned char *) (&encoding[1]))[pos], size, |
443 | &((const unsigned char *) (&encoding[1]))[pos], | 442 | &size); |
444 | size, &size); | ||
445 | pos += ntohs (encoding->sizep); | 443 | pos += ntohs (encoding->sizep); |
446 | if (rc) | 444 | if (rc) |
447 | { | 445 | { |
@@ -457,10 +455,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
457 | size = ntohs (encoding->sizeq); | 455 | size = ntohs (encoding->sizeq); |
458 | if (size > 0) | 456 | if (size > 0) |
459 | { | 457 | { |
460 | rc = gcry_mpi_scan (&p, | 458 | rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG, |
461 | GCRYMPI_FMT_USG, | 459 | &((const unsigned char *) (&encoding[1]))[pos], size, |
462 | &((const unsigned char *) (&encoding[1]))[pos], | 460 | &size); |
463 | size, &size); | ||
464 | pos += ntohs (encoding->sizeq); | 461 | pos += ntohs (encoding->sizeq); |
465 | if (rc) | 462 | if (rc) |
466 | { | 463 | { |
@@ -481,10 +478,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
481 | ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos; | 478 | ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos; |
482 | if (size > 0) | 479 | if (size > 0) |
483 | { | 480 | { |
484 | rc = gcry_mpi_scan (&u, | 481 | rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG, |
485 | GCRYMPI_FMT_USG, | 482 | &((const unsigned char *) (&encoding[1]))[pos], size, |
486 | &((const unsigned char *) (&encoding[1]))[pos], | 483 | &size); |
487 | size, &size); | ||
488 | if (rc) | 484 | if (rc) |
489 | { | 485 | { |
490 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 486 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
@@ -577,9 +573,8 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
577 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 573 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
578 | { | 574 | { |
579 | fd = GNUNET_DISK_file_open (filename, | 575 | fd = GNUNET_DISK_file_open (filename, |
580 | GNUNET_DISK_OPEN_WRITE | | 576 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
581 | GNUNET_DISK_OPEN_CREATE | | 577 | | GNUNET_DISK_OPEN_FAILIFEXISTS, |
582 | GNUNET_DISK_OPEN_FAILIFEXISTS, | ||
583 | GNUNET_DISK_PERM_USER_READ | | 578 | GNUNET_DISK_PERM_USER_READ | |
584 | GNUNET_DISK_PERM_USER_WRITE); | 579 | GNUNET_DISK_PERM_USER_WRITE); |
585 | if (NULL == fd) | 580 | if (NULL == fd) |
@@ -590,8 +585,8 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
590 | { | 585 | { |
591 | /* must exist but not be accessible, fail for good! */ | 586 | /* must exist but not be accessible, fail for good! */ |
592 | if (0 != ACCESS (filename, R_OK)) | 587 | if (0 != ACCESS (filename, R_OK)) |
593 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 588 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access", |
594 | "access", filename); | 589 | filename); |
595 | else | 590 | else |
596 | GNUNET_break (0); /* what is going on!? */ | 591 | GNUNET_break (0); /* what is going on!? */ |
597 | return NULL; | 592 | return NULL; |
@@ -605,8 +600,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
605 | 600 | ||
606 | while (GNUNET_YES != | 601 | while (GNUNET_YES != |
607 | GNUNET_DISK_file_lock (fd, 0, | 602 | GNUNET_DISK_file_lock (fd, 0, |
608 | sizeof (struct | 603 | sizeof (struct RsaPrivateKeyBinaryEncoded), |
609 | RsaPrivateKeyBinaryEncoded), | ||
610 | GNUNET_YES)) | 604 | GNUNET_YES)) |
611 | { | 605 | { |
612 | sleep (1); | 606 | sleep (1); |
@@ -614,9 +608,8 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
614 | { | 608 | { |
615 | ec = errno; | 609 | ec = errno; |
616 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 610 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
617 | _ | 611 | _("Could not aquire lock on file `%s': %s...\n"), filename, |
618 | ("Could not aquire lock on file `%s': %s...\n"), | 612 | STRERROR (ec)); |
619 | filename, STRERROR (ec)); | ||
620 | } | 613 | } |
621 | } | 614 | } |
622 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 615 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -662,8 +655,8 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
662 | { | 655 | { |
663 | ec = errno; | 656 | ec = errno; |
664 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 657 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
665 | _("Could not aquire lock on file `%s': %s...\n"), | 658 | _("Could not aquire lock on file `%s': %s...\n"), filename, |
666 | filename, STRERROR (ec)); | 659 | STRERROR (ec)); |
667 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 660 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
668 | _ | 661 | _ |
669 | ("This may be ok if someone is currently generating a hostkey.\n")); | 662 | ("This may be ok if someone is currently generating a hostkey.\n")); |
@@ -754,10 +747,9 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
754 | * @returns GNUNET_SYSERR on error, GNUNET_OK if ok | 747 | * @returns GNUNET_SYSERR on error, GNUNET_OK if ok |
755 | */ | 748 | */ |
756 | int | 749 | int |
757 | GNUNET_CRYPTO_rsa_encrypt (const void *block, | 750 | GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, |
758 | size_t size, | 751 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
759 | const struct | 752 | *publicKey, |
760 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey, | ||
761 | struct GNUNET_CRYPTO_RsaEncryptedData *target) | 753 | struct GNUNET_CRYPTO_RsaEncryptedData *target) |
762 | { | 754 | { |
763 | gcry_sexp_t result; | 755 | gcry_sexp_t result; |
@@ -786,9 +778,9 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, | |||
786 | GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "a")); | 778 | GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "a")); |
787 | gcry_sexp_release (result); | 779 | gcry_sexp_release (result); |
788 | isize = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); | 780 | isize = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); |
789 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, | 781 | GNUNET_assert (0 == |
790 | (unsigned char *) target, isize, &isize, | 782 | gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) target, |
791 | rval)); | 783 | isize, &isize, rval)); |
792 | gcry_mpi_release (rval); | 784 | gcry_mpi_release (rval); |
793 | adjust (&target->encoding[0], isize, | 785 | adjust (&target->encoding[0], isize, |
794 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); | 786 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); |
@@ -807,8 +799,8 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, | |||
807 | */ | 799 | */ |
808 | ssize_t | 800 | ssize_t |
809 | GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, | 801 | GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, |
810 | const struct GNUNET_CRYPTO_RsaEncryptedData * | 802 | const struct GNUNET_CRYPTO_RsaEncryptedData * block, |
811 | block, void *result, size_t max) | 803 | void *result, size_t max) |
812 | { | 804 | { |
813 | gcry_sexp_t resultsexp; | 805 | gcry_sexp_t resultsexp; |
814 | gcry_sexp_t data; | 806 | gcry_sexp_t data; |
@@ -822,12 +814,12 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, | |||
822 | GNUNET_assert (0 == gcry_pk_testkey (key->sexp)); | 814 | GNUNET_assert (0 == gcry_pk_testkey (key->sexp)); |
823 | #endif | 815 | #endif |
824 | size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); | 816 | size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); |
825 | GNUNET_assert (0 == gcry_mpi_scan (&val, | ||
826 | GCRYMPI_FMT_USG, &block->encoding[0], | ||
827 | size, &size)); | ||
828 | GNUNET_assert (0 == | 817 | GNUNET_assert (0 == |
829 | gcry_sexp_build (&data, &erroff, | 818 | gcry_mpi_scan (&val, GCRYMPI_FMT_USG, &block->encoding[0], |
830 | "(enc-val(flags)(rsa(a %m)))", val)); | 819 | size, &size)); |
820 | GNUNET_assert (0 == | ||
821 | gcry_sexp_build (&data, &erroff, "(enc-val(flags)(rsa(a %m)))", | ||
822 | val)); | ||
831 | gcry_mpi_release (val); | 823 | gcry_mpi_release (val); |
832 | GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, key->sexp)); | 824 | GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, key->sexp)); |
833 | gcry_sexp_release (data); | 825 | gcry_sexp_release (data); |
@@ -858,8 +850,8 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, | |||
858 | */ | 850 | */ |
859 | int | 851 | int |
860 | GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | 852 | GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
861 | const struct GNUNET_CRYPTO_RsaSignaturePurpose | 853 | const struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose, |
862 | *purpose, struct GNUNET_CRYPTO_RsaSignature *sig) | 854 | struct GNUNET_CRYPTO_RsaSignature *sig) |
863 | { | 855 | { |
864 | gcry_sexp_t result; | 856 | gcry_sexp_t result; |
865 | gcry_sexp_t data; | 857 | gcry_sexp_t data; |
@@ -886,9 +878,9 @@ GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | |||
886 | GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "s")); | 878 | GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "s")); |
887 | gcry_sexp_release (result); | 879 | gcry_sexp_release (result); |
888 | ssize = sizeof (struct GNUNET_CRYPTO_RsaSignature); | 880 | ssize = sizeof (struct GNUNET_CRYPTO_RsaSignature); |
889 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, | 881 | GNUNET_assert (0 == |
890 | (unsigned char *) sig, ssize, &ssize, | 882 | gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) sig, ssize, |
891 | rval)); | 883 | &ssize, rval)); |
892 | gcry_mpi_release (rval); | 884 | gcry_mpi_release (rval); |
893 | adjust (sig->sig, ssize, sizeof (struct GNUNET_CRYPTO_RsaSignature)); | 885 | adjust (sig->sig, ssize, sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
894 | return GNUNET_OK; | 886 | return GNUNET_OK; |
@@ -927,9 +919,9 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose, | |||
927 | return GNUNET_SYSERR; /* purpose mismatch */ | 919 | return GNUNET_SYSERR; /* purpose mismatch */ |
928 | GNUNET_CRYPTO_hash (validate, ntohl (validate->size), &hc); | 920 | GNUNET_CRYPTO_hash (validate, ntohl (validate->size), &hc); |
929 | size = sizeof (struct GNUNET_CRYPTO_RsaSignature); | 921 | size = sizeof (struct GNUNET_CRYPTO_RsaSignature); |
930 | GNUNET_assert (0 == gcry_mpi_scan (&val, | 922 | GNUNET_assert (0 == |
931 | GCRYMPI_FMT_USG, | 923 | gcry_mpi_scan (&val, GCRYMPI_FMT_USG, |
932 | (const unsigned char *) sig, size, &size)); | 924 | (const unsigned char *) sig, size, &size)); |
933 | GNUNET_assert (0 == | 925 | GNUNET_assert (0 == |
934 | gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))", | 926 | gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))", |
935 | val)); | 927 | val)); |
@@ -937,9 +929,10 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose, | |||
937 | bufSize = strlen (FORMATSTRING) + 1; | 929 | bufSize = strlen (FORMATSTRING) + 1; |
938 | buff = GNUNET_malloc (bufSize); | 930 | buff = GNUNET_malloc (bufSize); |
939 | memcpy (buff, FORMATSTRING, bufSize); | 931 | memcpy (buff, FORMATSTRING, bufSize); |
940 | memcpy (&buff[strlen (FORMATSTRING) - | 932 | memcpy (&buff |
941 | strlen | 933 | [strlen (FORMATSTRING) - |
942 | ("0123456789012345678901234567890123456789012345678901234567890123))")], | 934 | strlen |
935 | ("0123456789012345678901234567890123456789012345678901234567890123))")], | ||
943 | &hc, sizeof (GNUNET_HashCode)); | 936 | &hc, sizeof (GNUNET_HashCode)); |
944 | GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); | 937 | GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); |
945 | GNUNET_free (buff); | 938 | GNUNET_free (buff); |
@@ -957,8 +950,8 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose, | |||
957 | if (rc) | 950 | if (rc) |
958 | { | 951 | { |
959 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 952 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
960 | _("RSA signature verification failed at %s:%d: %s\n"), | 953 | _("RSA signature verification failed at %s:%d: %s\n"), __FILE__, |
961 | __FILE__, __LINE__, gcry_strerror (rc)); | 954 | __LINE__, gcry_strerror (rc)); |
962 | return GNUNET_SYSERR; | 955 | return GNUNET_SYSERR; |
963 | } | 956 | } |
964 | return GNUNET_OK; | 957 | return GNUNET_OK; |