• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SHARES_H
18 #define MINDSPORE_CCSRC_ARMOUR_CIPHER_SHARES_H
19 
20 #include <vector>
21 #include <string>
22 #include <memory>
23 #include <map>
24 #include <utility>
25 #include "fl/armour/secure_protocol/secret_sharing.h"
26 #include "proto/ps.pb.h"
27 #include "utils/log_adapter.h"
28 #include "fl/armour/cipher/cipher_init.h"
29 #include "fl/armour/cipher/cipher_meta_storage.h"
30 
31 namespace mindspore {
32 namespace armour {
33 
34 class CipherShares {
35  public:
36   // initialize: get cipher_init_
CipherShares()37   CipherShares() { cipher_init_ = &CipherInit::GetInstance(); }
38   ~CipherShares() = default;
39 
GetInstance()40   static CipherShares &GetInstance() {
41     static CipherShares instance;
42     return instance;
43   }
44 
45   // handle the client's request of share secrets.
46   bool ShareSecrets(const int cur_iterator, const schema::RequestShareSecrets *share_secrets_req,
47                     const std::shared_ptr<fl::server::FBBuilder> &share_secrets_resp_builder,
48                     const string next_req_time);
49   // handle the client's request of get secrets.
50   bool GetSecrets(const schema::GetShareSecrets *get_secrets_req,
51                   const std::shared_ptr<fl::server::FBBuilder> &get_secrets_resp_builder,
52                   const std::string &next_req_time);
53 
54   // build response code of share secrets.
55   void BuildShareSecretsRsp(const std::shared_ptr<fl::server::FBBuilder> &share_secrets_resp_builder,
56                             const schema::ResponseCode retcode, const string &reason, const string &next_req_time,
57                             const int iteration);
58   // build response code of get secrets.
59   void BuildGetSecretsRsp(const std::shared_ptr<fl::server::FBBuilder> &fbb, const schema::ResponseCode retcode,
60                           const size_t iteration, const string &next_req_time,
61                           const std::vector<flatbuffers::Offset<mindspore::schema::ClientShare>> *encrypted_shares);
62   // clear the shared memory.
63   void ClearShareSecrets();
64 
65  private:
66   CipherInit *cipher_init_;  // the parameter of the secure aggregation
67 };
68 }  // namespace armour
69 }  // namespace mindspore
70 
71 #endif  // MINDSPORE_CCSRC_ARMOUR_CIPHER_SHARES_H
72