aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/amount.c14
-rw-r--r--src/util/auditor_signatures.c32
-rw-r--r--src/util/config.c68
-rw-r--r--src/util/crypto.c32
-rw-r--r--src/util/denom.c93
-rw-r--r--src/util/offline_signatures.c30
-rw-r--r--src/util/util.c67
7 files changed, 199 insertions, 137 deletions
diff --git a/src/util/amount.c b/src/util/amount.c
index ae9ae652e..3ce8c0711 100644
--- a/src/util/amount.c
+++ b/src/util/amount.c
@@ -253,6 +253,20 @@ TALER_amount_is_zero (const struct TALER_Amount *amount)
}
+enum GNUNET_GenericReturnValue
+TALER_amount_is_currency (const struct TALER_Amount *amount,
+ const char *currency)
+{
+ if (GNUNET_OK !=
+ TALER_amount_is_valid (amount))
+ return GNUNET_SYSERR;
+ return (0 == strcasecmp (currency,
+ amount->currency))
+ ? GNUNET_OK
+ : GNUNET_NO;
+}
+
+
/**
* Test if @a a is valid, NBO variant.
*
diff --git a/src/util/auditor_signatures.c b/src/util/auditor_signatures.c
index 7b53c21c1..2ab690a03 100644
--- a/src/util/auditor_signatures.c
+++ b/src/util/auditor_signatures.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020, 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
@@ -33,10 +33,7 @@ TALER_auditor_denom_validity_sign (
struct GNUNET_TIME_Timestamp stamp_expire_deposit,
struct GNUNET_TIME_Timestamp stamp_expire_legal,
const struct TALER_Amount *coin_value,
- const struct TALER_Amount *fee_withdraw,
- const struct TALER_Amount *fee_deposit,
- const struct TALER_Amount *fee_refresh,
- const struct TALER_Amount *fee_refund,
+ const struct TALER_DenomFeeSet *fees,
const struct TALER_AuditorPrivateKeyP *auditor_priv,
struct TALER_AuditorSignatureP *auditor_sig)
{
@@ -53,14 +50,8 @@ TALER_auditor_denom_validity_sign (
TALER_amount_hton (&kv.value,
coin_value);
- TALER_amount_hton (&kv.fee_withdraw,
- fee_withdraw);
- TALER_amount_hton (&kv.fee_deposit,
- fee_deposit);
- TALER_amount_hton (&kv.fee_refresh,
- fee_refresh);
- TALER_amount_hton (&kv.fee_refund,
- fee_refund);
+ TALER_denom_fee_set_hton (&kv.fees,
+ fees);
GNUNET_CRYPTO_hash (auditor_url,
strlen (auditor_url) + 1,
&kv.auditor_url_hash);
@@ -80,10 +71,7 @@ TALER_auditor_denom_validity_verify (
struct GNUNET_TIME_Timestamp stamp_expire_deposit,
struct GNUNET_TIME_Timestamp stamp_expire_legal,
const struct TALER_Amount *coin_value,
- const struct TALER_Amount *fee_withdraw,
- const struct TALER_Amount *fee_deposit,
- const struct TALER_Amount *fee_refresh,
- const struct TALER_Amount *fee_refund,
+ const struct TALER_DenomFeeSet *fees,
const struct TALER_AuditorPublicKeyP *auditor_pub,
const struct TALER_AuditorSignatureP *auditor_sig)
{
@@ -100,14 +88,8 @@ TALER_auditor_denom_validity_verify (
TALER_amount_hton (&kv.value,
coin_value);
- TALER_amount_hton (&kv.fee_withdraw,
- fee_withdraw);
- TALER_amount_hton (&kv.fee_deposit,
- fee_deposit);
- TALER_amount_hton (&kv.fee_refresh,
- fee_refresh);
- TALER_amount_hton (&kv.fee_refund,
- fee_refund);
+ TALER_denom_fee_set_hton (&kv.fees,
+ fees);
GNUNET_CRYPTO_hash (auditor_url,
strlen (auditor_url) + 1,
&kv.auditor_url_hash);
diff --git a/src/util/config.c b/src/util/config.c
index 8123b7343..dc342fdcf 100644
--- a/src/util/config.c
+++ b/src/util/config.c
@@ -59,6 +59,74 @@ TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg,
enum GNUNET_GenericReturnValue
+TALER_config_get_denom_fees (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *currency,
+ const char *section,
+ struct TALER_DenomFeeSet *fees)
+{
+ if (GNUNET_OK !=
+ TALER_config_get_amount (cfg,
+ section,
+ "FEE_WITHDRAW",
+ &fees->withdraw))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "Need amount for option `%s' in section `%s'\n",
+ "FEE_WITHDRAW",
+ section);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_config_get_amount (cfg,
+ section,
+ "FEE_DEPOSIT",
+ &fees->deposit))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "Need amount for option `%s' in section `%s'\n",
+ "FEE_DEPOSIT",
+ section);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_config_get_amount (cfg,
+ section,
+ "FEE_REFRESH",
+ &fees->refresh))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "Need amount for option `%s' in section `%s'\n",
+ "FEE_REFRESH",
+ section);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_config_get_amount (cfg,
+ section,
+ "FEE_REFUND",
+ &fees->refund))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "Need amount for option `%s' in section `%s'\n",
+ "FEE_REFUND",
+ section);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_denom_fee_check_currency (currency,
+ fees))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Need fee amounts in section `%s' to use currency `%s'\n",
+ section,
+ currency);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
TALER_config_get_currency (const struct GNUNET_CONFIGURATION_Handle *cfg,
char **currency)
{
diff --git a/src/util/crypto.c b/src/util/crypto.c
index 6bea984f3..d3f3cd3fa 100644
--- a/src/util/crypto.c
+++ b/src/util/crypto.c
@@ -193,6 +193,7 @@ TALER_transfer_secret_to_planchet_secret (
void
TALER_planchet_secret_to_transfer_priv (
const struct TALER_RefreshMasterSecretP *rms,
+ const struct TALER_CoinSpendPrivateKeyP *old_coin_priv,
uint32_t cnc_num,
struct TALER_TransferPrivateKeyP *tpriv)
{
@@ -203,6 +204,8 @@ TALER_planchet_secret_to_transfer_priv (
sizeof (*tpriv),
&be_salt,
sizeof (be_salt),
+ old_coin_priv,
+ sizeof (*old_coin_priv),
rms,
sizeof (*rms),
"taler-transfer-priv-derivation",
@@ -337,6 +340,7 @@ TALER_planchet_to_coin (
void
TALER_refresh_get_commitment (struct TALER_RefreshCommitmentP *rc,
uint32_t kappa,
+ const struct TALER_RefreshMasterSecretP *rms,
uint32_t num_new_coins,
const struct TALER_RefreshCommitmentEntry *rcs,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
@@ -345,6 +349,10 @@ TALER_refresh_get_commitment (struct TALER_RefreshCommitmentP *rc,
struct GNUNET_HashContext *hash_context;
hash_context = GNUNET_CRYPTO_hash_context_start ();
+ if (NULL != rms)
+ GNUNET_CRYPTO_hash_context_read (hash_context,
+ rms,
+ sizeof (*rms));
/* first, iterate over transfer public keys for hash_context */
for (unsigned int i = 0; i<kappa; i++)
{
@@ -391,8 +399,8 @@ TALER_refresh_get_commitment (struct TALER_RefreshCommitmentP *rc,
{
const struct TALER_RefreshCoinData *rcd = &rce->new_coins[j];
- TALER_blinded_planchet_hash (&rcd->blinded_planchet,
- hash_context);
+ TALER_blinded_planchet_hash_ (&rcd->blinded_planchet,
+ hash_context);
}
}
@@ -702,9 +710,27 @@ TALER_age_restriction_commmitment_free_inside (
GNUNET_free (commitment->pub);
commitment->priv = NULL;
}
-
/* Caller is responsible for commitment itself */
}
+enum GNUNET_GenericReturnValue
+TALER_coin_ev_hash (const struct TALER_BlindedPlanchet *blinded_planchet,
+ const struct TALER_DenominationHash *denom_hash,
+ struct TALER_BlindedCoinHash *bch)
+{
+ struct GNUNET_HashContext *hash_context;
+
+ hash_context = GNUNET_CRYPTO_hash_context_start ();
+ GNUNET_CRYPTO_hash_context_read (hash_context,
+ denom_hash,
+ sizeof(*denom_hash));
+ TALER_blinded_planchet_hash_ (blinded_planchet,
+ hash_context);
+ GNUNET_CRYPTO_hash_context_finish (hash_context,
+ &bch->hash);
+ return GNUNET_OK;
+}
+
+
/* end of crypto.c */
diff --git a/src/util/denom.c b/src/util/denom.c
index 7c2c42c9e..7afc7f408 100644
--- a/src/util/denom.c
+++ b/src/util/denom.c
@@ -652,8 +652,8 @@ TALER_blinded_denom_sig_cmp (
void
-TALER_blinded_planchet_hash (const struct TALER_BlindedPlanchet *bp,
- struct GNUNET_HashContext *hash_context)
+TALER_blinded_planchet_hash_ (const struct TALER_BlindedPlanchet *bp,
+ struct GNUNET_HashContext *hash_context)
{
uint32_t cipher = htonl (bp->cipher);
@@ -771,97 +771,20 @@ TALER_blinded_planchet_free (struct TALER_BlindedPlanchet *blinded_planchet)
{
switch (blinded_planchet->cipher)
{
+ case TALER_DENOMINATION_INVALID:
+ GNUNET_break (0);
+ return;
case TALER_DENOMINATION_RSA:
GNUNET_free (blinded_planchet->details.rsa_blinded_planchet.blinded_msg);
- break;
+ return;
case TALER_DENOMINATION_CS:
memset (blinded_planchet,
0,
sizeof (*blinded_planchet));
/* nothing to do for CS */
- break;
- default:
- GNUNET_break (0);
- }
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_coin_ev_hash (const struct TALER_BlindedPlanchet *blinded_planchet,
- const struct TALER_DenominationHash *denom_hash,
- struct TALER_BlindedCoinHash *bch)
-{
- struct GNUNET_HashContext *hash_context;
-
- hash_context = GNUNET_CRYPTO_hash_context_start ();
- GNUNET_CRYPTO_hash_context_read (hash_context,
- denom_hash,
- sizeof(*denom_hash));
- switch (blinded_planchet->cipher)
- {
- case TALER_DENOMINATION_RSA:
- GNUNET_CRYPTO_hash_context_read (
- hash_context,
- blinded_planchet->details.rsa_blinded_planchet.blinded_msg,
- blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size);
- break;
- case TALER_DENOMINATION_CS:
- // FIXME: c-values MUST NOT be included in idempotency check
- // during withdraw (or recoup), but right now they are!!!
- GNUNET_CRYPTO_hash_context_read (
- hash_context,
- &blinded_planchet->details.cs_blinded_planchet.c[0],
- sizeof (struct GNUNET_CRYPTO_CsC) * 2);
- GNUNET_CRYPTO_hash_context_read (
- hash_context,
- &blinded_planchet->details.cs_blinded_planchet.nonce,
- sizeof (struct TALER_CsNonce));
- break;
- default:
- GNUNET_break (0);
- GNUNET_CRYPTO_hash_context_abort (hash_context);
- return GNUNET_SYSERR;
- }
- GNUNET_CRYPTO_hash_context_finish (hash_context,
- &bch->hash);
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_withdraw_request_hash (
- const struct TALER_BlindedPlanchet *blinded_planchet,
- const struct TALER_DenominationHash *denom_hash,
- struct TALER_WithdrawIdentificationHash *wih)
-{
- struct GNUNET_HashContext *hash_context;
-
- hash_context = GNUNET_CRYPTO_hash_context_start ();
- GNUNET_CRYPTO_hash_context_read (hash_context,
- denom_hash,
- sizeof(*denom_hash));
- switch (blinded_planchet->cipher)
- {
- case TALER_DENOMINATION_RSA:
- GNUNET_CRYPTO_hash_context_read (
- hash_context,
- blinded_planchet->details.rsa_blinded_planchet.blinded_msg,
- blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size);
- break;
- case TALER_DENOMINATION_CS:
- GNUNET_CRYPTO_hash_context_read (
- hash_context,
- &blinded_planchet->details.cs_blinded_planchet.nonce,
- sizeof (struct TALER_CsNonce));
- break;
- default:
- GNUNET_break (0);
- GNUNET_CRYPTO_hash_context_abort (hash_context);
- return GNUNET_SYSERR;
+ return;
}
- GNUNET_CRYPTO_hash_context_finish (hash_context,
- &wih->hash);
- return GNUNET_OK;
+ GNUNET_assert (0);
}
diff --git a/src/util/offline_signatures.c b/src/util/offline_signatures.c
index ab2988349..fa4b80fe2 100644
--- a/src/util/offline_signatures.c
+++ b/src/util/offline_signatures.c
@@ -255,10 +255,7 @@ TALER_exchange_offline_denom_validity_sign (
struct GNUNET_TIME_Timestamp stamp_expire_deposit,
struct GNUNET_TIME_Timestamp stamp_expire_legal,
const struct TALER_Amount *coin_value,
- const struct TALER_Amount *fee_withdraw,
- const struct TALER_Amount *fee_deposit,
- const struct TALER_Amount *fee_refresh,
- const struct TALER_Amount *fee_refund,
+ const struct TALER_DenomFeeSet *fees,
const struct TALER_MasterPrivateKeyP *master_priv,
struct TALER_MasterSignatureP *master_sig)
{
@@ -278,14 +275,8 @@ TALER_exchange_offline_denom_validity_sign (
&issue.master.eddsa_pub);
TALER_amount_hton (&issue.value,
coin_value);
- TALER_amount_hton (&issue.fee_withdraw,
- fee_withdraw);
- TALER_amount_hton (&issue.fee_deposit,
- fee_deposit);
- TALER_amount_hton (&issue.fee_refresh,
- fee_refresh);
- TALER_amount_hton (&issue.fee_refund,
- fee_refund);
+ TALER_denom_fee_set_hton (&issue.fees,
+ fees);
GNUNET_CRYPTO_eddsa_sign (&master_priv->eddsa_priv,
&issue,
&master_sig->eddsa_signature);
@@ -300,10 +291,7 @@ TALER_exchange_offline_denom_validity_verify (
struct GNUNET_TIME_Timestamp stamp_expire_deposit,
struct GNUNET_TIME_Timestamp stamp_expire_legal,
const struct TALER_Amount *coin_value,
- const struct TALER_Amount *fee_withdraw,
- const struct TALER_Amount *fee_deposit,
- const struct TALER_Amount *fee_refresh,
- const struct TALER_Amount *fee_refund,
+ const struct TALER_DenomFeeSet *fees,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_MasterSignatureP *master_sig)
{
@@ -321,14 +309,8 @@ TALER_exchange_offline_denom_validity_verify (
TALER_amount_hton (&dkv.value,
coin_value);
- TALER_amount_hton (&dkv.fee_withdraw,
- fee_withdraw);
- TALER_amount_hton (&dkv.fee_deposit,
- fee_deposit);
- TALER_amount_hton (&dkv.fee_refresh,
- fee_refresh);
- TALER_amount_hton (&dkv.fee_refund,
- fee_refund);
+ TALER_denom_fee_set_hton (&dkv.fees,
+ fees);
return
GNUNET_CRYPTO_eddsa_verify (
TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY,
diff --git a/src/util/util.c b/src/util/util.c
index 2ff295b0b..5b7181a13 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -46,6 +46,73 @@ TALER_b2s (const void *buf,
}
+void
+TALER_denom_fee_set_hton (struct TALER_DenomFeeSetNBOP *nbo,
+ const struct TALER_DenomFeeSet *fees)
+{
+ TALER_amount_hton (&nbo->withdraw,
+ &fees->withdraw);
+ TALER_amount_hton (&nbo->deposit,
+ &fees->deposit);
+ TALER_amount_hton (&nbo->refresh,
+ &fees->refresh);
+ TALER_amount_hton (&nbo->refund,
+ &fees->refund);
+}
+
+
+void
+TALER_denom_fee_set_ntoh (struct TALER_DenomFeeSet *fees,
+ const struct TALER_DenomFeeSetNBOP *nbo)
+{
+ TALER_amount_ntoh (&fees->withdraw,
+ &nbo->withdraw);
+ TALER_amount_ntoh (&fees->deposit,
+ &nbo->deposit);
+ TALER_amount_ntoh (&fees->refresh,
+ &nbo->refresh);
+ TALER_amount_ntoh (&fees->refund,
+ &nbo->refund);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_denom_fee_check_currency (
+ const char *currency,
+ const struct TALER_DenomFeeSet *fees)
+{
+ if (GNUNET_YES !=
+ TALER_amount_is_currency (&fees->withdraw,
+ currency))
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_YES !=
+ TALER_amount_is_currency (&fees->deposit,
+ currency))
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_YES !=
+ TALER_amount_is_currency (&fees->refresh,
+ currency))
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_YES !=
+ TALER_amount_is_currency (&fees->refund,
+ currency))
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
+ return GNUNET_OK;
+}
+
+
#ifdef __APPLE__
char *
strchrnul (const char *s,