trusteddealer.c (2184B)
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 trusteddealer.c 18 * @brief Implementation of the trusted dealer key generation 19 * @author Joel Urech 20 */ 21 #include "frost_high.h" 22 #include "keygen.h" 23 #include "keygen_common.h" 24 25 /** 26 * Generates a rnd key pair 27 * 28 * @param[out] sk the complete secret key 29 * @param[out] pk corresponding public key 30 */ 31 static void 32 generate_keypair (struct FROST_DkgSecretKey *sk, 33 struct FROST_PublicKey *pk) 34 { 35 FROST_scalar_random (&sk->sk); 36 FROST_base_mul_scalar (&pk->pk, &sk->sk); 37 } 38 39 40 void 41 FROST_trusted_dealer_keygen (struct FROST_KeyPair key_pairs[], 42 uint8_t num_of_participants, 43 uint8_t threshold) 44 { 45 // Generate keypair 46 struct FROST_DkgSecretKey secret_key; 47 struct FROST_PublicKey public_key; 48 generate_keypair (&secret_key, &public_key); 49 50 struct FROST_DkgShare participant_shares[num_of_participants]; 51 FROST_generate_shares_ (participant_shares, 52 NULL, 53 &secret_key, 54 NULL, 55 num_of_participants, threshold); 56 57 for (int i = 0; i < num_of_participants; i++) 58 { 59 key_pairs[i].identifier = i + 1; 60 FROST_point_copy_to (&key_pairs[i].group_pk.pk, &public_key.pk); 61 FROST_scalar_copy_to (&key_pairs[i].my_sk, 62 &participant_shares[i].share); 63 FROST_base_mul_scalar (&key_pairs[i].my_pk, 64 &participant_shares[i].share); 65 } 66 }