summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-11-25 14:38:48 +0100
committerChristian Grothoff <christian@grothoff.org>2021-11-25 14:38:48 +0100
commit63854ee52ec8d24928c2346928a3dbea22ebd1fe (patch)
tree353e8104a758592004d59c1d3ecdcd0186a4fe8e
parentfff38c7f0b1bee8302b4e5689c77412d28542398 (diff)
add pk invariant check
-rw-r--r--src/include/gnunet_crypto_lib.h9
-rw-r--r--src/util/crypto_rsa.c24
2 files changed, 33 insertions, 0 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 0eb2ea8cd..edb4bb230 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -2216,6 +2216,15 @@ GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key,
/**
+ * Check if @a key is well-formed.
+ *
+ * @return true if @a key is well-formed.
+ */
+bool
+GNUNET_CRYPTO_rsa_public_key_check (
+ const struct GNUNET_CRYPTO_RsaPublicKey *key);
+
+/**
* Obtain the length of the RSA key in bits.
*
* @param key the public key to introspect
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index f017d1f10..43e6eedac 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -296,6 +296,30 @@ struct GNUNET_CRYPTO_RsaPublicKeyHeaderP
GNUNET_NETWORK_STRUCT_END
+bool
+GNUNET_CRYPTO_rsa_public_key_check (
+ const struct GNUNET_CRYPTO_RsaPublicKey *key)
+{
+ gcry_mpi_t ne[2];
+ int ret;
+
+ ret = key_from_sexp (ne,
+ key->sexp,
+ "public-key",
+ "ne");
+ if (0 != ret)
+ ret = key_from_sexp (ne,
+ key->sexp,
+ "rsa",
+ "ne");
+ if (0 != ret)
+ return false;
+ gcry_mpi_release (ne[0]);
+ gcry_mpi_release (ne[1]);
+ return true;
+}
+
+
size_t
GNUNET_CRYPTO_rsa_public_key_encode (
const struct GNUNET_CRYPTO_RsaPublicKey *key,