exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 8fb9b71939248c9323962e06f03768b34f8fa108
parent 8b159830567006f8faad263bd3084acacd2d72cd
Author: Christian Blättler <blatc2@bfh.ch>
Date:   Thu, 25 Apr 2024 10:25:25 +0200

add token use signature functions

Diffstat:
Msrc/include/taler_crypto_lib.h | 191++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Msrc/include/taler_json_lib.h | 2+-
Msrc/json/json_helper.c | 6+++---
Msrc/util/wallet_signatures.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 196 insertions(+), 73 deletions(-)

diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h @@ -2242,6 +2242,102 @@ TALER_CRYPTO_contract_decrypt_for_deposit ( size_t econtract_size); +/* ***************** Token crypto primitives ************* */ + + +/** + * Public key used to verify (blind) signature of issued coins. + */ +struct TALER_TokenIssuePublicKeyP +{ + /** + * RSA or CS blind sign public key. + */ + struct GNUNET_CRYPTO_BlindSignPublicKey *public_key; +}; + + +/** + * Hash of a public key used to issue tokens for a token family. + */ +struct TALER_TokenIssuePublicKeyHashP +{ + /** + * Public key hash. + */ + struct GNUNET_HashCode hash; +}; + + +/** + * Private key used to issue tokens by sign blinded + * token public keys (provided by wallet). + */ +struct TALER_TokenIssuePrivateKeyP +{ + /** + * RSA or CS blind sign private key. + */ + struct GNUNET_CRYPTO_BlindSignPrivateKey *private_key; +}; + + +/** + * Unblinded signature created using merchants token issue private key. + */ +struct TALER_TokenIssueSignatureP +{ + struct GNUNET_CRYPTO_UnblindedSignature *signature; +}; + + +/** + * Blinded signature created using merchants token issue private key. + */ +struct TALER_TokenIssueBlindSignatureP +{ + struct GNUNET_CRYPTO_BlindedSignature signature; +}; + + +/** + * The public key of a token. An EdDSA public key generated by the wallet + * and blindly signed by the merchant using the @struct TALER_TokenIssuePrivateKey. + */ +struct TALER_TokenUsePublicKeyP +{ + struct GNUNET_CRYPTO_EddsaPublicKey public_key; +}; + + +/** + * The private key of a token. An EdDSA private key generated by the wallet. + * Used to create @struct TALER_TokenUseSignatureP confirm the usage of a token. + */ +struct TALER_TokenUsePrivateKeyP +{ + struct GNUNET_CRYPTO_EddsaPrivateKey private_key; +}; + + +/** + * Signature made by the wallet using the token private key (EdDSA). + */ +struct TALER_TokenUseSignatureP +{ + struct GNUNET_CRYPTO_EddsaSignature signature; +}; + + +/** + * Free internals of @a issue_sig, but not @a issue_sig itself. + * + * @param[in] issue_sig signature to free + */ +void +TALER_token_issue_sig_free (struct TALER_TokenIssueSignatureP *issue_sig); + + /* **************** AML officer signatures **************** */ /** @@ -3741,12 +3837,36 @@ TALER_wallet_coin_history_sign ( struct TALER_CoinSpendSignatureP *coin_sig); +/** + * Create token use request signature. + * + * @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the exchange) + * @param wallet_data_hash hash over wallet inputs into the contract + * @param token_use_priv token use private key + * @param[out] token_sig set to the signature made with purpose #TALER_SIGNATURE_WALLET_TOKEN_USE + */ void -TALER_wallet_token_use_sign (); +TALER_wallet_token_use_sign ( + const struct TALER_PrivateContractHashP *h_contract_terms, + const struct GNUNET_HashCode *wallet_data_hash, + const struct TALER_TokenUsePrivateKeyP *token_use_priv, + struct TALER_TokenUseSignatureP *token_sig); +/** + * Verify token use signature. + * + * @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the exchange) + * @param wallet_data_hash hash over wallet inputs into the contract + * @param token_use_pub token use private key + * @param token_sig the signature made with purpose #TALER_SIGNATURE_WALLET_TOKEN_USE + */ enum GNUNET_GenericReturnValue -TALER_wallet_token_use_verify (); +TALER_wallet_token_use_verify ( + const struct TALER_PrivateContractHashP *h_contract_terms, + const struct GNUNET_HashCode *wallet_data_hash, + const struct TALER_TokenUsePublicKeyP *token_use_pub, + const struct TALER_TokenUseSignatureP *token_sig); /* ********************* merchant signing ************************** */ @@ -5929,71 +6049,4 @@ TALER_denomination_group_get_key ( struct GNUNET_HashCode *key); -/** - * Token family public key. - */ -struct TALER_TokenIssuePublicKey -{ - struct GNUNET_CRYPTO_BlindSignPublicKey *public_key; -}; - -/** - * Hash of a public key of a token family. - */ -struct TALER_TokenIssuePublicKeyHash -{ - /** - * Hash of the token public key. - */ - struct GNUNET_HashCode hash; -}; - -/** - * Token family private key. - */ -struct TALER_TokenIssuePrivateKey -{ - struct GNUNET_CRYPTO_BlindSignPrivateKey *private_key; -}; - -/** - * Token public key. - */ -struct TALER_TokenUsePublicKey -{ - struct GNUNET_CRYPTO_EddsaPublicKey public_key; -}; - -/** - * Signature made using a token private key. - */ -struct TALER_TokenUseSignature -{ - struct GNUNET_CRYPTO_EddsaSignature signature; -}; - -/** - * Unblinded signature created using merchants token issue private key. - */ -struct TALER_TokenIssueSignature -{ - struct GNUNET_CRYPTO_UnblindedSignature *signature; -}; - -/** - * Blind signature created using merchants token issue private key. - */ -struct TALER_TokenIssueBlindSignature -{ - struct GNUNET_CRYPTO_BlindedSignature signature; -}; - -/** - * Free internals of @a issue_sig, but not @a issue_sig itself. - * - * @param[in] issue_sig signature to free - */ -void -TALER_token_issue_sig_free (struct TALER_TokenIssueSignature *issue_sig); - #endif diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h @@ -597,7 +597,7 @@ TALER_JSON_spec_i18n_str (const char *name, */ struct GNUNET_JSON_Specification TALER_JSON_spec_token_issue_sig (const char *field, - struct TALER_TokenIssueSignature *sig); + struct TALER_TokenIssueSignatureP *sig); /** * Hash a JSON for binary signing. diff --git a/src/json/json_helper.c b/src/json/json_helper.c @@ -546,7 +546,7 @@ parse_token_issue_sig (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) { - struct TALER_TokenIssueSignature *issue_sig = spec->ptr; + struct TALER_TokenIssueSignatureP *issue_sig = spec->ptr; struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig; const char *cipher; struct GNUNET_JSON_Specification dspec[] = { @@ -638,7 +638,7 @@ static void clean_token_issue_sig (void *cls, struct GNUNET_JSON_Specification *spec) { - struct TALER_TokenIssueSignature *issue_sig = spec->ptr; + struct TALER_TokenIssueSignatureP *issue_sig = spec->ptr; (void) cls; TALER_token_issue_sig_free (issue_sig); @@ -647,7 +647,7 @@ clean_token_issue_sig (void *cls, struct GNUNET_JSON_Specification TALER_JSON_spec_token_issue_sig (const char *field, - struct TALER_TokenIssueSignature *sig) + struct TALER_TokenIssueSignatureP *sig) { struct GNUNET_JSON_Specification ret = { .parser = &parse_token_issue_sig, diff --git a/src/util/wallet_signatures.c b/src/util/wallet_signatures.c @@ -23,6 +23,7 @@ #include "taler_util.h" #include "taler_signatures.h" #include <gnunet/gnunet_common.h> +#include <stdint.h> GNUNET_NETWORK_STRUCT_BEGIN @@ -1827,4 +1828,73 @@ TALER_wallet_econtract_upload_verify ( } +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * Message signed by wallet to confirm usage of a coin for a transaction. + */ +struct TALER_TokenUseRequestPS +{ + + /** + * Purpose is #TALER_SIGNATURE_WALLET_TOKEN_USE + */ + struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + + /** + * Hash over the contract for which this token is used. + */ + struct TALER_PrivateContractHashP h_contract_terms GNUNET_PACKED; + + /** + * Hash over a JSON containing data provided by the + * wallet to complete the contract upon payment. + */ + struct GNUNET_HashCode wallet_data_hash; + +}; + +GNUNET_NETWORK_STRUCT_END + + +void +TALER_wallet_token_use_sign ( + const struct TALER_PrivateContractHashP *h_contract_terms, + const struct GNUNET_HashCode *wallet_data_hash, + const struct TALER_TokenUsePrivateKeyP *token_use_priv, + struct TALER_TokenUseSignatureP *token_sig) +{ + struct TALER_TokenUseRequestPS tur = { + .purpose.size = htonl (sizeof (tur)), + .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_TOKEN_USE), + .h_contract_terms = *h_contract_terms, + .wallet_data_hash = *wallet_data_hash + }; + + GNUNET_CRYPTO_eddsa_sign (&token_use_priv->private_key, + &tur, + &token_sig->signature); +} + + +enum GNUNET_GenericReturnValue +TALER_wallet_token_use_verify ( + const struct TALER_PrivateContractHashP *h_contract_terms, + const struct GNUNET_HashCode *wallet_data_hash, + const struct TALER_TokenUsePublicKeyP *token_use_pub, + const struct TALER_TokenUseSignatureP *token_sig) +{ + struct TALER_TokenUseRequestPS tur = { + .purpose.size = htonl (sizeof (tur)), + .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_TOKEN_USE), + .h_contract_terms = *h_contract_terms, + .wallet_data_hash = *wallet_data_hash + }; + + return GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_TOKEN_USE, + &tur, + &token_sig->signature, + &token_use_pub->public_key); +} + /* end of wallet_signatures.c */