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>
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 17:10:09 +01:00
|
|
|
enum GNUNET_GenericReturnValue
|
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
|
|
|
{
|
2021-10-22 22:30:33 +02:00
|
|
|
struct TALER_CoinPubHash c_hash;
|
2020-03-01 13:13:33 +01:00
|
|
|
#if ENABLE_SANITY_CHECKS
|
2021-10-22 22:30:33 +02:00
|
|
|
struct TALER_DenominationHash d_hash;
|
2015-01-27 18:49:02 +01:00
|
|
|
|
2021-10-22 22:30:33 +02:00
|
|
|
TALER_denom_pub_hash (denom_pub,
|
|
|
|
&d_hash);
|
2019-05-02 21:16:51 +02:00
|
|
|
GNUNET_assert (0 ==
|
|
|
|
GNUNET_memcmp (&d_hash,
|
|
|
|
&coin_public_info->denom_pub_hash));
|
|
|
|
#endif
|
2021-10-22 22:30:33 +02:00
|
|
|
// FIXME-Oec: replace with function that
|
|
|
|
// also hashes the age vector if we have
|
|
|
|
// one!
|
2016-08-05 16:08:19 +02:00
|
|
|
GNUNET_CRYPTO_hash (&coin_public_info->coin_pub,
|
|
|
|
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
|
2021-10-22 22:30:33 +02:00
|
|
|
&c_hash.hash);
|
2016-08-05 16:08:19 +02:00
|
|
|
if (GNUNET_OK !=
|
2021-10-22 22:30:33 +02:00
|
|
|
TALER_denom_pub_verify (denom_pub,
|
|
|
|
&coin_public_info->denom_sig,
|
|
|
|
&c_hash))
|
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
|
|
|
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));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
void
|
2021-12-22 12:52:54 +01:00
|
|
|
cs_blinding_seed_derive (const struct
|
|
|
|
TALER_CoinSpendPrivateKeyP *coin_priv,
|
2021-12-22 11:45:22 +01:00
|
|
|
const struct GNUNET_CRYPTO_CsRPublic r_pub[2],
|
|
|
|
struct GNUNET_CRYPTO_CsNonce *blind_seed)
|
2021-12-17 14:35:10 +01:00
|
|
|
{
|
2021-12-22 11:45:22 +01:00
|
|
|
GNUNET_assert (GNUNET_YES ==
|
|
|
|
GNUNET_CRYPTO_hkdf (blind_seed,
|
|
|
|
sizeof (*blind_seed),
|
|
|
|
GCRY_MD_SHA512,
|
|
|
|
GCRY_MD_SHA256,
|
|
|
|
"bseed",
|
|
|
|
strlen ("bseed"),
|
2021-12-22 12:52:54 +01:00
|
|
|
coin_priv,
|
|
|
|
sizeof(*coin_priv),
|
2021-12-22 11:45:22 +01:00
|
|
|
r_pub,
|
|
|
|
sizeof(struct GNUNET_CRYPTO_CsRPublic) * 2,
|
|
|
|
NULL,
|
|
|
|
0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TALER_cs_withdraw_nonce_derive (const struct
|
|
|
|
TALER_CoinSpendPrivateKeyP *coin_priv,
|
2022-01-17 09:37:36 +01:00
|
|
|
struct TALER_CsNonce *nonce)
|
2021-12-22 11:45:22 +01:00
|
|
|
{
|
|
|
|
GNUNET_assert (GNUNET_YES ==
|
|
|
|
GNUNET_CRYPTO_hkdf (nonce,
|
|
|
|
sizeof (*nonce),
|
|
|
|
GCRY_MD_SHA512,
|
|
|
|
GCRY_MD_SHA256,
|
|
|
|
"n",
|
|
|
|
strlen ("n"),
|
|
|
|
coin_priv,
|
|
|
|
sizeof(*coin_priv),
|
|
|
|
NULL,
|
|
|
|
0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-17 09:37:36 +01:00
|
|
|
void
|
|
|
|
TALER_cs_withdraw_nonce_generate (struct TALER_CsNonce *nonce)
|
|
|
|
{
|
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
|
|
|
|
nonce,
|
|
|
|
sizeof (*nonce));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-22 11:45:22 +01:00
|
|
|
void
|
2022-01-09 16:49:27 +01:00
|
|
|
TALER_planchet_blinding_secret_create (struct TALER_PlanchetSecretsP *ps,
|
2022-01-11 21:21:18 +01:00
|
|
|
const struct
|
|
|
|
TALER_ExchangeWithdrawValues *alg_values)
|
2021-12-22 11:45:22 +01:00
|
|
|
{
|
2022-01-16 17:02:15 +01:00
|
|
|
switch (alg_values->cipher)
|
2021-12-17 14:35:10 +01:00
|
|
|
{
|
|
|
|
case TALER_DENOMINATION_INVALID:
|
|
|
|
GNUNET_break (0);
|
|
|
|
return;
|
|
|
|
case TALER_DENOMINATION_RSA:
|
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
|
2022-01-09 16:49:27 +01:00
|
|
|
&ps->blinding_key.rsa_bks,
|
2021-12-17 14:35:10 +01:00
|
|
|
sizeof (struct
|
|
|
|
GNUNET_CRYPTO_RsaBlindingKeySecret));
|
|
|
|
return;
|
|
|
|
case TALER_DENOMINATION_CS:
|
|
|
|
{
|
2022-01-09 16:49:27 +01:00
|
|
|
cs_blinding_seed_derive (&ps->coin_priv,
|
2022-01-11 21:21:18 +01:00
|
|
|
alg_values->details.cs_values.r_pub.r_pub,
|
2022-01-09 16:49:27 +01:00
|
|
|
&ps->blinding_key.nonce);
|
2021-12-17 14:35:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
GNUNET_break (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-22 11:45:22 +01:00
|
|
|
/**
|
|
|
|
* @brief setup a random planchet
|
|
|
|
* In Case of RSA planchet, the bks gets set
|
2021-12-27 16:21:26 +01:00
|
|
|
* In Case of Clause Schnorr this will be set in future
|
2021-12-22 11:45:22 +01:00
|
|
|
*/
|
2021-12-17 14:35:10 +01:00
|
|
|
void
|
|
|
|
TALER_planchet_setup_random (struct TALER_PlanchetSecretsP *ps,
|
2022-01-16 17:02:15 +01:00
|
|
|
const struct
|
|
|
|
TALER_ExchangeWithdrawValues *alg_values)
|
2017-10-31 14:02:54 +01:00
|
|
|
{
|
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
|
2021-12-17 14:35:10 +01:00
|
|
|
&ps->coin_priv,
|
|
|
|
sizeof (struct TALER_CoinSpendPrivateKeyP));
|
2022-01-16 17:02:15 +01:00
|
|
|
switch (alg_values->cipher)
|
2021-12-22 11:45:22 +01:00
|
|
|
{
|
|
|
|
case TALER_DENOMINATION_INVALID:
|
|
|
|
GNUNET_break (0);
|
|
|
|
return;
|
|
|
|
case TALER_DENOMINATION_RSA:
|
2022-01-16 17:02:15 +01:00
|
|
|
TALER_planchet_blinding_secret_create (ps,
|
|
|
|
alg_values);
|
2021-12-22 11:45:22 +01:00
|
|
|
return;
|
|
|
|
case TALER_DENOMINATION_CS:
|
|
|
|
// Will be set in a later stage for Clause Blind Schnorr Scheme
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
GNUNET_break (0);
|
|
|
|
}
|
2017-10-31 14:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 17:10:09 +01:00
|
|
|
enum GNUNET_GenericReturnValue
|
2017-10-31 14:02:54 +01:00
|
|
|
TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk,
|
2022-01-11 21:21:18 +01:00
|
|
|
const struct TALER_ExchangeWithdrawValues *alg_values,
|
2021-12-31 15:24:41 +01:00
|
|
|
struct TALER_PlanchetSecretsP *ps,
|
2021-10-22 22:30:33 +02:00
|
|
|
struct TALER_CoinPubHash *c_hash,
|
2021-12-31 15:24:41 +01:00
|
|
|
struct TALER_PlanchetDetail *pd)
|
2017-10-31 14:02:54 +01:00
|
|
|
{
|
|
|
|
struct TALER_CoinSpendPublicKeyP coin_pub;
|
|
|
|
|
2022-01-16 17:02:15 +01:00
|
|
|
GNUNET_assert (alg_values->cipher == dk->cipher);
|
|
|
|
|
2017-10-31 14:02:54 +01:00
|
|
|
GNUNET_CRYPTO_eddsa_key_get_public (&ps->coin_priv.eddsa_priv,
|
|
|
|
&coin_pub.eddsa_pub);
|
2021-12-22 16:55:34 +01:00
|
|
|
|
|
|
|
switch (dk->cipher)
|
2017-10-31 14:02:54 +01:00
|
|
|
{
|
2021-12-22 16:55:34 +01:00
|
|
|
case TALER_DENOMINATION_RSA:
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
TALER_denom_blind (dk,
|
|
|
|
&ps->blinding_key,
|
|
|
|
NULL, /* FIXME-Oec */
|
|
|
|
&coin_pub,
|
2022-01-16 17:02:15 +01:00
|
|
|
alg_values,
|
2021-12-22 16:55:34 +01:00
|
|
|
c_hash,
|
|
|
|
&pd->blinded_planchet))
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TALER_DENOMINATION_CS:
|
2021-12-31 17:38:20 +01:00
|
|
|
if (GNUNET_OK !=
|
|
|
|
TALER_denom_blind (dk,
|
|
|
|
&ps->blinding_key,
|
|
|
|
NULL, /* FIXME-Oec */
|
|
|
|
&coin_pub,
|
2022-01-11 21:21:18 +01:00
|
|
|
alg_values,
|
2021-12-31 17:38:20 +01:00
|
|
|
c_hash,
|
2022-01-11 21:21:18 +01:00
|
|
|
&pd->blinded_planchet))
|
2021-12-22 16:55:34 +01:00
|
|
|
{
|
2021-12-31 17:38:20 +01:00
|
|
|
GNUNET_break (0);
|
|
|
|
return GNUNET_SYSERR;
|
2021-12-22 16:55:34 +01:00
|
|
|
}
|
2021-12-31 17:38:20 +01:00
|
|
|
break;
|
2021-12-22 16:55:34 +01:00
|
|
|
default:
|
2021-11-25 10:00:55 +01:00
|
|
|
GNUNET_break (0);
|
2017-10-31 14:02:54 +01:00
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
2021-12-22 16:55:34 +01:00
|
|
|
|
2022-01-04 17:46:36 +01:00
|
|
|
pd->blinded_planchet.cipher = dk->cipher;
|
2021-10-22 22:30:33 +02:00
|
|
|
TALER_denom_pub_hash (dk,
|
|
|
|
&pd->denom_pub_hash);
|
2017-10-31 14:02:54 +01:00
|
|
|
return GNUNET_OK;
|
2015-04-15 18:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-16 17:02:15 +01:00
|
|
|
void
|
|
|
|
TALER_blinded_planchet_free (struct TALER_BlindedPlanchet *blinded_planchet)
|
|
|
|
{
|
|
|
|
switch (blinded_planchet->cipher)
|
|
|
|
{
|
|
|
|
case TALER_DENOMINATION_RSA:
|
|
|
|
GNUNET_free (blinded_planchet->details.rsa_blinded_planchet.blinded_msg);
|
|
|
|
break;
|
|
|
|
case TALER_DENOMINATION_CS:
|
|
|
|
// nothing to do for CS
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GNUNET_break (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 17:10:09 +01:00
|
|
|
enum GNUNET_GenericReturnValue
|
2021-12-31 15:24:41 +01:00
|
|
|
TALER_planchet_to_coin (const struct TALER_DenominationPublicKey *dk,
|
|
|
|
const struct
|
|
|
|
TALER_BlindedDenominationSignature *blind_sig,
|
|
|
|
const struct TALER_PlanchetSecretsP *ps,
|
|
|
|
const struct TALER_CoinPubHash *c_hash,
|
2022-01-11 21:21:18 +01:00
|
|
|
const struct TALER_ExchangeWithdrawValues *alg_values,
|
2021-12-31 15:24:41 +01:00
|
|
|
struct TALER_FreshCoin *coin)
|
2017-10-31 14:02:54 +01:00
|
|
|
{
|
2021-10-22 22:30:33 +02:00
|
|
|
struct TALER_DenominationSignature sig;
|
|
|
|
|
2022-01-11 21:21:18 +01:00
|
|
|
if (dk->cipher != blind_sig->cipher
|
|
|
|
&& dk->cipher != alg_values->cipher)
|
2022-01-04 17:46:36 +01:00
|
|
|
{
|
|
|
|
GNUNET_break_op (0);
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
|
2021-12-23 12:36:04 +01:00
|
|
|
switch (dk->cipher)
|
2021-11-05 22:48:11 +01:00
|
|
|
{
|
2021-12-23 12:36:04 +01:00
|
|
|
case TALER_DENOMINATION_RSA:
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
TALER_denom_sig_unblind (&sig,
|
|
|
|
blind_sig,
|
|
|
|
&ps->blinding_key,
|
|
|
|
dk))
|
|
|
|
{
|
|
|
|
GNUNET_break_op (0);
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TALER_DENOMINATION_CS:
|
|
|
|
{
|
2022-01-13 19:30:20 +01:00
|
|
|
struct GNUNET_CRYPTO_CsC c[2];
|
|
|
|
struct GNUNET_CRYPTO_CsBlindingSecret bs[2];
|
|
|
|
struct TALER_DenominationCsPublicR r_pub_blind;
|
|
|
|
|
|
|
|
GNUNET_CRYPTO_cs_blinding_secrets_derive (&ps->blinding_key.nonce, bs);
|
|
|
|
|
|
|
|
GNUNET_CRYPTO_cs_calc_blinded_c (bs,
|
|
|
|
alg_values->details.cs_values.r_pub.r_pub,
|
|
|
|
&dk->details.cs_public_key,
|
|
|
|
&c_hash->hash,
|
|
|
|
sizeof(struct GNUNET_HashCode),
|
|
|
|
c,
|
|
|
|
r_pub_blind.r_pub);
|
|
|
|
|
|
|
|
sig.details.cs_signature.r_point
|
|
|
|
= r_pub_blind.r_pub[blind_sig->details.blinded_cs_answer.b];
|
|
|
|
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
TALER_denom_sig_unblind (&sig,
|
|
|
|
blind_sig,
|
|
|
|
&ps->blinding_key,
|
|
|
|
dk))
|
|
|
|
{
|
|
|
|
GNUNET_break_op (0);
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
break;
|
2021-12-23 12:36:04 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
GNUNET_break (0);
|
2021-11-05 22:48:11 +01:00
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
2021-12-23 12:36:04 +01:00
|
|
|
|
2017-10-31 14:02:54 +01:00
|
|
|
if (GNUNET_OK !=
|
2021-10-22 22:30:33 +02:00
|
|
|
TALER_denom_pub_verify (dk,
|
|
|
|
&sig,
|
|
|
|
c_hash))
|
2017-10-31 14:02:54 +01:00
|
|
|
{
|
|
|
|
GNUNET_break_op (0);
|
2021-11-05 22:48:11 +01:00
|
|
|
TALER_denom_sig_free (&sig);
|
2017-10-31 14:02:54 +01:00
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
2021-12-27 16:21:26 +01:00
|
|
|
|
2021-10-22 22:30:33 +02:00
|
|
|
coin->sig = sig;
|
2017-10-31 14:02:54 +01:00
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
{
|
2021-10-22 22:30:33 +02:00
|
|
|
struct TALER_DenominationHash denom_hash;
|
2017-11-27 23:42:17 +01:00
|
|
|
|
|
|
|
/* The denomination keys should / must all be identical regardless
|
|
|
|
of what offset we use, so we use [0]. */
|
|
|
|
GNUNET_assert (kappa > 0); /* sanity check */
|
2021-10-22 22:30:33 +02:00
|
|
|
TALER_denom_pub_hash (rcs[0].new_coins[i].dk,
|
|
|
|
&denom_hash);
|
2017-11-27 23:42:17 +01:00
|
|
|
GNUNET_CRYPTO_hash_context_read (hash_context,
|
2021-10-22 22:30:33 +02:00
|
|
|
&denom_hash,
|
|
|
|
sizeof (denom_hash));
|
2017-11-27 23:42:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-16 17:02:15 +01:00
|
|
|
enum GNUNET_GenericReturnValue
|
|
|
|
TALER_coin_ev_hash (const struct TALER_BlindedPlanchet *blinded_planchet,
|
2022-01-17 15:10:47 +01:00
|
|
|
const struct TALER_DenominationPublicKey *denom_pub,
|
2021-10-25 18:02:27 +02:00
|
|
|
struct TALER_BlindedCoinHash *bch)
|
|
|
|
{
|
2022-01-16 17:02:15 +01:00
|
|
|
switch (blinded_planchet->cipher)
|
|
|
|
{
|
|
|
|
case TALER_DENOMINATION_RSA:
|
2022-01-17 15:10:47 +01:00
|
|
|
// FIXME: Include denom_pub into hash
|
2022-01-16 17:02:15 +01:00
|
|
|
GNUNET_CRYPTO_hash (
|
|
|
|
blinded_planchet->details.rsa_blinded_planchet.blinded_msg,
|
|
|
|
blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size,
|
|
|
|
&bch->hash);
|
|
|
|
return GNUNET_OK;
|
|
|
|
case TALER_DENOMINATION_CS:
|
2022-01-17 15:10:47 +01:00
|
|
|
{
|
|
|
|
char delim = ':';
|
|
|
|
size_t buf_len = sizeof(denom_pub->details.cs_public_key)
|
|
|
|
+ sizeof (blinded_planchet->details.cs_blinded_planchet.
|
|
|
|
nonce)
|
|
|
|
+ sizeof(delim);
|
|
|
|
void*buf = GNUNET_malloc (buf_len);
|
|
|
|
memcpy (buf,
|
|
|
|
&denom_pub->details.cs_public_key,
|
|
|
|
sizeof(denom_pub->details.cs_public_key));
|
|
|
|
memcpy (buf + sizeof(denom_pub->details.cs_public_key),
|
|
|
|
&delim,
|
|
|
|
sizeof(delim));
|
|
|
|
memcpy (buf + sizeof(denom_pub->details.cs_public_key) + sizeof(delim),
|
|
|
|
&blinded_planchet->details.cs_blinded_planchet.nonce,
|
|
|
|
sizeof (blinded_planchet->details.cs_blinded_planchet.nonce));
|
|
|
|
GNUNET_CRYPTO_hash (
|
|
|
|
buf,
|
|
|
|
buf_len,
|
|
|
|
&bch->hash);
|
|
|
|
GNUNET_free (buf);
|
|
|
|
return GNUNET_OK;
|
|
|
|
}
|
|
|
|
|
2022-01-16 17:02:15 +01:00
|
|
|
default:
|
|
|
|
GNUNET_break (0);
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
2021-10-25 18:02:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TALER_coin_pub_hash (const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
2021-11-16 14:43:54 +01:00
|
|
|
const struct TALER_AgeHash *age_commitment_hash,
|
2021-10-25 18:02:27 +02:00
|
|
|
struct TALER_CoinPubHash *coin_h)
|
|
|
|
{
|
2021-11-16 14:43:54 +01:00
|
|
|
if (NULL == age_commitment_hash)
|
2021-11-14 16:39:42 +01:00
|
|
|
{
|
|
|
|
/* No age commitment was set */
|
|
|
|
GNUNET_CRYPTO_hash (&coin_pub->eddsa_pub,
|
|
|
|
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
|
|
|
|
&coin_h->hash);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Coin comes with age commitment. Take the hash of the age commitment
|
|
|
|
* into account */
|
|
|
|
const size_t key_s = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey);
|
|
|
|
const size_t age_s = sizeof(struct TALER_AgeHash);
|
|
|
|
char data[key_s + age_s];
|
|
|
|
|
|
|
|
GNUNET_memcpy (&data[0],
|
|
|
|
&coin_pub->eddsa_pub,
|
|
|
|
key_s);
|
|
|
|
|
|
|
|
GNUNET_memcpy (&data[key_s],
|
2021-11-16 14:43:54 +01:00
|
|
|
age_commitment_hash,
|
2021-11-14 16:39:42 +01:00
|
|
|
age_s);
|
|
|
|
|
|
|
|
GNUNET_CRYPTO_hash (&data,
|
|
|
|
key_s + age_s,
|
|
|
|
&coin_h->hash);
|
|
|
|
}
|
2021-10-25 18:02:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-27 16:18:33 +01:00
|
|
|
/* end of crypto.c */
|