/* This file is part of TALER Copyright (C) 2014-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 Foundation; either version 3, or (at your option) any later version. TALER is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see */ /** * @file util/donau_crypto.c * @brief Cryptographic utility functions * @author Lukas Matyja */ #include #include #include "donau_util.h" #include GNUNET_NETWORK_STRUCT_BEGIN /** * Structure we hash to compute the group key for * a donation unit group. */ struct DonationUnitGroupP { /** * Value of coins in this donation unit group. */ struct TALER_AmountNBO value; /** * Cipher used for the donation unit, in NBO. */ uint32_t cipher GNUNET_PACKED; }; GNUNET_NETWORK_STRUCT_END void DONAU_donation_unit_group_get_key ( const struct DONAU_DonationUnitGroup *dg, struct GNUNET_HashCode *key) { struct DonationUnitGroupP dgp = { .cipher = htonl (dg->cipher) }; TALER_amount_hton (&dgp.value, &dg->value); GNUNET_CRYPTO_hash (&dgp, sizeof (dgp), key); } int DONAU_donation_unit_pub_cmp ( const struct DONAU_DonationUnitPublicKey *donation_unit1, const struct DONAU_DonationUnitPublicKey *donation_unit2) { if (donation_unit1->bsign_pub_key->cipher != donation_unit2->bsign_pub_key->cipher) return (donation_unit1->bsign_pub_key->cipher > donation_unit2->bsign_pub_key->cipher) ? 1 : -1; return GNUNET_CRYPTO_bsign_pub_cmp (donation_unit1->bsign_pub_key, donation_unit2->bsign_pub_key); } void DONAU_donation_unit_pub_deep_copy ( struct DONAU_DonationUnitPublicKey *donation_unit_dst, const struct DONAU_DonationUnitPublicKey *donation_unit_src) { donation_unit_dst->bsign_pub_key = GNUNET_CRYPTO_bsign_pub_incref (donation_unit_src->bsign_pub_key); } void DONAU_donation_unit_pub_free ( struct DONAU_DonationUnitPublicKey *donation_unit_pub) { if (NULL != donation_unit_pub->bsign_pub_key) { GNUNET_CRYPTO_blind_sign_pub_decref (donation_unit_pub->bsign_pub_key); donation_unit_pub->bsign_pub_key = NULL; } } void DONAU_donation_unit_pub_hash ( const struct DONAU_DonationUnitPublicKey *donation_unit_pub, struct DONAU_DonationUnitHashP *donation_unit_hash ) { struct GNUNET_CRYPTO_BlindSignPublicKey *bsp = donation_unit_pub->bsign_pub_key; switch (bsp->cipher) { case GNUNET_CRYPTO_BSA_RSA: /* Important: this MUST match the way the RSA-secmod does the hashing of the public keys (see donau-httpd_keys.c) */ GNUNET_CRYPTO_rsa_public_key_hash (bsp->details.rsa_public_key, &donation_unit_hash->hash); break; case GNUNET_CRYPTO_BSA_CS: /* Important: this MUST match the way the CS-secmod does the hashing of the public keys (see donau-httpd_keys.c) */ GNUNET_CRYPTO_hash (&bsp->details.cs_public_key, sizeof(bsp->details.cs_public_key), &donation_unit_hash->hash); break; default: GNUNET_assert (0); } }