xtrace_sdk.x_vec.crypto.paillier_lookup_client¶
Attributes¶
Classes¶
Wrapper for the C++ GPU implementation of the Paillier-Lookup cryptography system. |
|
This is an implementation of paillier cryptography system optimized for caculating hamming distance between |
|
Paillier-Lookup homomorphic encryption client optimised for computing encrypted Hamming |
Module Contents¶
- xtrace_sdk.x_vec.crypto.paillier_lookup_client.DEVICE¶
- class xtrace_sdk.x_vec.crypto.paillier_lookup_client.PaillierLookupGPU(embed_len=512, key_len=1024, alpha_len=50, skip_key_gen=False)¶
Wrapper for the C++ GPU implementation of the Paillier-Lookup cryptography system.
This class is not instantiated directly — use
PaillierLookupClientwhich 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, precomputed_tables=None, tables_bytes=None)¶
Load encryption configuration and optionally restore precomputed tables.
- Parameters:
- Return type:
None
- dump_tables()¶
Dump precomputed tables as a dict of Python-native types for caching.
- Return type:
- class xtrace_sdk.x_vec.crypto.paillier_lookup_client.PaillierLookupCPU(embed_len=512, key_len=1024, alpha_len=50, skip_key_gen=False)¶
This is an implementation of paillier cryptography system optimized for caculating hamming distance between two binary vectors.
- alpha_len = 50¶
- key_len = 1024¶
- chunk_len = 2048¶
- embed_len = 512¶
- stringify_pk()¶
stringify public key for networking/storage purpose
- Returns:
stringified public key
- Return type:
- stringify_sk()¶
stringify secret key for networking/storage purpose
- Returns:
stringified secret key
- Return type:
- stringify_config()¶
stringify crypto context for networking/storage purpose
- Returns:
stringified crypto context
- Return type:
- load_stringified_keys(pk, sk)¶
load stringified keys
- load_config(config, precomputed_tables=None)¶
load crypto context from a json string
- id2power(id_)¶
Helper: return chunk index and corresponding power of 2 for a given position in the padded array.
- encrypt(embd)¶
This function implements the encryption scheme on embedding vectors that needs to be run on client side.
- Parameters:
embd (iterable[0,1]) – the embedding vector to be encrypted
- Returns:
return a list of length chunk_num contaning PaillierEncryptedNumber
- Return type:
PaillierEncryptedNumber
- class xtrace_sdk.x_vec.crypto.paillier_lookup_client.PaillierLookupClient(embed_len=512, key_len=1024, alpha_len=50, skip_key_gen=False)¶
Bases:
xtrace_sdk.x_vec.crypto.hamming_client_base.HammingClientBasePaillier-Lookup homomorphic encryption client optimised for computing encrypted Hamming distances between binary embedding vectors.
Uses precomputed lookup tables to accelerate encryption, making it significantly faster than
PaillierClientfor large collections. Dispatches to CPU or GPU backend via theDEVICEenvironment variable (cpuby default).- alpha_len = 50¶
- key_len = 1024¶
- embed_len = 512¶
- chunk_len = 2048¶
- device¶
- client: PaillierLookupGPU | PaillierLookupCPU¶
- 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, precomputed_tables=None)¶
Load encryption configuration and optionally restore precomputed tables.
- __getstate__()¶
Support for pickling. We serialize the configuration, keys, and for CPU, the precomputed tables.
- Return type: