donau_signatures.c (3190B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2021, 2022 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 donau_signatures.c 18 * @brief Utility functions for Taler donau security module signatures 19 * @author Christian Grothoff 20 * @author Lukas Matyja 21 */ 22 #include "donau_config.h" 23 #include <taler/taler_util.h> 24 #include <taler/taler_signatures.h> 25 #include "donau_util.h" 26 #include "donau_signatures.h" 27 28 GNUNET_NETWORK_STRUCT_BEGIN 29 30 /** 31 * @brief Format used to generate the signature/donation statement 32 * over the total amount and a donor identifier of a year. 33 */ 34 struct DONAU_DonationStatementConfirmationPS 35 { 36 /** 37 * Purpose must be #DONAU_SIGNATURE_DONAU_DONATION_STATEMENT. Signed 38 * by a `struct DONAU_DonauPublicKeyP` using EdDSA. 39 */ 40 struct GNUNET_CRYPTO_SignaturePurpose purpose; 41 42 /** 43 * Total amount donated of a specific @a year. 44 */ 45 struct TALER_AmountNBO amount_tot; 46 47 /** 48 * The hash of the identifier of the donor. 49 */ 50 struct DONAU_HashDonorTaxId i; 51 52 /** 53 * The corresponding year. 54 */ 55 uint32_t year; 56 57 }; 58 59 GNUNET_NETWORK_STRUCT_END 60 61 62 enum TALER_ErrorCode 63 DONAU_donation_statement_sign ( 64 DONAU_DonauSignCallback scb, 65 const struct TALER_Amount *amount_tot, 66 const uint64_t year, 67 const struct DONAU_HashDonorTaxId *i, 68 struct DONAU_DonauPublicKeyP *donau_pub, 69 struct DONAU_DonauSignatureP *donau_sig) 70 { 71 struct DONAU_DonationStatementConfirmationPS confirm = { 72 .purpose.purpose = htonl (DONAU_SIGNATURE_DONAU_DONATION_STATEMENT), 73 .purpose.size = htonl (sizeof (confirm)), 74 .year = htonl (year), 75 .i = *i 76 }; 77 78 TALER_amount_hton (&confirm.amount_tot, 79 amount_tot); 80 81 return scb (&confirm.purpose, 82 donau_pub, 83 donau_sig); 84 } 85 86 87 enum GNUNET_GenericReturnValue 88 DONAU_donation_statement_verify ( 89 const struct TALER_Amount *amount_tot, 90 const uint64_t year, 91 const struct DONAU_HashDonorTaxId *i, 92 const struct DONAU_DonauPublicKeyP *donau_pub, 93 const struct DONAU_DonauSignatureP *statement_sig) 94 { 95 struct DONAU_DonationStatementConfirmationPS confirm = { 96 .purpose.purpose = htonl (DONAU_SIGNATURE_DONAU_DONATION_STATEMENT), 97 .purpose.size = htonl (sizeof (confirm)), 98 .year = htonl (year), 99 .i = *i 100 }; 101 102 TALER_amount_hton (&confirm.amount_tot, 103 amount_tot); 104 105 return 106 GNUNET_CRYPTO_eddsa_verify (DONAU_SIGNATURE_DONAU_DONATION_STATEMENT, 107 &confirm, 108 &statement_sig->eddsa_sig, 109 &donau_pub->eddsa_pub); 110 } 111 112 113 /* end of donau_signatures.c */