[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: add pq result and query helpers for blin
From: |
gnunet |
Subject: |
[gnunet] branch master updated: add pq result and query helpers for blind sign keys |
Date: |
Thu, 18 Apr 2024 10:21:13 +0200 |
This is an automated email from the git hooks/post-receive script.
christian-blaettler pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new ca828a0ed add pq result and query helpers for blind sign keys
ca828a0ed is described below
commit ca828a0edb853ef841620253c8e56ad5eae16014
Author: Christian Blättler <blatc2@bfh.ch>
AuthorDate: Thu Apr 18 08:52:43 2024 +0200
add pq result and query helpers for blind sign keys
---
src/include/gnunet_pq_lib.h | 47 ++++++++
src/lib/pq/pq_query_helper.c | 200 ++++++++++++++++++++++++++++++++
src/lib/pq/pq_result_helper.c | 263 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 510 insertions(+)
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index b5d39ed41..8b4077d0e 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -595,6 +595,27 @@ GNUNET_PQ_query_param_uint64 (const uint64_t *x);
struct GNUNET_PQ_QueryParam
GNUNET_PQ_query_param_int64 (const int64_t *x);
+/**
+ * Generate query parameter for a blind sign public key.
+ * Internally, the various attributes of the public key
+ * will be serialized into on variable-size BLOB.
+ *
+ * @param pub pointer to the query parameter to pass
+ *
+ */
+struct GNUNET_PQ_QueryParam
+GNUNET_PQ_query_param_blind_sign_pub (
+ const struct GNUNET_CRYPTO_BlindSignPublicKey *pub);
+
+/**
+ * Generate query parameter for a blind sign private key of variable size.
+ *
+ * @param priv pointer to the query parameter to pass
+ *
+ */
+struct GNUNET_PQ_QueryParam
+GNUNET_PQ_query_param_blind_sign_priv (
+ const struct GNUNET_CRYPTO_BlindSignPrivateKey *priv);
/* ************************* pq_result_helper.c functions
************************ */
@@ -1104,6 +1125,32 @@ GNUNET_PQ_result_spec_array_string (
size_t *num,
char **dst);
+
+/**
+ * Blind sign public key expected.
+ *
+ * @param name name of the field in the table
+ * @param[out] public_key where to store the denomination signature
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+GNUNET_PQ_result_spec_blind_sign_pub (
+ const char *name,
+ struct GNUNET_CRYPTO_BlindSignPublicKey *public_key);
+
+
+/**
+ * Blind sign private key expected.
+ *
+ * @param name name of the field in the table
+ * @param[out] private_key where to store the denomination signature
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+GNUNET_PQ_result_spec_blind_sign_priv (
+ const char *name,
+ struct GNUNET_CRYPTO_BlindSignPrivateKey *private_key);
+
/* ************************* pq.c functions ************************ */
/**
diff --git a/src/lib/pq/pq_query_helper.c b/src/lib/pq/pq_query_helper.c
index 211c35076..913ce9235 100644
--- a/src/lib/pq/pq_query_helper.c
+++ b/src/lib/pq/pq_query_helper.c
@@ -1382,4 +1382,204 @@ GNUNET_PQ_query_param_array_ptrs_timestamp (
}
+/**
+ * Function called to convert input argument into SQL parameters.
+ *
+ * @param cls closure
+ * @param data pointer to input argument
+ * @param data_len number of bytes in @a data (if applicable)
+ * @param[out] param_values SQL data to set
+ * @param[out] param_lengths SQL length data to set
+ * @param[out] param_formats SQL format data to set
+ * @param param_length number of entries available in the @a param_values, @a
param_lengths and @a param_formats arrays
+ * @param[out] scratch buffer for dynamic allocations (to be done via
#GNUNET_malloc()
+ * @param scratch_length number of entries left in @a scratch
+ * @return -1 on error, number of offsets used in @a scratch otherwise
+ */
+static int
+qconv_blind_sign_pub (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
+{
+ const struct GNUNET_CRYPTO_BlindSignPublicKey *public_key = data;
+ size_t tlen;
+ size_t len;
+ uint32_t be;
+ char *buf;
+ void *tbuf;
+
+ (void) cls;
+ (void) data_len;
+ GNUNET_assert (1 == param_length);
+ GNUNET_assert (scratch_length > 0);
+ GNUNET_break (NULL == cls);
+ be = htonl ((uint32_t) public_key->cipher);
+ switch (public_key->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ tlen = GNUNET_CRYPTO_rsa_public_key_encode (
+ public_key->details.rsa_public_key,
+ &tbuf);
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ tlen = sizeof (public_key->details.cs_public_key);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ len = tlen + sizeof (be);
+ buf = GNUNET_malloc (len);
+ GNUNET_memcpy (buf,
+ &be,
+ sizeof (be));
+ switch (public_key->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ tbuf,
+ tlen);
+ GNUNET_free (tbuf);
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ &public_key->details.cs_public_key,
+ tlen);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+
+ scratch[0] = buf;
+ param_values[0] = (void *) buf;
+ param_lengths[0] = len;
+ param_formats[0] = 1;
+ return 1;
+}
+
+
+/**
+ * Generate query parameter for a blind sign public key of variable size.
+ *
+ * @param pub pointer to the query parameter to pass
+ */
+struct GNUNET_PQ_QueryParam
+GNUNET_PQ_query_param_blind_sign_pub (
+ const struct GNUNET_CRYPTO_BlindSignPublicKey *pub)
+{
+ struct GNUNET_PQ_QueryParam res = {
+ .conv = &qconv_blind_sign_pub,
+ .data = pub,
+ .num_params = 1
+ };
+
+ return res;
+}
+
+
+/**
+ * Function called to convert input argument into SQL parameters.
+ *
+ * @param cls closure
+ * @param data pointer to input argument
+ * @param data_len number of bytes in @a data (if applicable)
+ * @param[out] param_values SQL data to set
+ * @param[out] param_lengths SQL length data to set
+ * @param[out] param_formats SQL format data to set
+ * @param param_length number of entries available in the @a param_values, @a
param_lengths and @a param_formats arrays
+ * @param[out] scratch buffer for dynamic allocations (to be done via
#GNUNET_malloc()
+ * @param scratch_length number of entries left in @a scratch
+ * @return -1 on error, number of offsets used in @a scratch otherwise
+ */
+static int
+qconv_blind_sign_priv (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
+{
+ const struct GNUNET_CRYPTO_BlindSignPrivateKey *private_key = data;
+ size_t tlen;
+ size_t len;
+ uint32_t be;
+ char *buf;
+ void *tbuf;
+
+ (void) cls;
+ (void) data_len;
+ GNUNET_assert (1 == param_length);
+ GNUNET_assert (scratch_length > 0);
+ GNUNET_break (NULL == cls);
+ be = htonl ((uint32_t) private_key->cipher);
+ switch (private_key->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ tlen = GNUNET_CRYPTO_rsa_private_key_encode (
+ private_key->details.rsa_private_key,
+ &tbuf);
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ tlen = sizeof (private_key->details.cs_private_key);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ len = tlen + sizeof (be);
+ buf = GNUNET_malloc (len);
+ GNUNET_memcpy (buf,
+ &be,
+ sizeof (be));
+ switch (private_key->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ tbuf,
+ tlen);
+ GNUNET_free (tbuf);
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ &private_key->details.cs_private_key,
+ tlen);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+
+ scratch[0] = buf;
+ param_values[0] = (void *) buf;
+ param_lengths[0] = len;
+ param_formats[0] = 1;
+ return 1;
+}
+
+
+/**
+ * Generate query parameter for a blind sign private key of variable size.
+ *
+ * @param priv pointer to the query parameter to pass
+ */
+struct GNUNET_PQ_QueryParam
+GNUNET_PQ_query_param_blind_sign_priv (
+ const struct GNUNET_CRYPTO_BlindSignPrivateKey *priv)
+{
+ struct GNUNET_PQ_QueryParam res = {
+ .conv = &qconv_blind_sign_priv,
+ .data = priv,
+ .num_params = 1
+ };
+
+ return res;
+}
+
+
/* end of pq_query_helper.c */
diff --git a/src/lib/pq/pq_result_helper.c b/src/lib/pq/pq_result_helper.c
index 6210746bb..f8759eba1 100644
--- a/src/lib/pq/pq_result_helper.c
+++ b/src/lib/pq/pq_result_helper.c
@@ -1795,4 +1795,267 @@ GNUNET_PQ_result_spec_array_string (
}
+/**
+ * Extract data from a Postgres database @a result at row @a row.
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param row the row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ * #GNUNET_YES if all results could be extracted
+ * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static enum GNUNET_GenericReturnValue
+extract_blind_sign_pub (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bpk = dst;
+ size_t len;
+ const char *res;
+ int fnum;
+ uint32_t be;
+
+ (void) cls;
+ (void) dst_size;
+ fnum = PQfnumber (result,
+ fname);
+ if (fnum < 0)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ return GNUNET_NO;
+
+ /* if a field is null, continue but
+ * remember that we now return a different result */
+ len = PQgetlength (result,
+ row,
+ fnum);
+ res = PQgetvalue (result,
+ row,
+ fnum);
+ if (len < sizeof (be))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_memcpy (&be,
+ res,
+ sizeof (be));
+ res += sizeof (be);
+ len -= sizeof (be);
+ bpk = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPublicKey);
+ bpk->cipher = ntohl (be);
+ bpk->rc = 1;
+ switch (bpk->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
+ bpk->details.rsa_public_key
+ = GNUNET_CRYPTO_rsa_public_key_decode (res,
+ len);
+ if (NULL == bpk->details.rsa_public_key)
+ {
+ GNUNET_break (0);
+ GNUNET_free (bpk);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_CRYPTO_hash (res,
+ len,
+ &bpk->pub_key_hash);
+ return GNUNET_OK;
+ case GNUNET_CRYPTO_BSA_CS:
+ if (sizeof (bpk->details.cs_public_key) != len)
+ {
+ GNUNET_break (0);
+ GNUNET_free (bpk);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_memcpy (&bpk->details.cs_public_key,
+ res,
+ len);
+ GNUNET_CRYPTO_hash (res,
+ len,
+ &bpk->pub_key_hash);
+ return GNUNET_OK;
+ }
+ GNUNET_break (0);
+ GNUNET_free (bpk);
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Function called to clean up memory allocated
+ * by a #GNUNET_PQ_ResultConverter.
+ *
+ * @param cls closure
+ * @param rd result data to clean up
+ */
+static void
+clean_blind_sign_pub (void *cls,
+ void *rd)
+{
+ struct GNUNET_CRYPTO_BlindSignPublicKey *pub = rd;
+
+ (void) cls;
+ GNUNET_CRYPTO_blind_sign_pub_decref (pub);
+ pub = NULL;
+}
+
+
+struct GNUNET_PQ_ResultSpec
+GNUNET_PQ_result_spec_blind_sign_pub (const char *name,
+ struct GNUNET_CRYPTO_BlindSignPublicKey
*pub)
+{
+ struct GNUNET_PQ_ResultSpec res = {
+ .conv = &extract_blind_sign_pub,
+ .cleaner = &clean_blind_sign_pub,
+ .dst = (void *) pub,
+ .fname = name
+ };
+
+ return res;
+}
+
+
+/**
+ * Extract data from a Postgres database @a result at row @a row.
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param row the row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ * #GNUNET_YES if all results could be extracted
+ * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static enum GNUNET_GenericReturnValue
+extract_blind_sign_priv (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ struct GNUNET_CRYPTO_BlindSignPrivateKey *bpk = dst;
+ size_t len;
+ const char *res;
+ int fnum;
+ uint32_t be;
+
+ (void) cls;
+ (void) dst_size;
+ fnum = PQfnumber (result,
+ fname);
+ if (fnum < 0)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ return GNUNET_NO;
+
+ /* if a field is null, continue but
+ * remember that we now return a different result */
+ len = PQgetlength (result,
+ row,
+ fnum);
+ res = PQgetvalue (result,
+ row,
+ fnum);
+ if (len < sizeof (be))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_memcpy (&be,
+ res,
+ sizeof (be));
+ res += sizeof (be);
+ len -= sizeof (be);
+ bpk = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPrivateKey);
+ bpk->cipher = ntohl (be);
+ bpk->rc = 1;
+ switch (bpk->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
+ bpk->details.rsa_private_key
+ = GNUNET_CRYPTO_rsa_private_key_decode (res,
+ len);
+ if (NULL == bpk->details.rsa_private_key)
+ {
+ GNUNET_break (0);
+ GNUNET_free (bpk);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+ case GNUNET_CRYPTO_BSA_CS:
+ if (sizeof (bpk->details.cs_private_key) != len)
+ {
+ GNUNET_break (0);
+ GNUNET_free (bpk);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_memcpy (&bpk->details.cs_private_key,
+ res,
+ len);
+ return GNUNET_OK;
+ }
+ GNUNET_break (0);
+ GNUNET_free (bpk);
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Function called to clean up memory allocated
+ * by a #GNUNET_PQ_ResultConverter.
+ *
+ * @param cls closure
+ * @param rd result data to clean up
+ */
+static void
+clean_blind_sign_priv (void *cls,
+ void *rd)
+{
+ struct GNUNET_CRYPTO_BlindSignPublicKey *pub = rd;
+
+ (void) cls;
+ GNUNET_CRYPTO_blind_sign_pub_decref (pub);
+ pub = NULL;
+}
+
+
+struct GNUNET_PQ_ResultSpec
+GNUNET_PQ_result_spec_blind_sign_priv (const char *name,
+ struct
GNUNET_CRYPTO_BlindSignPrivateKey *priv)
+{
+ struct GNUNET_PQ_ResultSpec res = {
+ .conv = &extract_blind_sign_priv,
+ .cleaner = &clean_blind_sign_priv,
+ .dst = (void *) priv,
+ .fname = name
+ };
+
+ return res;
+}
+
/* end of pq_result_helper.c */
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: add pq result and query helpers for blind sign keys,
gnunet <=