donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 064e297362fc9ae14b886aad99def74a0b4878b4
parent 02d6199b8cc42f42b847bc7e19010d9dda18887e
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Thu, 18 Apr 2024 00:18:12 +0200

[donau] batch  blind signing

Diffstat:
Msrc/donau/donau-httpd_batch-issue.c | 8+++++---
Msrc/donau/donau-httpd_keys.c | 277+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/donau/donau-httpd_keys.h | 10+++++-----
Msrc/donaudb/donau_do_save_issue_receipts_request.sql | 2+-
Asrc/testing/.test-suite.log.swp | 0
5 files changed, 149 insertions(+), 148 deletions(-)

diff --git a/src/donau/donau-httpd_batch-issue.c b/src/donau/donau-httpd_batch-issue.c @@ -345,12 +345,14 @@ start: bkps_sign_data[i].h_donation_unit_pub = &bkps[i].h_donation_unit_pub; bkps_sign_data[i].budi = &bkps[i].blinded_udi; } - if (TALER_EC_NONE != DH_keys_donation_unit_batch_sign (num_bkps, + enum TALER_ErrorCode batch_sign_ec; + batch_sign_ec = DH_keys_donation_unit_batch_sign (num_bkps, bkps_sign_data, - du_sigs)) + du_sigs); + if (TALER_EC_NONE != batch_sign_ec) return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_FETCH_FAILED, // TODO:other EC + batch_sign_ec, // TODO:other EC NULL); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "made blind signatures!\n"); diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c @@ -1289,147 +1289,146 @@ DH_keys_donau_sign_ ( enum TALER_ErrorCode DH_keys_donation_unit_batch_sign ( - unsigned int budis_length, - const struct DONAU_BkpSignData bkps[budis_length], - struct DONAU_BlindedDonationUnitSignature du_sigs[budis_length]) + unsigned int num_bkps, + const struct DONAU_BkpSignData bkps[num_bkps], + struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkps]) { + struct DH_KeyStateHandle *ksh; + struct DH_DonationUnitKey *du; + struct TALER_CRYPTO_RsaSignRequest rsrs[num_bkps]; + struct TALER_CRYPTO_CsSignRequest csrs[num_bkps]; + struct TALER_BlindedDenominationSignature rs[num_bkps]; + struct TALER_BlindedDenominationSignature cs[num_bkps]; + unsigned int rsrs_pos = 0; + unsigned int csrs_pos = 0; + enum TALER_ErrorCode ec; + + ksh = DH_keys_get_state (); + if (NULL == ksh) + // FIXME change error code + return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING; + for (unsigned int i = 0; i<num_bkps; i++) + { + const struct DONAU_DonationUnitHashP *h_du_pub = bkps[i].h_donation_unit_pub; + const struct DONAU_BlindedUniqueDonorIdentifier *budi = bkps[i].budi; + + du = GNUNET_CONTAINER_multihashmap_get (du_keys, + &h_du_pub->hash); + if (NULL == du) + // FIXME change error code + return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; + if (budi->blinded_message->cipher != + du->donation_unit_pub.bsign_pub_key->cipher) + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + switch (du->donation_unit_pub.bsign_pub_key->cipher) + { + case GNUNET_CRYPTO_BSA_RSA: + /* See DONAU_donation_unit_pub_hash: we guarantee that these + hashes are equivalent! */ + rsrs[rsrs_pos].h_rsa + = (const struct TALER_RsaPubHashP *) &du->h_donation_unit_pub; + rsrs[rsrs_pos].msg + = budi->blinded_message->details.rsa_blinded_message.blinded_msg; + rsrs[rsrs_pos].msg_size + = budi->blinded_message->details.rsa_blinded_message.blinded_msg_size; + rsrs_pos++; + break; + case GNUNET_CRYPTO_BSA_CS: + /* See DONAU_donation_unit_pub_hash: we guarantee that these + hashes are equivalent! */ + csrs[csrs_pos].h_cs + = (const struct TALER_CsPubHashP *) &du->h_donation_unit_pub; + csrs[csrs_pos].blinded_planchet + = &budi->blinded_message->details.cs_blinded_message; + csrs_pos++; + break; + default: + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + } + } + + if ( (0 != csrs_pos) && + (0 != rsrs_pos) ) + { + memset (rs, + 0, + sizeof (rs)); + memset (cs, + 0, + sizeof (cs)); + } + ec = TALER_EC_NONE; + if (0 != csrs_pos) + { + ec = TALER_CRYPTO_helper_cs_batch_sign ( + csdh, + csrs_pos, + csrs, + false, // for_melt + cs); + if (TALER_EC_NONE != ec) + { + for (unsigned int i = 0; i<csrs_pos; i++) + { + if (NULL != cs[i].blinded_sig) + { + GNUNET_CRYPTO_blinded_sig_decref (cs[i].blinded_sig); + cs[i].blinded_sig = NULL; + } + } + return ec; + } + // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS] += csrs_pos; + } + if (0 != rsrs_pos) + { + ec = TALER_CRYPTO_helper_rsa_batch_sign ( + rsadh, + rsrs_pos, + rsrs, + rs); + if (TALER_EC_NONE != ec) + { + for (unsigned int i = 0; i<csrs_pos; i++) + { + if (NULL != cs[i].blinded_sig) + { + GNUNET_CRYPTO_blinded_sig_decref (cs[i].blinded_sig); + cs[i].blinded_sig = NULL; + } + } + for (unsigned int i = 0; i<rsrs_pos; i++) + { + if (NULL != rs[i].blinded_sig) + { + GNUNET_CRYPTO_blinded_sig_decref (rs[i].blinded_sig); + rs[i].blinded_sig = NULL; + } + } + return ec; + } + // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA] += rsrs_pos; + } + + rsrs_pos = 0; + csrs_pos = 0; + for (unsigned int i = 0; i<num_bkps; i++) + { + const struct DONAU_BlindedUniqueDonorIdentifier *budi = bkps[i].budi; + + switch (budi->blinded_message->cipher) + { + case GNUNET_CRYPTO_BSA_RSA: + du_sigs[i].blinded_sig = rs[rsrs_pos++].blinded_sig; + break; + case GNUNET_CRYPTO_BSA_CS: + du_sigs[i].blinded_sig = cs[csrs_pos++].blinded_sig; + break; + default: + GNUNET_assert (0); + } + } return TALER_EC_NONE; - // struct DH_KeyStateHandle *ksh; - // struct DH_DonationUnitKey *du; - // struct TALER_CRYPTO_RsaSignRequest rsrs[csds_length]; - // struct TALER_CRYPTO_CsSignRequest csrs[csds_length]; - // struct TALER_BlindedDenominationSignature rs[csds_length]; - // struct TALER_BlindedDenominationSignature cs[csds_length]; - // unsigned int rsrs_pos = 0; - // unsigned int csrs_pos = 0; - // enum TALER_ErrorCode ec; - - // ksh = DH_keys_get_state (); - // if (NULL == ksh) - // // FIXME change error code - // return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING; - // for (unsigned int i = 0; i<csds_length; i++) - // { - // const struct DONAU_DonationUnitHashP *h_du_pub = csds[i].h_du_pub; - // const struct DONAU_BlindedUniqueDonorIdentifier *budi = csds[i].budi; - - // du = GNUNET_CONTAINER_multihashmap_get (du_keys, - // &h_du_pub->hash); - // if (NULL == du) - // // FIXME change error code - // return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; - // if (budi->blinded_message->cipher != - // du->donation_unit_pub.bsign_pub_key->cipher) - // return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; - // switch (du->donation_unit_pub.bsign_pub_key->cipher) - // { - // case GNUNET_CRYPTO_BSA_RSA: - // /* See DONAU_donation_unit_pub_hash: we guarantee that these - // hashes are equivalent! */ - // rsrs[rsrs_pos].h_rsa - // = (const struct TALER_RsaPubHashP *) &du->h_donation_unit_pub; - // rsrs[rsrs_pos].msg - // = budi->blinded_message->details.rsa_blinded_message.blinded_msg; - // rsrs[rsrs_pos].msg_size - // = budi->blinded_message->details.rsa_blinded_message.blinded_msg_size; - // rsrs_pos++; - // break; - // case GNUNET_CRYPTO_BSA_CS: - // /* See DONAU_donation_unit_pub_hash: we guarantee that these - // hashes are equivalent! */ - // csrs[csrs_pos].h_cs - // = (const struct TALER_CsPubHashP *) &du->h_donation_unit_pub; - // csrs[csrs_pos].blinded_planchet - // = &budi->blinded_message->details.cs_blinded_message; - // csrs_pos++; - // break; - // default: - // return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; - // } - // } - - // if ( (0 != csrs_pos) && - // (0 != rsrs_pos) ) - // { - // memset (rs, - // 0, - // sizeof (rs)); - // memset (cs, - // 0, - // sizeof (cs)); - // } - // ec = TALER_EC_NONE; - // if (0 != csrs_pos) - // { - // ec = TALER_CRYPTO_helper_cs_batch_sign ( - // csdh, - // csrs_pos, - // csrs, - // false, // for_melt - // cs); - // if (TALER_EC_NONE != ec) - // { - // for (unsigned int i = 0; i<csrs_pos; i++) - // { - // if (NULL != cs[i].blinded_sig) - // { - // GNUNET_CRYPTO_blinded_sig_decref (cs[i].blinded_sig); - // cs[i].blinded_sig = NULL; - // } - // } - // return ec; - // } - // // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS] += csrs_pos; - // } - // if (0 != rsrs_pos) - // { - // ec = TALER_CRYPTO_helper_rsa_batch_sign ( - // rsadh, - // rsrs_pos, - // rsrs, - // rs); - // if (TALER_EC_NONE != ec) - // { - // for (unsigned int i = 0; i<csrs_pos; i++) - // { - // if (NULL != cs[i].blinded_sig) - // { - // GNUNET_CRYPTO_blinded_sig_decref (cs[i].blinded_sig); - // cs[i].blinded_sig = NULL; - // } - // } - // for (unsigned int i = 0; i<rsrs_pos; i++) - // { - // if (NULL != rs[i].blinded_sig) - // { - // GNUNET_CRYPTO_blinded_sig_decref (rs[i].blinded_sig); - // rs[i].blinded_sig = NULL; - // } - // } - // return ec; - // } - // // TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA] += rsrs_pos; - // } - - // rsrs_pos = 0; - // csrs_pos = 0; - // for (unsigned int i = 0; i<csds_length; i++) - // { - // const struct DONAU_BlindedUniqueDonorIdentifier *budi = csds[i].budi; - - // switch (budi->blinded_message->cipher) - // { - // case GNUNET_CRYPTO_BSA_RSA: - // bss[i].blinded_sig = rs[rsrs_pos++].blinded_sig; - // break; - // case GNUNET_CRYPTO_BSA_CS: - // bss[i].blinded_sig = cs[csrs_pos++].blinded_sig; - // break; - // default: - // GNUNET_assert (0); - // } - // } - // return TALER_EC_NONE; } diff --git a/src/donau/donau-httpd_keys.h b/src/donau/donau-httpd_keys.h @@ -179,16 +179,16 @@ DH_keys_finished (void); /** * Request to sign @a budis. * - * @param budis_length length of @a budis array + * @param num_bkps length of @a budis array * @param bkps array with data to blindly sign (and keys to sign with) - * @param[out] du_sigs array set to the blind signature on success; must be of length @a budis_length + * @param[out] du_sigs array set to the blind signature on success; must be of length @a num_bkps * @return #TALER_EC_NONE on success */ enum TALER_ErrorCode DH_keys_donation_unit_batch_sign ( - unsigned int budis_length, - const struct DONAU_BkpSignData bkps[budis_length], - struct DONAU_BlindedDonationUnitSignature du_sigs[budis_length]); + unsigned int num_bkps, + const struct DONAU_BkpSignData bkps[num_bkps], + struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkps]); #endif diff --git a/src/donaudb/donau_do_save_issue_receipts_request.sql b/src/donaudb/donau_do_save_issue_receipts_request.sql @@ -29,7 +29,7 @@ BEGIN UPDATE charities SET receipts_to_date = in_new_total_amount; -- Insert into the table receipts_issued INSERT INTO receipts_issued (/*blinded_sig,*/ charity_id, receipt_hash, amount) -VALUES (/*in_blinded_sig,*/ in_charity_id, in_receipt_hash, in_amount) RETURNING receipt_id INTO out_receipt_id; +VALUES (/*in_blinded_sig,*/ in_charity_id, in_receipt_hash, in_amount); --RETURNING receipt_id INTO out_receipt_id; -- Get the receipts id -- SELECT receipt_id INTO out_receipt_id SELECT WHERE receipt_hash=in_receipts_hash FROM receipts_issued ; -- Commit the transaction if everything is successful diff --git a/src/testing/.test-suite.log.swp b/src/testing/.test-suite.log.swp Binary files differ.