diff options
Diffstat (limited to 'src/util/crypto_rsa.c')
-rw-r--r-- | src/util/crypto_rsa.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index b8e29146f..d1ca760cf 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -494,6 +494,39 @@ GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_rsa_PublicKey *p1, | |||
494 | 494 | ||
495 | 495 | ||
496 | /** | 496 | /** |
497 | * Compare the values of two private keys. | ||
498 | * | ||
499 | * @param p1 one private key | ||
500 | * @param p2 the other private key | ||
501 | * @return 0 if the two are equal | ||
502 | */ | ||
503 | int | ||
504 | GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_rsa_PrivateKey *p1, | ||
505 | struct GNUNET_CRYPTO_rsa_PrivateKey *p2) | ||
506 | { | ||
507 | char *b1; | ||
508 | char *b2; | ||
509 | size_t z1; | ||
510 | size_t z2; | ||
511 | int ret; | ||
512 | |||
513 | z1 = GNUNET_CRYPTO_rsa_private_key_encode (p1, | ||
514 | &b1); | ||
515 | z2 = GNUNET_CRYPTO_rsa_private_key_encode (p2, | ||
516 | &b2); | ||
517 | if (z1 != z2) | ||
518 | ret = 1; | ||
519 | else | ||
520 | ret = memcmp (b1, | ||
521 | b2, | ||
522 | z1); | ||
523 | GNUNET_free (b1); | ||
524 | GNUNET_free (b2); | ||
525 | return ret; | ||
526 | } | ||
527 | |||
528 | |||
529 | /** | ||
497 | * Destroy a blinding key | 530 | * Destroy a blinding key |
498 | * | 531 | * |
499 | * @param bkey the blinding key to destroy | 532 | * @param bkey the blinding key to destroy |
@@ -929,4 +962,57 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, | |||
929 | } | 962 | } |
930 | 963 | ||
931 | 964 | ||
965 | /** | ||
966 | * Duplicate the given private key | ||
967 | * | ||
968 | * @param key the private key to duplicate | ||
969 | * @return the duplicate key; NULL upon error | ||
970 | */ | ||
971 | struct GNUNET_CRYPTO_rsa_PrivateKey * | ||
972 | GNUNET_CRYPTO_rsa_private_key_dup (const struct GNUNET_CRYPTO_rsa_PrivateKey *key) | ||
973 | { | ||
974 | struct GNUNET_CRYPTO_rsa_PrivateKey *dup; | ||
975 | gcry_sexp_t dup_sexp; | ||
976 | size_t erroff; | ||
977 | |||
978 | /* check if we really are exporting a private key */ | ||
979 | dup_sexp = gcry_sexp_find_token (key->sexp, "private-key", 0); | ||
980 | GNUNET_assert (NULL != dup_sexp); | ||
981 | gcry_sexp_release (dup_sexp); | ||
982 | /* copy the sexp */ | ||
983 | GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp)); | ||
984 | dup = GNUNET_new (struct GNUNET_CRYPTO_rsa_PrivateKey); | ||
985 | dup->sexp = dup_sexp; | ||
986 | return dup; | ||
987 | } | ||
988 | |||
989 | |||
990 | /** | ||
991 | * Duplicate the given private key | ||
992 | * | ||
993 | * @param key the private key to duplicate | ||
994 | * @return the duplicate key; NULL upon error | ||
995 | */ | ||
996 | struct GNUNET_CRYPTO_rsa_Signature * | ||
997 | GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_rsa_Signature *sig) | ||
998 | { | ||
999 | struct GNUNET_CRYPTO_rsa_Signature *dup; | ||
1000 | gcry_sexp_t dup_sexp; | ||
1001 | size_t erroff; | ||
1002 | gcry_mpi_t s; | ||
1003 | int ret; | ||
1004 | |||
1005 | /* verify that this is an RSA signature */ | ||
1006 | ret = key_from_sexp (&s, sig->sexp, "sig-val", "s"); | ||
1007 | GNUNET_assert (0 == ret); | ||
1008 | ret = key_from_sexp (&s, sig->sexp, "rsa", "s"); | ||
1009 | GNUNET_assert (0==ret); | ||
1010 | /* copy the sexp */ | ||
1011 | GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", sig->sexp)); | ||
1012 | dup = GNUNET_new (struct GNUNET_CRYPTO_rsa_Signature); | ||
1013 | dup->sexp = dup_sexp; | ||
1014 | return dup; | ||
1015 | } | ||
1016 | |||
1017 | |||
932 | /* end of util/rsa.c */ | 1018 | /* end of util/rsa.c */ |