1 /* 2 * Copyright 2019 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_SERVER_SECAGG_SERVER_R1_SHARE_KEYS_STATE_H_ 18 #define FCP_SECAGG_SERVER_SECAGG_SERVER_R1_SHARE_KEYS_STATE_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "fcp/secagg/server/secagg_server_state.h" 24 25 namespace fcp { 26 namespace secagg { 27 28 // This class is the State for the SecAggServer when it is in the 29 // Round 1: Share Keys state. This state collects encrypted key shares from 30 // clients, and at the end of the round, delivers the appropriate shares to the 31 // right clients. It should transition to Round 2: Masked Input Collection, but 32 // might transition to Aborted if too many clients abort. 33 34 class SecAggServerR1ShareKeysState : public SecAggServerState { 35 public: 36 SecAggServerR1ShareKeysState( 37 std::unique_ptr<SecAggServerProtocolImpl> impl, 38 int number_of_clients_failed_after_sending_masked_input, 39 int number_of_clients_failed_before_sending_masked_input, 40 int number_of_clients_terminated_without_unmasking); 41 42 ~SecAggServerR1ShareKeysState() override; 43 44 // Handles a share keys response or abort message from a client. 45 Status HandleMessage(uint32_t client_id, 46 const ClientToServerWrapperMessage& message) override; 47 48 bool IsNumberOfIncludedInputsCommitted() const override; 49 50 int MinimumMessagesNeededForNextRound() const override; 51 52 int NumberOfPendingClients() const override; 53 54 StatusOr<std::unique_ptr<SecAggServerState>> ProceedToNextRound() override; 55 56 // This will return true only after minimum_number_of_clients_to_proceed 57 // clients have sent messages (and not subsequently aborted). 58 bool ReadyForNextRound() const override; 59 60 private: 61 void HandleAbortClient(uint32_t client_id, 62 ClientDropReason reason_code) override; 63 }; 64 65 } // namespace secagg 66 } // namespace fcp 67 68 #endif // FCP_SECAGG_SERVER_SECAGG_SERVER_R1_SHARE_KEYS_STATE_H_ 69