xtrace_sdk.x_vec.crypto.paillier_client¶
Attributes¶
Classes¶
Wrapper for the C++ GPU implementation of the Paillier cryptography system. |
|
CPU implementation of Paillier homomorphic encryption optimised for Hamming distance. |
|
Paillier homomorphic encryption client optimised for computing encrypted Hamming distances |
Module Contents¶
- xtrace_sdk.x_vec.crypto.paillier_client.DEVICE¶
- class xtrace_sdk.x_vec.crypto.paillier_client.PaillierGPU(embed_len=512, key_len=1024, skip_key_gen=False)¶
Wrapper for the C++ GPU implementation of the Paillier cryptography system.
This class is not instantiated directly — use
PaillierClientwhich dispatches to this backend automatically whenDEVICE=gpu.- gpu_client¶
- encrypt(embds)¶
Encrypt a batch of binary embedding vectors on GPU.
- decode_hamming_client(cipher)¶
Decrypt a batch of encrypted Hamming distances on GPU.
- stringify_config()¶
Return a JSON string representation of the encryption configuration.
- Return type:
- load_stringified_keys(pk, sk)¶
Load public and secret keys from their JSON string representations.
- Parameters:
pk (str) – JSON-encoded public key produced by
stringify_pk().sk (str) – JSON-encoded secret key produced by
stringify_sk().
- Return type:
None
- load_config(config)¶
Load encryption configuration from a dict produced by
stringify_config().- Parameters:
config (dict) – Configuration dict (
embed_len,key_len).- Return type:
None
- class xtrace_sdk.x_vec.crypto.paillier_client.PaillierCPU(embed_len=512, key_len=1024, skip_key_gen=False)¶
CPU implementation of Paillier homomorphic encryption optimised for Hamming distance.
- chunk_len = 2048¶
- key_len = 1024¶
- embed_len = 512¶
- stringify_config()¶
Return a JSON string representation of the encryption configuration.
- Return type:
- load_stringified_keys(pk, sk)¶
Load public and secret keys from their JSON string representations.
- Parameters:
pk (str) – JSON-encoded public key produced by
stringify_pk().sk (str) – JSON-encoded secret key produced by
stringify_sk().
- Return type:
None
- load_config(config)¶
Load encryption configuration from a dict produced by
stringify_config().- Parameters:
config (dict) – Configuration dict (
embed_len,key_len).- Return type:
None
- id2power(id_)¶
Return the chunk index and bit power for a given position in the padded embedding.
- encrypt(embd)¶
Encrypt a single binary embedding vector.
- class xtrace_sdk.x_vec.crypto.paillier_client.PaillierClient(embed_len=512, key_len=1024, skip_key_gen=False)¶
Bases:
xtrace_sdk.x_vec.crypto.hamming_client_base.HammingClientBasePaillier homomorphic encryption client optimised for computing encrypted Hamming distances between binary embedding vectors. Dispatches to CPU or GPU backend via the
DEVICEenvironment variable (cpuby default).- embed_len = 512¶
- key_len = 1024¶
- chunk_len = 2048¶
- device¶
- client: PaillierGPU | PaillierCPU¶
- static has_gpu()¶
Return
Trueif the GPU backend extension is available and loadable.- Return type:
- encrypt_vec_one(embd)¶
Encrypt a single binary embedding vector.
- encrypt_vec_batch(embds)¶
Encrypt a batch of binary embedding vectors.
- decode_hamming_client_one(cipher)¶
Decrypt a single encrypted Hamming distance returned by the XTrace server.
- Parameters:
cipher (PaillierEncryptedNumber) – Encrypted Hamming encoding.
- Returns:
Plain-text Hamming distance.
- Return type:
- decode_hamming_client_batch(ciphers)¶
Decrypt a batch of encrypted Hamming distances returned by the XTrace server.
- stringify_config()¶
Return a JSON string representation of the encryption configuration.
- Return type:
- load_stringified_keys(pk, sk)¶
Load public and secret keys from their JSON string representations.
- Parameters:
pk (str) – JSON-encoded public key produced by
stringify_pk().sk (str) – JSON-encoded secret key produced by
stringify_sk().
- Return type:
None
- load_config(config)¶
Load encryption configuration from a dict produced by
stringify_config().- Parameters:
config (dict) – Configuration dict (
embed_len,key_len).- Return type:
None