Package org.apache.sysds.runtime.controlprogram.paramserv

## Class NativeHEHelper

- java.lang.Object
- - org.apache.sysds.runtime.controlprogram.paramserv.NativeHEHelper

    public class NativeHEHelper
    extends Object

### Constructor Summary

Constructors
`NativeHEHelper()`

### Method Summary

All Methods Static Methods Concrete Methods
`static byte[]` `accumulateCiphertexts​(long server, byte[][] ciphertexts)` accumulates the given ciphertexts into a sum ciphertext and returns it
`static byte[]` `aggregatePartialPublicKeys​(long server, byte[][] partial_public_keys)` accumulates the given partial public keys into a public key, stores it in server and returns it
`static double[]` `average​(long server, byte[] encrypted_sum, byte[][] partial_plaintexts)` averages the partial decryptions and returns the result
`static byte[]` `encrypt​(long client, double[] plaintexts)` encrypts data with public key stored in client setPublicKey() must have been called before calling this
`static byte[]` `generateA​(long server)` this generates the a constant.
`static byte[]` `generatePartialPublicKey​(long client)` generates a partial public key stores a partial private key corresponding to the partial public key in client
`static long` `initClient​(byte[] a)` generates a Client object
`static boolean` `initialize()`
`static long` `initServer()` generates the Server object and returns a pointer to it
`static byte[]` `partiallyDecrypt​(long client, byte[] ciphertext)` partially decrypts ciphertexts with the partial private key.
`static void` `setPublicKey​(long client, byte[] public_key)` sets the public key and stores it in client

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### NativeHEHelper

    public NativeHEHelper()

### Method Detail

#### initialize

    public static boolean initialize()

#### initClient

    public static long initClient​(byte[] a)

generates a Client object

Parameters:
  `a` - a constant generated by generateA
Returns:
  a pointer to the native client object

#### generatePartialPublicKey

    public static byte[] generatePartialPublicKey​(long client)

generates a partial public key stores a partial private key corresponding to the partial public key in client

Parameters:
  `client` - A pointer to a Client, obtained from initClient
Returns:
  a serialized partial public key

#### setPublicKey

    public static void setPublicKey​(long client,
                                    byte[] public_key)

sets the public key and stores it in client

Parameters:
  `client` - A pointer to a Client, obtained from initClient
  `public_key` - serialized public key obtained from generatePartialPublicKey

#### encrypt

    public static byte[] encrypt​(long client,
                                 double[] plaintexts)

encrypts data with public key stored in client setPublicKey() must have been called before calling this

Parameters:
  `client` - A pointer to a Client, obtained from initClient
  `plaintexts` - array of double values to be encrypted
Returns:
  serialized ciphertext

#### partiallyDecrypt

    public static byte[] partiallyDecrypt​(long client,
                                          byte[] ciphertext)

partially decrypts ciphertexts with the partial private key. generatePartialPublicKey() must have been called before calling this function

Parameters:
  `client` - A pointer to a Client, obtained from initClient
  `ciphertext` - serialized ciphertext
Returns:
  serialized partial decryption

#### initServer

    public static long initServer()

generates the Server object and returns a pointer to it

Returns:
  pointer to a native Server object

#### generateA

    public static byte[] generateA​(long server)

this generates the a constant. in a future version we want to generate this together with the clients to prevent misuse

Parameters:
  `server` - A pointer to a Server, obtained from initServer
Returns:
  serialized a constant

#### aggregatePartialPublicKeys

    public static byte[] aggregatePartialPublicKeys​(long server,
                                                    byte[][] partial_public_keys)

accumulates the given partial public keys into a public key, stores it in server and returns it

Parameters:
  `server` - A pointer to a Server, obtained from initServer
  `partial_public_keys` - array of serialized partial public keys
Returns:
  serialized partial public key

#### accumulateCiphertexts

    public static byte[] accumulateCiphertexts​(long server,
                                               byte[][] ciphertexts)

accumulates the given ciphertexts into a sum ciphertext and returns it

Parameters:
  `server` - A pointer to a Server, obtained from initServer
  `ciphertexts` - array of serialized ciphertexts
Returns:
  serialized accumulated ciphertext

#### average

    public static double[] average​(long server,
                                   byte[] encrypted_sum,
                                   byte[][] partial_plaintexts)

averages the partial decryptions and returns the result

Parameters:
  `server` - A pointer to a Server, obtained from initServer
  `encrypted_sum` - the result of accumulateCiphertexts()
  `partial_plaintexts` - the result of partiallyDecrypt of each ciphertext fed into accumulateCiphertexts
Returns:
  average of original data