verify_signature.c (1837B)
1 /* 2 This file is part of Frosix 3 Copyright (C) 2022, 2023 Frosix 4 5 Frosix is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 Frosix 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 Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 Frosix; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file verify_signature.c 18 * @brief Implementation of the signature verification function 19 * @author Joel Urech 20 */ 21 #include "high_common.h" 22 23 /** 24 * Verifies the validity of a given signature and hash of a message against a 25 * public key. 26 */ 27 enum GNUNET_GenericReturnValue 28 FROST_verify_signature ( 29 const struct FROST_PublicKey *public_key, 30 const struct FROST_Signature *signature, 31 const struct FROST_MessageHash *message_hash) 32 { 33 struct FROST_GroupCommitment sig_r; 34 FROST_point_copy_to (&sig_r.commitment, &signature->r); 35 36 // compute challenge H(r || pk || m) 37 struct FROST_Challenge challenge; 38 FROST_compute_challenge_ (&challenge, &sig_r, public_key, message_hash); 39 40 // pk^challenge 41 struct FROST_Point pk_challenge; 42 FROST_point_mul_scalar (&pk_challenge, &public_key->pk, 43 &challenge.challenge); 44 45 // g^sig 46 struct FROST_Point g_sig; 47 FROST_base_mul_scalar (&g_sig, &signature->z); 48 49 // g^sig - pk^challenge 50 struct FROST_Point ver_r; 51 FROST_point_sub_point (&ver_r, &g_sig, &pk_challenge); 52 53 return FROST_point_cmp (&signature->r, 54 &ver_r); 55 }