diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-15 12:15:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-15 12:15:58 +0000 |
commit | c0e6f18c0ebe60bff0437740d64a7de43b9304ca (patch) | |
tree | 77024e5403213727b5f4acbbb5c52266f23b3ba5 /src/util/crypto_rsa.c | |
parent | 55d612a4f2b68911b472d10bb7efd50d8740fe6e (diff) |
-adding cmp functions for RSA public keys and sigs
Diffstat (limited to 'src/util/crypto_rsa.c')
-rw-r--r-- | src/util/crypto_rsa.c | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 47aa798e73..9896d8dcea 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, /** + * Compare the values of two signatures. + * + * @param s1 one signature + * @param s2 the other signature + * @return 0 if the two are equal + */ +int +GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_rsa_Signature *s1, + struct GNUNET_CRYPTO_rsa_Signature *s2) +{ + char *b1; + char *b2; + size_t z1; + size_t z2; + int ret; + + z1 = GNUNET_CRYPTO_rsa_signature_encode (s1, + &b1); + z2 = GNUNET_CRYPTO_rsa_signature_encode (s2, + &b2); + if (z1 != z2) + ret = 1; + else + ret = memcmp (b1, + b2, + z1); + GNUNET_free (b1); + GNUNET_free (b2); + return ret; +} + + +/** + * Compare the values of two public keys. + * + * @param p1 one public key + * @param p2 the other public key + * @return 0 if the two are equal + */ +int +GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_rsa_PublicKey *p1, + struct GNUNET_CRYPTO_rsa_PublicKey *p2) +{ + char *b1; + char *b2; + size_t z1; + size_t z2; + int ret; + + z1 = GNUNET_CRYPTO_rsa_public_key_encode (p1, + &b1); + z2 = GNUNET_CRYPTO_rsa_public_key_encode (p2, + &b2); + if (z1 != z2) + ret = 1; + else + ret = memcmp (b1, + b2, + z1); + GNUNET_free (b1); + GNUNET_free (b2); + return ret; +} + + +/** * Destroy a blinding key * * @param bkey the blinding key to destroy @@ -618,8 +684,8 @@ data_to_sexp (const void *ptr, size_t size) */ struct GNUNET_CRYPTO_rsa_Signature * GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_rsa_PrivateKey *key, - const void *msg, - size_t msg_len) + const void *msg, + size_t msg_len) { struct GNUNET_CRYPTO_rsa_Signature *sig; gcry_sexp_t result; @@ -664,7 +730,7 @@ GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_rsa_Signature *sig) */ size_t GNUNET_CRYPTO_rsa_signature_encode (const struct GNUNET_CRYPTO_rsa_Signature *sig, - char **buffer) + char **buffer) { size_t n; char *b; |