commit 93617735969d6a282c869a2a3c5ad2071627dc36 parent f487577e2bab33057c322ae89aca44e9326e841b Author: Özgür Kesim <oec@kesim.org> Date: Wed, 2 Apr 2025 22:50:53 +0200 [withdraw] simplify withdraw table and all related handlers and protocol parts - remove h_commitment from table - remove h_commitment from db and http handlers, use h_planchets instead Diffstat:
37 files changed, 314 insertions(+), 543 deletions(-)
diff --git a/src/auditor/taler-helper-auditor-coins.c b/src/auditor/taler-helper-auditor-coins.c @@ -973,7 +973,6 @@ cleanup_denomination (void *cls, * @param num_evs number of elements in @e h_blind_evs * @param h_blind_evs array @e num_evs of blinded hashes of the coin's public keys * @param denom_serials array @e num_evs of serial ID's of denominations in our DB - * @param h_commitment hash of the commitment of the withdraw * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request * @param age_proof_required true if the withdraw request required an age proof. * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins. @@ -990,7 +989,6 @@ withdraw_cb (void *cls, size_t num_evs, const struct TALER_BlindedCoinHashP *h_blind_evs, const uint64_t *denom_serials, - const struct TALER_WithdrawCommitmentHashP *h_commitment, const struct TALER_HashBlindedPlanchetsP *h_planchets, bool age_proof_required, uint8_t max_age, @@ -1009,7 +1007,6 @@ withdraw_cb (void *cls, /* Note: some optimization potential here: lots of fields we could avoid fetching from the database with a custom function. */ (void) h_blind_evs; - (void) h_commitment; (void) h_planchets; (void) reserve_pub; (void) reserve_sig; diff --git a/src/auditor/taler-helper-auditor-reserves.c b/src/auditor/taler-helper-auditor-reserves.c @@ -515,7 +515,6 @@ handle_reserve_in ( * @param num_evs number of elements in @e h_blind_evs * @param h_blind_evs array @e num_evs of blinded hashes of the coin's public keys * @param denom_serials array @e num_evs of serial ID's of denominations in our DB - * @param h_commitment hash of the commitment of the withdraw * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request * @param age_proof_required true if the withdraw request required an age proof. * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins. @@ -533,7 +532,6 @@ handle_withdrawals ( size_t num_evs, const struct TALER_BlindedCoinHashP *h_blind_evs, const uint64_t *denom_serials, - const struct TALER_WithdrawCommitmentHashP *h_commitment, const struct TALER_HashBlindedPlanchetsP *h_planchets, bool age_proof_required, uint8_t max_age, @@ -575,7 +573,7 @@ handle_withdrawals ( GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Hard database error trying to get denomination by serial %lu (%s) from database!\n", denom_serials[i], - GNUNET_h2s (&h_commitment->hash)); + GNUNET_h2s (&h_planchets->hash)); rc->qs = qs; return GNUNET_SYSERR; } diff --git a/src/exchange/taler-exchange-httpd_recoup.c b/src/exchange/taler-exchange-httpd_recoup.c @@ -169,7 +169,7 @@ recoup_transaction (void *cls, * @param exchange_vals values contributed by the exchange * during withdrawal * @param coin_bks blinding data of the coin (to be checked) - * @param h_commitment The hash of the commitment of the original withdraw request + * @param h_planchets The hash of the commitment of the original withdraw request * @param nonce coin's nonce if CS is used * @param coin_sig signature of the coin * @return MHD result code @@ -180,7 +180,7 @@ verify_and_execute_recoup ( const struct TALER_CoinPublicInfo *coin, const struct TALER_ExchangeWithdrawValues *exchange_vals, const union GNUNET_CRYPTO_BlindingSecretP *coin_bks, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, const union GNUNET_CRYPTO_BlindSessionNonce *nonce, const struct TALER_CoinSpendSignatureP *coin_sig) { @@ -314,9 +314,9 @@ verify_and_execute_recoup ( { enum GNUNET_DB_QueryStatus qs; - qs = TEH_plugin->get_reserve_by_h_commitment ( + qs = TEH_plugin->get_reserve_by_h_planchets ( TEH_plugin->cls, - h_commitment, + h_planchets, &pc.reserve_pub, &pc.withdraw_serial_id); if (0 > qs) @@ -384,7 +384,7 @@ TEH_handler_recoup (struct MHD_Connection *connection, union GNUNET_CRYPTO_BlindingSecretP coin_bks; struct TALER_CoinSpendSignatureP coin_sig; struct TALER_ExchangeWithdrawValues exchange_vals; - struct TALER_WithdrawCommitmentHashP withdraw_commitment_h; + struct TALER_HashBlindedPlanchetsP h_planchets; union GNUNET_CRYPTO_BlindSessionNonce nonce; bool no_nonce; struct GNUNET_JSON_Specification spec[] = { @@ -392,8 +392,8 @@ TEH_handler_recoup (struct MHD_Connection *connection, &coin.denom_pub_hash), TALER_JSON_spec_denom_sig ("denom_sig", &coin.denom_sig), - GNUNET_JSON_spec_fixed_auto ("withdraw_commitment_hash", - &withdraw_commitment_h), + GNUNET_JSON_spec_fixed_auto ("h_planchets", + &h_planchets), TALER_JSON_spec_exchange_withdraw_values ("ewv", &exchange_vals), GNUNET_JSON_spec_fixed_auto ("coin_blind_key_secret", @@ -429,7 +429,7 @@ TEH_handler_recoup (struct MHD_Connection *connection, &coin, &exchange_vals, &coin_bks, - &withdraw_commitment_h, + &h_planchets, no_nonce ? NULL : &nonce, diff --git a/src/exchange/taler-exchange-httpd_reserves_history.c b/src/exchange/taler-exchange-httpd_reserves_history.c @@ -139,9 +139,6 @@ compile_reserve_history ( "reserve_sig", &withdraw->reserve_sig), GNUNET_JSON_pack_data_auto ( - "h_commitment", - &withdraw->h_commitment), - GNUNET_JSON_pack_data_auto ( "h_planchets", &withdraw->h_planchets), GNUNET_JSON_pack_uint64 ( diff --git a/src/exchange/taler-exchange-httpd_reveal-withdraw.c b/src/exchange/taler-exchange-httpd_reveal-withdraw.c @@ -42,7 +42,7 @@ struct WithdrawRevealContext * Commitment for the withdraw operation, previously called by the * client. */ - struct TALER_WithdrawCommitmentHashP ach; + struct TALER_HashBlindedPlanchetsP h_planchets; /** * TALER_CNC_KAPPA-1 secrets for disclosed coin batches. @@ -133,7 +133,7 @@ parse_withdraw_reveal_json ( * Otherwise, it queues an appropriate MHD response. * * @param connection The HTTP connection to the client - * @param h_commitment Original commitment value sent with the withdraw request + * @param h_planchets Original commitment value sent with the withdraw request * @param[out] commitment Data from the original withdraw request * @param[out] result In the error cases, a response will be queued with MHD and this will be the result. * @return #GNUNET_OK if the withdraw request has been found, @@ -142,7 +142,7 @@ parse_withdraw_reveal_json ( static enum GNUNET_GenericReturnValue find_original_commitment ( struct MHD_Connection *connection, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, struct TALER_EXCHANGEDB_Withdraw *commitment, MHD_RESULT *result) { @@ -151,7 +151,7 @@ find_original_commitment ( for (unsigned int try = 0; try < 3; try++) { qs = TEH_plugin->get_withdraw (TEH_plugin->cls, - h_commitment, + h_planchets, commitment); switch (qs) { @@ -298,8 +298,8 @@ calculate_blinded_hash ( * - age commitments, * - blindings * - blinded hashes - * - Computes h_commitment with those calculated and the undisclosed hashes - * - Compares h_commitment with the value from the original commitment + * - Computes h_planchets with those calculated and the undisclosed hashes + * - Compares h_planchets with the value from the original commitment * - Verifies that all public keys in indices larger than the age group * corresponding to max_age are derived from the constant public key. * @@ -446,24 +446,14 @@ verify_commitment_and_max_age ( /* Finally, compare the calculated hash with the original commitment */ { struct TALER_HashBlindedPlanchetsP h_planchets; - struct TALER_WithdrawCommitmentHashP wch; GNUNET_CRYPTO_hash_context_finish ( hash_context, &h_planchets.hash); - TALER_wallet_withdraw_commit ( - &commitment->reserve_pub, - &total_amount, - &total_fee, - &h_planchets, - &mask, - commitment->max_age, - &wch); - if (0 != GNUNET_CRYPTO_hash_cmp ( - &commitment->h_commitment.hash, - &wch.hash)) + &commitment->h_planchets.hash, + &h_planchets.hash)) { GNUNET_break_op (0); *result = TALER_MHD_reply_with_ec (connection, @@ -521,8 +511,8 @@ TEH_handler_reveal_withdraw ( struct WithdrawRevealContext actx = {0}; const json_t *j_disclosed_batch_seeds; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_fixed_auto ("withdraw_commitment_h", - &actx.ach), + GNUNET_JSON_spec_fixed_auto ("h_planchets", + &actx.h_planchets), GNUNET_JSON_spec_array_const ("disclosed_batch_seeds", &j_disclosed_batch_seeds), GNUNET_JSON_spec_end () @@ -554,12 +544,12 @@ TEH_handler_reveal_withdraw ( if (GNUNET_OK != find_original_commitment ( rc->connection, - &actx.ach, + &actx.h_planchets, &actx.commitment, &result)) break; - /* Verify the computed h_commitment equals the committed one and that coins + /* Verify the computed h_planchets equals the committed one and that coins * have a maximum age group corresponding max_age (age-mask dependent) */ if (GNUNET_OK != verify_commitment_and_max_age ( diff --git a/src/exchange/taler-exchange-httpd_withdraw.c b/src/exchange/taler-exchange-httpd_withdraw.c @@ -19,7 +19,7 @@ /** * @file taler-exchange-httpd_withdraw.c * @brief Code to handle /withdraw requests - * @note This endpoint is active since v24 of the protocol API + * @note This endpoint is active since v26 of the protocol API * @author Özgür Kesim */ @@ -40,7 +40,7 @@ * This bit will be set on errors of type #WithdrawError * that require a check for idempotency before actually * returning an error. - * This value must be outside the range of enum #WithdrawError. + * This value must be larger than the number of entries in #WithdrawError. */ #define IDEMPOTENCY_FLAG 1 << 5 @@ -337,7 +337,7 @@ withdraw_is_idempotent ( qs = TEH_plugin->get_withdraw ( TEH_plugin->cls, - &wc->request.persist.h_commitment, + &wc->request.persist.h_planchets, &wc->request.idem); if (0 > qs) { @@ -990,22 +990,6 @@ phase_check_reserve_signature ( return; } - /** - * Now that request is verified, calculate the h_commitment for persistence - */ - TALER_wallet_withdraw_commit ( - &wc->request.persist.reserve_pub, - &wc->request.amount, - &wc->request.fee, - &wc->request.persist.h_planchets, - wc->request.persist.age_proof_required - ? &TEH_age_restriction_config.mask - : NULL, - wc->request.persist.age_proof_required - ? wc->request.persist.max_age - : 0, - &wc->request.persist.h_commitment); - wc->phase++; } @@ -1086,7 +1070,7 @@ phase_generate_reply_success (struct WithdrawContext *wc) ec_confirmation_sign = TALER_exchange_online_withdraw_age_confirmation_sign ( &TEH_keys_exchange_sign_, - &db_obj->h_commitment, + &db_obj->h_planchets, db_obj->noreveal_index, &pub, &sig); diff --git a/src/exchange/taler-exchange-httpd_withdraw.h b/src/exchange/taler-exchange-httpd_withdraw.h @@ -16,7 +16,7 @@ /** * @file taler-exchange-httpd_withdraw.h * @brief Handle /withdraw requests - * @note This endpoint was introduced in v24 of the protocol. + * @note This endpoint was introduced in v26 of the protocol. * @author Özgür Kesim */ #ifndef TALER_EXCHANGE_HTTPD_WITHDRAW_H @@ -41,7 +41,7 @@ TEH_withdraw_cleanup (void); * If the "max_age" value is set in the request, * it is considered a commitment to withdraw age restricted coins. * If the request is valid, the response contains a noreveal_index - * which the client has to use for the subsequent call to /reveal-withdraw/$ACH. + * which the client has to use for the subsequent call to /reveal-withdraw. * If "max_age" value is not set, and the request is valid, the envelopes * with the blinded coins "blinded_coin_evs" is processed * and the client receives the blinded signatures as response. diff --git a/src/exchangedb/0009-withdraw.sql b/src/exchangedb/0009-withdraw.sql @@ -27,10 +27,9 @@ BEGIN PERFORM create_partitioned_table( 'CREATE TABLE %I' '(withdraw_id BIGINT GENERATED BY DEFAULT AS IDENTITY' - ',h_commitment BYTEA NOT NULL CONSTRAINT h_commitment_length CHECK(LENGTH(h_commitment)=64)' + ',h_planchets BYTEA NOT NULL CONSTRAINT h_planchets_length CHECK(LENGTH(h_planchets)=64)' ',execution_date INT8 NOT NULL' ',amount_with_fee taler_amount NOT NULL' - ',h_planchets BYTEA NOT NULL CONSTRAINT h_planchets_length CHECK(LENGTH(h_planchets)=64)' ',reserve_pub BYTEA NOT NULL CONSTRAINT reserve_pub_length CHECK(LENGTH(reserve_pub)=32)' ',reserve_sig BYTEA NOT NULL CONSTRAINT reserve_sig_length CHECK(LENGTH(reserve_sig)=64)' ',max_age SMALLINT CONSTRAINT max_age_positive CHECK(max_age>=0)' @@ -44,7 +43,7 @@ BEGIN ,partition_suffix ); PERFORM comment_partitioned_table( - 'Commitments made when withdrawing coins with age restriction and the gamma value chosen by the exchange. ' + 'Commitments made when withdrawing coins and, in case of required proof of age restriction, the gamma value chosen by the exchange. ' 'It also contains the blindly signed coins, their signatures and denominations.' ,table_name ,partition_suffix @@ -56,7 +55,7 @@ BEGIN ,partition_suffix ); PERFORM comment_partitioned_column( - 'The running hash over all committed blinded planchets.' + 'The running hash over all committed blinded planchets. Needed in the cut-and-choose protocol when aproof of age-restriction is required, and recoup.' ,'h_planchets' ,table_name ,partition_suffix @@ -74,12 +73,6 @@ BEGIN ,partition_suffix ); PERFORM comment_partitioned_column( - 'Commitment made by the client, hash over the various client inputs. Needed in the cut-and-choose protocol when aproof of age-restriction is required, and recoup.' - ,'h_commitment' - ,table_name - ,partition_suffix - ); - PERFORM comment_partitioned_column( 'Reference to the public key of the reserve from which the coins are going to be withdrawn' ,'reserve_pub' ,table_name @@ -125,12 +118,12 @@ BEGIN table_name = concat_ws('_', table_name, partition_suffix); EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || - ' ADD PRIMARY KEY (h_commitment);' + ' ADD PRIMARY KEY (h_planchets);' ); EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || - ' ADD CONSTRAINT ' || table_name || '_h_commitment_reserve_pub_key' - ' UNIQUE (h_commitment, reserve_pub);' + ' ADD CONSTRAINT ' || table_name || '_h_planchets_reserve_pub_key' + ' UNIQUE (h_planchets, reserve_pub);' ); EXECUTE FORMAT ( 'ALTER TABLE ' || table_name || diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am @@ -208,7 +208,7 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \ pg_get_ready_deposit.h pg_get_ready_deposit.c \ pg_get_refresh_reveal.h pg_get_refresh_reveal.c \ pg_get_reserve_balance.h pg_get_reserve_balance.c \ - pg_get_reserve_by_h_commitment.h pg_get_reserve_by_h_commitment.c \ + pg_get_reserve_by_h_planchets.h pg_get_reserve_by_h_planchets.c \ pg_get_reserve_history.c pg_get_reserve_history.h \ pg_get_signature_for_known_coin.h pg_get_signature_for_known_coin.c \ pg_get_unfinished_close_requests.c pg_get_unfinished_close_requests.h \ diff --git a/src/exchangedb/exchange_do_withdraw.sql b/src/exchangedb/exchange_do_withdraw.sql @@ -15,13 +15,14 @@ -- -- @author Özgür Kesim -CREATE OR REPLACE FUNCTION exchange_do_withdraw( +DROP FUNCTION IF EXISTS exchange_do_withdraw; + +CREATE FUNCTION exchange_do_withdraw( IN amount_with_fee taler_amount, IN rpub BYTEA, IN rsig BYTEA, IN now INT8, IN min_reserve_gc INT8, - IN h_commitment BYTEA, IN h_planchets BYTEA, IN maximum_age_committed INT2, -- in years ϵ [0,1..) IN noreveal_index INT2, @@ -130,8 +131,7 @@ WHERE -- Write the commitment into the withdraw table INSERT INTO withdraw - (h_commitment - ,h_planchets + (h_planchets ,execution_date ,max_age ,amount_with_fee @@ -142,8 +142,7 @@ INSERT INTO withdraw ,h_blind_evs ,denom_sigs) VALUES - (h_commitment - ,h_planchets + (h_planchets ,now ,maximum_age_committed ,amount_with_fee @@ -167,5 +166,5 @@ END IF; END $$; -COMMENT ON FUNCTION exchange_do_withdraw(taler_amount, BYTEA, BYTEA, INT8, INT8, BYTEA, BYTEA, INT2, INT2, BYTEA[], INT8[], BYTEA[]) +COMMENT ON FUNCTION exchange_do_withdraw(taler_amount, BYTEA, BYTEA, INT8, INT8, BYTEA, INT2, INT2, BYTEA[], INT8[], BYTEA[]) IS 'Checks whether the reserve has sufficient balance for an withdraw operation (or the request is repeated and was previously approved) and that age requirements are met. If so updates the database with the result. Includes storing the blinded planchets and denomination signatures, or signaling conflict'; diff --git a/src/exchangedb/pg_do_withdraw.c b/src/exchangedb/pg_do_withdraw.c @@ -50,7 +50,6 @@ TEH_PG_do_withdraw ( GNUNET_PQ_query_param_auto_from_type (&withdraw->reserve_sig), GNUNET_PQ_query_param_timestamp (&now), GNUNET_PQ_query_param_timestamp (&gc), - GNUNET_PQ_query_param_auto_from_type (&withdraw->h_commitment), GNUNET_PQ_query_param_auto_from_type (&withdraw->h_planchets), withdraw->age_proof_required ? GNUNET_PQ_query_param_uint16 (&withdraw->max_age) @@ -103,7 +102,7 @@ TEH_PG_do_withdraw ( ",reserve_birthday" ",conflict" " FROM exchange_do_withdraw" - " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);"); + " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);"); qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "call_withdraw", params, diff --git a/src/exchangedb/pg_get_reserve_by_h_commitment.c b/src/exchangedb/pg_get_reserve_by_h_commitment.c @@ -1,62 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022,2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file exchangedb/pg_get_reserve_by_h_commitment.c - * @brief Implementation of the get_reserve_by_h_commitment function for Postgres - * @author Christian Grothoff - * @author Özgür Kesim - */ -#include "platform.h" -#include "taler_error_codes.h" -#include "taler_dbevents.h" -#include "taler_pq_lib.h" -#include "pg_get_reserve_by_h_commitment.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_get_reserve_by_h_commitment ( - void *cls, - const struct TALER_WithdrawCommitmentHashP *h_commitment, - struct TALER_ReservePublicKeyP *reserve_pub, - uint64_t *withdraw_serial_id) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_commitment), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - reserve_pub), - GNUNET_PQ_result_spec_uint64 ("withdraw_id", - withdraw_serial_id), - GNUNET_PQ_result_spec_end - }; - /* Used in #postgres_get_reserve_by_h_commitment() */ - PREPARE (pg, - "reserve_by_h_commitment", - "SELECT" - " reserve_pub" - ",withdraw_id" - " FROM withdraw" - " WHERE h_commitment=$1" - " LIMIT 1;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "reserve_by_h_commitment", - params, - rs); -} diff --git a/src/exchangedb/pg_get_reserve_by_h_commitment.h b/src/exchangedb/pg_get_reserve_by_h_commitment.h @@ -1,45 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file exchangedb/pg_get_reserve_by_h_commitment.h - * @brief implementation of the get_reserve_by_h_commitment function for Postgres - * @author Christian Grothoff - * @author Özgür Kesim - */ -#ifndef PG_GET_RESERVE_BY_H_COMMITMENT_H -#define PG_GET_RESERVE_BY_H_COMMITMENT_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_exchangedb_plugin.h" -/** - * Obtain information about which reserve a coin was generated - * from given the hash of the blinded coin. - * - * @param cls closure - * @param h_commitment hash that uniquely identifies the withdraw request - * @param[out] reserve_pub set to information about the reserve (on success only) - * @param[out] withdraw_serial_id set to row of the @a h_commitment in withdraw - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_reserve_by_h_commitment ( - void *cls, - const struct TALER_WithdrawCommitmentHashP *h_commitment, - struct TALER_ReservePublicKeyP *reserve_pub, - uint64_t *withdraw_serial_id); - -#endif diff --git a/src/exchangedb/pg_get_reserve_by_h_planchets.c b/src/exchangedb/pg_get_reserve_by_h_planchets.c @@ -0,0 +1,62 @@ +/* + This file is part of TALER + Copyright (C) 2022,2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file exchangedb/pg_get_reserve_by_h_planchets.c + * @brief Implementation of the get_reserve_by_h_planchets function for Postgres + * @author Christian Grothoff + * @author Özgür Kesim + */ +#include "platform.h" +#include "taler_error_codes.h" +#include "taler_dbevents.h" +#include "taler_pq_lib.h" +#include "pg_get_reserve_by_h_planchets.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TEH_PG_get_reserve_by_h_planchets ( + void *cls, + const struct TALER_HashBlindedPlanchetsP *h_planchets, + struct TALER_ReservePublicKeyP *reserve_pub, + uint64_t *withdraw_serial_id) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_planchets), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", + reserve_pub), + GNUNET_PQ_result_spec_uint64 ("withdraw_id", + withdraw_serial_id), + GNUNET_PQ_result_spec_end + }; + /* Used in #postgres_get_reserve_by_h_planchets() */ + PREPARE (pg, + "reserve_by_h_planchets", + "SELECT" + " reserve_pub" + ",withdraw_id" + " FROM withdraw" + " WHERE h_planchets=$1" + " LIMIT 1;"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "reserve_by_h_planchets", + params, + rs); +} diff --git a/src/exchangedb/pg_get_reserve_by_h_planchets.h b/src/exchangedb/pg_get_reserve_by_h_planchets.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file exchangedb/pg_get_reserve_by_h_planchets.h + * @brief implementation of the get_reserve_by_h_planchets function for Postgres + * @author Christian Grothoff + * @author Özgür Kesim + */ +#ifndef PG_GET_RESERVE_BY_H_PLANCHETS_H +#define PG_GET_RESERVE_BY_H_PLANCHETS_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_exchangedb_plugin.h" +/** + * Obtain information about which reserve a coin was generated + * from given the hash of the blinded coin. + * + * @param cls closure + * @param h_planchets hash that uniquely identifies the withdraw request + * @param[out] reserve_pub set to information about the reserve (on success only) + * @param[out] withdraw_serial_id set to row of the @a h_commitment in withdraw + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TEH_PG_get_reserve_by_h_planchets ( + void *cls, + const struct TALER_HashBlindedPlanchetsP *h_planchets, + struct TALER_ReservePublicKeyP *reserve_pub, + uint64_t *withdraw_serial_id); + +#endif diff --git a/src/exchangedb/pg_get_reserve_history.c b/src/exchangedb/pg_get_reserve_history.c @@ -192,8 +192,6 @@ add_withdraw (void *cls, size_t num_h_coin_evs; size_t num_denom_hs; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_commitment", - &wd->h_commitment), GNUNET_PQ_result_spec_auto_from_type ("h_planchets", &wd->h_planchets), GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", @@ -835,8 +833,7 @@ TEH_PG_get_reserve_history ( PREPARE (pg, "get_withdraw_details", "SELECT" - " h_commitment" - ",h_planchets" + " h_planchets" ",amount_with_fee" ",reserve_sig" ",max_age" diff --git a/src/exchangedb/pg_get_withdraw.c b/src/exchangedb/pg_get_withdraw.c @@ -29,7 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_get_withdraw ( void *cls, - const struct TALER_WithdrawCommitmentHashP *wch, + const struct TALER_HashBlindedPlanchetsP *wch, struct TALER_EXCHANGEDB_Withdraw *wd) { enum GNUNET_DB_QueryStatus ret; @@ -43,8 +43,6 @@ TEH_PG_get_withdraw ( GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_commitment", - &wd->h_commitment), GNUNET_PQ_result_spec_auto_from_type ("h_planchets", &wd->h_planchets), GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", @@ -84,8 +82,7 @@ TEH_PG_get_withdraw ( PREPARE (pg, "get_withdraw", "SELECT" - " h_commitment" - ",h_planchets" + " h_planchets" ",reserve_sig" ",reserve_pub" ",max_age" @@ -101,7 +98,7 @@ TEH_PG_get_withdraw ( " LEFT JOIN denominations ON denominations.denominations_serial=denoms.id" ") AS denom_pub_hashes" " FROM withdraw" - " WHERE h_commitment=$1;"); + " WHERE h_planchets=$1;"); ret = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "get_withdraw", diff --git a/src/exchangedb/pg_get_withdraw.h b/src/exchangedb/pg_get_withdraw.h @@ -31,14 +31,14 @@ * request. * * @param cls the @e cls of this struct with the plugin-specific state - * @param wch hash that uniquely identifies the withdraw operation + * @param wch hash over all hashes of blinded planchets that uniquely identifies the withdraw operation * @param[out] wd corresponding details of the previous withdraw request if an entry was found * @return statement execution status */ enum GNUNET_DB_QueryStatus TEH_PG_get_withdraw ( void *cls, - const struct TALER_WithdrawCommitmentHashP *wch, + const struct TALER_HashBlindedPlanchetsP *wch, struct TALER_EXCHANGEDB_Withdraw *wd); #endif diff --git a/src/exchangedb/pg_insert_records_by_table.c b/src/exchangedb/pg_insert_records_by_table.c @@ -2267,7 +2267,7 @@ irbt_cb_table_withdraw ( struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type ( - &td->details.withdraw.h_commitment), + &td->details.withdraw.h_planchets), TALER_PQ_query_param_amount ( pg->conn, &td->details.withdraw.amount_with_fee), @@ -2276,10 +2276,6 @@ irbt_cb_table_withdraw ( &td->details.withdraw.max_age) : GNUNET_PQ_query_param_null (), td->details.withdraw.age_proof_required - ? GNUNET_PQ_query_param_auto_from_type ( - &td->details.withdraw.h_planchets) - : GNUNET_PQ_query_param_null (), - td->details.withdraw.age_proof_required ? GNUNET_PQ_query_param_uint32 ( &td->details.withdraw.noreveal_index) : GNUNET_PQ_query_param_null (), @@ -2296,16 +2292,15 @@ irbt_cb_table_withdraw ( "insert_into_table_withdraw", "INSERT INTO withdraw" "(withdraw_id" - ",h_commitment" + ",h_planchets" ",amount_with_fee" ",max_age" - ",h_planchets" ",noreveal_index" ",reserve_pub" ",reserve_sig" ",execution_date" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); + "($1, $2, $3, $4, $5, $6, $7, $8);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_withdraw", params); diff --git a/src/exchangedb/pg_lookup_records_by_table.c b/src/exchangedb/pg_lookup_records_by_table.c @@ -2670,8 +2670,8 @@ lrbt_cb_table_withdraw (void *cls, "withdraw_id", &td.serial), GNUNET_PQ_result_spec_auto_from_type ( - "h_commitment", - &td.details.withdraw.h_commitment), + "h_planchets", + &td.details.withdraw.h_planchets), TALER_PQ_RESULT_SPEC_AMOUNT ( "amount_with_fee", &td.details.withdraw.amount_with_fee), @@ -3719,7 +3719,7 @@ TEH_PG_lookup_records_by_table (void *cls, XPREPARE ("select_above_serial_by_table_withdraw", "SELECT" " withdraw_id" - ",h_commitment" + ",h_planchets" ",amount_with_fee" ",max_age" ",noreveal_index" diff --git a/src/exchangedb/pg_select_withdrawals_above_serial_id.c b/src/exchangedb/pg_select_withdrawals_above_serial_id.c @@ -79,7 +79,6 @@ withdraw_serial_helper_cb (void *cls, struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReserveSignatureP reserve_sig; struct GNUNET_TIME_Timestamp execution_date; - struct TALER_WithdrawCommitmentHashP h_commitment; struct TALER_HashBlindedPlanchetsP h_planchets; struct TALER_Amount amount_with_fee; uint64_t rowid; @@ -102,8 +101,6 @@ withdraw_serial_helper_cb (void *cls, &reserve_sig), GNUNET_PQ_result_spec_auto_from_type ("h_planchets", &h_planchets), - GNUNET_PQ_result_spec_auto_from_type ("h_commitment", - &h_commitment), GNUNET_PQ_result_spec_timestamp ("execution_date", &execution_date), TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", @@ -159,7 +156,6 @@ withdraw_serial_helper_cb (void *cls, num_evs, h_blind_evs, denom_serials, - &h_commitment, &h_planchets, ! no_max_age, (uint8_t) max_age, @@ -200,9 +196,8 @@ TEH_PG_select_withdrawals_above_serial_id ( "audit_get_withdraw_incr", "SELECT" " withdraw_id" - ",h_commitment" - ",h_blind_evs" ",h_planchets" + ",h_blind_evs" ",max_age" ",noreveal_index" ",denom_serials" diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c @@ -92,7 +92,7 @@ #include "pg_get_ready_deposit.h" #include "pg_get_refresh_reveal.h" #include "pg_get_reserve_balance.h" -#include "pg_get_reserve_by_h_commitment.h" +#include "pg_get_reserve_by_h_planchets.h" #include "pg_get_reserve_history.h" #include "pg_get_signature_for_known_coin.h" #include "pg_get_unfinished_close_requests.h" @@ -669,8 +669,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &TEH_PG_select_recoup_above_serial_id; plugin->select_recoup_refresh_above_serial_id = &TEH_PG_select_recoup_refresh_above_serial_id; - plugin->get_reserve_by_h_commitment - = &TEH_PG_get_reserve_by_h_commitment; + plugin->get_reserve_by_h_planchets + = &TEH_PG_get_reserve_by_h_planchets; plugin->get_old_coin_by_h_blind = &TEH_PG_get_old_coin_by_h_blind; plugin->insert_denomination_revocation diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c @@ -720,7 +720,6 @@ audit_reserve_in_cb (void *cls, * @param num_evs number of elements in @e h_blind_evs * @param h_blind_evs array @e num_evs of blinded hashes of the coin's public keys * @param denom_serials array @e num_evs of serial ids of denominations - * @param h_commitment hash of the commitment of the withdraw * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request * @param age_proof_required true if the withdraw request required an age proof. * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins. @@ -737,7 +736,6 @@ audit_reserve_out_cb (void *cls, size_t num_evs, const struct TALER_BlindedCoinHashP *h_blind_evs, const uint64_t *denom_serials, - const struct TALER_WithdrawCommitmentHashP *h_commitment, const struct TALER_HashBlindedPlanchetsP *h_planchets, bool age_proof_required, uint8_t max_age, @@ -1229,7 +1227,7 @@ run (void *cls) uint64_t rrc_serial; struct TALER_EXCHANGEDB_Refresh refresh; struct TALER_DenominationPublicKey *new_denom_pubs = NULL; - struct TALER_WithdrawCommitmentHashP h_commitment; + struct TALER_HashBlindedPlanchetsP h_planchets; uint64_t withdraw_serial_id; uint64_t melt_serial_id; struct TALER_PlanchetMasterSecretP ps; @@ -1443,23 +1441,13 @@ run (void *cls) .noreveal_index = 0, .reserve_pub = reserve_pub, .reserve_sig = cbc.reserve_sig, + .h_planchets = h_planchets, .num_coins = 1, .h_coin_evs = &cbc.h_coin_envelope, .denom_sigs = &cbc.sig, .denom_serials = &denom_serial, }; - /** - * Calculate the commitment - */ - TALER_wallet_withdraw_commit ( - &reserve_pub, - &global_amount, - &global_fees.withdraw, - &h_planchets, - NULL, - 0, - &commitment.h_commitment); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->do_withdraw (plugin->cls, @@ -1475,7 +1463,6 @@ run (void *cls) GNUNET_assert (! conflict); GNUNET_assert (balance_ok); - h_commitment = commitment.h_commitment; } FAILIF (GNUNET_OK != @@ -1489,15 +1476,15 @@ run (void *cls) global_value.fraction, global_value.currency)); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - plugin->get_reserve_by_h_commitment (plugin->cls, - &h_commitment, - &reserve_pub3, - &withdraw_serial_id)); + plugin->get_reserve_by_h_planchets (plugin->cls, + &h_planchets, + &reserve_pub3, + &withdraw_serial_id)); FAILIF (0 != GNUNET_memcmp (&reserve_pub, &reserve_pub3)); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->get_withdraw (plugin->cls, - &h_commitment, + &h_planchets, &withdraw)); FAILIF (0 != GNUNET_memcmp (&withdraw.reserve_sig, &cbc.reserve_sig)); diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h @@ -552,20 +552,6 @@ struct TALER_HashBlindedPlanchetsP /** - * @brief Hash to represent the commitment to a withdraw operation, - * which needs to be signed. It is calculated as hash over the struct - * TALER_WithdrawCommitmentP. - * - * The hash is needed for later calls to /reveal-withdraw (in case of age restriction) - * and /recoup. - */ -struct TALER_WithdrawCommitmentHashP -{ - struct GNUNET_HashCode hash; -}; - - -/** * @brief Type of online public keys used by the wallet to establish a purse and the associated contract meta data. */ struct TALER_PurseContractPublicKeyP @@ -4185,74 +4171,51 @@ TALER_wallet_blinded_planchets_hash ( const struct TALER_DenominationHashP h_denom_pubs[static num_planchets], struct TALER_HashBlindedPlanchetsP *h_planchets); + /** - * Calculate a windraw commitment hash for a withdraw request, - * optionally with age restriction. If age restriction is applied, - * the denominations for the coins MUST support it. + * @brief Sign the a withdraw request with the reserve's private key. * - * @param reserve_pub public key of the reserve * @param amount total amount to withdraw, excluding fees * @param fee total amount of fees * @param h_planchets running hash over all coins' TALER_BlindingCoinHash values * @param mask age mask to apply, or NULL, if not applicable. * @param max_age maximum age (in years) to commit to. Must be 0 if age restriction does not apply - * @param[out] wch resulting hash + * @param reserve_priv private key to sign with + * @param[out] reserve_sig resulting signature */ void -TALER_wallet_withdraw_commit ( - const struct TALER_ReservePublicKeyP *reserve_pub, +TALER_wallet_withdraw_sign ( const struct TALER_Amount *amount, const struct TALER_Amount *fee, const struct TALER_HashBlindedPlanchetsP *h_planchets, const struct TALER_AgeMask *mask, uint8_t max_age, - struct TALER_WithdrawCommitmentHashP *wch); - -/** - * Calculate a windraw commitment hash for a withdraw request - * without age restriction. Note that the denominations for - * the coins MUST NOT support age restriction. - * - * @param reserve_pub public key of the reserve - * @param amount total amount to withdraw, excluding fees - * @param fee total amount of fees - * @param h_planchets running hash over all coins' TALER_BlindingCoinHash values - * @param[out] wch resulting hash - */ -#define TALER_wallet_withdraw_commit_without_age(reserve_pub, \ - amount, \ - fee, \ - h_planchets, \ - wch) \ - TALER_wallet_withdraw_commit ((reserve_pub), \ - (amount), \ - (fee), \ - (h_planchets), \ - NULL, \ - 0, \ - (wch)); + const struct TALER_ReservePrivateKeyP *reserve_priv, + struct TALER_ReserveSignatureP *reserve_sig); /** - * @brief Sign the hash of a withdraw request with the reserve's private key. + * @brief Sign a withdraw request with no age restriction, using the reserve's public key * * @param amount total amount to withdraw, excluding fees * @param fee total amount of fees * @param h_planchets running hash over all coins' TALER_BlindingCoinHash values - * @param mask age mask to apply, or NULL, if not applicable. - * @param max_age maximum age (in years) to commit to. Must be 0 if age restriction does not apply * @param reserve_priv private key to sign with - * @param[out] reserve_sig resulting signature - */ -void -TALER_wallet_withdraw_sign ( - const struct TALER_Amount *amount, - const struct TALER_Amount *fee, - const struct TALER_HashBlindedPlanchetsP *h_planchets, - const struct TALER_AgeMask *mask, - uint8_t max_age, - const struct TALER_ReservePrivateKeyP *reserve_priv, - struct TALER_ReserveSignatureP *reserve_sig); + * @param reserve_sig resulting signature + * @return #GNUNET_OK if the signature is valid + */ +#define TALER_wallet_withdraw_sign_without_age(amount, \ + fee, \ + h_planchets, \ + reserve_priv, \ + reserve_sig) \ + TALER_wallet_withdraw_sign ((amount), \ + (fee), \ + (h_planchets), \ + NULL, \ + 0, \ + (reserve_priv), \ + (reserve_sig)); /** @@ -5386,7 +5349,7 @@ TALER_exchange_online_purse_status_verify ( * Create withdraw confirmation signature, for a request with age restriction set. * * @param scb function to call to create the signature - * @param h_commitment withdraw commitment that identifies the n*kappa blinded coins + * @param h_planchets withdraw commitment that identifies the n*kappa blinded coins * @param noreveal_index gamma cut-and-choose value chosen by the exchange * @param[out] pub where to write the exchange public key * @param[out] sig where to write the exchange signature @@ -5395,7 +5358,7 @@ TALER_exchange_online_purse_status_verify ( enum TALER_ErrorCode TALER_exchange_online_withdraw_age_confirmation_sign ( TALER_ExchangeSignCallback scb, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, uint32_t noreveal_index, struct TALER_ExchangePublicKeyP *pub, struct TALER_ExchangeSignatureP *sig); @@ -5404,7 +5367,7 @@ TALER_exchange_online_withdraw_age_confirmation_sign ( * Create withdraw confirmation signature, for a request without age restriction. * * @param scb function to call to create the signature - * @param h_commitment withdraw commitment that identifies the n blinded coins + * @param h_planchets withdraw commitment that identifies the n blinded coins * @param[out] pub where to write the exchange public key * @param[out] sig where to write the exchange signature * @return #TALER_EC_NONE on success @@ -5412,7 +5375,7 @@ TALER_exchange_online_withdraw_age_confirmation_sign ( enum TALER_ErrorCode TALER_exchange_online_withdraw_confirmation_sign ( TALER_ExchangeSignCallback scb, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, struct TALER_ExchangePublicKeyP *pub, struct TALER_ExchangeSignatureP *sig); @@ -5420,27 +5383,27 @@ TALER_exchange_online_withdraw_confirmation_sign ( /** * Verify an exchange withdraw confirmation, for a request without age restriction * - * @param h_commitment Commitment over all n coin candidates from the original request to withdraw + * @param h_planchets Commitment over all n coin candidates from the original request to withdraw * @param exchange_pub The public key used for signing * @param exchange_sig The signature from the exchange */ enum GNUNET_GenericReturnValue TALER_exchange_online_withdraw_confirmation_verify ( - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, const struct TALER_ExchangePublicKeyP *exchange_pub, const struct TALER_ExchangeSignatureP *exchange_sig); /** * Verify an exchange withdraw confirmation, for a withdraw request with age restriction * - * @param h_commitment Commitment over all n (or n*kappa) coin candidates from the original request to withdraw + * @param h_planchets Commitment over all n (or n*kappa) coin candidates from the original request to withdraw * @param noreveal_index The index returned by the exchange * @param exchange_pub The public key used for signing * @param exchange_sig The signature from the exchange */ enum GNUNET_GenericReturnValue TALER_exchange_online_withdraw_age_confirmation_verify ( - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, uint32_t noreveal_index, const struct TALER_ExchangePublicKeyP *exchange_pub, const struct TALER_ExchangeSignatureP *exchange_sig); diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h @@ -2183,11 +2183,6 @@ struct TALER_EXCHANGE_ReserveHistoryEntry uint8_t noreveal_index; /** - * The commitment of the withdrawal - */ - struct TALER_WithdrawCommitmentHashP h_commitment; - - /** * The running hash over all hashes of blinded planchets of the withrdawal */ struct TALER_HashBlindedPlanchetsP h_planchets; @@ -2826,7 +2821,7 @@ struct TALER_EXCHANGE_WithdrawResponse /** * The commitment of the withdraw request, needed for the later calls to /recoup */ - struct TALER_WithdrawCommitmentHashP h_commitment; + struct TALER_HashBlindedPlanchetsP h_planchets; } ok; @@ -2847,7 +2842,7 @@ struct TALER_EXCHANGE_WithdrawResponse * The commitment of the withdraw request with age restriction, needed for the * subsequent call to /reveal-withdraw and later calls to /recoup */ - struct TALER_WithdrawCommitmentHashP h_commitment; + struct TALER_HashBlindedPlanchetsP h_planchets; /** * The number of elements in @e coins, each referring to @@ -3018,7 +3013,7 @@ struct TALER_EXCHANGE_WithdrawBlindedResponse /** * The commitment of the withdraw request, needed for the later calls to /recoup */ - struct TALER_WithdrawCommitmentHashP h_commitment; + struct TALER_HashBlindedPlanchetsP h_planchets; } ok; @@ -3249,7 +3244,7 @@ typedef void * @param curl_ctx The curl context * @param exchange_url The base url of the exchange * @param num_coins Number of coin signatures to expect from the reveal - * @param h_commitment The commitment from the previous call to withdraw + * @param h_planchets The commitment from the previous call to withdraw * @param seeds TALER_CNC_KAPPA-1 tuple of seeds to reveal * @param res_cb A callback for the result, maybe NULL * @param res_cb_cls A closure for @e res_cb, maybe NULL @@ -3261,7 +3256,7 @@ TALER_EXCHANGE_reveal_withdraw ( struct GNUNET_CURL_Context *curl_ctx, const char *exchange_url, size_t num_coins, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, const struct TALER_RevealWithdrawMasterSeedsP *seeds, TALER_EXCHANGE_RevealWithdrawCallback res_cb, void *res_cb_cls); @@ -4085,7 +4080,7 @@ typedef void * @param denom_sig signature over the coin by the exchange using @a pk * @param exchange_vals contribution from the exchange on the withdraw * @param ps secret internals of the original planchet - * @param h_commitment hash of the commitment of the corresponding original withdraw request + * @param h_planchets hash of the commitment of the corresponding original withdraw request * @param recoup_cb the callback to call when the final result for this request is available * @param recoup_cb_cls closure for @a recoup_cb * @return NULL @@ -4101,7 +4096,7 @@ TALER_EXCHANGE_recoup ( const struct TALER_DenominationSignature *denom_sig, const struct TALER_ExchangeWithdrawValues *exchange_vals, const struct TALER_PlanchetMasterSecretP *ps, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, TALER_EXCHANGE_RecoupResultCallback recoup_cb, void *recoup_cb_cls); diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h @@ -838,13 +838,12 @@ struct TALER_EXCHANGEDB_TableData struct { - struct TALER_WithdrawCommitmentHashP h_commitment; + struct TALER_HashBlindedPlanchetsP h_planchets; struct TALER_Amount amount_with_fee; struct GNUNET_TIME_Timestamp execution_date; bool age_proof_required; uint16_t max_age; uint32_t noreveal_index; - struct TALER_HashBlindedPlanchetsP h_planchets; struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReserveSignatureP reserve_sig; uint64_t num_coins; @@ -1276,12 +1275,6 @@ struct TALER_EXCHANGEDB_Withdraw uint16_t noreveal_index; /** - * The hash over the struct TALER_WithdrawCommitmentP for - * this withdraw request. - */ - struct TALER_WithdrawCommitmentHashP h_commitment; - - /** * If @e age_proof_required is true, the running hash over all blinded coin * envelope's TALER_BlindedCoinHashP values. * It runs over ``kappa*num_coins``, starting with the hashes for the coins @@ -3301,7 +3294,6 @@ typedef void * @param num_evs number of elements in @e h_blind_evs * @param h_blind_evs array @e num_evs of blinded hashes of the coin's public keys * @param denom_serials array @e num_evs of serial ID's of denominations in our DB - * @param h_commitment hash of the commitment of the withdraw * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request * @param age_proof_required true if the withdraw request required an age proof. * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins. @@ -3319,7 +3311,6 @@ typedef enum GNUNET_GenericReturnValue size_t num_evs, const struct TALER_BlindedCoinHashP *h_blind_evs, const uint64_t *denom_serials, - const struct TALER_WithdrawCommitmentHashP *h_commitment, const struct TALER_HashBlindedPlanchetsP *h_planchets, bool age_proof_required, uint8_t max_age, @@ -4275,14 +4266,14 @@ struct TALER_EXCHANGEDB_Plugin * Used to ensure idempotency of the request. * * @param cls the @e cls of this struct with the plugin-specific state - * @param wch hash that uniquely identifies the withdraw operation + * @param h_planchets hash that uniquely identifies the withdraw operation * @param[out] wr corresponding details of the previous withdraw request if an entry was found * @return statement execution status */ enum GNUNET_DB_QueryStatus (*get_withdraw)( void *cls, - const struct TALER_WithdrawCommitmentHashP *ch, + const struct TALER_HashBlindedPlanchetsP *h_planchets, struct TALER_EXCHANGEDB_Withdraw *wr); /** @@ -5891,15 +5882,15 @@ struct TALER_EXCHANGEDB_Plugin * withdraw protocol, given the commitment. * * @param cls closure - * @param h_commitment hash of the commitment, identifying the withdraw operation + * @param h_planchets hash of the planchets, identifying the withdraw operation * @param[out] reserve_pub set to information about the reserve (on success only) * @param[out] withdraw_serial_id set to row of the @a h_commitment in withdraw * @return transaction status code */ enum GNUNET_DB_QueryStatus - (*get_reserve_by_h_commitment)( + (*get_reserve_by_h_planchets)( void *cls, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, struct TALER_ReservePublicKeyP *reserve_pub, uint64_t *withdraw_serial_id); diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h @@ -2769,7 +2769,7 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits, op (account_pub, const union TALER_AccountPublicKeyP) \ op (planchet_secret, const struct TALER_PlanchetMasterSecretP) \ op (withdraw_seed, const struct TALER_WithdrawMasterSeedP) \ - op (withdraw_commitment, const struct TALER_WithdrawCommitmentHashP) \ + op (withdraw_commitment, const struct TALER_HashBlindedPlanchetsP) \ op (kappa_seed, const struct TALER_KappaWithdrawMasterSeedP) \ op (refresh_secret, const struct TALER_RefreshMasterSecretP) \ op (reserve_pub, const struct TALER_ReservePublicKeyP) \ diff --git a/src/lib/exchange_api_recoup.c b/src/lib/exchange_api_recoup.c @@ -236,7 +236,7 @@ TALER_EXCHANGE_recoup ( const struct TALER_DenominationSignature *denom_sig, const struct TALER_ExchangeWithdrawValues *exchange_vals, const struct TALER_PlanchetMasterSecretP *ps, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, TALER_EXCHANGE_RecoupResultCallback recoup_cb, void *recoup_cb_cls) { @@ -272,8 +272,8 @@ TALER_EXCHANGE_recoup ( exchange_vals), GNUNET_JSON_pack_data_auto ("coin_sig", &ph->coin_sig), - GNUNET_JSON_pack_data_auto ("withdraw_commitment_hash", - h_commitment), + GNUNET_JSON_pack_data_auto ("h_planchets", + h_planchets), GNUNET_JSON_pack_data_auto ("coin_blind_key_secret", &bks)); switch (denom_sig->unblinded_sig->cipher) diff --git a/src/lib/exchange_api_reserves_history.c b/src/lib/exchange_api_reserves_history.c @@ -205,8 +205,7 @@ parse_withdraw (struct TALER_EXCHANGE_ReserveHistoryEntry *rh, struct TALER_Amount withdraw_amount; uint8_t max_age = 0; uint8_t noreveal_index = 0; - struct TALER_WithdrawCommitmentHashP h_commitment; - struct TALER_HashBlindedPlanchetsP h_planchets = {0}; + struct TALER_HashBlindedPlanchetsP h_planchets; struct TALER_ReserveSignatureP reserve_sig; const json_t *j_h_coin_evs; const json_t *j_denom_pub_hashes; @@ -217,8 +216,6 @@ parse_withdraw (struct TALER_EXCHANGE_ReserveHistoryEntry *rh, &reserve_sig), GNUNET_JSON_spec_uint16 ("num_coins", &num_coins), - GNUNET_JSON_spec_fixed_auto ("h_commitment", - &h_commitment), GNUNET_JSON_spec_fixed_auto ("h_planchets", &h_planchets), TALER_JSON_spec_amount_any ("amount", @@ -298,7 +295,6 @@ parse_withdraw (struct TALER_EXCHANGE_ReserveHistoryEntry *rh, rh->details.withdraw.age_restricted = ! no_max_age; rh->details.withdraw.max_age = max_age; rh->details.withdraw.h_planchets = h_planchets; - rh->details.withdraw.h_commitment = h_commitment; rh->details.withdraw.noreveal_index = noreveal_index; diff --git a/src/lib/exchange_api_reveal_withdraw.c b/src/lib/exchange_api_reveal_withdraw.c @@ -43,7 +43,7 @@ struct TALER_EXCHANGE_RevealWithdrawHandle /** * The commitment from the previous call withdraw */ - const struct TALER_WithdrawCommitmentHashP *h_commitment; + const struct TALER_HashBlindedPlanchetsP *h_planchets; /** * Number of coins for which to reveal tuples of seeds @@ -278,8 +278,8 @@ perform_protocol ( json_t *j_request_body; j_request_body = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("withdraw_commitment_h", - wrh->h_commitment), + GNUNET_JSON_pack_data_auto ("h_planchets", + wrh->h_planchets), GNUNET_JSON_pack_array_steal ("disclosed_batch_seeds", j_array_of_secrets)); GNUNET_assert (NULL != j_request_body); @@ -316,14 +316,14 @@ TALER_EXCHANGE_reveal_withdraw ( struct GNUNET_CURL_Context *curl_ctx, const char *exchange_url, size_t num_coins, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, const struct TALER_RevealWithdrawMasterSeedsP *seeds, TALER_EXCHANGE_RevealWithdrawCallback reveal_cb, void *reveal_cb_cls) { struct TALER_EXCHANGE_RevealWithdrawHandle *wrh = GNUNET_new (struct TALER_EXCHANGE_RevealWithdrawHandle); - wrh->h_commitment = h_commitment; + wrh->h_planchets = h_planchets; wrh->num_coins = num_coins; wrh->seeds = *seeds; wrh->callback = reveal_cb; diff --git a/src/lib/exchange_api_withdraw.c b/src/lib/exchange_api_withdraw.c @@ -172,11 +172,6 @@ struct TALER_EXCHANGE_WithdrawBlindedHandle struct TALER_EXCHANGE_Keys *keys; /** - * The hash of the withdraw commitment - */ - struct TALER_WithdrawCommitmentHashP h_commitment; - - /** * The hash of the planchets */ struct TALER_HashBlindedPlanchetsP h_planchets; @@ -428,7 +423,7 @@ withdraw_blinded_ok ( response.details.ok.num_sigs = wbh->num_input; response.details.ok.blinded_denom_sigs = denoms_sig; - response.details.ok.h_commitment = wbh->h_commitment; + response.details.ok.h_planchets = wbh->h_planchets; wbh->callback ( wbh->callback_cls, &response); @@ -459,7 +454,7 @@ withdraw_blinded_created ( struct TALER_EXCHANGE_WithdrawBlindedResponse response = { .hr.reply = j_response, .hr.http_status = MHD_HTTP_CREATED, - .details.created.h_commitment = wbh->h_commitment, + .details.created.h_planchets = wbh->h_planchets, .details.created.num_coins = wbh->num_input, }; struct TALER_ExchangeSignatureP exchange_sig; @@ -484,7 +479,7 @@ withdraw_blinded_created ( if (GNUNET_OK != TALER_exchange_online_withdraw_age_confirmation_verify ( - &wbh->h_commitment, + &wbh->h_planchets, response.details.created.noreveal_index, &response.details.created.exchange_pub, &exchange_sig)) @@ -808,20 +803,6 @@ perform_withdraw_protocol ( &wbh->h_planchets.hash); coins_hctx = NULL; - /** - * Calculate the commitment, needed when verify the response, - * or - in case of age restriction with required proof - a subsequent - * call to /reveal-withdraw - */ - TALER_wallet_withdraw_commit ( - &wbh->reserve_pub, - &wbh->amount, - &wbh->fee, - &wbh->h_planchets, - wbh->with_age_proof ? &wbh->age_mask : NULL, - wbh->with_age_proof ? wbh->max_age : 0, - &wbh->h_commitment); - /* Sign the request */ TALER_wallet_withdraw_sign ( &wbh->amount, @@ -926,7 +907,7 @@ copy_results ( resp.details.ok.num_sigs = wbr->details.ok.num_sigs; resp.details.ok.coin_details = details; - resp.details.ok.h_commitment = wbr->details.ok.h_commitment; + resp.details.ok.h_planchets = wbr->details.ok.h_planchets; memset (details, 0, sizeof(details)); diff --git a/src/testing/testing_api_cmd_age_withdraw.c b/src/testing/testing_api_cmd_age_withdraw.c @@ -146,7 +146,7 @@ struct AgeWithdrawState /** * The hash of the commitment, needed for the reveal step. */ - struct TALER_WithdrawCommitmentHashP h_commitment; + struct TALER_HashBlindedPlanchetsP h_planchets; /** * Set to the KYC requirement payto hash *if* the exchange replied with a @@ -196,8 +196,8 @@ age_withdraw_cb ( { case MHD_HTTP_CREATED: aws->noreveal_index = response->details.created.noreveal_index; - aws->h_commitment = response->details.created.h_commitment; - aws->reserve_history.details.withdraw.h_commitment = aws->h_commitment; + aws->h_planchets = response->details.created.h_planchets; + aws->reserve_history.details.withdraw.h_planchets = aws->h_planchets; aws->reserve_history.details.withdraw.noreveal_index = aws->noreveal_index; GNUNET_assert (aws->num_coins == response->details.created.num_coins); @@ -472,7 +472,7 @@ age_withdraw_traits ( &aws->denoms_pub[idx]), TALER_TESTING_make_trait_reserve_priv (&aws->reserve_priv), TALER_TESTING_make_trait_reserve_pub (&aws->reserve_pub), - TALER_TESTING_make_trait_withdraw_commitment (&aws->h_commitment), + TALER_TESTING_make_trait_withdraw_commitment (&aws->h_planchets), TALER_TESTING_make_trait_amounts (idx, &out->amount), /* FIXME[oec]: add legal requirement to response and handle it here, as well @@ -737,7 +737,7 @@ age_reveal_withdraw_run ( TALER_TESTING_interpreter_get_context (is), TALER_TESTING_get_exchange_url (is), aws->num_coins, - &aws->h_commitment, + &aws->h_planchets, &revealed_seeds, age_reveal_withdraw_cb, awrs); diff --git a/src/testing/testing_api_cmd_batch_withdraw.c b/src/testing/testing_api_cmd_batch_withdraw.c @@ -162,7 +162,7 @@ struct BatchWithdrawState /** * The commitment of the call to withdraw, needed later for recoup. */ - struct TALER_WithdrawCommitmentHashP h_commitment; + struct TALER_HashBlindedPlanchetsP h_planchets; }; @@ -205,7 +205,7 @@ batch_withdraw_cb (void *cls, TALER_denom_ewv_copy (&cs->details.alg_values, &wr->details.ok.coin_details[i].alg_values); } - ws->h_commitment = wr->details.ok.h_commitment; + ws->h_planchets = wr->details.ok.h_planchets; break; case MHD_HTTP_FORBIDDEN: /* nothing to check */ @@ -456,7 +456,7 @@ batch_withdraw_traits (void *cls, TALER_TESTING_make_trait_denom_sig (index, &cs->details.denom_sig), TALER_TESTING_make_trait_withdraw_seed (&ws->seed), - TALER_TESTING_make_trait_withdraw_commitment (&ws->h_commitment), + TALER_TESTING_make_trait_withdraw_commitment (&ws->h_planchets), TALER_TESTING_make_trait_reserve_priv (&ws->reserve_priv), TALER_TESTING_make_trait_reserve_pub (&ws->reserve_pub), TALER_TESTING_make_trait_amounts (index, diff --git a/src/testing/testing_api_cmd_recoup.c b/src/testing/testing_api_cmd_recoup.c @@ -191,7 +191,7 @@ recoup_run (void *cls, const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; const struct TALER_DenominationSignature *coin_sig; const struct TALER_WithdrawMasterSeedP *seed; - const struct TALER_WithdrawCommitmentHashP *h_commitment; + const struct TALER_HashBlindedPlanchetsP *h_planchets; struct TALER_PlanchetMasterSecretP secret; char *cref; unsigned int idx; @@ -271,7 +271,7 @@ recoup_run (void *cls, } if (GNUNET_OK != TALER_TESTING_get_trait_withdraw_commitment (coin_cmd, - &h_commitment)) + &h_planchets)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); @@ -302,7 +302,7 @@ recoup_run (void *cls, coin_sig, ewv, &secret, - h_commitment, + h_planchets, &recoup_cb, ps); GNUNET_assert (NULL != ps->ph); diff --git a/src/testing/testing_api_cmd_withdraw.c b/src/testing/testing_api_cmd_withdraw.c @@ -163,7 +163,7 @@ struct WithdrawState /** * The commitment for the withdraw operation, later needed for /recoup */ - struct TALER_WithdrawCommitmentHashP h_commitment; + struct TALER_HashBlindedPlanchetsP h_planchets; /** * Task scheduled to try later. @@ -304,7 +304,7 @@ withdraw_cb (void *cls, ws->bks = wr->details.ok.coin_details[0].blinding_key; TALER_denom_ewv_copy (&ws->exchange_vals, &wr->details.ok.coin_details[0].alg_values); - ws->h_commitment = wr->details.ok.h_commitment; + ws->h_planchets = wr->details.ok.h_planchets; if (0<ws->age) { /* copy the age-commitment data */ @@ -540,7 +540,7 @@ withdraw_traits (void *cls, TALER_TESTING_make_trait_coin_priv (0 /* only one coin */, &ws->coin_priv), TALER_TESTING_make_trait_withdraw_seed (&ws->seed), - TALER_TESTING_make_trait_withdraw_commitment (&ws->h_commitment), + TALER_TESTING_make_trait_withdraw_commitment (&ws->h_planchets), TALER_TESTING_make_trait_blinding_key (0 /* only one coin */, &ws->bks), TALER_TESTING_make_trait_exchange_wd_value (0 /* only one coin */, diff --git a/src/util/exchange_signatures.c b/src/util/exchange_signatures.c @@ -380,7 +380,7 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * @brief Format of the block signed by the Exchange in response to a - * successful "/reserves/$RESERVE_PUB/withdraw" request. + * successful "/withdraw" request. * If age restriction is set, the exchange hereby also * affirms that the commitment along with the maximum age group and * the amount were accepted. This also commits the exchange to a particular @@ -395,9 +395,9 @@ struct TALER_WithdrawConfirmationPS struct GNUNET_CRYPTO_EccSignaturePurpose purpose; /** - * Commitment made in the /reserves/$RESERVE_PUB/withdraw. + * Commitment made in the /withdraw call. */ - struct TALER_WithdrawCommitmentHashP h_commitment GNUNET_PACKED; + struct TALER_HashBlindedPlanchetsP h_planchets GNUNET_PACKED; /** * If age restriction does not apply to this withdrawal, @@ -416,7 +416,7 @@ GNUNET_NETWORK_STRUCT_END enum TALER_ErrorCode TALER_exchange_online_withdraw_age_confirmation_sign ( TALER_ExchangeSignCallback scb, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, uint32_t noreveal_index, struct TALER_ExchangePublicKeyP *pub, struct TALER_ExchangeSignatureP *sig) @@ -425,7 +425,7 @@ TALER_exchange_online_withdraw_age_confirmation_sign ( struct TALER_WithdrawConfirmationPS confirm = { .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW), .purpose.size = htonl (sizeof (confirm)), - .h_commitment = *h_commitment, + .h_planchets = *h_planchets, .noreveal_index = htonl (noreveal_index) }; @@ -438,7 +438,7 @@ TALER_exchange_online_withdraw_age_confirmation_sign ( enum TALER_ErrorCode TALER_exchange_online_withdraw_confirmation_sign ( TALER_ExchangeSignCallback scb, - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, struct TALER_ExchangePublicKeyP *pub, struct TALER_ExchangeSignatureP *sig) { @@ -446,7 +446,7 @@ TALER_exchange_online_withdraw_confirmation_sign ( struct TALER_WithdrawConfirmationPS confirm = { .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW), .purpose.size = htonl (sizeof (confirm)), - .h_commitment = *h_commitment, + .h_planchets = *h_planchets, .noreveal_index = htonl (0xFFFFFFFF) }; @@ -458,7 +458,7 @@ TALER_exchange_online_withdraw_confirmation_sign ( enum GNUNET_GenericReturnValue TALER_exchange_online_withdraw_age_confirmation_verify ( - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, uint32_t noreveal_index, const struct TALER_ExchangePublicKeyP *exchange_pub, const struct TALER_ExchangeSignatureP *exchange_sig) @@ -466,7 +466,7 @@ TALER_exchange_online_withdraw_age_confirmation_verify ( struct TALER_WithdrawConfirmationPS confirm = { .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW), .purpose.size = htonl (sizeof (confirm)), - .h_commitment = *h_commitment, + .h_planchets = *h_planchets, .noreveal_index = htonl (noreveal_index) }; @@ -486,14 +486,14 @@ TALER_exchange_online_withdraw_age_confirmation_verify ( enum GNUNET_GenericReturnValue TALER_exchange_online_withdraw_confirmation_verify ( - const struct TALER_WithdrawCommitmentHashP *h_commitment, + const struct TALER_HashBlindedPlanchetsP *h_planchets, const struct TALER_ExchangePublicKeyP *exchange_pub, const struct TALER_ExchangeSignatureP *exchange_sig) { struct TALER_WithdrawConfirmationPS confirm = { .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW), .purpose.size = htonl (sizeof (confirm)), - .h_commitment = *h_commitment, + .h_planchets = *h_planchets, .noreveal_index = htonl (0xFFFFFFFF) }; diff --git a/src/util/wallet_signatures.c b/src/util/wallet_signatures.c @@ -621,83 +621,53 @@ TALER_wallet_withdraw_verify_pre26 ( GNUNET_NETWORK_STRUCT_BEGIN /** - * @brief Format used to generate the commitment for a request to - * withdraw from a reserve. The hash of this struct is needed - * to sign a withdraw request and also in subsequent calls to - * /reveal-withdraw (in case of age restriction) or /recoup. + * @brief Format used for to generate the signature on a request to withdraw + * coins from a reserve. + * */ -struct TALER_WithdrawCommitmentP +struct TALER_WithdrawRequestPS { - /** - * The hash of the reserve's public key + * Purpose is #TALER_SIGNATURE_WALLET_WITHDRAW */ - struct TALER_HashReservePublicKeyP h_reserve_pub; + struct GNUNET_CRYPTO_EccSignaturePurpose purpose; /** - * The details of the withdraw request. - * This struct is also used in TALER_WithdrawRequestPS. + * Total value of all coins being exchanged (matching the denomination keys), + * without the fee. + * Note that the reserve must have a value of at least amount+fee. */ - struct TALER_WithdrawRequestDetailsP - { - - /** - * Total value of all coins being exchanged (matching the denomination keys), - * without the fee. - * Note that the reserve must have a value of at least amount+fee. - */ - struct TALER_AmountNBO amount; - - /** - * Total fee for the withdrawal. - * Note that the reserve must have a value of at least amount+fee. - */ - struct TALER_AmountNBO fee; - - /** - * Running SHA512 hash of all TALER_BlindedCoinHashP's - * of the of n coins, or n*kappa candidate coins in case of age restriction. - * In the later case, the coins' hashes are arranged [0..num_coins)...[0..num_coins), - * i.e. the coins are grouped per kappa-index. - * Note that each coin's TALER_BlindedCoinHashP also captures - * the hash of the public key of the corresponding denomination. - */ - struct TALER_HashBlindedPlanchetsP h_planchets GNUNET_PACKED; - - /** - * Maximum age group that the coins are going to be restricted to. - * MUST be 0 if no age restriction applies. - */ - uint32_t max_age_group; - - /** - * The mask that defines the age groups. - * MUST be the same for all denominations. - * MUST be 0 if no age restriction applies. - */ - struct TALER_AgeMask mask; - - } details GNUNET_PACKED; + struct TALER_AmountNBO amount; -}; + /** + * Total fee for the withdrawal. + * Note that the reserve must have a value of at least amount+fee. + */ + struct TALER_AmountNBO fee; + /** + * Running SHA512 hash of all TALER_BlindedCoinHashP's + * of the of n coins, or n*kappa candidate coins in case of age restriction. + * In the later case, the coins' hashes are arranged [0..num_coins)...[0..num_coins), + * i.e. the coins are grouped per kappa-index. + * Note that each coin's TALER_BlindedCoinHashP also captures + * the hash of the public key of the corresponding denomination. + */ + struct TALER_HashBlindedPlanchetsP h_planchets GNUNET_PACKED; -/** - * @brief Format used for to generate the signature on a request to withdraw - * coins from a reserve. - * - */ -struct TALER_WithdrawRequestPS -{ -/** - * Purpose is #TALER_SIGNATURE_WALLET_WITHDRAW - */ - struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + /** + * Maximum age group that the coins are going to be restricted to. + * MUST be 0 if no age restriction applies. + */ + uint32_t max_age_group; /** - * The details of the withdraw request + * The mask that defines the age groups. + * MUST be the same for all denominations. + * MUST be 0 if no age restriction applies. */ - struct TALER_WithdrawRequestDetailsP details GNUNET_PACKED; + struct TALER_AgeMask mask; + }; @@ -737,47 +707,6 @@ TALER_wallet_blinded_planchets_hash ( } -/** - * @brief fill a withdraw request details object from parameters - * - * @param amount the amount to withdraw, without fee's. - * @param fee the fee's for the request - * @param h_planchets the running hash over all coin's planchets - * @param mask the age mask, in case of age restriction, or NULL - * @param max_age the maximum age to commit to, if age restriction applies - * @param[out] req details of the withdraw request - */ -static void -fill_withdraw_request_details ( - const struct TALER_Amount *amount, - const struct TALER_Amount *fee, - const struct TALER_HashBlindedPlanchetsP *h_planchets, - const struct TALER_AgeMask *mask, - uint8_t max_age, - struct TALER_WithdrawRequestDetailsP *req) -{ - GNUNET_assert (NULL != req); - memset (req, - 0, - sizeof(*req)); - - GNUNET_assert (NULL != h_planchets); - req->h_planchets = *h_planchets; - if (NULL != mask) - { - req->mask = *mask; - req->max_age_group = - TALER_get_age_group (mask, - max_age); - } - TALER_amount_hton (&req->amount, - amount); - TALER_amount_hton (&req->fee, - fee); - -} - - struct TALER_HashReservePublicKeyP TALER_wallet_hash_reserve_pub ( const struct TALER_ReservePublicKeyP *reserve_pub) @@ -792,32 +721,6 @@ TALER_wallet_hash_reserve_pub ( void -TALER_wallet_withdraw_commit ( - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_Amount *amount, - const struct TALER_Amount *fee, - const struct TALER_HashBlindedPlanchetsP *h_planchets, - const struct TALER_AgeMask *mask, - uint8_t max_age, - struct TALER_WithdrawCommitmentHashP *wch) -{ - struct TALER_WithdrawCommitmentP com = { - .h_reserve_pub = TALER_wallet_hash_reserve_pub (reserve_pub), - }; - fill_withdraw_request_details (amount, - fee, - h_planchets, - mask, - max_age, - &com.details); - - GNUNET_CRYPTO_hash (&com, - sizeof(com), - &wch->hash); -} - - -void TALER_wallet_withdraw_sign ( const struct TALER_Amount *amount, const struct TALER_Amount *fee, @@ -832,12 +735,19 @@ TALER_wallet_withdraw_sign ( .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW), }; - fill_withdraw_request_details (amount, - fee, - h_planchets, - mask, - max_age, - &req.details); + GNUNET_assert (NULL != h_planchets); + req.h_planchets = *h_planchets; + if (NULL != mask) + { + req.mask = *mask; + req.max_age_group = + TALER_get_age_group (mask, + max_age); + } + TALER_amount_hton (&req.amount, + amount); + TALER_amount_hton (&req.fee, + fee); GNUNET_CRYPTO_eddsa_sign ( &reserve_priv->eddsa_priv, @@ -862,12 +772,19 @@ TALER_wallet_withdraw_verify ( .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW), }; - fill_withdraw_request_details (amount, - fee, - h_planchets, - mask, - max_age, - &req.details); + GNUNET_assert (NULL != h_planchets); + req.h_planchets = *h_planchets; + if (NULL != mask) + { + req.mask = *mask; + req.max_age_group = + TALER_get_age_group (mask, + max_age); + } + TALER_amount_hton (&req.amount, + amount); + TALER_amount_hton (&req.fee, + fee); return GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW,