xref: /aosp_15_r20/external/federated-compute/fcp/secagg/client/secagg_client_r3_unmasking_state.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2018 Google LLC
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 FCP_SECAGG_CLIENT_SECAGG_CLIENT_R3_UNMASKING_STATE_H_
18 #define FCP_SECAGG_CLIENT_SECAGG_CLIENT_R3_UNMASKING_STATE_H_
19 
20 #include <cstdint>
21 #include <memory>
22 #include <set>
23 #include <string>
24 
25 #include "fcp/base/monitoring.h"
26 #include "fcp/secagg/client/other_client_state.h"
27 #include "fcp/secagg/client/secagg_client_alive_base_state.h"
28 #include "fcp/secagg/client/secagg_client_state.h"
29 #include "fcp/secagg/client/send_to_server_interface.h"
30 #include "fcp/secagg/client/state_transition_listener_interface.h"
31 #include "fcp/secagg/shared/secagg_messages.pb.h"
32 #include "fcp/secagg/shared/shamir_secret_sharing.h"
33 
34 namespace fcp {
35 namespace secagg {
36 
37 // This class represents the client's Round 3: Unmasking state. This state
38 // should transition to the Completed state, but can also transition to the
39 // Aborted state.
40 
41 class SecAggClientR3UnmaskingState : public SecAggClientAliveBaseState {
42  public:
43   SecAggClientR3UnmaskingState(
44       uint32_t client_id, uint32_t number_of_alive_neighbors,
45       uint32_t minimum_surviving_neighbors_for_reconstruction,
46       uint32_t number_of_neighbors,
47       std::unique_ptr<std::vector<OtherClientState> > other_client_states,
48       std::unique_ptr<std::vector<ShamirShare> > pairwise_key_shares,
49       std::unique_ptr<std::vector<ShamirShare> > self_key_shares,
50       std::unique_ptr<SendToServerInterface> sender,
51       std::unique_ptr<StateTransitionListenerInterface> transition_listener,
52 
53       AsyncAbort* async_abort = nullptr);
54 
55   ~SecAggClientR3UnmaskingState() override;
56 
57   StatusOr<std::unique_ptr<SecAggClientState> > HandleMessage(
58       const ServerToClientWrapperMessage& message) override;
59 
60   // Returns the name of this state, "R3_UNMASKING".
61   std::string StateName() const override;
62 
63  private:
64   const uint32_t client_id_;
65   uint32_t number_of_alive_neighbors_;
66   const uint32_t minimum_surviving_neighbors_for_reconstruction_;
67   const uint32_t number_of_neighbors_;
68   std::unique_ptr<std::vector<OtherClientState> > other_client_states_;
69   std::unique_ptr<std::vector<ShamirShare> > pairwise_key_shares_;
70   std::unique_ptr<std::vector<ShamirShare> > self_key_shares_;
71 };
72 
73 }  // namespace secagg
74 }  // namespace fcp
75 
76 #endif  // FCP_SECAGG_CLIENT_SECAGG_CLIENT_R3_UNMASKING_STATE_H_
77