1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_ARMOUR_CIPHER_INIT_H 18 #define MINDSPORE_CCSRC_ARMOUR_CIPHER_INIT_H 19 20 #include <vector> 21 #include <string> 22 #include "fl/armour/secure_protocol/secret_sharing.h" 23 #include "proto/ps.pb.h" 24 #include "utils/log_adapter.h" 25 #include "schema/fl_job_generated.h" 26 #include "schema/cipher_generated.h" 27 #include "fl/armour/cipher/cipher_meta_storage.h" 28 29 namespace mindspore { 30 namespace armour { 31 32 // Initialization of secure aggregation. 33 class CipherInit { 34 public: GetInstance()35 static CipherInit &GetInstance() { 36 static CipherInit instance; 37 return instance; 38 } 39 40 // Initialize the parameters of the secure aggregation. 41 bool Init(const CipherPublicPara ¶m, size_t time_out_mutex, size_t cipher_exchange_keys_cnt, 42 size_t cipher_get_keys_cnt, size_t cipher_share_secrets_cnt, size_t cipher_get_secrets_cnt, 43 size_t cipher_get_clientlist_cnt, size_t cipher_reconstruct_secrets_up_cnt); 44 45 // Get public params. which is given to start fl job thread. GetPublicParams()46 CipherPublicPara *GetPublicParams() { return &publicparam_; } 47 48 size_t share_secrets_threshold; // the minimum number of clients to share secret fragments. 49 size_t reconstruct_secrets_threshold; // the minimum number of clients to reconstruct secret mask. 50 size_t exchange_key_threshold; // the minimum number of clients to send public keys. 51 size_t push_list_sign_threshold; // the minimum number of clients to push client list signature. 52 size_t secrets_minnums_; // the minimum number of secret fragment s to reconstruct secret mask. 53 size_t featuremap_; // the size of data to deal. 54 55 CipherPublicPara publicparam_; // the param containing encrypted public parameters. 56 CipherMetaStorage cipher_meta_storage_; 57 58 private: 59 size_t client_list_threshold; // the minimum number of clients to get update model client list. 60 size_t get_key_threshold; // the minimum number of clients to get public keys. 61 size_t get_list_sign_threshold; // the minimum number of clients to get client list signature. 62 size_t get_secrets_threshold; // the minimum number of clients to get secret fragments. 63 size_t time_out_mutex_; // timeout mutex. 64 65 // Check whether the parameters are valid. 66 bool Check_Parames(); 67 }; 68 } // namespace armour 69 } // namespace mindspore 70 71 #endif // MINDSPORE_CCSRC_ARMOUR_CIPHER_COMMON_H 72