diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-03-21 13:41:12 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-03-21 13:41:12 +0000 |
commit | 1733de7305720882b8745e82b51b6ff47c10099e (patch) | |
tree | df9199b0e8670b089ead17186b191b80629bda8f /src/util/crypto_rsa.c | |
parent | 60de5f48cbfc3868570284e91415ca7e06c390e1 (diff) | |
download | gnunet-1733de7305720882b8745e82b51b6ff47c10099e.tar.gz gnunet-1733de7305720882b8745e82b51b6ff47c10099e.zip |
fixing symbol naming and coding convention issues
Diffstat (limited to 'src/util/crypto_rsa.c')
-rw-r--r-- | src/util/crypto_rsa.c | 198 |
1 files changed, 104 insertions, 94 deletions
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index a14eff407..b19634ab8 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -30,7 +30,7 @@ | |||
30 | /** | 30 | /** |
31 | * The private information of an RSA key pair. | 31 | * The private information of an RSA key pair. |
32 | */ | 32 | */ |
33 | struct GNUNET_CRYPTO_rsa_PrivateKey | 33 | struct GNUNET_CRYPTO_RsaPrivateKey |
34 | { | 34 | { |
35 | /** | 35 | /** |
36 | * Libgcrypt S-expression for the RSA private key. | 36 | * Libgcrypt S-expression for the RSA private key. |
@@ -42,7 +42,7 @@ struct GNUNET_CRYPTO_rsa_PrivateKey | |||
42 | /** | 42 | /** |
43 | * The public information of an RSA key pair. | 43 | * The public information of an RSA key pair. |
44 | */ | 44 | */ |
45 | struct GNUNET_CRYPTO_rsa_PublicKey | 45 | struct GNUNET_CRYPTO_RsaPublicKey |
46 | { | 46 | { |
47 | /** | 47 | /** |
48 | * Libgcrypt S-expression for the RSA public key. | 48 | * Libgcrypt S-expression for the RSA public key. |
@@ -54,7 +54,7 @@ struct GNUNET_CRYPTO_rsa_PublicKey | |||
54 | /** | 54 | /** |
55 | * @brief an RSA signature | 55 | * @brief an RSA signature |
56 | */ | 56 | */ |
57 | struct GNUNET_CRYPTO_rsa_Signature | 57 | struct GNUNET_CRYPTO_RsaSignature |
58 | { | 58 | { |
59 | /** | 59 | /** |
60 | * Libgcrypt S-expression for the RSA signature. | 60 | * Libgcrypt S-expression for the RSA signature. |
@@ -140,10 +140,10 @@ key_from_sexp (gcry_mpi_t *array, | |||
140 | * @param len length of the key in bits (i.e. 2048) | 140 | * @param len length of the key in bits (i.e. 2048) |
141 | * @return fresh private key | 141 | * @return fresh private key |
142 | */ | 142 | */ |
143 | struct GNUNET_CRYPTO_rsa_PrivateKey * | 143 | struct GNUNET_CRYPTO_RsaPrivateKey * |
144 | GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) | 144 | GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) |
145 | { | 145 | { |
146 | struct GNUNET_CRYPTO_rsa_PrivateKey *ret; | 146 | struct GNUNET_CRYPTO_RsaPrivateKey *ret; |
147 | gcry_sexp_t s_key; | 147 | gcry_sexp_t s_key; |
148 | gcry_sexp_t s_keyparam; | 148 | gcry_sexp_t s_keyparam; |
149 | 149 | ||
@@ -160,7 +160,7 @@ GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) | |||
160 | GNUNET_assert (0 == | 160 | GNUNET_assert (0 == |
161 | gcry_pk_testkey (s_key)); | 161 | gcry_pk_testkey (s_key)); |
162 | #endif | 162 | #endif |
163 | ret = GNUNET_new (struct GNUNET_CRYPTO_rsa_PrivateKey); | 163 | ret = GNUNET_new (struct GNUNET_CRYPTO_RsaPrivateKey); |
164 | ret->sexp = s_key; | 164 | ret->sexp = s_key; |
165 | return ret; | 165 | return ret; |
166 | } | 166 | } |
@@ -172,7 +172,7 @@ GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) | |||
172 | * @param key pointer to the memory to free | 172 | * @param key pointer to the memory to free |
173 | */ | 173 | */ |
174 | void | 174 | void |
175 | GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_rsa_PrivateKey *key) | 175 | GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key) |
176 | { | 176 | { |
177 | gcry_sexp_release (key->sexp); | 177 | gcry_sexp_release (key->sexp); |
178 | GNUNET_free (key); | 178 | GNUNET_free (key); |
@@ -188,7 +188,7 @@ GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_rsa_PrivateKey *key) | |||
188 | * @return size of memory allocated in @a buffer | 188 | * @return size of memory allocated in @a buffer |
189 | */ | 189 | */ |
190 | size_t | 190 | size_t |
191 | GNUNET_CRYPTO_rsa_private_key_encode (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, | 191 | GNUNET_CRYPTO_rsa_private_key_encode (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
192 | char **buffer) | 192 | char **buffer) |
193 | { | 193 | { |
194 | size_t n; | 194 | size_t n; |
@@ -217,12 +217,12 @@ GNUNET_CRYPTO_rsa_private_key_encode (const struct GNUNET_CRYPTO_rsa_PrivateKey | |||
217 | * @param len the length of the data in @a buf | 217 | * @param len the length of the data in @a buf |
218 | * @return NULL on error | 218 | * @return NULL on error |
219 | */ | 219 | */ |
220 | struct GNUNET_CRYPTO_rsa_PrivateKey * | 220 | struct GNUNET_CRYPTO_RsaPrivateKey * |
221 | GNUNET_CRYPTO_rsa_private_key_decode (const char *buf, | 221 | GNUNET_CRYPTO_rsa_private_key_decode (const char *buf, |
222 | size_t len) | 222 | size_t len) |
223 | { | 223 | { |
224 | struct GNUNET_CRYPTO_rsa_PrivateKey *key; | 224 | struct GNUNET_CRYPTO_RsaPrivateKey *key; |
225 | key = GNUNET_new (struct GNUNET_CRYPTO_rsa_PrivateKey); | 225 | key = GNUNET_new (struct GNUNET_CRYPTO_RsaPrivateKey); |
226 | if (0 != | 226 | if (0 != |
227 | gcry_sexp_new (&key->sexp, | 227 | gcry_sexp_new (&key->sexp, |
228 | buf, | 228 | buf, |
@@ -251,10 +251,10 @@ GNUNET_CRYPTO_rsa_private_key_decode (const char *buf, | |||
251 | * @param priv the private key | 251 | * @param priv the private key |
252 | * @retur NULL on error, otherwise the public key | 252 | * @retur NULL on error, otherwise the public key |
253 | */ | 253 | */ |
254 | struct GNUNET_CRYPTO_rsa_PublicKey * | 254 | struct GNUNET_CRYPTO_RsaPublicKey * |
255 | GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_rsa_PrivateKey *priv) | 255 | GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey *priv) |
256 | { | 256 | { |
257 | struct GNUNET_CRYPTO_rsa_PublicKey *pub; | 257 | struct GNUNET_CRYPTO_RsaPublicKey *pub; |
258 | gcry_mpi_t ne[2]; | 258 | gcry_mpi_t ne[2]; |
259 | int rc; | 259 | int rc; |
260 | gcry_sexp_t result; | 260 | gcry_sexp_t result; |
@@ -276,7 +276,7 @@ GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_rsa_Private | |||
276 | ne[1]); | 276 | ne[1]); |
277 | gcry_mpi_release (ne[0]); | 277 | gcry_mpi_release (ne[0]); |
278 | gcry_mpi_release (ne[1]); | 278 | gcry_mpi_release (ne[1]); |
279 | pub = GNUNET_new (struct GNUNET_CRYPTO_rsa_PublicKey); | 279 | pub = GNUNET_new (struct GNUNET_CRYPTO_RsaPublicKey); |
280 | pub->sexp = result; | 280 | pub->sexp = result; |
281 | return pub; | 281 | return pub; |
282 | } | 282 | } |
@@ -288,7 +288,7 @@ GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_rsa_Private | |||
288 | * @param key pointer to the memory to free | 288 | * @param key pointer to the memory to free |
289 | */ | 289 | */ |
290 | void | 290 | void |
291 | GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_rsa_PublicKey *key) | 291 | GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_RsaPublicKey *key) |
292 | { | 292 | { |
293 | gcry_sexp_release (key->sexp); | 293 | gcry_sexp_release (key->sexp); |
294 | GNUNET_free (key); | 294 | GNUNET_free (key); |
@@ -304,7 +304,7 @@ GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_rsa_PublicKey *key) | |||
304 | * @return size of memory allocated in @a buffer | 304 | * @return size of memory allocated in @a buffer |
305 | */ | 305 | */ |
306 | size_t | 306 | size_t |
307 | GNUNET_CRYPTO_rsa_public_key_encode (const struct GNUNET_CRYPTO_rsa_PublicKey *key, | 307 | GNUNET_CRYPTO_rsa_public_key_encode (const struct GNUNET_CRYPTO_RsaPublicKey *key, |
308 | char **buffer) | 308 | char **buffer) |
309 | { | 309 | { |
310 | size_t n; | 310 | size_t n; |
@@ -332,7 +332,7 @@ GNUNET_CRYPTO_rsa_public_key_encode (const struct GNUNET_CRYPTO_rsa_PublicKey *k | |||
332 | * @param hc where to store the hash code | 332 | * @param hc where to store the hash code |
333 | */ | 333 | */ |
334 | void | 334 | void |
335 | GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_rsa_PublicKey *key, | 335 | GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, |
336 | struct GNUNET_HashCode *hc) | 336 | struct GNUNET_HashCode *hc) |
337 | { | 337 | { |
338 | char *buf; | 338 | char *buf; |
@@ -355,15 +355,15 @@ GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_rsa_PublicKey *key | |||
355 | * @param len the length of the data in @a buf | 355 | * @param len the length of the data in @a buf |
356 | * @return NULL on error | 356 | * @return NULL on error |
357 | */ | 357 | */ |
358 | struct GNUNET_CRYPTO_rsa_PublicKey * | 358 | struct GNUNET_CRYPTO_RsaPublicKey * |
359 | GNUNET_CRYPTO_rsa_public_key_decode (const char *buf, | 359 | GNUNET_CRYPTO_rsa_public_key_decode (const char *buf, |
360 | size_t len) | 360 | size_t len) |
361 | { | 361 | { |
362 | struct GNUNET_CRYPTO_rsa_PublicKey *key; | 362 | struct GNUNET_CRYPTO_RsaPublicKey *key; |
363 | gcry_mpi_t n; | 363 | gcry_mpi_t n; |
364 | int ret; | 364 | int ret; |
365 | 365 | ||
366 | key = GNUNET_new (struct GNUNET_CRYPTO_rsa_PublicKey); | 366 | key = GNUNET_new (struct GNUNET_CRYPTO_RsaPublicKey); |
367 | if (0 != | 367 | if (0 != |
368 | gcry_sexp_new (&key->sexp, | 368 | gcry_sexp_new (&key->sexp, |
369 | buf, | 369 | buf, |
@@ -435,8 +435,8 @@ GNUNET_CRYPTO_rsa_blinding_key_cmp (struct GNUNET_CRYPTO_rsa_BlindingKey *b1, | |||
435 | * @return 0 if the two are equal | 435 | * @return 0 if the two are equal |
436 | */ | 436 | */ |
437 | int | 437 | int |
438 | GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_rsa_Signature *s1, | 438 | GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1, |
439 | struct GNUNET_CRYPTO_rsa_Signature *s2) | 439 | struct GNUNET_CRYPTO_RsaSignature *s2) |
440 | { | 440 | { |
441 | char *b1; | 441 | char *b1; |
442 | char *b2; | 442 | char *b2; |
@@ -468,8 +468,8 @@ GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_rsa_Signature *s1, | |||
468 | * @return 0 if the two are equal | 468 | * @return 0 if the two are equal |
469 | */ | 469 | */ |
470 | int | 470 | int |
471 | GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_rsa_PublicKey *p1, | 471 | GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1, |
472 | struct GNUNET_CRYPTO_rsa_PublicKey *p2) | 472 | struct GNUNET_CRYPTO_RsaPublicKey *p2) |
473 | { | 473 | { |
474 | char *b1; | 474 | char *b1; |
475 | char *b2; | 475 | char *b2; |
@@ -501,8 +501,8 @@ GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_rsa_PublicKey *p1, | |||
501 | * @return 0 if the two are equal | 501 | * @return 0 if the two are equal |
502 | */ | 502 | */ |
503 | int | 503 | int |
504 | GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_rsa_PrivateKey *p1, | 504 | GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1, |
505 | struct GNUNET_CRYPTO_rsa_PrivateKey *p2) | 505 | struct GNUNET_CRYPTO_RsaPrivateKey *p2) |
506 | { | 506 | { |
507 | char *b1; | 507 | char *b1; |
508 | char *b2; | 508 | char *b2; |
@@ -533,7 +533,7 @@ GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_rsa_PrivateKey *p1, | |||
533 | * @return length of the key in bits | 533 | * @return length of the key in bits |
534 | */ | 534 | */ |
535 | unsigned int | 535 | unsigned int |
536 | GNUNET_CRYPTO_rsa_public_key_len (const struct GNUNET_CRYPTO_rsa_PublicKey *key) | 536 | GNUNET_CRYPTO_rsa_public_key_len (const struct GNUNET_CRYPTO_RsaPublicKey *key) |
537 | { | 537 | { |
538 | gcry_mpi_t n; | 538 | gcry_mpi_t n; |
539 | int ret; | 539 | int ret; |
@@ -645,27 +645,32 @@ GNUNET_CRYPTO_rsa_blinding_key_decode (const char *buf, | |||
645 | 645 | ||
646 | 646 | ||
647 | /** | 647 | /** |
648 | * Computes a full domain hash seeded by the given public key. | 648 | * Computes a full domain hash seeded by the given public key. |
649 | * This gives a measure of provable security to the Taler exchange | 649 | * This gives a measure of provable security to the Taler exchange |
650 | * against one-more forgery attacks. See: | 650 | * against one-more forgery attacks. See: |
651 | * https://eprint.iacr.org/2001/002.pdf | 651 | * https://eprint.iacr.org/2001/002.pdf |
652 | * http://www.di.ens.fr/~pointche/Documents/Papers/2001_fcA.pdf | 652 | * http://www.di.ens.fr/~pointche/Documents/Papers/2001_fcA.pdf |
653 | * | 653 | * |
654 | * @param[out] r MPI value set to the FDH | ||
654 | * @param hash initial hash of the message to sign | 655 | * @param hash initial hash of the message to sign |
655 | * @param pkey the public key of the signer | 656 | * @param pkey the public key of the signer |
657 | * @param rsize FIXME JEFF | ||
656 | * @return libgcrypt error that to represent an allocation failure | 658 | * @return libgcrypt error that to represent an allocation failure |
657 | */ | 659 | */ |
658 | gcry_error_t | 660 | gcry_error_t |
659 | rsa_full_domain_hash (gcry_mpi_t *r, | 661 | rsa_full_domain_hash (gcry_mpi_t *r, |
660 | const struct GNUNET_HashCode *hash, | 662 | const struct GNUNET_HashCode *hash, |
661 | const struct GNUNET_CRYPTO_rsa_PublicKey *pkey, | 663 | const struct GNUNET_CRYPTO_RsaPublicKey *pkey, |
662 | size_t *rsize) | 664 | size_t *rsize) |
663 | { | 665 | { |
664 | int i,nbits,nhashes; | 666 | unsigned int i; |
667 | unsigned int nbits; | ||
668 | unsigned int nhashes; | ||
665 | gcry_error_t rc; | 669 | gcry_error_t rc; |
666 | char *buf; | 670 | char *buf; |
667 | size_t buf_len; | 671 | size_t buf_len; |
668 | gcry_md_hd_t h,h0; | 672 | gcry_md_hd_t h; |
673 | gcry_md_hd_t h0; | ||
669 | struct GNUNET_HashCode *hs; | 674 | struct GNUNET_HashCode *hs; |
670 | 675 | ||
671 | /* Uncomment the following to debug without using the full domain hash */ | 676 | /* Uncomment the following to debug without using the full domain hash */ |
@@ -675,60 +680,64 @@ rsa_full_domain_hash (gcry_mpi_t *r, | |||
675 | (const unsigned char *)hash, | 680 | (const unsigned char *)hash, |
676 | sizeof(struct GNUNET_HashCode), | 681 | sizeof(struct GNUNET_HashCode), |
677 | rsize); | 682 | rsize); |
678 | return rc; | 683 | return rc; |
679 | */ | 684 | */ |
680 | 685 | ||
681 | nbits = GNUNET_CRYPTO_rsa_public_key_len (pkey); | 686 | nbits = GNUNET_CRYPTO_rsa_public_key_len (pkey); |
682 | // calls gcry_mpi_get_nbits(.. pkey->sexp ..) | ||
683 | if (nbits < 512) | 687 | if (nbits < 512) |
684 | nbits = 512; | 688 | nbits = 512; |
685 | 689 | ||
686 | // Already almost an HMAC since we consume a hash, so no GCRY_MD_FLAG_HMAC. | 690 | /* Already almost an HMAC since we consume a hash, so no GCRY_MD_FLAG_HMAC. */ |
687 | rc = gcry_md_open (&h,GCRY_MD_SHA512,0); | 691 | rc = gcry_md_open (&h, GCRY_MD_SHA512, 0); |
688 | if (0 != rc) return rc; | 692 | if (0 != rc) |
693 | return rc; | ||
689 | 694 | ||
690 | // We seed with the public denomination key as a homage to RSA-PSS by | 695 | // We seed with the public denomination key as a homage to RSA-PSS by |
691 | // Mihir Bellare and Phillip Rogaway. Doing this lowers the degree | 696 | // Mihir Bellare and Phillip Rogaway. Doing this lowers the degree |
692 | // of the hypothetical polyomial-time attack on RSA-KTI created by a | 697 | // of the hypothetical polyomial-time attack on RSA-KTI created by a |
693 | // polynomial-time one-more forgary attack. Yey seeding! | 698 | // polynomial-time one-more forgary attack. Yey seeding! |
694 | buf_len = GNUNET_CRYPTO_rsa_public_key_encode (pkey, &buf); | 699 | buf_len = GNUNET_CRYPTO_rsa_public_key_encode (pkey, &buf); |
695 | gcry_md_write (h, buf,buf_len); | 700 | gcry_md_write (h, buf, buf_len); |
696 | GNUNET_free (buf); | 701 | GNUNET_free (buf); |
697 | 702 | ||
698 | nhashes = (nbits-1) / (8 * sizeof(struct GNUNET_HashCode)) + 1; | 703 | nhashes = (nbits-1) / (8 * sizeof(struct GNUNET_HashCode)) + 1; |
699 | hs = (struct GNUNET_HashCode *)GNUNET_malloc (nhashes * sizeof(struct GNUNET_HashCode)); | 704 | hs = GNUNET_new_array (nhashes, |
700 | for (i=0; i<nhashes; i++) | 705 | struct GNUNET_HashCode); |
706 | for (i=0; i<nhashes; i++) | ||
701 | { | 707 | { |
702 | gcry_md_write (h, hash, sizeof(struct GNUNET_HashCode)); | 708 | gcry_md_write (h, hash, sizeof(struct GNUNET_HashCode)); |
703 | rc = gcry_md_copy (&h0, h); | 709 | rc = gcry_md_copy (&h0, h); |
704 | if (0 != rc) break; | 710 | if (0 != rc) |
711 | { | ||
712 | gcry_md_close (h0); | ||
713 | break; | ||
714 | } | ||
705 | gcry_md_putc (h0, i % 256); | 715 | gcry_md_putc (h0, i % 256); |
706 | // gcry_md_final (&h0); | 716 | memcpy (&hs[i], |
707 | memcpy (&hs[i], | 717 | gcry_md_read (h0, GCRY_MD_SHA512), |
708 | gcry_md_read (h0,GCRY_MD_SHA512), | ||
709 | sizeof(struct GNUNET_HashCode)); | 718 | sizeof(struct GNUNET_HashCode)); |
710 | gcry_md_close (h0); | 719 | gcry_md_close (h0); |
711 | } | 720 | } |
712 | gcry_md_close (h); | 721 | gcry_md_close (h); |
713 | if (0 != rc) { | 722 | if (0 != rc) |
723 | { | ||
714 | GNUNET_free (hs); | 724 | GNUNET_free (hs); |
715 | return rc; | 725 | return rc; |
716 | } | 726 | } |
717 | 727 | ||
718 | rc = gcry_mpi_scan (r, | 728 | rc = gcry_mpi_scan (r, |
719 | GCRYMPI_FMT_USG, | 729 | GCRYMPI_FMT_USG, |
720 | (const unsigned char *)hs, | 730 | (const unsigned char *) hs, |
721 | nhashes * sizeof(struct GNUNET_HashCode), | 731 | nhashes * sizeof(struct GNUNET_HashCode), |
722 | rsize); | 732 | rsize); |
723 | GNUNET_free (hs); | 733 | GNUNET_free (hs); |
724 | if (0 != rc) return rc; | 734 | if (0 != rc) |
735 | return rc; | ||
725 | 736 | ||
726 | // Do not allow *r to exceed n or signatures fail to verify unpredictably. | 737 | // Do not allow *r to exceed n or signatures fail to verify unpredictably. |
727 | // This happening with gcry_mpi_clear_highbit (*r, nbits-1) so maybe | 738 | // This happening with gcry_mpi_clear_highbit (*r, nbits-1) so maybe |
728 | // gcry_mpi_clear_highbit is broken, but setting the highbit sounds good. | 739 | // gcry_mpi_clear_highbit is broken, but setting the highbit sounds good. |
729 | // (void) fprintf (stderr, "%d %d %d",nbits,nhashes, gcry_mpi_get_nbits(*r)); | ||
730 | gcry_mpi_set_highbit (*r, nbits-2); | 740 | gcry_mpi_set_highbit (*r, nbits-2); |
731 | // (void) fprintf (stderr, " %d\n",gcry_mpi_get_nbits(*r)); | ||
732 | return rc; | 741 | return rc; |
733 | } | 742 | } |
734 | 743 | ||
@@ -745,7 +754,7 @@ rsa_full_domain_hash (gcry_mpi_t *r, | |||
745 | size_t | 754 | size_t |
746 | GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, | 755 | GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, |
747 | struct GNUNET_CRYPTO_rsa_BlindingKey *bkey, | 756 | struct GNUNET_CRYPTO_rsa_BlindingKey *bkey, |
748 | struct GNUNET_CRYPTO_rsa_PublicKey *pkey, | 757 | struct GNUNET_CRYPTO_RsaPublicKey *pkey, |
749 | char **buffer) | 758 | char **buffer) |
750 | { | 759 | { |
751 | gcry_mpi_t data; | 760 | gcry_mpi_t data; |
@@ -767,7 +776,7 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, | |||
767 | return 0; | 776 | return 0; |
768 | } | 777 | } |
769 | 778 | ||
770 | rc = rsa_full_domain_hash(&data, hash, pkey, &rsize); | 779 | rc = rsa_full_domain_hash (&data, hash, pkey, &rsize); |
771 | if (0 != rc) // Allocation error in libgcrypt | 780 | if (0 != rc) // Allocation error in libgcrypt |
772 | { | 781 | { |
773 | GNUNET_break (0); | 782 | GNUNET_break (0); |
@@ -824,13 +833,14 @@ mpi_to_sexp (gcry_mpi_t value) | |||
824 | * @param value the MPI to sign | 833 | * @param value the MPI to sign |
825 | * @return NULL on error, signature on success | 834 | * @return NULL on error, signature on success |
826 | */ | 835 | */ |
827 | struct GNUNET_CRYPTO_rsa_Signature * | 836 | static struct GNUNET_CRYPTO_RsaSignature * |
828 | rsa_sign_mpi (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, | 837 | rsa_sign_mpi (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
829 | gcry_mpi_t value) | 838 | gcry_mpi_t value) |
830 | { | 839 | { |
831 | struct GNUNET_CRYPTO_rsa_Signature *sig; | 840 | struct GNUNET_CRYPTO_RsaSignature *sig; |
832 | struct GNUNET_CRYPTO_rsa_PublicKey *public_key; | 841 | struct GNUNET_CRYPTO_RsaPublicKey *public_key; |
833 | gcry_sexp_t data,result; | 842 | gcry_sexp_t data; |
843 | gcry_sexp_t result; | ||
834 | 844 | ||
835 | data = mpi_to_sexp (value); | 845 | data = mpi_to_sexp (value); |
836 | gcry_mpi_release (value); | 846 | gcry_mpi_release (value); |
@@ -851,7 +861,7 @@ rsa_sign_mpi (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, | |||
851 | data, | 861 | data, |
852 | public_key->sexp)) | 862 | public_key->sexp)) |
853 | { | 863 | { |
854 | GNUNET_break (0); | 864 | GNUNET_break (0); |
855 | GNUNET_CRYPTO_rsa_public_key_free (public_key); | 865 | GNUNET_CRYPTO_rsa_public_key_free (public_key); |
856 | gcry_sexp_release (data); | 866 | gcry_sexp_release (data); |
857 | gcry_sexp_release (result); | 867 | gcry_sexp_release (result); |
@@ -861,7 +871,7 @@ rsa_sign_mpi (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, | |||
861 | 871 | ||
862 | /* return signature */ | 872 | /* return signature */ |
863 | gcry_sexp_release (data); | 873 | gcry_sexp_release (data); |
864 | sig = GNUNET_new (struct GNUNET_CRYPTO_rsa_Signature); | 874 | sig = GNUNET_new (struct GNUNET_CRYPTO_RsaSignature); |
865 | sig->sexp = result; | 875 | sig->sexp = result; |
866 | return sig; | 876 | return sig; |
867 | } | 877 | } |
@@ -875,21 +885,21 @@ rsa_sign_mpi (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, | |||
875 | * @param msg_len number of bytes in @a msg to sign | 885 | * @param msg_len number of bytes in @a msg to sign |
876 | * @return NULL on error, signature on success | 886 | * @return NULL on error, signature on success |
877 | */ | 887 | */ |
878 | struct GNUNET_CRYPTO_rsa_Signature * | 888 | struct GNUNET_CRYPTO_RsaSignature * |
879 | GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, | 889 | GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
880 | const void *msg, | 890 | const void *msg, |
881 | size_t msg_len) | 891 | size_t msg_len) |
882 | { | 892 | { |
883 | gcry_mpi_t v = NULL; | 893 | gcry_mpi_t v = NULL; |
884 | 894 | ||
885 | GNUNET_assert (0 == | 895 | GNUNET_assert (0 == |
886 | gcry_mpi_scan (&v, | 896 | gcry_mpi_scan (&v, |
887 | GCRYMPI_FMT_USG, | 897 | GCRYMPI_FMT_USG, |
888 | msg, | 898 | msg, |
889 | msg_len, | 899 | msg_len, |
890 | NULL)); | 900 | NULL)); |
891 | 901 | ||
892 | return rsa_sign_mpi (key,v); | 902 | return rsa_sign_mpi (key, v); |
893 | } | 903 | } |
894 | 904 | ||
895 | 905 | ||
@@ -900,11 +910,11 @@ GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, | |||
900 | * @param hash the hash of the message to sign | 910 | * @param hash the hash of the message to sign |
901 | * @return NULL on error, signature on success | 911 | * @return NULL on error, signature on success |
902 | */ | 912 | */ |
903 | struct GNUNET_CRYPTO_rsa_Signature * | 913 | struct GNUNET_CRYPTO_RsaSignature * |
904 | GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, | 914 | GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
905 | const struct GNUNET_HashCode *hash) | 915 | const struct GNUNET_HashCode *hash) |
906 | { | 916 | { |
907 | struct GNUNET_CRYPTO_rsa_PublicKey *pkey; | 917 | struct GNUNET_CRYPTO_RsaPublicKey *pkey; |
908 | gcry_mpi_t v = NULL; | 918 | gcry_mpi_t v = NULL; |
909 | gcry_error_t rc; | 919 | gcry_error_t rc; |
910 | 920 | ||
@@ -923,7 +933,7 @@ GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, | |||
923 | * @param sig memory to freee | 933 | * @param sig memory to freee |
924 | */ | 934 | */ |
925 | void | 935 | void |
926 | GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_rsa_Signature *sig) | 936 | GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig) |
927 | { | 937 | { |
928 | gcry_sexp_release (sig->sexp); | 938 | gcry_sexp_release (sig->sexp); |
929 | GNUNET_free (sig); | 939 | GNUNET_free (sig); |
@@ -938,7 +948,7 @@ GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_rsa_Signature *sig) | |||
938 | * @return size of memory allocated in @a buffer | 948 | * @return size of memory allocated in @a buffer |
939 | */ | 949 | */ |
940 | size_t | 950 | size_t |
941 | GNUNET_CRYPTO_rsa_signature_encode (const struct GNUNET_CRYPTO_rsa_Signature *sig, | 951 | GNUNET_CRYPTO_rsa_signature_encode (const struct GNUNET_CRYPTO_RsaSignature *sig, |
942 | char **buffer) | 952 | char **buffer) |
943 | { | 953 | { |
944 | size_t n; | 954 | size_t n; |
@@ -967,15 +977,15 @@ GNUNET_CRYPTO_rsa_signature_encode (const struct GNUNET_CRYPTO_rsa_Signature *si | |||
967 | * @param len the length of the data in @a buf | 977 | * @param len the length of the data in @a buf |
968 | * @return NULL on error | 978 | * @return NULL on error |
969 | */ | 979 | */ |
970 | struct GNUNET_CRYPTO_rsa_Signature * | 980 | struct GNUNET_CRYPTO_RsaSignature * |
971 | GNUNET_CRYPTO_rsa_signature_decode (const char *buf, | 981 | GNUNET_CRYPTO_rsa_signature_decode (const char *buf, |
972 | size_t len) | 982 | size_t len) |
973 | { | 983 | { |
974 | struct GNUNET_CRYPTO_rsa_Signature *sig; | 984 | struct GNUNET_CRYPTO_RsaSignature *sig; |
975 | int ret; | 985 | int ret; |
976 | gcry_mpi_t s; | 986 | gcry_mpi_t s; |
977 | 987 | ||
978 | sig = GNUNET_new (struct GNUNET_CRYPTO_rsa_Signature); | 988 | sig = GNUNET_new (struct GNUNET_CRYPTO_RsaSignature); |
979 | if (0 != | 989 | if (0 != |
980 | gcry_sexp_new (&sig->sexp, | 990 | gcry_sexp_new (&sig->sexp, |
981 | buf, | 991 | buf, |
@@ -1009,10 +1019,10 @@ GNUNET_CRYPTO_rsa_signature_decode (const char *buf, | |||
1009 | * @param key the public key to duplicate | 1019 | * @param key the public key to duplicate |
1010 | * @return the duplicate key; NULL upon error | 1020 | * @return the duplicate key; NULL upon error |
1011 | */ | 1021 | */ |
1012 | struct GNUNET_CRYPTO_rsa_PublicKey * | 1022 | struct GNUNET_CRYPTO_RsaPublicKey * |
1013 | GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_rsa_PublicKey *key) | 1023 | GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key) |
1014 | { | 1024 | { |
1015 | struct GNUNET_CRYPTO_rsa_PublicKey *dup; | 1025 | struct GNUNET_CRYPTO_RsaPublicKey *dup; |
1016 | gcry_sexp_t dup_sexp; | 1026 | gcry_sexp_t dup_sexp; |
1017 | size_t erroff; | 1027 | size_t erroff; |
1018 | 1028 | ||
@@ -1022,7 +1032,7 @@ GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_rsa_PublicKey *key) | |||
1022 | gcry_sexp_release (dup_sexp); | 1032 | gcry_sexp_release (dup_sexp); |
1023 | /* copy the sexp */ | 1033 | /* copy the sexp */ |
1024 | GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp)); | 1034 | GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp)); |
1025 | dup = GNUNET_new (struct GNUNET_CRYPTO_rsa_PublicKey); | 1035 | dup = GNUNET_new (struct GNUNET_CRYPTO_RsaPublicKey); |
1026 | dup->sexp = dup_sexp; | 1036 | dup->sexp = dup_sexp; |
1027 | return dup; | 1037 | return dup; |
1028 | } | 1038 | } |
@@ -1038,17 +1048,17 @@ GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_rsa_PublicKey *key) | |||
1038 | * @param pkey the public key of the signer | 1048 | * @param pkey the public key of the signer |
1039 | * @return unblinded signature on success, NULL on error | 1049 | * @return unblinded signature on success, NULL on error |
1040 | */ | 1050 | */ |
1041 | struct GNUNET_CRYPTO_rsa_Signature * | 1051 | struct GNUNET_CRYPTO_RsaSignature * |
1042 | GNUNET_CRYPTO_rsa_unblind (struct GNUNET_CRYPTO_rsa_Signature *sig, | 1052 | GNUNET_CRYPTO_rsa_unblind (struct GNUNET_CRYPTO_RsaSignature *sig, |
1043 | struct GNUNET_CRYPTO_rsa_BlindingKey *bkey, | 1053 | struct GNUNET_CRYPTO_rsa_BlindingKey *bkey, |
1044 | struct GNUNET_CRYPTO_rsa_PublicKey *pkey) | 1054 | struct GNUNET_CRYPTO_RsaPublicKey *pkey) |
1045 | { | 1055 | { |
1046 | gcry_mpi_t n; | 1056 | gcry_mpi_t n; |
1047 | gcry_mpi_t s; | 1057 | gcry_mpi_t s; |
1048 | gcry_mpi_t r_inv; | 1058 | gcry_mpi_t r_inv; |
1049 | gcry_mpi_t ubsig; | 1059 | gcry_mpi_t ubsig; |
1050 | int ret; | 1060 | int ret; |
1051 | struct GNUNET_CRYPTO_rsa_Signature *sret; | 1061 | struct GNUNET_CRYPTO_RsaSignature *sret; |
1052 | 1062 | ||
1053 | ret = key_from_sexp (&n, pkey->sexp, "public-key", "n"); | 1063 | ret = key_from_sexp (&n, pkey->sexp, "public-key", "n"); |
1054 | if (0 != ret) | 1064 | if (0 != ret) |
@@ -1085,7 +1095,7 @@ GNUNET_CRYPTO_rsa_unblind (struct GNUNET_CRYPTO_rsa_Signature *sig, | |||
1085 | gcry_mpi_release (r_inv); | 1095 | gcry_mpi_release (r_inv); |
1086 | gcry_mpi_release (s); | 1096 | gcry_mpi_release (s); |
1087 | 1097 | ||
1088 | sret = GNUNET_new (struct GNUNET_CRYPTO_rsa_Signature); | 1098 | sret = GNUNET_new (struct GNUNET_CRYPTO_RsaSignature); |
1089 | GNUNET_assert (0 == | 1099 | GNUNET_assert (0 == |
1090 | gcry_sexp_build (&sret->sexp, | 1100 | gcry_sexp_build (&sret->sexp, |
1091 | NULL, | 1101 | NULL, |
@@ -1107,8 +1117,8 @@ GNUNET_CRYPTO_rsa_unblind (struct GNUNET_CRYPTO_rsa_Signature *sig, | |||
1107 | */ | 1117 | */ |
1108 | int | 1118 | int |
1109 | GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, | 1119 | GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, |
1110 | const struct GNUNET_CRYPTO_rsa_Signature *sig, | 1120 | const struct GNUNET_CRYPTO_RsaSignature *sig, |
1111 | const struct GNUNET_CRYPTO_rsa_PublicKey *pkey) | 1121 | const struct GNUNET_CRYPTO_RsaPublicKey *pkey) |
1112 | { | 1122 | { |
1113 | gcry_sexp_t data; | 1123 | gcry_sexp_t data; |
1114 | gcry_mpi_t r; | 1124 | gcry_mpi_t r; |
@@ -1142,10 +1152,10 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, | |||
1142 | * @param key the private key to duplicate | 1152 | * @param key the private key to duplicate |
1143 | * @return the duplicate key; NULL upon error | 1153 | * @return the duplicate key; NULL upon error |
1144 | */ | 1154 | */ |
1145 | struct GNUNET_CRYPTO_rsa_PrivateKey * | 1155 | struct GNUNET_CRYPTO_RsaPrivateKey * |
1146 | GNUNET_CRYPTO_rsa_private_key_dup (const struct GNUNET_CRYPTO_rsa_PrivateKey *key) | 1156 | GNUNET_CRYPTO_rsa_private_key_dup (const struct GNUNET_CRYPTO_RsaPrivateKey *key) |
1147 | { | 1157 | { |
1148 | struct GNUNET_CRYPTO_rsa_PrivateKey *dup; | 1158 | struct GNUNET_CRYPTO_RsaPrivateKey *dup; |
1149 | gcry_sexp_t dup_sexp; | 1159 | gcry_sexp_t dup_sexp; |
1150 | size_t erroff; | 1160 | size_t erroff; |
1151 | 1161 | ||
@@ -1155,7 +1165,7 @@ GNUNET_CRYPTO_rsa_private_key_dup (const struct GNUNET_CRYPTO_rsa_PrivateKey *ke | |||
1155 | gcry_sexp_release (dup_sexp); | 1165 | gcry_sexp_release (dup_sexp); |
1156 | /* copy the sexp */ | 1166 | /* copy the sexp */ |
1157 | GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp)); | 1167 | GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp)); |
1158 | dup = GNUNET_new (struct GNUNET_CRYPTO_rsa_PrivateKey); | 1168 | dup = GNUNET_new (struct GNUNET_CRYPTO_RsaPrivateKey); |
1159 | dup->sexp = dup_sexp; | 1169 | dup->sexp = dup_sexp; |
1160 | return dup; | 1170 | return dup; |
1161 | } | 1171 | } |
@@ -1167,10 +1177,10 @@ GNUNET_CRYPTO_rsa_private_key_dup (const struct GNUNET_CRYPTO_rsa_PrivateKey *ke | |||
1167 | * @param key the private key to duplicate | 1177 | * @param key the private key to duplicate |
1168 | * @return the duplicate key; NULL upon error | 1178 | * @return the duplicate key; NULL upon error |
1169 | */ | 1179 | */ |
1170 | struct GNUNET_CRYPTO_rsa_Signature * | 1180 | struct GNUNET_CRYPTO_RsaSignature * |
1171 | GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_rsa_Signature *sig) | 1181 | GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig) |
1172 | { | 1182 | { |
1173 | struct GNUNET_CRYPTO_rsa_Signature *dup; | 1183 | struct GNUNET_CRYPTO_RsaSignature *dup; |
1174 | gcry_sexp_t dup_sexp; | 1184 | gcry_sexp_t dup_sexp; |
1175 | size_t erroff; | 1185 | size_t erroff; |
1176 | gcry_mpi_t s; | 1186 | gcry_mpi_t s; |
@@ -1184,7 +1194,7 @@ GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_rsa_Signature *sig) | |||
1184 | gcry_mpi_release (s); | 1194 | gcry_mpi_release (s); |
1185 | /* copy the sexp */ | 1195 | /* copy the sexp */ |
1186 | GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", sig->sexp)); | 1196 | GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", sig->sexp)); |
1187 | dup = GNUNET_new (struct GNUNET_CRYPTO_rsa_Signature); | 1197 | dup = GNUNET_new (struct GNUNET_CRYPTO_RsaSignature); |
1188 | dup->sexp = dup_sexp; | 1198 | dup->sexp = dup_sexp; |
1189 | return dup; | 1199 | return dup; |
1190 | } | 1200 | } |