charity_signatures.c (5898B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2020 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file charity_signatures.c 18 * @brief Utility functions for Taler charity signatures 19 * @author Christian Grothoff 20 * @author Lukas Matyja 21 */ 22 #include "donau_util.h" 23 #include <taler/taler_util.h> 24 #include <gnunet/gnunet_common.h> 25 #include <taler/taler_signatures.h> 26 #include "donau_signatures.h" 27 28 29 GNUNET_NETWORK_STRUCT_BEGIN 30 31 /** 32 * @brief Format used to generate the charity signature on all blinded 33 * identifiers and key pairs as a agreement of the charity with the 34 * donation request from the donor. 35 */ 36 struct DONAU_BudiKeyPairTrackPS 37 { 38 /** 39 * Purpose must be #DONAU_SIGNATURE_DONAU_CHARITY_DONATION_CONFIRMATION. Signed 40 * by a `struct DONAU_CharityPublicKeyP` using EdDSA. 41 */ 42 struct GNUNET_CRYPTO_SignaturePurpose purpose; 43 44 /** 45 * List of BUDI-Key-Pairs. A BUID-Key-Pair contains the BUDI value which must be 46 * signed (blindly) by the Donau. 47 */ 48 struct GNUNET_HashCode bkps_hash; 49 50 /** 51 * num of bkps 52 */ 53 uint32_t num_bkp; 54 55 }; 56 GNUNET_NETWORK_STRUCT_END 57 58 void 59 DONAU_charity_bkp_sign ( 60 const size_t num_bkp, 61 const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, 62 const struct DONAU_CharityPrivateKeyP *charity_priv, 63 struct DONAU_CharitySignatureP *charity_sig) 64 { 65 struct DONAU_BudiKeyPairTrackPS tps = { 66 .purpose.purpose = htonl (DONAU_SIGNATURE_CHARITY_DONATION_CONFIRMATION), 67 .purpose.size = htonl (sizeof (tps)), 68 .num_bkp = htonl (num_bkp) 69 }; 70 struct GNUNET_HashContext *hc; 71 72 hc = GNUNET_CRYPTO_hash_context_start (); 73 for (unsigned int i = 0; i < num_bkp; i++) 74 { 75 const struct GNUNET_CRYPTO_BlindedMessage *bm 76 = bkp[i].blinded_udi.blinded_message; 77 78 GNUNET_CRYPTO_hash_context_read (hc, 79 &bkp[i].h_donation_unit_pub, 80 sizeof (bkp[i].h_donation_unit_pub)); 81 switch (bm->cipher) 82 { 83 case GNUNET_CRYPTO_BSA_INVALID: 84 GNUNET_assert (0); 85 case GNUNET_CRYPTO_BSA_CS: 86 GNUNET_CRYPTO_hash_context_read ( 87 hc, 88 &bm->details.cs_blinded_message, 89 sizeof (bm->details.cs_blinded_message)); 90 break; 91 case GNUNET_CRYPTO_BSA_RSA: 92 GNUNET_CRYPTO_hash_context_read ( 93 hc, 94 bm->details.rsa_blinded_message.blinded_msg, 95 bm->details.rsa_blinded_message.blinded_msg_size); 96 break; 97 } 98 } 99 GNUNET_CRYPTO_hash_context_finish (hc, 100 &tps.bkps_hash); 101 102 GNUNET_CRYPTO_eddsa_sign (&charity_priv->eddsa_priv, 103 &tps, 104 &charity_sig->eddsa_sig); 105 } 106 107 108 enum GNUNET_GenericReturnValue 109 DONAU_charity_bkp_verify ( 110 const size_t num_bkp, 111 const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, 112 const struct DONAU_CharityPublicKeyP *charity_pub, 113 const struct DONAU_CharitySignatureP *charity_sig) 114 { 115 struct DONAU_BudiKeyPairTrackPS tps = { 116 .purpose.purpose = htonl (DONAU_SIGNATURE_CHARITY_DONATION_CONFIRMATION), 117 .purpose.size = htonl (sizeof (tps)), 118 .num_bkp = htonl (num_bkp) 119 }; 120 struct GNUNET_HashContext *hc; 121 122 hc = GNUNET_CRYPTO_hash_context_start (); 123 for (unsigned int i = 0; i < num_bkp; i++) 124 { 125 const struct GNUNET_CRYPTO_BlindedMessage *bm 126 = bkp[i].blinded_udi.blinded_message; 127 128 GNUNET_CRYPTO_hash_context_read (hc, 129 &bkp[i].h_donation_unit_pub, 130 sizeof (bkp[i].h_donation_unit_pub)); 131 switch (bm->cipher) 132 { 133 case GNUNET_CRYPTO_BSA_INVALID: 134 GNUNET_assert (0); 135 case GNUNET_CRYPTO_BSA_CS: 136 GNUNET_CRYPTO_hash_context_read ( 137 hc, 138 &bm->details.cs_blinded_message, 139 sizeof (bm->details.cs_blinded_message)); 140 break; 141 case GNUNET_CRYPTO_BSA_RSA: 142 GNUNET_CRYPTO_hash_context_read ( 143 hc, 144 bm->details.rsa_blinded_message.blinded_msg, 145 bm->details.rsa_blinded_message.blinded_msg_size); 146 break; 147 } 148 } 149 GNUNET_CRYPTO_hash_context_finish (hc, 150 &tps.bkps_hash); 151 152 return 153 GNUNET_CRYPTO_eddsa_verify (DONAU_SIGNATURE_CHARITY_DONATION_CONFIRMATION, 154 &tps, 155 &charity_sig->eddsa_sig, 156 &charity_pub->eddsa_pub); 157 } 158 159 160 enum GNUNET_GenericReturnValue 161 DONAU_charity_get_info_verify ( 162 const struct DONAU_CharityPublicKeyP *charity_pub, 163 const struct DONAU_CharitySignatureP *charity_sig) 164 { 165 struct GNUNET_CRYPTO_SignaturePurpose purpose = { 166 .purpose = htonl (DONAU_SIGNATURE_CHARITY_GET_INFO), 167 .size = htonl (sizeof (purpose)) 168 }; 169 170 return GNUNET_CRYPTO_eddsa_verify_ ( 171 DONAU_SIGNATURE_CHARITY_GET_INFO, 172 &purpose, 173 &charity_sig->eddsa_sig, 174 &charity_pub->eddsa_pub); 175 } 176 177 178 void 179 DONAU_charity_get_info_sign ( 180 const struct DONAU_CharityPrivateKeyP *charity_priv, 181 struct DONAU_CharitySignatureP *charity_sig) 182 { 183 struct GNUNET_CRYPTO_SignaturePurpose purpose = { 184 .purpose = htonl (DONAU_SIGNATURE_CHARITY_GET_INFO), 185 .size = htonl (sizeof (purpose)) 186 }; 187 188 GNUNET_CRYPTO_eddsa_sign_ (&charity_priv->eddsa_priv, 189 &purpose, 190 &charity_sig->eddsa_sig); 191 } 192 193 194 /* end of charity_signatures.c */