keygen_begin.c (3601B)
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 keygen_begin.c 18 * @brief Implementation of the first round of the distributed key generation 19 * @author Joel Urech 20 */ 21 #include "keygen.h" 22 #include "keygen_common.h" 23 24 25 enum GNUNET_GenericReturnValue 26 FROST_keygen_begin (struct FROST_DkgCommitment *dkg_commitment, 27 struct FROST_DkgShare dkg_shares[], 28 const struct FROST_DkgContextString *context_string, 29 const struct FROST_HashCode *additional_data, 30 uint8_t my_index, 31 uint8_t num_of_participants, 32 uint8_t threshold) 33 { 34 /* check params */ 35 if (GNUNET_OK != FROST_validate_dkg_params (my_index, 36 threshold, 37 num_of_participants)) 38 return GNUNET_NO; 39 40 /* check if calling function misbehaves */ 41 GNUNET_assert (NULL != dkg_commitment); 42 GNUNET_assert (NULL != dkg_shares); 43 GNUNET_assert (NULL != context_string); 44 45 /* derive secret value 'x0' from context_string */ 46 struct FROST_DkgSecretKey secret; 47 FROST_kdf_scalar_to_curve (&secret.sk, 48 0, 49 &context_string->con_str); 50 51 /* Generate commitments and shares */ 52 FROST_generate_shares_ (dkg_shares, 53 dkg_commitment, 54 &secret, 55 &context_string->con_str, 56 num_of_participants, 57 threshold); 58 59 /* Generate the signature / zero knowledge proof of secret 'x0' */ 60 61 // hash secret value and map back to a scalar -> our 'rnd'-value 62 struct FROST_HashState r_h_state; 63 FROST_hash_init (&r_h_state); 64 FROST_hash_scalar_update (&r_h_state, 65 &secret.sk); 66 FROST_hash_fixed_update (&r_h_state, 67 "FROST-DKG-ZKP", 68 strlen ("FROST-DKG-ZKP")); 69 struct FROST_HashCode r_h; 70 FROST_hash_final (&r_h_state, 71 &r_h); 72 73 struct FROST_Scalar r; 74 FROST_hash_to_scalar (&r, 75 &r_h); 76 77 // compute signature / zkp 78 FROST_base_mul_scalar (&dkg_commitment->zkp.r, 79 &r); 80 81 struct FROST_DkgShareCommitment s_pub; 82 FROST_base_mul_scalar (&s_pub.sc, 83 &secret.sk); 84 85 struct FROST_DkgChallenge challenge; 86 FROST_generate_dkg_challenge_ (&challenge, 87 my_index, 88 &s_pub, 89 &dkg_commitment->zkp, 90 additional_data); 91 92 FROST_scalar_mul_scalar (&dkg_commitment->zkp.z, 93 &secret.sk, 94 &challenge.c); 95 FROST_scalar_add_scalar (&dkg_commitment->zkp.z, 96 &dkg_commitment->zkp.z, 97 &r); 98 99 return GNUNET_OK; 100 }