dlpa package

Client and Server of the distributed Laplace Perturbation Algorithm service.

By default, this package exports two classes:

and one function:

  • server which starts a DLPA server.

The distributed Laplace Perturbation Algorithm (DLPA) service is defined in dlpa.proto, see this file for more information.

Submodules

dlpa.client module

Client of the distributed Laplace Perturbation Algorithm (DLPA) service.

class dlpa.client.DLPAClient(host='localhost', port=50051)[source]

Bases: object

DLPAClient provides methods the DLPA service defines.

See dlpa.proto for more information about DLPA service.

Parameters:
  • host – Address of a DLPA server to connect.
  • port – Port number of the DLPA server to connect.
encrypt_noisy_sum(ck, client_id, value, epsilon, rand=None)[source]

Run Encrypt-Noisy-Sum protocol.

Parameters:
  • ck – Client key.
  • client_id – Client ID.
  • value – Scalar or vector to be sent to the server by Encrypt-Sum protocol.
  • epsilon – Parameter to generate Laplace noises.
  • rand – Use specific values as random values used in the protocol. If set None, by default, use actual random values.
Returns:

Time slot number attached to the given value.

encrypt_sum(ck, client_id, value, rand=None, target=None)[source]

Run Encrypt-Sum protocol to send a given value.

This method returns a time slot with which the given value is associated.

Parameters:
  • ck – Client key.
  • client_id – Client ID.
  • value – Scalar or vector to be sent to the server by Encrypt-Sum protocol.
  • rand – Use specific values as random values used in the protocol. If set None, by default, use actual random values.
  • target – If given, store the value with a specific name in the server.
Returns:

Time slot number attached to the given value.

encrypt_sum_squared(ck, client_id, value, rand, target=None)[source]

Run Encrypt-Sum-Squared protocol to send a given value.

This method returns a time slot with which the given value is associated.

Parameters:
  • ck – Client key.
  • client_id – Client ID.
  • value – Scalar or vector to be sent to the server by Encrypt-Sum-Squared protocol.
  • rand – Use specific values as random values used in the protocol.
  • target – If given store the value with a specific name in the server.
Returns:

Time slot number attached to the given value.

get_key(client_id)[source]

Request a client key associated with a given client id.

Parameters:client_id – Given ID of this client.
Returns:a client key object.
Raises:RuntimeError – when the GetKey protocol ends with errors.
static now()[source]

Returns a UNIX time of now.

dlpa.dlpa_pb2 module

class dlpa.dlpa_pb2.BetaDLPAServicer[source]

Bases: object

The Beta API is deprecated for 0.15.0 and later.

It is recommended to use the GA API (classes and functions in this file not marked beta) for all further purposes. This class was generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.

GetKey(request, context)[source]

GetKey is used in the setup phase to obtain keys.

PutEncryptNoisySum(request, context)[source]

PutEncryptNoisySum is used in the first step of Encrypt-Noisy-Sum protocol, to upload a ciphertext. It returns an aggregated ciphertext to create a decription share.

PutEncryptNoisySumLastShare(request, context)[source]

PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a last decryption share.

PutEncryptNoisySumShare(request, context)[source]

PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a set of decryption shares.

PutEncryptSum(request, context)[source]

PutEncryptSum is used in the first step of Encrypt-Sum protocol, to upload a ciphertext. It returns an aggregated ciphertext to create a decription share.

PutEncryptSumShare(request, context)[source]

PutEncryptSumShare is used in the second step of Encrypt-Sum protocol, to upload a decryption share.

PutEncryptSumSquared(request, context)[source]

PutEncryptSumSquared is used in the first step of Encrypt-Sum-Squared protocol, to upload a Ciphertext. It returns an aggregated ciphertext to create a decryption share.

PutEncryptSumSquaredShare(request, context)[source]

PutEncryptSumSquaredShare is used in the second step of Encrypt-Sum-Squared protocol, to upload a decryption share.

