BinFHEContext
- class openfhe.BinFHEContext
Bases:
pybind11_object
- BTKeyGen(self: openfhe.BinFHEContext, sk: lbcrypto::LWEPrivateKeyImpl, keygenMode: openfhe.KEYGEN_MODE = <KEYGEN_MODE.SYM_ENCRYPT: 0>) None
Generates bootstrapping keys.
- Parameters:
sk (LWEPrivateKey) – The secret key.
- Decrypt(self: openfhe.BinFHEContext, sk: lbcrypto::LWEPrivateKeyImpl, ct: lbcrypto::LWECiphertextImpl, p: int = 4) int
Decrypts a ciphertext using a secret key.
- Parameters:
sk (LWEPrivateKey) – The secret key.
ct (LWECiphertext) – The ciphertext.
p (int) – Plaintext modulus (default 4).
- Returns:
The plaintext.
- Return type:
int
- Encrypt(self: openfhe.BinFHEContext, sk: lbcrypto::LWEPrivateKeyImpl, m: int, output: openfhe.BINFHE_OUTPUT = <BINFHE_OUTPUT.BOOTSTRAPPED: 2>, p: int = 4, mod: int = 0) lbcrypto::LWECiphertextImpl
Encrypts a bit or integer using a secret key (symmetric key encryption).
- Parameters:
sk (LWEPrivateKey) – The secret key.
m (int) – The plaintext.
output (BINFHE_OUTPUT) – FRESH to generate a fresh ciphertext, BOOTSTRAPPED to generate a refreshed ciphertext (default).
p (int) – Plaintext modulus (default 4).
mod (int) – Encrypt according to mod instead of m_q if mod != 0.
- Returns:
The ciphertext.
- Return type:
- EvalBinGate(self: openfhe.BinFHEContext, gate: openfhe.BINGATE, ct1: lbcrypto::LWECiphertextImpl, ct2: lbcrypto::LWECiphertextImpl) lbcrypto::LWECiphertextImpl
Evaluates a binary gate (calls bootstrapping as a subroutine).
- Parameters:
gate (BINGATE) – The gate; can be AND, OR, NAND, NOR, XOR, or XNOR.
ct1 (LWECiphertext) – First ciphertext.
ct2 (LWECiphertext) – Second ciphertext.
- Returns:
The resulting ciphertext.
- Return type:
- EvalDecomp(self: openfhe.BinFHEContext, ct: lbcrypto::LWECiphertextImpl) List[lbcrypto::LWECiphertextImpl]
Evaluate ciphertext decomposition
- Parameters:
ct (LWECiphertext) – ciphertext to be bootstrapped
- Returns:
a list with the resulting ciphertexts
- Return type:
List[LWECiphertext]
- EvalFloor(self: openfhe.BinFHEContext, ct: lbcrypto::LWECiphertextImpl, roundbits: int = 0) lbcrypto::LWECiphertextImpl
Evaluate a round down function
- Parameters:
ct (LWECiphertext) – ciphertext to be bootstrapped
roundbits (int) – number of bits to be rounded
- Returns:
the resulting ciphertext
- Return type:
- EvalFunc(self: openfhe.BinFHEContext, ct: lbcrypto::LWECiphertextImpl, LUT: List[int]) lbcrypto::LWECiphertextImpl
Evaluate an arbitrary function
- Parameters:
ct (LWECiphertext) – ciphertext to be bootstrapped
LUT (List[int]) – the look-up table of the to-be-evaluated function
- Returns:
the resulting ciphertext
- Return type:
- EvalNOT(self: openfhe.BinFHEContext, ct: lbcrypto::LWECiphertextImpl) lbcrypto::LWECiphertextImpl
Evaluates the NOT gate.
- Parameters:
ct (LWECiphertext) – The input ciphertext.
- Returns:
The resulting ciphertext.
- Return type:
- EvalSign(self: openfhe.BinFHEContext, ct: lbcrypto::LWECiphertextImpl, schemeSwitch: bool = False) lbcrypto::LWECiphertextImpl
Evaluate a sign function over large precisions
- Parameters:
ct (LWECiphertext) – ciphertext to be bootstrapped
schemeSwitch (bool) – flag that indicates if it should be compatible to scheme switching
- Returns:
the resulting ciphertext
- Return type:
- GenerateBinFHEContext(*args, **kwargs)
Overloaded function.
GenerateBinFHEContext(self: openfhe.BinFHEContext, set: openfhe.BINFHE_PARAMSET, method: openfhe.BINFHE_METHOD = <BINFHE_METHOD.GINX: 2>) -> None
Creates a crypto context using predefined parameters sets. Recommended for most users.
- param set:
the parameter set: TOY, MEDIUM, STD128, STD192, STD256 with variants
- type set:
BINFHE_PARAMSET
- param method:
the bootstrapping method (DM or CGGI or LMKCDEY)
- type method:
BINFHE_METHOD
- return:
The created crypto context.
- rtype:
BinFHEContext
GenerateBinFHEContext(self: openfhe.BinFHEContext, set: openfhe.BINFHE_PARAMSET, arbFunc: bool, logQ: int = 11, N: int = 0, method: openfhe.BINFHE_METHOD = <BINFHE_METHOD.GINX: 2>, timeOptimization: bool = False) -> None
Creates a crypto context using custom parameters. Should be used with care (only for advanced users familiar with LWE parameter selection).
- param set:
The parameter set: TOY, MEDIUM, STD128, STD192, STD256 with variants.
- type set:
BINFHE_PARAMSET
- param arbFunc:
whether need to evaluate an arbitrary function using functional bootstrapping
- type arbFunc:
bool
- param logQ:
log(input ciphertext modulus)
- type logQ:
int
- param N:
ring dimension for RingGSW/RLWE used in bootstrapping
- type N:
int
- param method:
the bootstrapping method (DM or CGGI or LMKCDEY)
- type method:
BINFHE_METHOD
- param timeOptimization:
whether to use dynamic bootstrapping technique
- type timeOptimization:
bool
- return:
creates the cryptocontext.
- rtype:
BinFHEContext
- GenerateLUTviaFunction(self: openfhe.BinFHEContext, f: function, p: int) List[int]
Generate the LUT for the to-be-evaluated function
- Parameters:
f (function(int, int) -> int) – the to-be-evaluated function on an integer message and a plaintext modulus
p (int) – plaintext modulus
- Returns:
the resulting ciphertext
- Return type:
List[int]
- GetBeta(self: openfhe.BinFHEContext) int
- GetMaxPlaintextSpace(self: openfhe.BinFHEContext) int
- Getn(self: openfhe.BinFHEContext) int
- Getq(self: openfhe.BinFHEContext) int
- KeyGen(self: openfhe.BinFHEContext) lbcrypto::LWEPrivateKeyImpl
Generates a secret key for the main LWE scheme.
- Returns:
The secret key.
- Return type:
LWECiphertext
- class openfhe.LWECiphertext
Bases:
pybind11_object
- GetLength(self: openfhe.LWECiphertext) int
- GetModulus(self: openfhe.LWECiphertext) int
LWEPrivateKey
- class openfhe.LWEPrivateKey
Bases:
pybind11_object
- GetLength(self: openfhe.LWEPrivateKey) int