• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_R1_SHARE_KEYS_INPUT_SET_STATE_H_
18 #define FCP_SECAGG_CLIENT_SECAGG_CLIENT_R1_SHARE_KEYS_INPUT_SET_STATE_H_
19 
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "fcp/base/monitoring.h"
26 #include "fcp/secagg/client/secagg_client_r1_share_keys_base_state.h"
27 #include "fcp/secagg/client/secagg_client_state.h"
28 #include "fcp/secagg/client/send_to_server_interface.h"
29 #include "fcp/secagg/client/state_transition_listener_interface.h"
30 #include "fcp/secagg/shared/aes_prng_factory.h"
31 #include "fcp/secagg/shared/ecdh_key_agreement.h"
32 #include "fcp/secagg/shared/input_vector_specification.h"
33 #include "fcp/secagg/shared/prng.h"
34 #include "fcp/secagg/shared/secagg_messages.pb.h"
35 
36 namespace fcp {
37 namespace secagg {
38 
39 // This class represents the client's Round 1: Share Keys state with the input
40 // already set. This state should transition to the Round 2: Masked Input
41 // Collection (Input Set) state, but can also transition directly to the
42 // Completed or Aborted states.
43 
44 class SecAggClientR1ShareKeysInputSetState
45     : public SecAggClientR1ShareKeysBaseState {
46  public:
47   SecAggClientR1ShareKeysInputSetState(
48       uint32_t max_neighbors_expected,
49       uint32_t minimum_surviving_neighbors_for_reconstruction,
50       std::unique_ptr<EcdhKeyAgreement> enc_key_agreement,
51       std::unique_ptr<SecAggVectorMap> input_map,
52       std::unique_ptr<std::vector<InputVectorSpecification> >
53           input_vector_specs,
54       std::unique_ptr<SecurePrng> prng,
55       std::unique_ptr<EcdhKeyAgreement> prng_key_agreement,
56       std::unique_ptr<SendToServerInterface> sender,
57       std::unique_ptr<StateTransitionListenerInterface> transition_listener,
58       std::unique_ptr<AesPrngFactory> prng_factory,
59       AsyncAbort* async_abort = nullptr);
60 
61   ~SecAggClientR1ShareKeysInputSetState() override = default;
62 
63   StatusOr<std::unique_ptr<SecAggClientState> > HandleMessage(
64       const ServerToClientWrapperMessage& message) override;
65 
66   // Returns the name of this state, "R1_SHARE_KEYS_INPUT_SET".
67   std::string StateName() const override;
68 
69  private:
70   friend class SecAggClientR1ShareKeysInputSetStateTest_ShareKeysRequestIsHandledCorrectlyWithDeadClient_Test;  // NOLINT
71 
72   const uint32_t max_neighbors_expected_;
73   const uint32_t minimum_surviving_neighbors_for_reconstruction_;
74   std::unique_ptr<EcdhKeyAgreement> enc_key_agreement_;
75   std::unique_ptr<SecAggVectorMap> input_map_;
76   std::unique_ptr<std::vector<InputVectorSpecification> > input_vector_specs_;
77   std::unique_ptr<SecurePrng> prng_;
78   std::unique_ptr<EcdhKeyAgreement> prng_key_agreement_;
79   std::unique_ptr<AesPrngFactory> prng_factory_;
80   std::vector<ShamirShare> self_prng_key_shares_;
81   std::vector<ShamirShare> pairwise_prng_key_shares_;
82 };
83 
84 }  // namespace secagg
85 }  // namespace fcp
86 
87 #endif  // FCP_SECAGG_CLIENT_SECAGG_CLIENT_R1_SHARE_KEYS_INPUT_SET_STATE_H_
88