class dlpa.dlpa_pb2.BetaDLPAStub[source]

Bases: object

The Beta API is deprecated for 0.15.0 and later.

It is recommended to use the GA API (classes and functions in this file not marked beta) for all further purposes. This class was generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.

GetKey(request, timeout, metadata=None, with_call=False, protocol_options=None)[source]

GetKey is used in the setup phase to obtain keys.

PutEncryptNoisySum(request, timeout, metadata=None, with_call=False, protocol_options=None)[source]

PutEncryptNoisySum is used in the first step of Encrypt-Noisy-Sum protocol, to upload a ciphertext. It returns an aggregated ciphertext to create a decription share.

PutEncryptNoisySumLastShare(request, timeout, metadata=None, with_call=False, protocol_options=None)[source]

PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a last decryption share.

PutEncryptNoisySumShare(request, timeout, metadata=None, with_call=False, protocol_options=None)[source]

PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a set of decryption shares.

PutEncryptSum(request, timeout, metadata=None, with_call=False, protocol_options=None)[source]

PutEncryptSum is used in the first step of Encrypt-Sum protocol, to upload a ciphertext. It returns an aggregated ciphertext to create a decription share.

PutEncryptSumShare(request, timeout, metadata=None, with_call=False, protocol_options=None)[source]

PutEncryptSumShare is used in the second step of Encrypt-Sum protocol, to upload a decryption share.

PutEncryptSumSquared(request, timeout, metadata=None, with_call=False, protocol_options=None)[source]

PutEncryptSumSquared is used in the first step of Encrypt-Sum-Squared protocol, to upload a Ciphertext. It returns an aggregated ciphertext to create a decryption share.

PutEncryptSumSquaredShare(request, timeout, metadata=None, with_call=False, protocol_options=None)[source]

PutEncryptSumSquaredShare is used in the second step of Encrypt-Sum-Squared protocol, to upload a decryption share.

class dlpa.dlpa_pb2.Ciphertext

Bases: google.protobuf.pyext._message.CMessage, google.protobuf.message.Message

DESCRIPTOR = <google.protobuf.pyext._message.MessageDescriptor object>
ID_FIELD_NUMBER = 1
TARGET_FIELD_NUMBER = 4
TIME_FIELD_NUMBER = 2
VALUE_FIELD_NUMBER = 3
class dlpa.dlpa_pb2.CiphertextVector

Bases: google.protobuf.pyext._message.CMessage, google.protobuf.message.Message

C1_FIELD_NUMBER = 1
C2_FIELD_NUMBER = 2
C3_FIELD_NUMBER = 3
C4_FIELD_NUMBER = 4
C5_FIELD_NUMBER = 5
DESCRIPTOR = <google.protobuf.pyext._message.MessageDescriptor object>
class dlpa.dlpa_pb2.ClientKey

Bases: google.protobuf.pyext._message.CMessage, google.protobuf.message.Message

A_FIELD_NUMBER = 2
B_FIELD_NUMBER = 3
DESCRIPTOR = <google.protobuf.pyext._message.MessageDescriptor object>
LAMBDA_U_FIELD_NUMBER = 1
PUBLIC_KEY_FIELD_NUMBER = 4
class dlpa.dlpa_pb2.DLPAServicer[source]

Bases: object

DLPA defines the interface of distributed Laplace Perturbation Algorithm (DLPA) service.

GetKey(request, context)[source]

GetKey is used in the setup phase to obtain keys.

PutEncryptNoisySum(request, context)[source]

PutEncryptNoisySum is used in the first step of Encrypt-Noisy-Sum protocol, to upload a ciphertext. It returns an aggregated ciphertext to create a decription share.

PutEncryptNoisySumLastShare(request, context)[source]

PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a last decryption share.

PutEncryptNoisySumShare(request, context)[source]

PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a set of decryption shares.

PutEncryptSum(request, context)[source]

PutEncryptSum is used in the first step of Encrypt-Sum protocol, to upload a ciphertext. It returns an aggregated ciphertext to create a decription share.

