2015-01-27 16:18:33 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2017-11-27 23:42:17 +01:00
|
|
|
Copyright (C) 2014-2017 Taler Systems SA
|
2015-01-27 16:18:33 +01:00
|
|
|
|
|
|
|
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
|
2016-07-07 17:55:25 +02:00
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2015-01-27 16:18:33 +01:00
|
|
|
*/
|
|
|
|
/**
|
2015-01-28 20:53:21 +01:00
|
|
|
* @file util/crypto.c
|
2015-01-27 16:18:33 +01:00
|
|
|
* @brief Cryptographic utility functions
|
|
|
|
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
|
|
|
|
* @author Florian Dold
|
|
|
|
* @author Benedikt Mueller
|
2015-01-28 20:53:21 +01:00
|
|
|
* @author Christian Grothoff
|
2015-01-27 16:18:33 +01:00
|
|
|
*/
|
|
|
|
#include "platform.h"
|
2015-07-15 11:40:51 +02:00
|
|
|
#include "taler_util.h"
|
2015-01-27 16:18:33 +01:00
|
|
|
#include <gcrypt.h>
|
|
|
|
|
2020-12-04 12:09:27 +01:00
|
|
|
/**
|
|
|
|
* Should we use the RSA blind signing implementation
|
|
|
|
* from libgnunetutil? The blinding only works
|
|
|
|
* correctly with a current version of libgnunetutil.
|
|
|
|
*
|
|
|
|
* Only applies to blinding and unblinding, but
|
|
|
|
* not to blind signing.
|
|
|
|
*
|
|
|
|
* FIXME: Can we define some macro for this in configure.ac
|
|
|
|
* to detect the version?
|
|
|
|
*/
|
|
|
|
#define USE_GNUNET_RSA_BLINDING 1
|
|
|
|
|
2015-01-27 16:18:33 +01:00
|
|
|
|
2015-01-27 22:01:08 +01:00
|
|
|
/**
|
|
|
|
* Function called by libgcrypt on serious errors.
|
|
|
|
* Prints an error message and aborts the process.
|
|
|
|
*
|
|
|
|
* @param cls NULL
|
|
|
|
* @param wtf unknown
|
|
|
|
* @param msg error message
|
|
|
|
*/
|
2015-01-27 16:18:33 +01:00
|
|
|
static void
|
2015-01-27 22:01:08 +01:00
|
|
|
fatal_error_handler (void *cls,
|
|
|
|
int wtf,
|
|
|
|
const char *msg)
|
2015-01-27 16:18:33 +01:00
|
|
|
{
|
2019-09-05 11:11:00 +02:00
|
|
|
(void) cls;
|
|
|
|
(void) wtf;
|
2015-05-18 18:52:52 +02:00
|
|
|
fprintf (stderr,
|
|
|
|
"Fatal error in libgcrypt: %s\n",
|
|
|
|
msg);
|
2019-08-25 16:18:24 +02:00
|
|
|
abort ();
|
2015-01-27 16:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-01-27 22:01:08 +01:00
|
|
|
* Initialize libgcrypt.
|
2015-01-27 16:18:33 +01:00
|
|
|
*/
|
2019-08-25 16:18:24 +02:00
|
|
|
void __attribute__ ((constructor))
|
2015-01-27 22:01:08 +01:00
|
|
|
TALER_gcrypt_init ()
|
2015-01-27 16:18:33 +01:00
|
|
|
{
|
2015-03-22 22:14:30 +01:00
|
|
|
gcry_set_fatalerror_handler (&fatal_error_handler,
|
|
|
|
NULL);
|
2015-05-18 18:52:52 +02:00
|
|
|
if (! gcry_check_version (NEED_LIBGCRYPT_VERSION))
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"libgcrypt version mismatch\n");
|
|
|
|
abort ();
|
|
|
|
}
|
2020-03-01 13:13:33 +01:00
|
|
|
/* Disable secure memory (we should never run on a system that
|
|
|
|
even uses swap space for memory). */
|
2015-01-27 16:18:33 +01:00
|
|
|
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
|
|
|
|
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-08-05 16:08:19 +02:00
|
|
|
* Check if a coin is valid; that is, whether the denomination key exists,
|
|
|
|
* is not expired, and the signature is correct.
|
2015-01-27 18:49:02 +01:00
|
|
|
*
|
2016-08-05 16:08:19 +02:00
|
|
|
* @param coin_public_info the coin public info to check for validity
|
2019-05-02 21:16:51 +02:00
|
|
|
* @param denom_pub denomination key, must match @a coin_public_info's `denom_pub_hash`
|
2016-08-05 16:08:19 +02:00
|
|
|
* @return #GNUNET_YES if the coin is valid,
|
|
|
|
* #GNUNET_NO if it is invalid
|
2020-03-31 20:57:11 +02:00
|
|
|
* #GNUNET_SYSERR if an internal error occurred
|
2015-01-27 18:49:02 +01:00
|
|
|
*/
|
|
|
|
int
|
2019-05-02 21:16:51 +02:00
|
|
|
TALER_test_coin_valid (const struct TALER_CoinPublicInfo *coin_public_info,
|
|
|
|
const struct TALER_DenominationPublicKey *denom_pub)
|
2015-01-27 18:49:02 +01:00
|
|
|
{
|
2016-08-05 16:08:19 +02:00
|
|
|
struct GNUNET_HashCode c_hash;
|
2020-03-01 13:13:33 +01:00
|
|
|
#if ENABLE_SANITY_CHECKS
|
2019-05-02 21:16:51 +02:00
|
|
|
struct GNUNET_HashCode d_hash;
|
2015-01-27 18:49:02 +01:00
|
|
|
|
2019-05-02 21:16:51 +02:00
|
|
|
GNUNET_CRYPTO_rsa_public_key_hash (denom_pub->rsa_public_key,
|
|
|
|
&d_hash);
|
|
|
|
GNUNET_assert (0 ==
|
|
|
|
GNUNET_memcmp (&d_hash,
|
|
|
|
&coin_public_info->denom_pub_hash));
|
|
|
|
#endif
|
2016-08-05 16:08:19 +02:00
|
|
|
GNUNET_CRYPTO_hash (&coin_public_info->coin_pub,
|
|
|
|
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
|
|
|
|
&c_hash);
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
GNUNET_CRYPTO_rsa_verify (&c_hash,
|
|
|
|
coin_public_info->denom_sig.rsa_signature,
|
2019-05-02 21:16:51 +02:00
|
|
|
denom_pub->rsa_public_key))
|
2016-08-05 16:08:19 +02:00
|
|
|
{
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
|
|
|
"coin signature is invalid\n");
|
|
|
|
return GNUNET_NO;
|
|
|
|
}
|
|
|
|
return GNUNET_YES;
|
2015-01-27 18:49:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-08 19:52:05 +02:00
|
|
|
/**
|
|
|
|
* Given the coin and the transfer private keys, compute the
|
|
|
|
* transfer secret. (Technically, we only need one of the two
|
|
|
|
* private keys, but the caller currently trivially only has
|
|
|
|
* the two private keys, so we derive one of the public keys
|
|
|
|
* internally to this function.)
|
|
|
|
*
|
|
|
|
* @param coin_priv coin key
|
|
|
|
* @param trans_priv transfer private key
|
2015-08-09 15:40:16 +02:00
|
|
|
* @param[out] ts computed transfer secret
|
2015-08-08 19:52:05 +02:00
|
|
|
*/
|
|
|
|
void
|
2020-03-07 00:28:07 +01:00
|
|
|
TALER_link_derive_transfer_secret (
|
|
|
|
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
|
|
|
const struct TALER_TransferPrivateKeyP *trans_priv,
|
|
|
|
struct TALER_TransferSecretP *ts)
|
2015-08-08 19:52:05 +02:00
|
|
|
{
|
|
|
|
struct TALER_CoinSpendPublicKeyP coin_pub;
|
|
|
|
|
|
|
|
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
|
|
|
|
&coin_pub.eddsa_pub);
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
GNUNET_CRYPTO_ecdh_eddsa (&trans_priv->ecdhe_priv,
|
|
|
|
&coin_pub.eddsa_pub,
|
|
|
|
&ts->key));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-15 18:12:21 +02:00
|
|
|
/**
|
|
|
|
* Decrypt the shared @a secret from the information in the
|
2016-08-05 16:08:19 +02:00
|
|
|
* @a trans_priv and @a coin_pub.
|
2015-05-01 09:59:18 +02:00
|
|
|
*
|
2015-05-16 18:26:34 +02:00
|
|
|
* @param trans_priv transfer private key
|
2015-04-15 18:12:21 +02:00
|
|
|
* @param coin_pub coin public key
|
2017-04-20 07:49:56 +02:00
|
|
|
* @param[out] transfer_secret set to the shared secret
|
2015-04-15 18:12:21 +02:00
|
|
|
*/
|
2016-08-05 16:08:19 +02:00
|
|
|
void
|
2020-03-07 00:28:07 +01:00
|
|
|
TALER_link_reveal_transfer_secret (
|
|
|
|
const struct TALER_TransferPrivateKeyP *trans_priv,
|
|
|
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
|
|
|
struct TALER_TransferSecretP *transfer_secret)
|
2015-04-15 18:12:21 +02:00
|
|
|
{
|
2016-08-05 16:08:19 +02:00
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
GNUNET_CRYPTO_ecdh_eddsa (&trans_priv->ecdhe_priv,
|
|
|
|
&coin_pub->eddsa_pub,
|
|
|
|
&transfer_secret->key));
|
2015-04-15 18:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-15 18:34:14 +02:00
|
|
|
/**
|
|
|
|
* Decrypt the shared @a secret from the information in the
|
2016-08-05 16:08:19 +02:00
|
|
|
* @a trans_priv and @a coin_pub.
|
2015-05-01 09:59:18 +02:00
|
|
|
*
|
2016-08-05 16:08:19 +02:00
|
|
|
* @param trans_pub transfer private key
|
|
|
|
* @param coin_priv coin public key
|
2017-04-20 07:49:56 +02:00
|
|
|
* @param[out] transfer_secret set to the shared secret
|
2015-04-15 18:34:14 +02:00
|
|
|
*/
|
2016-08-05 16:08:19 +02:00
|
|
|
void
|
2020-03-07 00:28:07 +01:00
|
|
|
TALER_link_recover_transfer_secret (
|
|
|
|
const struct TALER_TransferPublicKeyP *trans_pub,
|
|
|
|
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
|
|
|
|
struct TALER_TransferSecretP *transfer_secret)
|
2015-04-15 18:34:14 +02:00
|
|
|
{
|
2016-08-05 16:08:19 +02:00
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
GNUNET_CRYPTO_eddsa_ecdh (&coin_priv->eddsa_priv,
|
|
|
|
&trans_pub->ecdhe_pub,
|
|
|
|
&transfer_secret->key));
|
2015-04-15 18:34:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-15 18:12:21 +02:00
|
|
|
/**
|
2016-08-05 16:08:19 +02:00
|
|
|
* Setup information for a fresh coin.
|
2015-05-01 09:59:18 +02:00
|
|
|
*
|
2016-08-05 16:08:19 +02:00
|
|
|
* @param secret_seed seed to use for KDF to derive coin keys
|
|
|
|
* @param coin_num_salt number of the coin to include in KDF
|
2017-10-31 14:02:54 +01:00
|
|
|
* @param[out] ps value to initialize
|
2015-04-15 18:12:21 +02:00
|
|
|
*/
|
2016-08-05 16:08:19 +02:00
|
|
|
void
|
2017-10-31 12:44:17 +01:00
|
|
|
TALER_planchet_setup_refresh (const struct TALER_TransferSecretP *secret_seed,
|
2017-11-27 23:42:17 +01:00
|
|
|
uint32_t coin_num_salt,
|
2017-10-31 14:02:54 +01:00
|
|
|
struct TALER_PlanchetSecretsP *ps)
|
2015-04-15 18:12:21 +02:00
|
|
|
{
|
2016-08-05 16:08:19 +02:00
|
|
|
uint32_t be_salt = htonl (coin_num_salt);
|
2015-04-15 18:12:21 +02:00
|
|
|
|
2016-08-05 16:08:19 +02:00
|
|
|
GNUNET_assert (GNUNET_OK ==
|
2017-10-31 14:02:54 +01:00
|
|
|
GNUNET_CRYPTO_kdf (ps,
|
|
|
|
sizeof (*ps),
|
2016-08-05 16:08:19 +02:00
|
|
|
&be_salt,
|
|
|
|
sizeof (be_salt),
|
2016-08-08 12:43:59 +02:00
|
|
|
secret_seed,
|
|
|
|
sizeof (*secret_seed),
|
2016-08-05 16:08:19 +02:00
|
|
|
"taler-coin-derivation",
|
|
|
|
strlen ("taler-coin-derivation"),
|
|
|
|
NULL, 0));
|
2017-10-31 14:02:54 +01:00
|
|
|
}
|
2016-08-08 10:38:07 +02:00
|
|
|
|
|
|
|
|
2017-10-31 14:02:54 +01:00
|
|
|
/**
|
|
|
|
* Setup information for a fresh coin.
|
|
|
|
*
|
|
|
|
* @param[out] ps value to initialize
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
TALER_planchet_setup_random (struct TALER_PlanchetSecretsP *ps)
|
|
|
|
{
|
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
|
|
|
|
ps,
|
|
|
|
sizeof (*ps));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare a planchet for tipping. Creates and blinds a coin.
|
|
|
|
*
|
|
|
|
* @param dk denomination key for the coin to be created
|
|
|
|
* @param ps secret planchet internals (for #TALER_planchet_to_coin)
|
2020-04-12 16:44:28 +02:00
|
|
|
* @param[out] c_hash set to the hash of the public key of the coin (needed later)
|
2017-10-31 14:02:54 +01:00
|
|
|
* @param[out] pd set to the planchet detail for TALER_MERCHANT_tip_pickup() and
|
|
|
|
* other withdraw operations
|
|
|
|
* @return #GNUNET_OK on success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk,
|
|
|
|
const struct TALER_PlanchetSecretsP *ps,
|
2020-04-12 16:44:28 +02:00
|
|
|
struct GNUNET_HashCode *c_hash,
|
2017-10-31 14:02:54 +01:00
|
|
|
struct TALER_PlanchetDetail *pd)
|
|
|
|
{
|
|
|
|
struct TALER_CoinSpendPublicKeyP coin_pub;
|
|
|
|
|
|
|
|
GNUNET_CRYPTO_eddsa_key_get_public (&ps->coin_priv.eddsa_priv,
|
|
|
|
&coin_pub.eddsa_pub);
|
|
|
|
GNUNET_CRYPTO_hash (&coin_pub.eddsa_pub,
|
|
|
|
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
|
2020-04-12 16:44:28 +02:00
|
|
|
c_hash);
|
2017-10-31 14:02:54 +01:00
|
|
|
if (GNUNET_YES !=
|
2020-12-04 12:09:27 +01:00
|
|
|
TALER_rsa_blind (c_hash,
|
|
|
|
&ps->blinding_key.bks,
|
|
|
|
dk->rsa_public_key,
|
|
|
|
&pd->coin_ev,
|
|
|
|
&pd->coin_ev_size))
|
2017-10-31 14:02:54 +01:00
|
|
|
{
|
|
|
|
GNUNET_break_op (0);
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
GNUNET_CRYPTO_rsa_public_key_hash (dk->rsa_public_key,
|
|
|
|
&pd->denom_pub_hash);
|
|
|
|
return GNUNET_OK;
|
2015-04-15 18:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-31 14:02:54 +01:00
|
|
|
/**
|
|
|
|
* Obtain a coin from the planchet's secrets and the blind signature
|
|
|
|
* of the exchange.
|
|
|
|
*
|
|
|
|
* @param dk denomination key, must match what was given to #TALER_planchet_prepare()
|
|
|
|
* @param blind_sig blind signature from the exchange
|
|
|
|
* @param ps secrets from #TALER_planchet_prepare()
|
|
|
|
* @param c_hash hash of the coin's public key for verification of the signature
|
|
|
|
* @param[out] coin set to the details of the fresh coin
|
|
|
|
* @return #GNUNET_OK on success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
TALER_planchet_to_coin (const struct TALER_DenominationPublicKey *dk,
|
|
|
|
const struct GNUNET_CRYPTO_RsaSignature *blind_sig,
|
|
|
|
const struct TALER_PlanchetSecretsP *ps,
|
|
|
|
const struct GNUNET_HashCode *c_hash,
|
|
|
|
struct TALER_FreshCoin *coin)
|
|
|
|
{
|
|
|
|
struct GNUNET_CRYPTO_RsaSignature *sig;
|
2016-08-05 16:08:19 +02:00
|
|
|
|
2020-12-04 12:09:27 +01:00
|
|
|
sig = TALER_rsa_unblind (blind_sig,
|
|
|
|
&ps->blinding_key.bks,
|
|
|
|
dk->rsa_public_key);
|
2017-10-31 14:02:54 +01:00
|
|
|
if (GNUNET_OK !=
|
|
|
|
GNUNET_CRYPTO_rsa_verify (c_hash,
|
|
|
|
sig,
|
|
|
|
dk->rsa_public_key))
|
|
|
|
{
|
|
|
|
GNUNET_break_op (0);
|
|
|
|
GNUNET_CRYPTO_rsa_signature_free (sig);
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
coin->sig.rsa_signature = sig;
|
|
|
|
coin->coin_priv = ps->coin_priv;
|
|
|
|
return GNUNET_OK;
|
|
|
|
}
|
2016-08-05 16:08:19 +02:00
|
|
|
|
2017-11-27 23:42:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2020-01-18 14:16:40 +01:00
|
|
|
* @param rcs commitments array of @a kappa commitments
|
2017-11-27 23:42:17 +01:00
|
|
|
* @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 */
|
2019-08-25 16:18:24 +02:00
|
|
|
for (unsigned int i = 0; i<kappa; i++)
|
2017-11-27 23:42:17 +01:00
|
|
|
{
|
|
|
|
GNUNET_CRYPTO_hash_context_read (hash_context,
|
|
|
|
&rcs[i].transfer_pub,
|
|
|
|
sizeof (struct TALER_TransferPublicKeyP));
|
|
|
|
}
|
|
|
|
/* next, add all of the hashes from the denomination keys to the
|
|
|
|
hash_context */
|
2019-08-25 16:18:24 +02:00
|
|
|
for (unsigned int i = 0; i<num_new_coins; i++)
|
2017-11-27 23:42:17 +01:00
|
|
|
{
|
2020-03-17 01:09:16 +01:00
|
|
|
void *buf;
|
2017-11-27 23:42:17 +01:00
|
|
|
size_t buf_size;
|
|
|
|
|
|
|
|
/* The denomination keys should / must all be identical regardless
|
|
|
|
of what offset we use, so we use [0]. */
|
|
|
|
GNUNET_assert (kappa > 0); /* sanity check */
|
2019-08-25 16:18:24 +02:00
|
|
|
buf_size = GNUNET_CRYPTO_rsa_public_key_encode (
|
|
|
|
rcs[0].new_coins[i].dk->rsa_public_key,
|
|
|
|
&buf);
|
2017-11-27 23:42:17 +01:00
|
|
|
GNUNET_CRYPTO_hash_context_read (hash_context,
|
2019-08-25 16:18:24 +02:00
|
|
|
buf,
|
|
|
|
buf_size);
|
2017-11-27 23:42:17 +01:00
|
|
|
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 */
|
2019-08-25 16:18:24 +02:00
|
|
|
for (unsigned int i = 0; i<kappa; i++)
|
2017-11-27 23:42:17 +01:00
|
|
|
{
|
|
|
|
const struct TALER_RefreshCommitmentEntry *rce = &rcs[i];
|
|
|
|
|
2019-08-25 16:18:24 +02:00
|
|
|
for (unsigned int j = 0; j<num_new_coins; j++)
|
2017-11-27 23:42:17 +01:00
|
|
|
{
|
|
|
|
const struct TALER_RefreshCoinData *rcd = &rce->new_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-04 12:09:27 +01:00
|
|
|
/**
|
|
|
|
* Blinds the given message with the given blinding key
|
|
|
|
*
|
|
|
|
* @param hash hash of the message to sign
|
|
|
|
* @param bkey the blinding key
|
|
|
|
* @param pkey the public key of the signer
|
|
|
|
* @param[out] buf set to a buffer with the blinded message to be signed
|
|
|
|
* @param[out] buf_size number of bytes stored in @a buf
|
|
|
|
* @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
TALER_rsa_blind (const struct GNUNET_HashCode *hash,
|
|
|
|
const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks,
|
|
|
|
struct GNUNET_CRYPTO_RsaPublicKey *pkey,
|
|
|
|
void **buf,
|
|
|
|
size_t *buf_size)
|
|
|
|
{
|
|
|
|
#if USE_GNUNET_RSA_BLINDING
|
|
|
|
return GNUNET_CRYPTO_rsa_blind (hash,
|
|
|
|
bks,
|
|
|
|
pkey,
|
|
|
|
buf,
|
|
|
|
buf_size);
|
|
|
|
#else
|
|
|
|
# error "FIXME: implement"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unblind a blind-signed signature. The signature should have been generated
|
|
|
|
* with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with
|
|
|
|
* #GNUNET_CRYPTO_rsa_blind().
|
|
|
|
*
|
|
|
|
* @param sig the signature made on the blinded signature purpose
|
|
|
|
* @param bks the blinding key secret used to blind the signature purpose
|
|
|
|
* @param pkey the public key of the signer
|
|
|
|
* @return unblinded signature on success, NULL if RSA key is bad or malicious.
|
|
|
|
*/
|
|
|
|
struct GNUNET_CRYPTO_RsaSignature *
|
|
|
|
TALER_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig,
|
|
|
|
const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks,
|
|
|
|
struct GNUNET_CRYPTO_RsaPublicKey *pkey)
|
|
|
|
{
|
|
|
|
#if USE_GNUNET_RSA_BLINDING
|
|
|
|
return GNUNET_CRYPTO_rsa_unblind (sig,
|
|
|
|
bks,
|
|
|
|
pkey);
|
|
|
|
#else
|
|
|
|
# error "FIXME: implement"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-27 16:18:33 +01:00
|
|
|
/* end of crypto.c */
|