summaryrefslogtreecommitdiff
path: root/src/util/test_crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_crypto.c')
-rw-r--r--src/util/test_crypto.c186
1 files changed, 111 insertions, 75 deletions
diff --git a/src/util/test_crypto.c b/src/util/test_crypto.c
index 186874e3c..2a2090952 100644
--- a/src/util/test_crypto.c
+++ b/src/util/test_crypto.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2015, 2020-2022 Taler Systems SA
+ (C) 2015, 2020-2023 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
@@ -21,7 +21,6 @@
*/
#include "platform.h"
#include "taler_util.h"
-#include "taler_crypto_lib.h"
/**
@@ -38,14 +37,21 @@ test_high_level (void)
struct TALER_TransferPublicKeyP trans_pub;
struct TALER_TransferSecretP secret;
struct TALER_TransferSecretP secret2;
- union TALER_DenominationBlindingKeyP bks1;
- union TALER_DenominationBlindingKeyP bks2;
+ union GNUNET_CRYPTO_BlindingSecretP bks1;
+ union GNUNET_CRYPTO_BlindingSecretP bks2;
struct TALER_CoinSpendPrivateKeyP coin_priv1;
struct TALER_CoinSpendPrivateKeyP coin_priv2;
struct TALER_PlanchetMasterSecretP ps1;
struct TALER_PlanchetMasterSecretP ps2;
- struct TALER_ExchangeWithdrawValues alg1;
- struct TALER_ExchangeWithdrawValues alg2;
+ struct GNUNET_CRYPTO_BlindingInputValues bi = {
+ .cipher = GNUNET_CRYPTO_BSA_RSA
+ };
+ struct TALER_ExchangeWithdrawValues alg1 = {
+ .blinding_inputs = &bi
+ };
+ struct TALER_ExchangeWithdrawValues alg2 = {
+ .blinding_inputs = &bi
+ };
GNUNET_CRYPTO_eddsa_key_create (&coin_priv.eddsa_priv);
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv.eddsa_priv,
@@ -71,14 +77,12 @@ test_high_level (void)
TALER_transfer_secret_to_planchet_secret (&secret,
0,
&ps1);
- alg1.cipher = TALER_DENOMINATION_RSA;
TALER_planchet_setup_coin_priv (&ps1,
&alg1,
&coin_priv1);
TALER_planchet_blinding_secret_create (&ps1,
&alg1,
&bks1);
- alg2.cipher = TALER_DENOMINATION_RSA;
TALER_transfer_secret_to_planchet_secret (&secret,
1,
&ps2);
@@ -117,31 +121,30 @@ test_planchets_rsa (uint8_t age)
{
struct TALER_PlanchetMasterSecretP ps;
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
struct TALER_DenominationPrivateKey dk_priv;
struct TALER_DenominationPublicKey dk_pub;
- struct TALER_ExchangeWithdrawValues alg_values;
+ const struct TALER_ExchangeWithdrawValues *alg_values;
struct TALER_PlanchetDetail pd;
struct TALER_BlindedDenominationSignature blind_sig;
struct TALER_FreshCoin coin;
struct TALER_CoinPubHashP c_hash;
struct TALER_AgeCommitmentHash *ach = NULL;
+ struct TALER_AgeCommitmentHash ah = {0};
+ alg_values = TALER_denom_ewv_rsa_singleton ();
if (0 < age)
{
struct TALER_AgeCommitmentProof acp;
- struct TALER_AgeCommitmentHash ah = {0};
struct GNUNET_HashCode seed;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&seed,
sizeof(seed));
-
- GNUNET_assert (GNUNET_OK ==
- TALER_age_restriction_commit (&age_mask,
- age,
- &seed,
- &acp));
+ TALER_age_restriction_commit (&age_mask,
+ age,
+ &seed,
+ &acp);
TALER_age_commitment_hash (&acp.commitment,
&ah);
ach = &ah;
@@ -151,12 +154,12 @@ test_planchets_rsa (uint8_t age)
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
&ps,
sizeof (ps));
-
+ GNUNET_log_skip (1, GNUNET_YES);
GNUNET_assert (GNUNET_SYSERR ==
TALER_denom_priv_create (&dk_priv,
&dk_pub,
- TALER_DENOMINATION_INVALID));
-
+ GNUNET_CRYPTO_BSA_INVALID));
+ GNUNET_log_skip (1, GNUNET_YES);
GNUNET_assert (GNUNET_SYSERR ==
TALER_denom_priv_create (&dk_priv,
&dk_pub,
@@ -165,19 +168,19 @@ test_planchets_rsa (uint8_t age)
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&dk_priv,
&dk_pub,
- TALER_DENOMINATION_RSA,
+ GNUNET_CRYPTO_BSA_RSA,
1024));
- alg_values.cipher = TALER_DENOMINATION_RSA;
TALER_planchet_setup_coin_priv (&ps,
- &alg_values,
+ alg_values,
&coin_priv);
TALER_planchet_blinding_secret_create (&ps,
- &alg_values,
+ alg_values,
&bks);
GNUNET_assert (GNUNET_OK ==
TALER_planchet_prepare (&dk_pub,
- &alg_values,
+ alg_values,
&bks,
+ NULL,
&coin_priv,
ach,
&c_hash,
@@ -195,7 +198,7 @@ test_planchets_rsa (uint8_t age)
&coin_priv,
ach,
&c_hash,
- &alg_values,
+ alg_values,
&coin));
TALER_blinded_denom_sig_free (&blind_sig);
TALER_denom_sig_free (&coin.sig);
@@ -206,39 +209,6 @@ test_planchets_rsa (uint8_t age)
/**
- * @brief Function for CS signatures to derive public R_0 and R_1
- *
- * @param nonce withdraw nonce from a client
- * @param denom_priv denomination privkey as long-term secret
- * @param r_pub the resulting R_0 and R_1
- * @return enum GNUNET_GenericReturnValue
- */
-static enum GNUNET_GenericReturnValue
-derive_r_public (
- const struct TALER_CsNonce *nonce,
- const struct TALER_DenominationPrivateKey *denom_priv,
- struct TALER_DenominationCSPublicRPairP *r_pub)
-{
- struct GNUNET_CRYPTO_CsRSecret r[2];
-
- if (denom_priv->cipher != TALER_DENOMINATION_CS)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- GNUNET_CRYPTO_cs_r_derive (&nonce->nonce,
- "rw",
- &denom_priv->details.cs_private_key,
- r);
- GNUNET_CRYPTO_cs_r_get_public (&r[0],
- &r_pub->r_pub[0]);
- GNUNET_CRYPTO_cs_r_get_public (&r[1],
- &r_pub->r_pub[1]);
- return GNUNET_OK;
-}
-
-
-/**
* Test the basic planchet functionality of creating a fresh planchet with CS denomination
* and extracting the respective signature.
*
@@ -249,11 +219,12 @@ test_planchets_cs (uint8_t age)
{
struct TALER_PlanchetMasterSecretP ps;
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
struct TALER_DenominationPrivateKey dk_priv;
struct TALER_DenominationPublicKey dk_pub;
struct TALER_PlanchetDetail pd;
struct TALER_CoinPubHashP c_hash;
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
struct TALER_BlindedDenominationSignature blind_sig;
struct TALER_FreshCoin coin;
struct TALER_ExchangeWithdrawValues alg_values;
@@ -268,12 +239,10 @@ test_planchets_cs (uint8_t age)
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&seed,
sizeof(seed));
-
- GNUNET_assert (GNUNET_OK ==
- TALER_age_restriction_commit (&age_mask,
- age,
- &seed,
- &acp));
+ TALER_age_restriction_commit (&age_mask,
+ age,
+ &seed,
+ &acp);
TALER_age_commitment_hash (&acp.commitment,
&ah);
ach = &ah;
@@ -286,16 +255,17 @@ test_planchets_cs (uint8_t age)
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&dk_priv,
&dk_pub,
- TALER_DENOMINATION_CS));
- alg_values.cipher = TALER_DENOMINATION_CS;
+ GNUNET_CRYPTO_BSA_CS));
TALER_cs_withdraw_nonce_derive (
&ps,
- &pd.blinded_planchet.details.cs_blinded_planchet.nonce);
- GNUNET_assert (GNUNET_OK ==
- derive_r_public (
- &pd.blinded_planchet.details.cs_blinded_planchet.nonce,
- &dk_priv,
- &alg_values.details.cs_values));
+ &nonce.cs_nonce);
+ // FIXME: define Taler abstraction for this:
+ alg_values.blinding_inputs
+ = GNUNET_CRYPTO_get_blinding_input_values (dk_priv.bsign_priv_key,
+ &nonce,
+ "rw");
+ TALER_denom_pub_hash (&dk_pub,
+ &pd.denom_pub_hash);
TALER_planchet_setup_coin_priv (&ps,
&alg_values,
&coin_priv);
@@ -306,6 +276,7 @@ test_planchets_cs (uint8_t age)
TALER_planchet_prepare (&dk_pub,
&alg_values,
&bks,
+ &nonce,
&coin_priv,
ach,
&c_hash,
@@ -315,7 +286,6 @@ test_planchets_cs (uint8_t age)
&dk_priv,
false,
&pd.blinded_planchet));
- TALER_planchet_detail_free (&pd);
GNUNET_assert (GNUNET_OK ==
TALER_planchet_to_coin (&dk_pub,
&blind_sig,
@@ -356,15 +326,24 @@ test_exchange_sigs (void)
struct TALER_MasterPrivateKeyP priv;
struct TALER_MasterPublicKeyP pub;
struct TALER_MasterSignatureP sig;
+ json_t *rest;
GNUNET_CRYPTO_eddsa_key_create (&priv.eddsa_priv);
+ rest = json_array ();
+ GNUNET_assert (NULL != rest);
TALER_exchange_wire_signature_make (pt,
+ NULL,
+ rest,
+ rest,
&priv,
&sig);
GNUNET_CRYPTO_eddsa_key_get_public (&priv.eddsa_priv,
&pub.eddsa_pub);
if (GNUNET_OK !=
TALER_exchange_wire_signature_check (pt,
+ NULL,
+ rest,
+ rest,
&pub,
&sig))
{
@@ -374,12 +353,28 @@ test_exchange_sigs (void)
if (GNUNET_OK ==
TALER_exchange_wire_signature_check (
"payto://x-taler-bank/localhost/Other",
+ NULL,
+ rest,
+ rest,
&pub,
&sig))
{
GNUNET_break (0);
return 1;
}
+ if (GNUNET_OK ==
+ TALER_exchange_wire_signature_check (
+ pt,
+ "http://example.com/",
+ rest,
+ rest,
+ &pub,
+ &sig))
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ json_decref (rest);
return 0;
}
@@ -482,12 +477,51 @@ test_contracts (void)
}
+static int
+test_attributes (void)
+{
+ struct TALER_AttributeEncryptionKeyP key;
+ void *eattr;
+ size_t eattr_size;
+ json_t *c;
+
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ &key,
+ sizeof (key));
+ c = json_pack ("{s:s}", "test", "value");
+ GNUNET_assert (NULL != c);
+ TALER_CRYPTO_kyc_attributes_encrypt (&key,
+ c,
+ &eattr,
+ &eattr_size);
+ json_decref (c);
+ c = TALER_CRYPTO_kyc_attributes_decrypt (&key,
+ eattr,
+ eattr_size);
+ GNUNET_free (eattr);
+ if (NULL == c)
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ GNUNET_assert (0 ==
+ strcmp ("value",
+ json_string_value (json_object_get (c,
+ "test"))));
+ json_decref (c);
+ return 0;
+}
+
+
int
main (int argc,
const char *const argv[])
{
(void) argc;
(void) argv;
+ GNUNET_log_setup ("test-crypto",
+ "WARNING",
+ NULL);
if (0 != test_high_level ())
return 1;
if (0 != test_planchets (0))
@@ -500,6 +534,8 @@ main (int argc,
return 5;
if (0 != test_contracts ())
return 6;
+ if (0 != test_attributes ())
+ return 7;
return 0;
}