PutEncryptSumShare(request, context)[source]

PutEncryptSumShare is used in the second step of Encrypt-Sum protocol, to upload a decryption share.

PutEncryptSumSquared(request, context)[source]

PutEncryptSumSquared is used in the first step of Encrypt-Sum-Squared protocol, to upload a Ciphertext. It returns an aggregated ciphertext to create a decryption share.

PutEncryptSumSquaredShare(request, context)[source]

PutEncryptSumSquaredShare is used in the second step of Encrypt-Sum-Squared protocol, to upload a decryption share.

class dlpa.dlpa_pb2.DLPAStub(channel)[source]

Bases: object

DLPA defines the interface of distributed Laplace Perturbation Algorithm (DLPA) service.

class dlpa.dlpa_pb2.DecryptionShare

Bases: google.protobuf.pyext._message.CMessage, google.protobuf.message.Message

DESCRIPTOR = <google.protobuf.pyext._message.MessageDescriptor object>
ID_FIELD_NUMBER = 1
SHARE_FIELD_NUMBER = 3
SLOT_FIELD_NUMBER = 2
TARGET_FIELD_NUMBER = 4
class dlpa.dlpa_pb2.EncryptNoisySumCiphertexts

Bases: google.protobuf.pyext._message.CMessage, google.protobuf.message.Message

DESCRIPTOR = <google.protobuf.pyext._message.MessageDescriptor object>
ID_FIELD_NUMBER = 1
TARGET_FIELD_NUMBER = 4
TIME_FIELD_NUMBER = 2
VALUE_FIELD_NUMBER = 3
class dlpa.dlpa_pb2.GetKeyRequest

Bases: google.protobuf.pyext._message.CMessage, google.protobuf.message.Message

DESCRIPTOR = <google.protobuf.pyext._message.MessageDescriptor object>
ID_FIELD_NUMBER = 1
class dlpa.dlpa_pb2.NoResponse

Bases: google.protobuf.pyext._message.CMessage, google.protobuf.message.Message

DESCRIPTOR = <google.protobuf.pyext._message.MessageDescriptor object>
class dlpa.dlpa_pb2.PublicKey

Bases: google.protobuf.pyext._message.CMessage, google.protobuf.message.Message

DESCRIPTOR = <google.protobuf.pyext._message.MessageDescriptor object>
GLAMBDA_FIELD_NUMBER = 3
G_FIELD_NUMBER = 2
M_FIELD_NUMBER = 1
dlpa.dlpa_pb2.add_DLPAServicer_to_server(servicer, server)[source]
dlpa.dlpa_pb2.beta_create_DLPA_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None)[source]

The Beta API is deprecated for 0.15.0 and later.

It is recommended to use the GA API (classes and functions in this file not marked beta) for all further purposes. This function was generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0

dlpa.dlpa_pb2.beta_create_DLPA_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None)[source]

The Beta API is deprecated for 0.15.0 and later.

It is recommended to use the GA API (classes and functions in this file not marked beta) for all further purposes. This function was generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0

dlpa.dlpa_pb2_grpc module

class dlpa.dlpa_pb2_grpc.DLPAServicer[source]

Bases: object

DLPA defines the interface of distributed Laplace Perturbation Algorithm (DLPA) service.

GetKey(request, context)[source]

GetKey is used in the setup phase to obtain keys.

PutEncryptNoisySum(request, context)[source]

PutEncryptNoisySum is used in the first step of Encrypt-Noisy-Sum protocol, to upload a ciphertext. It returns an aggregated ciphertext to create a decription share.

PutEncryptNoisySumLastShare(request, context)[source]

PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a last decryption share.

PutEncryptNoisySumShare(request, context)[source]

PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a set of decryption shares.

PutEncryptSum(request, context)[source]

PutEncryptSum is used in the first step of Encrypt-Sum protocol, to upload a ciphertext. It returns an aggregated ciphertext to create a decription share.

