PHE 模块#
小技巧
请使用 from heu import phe 引入 phe 模块
A high-performance partial homomorphic encryption library
- class heu.phe.BatchFloatEncoder#
BatchFloatEncoder can encode two floating number into one plaintext
- decode(self: heu.phe.BatchFloatEncoder, plaintext: heu.phe.Plaintext) tuple#
Decode plaintext and return two cleartexts
- encode(self: heu.phe.BatchFloatEncoder, cleartext_1: float, cleartext_2: float) heu.phe.Plaintext#
Batch encode two cleartexts into one plaintext
- class heu.phe.BatchFloatEncoderParams#
Store parameters for BatchFloatEncoder
- instance(self: heu.phe.BatchFloatEncoderParams, schema: heu.phe.SchemaType) heu::pylib::PyBatchFloatEncoder#
Create BatchFloatEncoder instance
- class heu.phe.BatchIntegerEncoder#
BatchIntegerEncoder can encode two integers into one plaintext
- decode(self: heu.phe.BatchIntegerEncoder, plaintext: heu.phe.Plaintext) tuple#
Decode plaintext and return two cleartexts
- encode(self: heu.phe.BatchIntegerEncoder, cleartext_1: int, cleartext_2: int) heu.phe.Plaintext#
Encode two int64 cleartexts into one plaintext
- class heu.phe.BatchIntegerEncoderParams#
Store parameters for BatchIntegerEncoder
- instance(self: heu.phe.BatchIntegerEncoderParams, schema: heu.phe.SchemaType) heu::pylib::PyBatchIntegerEncoder#
Create BatchIntegerEncoder instance
- class heu.phe.BigintDecoder#
BigintDecoder is used to decode plaintext into Python integers.
BigintEncoder is the most commonly used Encoder type. Creating an BigintEncoder instance depends on schema info, however, schema info is only needed for encoding, that is, decoding does not depend on schema. To make the BigintEncoder implicitly usable when decoding, we split out the decoding part called BigintDecoder, which does not rely on any initialization parameters and can create instances anywhere, making it easier to use
- decode(self: heu.phe.BigintDecoder, plaintext: heu.phe.Plaintext) object#
Decode plaintext to python int number
- class heu.phe.BigintEncoder#
Encode cleartext into plaintext.
BigintEncoder supports arbitrary precision integers
- encode(self: heu.phe.BigintEncoder, cleartext: int) heu.phe.Plaintext#
Encode python int number into plaintext
- class heu.phe.BigintEncoderParams#
- instance(self: heu.phe.BigintEncoderParams, schema: heu.phe.SchemaType) heu::pylib::PyBigintEncoder#
Create BigintEncoder instance
- class heu.phe.Ciphertext#
- class heu.phe.Decryptor#
- decrypt(self: heu.phe.Decryptor, ciphertext: heu.phe.Ciphertext) heu.phe.Plaintext#
Decrypt ciphertext to plaintext
- decrypt_raw(self: heu.phe.Decryptor, ciphertext: heu.phe.Ciphertext) int#
Decrypt and decoding. The decoding behavior is similar to BigintEncoder
- class heu.phe.DestinationHeKit#
- encryptor(self: heu.phe.DestinationHeKit) heu::lib::phe::Encryptor#
Get encryptor
- evaluator(self: heu.phe.DestinationHeKit) heu::lib::phe::Evaluator#
Get evaluator
- class heu.phe.Encryptor#
- encrypt(self: heu.phe.Encryptor, plaintext: heu.phe.Plaintext) heu.phe.Ciphertext#
Encrypt plaintext to ciphertext
- encrypt_raw(self: heu.phe.Encryptor, cleartext: int) heu.phe.Ciphertext#
Encode and encrypt an integer cleartext. The encoding behavior is similar to BigintEncoder
- encrypt_with_audit(self: heu.phe.Encryptor, plaintext: heu.phe.Plaintext) Tuple[heu.phe.Ciphertext, str]#
Encrypt and build audit string including plaintext/random/ciphertext
- class heu.phe.Evaluator#
- add(*args, **kwargs)#
Overloaded function.
add(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext, arg1: heu.phe.Plaintext) -> heu.phe.Ciphertext
add(self: heu.phe.Evaluator, arg0: heu.phe.Plaintext, arg1: heu.phe.Ciphertext) -> heu.phe.Ciphertext
add(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext, arg1: heu.phe.Ciphertext) -> heu.phe.Ciphertext
- add_inplace(*args, **kwargs)#
Overloaded function.
add_inplace(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext, arg1: heu.phe.Plaintext) -> None
add_inplace(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext, arg1: heu.phe.Ciphertext) -> None
- mul(*args, **kwargs)#
Overloaded function.
mul(self: heu.phe.Evaluator, ciphertext: heu.phe.Ciphertext, times: int) -> heu.phe.Ciphertext
mul(self: heu.phe.Evaluator, ciphertext: int, times: heu.phe.Ciphertext) -> heu.phe.Ciphertext
- mul_inplace(self: heu.phe.Evaluator, ciphertext: heu.phe.Ciphertext, times: int) None#
- negate(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext) heu.phe.Ciphertext#
- negate_inplace(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext) None#
- sub(*args, **kwargs)#
Overloaded function.
sub(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext, arg1: heu.phe.Plaintext) -> heu.phe.Ciphertext
sub(self: heu.phe.Evaluator, arg0: heu.phe.Plaintext, arg1: heu.phe.Ciphertext) -> heu.phe.Ciphertext
sub(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext, arg1: heu.phe.Ciphertext) -> heu.phe.Ciphertext
- sub_inplace(*args, **kwargs)#
Overloaded function.
sub_inplace(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext, arg1: heu.phe.Plaintext) -> None
sub_inplace(self: heu.phe.Evaluator, arg0: heu.phe.Ciphertext, arg1: heu.phe.Ciphertext) -> None
- class heu.phe.FloatEncoder#
Encode cleartext into plaintext.
The cleartext can be a floating point number
- decode(self: heu.phe.FloatEncoder, plaintext: heu.phe.Plaintext) float#
Decode plaintext to float number
- encode(*args, **kwargs)#
Overloaded function.
encode(self: heu.phe.FloatEncoder, cleartext: float) -> heu.phe.Plaintext
Encode a float number into plaintext
encode(self: heu.phe.FloatEncoder, cleartext: int) -> heu.phe.Plaintext
Encode an int128 number into plaintext
- class heu.phe.FloatEncoderParams#
- instance(self: heu.phe.FloatEncoderParams, schema: heu.phe.SchemaType) heu::pylib::PyFloatEncoder#
Create FloatEncoder instance
- class heu.phe.HeKit#
- decryptor(self: heu.phe.HeKit) heu::lib::phe::Decryptor#
Get decryptor
- encryptor(self: heu.phe.HeKit) heu::lib::phe::Encryptor#
Get encryptor
- evaluator(self: heu.phe.HeKit) heu::lib::phe::Evaluator#
Get evaluator
- class heu.phe.HeKitPublicBase#
- batch_float_encoder(self: heu.phe.HeKitPublicBase, scale: int = 1000000, padding_bits: int = 32) heu::pylib::PyBatchFloatEncoder#
Get an instance of BatchIntegerEncoder, equal to phe.BatchFloatEncoder(schema, scale, padding_size)
- batch_integer_encoder(self: heu.phe.HeKitPublicBase, scale: int = 1, padding_bits: int = 32) heu::pylib::PyBatchIntegerEncoder#
Get an instance of BatchIntegerEncoder, equal to phe.BatchIntegerEncoder(schema, scale, padding_size)
- bigint_encoder(self: heu.phe.HeKitPublicBase) heu::pylib::PyBigintEncoder#
Get an instance of BigintEncoder, equal to phe.BigintEncoder(schema)
- float_encoder(self: heu.phe.HeKitPublicBase, scale: int = 1000000) heu::pylib::PyFloatEncoder#
Get an instance of FloatEncoder, equal to phe.FloatEncoder(schema, scale)
- get_schema(self: heu.phe.HeKitPublicBase) heu.phe.SchemaType#
Get schema type
- integer_encoder(self: heu.phe.HeKitPublicBase, scale: int = 1000000) heu::pylib::PyIntegerEncoder#
Get an instance of IntegerEncoder, equal to phe.IntegerEncoder(schema, scale)
- plaintext(self: heu.phe.HeKitPublicBase, int_num: int) heu.phe.Plaintext#
Create a plaintext from int without bit size limit, equal to heu.phe.Plaintext(schema, int_num)
- public_key(self: heu.phe.HeKitPublicBase) heu.phe.PublicKey#
Get public key
- class heu.phe.HeKitSecretBase#
- secret_key(self: heu.phe.HeKitSecretBase) heu.phe.SecretKey#
Get secret key
- class heu.phe.IntegerEncoder#
Encode cleartext into plaintext.
The cleartext must be an integer. If the cleartext is a floating-point number, the fractional part will be discarded.
- decode(self: heu.phe.IntegerEncoder, plaintext: heu.phe.Plaintext) object#
Decode plaintext to int128 number
- encode(*args, **kwargs)#
Overloaded function.
encode(self: heu.phe.IntegerEncoder, cleartext: int) -> heu.phe.Plaintext
Encode an int128 number into plaintext
encode(self: heu.phe.IntegerEncoder, arg0: float) -> heu.phe.Plaintext
Encode the integer part of a floating point number. (discarding the fractional part)
- class heu.phe.IntegerEncoderParams#
- instance(self: heu.phe.IntegerEncoderParams, schema: heu.phe.SchemaType) heu::pylib::PyIntegerEncoder#
Create IntegerEncoder instance
- exception heu.phe.PheRuntimeError#
- class heu.phe.Plaintext#
- bit_count(self: heu.phe.Plaintext) int#
Bit size of this plaintext
- is_compatible(self: heu.phe.Plaintext, arg0: heu.phe.SchemaType) bool#
Is this plaintext compatible with schema type ‘x’
- to_bytes(self: heu.phe.Plaintext, length: int, byteorder: str) bytes#
Return an array of bytes representing an integer.
The byteorder argument determines the byte order used to represent the integer. If byteorder is “big”, the most significant byte is at the beginning of the byte array. If byteorder is “little”, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value.
- class heu.phe.PublicKey#
- plaintext_bound(self: heu.phe.PublicKey) heu.phe.Plaintext#
Get max_int, so valid plaintext range is (max_int, -max_int)
- class heu.phe.SchemaType#
Members:
Mock
OU
IPCL
ZPaillier
FPaillier
- FPaillier = <SchemaType.FPaillier: 4>#
- IPCL = <SchemaType.IPCL: 2>#
- Mock = <SchemaType.Mock: 0>#
- OU = <SchemaType.OU: 1>#
- ZPaillier = <SchemaType.ZPaillier: 3>#
- property name#
- property value#
- class heu.phe.SecretKey#
- heu.phe.parse_schema_type(arg0: str) heu.phe.SchemaType#
Parse schema string. (string -> SchemaType)
- heu.phe.setup(*args, **kwargs)#
Overloaded function.
setup(schema_type: heu.phe.SchemaType = <SchemaType.ZPaillier: 3>, key_size: int = 2048) -> heu.phe.HeKit
Setup phe environment by schema type and key size
setup(schema_string: str = ‘z-paillier’, key_size: int = 2048) -> heu.phe.HeKit
Setup phe environment by schema string and key size
setup(public_key: heu.phe.PublicKey) -> heu.phe.DestinationHeKit
Setup phe environment by an already generated public key