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:
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:

LWECiphertext

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:
Returns:

The resulting ciphertext.

Return type:

LWECiphertext

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:

LWECiphertext

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:

LWECiphertext

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:

LWECiphertext

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:

LWECiphertext

GenerateBinFHEContext(*args, **kwargs)

Overloaded function.

  1. 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

  2. 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:

LWEPrivateKey

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