dkg_commitment.c (1987B)
1 /* 2 This file is part of Frosix 3 Copyright (C) 2022, 2023 Joel Urech 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 dkg_commitment.c 18 * @brief helper functions to initialize and free a dkg commitment struct 19 * @author Joel Urech 20 */ 21 #include "keygen.h" 22 #include <gnunet/gnunet_util_lib.h> 23 24 25 enum GNUNET_GenericReturnValue 26 FROST_initialize_dkg_commitment (struct FROST_DkgCommitment *dkg_commitment, 27 uint8_t my_index, 28 uint8_t threshold) 29 { 30 /* check params */ 31 if (GNUNET_OK != FROST_validate_dkg_params (my_index, 32 threshold, 33 254)) 34 return GNUNET_NO; 35 36 /* abort if calling function misbehaves*/ 37 GNUNET_assert (NULL != dkg_commitment); 38 39 /* init memory and set initial values */ 40 dkg_commitment->identifier = my_index; 41 dkg_commitment->share_comm 42 = GNUNET_malloc (threshold * sizeof (struct FROST_Point)); 43 44 dkg_commitment->shares_commitments_length = threshold; 45 FROST_scalar_zero (&dkg_commitment->zkp.z); 46 FROST_point_identity (&dkg_commitment->zkp.r); 47 48 return GNUNET_OK; 49 } 50 51 52 void 53 FROST_free_dkg_commitment (struct FROST_DkgCommitment dkg_commitments[], 54 size_t length) 55 { 56 for (unsigned int i = 0; i < length; i++) 57 { 58 GNUNET_free (dkg_commitments[i].share_comm); 59 } 60 }