You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@systemds.apache.org by GitBox <gi...@apache.org> on 2022/02/04 15:10:47 UTC

[GitHub] [systemds] flo-l commented on a change in pull request #1525: [SYSTEMDS-3280] WIP: Add homomorphic encryption to Federated Parameter Server

flo-l commented on a change in pull request #1525:
URL: https://github.com/apache/systemds/pull/1525#discussion_r799550147



##########
File path: src/main/java/org/apache/sysds/runtime/controlprogram/paramserv/homomorphicEncryption/SEALServer.java
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ *
+ *   http://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.
+ */
+
+package org.apache.sysds.runtime.controlprogram.paramserv.homomorphicEncryption;
+
+import org.apache.sysds.common.Types;
+import org.apache.sysds.hops.OptimizerUtils;
+import org.apache.sysds.runtime.controlprogram.caching.MatrixObject;
+import org.apache.sysds.runtime.data.DenseBlock;
+import org.apache.sysds.runtime.data.DenseBlockFactory;
+import org.apache.sysds.runtime.instructions.cp.CiphertextMatrix;
+import org.apache.sysds.runtime.instructions.cp.Encrypted;
+import org.apache.sysds.runtime.instructions.cp.PlaintextMatrix;
+import org.apache.sysds.runtime.matrix.data.MatrixBlock;
+import org.apache.sysds.runtime.meta.DataCharacteristics;
+import org.apache.sysds.runtime.meta.MetaDataFormat;
+import org.apache.sysds.utils.NativeHelper;
+
+import java.util.Arrays;
+
+public class SEALServer {
+    public SEALServer() {
+        // TODO take params here, like slot_count etc.
+        ctx = NativeHelper.initServer();
+    }
+
+    // this is a pointer to the context used by all native methods of this class
+    private final long ctx;
+    private byte[] _a;
+
+    // NOTICE: all long[] arys here have to be of size SEAL slot_count
+    // they represent the data of one Ciphertext object
+    // NOTICE: all double[] arys here have to be half the size of SEAL slot_count
+    // they represent the data of one Plaintext object
+
+    // this generates the a constant. in a future version we want to generate this together with the clients to prevent misuse
+    public synchronized byte[] generateA() {
+        if (_a == null) {
+            _a = NativeHelper.generateA(ctx);
+        }
+        return _a;
+    }
+
+    // accumulates the given partial public keys into a public key, stores it in ctx and returns it
+    public PublicKey aggregatePartialPublicKeys(PublicKey[] partial_public_keys) {
+        return new PublicKey(NativeHelper.aggregatePartialPublicKeys(ctx, extractRawData(partial_public_keys)));
+    }
+
+    // accumulates the given ciphertext blocks into a sum ciphertext and returns it
+    // stores c0 of the sum to be used in averageBlocks()
+    public CiphertextMatrix accumulateCiphertexts(CiphertextMatrix[] ciphertexts) {
+        return new CiphertextMatrix(ciphertexts[0].getDims(), ciphertexts[0].getDataCharacteristics(), NativeHelper.accumulateCiphertexts(ctx, extractRawData(ciphertexts)));
+    }
+
+    // averages the partial decryptions and stores the result in old_mo
+    // encrypted_sum is the result of accumulateCiphertexts() and partial_plaintexts is the result of partiallyDecryptBlock
+    // of each ciphertext fed into accumulateCiphertexts

Review comment:
       fixed in 1d738f1766c8369884ce0b3ed793fe2bc7d0d1c1




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org