commit 0c4f43dd5fec6456e5bd9f5a69380ce7c6b357ca
parent d2fd9db6f3f6de2da24b33fa7f7de33d0817090b
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 10 Dec 2024 13:34:52 +0100
-more helper functions for merchant
Diffstat:
4 files changed, 205 insertions(+), 1 deletion(-)
diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h
@@ -1467,7 +1467,7 @@ TALER_denom_ewv_rsa_singleton (void);
/**
- * Make a (deep) copy of the given @a bi_src to
+ * Make a copy of the given @a bi_src to
* @a bi_dst.
*
* @param[out] bi_dst target to copy to
@@ -2391,6 +2391,40 @@ struct TALER_TokenIssuePublicKey
/**
+ * Free internals of @a token_pub, but not @a token_pub itself.
+ *
+ * @param[in] token_pub key to free
+ */
+void
+TALER_token_issue_pub_free (struct TALER_TokenIssuePublicKey *token_pub);
+
+
+/**
+ * Make a copy of the given @a tip_src to @a tip_dst.
+ *
+ * @param[out] tip_dst target to copy to
+ * @param tip_src public key to copy
+ */
+void
+TALER_token_issue_pub_copy (
+ struct TALER_TokenIssuePublicKey *tip_dst,
+ const struct TALER_TokenIssuePublicKey *tip_src);
+
+
+/**
+ * Compare two token issue public keys.
+ *
+ * @param tip1 first key to compare
+ * @param tip2 second key to compare
+ * @return 0 if the keys are equal, otherwise -1 or 1
+ */
+int
+TALER_token_issue_pub_cmp (
+ struct TALER_TokenIssuePublicKey *tip1,
+ const struct TALER_TokenIssuePublicKey *tip2);
+
+
+/**
* Hash of a public key used to issue tokens for a token family.
*/
struct TALER_TokenIssuePublicKeyHashP
@@ -6252,6 +6286,7 @@ struct TALER_AgeCommitmentProof *
TALER_age_commitment_proof_duplicate (
const struct TALER_AgeCommitmentProof *acp);
+
/**
* @brief helper function to copy a struct TALER_AgeCommitmentProof
*
@@ -6263,6 +6298,7 @@ TALER_age_commitment_proof_deep_copy (
struct TALER_AgeCommitmentProof *nacp,
const struct TALER_AgeCommitmentProof *acp);
+
/**
* @brief For age-withdraw, clients have to prove that the public keys for all
* age groups larger than the allowed maximum age group are derived by scalar
diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
@@ -444,6 +444,15 @@ struct GNUNET_JSON_Specification
TALER_JSON_spec_denom_pub (const char *field,
struct TALER_DenominationPublicKey *pk);
+/**
+ * Generate line in parser specification for token issue public key.
+ *
+ * @param[out] pk key to initialize
+ * @return corresponding field spec
+ */
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_token_pub (struct TALER_TokenIssuePublicKey *pk);
+
/**
* Generate line in parser specification for error codes.
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
@@ -697,6 +697,130 @@ TALER_JSON_spec_denom_pub (const char *field,
/**
+ * Parse given JSON object to token issue public key.
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static enum GNUNET_GenericReturnValue
+parse_token_pub (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ struct TALER_TokenIssuePublicKey *token_pub = spec->ptr;
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub;
+ const char *cipher;
+ struct GNUNET_JSON_Specification dspec[] = {
+ GNUNET_JSON_spec_string ("cipher",
+ &cipher),
+ GNUNET_JSON_spec_end ()
+ };
+ const char *emsg;
+ unsigned int eline;
+
+ (void) cls;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (root,
+ dspec,
+ &emsg,
+ &eline))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ bsign_pub = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPublicKey);
+ bsign_pub->rc = 1;
+ bsign_pub->cipher = string_to_cipher (cipher);
+ switch (bsign_pub->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
+ {
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_rsa_public_key (
+ "rsa_pub",
+ &bsign_pub->details.rsa_public_key),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (root,
+ ispec,
+ &emsg,
+ &eline))
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (bsign_pub);
+ return GNUNET_SYSERR;
+ }
+ token_pub->public_key = bsign_pub;
+ return GNUNET_OK;
+ }
+ case GNUNET_CRYPTO_BSA_CS:
+ {
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_fixed ("cs_pub",
+ &bsign_pub->details.cs_public_key,
+ sizeof (bsign_pub->details.cs_public_key)),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (root,
+ ispec,
+ &emsg,
+ &eline))
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (bsign_pub);
+ return GNUNET_SYSERR;
+ }
+ token_pub->public_key = bsign_pub;
+ return GNUNET_OK;
+ }
+ }
+ GNUNET_break_op (0);
+ GNUNET_free (bsign_pub);
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Cleanup data left from parsing token issue public key.
+ *
+ * @param cls closure, NULL
+ * @param[out] spec where to free the data
+ */
+static void
+clean_token_pub (void *cls,
+ struct GNUNET_JSON_Specification *spec)
+{
+ struct TALER_TokenIssuePublicKey *token_pub = spec->ptr;
+
+ (void) cls;
+ TALER_token_issue_pub_free (token_pub);
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_token_pub (struct TALER_TokenIssuePublicKey *pk)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_token_pub,
+ .cleaner = &clean_token_pub,
+ .ptr = pk
+ };
+
+ pk->public_key = NULL;
+ return ret;
+}
+
+
+/**
* Parse given JSON object partially into a denomination public key.
*
* Depending on the cipher in cls, it parses the corresponding public key type.
diff --git a/src/util/tokens.c b/src/util/tokens.c
@@ -236,3 +236,38 @@ TALER_token_issue_sig_unblind (
}
return GNUNET_OK;
}
+
+
+void
+TALER_token_issue_pub_free (struct TALER_TokenIssuePublicKey *token_pub)
+{
+ if (NULL != token_pub->public_key)
+ {
+ GNUNET_CRYPTO_blind_sign_pub_decref (token_pub->public_key);
+ token_pub->public_key = NULL;
+ }
+}
+
+
+int
+TALER_token_issue_pub_cmp (
+ struct TALER_TokenIssuePublicKey *tip1,
+ const struct TALER_TokenIssuePublicKey *tip2)
+{
+ if (tip1->public_key->cipher !=
+ tip2->public_key->cipher)
+ return (tip1->public_key->cipher >
+ tip2->public_key->cipher) ? 1 : -1;
+ return GNUNET_CRYPTO_bsign_pub_cmp (tip1->public_key,
+ tip2->public_key);
+}
+
+
+void
+TALER_token_issue_pub_copy (
+ struct TALER_TokenIssuePublicKey *tip_dst,
+ const struct TALER_TokenIssuePublicKey *tip_src)
+{
+ tip_dst->public_key
+ = GNUNET_CRYPTO_bsign_pub_incref (tip_src->public_key);
+}