dlpa package¶
Client and Server of the distributed Laplace Perturbation Algorithm service.
By default, this package exports two classes:
DLPAClient
, a client of DLPA service;DLPAServicer
, a servicer of DLPA service.
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.
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.
-
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.
PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a last decryption share.
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 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 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.
PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a last decryption share.
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 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 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.
-
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.
PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a last decryption share.
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 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 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.
Bases:
google.protobuf.pyext._message.CMessage
,google.protobuf.message.Message
- 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.
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.
-
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.
PutEncryptNoisySumShare is used in the second step of Encrypt-Noisy-Sum protocol, to upload a last decryption share.
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 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 is used in the second step of Encrypt-Sum-Squared protocol, to upload a decryption share.
-
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.
- 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_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})\]
-
- 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\).
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.
-
PutEncryptNoisySum
(request, context)[source]¶ Takes a cipertext for encrypt-noisy-sum and returns aggregated value.
Takes a decryption share; and decrypts them when receives all shares.
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.
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.
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.
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.
- class
dlpa.server.
ProtocolCondition
(aggregator, decrypter, nclient)[source]¶ Bases:
object
Maintain protocol conditions and results.
Put a decryption share.
-
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.
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.