LCOV - code coverage report
Current view: top level - util - secmod_signatures.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 34 34 100.0 %
Date: 2021-08-30 06:43:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 secmod_signatures.c
      18             :  * @brief Utility functions for Taler security module signatures
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler_util.h"
      23             : #include "taler_signatures.h"
      24             : 
      25             : 
      26             : void
      27          73 : TALER_exchange_secmod_eddsa_sign (
      28             :   const struct TALER_ExchangePublicKeyP *exchange_pub,
      29             :   struct GNUNET_TIME_Absolute start_sign,
      30             :   struct GNUNET_TIME_Relative duration,
      31             :   const struct TALER_SecurityModulePrivateKeyP *secm_priv,
      32             :   struct TALER_SecurityModuleSignatureP *secm_sig)
      33             : {
      34          73 :   struct TALER_SigningKeyAnnouncementPS ska = {
      35          73 :     .purpose.purpose = htonl (TALER_SIGNATURE_SM_SIGNING_KEY),
      36          73 :     .purpose.size = htonl (sizeof (ska)),
      37             :     .exchange_pub = *exchange_pub,
      38          73 :     .anchor_time = GNUNET_TIME_absolute_hton (start_sign),
      39          73 :     .duration = GNUNET_TIME_relative_hton (duration)
      40             :   };
      41             : 
      42          73 :   GNUNET_CRYPTO_eddsa_sign (&secm_priv->eddsa_priv,
      43             :                             &ska,
      44             :                             &secm_sig->eddsa_signature);
      45          73 : }
      46             : 
      47             : 
      48             : enum GNUNET_GenericReturnValue
      49         101 : TALER_exchange_secmod_eddsa_verify (
      50             :   const struct TALER_ExchangePublicKeyP *exchange_pub,
      51             :   struct GNUNET_TIME_Absolute start_sign,
      52             :   struct GNUNET_TIME_Relative duration,
      53             :   const struct TALER_SecurityModulePublicKeyP *secm_pub,
      54             :   const struct TALER_SecurityModuleSignatureP *secm_sig)
      55             : {
      56         101 :   struct TALER_SigningKeyAnnouncementPS ska = {
      57         101 :     .purpose.purpose = htonl (TALER_SIGNATURE_SM_SIGNING_KEY),
      58         101 :     .purpose.size = htonl (sizeof (ska)),
      59             :     .exchange_pub = *exchange_pub,
      60         101 :     .anchor_time = GNUNET_TIME_absolute_hton (start_sign),
      61         101 :     .duration = GNUNET_TIME_relative_hton (duration)
      62             :   };
      63             : 
      64             :   return
      65         101 :     GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_SM_SIGNING_KEY,
      66             :                                 &ska,
      67             :                                 &secm_sig->eddsa_signature,
      68             :                                 &secm_pub->eddsa_pub);
      69             : }
      70             : 
      71             : 
      72             : void
      73         527 : TALER_exchange_secmod_rsa_sign (
      74             :   const struct GNUNET_HashCode *h_denom_pub,
      75             :   const char *section_name,
      76             :   struct GNUNET_TIME_Absolute start_sign,
      77             :   struct GNUNET_TIME_Relative duration,
      78             :   const struct TALER_SecurityModulePrivateKeyP *secm_priv,
      79             :   struct TALER_SecurityModuleSignatureP *secm_sig)
      80             : {
      81         527 :   struct TALER_DenominationKeyAnnouncementPS dka = {
      82         527 :     .purpose.purpose = htonl (TALER_SIGNATURE_SM_DENOMINATION_KEY),
      83         527 :     .purpose.size = htonl (sizeof (dka)),
      84             :     .h_denom_pub = *h_denom_pub,
      85         527 :     .anchor_time = GNUNET_TIME_absolute_hton (start_sign),
      86         527 :     .duration_withdraw = GNUNET_TIME_relative_hton (duration)
      87             :   };
      88             : 
      89         527 :   GNUNET_CRYPTO_hash (section_name,
      90         527 :                       strlen (section_name) + 1,
      91             :                       &dka.h_section_name);
      92         527 :   GNUNET_CRYPTO_eddsa_sign (&secm_priv->eddsa_priv,
      93             :                             &dka,
      94             :                             &secm_sig->eddsa_signature);
      95             : 
      96         527 : }
      97             : 
      98             : 
      99             : enum GNUNET_GenericReturnValue
     100         745 : TALER_exchange_secmod_rsa_verify (
     101             :   const struct GNUNET_HashCode *h_denom_pub,
     102             :   const char *section_name,
     103             :   struct GNUNET_TIME_Absolute start_sign,
     104             :   struct GNUNET_TIME_Relative duration,
     105             :   const struct TALER_SecurityModulePublicKeyP *secm_pub,
     106             :   const struct TALER_SecurityModuleSignatureP *secm_sig)
     107             : {
     108         745 :   struct TALER_DenominationKeyAnnouncementPS dka = {
     109         745 :     .purpose.purpose = htonl (TALER_SIGNATURE_SM_DENOMINATION_KEY),
     110         745 :     .purpose.size = htonl (sizeof (dka)),
     111             :     .h_denom_pub = *h_denom_pub,
     112         745 :     .anchor_time = GNUNET_TIME_absolute_hton (start_sign),
     113         745 :     .duration_withdraw = GNUNET_TIME_relative_hton (duration)
     114             :   };
     115             : 
     116         745 :   GNUNET_CRYPTO_hash (section_name,
     117         745 :                       strlen (section_name) + 1,
     118             :                       &dka.h_section_name);
     119             :   return
     120         745 :     GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_SM_DENOMINATION_KEY,
     121             :                                 &dka,
     122             :                                 &secm_sig->eddsa_signature,
     123             :                                 &secm_pub->eddsa_pub);
     124             : }
     125             : 
     126             : 
     127             : /* end of secmod_signatures.c */

Generated by: LCOV version 1.14