aboutsummaryrefslogtreecommitdiff
path: root/private_join_and_compute/server_impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'private_join_and_compute/server_impl.h')
-rw-r--r--private_join_and_compute/server_impl.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/private_join_and_compute/server_impl.h b/private_join_and_compute/server_impl.h
new file mode 100644
index 0000000..fb39326
--- /dev/null
+++ b/private_join_and_compute/server_impl.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2019 Google Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OPEN_SOURCE_PRIVATE_INTERSECTION_SUM_SERVER_IMPL_H_
+#define OPEN_SOURCE_PRIVATE_INTERSECTION_SUM_SERVER_IMPL_H_
+
+#include "private_join_and_compute/crypto/context.h"
+#include "private_join_and_compute/crypto/ec_commutative_cipher.h"
+#include "private_join_and_compute/crypto/paillier.h"
+#include "private_join_and_compute/match.pb.h"
+#include "private_join_and_compute/message_sink.h"
+#include "private_join_and_compute/private_intersection_sum.pb.h"
+#include "private_join_and_compute/private_join_and_compute.pb.h"
+#include "private_join_and_compute/protocol_server.h"
+#include "private_join_and_compute/util/status.inc"
+
+namespace private_join_and_compute {
+
+// The "server side" of the intersection-sum protocol. This represents the
+// party that will receive the size of the intersection as its output. The
+// values that will be summed are supplied by the other party; this party will
+// only supply set elements as its inputs.
+class PrivateIntersectionSumProtocolServerImpl : public ProtocolServer {
+ public:
+ PrivateIntersectionSumProtocolServerImpl(
+ ::private_join_and_compute::Context* ctx, std::vector<std::string> inputs)
+ : ctx_(ctx), inputs_(std::move(inputs)) {}
+
+ ~PrivateIntersectionSumProtocolServerImpl() override = default;
+
+ // Executes the next Server round and creates a response.
+ //
+ // If the ClientMessage is StartProtocol, a ServerRoundOne will be sent to the
+ // message sink, containing the encrypted server identifiers.
+ //
+ // If the ClientMessage is ClientRoundOne, a ServerRoundTwo will be sent to
+ // the message sink, containing the intersection size, and encrypted
+ // intersection-sum.
+ //
+ // Fails with InvalidArgument if the message is not a
+ // PrivateIntersectionSumClientMessage of the expected round, or if the
+ // message is otherwise not as expected. Forwards all other failures
+ // encountered.
+ Status Handle(const ClientMessage& request,
+ MessageSink<ServerMessage>* server_message_sink) override;
+
+ bool protocol_finished() override { return protocol_finished_; }
+
+ // Utility function, used for testing.
+ ECCommutativeCipher* GetECCipher() { return ec_cipher_.get(); }
+
+ private:
+ // Encrypts the server's identifiers.
+ StatusOr<PrivateIntersectionSumServerMessage::ServerRoundOne> EncryptSet();
+
+ // Computes the intersection size and encrypted intersection_sum.
+ StatusOr<PrivateIntersectionSumServerMessage::ServerRoundTwo>
+ ComputeIntersection(const PrivateIntersectionSumClientMessage::ClientRoundOne&
+ client_message);
+
+ Context* ctx_; // not owned
+ std::unique_ptr<ECCommutativeCipher> ec_cipher_;
+
+ // inputs_ will first contain the plaintext server identifiers, and later
+ // contain the encrypted server identifiers.
+ std::vector<std::string> inputs_;
+ bool protocol_finished_ = false;
+};
+
+} // namespace private_join_and_compute
+
+#endif // OPEN_SOURCE_PRIVATE_INTERSECTION_SUM_SERVER_IMPL_H_