sync

Backup service to store encrypted wallet databases (experimental)
Log | Files | Refs | Submodules | README | LICENSE

sync_signatures.c (6788B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2026 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 util/sync_signatures.c
     18  * @brief Utility functions for sync signatures
     19  * @author Iván Ávalos
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_signatures.h>
     23 #include <sync/sync_signatures.h>
     24 
     25 
     26 GNUNET_NETWORK_STRUCT_BEGIN
     27 
     28 /**
     29  * Data signed by the account public key of a sync client to
     30  * authorize the append/update of a block.
     31  */
     32 struct SYNC_BlockUploadSignaturePS
     33 {
     34   struct GNUNET_CRYPTO_SignaturePurpose purpose;
     35 
     36   struct SYNC_BlockNonce prev_nonce;
     37 
     38   struct SYNC_BlockNonce next_nonce;
     39 
     40   struct SYNC_BlockNonce nonce;
     41 
     42   struct GNUNET_HashCode old_hash;
     43 
     44   struct GNUNET_HashCode new_hash;
     45 
     46   struct GNUNET_HashCode refs_hash;
     47 };
     48 
     49 /**
     50  * Data signed by the account public key of a sync client to
     51  * authorize the deletion of a block.
     52  */
     53 struct SYNC_BlockDeleteSignaturePS
     54 {
     55   struct GNUNET_CRYPTO_SignaturePurpose purpose;
     56 
     57   struct SYNC_BlockNonce nonce;
     58 
     59   struct SYNC_BlockNonce prev_nonce;
     60 
     61   struct SYNC_BlockNonce next_nonce;
     62 
     63   struct GNUNET_HashCode hash;
     64 
     65   struct GNUNET_HashCode refs_hash;
     66 };
     67 
     68 /**
     69  * Data signed by the account public key of a sync client to
     70  * authorize the upload of an object.
     71  */
     72 struct SYNC_ObjectUploadSignaturePS
     73 {
     74   struct GNUNET_CRYPTO_SignaturePurpose purpose;
     75 
     76   struct SYNC_ObjectUID uid;
     77 
     78   struct GNUNET_HashCode hash;
     79 };
     80 
     81 GNUNET_NETWORK_STRUCT_END
     82 
     83 
     84 void
     85 SYNC_block_upload_sign (
     86   const struct SYNC_AccountPrivateKeyP *account_priv,
     87   const struct SYNC_BlockNonce *nonce,
     88   const struct SYNC_BlockNonce *prev_nonce,
     89   const struct SYNC_BlockNonce *next_nonce,
     90   const struct GNUNET_HashCode *old_hash,
     91   const struct GNUNET_HashCode *new_hash,
     92   const struct GNUNET_HashCode *refs_hash,
     93   struct SYNC_AccountSignatureP *upload_sig)
     94 {
     95   struct SYNC_BlockUploadSignaturePS busp = {
     96     .purpose.size = htonl (sizeof (busp)),
     97     .purpose.purpose = htonl (TALER_SIGNATURE_SYNC_BLOCK_UPLOAD),
     98     .nonce = *nonce,
     99     .new_hash = *new_hash,
    100     .refs_hash = *refs_hash,
    101   };
    102 
    103   if (NULL != prev_nonce)
    104     busp.prev_nonce = *prev_nonce;
    105   if (NULL != next_nonce)
    106     busp.next_nonce = *next_nonce;
    107   if (NULL != old_hash)
    108     busp.old_hash = *old_hash;
    109 
    110   GNUNET_CRYPTO_eddsa_sign (&account_priv->eddsa_priv,
    111                             &busp,
    112                             &upload_sig->eddsa_sig);
    113 }
    114 
    115 
    116 enum GNUNET_GenericReturnValue
    117 SYNC_block_upload_verify (
    118   const struct SYNC_AccountPublicKeyP *account_pub,
    119   const struct SYNC_BlockNonce *nonce,
    120   const struct SYNC_BlockNonce *prev_nonce,
    121   const struct SYNC_BlockNonce *next_nonce,
    122   const struct GNUNET_HashCode *old_hash,
    123   const struct GNUNET_HashCode *new_hash,
    124   const struct GNUNET_HashCode *refs_hash,
    125   const struct SYNC_AccountSignatureP *upload_sig)
    126 {
    127   struct SYNC_BlockUploadSignaturePS busp = {
    128     .purpose.size = htonl (sizeof (busp)),
    129     .purpose.purpose = htonl (TALER_SIGNATURE_SYNC_BLOCK_UPLOAD),
    130     .nonce = *nonce,
    131     .new_hash = *new_hash,
    132     .refs_hash = *refs_hash,
    133   };
    134 
    135   if (NULL != prev_nonce)
    136     busp.prev_nonce = *prev_nonce;
    137   if (NULL != next_nonce)
    138     busp.next_nonce = *next_nonce;
    139   if (NULL != old_hash)
    140     busp.old_hash = *old_hash;
    141 
    142   return GNUNET_CRYPTO_eddsa_verify (
    143     TALER_SIGNATURE_SYNC_BLOCK_UPLOAD,
    144     &busp,
    145     &upload_sig->eddsa_sig,
    146     &account_pub->eddsa_pub);
    147 }
    148 
    149 
    150 void
    151 SYNC_block_delete_sign (
    152   const struct SYNC_AccountPrivateKeyP *account_priv,
    153   const struct SYNC_BlockNonce *nonce,
    154   const struct SYNC_BlockNonce *prev_nonce,
    155   const struct SYNC_BlockNonce *next_nonce,
    156   const struct GNUNET_HashCode *hash,
    157   const struct GNUNET_HashCode *refs_hash,
    158   struct SYNC_AccountSignatureP *delete_sig)
    159 {
    160   struct SYNC_BlockDeleteSignaturePS bdsp = {
    161     .purpose.size = htonl (sizeof (bdsp)),
    162     .purpose.purpose = htonl (TALER_SIGNATURE_SYNC_BLOCK_DELETE),
    163     .nonce = *nonce,
    164     .hash = *hash,
    165     .refs_hash = *refs_hash,
    166   };
    167 
    168   if (NULL != prev_nonce)
    169     bdsp.prev_nonce = *prev_nonce;
    170   if (NULL != next_nonce)
    171     bdsp.next_nonce = *next_nonce;
    172 
    173   GNUNET_CRYPTO_eddsa_sign (&account_priv->eddsa_priv,
    174                             &bdsp,
    175                             &delete_sig->eddsa_sig);
    176 }
    177 
    178 
    179 enum GNUNET_GenericReturnValue
    180 SYNC_block_delete_verify (
    181   const struct SYNC_AccountPublicKeyP *account_pub,
    182   const struct SYNC_BlockNonce *nonce,
    183   const struct SYNC_BlockNonce *prev_nonce,
    184   const struct SYNC_BlockNonce *next_nonce,
    185   const struct GNUNET_HashCode *hash,
    186   const struct GNUNET_HashCode *refs_hash,
    187   const struct SYNC_AccountSignatureP *delete_sig)
    188 {
    189   struct SYNC_BlockDeleteSignaturePS bdsp = {
    190     .purpose.size = htonl (sizeof (bdsp)),
    191     .purpose.purpose = htonl (TALER_SIGNATURE_SYNC_BLOCK_DELETE),
    192     .nonce = *nonce,
    193     .hash = *hash,
    194     .refs_hash = *refs_hash,
    195   };
    196 
    197   if (NULL != prev_nonce)
    198     bdsp.prev_nonce = *prev_nonce;
    199   if (NULL != next_nonce)
    200     bdsp.next_nonce = *next_nonce;
    201 
    202   return GNUNET_CRYPTO_eddsa_verify (
    203     TALER_SIGNATURE_SYNC_BLOCK_DELETE,
    204     &bdsp,
    205     &delete_sig->eddsa_sig,
    206     &account_pub->eddsa_pub);
    207 }
    208 
    209 
    210 void
    211 SYNC_object_upload_sign (
    212   const struct SYNC_AccountPrivateKeyP *account_priv,
    213   const struct SYNC_ObjectUID *uid,
    214   const struct GNUNET_HashCode *hash,
    215   struct SYNC_AccountSignatureP *upload_sig)
    216 {
    217   struct SYNC_ObjectUploadSignaturePS ousp = {
    218     .purpose.size = htonl (sizeof (ousp)),
    219     .purpose.purpose = htonl (TALER_SIGNATURE_SYNC_OBJECT_UPLOAD),
    220     .uid = *uid,
    221     .hash = *hash,
    222   };
    223 
    224   GNUNET_CRYPTO_eddsa_sign (&account_priv->eddsa_priv,
    225                             &ousp,
    226                             &upload_sig->eddsa_sig);
    227 }
    228 
    229 
    230 enum GNUNET_GenericReturnValue
    231 SYNC_object_upload_verify (
    232   const struct SYNC_AccountPublicKeyP *account_pub,
    233   const struct SYNC_ObjectUID *uid,
    234   const struct GNUNET_HashCode *hash,
    235   const struct SYNC_AccountSignatureP *upload_sig)
    236 {
    237   struct SYNC_ObjectUploadSignaturePS ousp = {
    238     .purpose.size = htonl (sizeof (ousp)),
    239     .purpose.purpose = htonl (TALER_SIGNATURE_SYNC_OBJECT_UPLOAD),
    240     .uid = *uid,
    241     .hash = *hash,
    242   };
    243 
    244   return GNUNET_CRYPTO_eddsa_verify (
    245     TALER_SIGNATURE_SYNC_OBJECT_UPLOAD,
    246     &ousp,
    247     &upload_sig->eddsa_sig,
    248     &account_pub->eddsa_pub);
    249 }