aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/crypto.c66
-rw-r--r--src/util/denom.c66
-rw-r--r--src/util/test_crypto.c78
-rw-r--r--src/util/test_helper_rsa.c29
4 files changed, 194 insertions, 45 deletions
diff --git a/src/util/crypto.c b/src/util/crypto.c
index 178db3aa..a8413e0f 100644
--- a/src/util/crypto.c
+++ b/src/util/crypto.c
@@ -167,11 +167,68 @@ TALER_planchet_setup_refresh (const struct TALER_TransferSecretP *secret_seed,
void
-TALER_planchet_setup_random (struct TALER_PlanchetSecretsP *ps)
+blinding_secret_create_va (union TALER_DenominationBlindingKeyP *bs,
+ enum TALER_DenominationCipher cipher,
+ va_list ap)
+{
+ switch (cipher)
+ {
+ case TALER_DENOMINATION_INVALID:
+ GNUNET_break (0);
+ return;
+ case TALER_DENOMINATION_RSA:
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
+ &bs->rsa_bks,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaBlindingKeySecret));
+ return;
+ case TALER_DENOMINATION_CS:
+ {
+ // TODO: nonce teil ist noch falsch. da kommt bs[2] zurück, was wir nicht speichern wollen!
+ struct TALER_PlanchetDeriveCsBlindingSecrets*seed;
+
+ seed = va_arg (ap, struct TALER_PlanchetDeriveCsBlindingSecrets *);
+
+ // GNUNET_CRYPTO_cs_blinding_secrets_derive(&seed->secret,
+ // seed->secret_len,
+ // &bs->nonce);
+ return;
+ }
+
+ default:
+ GNUNET_break (0);
+ }
+
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ bs,
+ sizeof (*bs));
+}
+
+
+void
+TALER_blinding_secret_create (union TALER_DenominationBlindingKeyP *bs,
+ enum TALER_DenominationCipher cipher,
+ ...)
+{
+ va_list ap;
+ va_start (ap, cipher);
+ blinding_secret_create_va (bs, cipher, ap);
+ va_end (ap);
+}
+
+
+void
+TALER_planchet_setup_random (struct TALER_PlanchetSecretsP *ps,
+ enum TALER_DenominationCipher cipher,
+ ...)
{
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
- ps,
- sizeof (*ps));
+ &ps->coin_priv,
+ sizeof (struct TALER_CoinSpendPrivateKeyP));
+ va_list ap;
+ va_start (ap, cipher);
+ blinding_secret_create_va (&ps->blinding_key, cipher, ap);
+ va_end (ap);
}
@@ -191,8 +248,7 @@ TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk,
NULL, /* FIXME-Oec */
&coin_pub,
c_hash,
- &pd->coin_ev,
- &pd->coin_ev_size))
+ &pd->blinded_planchet))
{
GNUNET_break (0);
return GNUNET_SYSERR;
diff --git a/src/util/denom.c b/src/util/denom.c
index b6b3764d..bcfa3efa 100644
--- a/src/util/denom.c
+++ b/src/util/denom.c
@@ -34,6 +34,10 @@ TALER_denom_priv_create (struct TALER_DenominationPrivateKey *denom_priv,
memset (denom_pub,
0,
sizeof (*denom_pub));
+
+ denom_priv->cipher = cipher;
+ denom_pub->cipher = cipher;
+
switch (cipher)
{
case TALER_DENOMINATION_INVALID:
@@ -63,10 +67,13 @@ TALER_denom_priv_create (struct TALER_DenominationPrivateKey *denom_priv,
denom_pub->details.rsa_public_key
= GNUNET_CRYPTO_rsa_private_key_get_public (
denom_priv->details.rsa_private_key);
- denom_priv->cipher = cipher;
- denom_pub->cipher = cipher;
return GNUNET_OK;
- // TODO: add case for Clause-Schnorr
+ case TALER_DENOMINATION_CS:
+ GNUNET_CRYPTO_cs_private_key_generate (&denom_priv->details.cs_private_key);
+ GNUNET_CRYPTO_cs_private_key_get_public (
+ &denom_priv->details.cs_private_key,
+ &denom_pub->details.cs_public_key);
+ return GNUNET_OK;
default:
GNUNET_break (0);
}
@@ -77,8 +84,7 @@ TALER_denom_priv_create (struct TALER_DenominationPrivateKey *denom_priv,
enum GNUNET_GenericReturnValue
TALER_denom_sign_blinded (struct TALER_BlindedDenominationSignature *denom_sig,
const struct TALER_DenominationPrivateKey *denom_priv,
- void *blinded_msg,
- size_t blinded_msg_size)
+ const struct TALER_BlindedPlanchet *blinded_planchet)
{
memset (denom_sig,
0,
@@ -92,8 +98,8 @@ TALER_denom_sign_blinded (struct TALER_BlindedDenominationSignature *denom_sig,
denom_sig->details.blinded_rsa_signature
= GNUNET_CRYPTO_rsa_sign_blinded (
denom_priv->details.rsa_private_key,
- blinded_msg,
- blinded_msg_size);
+ blinded_planchet->details.rsa_blinded_planchet.blinded_msg,
+ blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size);
if (NULL == denom_sig->details.blinded_rsa_signature)
{
GNUNET_break (0);
@@ -147,15 +153,6 @@ TALER_denom_sig_unblind (
}
-void
-TALER_blinding_secret_create (union TALER_DenominationBlindingKeyP *bs)
-{
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
- bs,
- sizeof (*bs));
-}
-
-
/**
* Hash @a rsa.
*
@@ -238,21 +235,28 @@ TALER_denom_blind (const struct TALER_DenominationPublicKey *dk,
const struct TALER_AgeHash *age_commitment_hash,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
struct TALER_CoinPubHash *c_hash,
- void **coin_ev,
- size_t *coin_ev_size)
+ struct TALER_BlindedPlanchet *blinded_planchet)
{
+ // if (dk->cipher != blinded_planchet->cipher)
+ // {
+ // GNUNET_break (0);
+ // return GNUNET_SYSERR;
+ // }
+ blinded_planchet->cipher = dk->cipher;
+ TALER_coin_pub_hash (coin_pub,
+ age_commitment_hash,
+ c_hash);
switch (dk->cipher)
{
case TALER_DENOMINATION_RSA:
- TALER_coin_pub_hash (coin_pub,
- age_commitment_hash,
- c_hash);
if (GNUNET_YES !=
GNUNET_CRYPTO_rsa_blind (&c_hash->hash,
&coin_bks->rsa_bks,
dk->details.rsa_public_key,
- coin_ev,
- coin_ev_size))
+ &blinded_planchet->details.rsa_blinded_planchet
+ .blinded_msg,
+ &blinded_planchet->details.rsa_blinded_planchet
+ .blinded_msg_size))
{
GNUNET_break (0);
return GNUNET_SYSERR;
@@ -314,7 +318,9 @@ TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub)
}
denom_pub->cipher = TALER_DENOMINATION_INVALID;
return;
- // TODO: add case for Clause-Schnorr
+ case TALER_DENOMINATION_CS:
+ // TODO: ATM nothing needs to be freed, but check again after implementation.
+ return;
default:
GNUNET_assert (0);
}
@@ -336,7 +342,9 @@ TALER_denom_priv_free (struct TALER_DenominationPrivateKey *denom_priv)
}
denom_priv->cipher = TALER_DENOMINATION_INVALID;
return;
- // TODO: add case for Clause-Schnorr
+ case TALER_DENOMINATION_CS:
+ // TODO: ATM nothing needs to be freed, but check again after implementation.
+ return;
default:
GNUNET_assert (0);
}
@@ -358,7 +366,9 @@ TALER_denom_sig_free (struct TALER_DenominationSignature *denom_sig)
}
denom_sig->cipher = TALER_DENOMINATION_INVALID;
return;
- // TODO: add case for Clause-Schnorr
+ case TALER_DENOMINATION_CS:
+ // TODO: ATM nothing needs to be freed, but check again after implementation.
+ return;
default:
GNUNET_assert (0);
}
@@ -382,7 +392,9 @@ TALER_blinded_denom_sig_free (
}
denom_sig->cipher = TALER_DENOMINATION_INVALID;
return;
- // TODO: add case for Clause-Schnorr
+ case TALER_DENOMINATION_CS:
+ // TODO: ATM nothing needs to be freed, but check again after implementation.
+ return;
default:
GNUNET_assert (0);
}
diff --git a/src/util/test_crypto.c b/src/util/test_crypto.c
index 5ee06487..12f9e64c 100644
--- a/src/util/test_crypto.c
+++ b/src/util/test_crypto.c
@@ -82,7 +82,7 @@ test_high_level (void)
* @return 0 on success
*/
static int
-test_planchets (void)
+test_planchets_rsa (void)
{
struct TALER_PlanchetSecretsP ps;
struct TALER_DenominationPrivateKey dk_priv;
@@ -92,12 +92,23 @@ test_planchets (void)
struct TALER_FreshCoin coin;
struct TALER_CoinPubHash c_hash;
+
+ GNUNET_assert (GNUNET_SYSERR ==
+ TALER_denom_priv_create (&dk_priv,
+ &dk_pub,
+ TALER_DENOMINATION_INVALID));
+
+ GNUNET_assert (GNUNET_SYSERR ==
+ TALER_denom_priv_create (&dk_priv,
+ &dk_pub,
+ 42));
+
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&dk_priv,
&dk_pub,
TALER_DENOMINATION_RSA,
1024));
- TALER_planchet_setup_random (&ps);
+ TALER_planchet_setup_random (&ps, TALER_DENOMINATION_RSA);
GNUNET_assert (GNUNET_OK ==
TALER_planchet_prepare (&dk_pub,
&ps,
@@ -106,8 +117,7 @@ test_planchets (void)
GNUNET_assert (GNUNET_OK ==
TALER_denom_sign_blinded (&blind_sig,
&dk_priv,
- pd.coin_ev,
- pd.coin_ev_size));
+ &pd.blinded_planchet));
GNUNET_assert (GNUNET_OK ==
TALER_planchet_to_coin (&dk_pub,
&blind_sig,
@@ -122,6 +132,66 @@ test_planchets (void)
}
+/**
+ * Test the basic planchet functionality of creating a fresh planchet with CS denomination
+ * and extracting the respective signature.
+ *
+ * @return 0 on success
+ */
+static int
+test_planchets_cs (void)
+{
+ // struct TALER_PlanchetSecretsP ps;
+ struct TALER_DenominationPrivateKey dk_priv;
+ struct TALER_DenominationPublicKey dk_pub;
+ // struct TALER_PlanchetDetail pd;
+ // struct TALER_BlindedDenominationSignature blind_sig;
+ // struct TALER_FreshCoin coin;
+ // struct TALER_CoinPubHash c_hash;
+ // struct TALER_PlanchetDeriveCsBlindingSecrets seed;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_priv_create (&dk_priv,
+ &dk_pub,
+ TALER_DENOMINATION_CS));
+
+ // seed.secret = "test secret";
+ // seed.secret_len = strlen ("test secret");
+
+ // TODO: Probably need to adjust GNUNET CS implementation for the CSNonce creation and afterwards adjust the derive function
+ // TALER_planchet_setup_random (&ps, TALER_DENOMINATION_CS, &seed);
+
+ // GNUNET_assert (GNUNET_OK ==
+ // TALER_planchet_prepare (&dk_pub,
+ // &ps,
+ // &c_hash,
+ // &pd));
+
+
+ // TALER_blinded_denom_sig_free (&blind_sig);
+ // TALER_denom_sig_free (&coin.sig);
+ TALER_denom_priv_free (&dk_priv);
+ TALER_denom_pub_free (&dk_pub);
+ return 0;
+}
+
+
+/**
+ * Test the basic planchet functionality of creating a fresh planchet
+ * and extracting the respective signature.
+ * Calls test_planchets_rsa and test_planchets_cs
+ *
+ * @return 0 on success
+ */
+static int
+test_planchets (void)
+{
+ if (0 != test_planchets_rsa ())
+ return -1;
+ return test_planchets_cs ();
+}
+
+
static int
test_exchange_sigs (void)
{
diff --git a/src/util/test_helper_rsa.c b/src/util/test_helper_rsa.c
index ac4ae1dc..e51fa26e 100644
--- a/src/util/test_helper_rsa.c
+++ b/src/util/test_helper_rsa.c
@@ -270,13 +270,15 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
struct TALER_PlanchetSecretsP ps;
struct TALER_CoinPubHash c_hash;
- TALER_planchet_setup_random (&ps);
+ TALER_planchet_setup_random (&ps, TALER_DENOMINATION_RSA);
for (unsigned int i = 0; i<MAX_KEYS; i++)
{
if (! keys[i].valid)
continue;
{
struct TALER_PlanchetDetail pd;
+ pd.blinded_planchet.cipher = TALER_DENOMINATION_RSA;
+ // keys[i].denom_pub.cipher = TALER_DENOMINATION_CS;
GNUNET_assert (GNUNET_YES ==
TALER_planchet_prepare (&keys[i].denom_pub,
@@ -285,14 +287,19 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
&pd));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting signature over %u bytes with key %s\n",
- (unsigned int) pd.coin_ev_size,
+ (unsigned
+ int) pd.blinded_planchet.details.rsa_blinded_planchet.
+ blinded_msg_size,
GNUNET_h2s (&keys[i].h_rsa.hash));
ds = TALER_CRYPTO_helper_rsa_sign (dh,
&keys[i].h_rsa,
- pd.coin_ev,
- pd.coin_ev_size,
+ pd.blinded_planchet.details.
+ rsa_blinded_planchet.blinded_msg,
+ pd.blinded_planchet.details.
+ rsa_blinded_planchet.blinded_msg_size,
&ec);
- GNUNET_free (pd.coin_ev);
+ GNUNET_free (
+ pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg);
}
switch (ec)
{
@@ -419,7 +426,7 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
struct GNUNET_TIME_Relative duration;
struct TALER_PlanchetSecretsP ps;
- TALER_planchet_setup_random (&ps);
+ TALER_planchet_setup_random (&ps, TALER_DENOMINATION_RSA);
duration = GNUNET_TIME_UNIT_ZERO;
TALER_CRYPTO_helper_rsa_poll (dh);
for (unsigned int j = 0; j<NUM_SIGN_PERFS;)
@@ -455,8 +462,11 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
ds = TALER_CRYPTO_helper_rsa_sign (dh,
&keys[i].h_rsa,
- pd.coin_ev,
- pd.coin_ev_size,
+ pd.blinded_planchet.details.
+ rsa_blinded_planchet.blinded_msg,
+ pd.blinded_planchet.details.
+ rsa_blinded_planchet.
+ blinded_msg_size,
&ec);
if (TALER_EC_NONE != ec)
break;
@@ -468,7 +478,8 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
if (NUM_SIGN_PERFS <= j)
break;
}
- GNUNET_free (pd.coin_ev);
+ GNUNET_free (
+ pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg);
}
} /* for i */
} /* for j */