PutEncryptSumShare(request, context)[source]

PutEncryptSumShare is used in the second step of Encrypt-Sum protocol, to upload a decryption share.

PutEncryptSumSquared(request, context)[source]

PutEncryptSumSquared is used in the first step of Encrypt-Sum-Squared protocol, to upload a Ciphertext. It returns an aggregated ciphertext to create a decryption share.

PutEncryptSumSquaredShare(request, context)[source]

PutEncryptSumSquaredShare is used in the second step of Encrypt-Sum-Squared protocol, to upload a decryption share.

class dlpa.dlpa_pb2_grpc.DLPAStub(channel)[source]

Bases: object

DLPA defines the interface of distributed Laplace Perturbation Algorithm (DLPA) service.

dlpa.dlpa_pb2_grpc.add_DLPAServicer_to_server(servicer, server)[source]

dlpa.key module

Public/private keys and encryption/decryption methods for the DLPA service.

class dlpa.key.ClientKey(pk, Lambda_u, a, b)[source]

Bases: object

Client’s private key of the DLPA service.

encrypt_noisy_sum(v, sigma, R=None)[source]

Encrypt a given number for Encrypt-Noisy-Sum.

encrypt_sum(v, r=None)[source]

Encrypt a given value.

encrypt_sum_squared(y, r)[source]

Encrypt a given number for Encrypt-Sum-Squared.

class dlpa.key.PrivateKey(pk, Lambda)[source]

Bases: object

Aggregator’s private key of the DLPA service.

aggregate_noisy_sum(C)[source]

Aggregate ciphertexts (c1, c2, c3, c4).

C must be a list of vectors (c1, c2, c3, c4).

aggregate_noisy_sum2(C)[source]

Second aggregate ciphertexts (c1, c2, c3, c4, c5).

C must be a list of vectors (c1, c2, c3, c4, c5).

aggregate_noisy_sum3(c1, c2, c3, c4, c5)[source]

Aggregate five cipertexts for Encrypt-Noisy-Sum.

The result \(c\) is

\[c = \frac{c^{1}c^{2}c^{5}}{c^{3}c^{4}}\]
aggregate_sum(ciphertexts)[source]

Aggregate a set of ciphertexts for the encrypt-sum algorithm.

aggregate_sum_squared(ciphertexts)[source]

First aggregation of a set of decryption shares for Encrypt-Sum-Squared.

aggregate_sum_squared2(shares)[source]

Second aggregation of a set of decryption shares for Encrypt-Sum-Squared.

The result \(c\) is

\[c = Enc( (\sum y_{n})^{2} + \sum r_{n})\]
decrypt(v)[source]

Decrypt a given ciphertext v with given key pair.

The plain text is defined:

\[Dec(v) = \frac{L(v^{\lambda})}{L(g^{\lambda})} \mod m\]
Parameters:v – scalar or vector of ciphertext.
Returns:vector of plain texts; even if the input is a scalar, one dimension vector is returned.
decrypt_sum(shares)[source]

Decrypt a set of decryption shares made in the encrypt-sum algorithm.

generate_user_keys(n)[source]

Generate the given number of user’s key.

class dlpa.key.PublicKey(m, g, glambda)[source]

Bases: object

Public key of the DLPA service.

Parameters:
  • m – Public parameter; \(m = pq\) where \(p\) and \(q\) are secret primes.
  • g – Representative element of group G.
  • glambda\(g^{\lambda}\), where \(\lambda = \beta {\rm lcm}(p-1,q-1)\) for a random \(\beta\).
encrypt(v)[source]

Encrypt a given number v.

The ciphertext of v is defined:

\[Enc(v) = g^{v} r^{m} \mod m^{2}\]
Parameters:v – scalar or vector to be encrypted.
Returns:vector of ciphertexts; even if the input is a scalar, one dimension vector is returned.
dlpa.key.generate_keypair(m_length=2048)[source]

Generate a key pair.

