charity_signatures.c (5918B)
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_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 break; 86 case GNUNET_CRYPTO_BSA_CS: 87 GNUNET_CRYPTO_hash_context_read ( 88 hc, 89 &bm->details.cs_blinded_message, 90 sizeof (bm->details.cs_blinded_message)); 91 break; 92 case GNUNET_CRYPTO_BSA_RSA: 93 GNUNET_CRYPTO_hash_context_read ( 94 hc, 95 bm->details.rsa_blinded_message.blinded_msg, 96 bm->details.rsa_blinded_message.blinded_msg_size); 97 break; 98 } 99 } 100 GNUNET_CRYPTO_hash_context_finish (hc, 101 &tps.bkps_hash); 102 103 GNUNET_CRYPTO_eddsa_sign (&charity_priv->eddsa_priv, 104 &tps, 105 &charity_sig->eddsa_sig); 106 } 107 108 109 enum GNUNET_GenericReturnValue 110 DONAU_charity_bkp_verify ( 111 const size_t num_bkp, 112 const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, 113 const struct DONAU_CharityPublicKeyP *charity_pub, 114 const struct DONAU_CharitySignatureP *charity_sig) 115 { 116 struct DONAU_BudiKeyPairTrackPS tps = { 117 .purpose.purpose = htonl (DONAU_SIGNATURE_CHARITY_DONATION_CONFIRMATION), 118 .purpose.size = htonl (sizeof (tps)), 119 .num_bkp = htonl (num_bkp) 120 }; 121 struct GNUNET_HashContext *hc; 122 123 hc = GNUNET_CRYPTO_hash_context_start (); 124 for (unsigned int i = 0; i < num_bkp; i++) 125 { 126 const struct GNUNET_CRYPTO_BlindedMessage *bm 127 = bkp[i].blinded_udi.blinded_message; 128 129 GNUNET_CRYPTO_hash_context_read (hc, 130 &bkp[i].h_donation_unit_pub, 131 sizeof (bkp[i].h_donation_unit_pub)); 132 switch (bm->cipher) 133 { 134 case GNUNET_CRYPTO_BSA_INVALID: 135 GNUNET_assert (0); 136 break; 137 case GNUNET_CRYPTO_BSA_CS: 138 GNUNET_CRYPTO_hash_context_read ( 139 hc, 140 &bm->details.cs_blinded_message, 141 sizeof (bm->details.cs_blinded_message)); 142 break; 143 case GNUNET_CRYPTO_BSA_RSA: 144 GNUNET_CRYPTO_hash_context_read ( 145 hc, 146 bm->details.rsa_blinded_message.blinded_msg, 147 bm->details.rsa_blinded_message.blinded_msg_size); 148 break; 149 } 150 } 151 GNUNET_CRYPTO_hash_context_finish (hc, 152 &tps.bkps_hash); 153 154 return 155 GNUNET_CRYPTO_eddsa_verify (DONAU_SIGNATURE_CHARITY_DONATION_CONFIRMATION, 156 &tps, 157 &charity_sig->eddsa_sig, 158 &charity_pub->eddsa_pub); 159 } 160 161 162 enum GNUNET_GenericReturnValue 163 DONAU_charity_get_info_verify ( 164 const struct DONAU_CharityPublicKeyP *charity_pub, 165 const struct DONAU_CharitySignatureP *charity_sig) 166 { 167 struct GNUNET_CRYPTO_SignaturePurpose purpose = { 168 .purpose = htonl (DONAU_SIGNATURE_CHARITY_GET_INFO), 169 .size = htonl (sizeof (purpose)) 170 }; 171 172 return GNUNET_CRYPTO_eddsa_verify_ ( 173 DONAU_SIGNATURE_CHARITY_GET_INFO, 174 &purpose, 175 &charity_sig->eddsa_sig, 176 &charity_pub->eddsa_pub); 177 } 178 179 180 void 181 DONAU_charity_get_info_sign ( 182 const struct DONAU_CharityPrivateKeyP *charity_priv, 183 struct DONAU_CharitySignatureP *charity_sig) 184 { 185 struct GNUNET_CRYPTO_SignaturePurpose purpose = { 186 .purpose = htonl (DONAU_SIGNATURE_CHARITY_GET_INFO), 187 .size = htonl (sizeof (purpose)) 188 }; 189 190 GNUNET_CRYPTO_eddsa_sign_ (&charity_priv->eddsa_priv, 191 &purpose, 192 &charity_sig->eddsa_sig); 193 } 194 195 196 /* end of charity_signatures.c */