diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2015-05-28 19:32:22 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2015-05-28 19:32:22 +0000 |
commit | 3e558d2e9f22c96328d27e5cd35a5da3866e3543 (patch) | |
tree | 3ec605430e95e80c9568166d16d013ccffd6e528 /src/util | |
parent | 88b7ba683487b4bbb03fc4d51b5e794572816d9d (diff) | |
download | gnunet-3e558d2e9f22c96328d27e5cd35a5da3866e3543.tar.gz gnunet-3e558d2e9f22c96328d27e5cd35a5da3866e3543.zip |
Introduce function to duplicate RSA public keys
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/crypto_rsa.c | 25 | ||||
-rw-r--r-- | src/util/test_crypto_rsa.c | 6 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 2aadf2fc4..0b21b40b4 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -801,6 +801,31 @@ GNUNET_CRYPTO_rsa_signature_decode (const char *buf, | |||
801 | 801 | ||
802 | 802 | ||
803 | /** | 803 | /** |
804 | * Duplicate the given public key | ||
805 | * | ||
806 | * @param key the public key to duplicate | ||
807 | * @return the duplicate key; NULL upon error | ||
808 | */ | ||
809 | struct GNUNET_CRYPTO_rsa_PublicKey * | ||
810 | GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_rsa_PublicKey *key) | ||
811 | { | ||
812 | struct GNUNET_CRYPTO_rsa_PublicKey *dup; | ||
813 | gcry_sexp_t dup_sexp; | ||
814 | size_t erroff; | ||
815 | |||
816 | /* check if we really are exporting a public key */ | ||
817 | dup_sexp = gcry_sexp_find_token (key->sexp, "public-key", 0); | ||
818 | GNUNET_assert (NULL != dup_sexp); | ||
819 | gcry_sexp_release (dup_sexp); | ||
820 | /* copy the sexp */ | ||
821 | GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp)); | ||
822 | dup = GNUNET_new (struct GNUNET_CRYPTO_rsa_PublicKey); | ||
823 | dup->sexp = dup_sexp; | ||
824 | return dup; | ||
825 | } | ||
826 | |||
827 | |||
828 | /** | ||
804 | * Unblind a blind-signed signature. The signature should have been generated | 829 | * Unblind a blind-signed signature. The signature should have been generated |
805 | * with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with | 830 | * with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with |
806 | * #GNUNET_CRYPTO_rsa_blind(). | 831 | * #GNUNET_CRYPTO_rsa_blind(). |
diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c index b2d749ab9..20c270583 100644 --- a/src/util/test_crypto_rsa.c +++ b/src/util/test_crypto_rsa.c | |||
@@ -33,6 +33,7 @@ main (int argc, | |||
33 | unsigned char rnd_blk[RND_BLK_SIZE]; | 33 | unsigned char rnd_blk[RND_BLK_SIZE]; |
34 | struct GNUNET_CRYPTO_rsa_PrivateKey *priv; | 34 | struct GNUNET_CRYPTO_rsa_PrivateKey *priv; |
35 | struct GNUNET_CRYPTO_rsa_PublicKey *pub; | 35 | struct GNUNET_CRYPTO_rsa_PublicKey *pub; |
36 | struct GNUNET_CRYPTO_rsa_PublicKey *pub_copy; | ||
36 | struct GNUNET_CRYPTO_rsa_BlindingKey *bkey; | 37 | struct GNUNET_CRYPTO_rsa_BlindingKey *bkey; |
37 | struct GNUNET_CRYPTO_rsa_Signature *sig; | 38 | struct GNUNET_CRYPTO_rsa_Signature *sig; |
38 | struct GNUNET_CRYPTO_rsa_Signature *bsig; | 39 | struct GNUNET_CRYPTO_rsa_Signature *bsig; |
@@ -69,8 +70,10 @@ main (int argc, | |||
69 | sig = GNUNET_CRYPTO_rsa_sign (priv, | 70 | sig = GNUNET_CRYPTO_rsa_sign (priv, |
70 | &hash, | 71 | &hash, |
71 | sizeof (hash)); | 72 | sizeof (hash)); |
73 | pub_copy = GNUNET_CRYPTO_rsa_public_key_dup (pub); | ||
74 | GNUNET_assert (NULL != pub_copy); | ||
72 | GNUNET_assert (GNUNET_OK == | 75 | GNUNET_assert (GNUNET_OK == |
73 | GNUNET_CRYPTO_rsa_verify (&hash, sig, pub)); | 76 | GNUNET_CRYPTO_rsa_verify (&hash, sig, pub_copy)); |
74 | /* corrupt our hash and see if the signature is still valid */ | 77 | /* corrupt our hash and see if the signature is still valid */ |
75 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &hash, | 78 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &hash, |
76 | sizeof (struct GNUNET_HashCode)); | 79 | sizeof (struct GNUNET_HashCode)); |
@@ -101,6 +104,7 @@ main (int argc, | |||
101 | GNUNET_CRYPTO_rsa_signature_free (sig); | 104 | GNUNET_CRYPTO_rsa_signature_free (sig); |
102 | GNUNET_CRYPTO_rsa_private_key_free (priv); | 105 | GNUNET_CRYPTO_rsa_private_key_free (priv); |
103 | GNUNET_CRYPTO_rsa_public_key_free (pub); | 106 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
107 | GNUNET_CRYPTO_rsa_public_key_free (pub_copy); | ||
104 | GNUNET_CRYPTO_rsa_blinding_key_free (bkey); | 108 | GNUNET_CRYPTO_rsa_blinding_key_free (bkey); |
105 | return 0; | 109 | return 0; |
106 | } | 110 | } |