diff options
author | Fournier Nicolas <nicolas.fournier@ensta-paristech.fr> | 2015-06-12 11:14:32 +0200 |
---|---|---|
committer | Fournier Nicolas <nicolas.fournier@ensta-paristech.fr> | 2015-06-12 11:14:32 +0200 |
commit | ec56e47809783fde3adfe159af0ec8e828a1f385 (patch) | |
tree | 3f979da065e705087bf53f62698266c6601621e7 /src/mintdb/perf_taler_mintdb_init.c | |
parent | 006c55b3de1262c390e2139798422ca0fb1e9c02 (diff) |
Fix includes and more indentation
Diffstat (limited to 'src/mintdb/perf_taler_mintdb_init.c')
-rw-r--r-- | src/mintdb/perf_taler_mintdb_init.c | 257 |
1 files changed, 93 insertions, 164 deletions
diff --git a/src/mintdb/perf_taler_mintdb_init.c b/src/mintdb/perf_taler_mintdb_init.c index 63c49da07..3ddf8abc2 100644 --- a/src/mintdb/perf_taler_mintdb_init.c +++ b/src/mintdb/perf_taler_mintdb_init.c @@ -34,66 +34,49 @@ struct TALER_MINTDB_CollectableBlindcoin * collectable_blindcoin_init () { + uint32_t random_int; struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key; struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key; - // indent by 2 spaces - struct TALER_MINTDB_CollectableBlindcoin *coin = - GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin); + struct { + struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + uint32_t data; + } unsigned_data; + struct TALER_MINTDB_CollectableBlindcoin *coin; + + coin = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin); GNUNET_assert (NULL != - (reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create ()) - ); + (reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create ())); GNUNET_assert (NULL != - (denomination_key = GNUNET_CRYPTO_rsa_private_key_create (512)) - ); + (denomination_key = GNUNET_CRYPTO_rsa_private_key_create (512))); GNUNET_assert (NULL == - (coin->denom_pub.rsa_public_key = - GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key)) - ); - + (coin->denom_pub.rsa_public_key = + GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key))); GNUNET_CRYPTO_eddsa_key_get_public (reserve_sig_key, - &coin->reserve_pub.eddsa_pub); - + &coin->reserve_pub.eddsa_pub); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":1.1", - &coin->amount_with_fee)); - + TALER_string_to_amount (CURRENCY ":1.1", + &coin->amount_with_fee)); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":1.1", - &coin->withdraw_fee)); - - - - uint32_t random_int = + TALER_string_to_amount (CURRENCY ":1.1", + &coin->withdraw_fee)); + random_int = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); GNUNET_assert (NULL != - (coin->sig.rsa_signature = - GNUNET_CRYPTO_rsa_sign (denomination_key, - &random_int, - sizeof (random_int) - )) - ); - + (coin->sig.rsa_signature = + GNUNET_CRYPTO_rsa_sign (denomination_key, + &random_int, + sizeof (random_int)))); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, - &coin->h_coin_envelope); - - struct { - struct GNUNET_CRYPTO_EccSignaturePurpose purpose; - uint32_t data; - } unsigned_data; - - unsigned_data.purpose.size = sizeof (unsigned_data); - unsigned_data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_TEST; - unsigned_data.data = random_int; - + &coin->h_coin_envelope); + unsigned_data.purpose.size = htonl (sizeof (unsigned_data)); + unsigned_data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); + unsigned_data.data = htonl (random_int); GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign (reserve_sig_key, - (struct GNUNET_CRYPTO_EccSignaturePurpose *) &unsigned_data, - &coin->reserve_sig.eddsa_signature) - ); - - - GNUNET_CRYPTO_eddsa_key_clear (reserve_sig_key); + GNUNET_CRYPTO_eddsa_sign (reserve_sig_key, + (struct GNUNET_CRYPTO_EccSignaturePurpose *) &unsigned_data, + &coin->reserve_sig.eddsa_signature)); + GNUNET_free (reserve_sig_key); GNUNET_CRYPTO_rsa_private_key_free (denomination_key); return coin; } @@ -106,11 +89,10 @@ collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *coin) { if (NULL == coin) return GNUNET_OK; + GNUNET_CRYPTO_rsa_signature_free (coin->sig.rsa_signature); GNUNET_CRYPTO_rsa_public_key_free (coin->denom_pub.rsa_public_key); - GNUNET_free (coin); - return GNUNET_OK; } @@ -121,28 +103,19 @@ collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *coin) struct TALER_MINTDB_Reserve * reserve_init () { - struct TALER_MINTDB_Reserve *reserve ; + struct TALER_MINTDB_Reserve *reserve; + struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv; GNUNET_assert (NULL != - (reserve = GNUNET_new (struct TALER_MINTDB_Reserve) - )); - - struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv ; - + (reserve = GNUNET_new (struct TALER_MINTDB_Reserve))); GNUNET_assert (NULL != - (reserve_priv = GNUNET_CRYPTO_eddsa_key_create () - )); - + (reserve_priv = GNUNET_CRYPTO_eddsa_key_create ())); GNUNET_CRYPTO_eddsa_key_get_public (reserve_priv , - &reserve->pub.eddsa_pub); - + &reserve->pub.eddsa_pub); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":1.1", &reserve->balance) - ); - + TALER_string_to_amount (CURRENCY ":1.1", &reserve->balance)); reserve->expiry = GNUNET_TIME_absolute_get_forever_ (); - - GNUNET_CRYPTO_eddsa_key_clear (reserve_priv); + GNUNET_free (reserve_priv); return reserve; } @@ -165,10 +138,9 @@ struct TALER_MINTDB_RefreshSession * refresh_session_init () { struct TALER_MINTDB_RefreshSession *refresh_session; - GNUNET_assert (NULL != - (refresh_session = GNUNET_new (struct TALER_MINTDB_RefreshSession) - )); + GNUNET_assert (NULL != + (refresh_session = GNUNET_new (struct TALER_MINTDB_RefreshSession))); refresh_session->noreveal_index = 1; refresh_session->num_oldcoins = 1; refresh_session->num_newcoins = 1; @@ -198,26 +170,20 @@ deposit_init () struct TALER_MINTDB_Deposit *deposit; GNUNET_assert (NULL != - (deposit = GNUNET_new (struct TALER_MINTDB_Deposit) - )); + (deposit = GNUNET_new (struct TALER_MINTDB_Deposit))); deposit-> transaction_id = transaction_id; GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":1.1", &deposit->amount_with_fee) - ); - + TALER_string_to_amount (CURRENCY ":1.1", + &deposit->amount_with_fee)); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":0.1", &deposit->deposit_fee) - ); - - + TALER_string_to_amount (CURRENCY ":0.1", + &deposit->deposit_fee)); deposit->timestamp = GNUNET_TIME_absolute_get (); deposit->refund_deadline = GNUNET_TIME_absolute_get (); - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, - &deposit->h_contract); + &deposit->h_contract); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, - &deposit->h_wire); - + &deposit->h_wire); // Coin Spend Signature { struct u32_presign @@ -225,81 +191,61 @@ deposit_init () struct GNUNET_CRYPTO_EccSignaturePurpose purpose; uint32_t data; } unsigned_data; - struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt; - GNUNET_assert (NULL != - (eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create () - )); - - uint32_t random_int = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + uint32_t random_int; + GNUNET_assert (NULL != + (eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create ())); + random_int = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + UINT32_MAX); unsigned_data.purpose.size = htonl (sizeof (struct u32_presign)); unsigned_data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); unsigned_data.data = random_int; - GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign (eddsa_prvt, - &unsigned_data.purpose, - &deposit->csig.eddsa_signature)); - - GNUNET_CRYPTO_eddsa_key_clear (eddsa_prvt); + GNUNET_CRYPTO_eddsa_sign (eddsa_prvt, + &unsigned_data.purpose, + &deposit->csig.eddsa_signature)); + // No need to clear as this is a dummy key + GNUNET_free (eddsa_prvt); } - - printf("coin signed"); // Merchant Key { struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prv; - GNUNET_assert(NULL != - (eddsa_prv = GNUNET_CRYPTO_eddsa_key_create () - )); + GNUNET_assert(NULL != + (eddsa_prv = GNUNET_CRYPTO_eddsa_key_create ())); GNUNET_CRYPTO_eddsa_key_get_public ( - eddsa_prv, - &deposit->merchant_pub.eddsa_pub); - - - GNUNET_CRYPTO_eddsa_key_clear (eddsa_prv); + eddsa_prv, + &deposit->merchant_pub.eddsa_pub); + GNUNET_free (eddsa_prv); } - - printf("merchant ok"); // Coin { { struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt; - GNUNET_assert (NULL != - (eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create () - )); + GNUNET_assert (NULL != + (eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create ())); GNUNET_CRYPTO_eddsa_key_get_public ( - eddsa_prvt, - &deposit->coin.coin_pub.eddsa_pub - ); - - - GNUNET_CRYPTO_eddsa_key_clear (eddsa_prvt); + eddsa_prvt, + &deposit->coin.coin_pub.eddsa_pub); + GNUNET_free (eddsa_prvt); } { struct GNUNET_CRYPTO_rsa_PrivateKey *rsa_prv; - GNUNET_assert (NULL != - (rsa_prv = GNUNET_CRYPTO_rsa_private_key_create (128) - )); GNUNET_assert (NULL != - (deposit->coin.denom_pub.rsa_public_key = - GNUNET_CRYPTO_rsa_private_key_get_public (rsa_prv) - )); - + (rsa_prv = GNUNET_CRYPTO_rsa_private_key_create (128))); GNUNET_assert (NULL != - (deposit->coin.denom_sig.rsa_signature = - GNUNET_CRYPTO_rsa_sign (rsa_prv, - (void *) &deposit->coin.coin_pub.eddsa_pub, - sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) - ) - )); - + (deposit->coin.denom_pub.rsa_public_key = + GNUNET_CRYPTO_rsa_private_key_get_public (rsa_prv))); + GNUNET_assert (NULL != + (deposit->coin.denom_sig.rsa_signature = + GNUNET_CRYPTO_rsa_sign (rsa_prv, + &deposit->coin.coin_pub.eddsa_pub, + sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)))); GNUNET_CRYPTO_rsa_private_key_free (rsa_prv); } } @@ -317,7 +263,6 @@ deposit_free (struct TALER_MINTDB_Deposit *deposit) return GNUNET_OK; GNUNET_CRYPTO_rsa_public_key_free (deposit->coin.denom_pub.rsa_public_key); GNUNET_CRYPTO_rsa_signature_free (deposit->coin.denom_sig.rsa_signature); - GNUNET_free (deposit); return GNUNET_OK; @@ -336,46 +281,32 @@ denomination_init () struct TALER_Amount amount; GNUNET_assert (NULL != - (dki = GNUNET_new (struct TALER_MINTDB_DenominationKeyIssueInformation) - )); - + (dki = GNUNET_new (struct TALER_MINTDB_DenominationKeyIssueInformation))); GNUNET_assert (NULL != - (dki->denom_priv.rsa_private_key - = GNUNET_CRYPTO_rsa_private_key_create (128) - )); + (dki->denom_priv.rsa_private_key + = GNUNET_CRYPTO_rsa_private_key_create (128))); GNUNET_assert (NULL != - (dki->denom_pub.rsa_public_key = - GNUNET_CRYPTO_rsa_private_key_get_public (dki->denom_priv.rsa_private_key) - )); - + (dki->denom_pub.rsa_public_key = + GNUNET_CRYPTO_rsa_private_key_get_public (dki->denom_priv.rsa_private_key))); GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub.rsa_public_key, - &dki->issue.denom_hash); - + &dki->issue.denom_hash); GNUNET_assert (NULL != - (master_prvt = GNUNET_CRYPTO_eddsa_key_create () - )); - - + (master_prvt = GNUNET_CRYPTO_eddsa_key_create ())); GNUNET_CRYPTO_eddsa_key_get_public (master_prvt, - &dki->issue.master.eddsa_pub); - + &dki->issue.master.eddsa_pub); anchor = GNUNET_TIME_absolute_get (); - dki->issue.start = GNUNET_TIME_absolute_hton (anchor); dki->issue.expire_withdraw = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor, - GNUNET_TIME_relative_get_hour_ ())); + GNUNET_TIME_relative_get_hour_ ())); dki->issue.expire_spend = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor, - GNUNET_TIME_relative_get_hour_ ())); + GNUNET_TIME_relative_get_hour_ ())); dki->issue.expire_legal = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor, - GNUNET_TIME_relative_get_hour_ ())); - + GNUNET_TIME_relative_get_hour_ ())); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":1.1", &amount) - ); - + TALER_string_to_amount (CURRENCY ":1.1", &amount)); TALER_amount_hton (&dki->issue.value, &amount); TALER_amount_hton (&dki->issue.fee_withdraw, &amount); TALER_amount_hton (&dki->issue.fee_deposit, &amount); @@ -383,14 +314,13 @@ denomination_init () dki->issue.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY); dki->issue.purpose.size = htonl (sizeof (struct TALER_MINTDB_DenominationKeyIssueInformation) - - offsetof (struct TALER_MINTDB_DenominationKeyIssueInformation, - issue.purpose)); + offsetof (struct TALER_MINTDB_DenominationKeyIssueInformation, + issue.purpose)); GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign (master_prvt, - &dki->issue.purpose, - &dki->issue.signature.eddsa_signature)); - - GNUNET_CRYPTO_eddsa_key_clear (master_prvt); + GNUNET_CRYPTO_eddsa_sign (master_prvt, + &dki->issue.purpose, + &dki->issue.signature.eddsa_signature)); + GNUNET_free (master_prvt); return dki; } @@ -406,7 +336,6 @@ denomination_free (struct TALER_MINTDB_DenominationKeyIssueInformation *dki) return GNUNET_OK; GNUNET_CRYPTO_rsa_private_key_free (dki->denom_priv.rsa_private_key); GNUNET_CRYPTO_rsa_public_key_free (dki->denom_pub.rsa_public_key); - GNUNET_free (dki); return GNUNET_OK; |