dlpa.server module

Server of the distributed Laplace Perturbation Algorithm (DLPA) service.

class dlpa.server.DLPAServicer(nclient=20, m_length=2048, span=300)[source]

Bases: dlpa.dlpa_pb2_grpc.DLPAServicer

DLPAServicer implements DLPAServicer defined in the proto file.

Parameters:
  • nclient – The number of client connecting this server.
  • m_length – Security parameter.
  • span – Second of one time slot.
GetKey(request, context)[source]

GetKey takes a client ID and returns a client key.

PutEncryptNoisySum(request, context)[source]

Takes a cipertext for encrypt-noisy-sum and returns aggregated value.

PutEncryptNoisySumLastShare(request, context)[source]

Takes a decryption share; and decrypts them when receives all shares.

PutEncryptNoisySumShare(request, context)[source]

Takes a cipertext for encrypt-noisy-sum and returns 2nd aggregated value.

PutEncryptSum(request, context)[source]

Takes a cipertext for encrypt-sum and returns aggregated value.

PutEncryptSumShare(request, context)[source]

Takes a decryption share; and decrypts them when receives all shares.

PutEncryptSumSquared(request, context)[source]

Takes a cipertext for encrypt-sum-squared and returns aggregated value.

PutEncryptSumSquaredShare(request, context)[source]

Takes a decryption share; and decrypts them when receives all shares.

aggregate_ciphertexts(conditon, request, _context)[source]

Put a cipertext and wait to aggregate them with a given context.

static aggregate_shares(condition, request, _context)[source]

Put a decryption share; if all shares are put, computes the result.

class dlpa.server.EncryptNoisySumCondition(aggregator, aggregator2, decrypter, nclient)[source]

Bases: dlpa.server.ProtocolCondition

Maintain protocol conditions and results for Encrypt-Noisy-Sum.

wait_aggregation2(slot, cid, value)[source]

Put a ciphertext and wait an aggregated ciphertext.

class dlpa.server.ProtocolCondition(aggregator, decrypter, nclient)[source]

Bases: object

Maintain protocol conditions and results.

put_share(slot, cid, share)[source]

Put a decryption share.

result(slot)[source]

Wait a result issued in a given slot.

wait_aggregation(slot, cid, value)[source]

Put a ciphertext and wait an aggregated ciphertext.

dlpa.server.main()[source]

The main function.

dlpa.server.server(port=50051, max_workers=10, servicer=None, **kwargs)[source]

Create a new server listening a given port.

This function starts the created server; but caller is responsible for stop it.

One of the servicer argument or the pair of the nclient and m_length arguments must be given.

Parameters:
  • port – Port number the created server listen.
  • max_workers – The number of maximum service workers.
  • servicer – Instance DLPAServicer.
  • nclient – The number of client connecting this server.
  • m_length – Security parameter.
Returns:

Server object which has stop method. Callers are responsible for calling this stop function to stop the created server.

dlpa.util module

Provides helper functions for the DLPA service.

dlpa.util.gcd(x, y)[source]

Return the G.C.D.

This function implements the Euclidian algorithm to find G.C.D. of two numbers

dlpa.util.getprimeover(N)[source]

Return a random N-bit prime number using the System’s best Cryptographic random source. Use GMP if available, otherwise fallback to PyCrypto

dlpa.util.has_inverse(v, m)[source]

Return True if the given v has an inverse in mod m.

dlpa.util.invert(a, b)[source]

The multiplicitive inverse of a in the integers modulo b. :return int: x, where a * x == 1 mod b

dlpa.util.lcm(x, y)[source]

Return the L.C.M.

This function takes two integers and returns the L.C.M.

dlpa.util.phi(n)[source]

Euler’s totient function.

dlpa.util.powmod(a, b, c)[source]

Uses GMP, if available, to do a^b mod c where a, b, c are integers. :return int: (a ** b) % c

dlpa.util.random_m(m)[source]

Random value from Zm*.