aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_rsa.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-05-15 12:15:58 +0000
committerChristian Grothoff <christian@grothoff.org>2015-05-15 12:15:58 +0000
commitc0e6f18c0ebe60bff0437740d64a7de43b9304ca (patch)
tree77024e5403213727b5f4acbbb5c52266f23b3ba5 /src/util/crypto_rsa.c
parent55d612a4f2b68911b472d10bb7efd50d8740fe6e (diff)
downloadgnunet-c0e6f18c0ebe60bff0437740d64a7de43b9304ca.tar.gz
gnunet-c0e6f18c0ebe60bff0437740d64a7de43b9304ca.zip
-adding cmp functions for RSA public keys and sigs
Diffstat (limited to 'src/util/crypto_rsa.c')
-rw-r--r--src/util/crypto_rsa.c72
1 files changed, 69 insertions, 3 deletions
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index 47aa798e7..9896d8dce 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -422,6 +422,72 @@ GNUNET_CRYPTO_rsa_blinding_key_cmp (struct GNUNET_CRYPTO_rsa_BlindingKey *b1,
422 422
423 423
424/** 424/**
425 * Compare the values of two signatures.
426 *
427 * @param s1 one signature
428 * @param s2 the other signature
429 * @return 0 if the two are equal
430 */
431int
432GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_rsa_Signature *s1,
433 struct GNUNET_CRYPTO_rsa_Signature *s2)
434{
435 char *b1;
436 char *b2;
437 size_t z1;
438 size_t z2;
439 int ret;
440
441 z1 = GNUNET_CRYPTO_rsa_signature_encode (s1,
442 &b1);
443 z2 = GNUNET_CRYPTO_rsa_signature_encode (s2,
444 &b2);
445 if (z1 != z2)
446 ret = 1;
447 else
448 ret = memcmp (b1,
449 b2,
450 z1);
451 GNUNET_free (b1);
452 GNUNET_free (b2);
453 return ret;
454}
455
456
457/**
458 * Compare the values of two public keys.
459 *
460 * @param p1 one public key
461 * @param p2 the other public key
462 * @return 0 if the two are equal
463 */
464int
465GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_rsa_PublicKey *p1,
466 struct GNUNET_CRYPTO_rsa_PublicKey *p2)
467{
468 char *b1;
469 char *b2;
470 size_t z1;
471 size_t z2;
472 int ret;
473
474 z1 = GNUNET_CRYPTO_rsa_public_key_encode (p1,
475 &b1);
476 z2 = GNUNET_CRYPTO_rsa_public_key_encode (p2,
477 &b2);
478 if (z1 != z2)
479 ret = 1;
480 else
481 ret = memcmp (b1,
482 b2,
483 z1);
484 GNUNET_free (b1);
485 GNUNET_free (b2);
486 return ret;
487}
488
489
490/**
425 * Destroy a blinding key 491 * Destroy a blinding key
426 * 492 *
427 * @param bkey the blinding key to destroy 493 * @param bkey the blinding key to destroy
@@ -618,8 +684,8 @@ data_to_sexp (const void *ptr, size_t size)
618 */ 684 */
619struct GNUNET_CRYPTO_rsa_Signature * 685struct GNUNET_CRYPTO_rsa_Signature *
620GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, 686GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_rsa_PrivateKey *key,
621 const void *msg, 687 const void *msg,
622 size_t msg_len) 688 size_t msg_len)
623{ 689{
624 struct GNUNET_CRYPTO_rsa_Signature *sig; 690 struct GNUNET_CRYPTO_rsa_Signature *sig;
625 gcry_sexp_t result; 691 gcry_sexp_t result;
@@ -664,7 +730,7 @@ GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_rsa_Signature *sig)
664 */ 730 */
665size_t 731size_t
666GNUNET_CRYPTO_rsa_signature_encode (const struct GNUNET_CRYPTO_rsa_Signature *sig, 732GNUNET_CRYPTO_rsa_signature_encode (const struct GNUNET_CRYPTO_rsa_Signature *sig,
667 char **buffer) 733 char **buffer)
668{ 734{
669 size_t n; 735 size_t n;
670 char *b; 736 char *b;