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_R2_MASKED_INPUT_COLL_BASE_STATE_H_ 18 #define FCP_SECAGG_CLIENT_SECAGG_CLIENT_R2_MASKED_INPUT_COLL_BASE_STATE_H_ 19 20 #include <cstdint> 21 #include <memory> 22 #include <set> 23 #include <string> 24 25 #include "absl/container/node_hash_map.h" 26 #include "fcp/base/monitoring.h" 27 #include "fcp/secagg/client/other_client_state.h" 28 #include "fcp/secagg/client/secagg_client_alive_base_state.h" 29 #include "fcp/secagg/client/secagg_client_state.h" 30 #include "fcp/secagg/client/send_to_server_interface.h" 31 #include "fcp/secagg/client/state_transition_listener_interface.h" 32 #include "fcp/secagg/shared/aes_key.h" 33 #include "fcp/secagg/shared/aes_prng_factory.h" 34 #include "fcp/secagg/shared/compute_session_id.h" 35 #include "fcp/secagg/shared/input_vector_specification.h" 36 #include "fcp/secagg/shared/map_of_masks.h" 37 #include "fcp/secagg/shared/secagg_messages.pb.h" 38 #include "fcp/secagg/shared/secagg_vector.h" 39 #include "fcp/secagg/shared/shamir_secret_sharing.h" 40 41 namespace fcp { 42 namespace secagg { 43 44 // This is an abstract class which is the parent of three possible state classes 45 // representing the states that the client may be in at Round 2: Masked Input 46 // Collection. It should never be instantiated directly, but defines code that 47 // will be used by multiple concrete Round 2 classes. 48 49 class SecAggClientR2MaskedInputCollBaseState 50 : public SecAggClientAliveBaseState { 51 public: 52 ~SecAggClientR2MaskedInputCollBaseState() override; 53 54 protected: 55 // SecAggClientR2MaskedInputCollBaseState should never be instantiated 56 // directly. 57 explicit SecAggClientR2MaskedInputCollBaseState( 58 std::unique_ptr<SendToServerInterface> sender, 59 std::unique_ptr<StateTransitionListenerInterface> transition_listener, 60 61 AsyncAbort* async_abort = nullptr); 62 63 // Handles the logic associated with receiving a MaskedInputCollectionRequest. 64 // Adds the recovered key shares to pairwise_key_shares and self_key_shares. 65 // Updates the other_client_states and number_of_alive_clients based on 66 // dropouts recorded in the request. 67 // 68 // The return value is computed map of masks if everything succeeed. 69 // If there was a failure, the return value is nullptr, and error_message is 70 // set to a non-empty string. 71 std::unique_ptr<SecAggVectorMap> HandleMaskedInputCollectionRequest( 72 const MaskedInputCollectionRequest& request, uint32_t client_id, 73 const std::vector<InputVectorSpecification>& input_vector_specs, 74 uint32_t minimum_surviving_neighbors_for_reconstruction, 75 uint32_t number_of_clients, 76 const std::vector<AesKey>& other_client_enc_keys, 77 const std::vector<AesKey>& other_client_prng_keys, 78 const ShamirShare& own_self_key_share, const AesKey& self_prng_key, 79 const SessionId& session_id, const AesPrngFactory& prng_factory, 80 uint32_t* number_of_alive_clients, 81 std::vector<OtherClientState>* other_client_states, 82 std::vector<ShamirShare>* pairwise_key_shares, 83 std::vector<ShamirShare>* self_key_shares, std::string* error_message); 84 85 // Consumes a map of masks to the input map and sends the result of adding 86 // the two to the server. 87 void SendMaskedInput(std::unique_ptr<SecAggVectorMap> input_map, 88 std::unique_ptr<SecAggVectorMap> map_of_masks); 89 }; 90 91 } // namespace secagg 92 } // namespace fcp 93 94 #endif // FCP_SECAGG_CLIENT_SECAGG_CLIENT_R2_MASKED_INPUT_COLL_BASE_STATE_H_ 95