From 499247a4805583dc67b9d6fef850ae86b4be1e32 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 27 Nov 2017 23:42:17 +0100 Subject: fixing #5178 --- src/util/crypto.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/crypto.c b/src/util/crypto.c index efc74850d..b44c31ff7 100644 --- a/src/util/crypto.c +++ b/src/util/crypto.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014, 2015 GNUnet e.V. + Copyright (C) 2014-2017 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 @@ -206,7 +206,7 @@ patch_private_key (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) */ void TALER_planchet_setup_refresh (const struct TALER_TransferSecretP *secret_seed, - unsigned int coin_num_salt, + uint32_t coin_num_salt, struct TALER_PlanchetSecretsP *ps) { uint32_t be_salt = htonl (coin_num_salt); @@ -314,4 +314,87 @@ TALER_planchet_to_coin (const struct TALER_DenominationPublicKey *dk, return GNUNET_OK; } + +/** + * Compute the commitment for a /refresh/melt operation from + * the respective public inputs. + * + * @param[out] rc set to the value the wallet must commit to + * @param kappa number of transfer public keys involved (must be #TALER_CNC_KAPPA) + * @param num_new_coins number of new coins to be created + * @param commitments array of @a kappa commitments + * @param coin_pub public key of the coin to be melted + * @param amount_with_fee amount to be melted, including fee + */ +void +TALER_refresh_get_commitment (struct TALER_RefreshCommitmentP *rc, + uint32_t kappa, + uint32_t num_new_coins, + const struct TALER_RefreshCommitmentEntry *rcs, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *amount_with_fee) +{ + struct GNUNET_HashContext *hash_context; + + hash_context = GNUNET_CRYPTO_hash_context_start (); + /* first, iterate over transfer public keys for hash_context */ + for (unsigned int i=0;i 0); /* sanity check */ + buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rcs[0].new_coins[i].dk->rsa_public_key, + &buf); + GNUNET_CRYPTO_hash_context_read (hash_context, + buf, + buf_size); + GNUNET_free (buf); + } + + /* next, add public key of coin and amount being refreshed */ + { + struct TALER_AmountNBO melt_amountn; + + GNUNET_CRYPTO_hash_context_read (hash_context, + coin_pub, + sizeof (struct TALER_CoinSpendPublicKeyP)); + TALER_amount_hton (&melt_amountn, + amount_with_fee); + GNUNET_CRYPTO_hash_context_read (hash_context, + &melt_amountn, + sizeof (struct TALER_AmountNBO)); + } + + /* finally, add all the envelopes */ + for (unsigned int i=0;inew_coins[j]; + + GNUNET_CRYPTO_hash_context_read (hash_context, + rcd->coin_ev, + rcd->coin_ev_size); + } + } + + /* Conclude */ + GNUNET_CRYPTO_hash_context_finish (hash_context, + &rc->session_hash); +} + + /* end of crypto.c */ -- cgit v1.2.3