CryptoContext

class openfhe.CryptoContext

Bases: pybind11_object

static ClearEvalAutomorphismKeys() None

ClearEvalAutomorphismKeys - flush EvalAutomorphismKey cache

static ClearEvalMultKeys() None

ClearEvalMultKeys - flush EvalMultKey cache for a given id

Parameters:

id (str) – the corresponding key id

Decrypt(*args, **kwargs)

Overloaded function.

  1. Decrypt(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, ciphertext: openfhe.Ciphertext) -> openfhe.Plaintext

Decrypt a single ciphertext into the appropriate plaintext

Parameters:
Returns:

decrypted plaintext

Return type:

Plaintext

  1. Decrypt(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, privateKey: openfhe.PrivateKey) -> openfhe.Plaintext

Decrypt a single ciphertext into the appropriate plaintext

Parameters:
Returns:

decrypted plaintext

Return type:

Plaintext

static DeserializeEvalAutomorphismKey(*args, **kwargs)

Overloaded function.

  1. DeserializeEvalAutomorphismKey(filename: str, sertype: openfhe.SERBINARY) -> bool

    DeserializeEvalAutomorphismKey deserialize all keys in the serialization deserialized keys silently replace any existing matching keys deserialization will create CryptoContext if necessary

    param filename:

    path for the file to deserialize from

    type filename:

    str

    param sertype:

    type of serialization

    type sertype:

    SERJSON, SERBINARY

    return:

    bool: true on success

  2. DeserializeEvalAutomorphismKey(filename: str, sertype: openfhe.SERJSON) -> bool

    DeserializeEvalAutomorphismKey deserialize all keys in the serialization deserialized keys silently replace any existing matching keys deserialization will create CryptoContext if necessary

    param filename:

    path for the file to deserialize from

    type filename:

    str

    param sertype:

    type of serialization

    type sertype:

    SERJSON, SERBINARY

    return:

    bool: true on success

static DeserializeEvalMultKey(*args, **kwargs)

Overloaded function.

  1. DeserializeEvalMultKey(filename: str, sertype: openfhe.SERBINARY) -> bool

    DeserializeEvalMultKey deserialize all keys in the serialization deserialized keys silently replace any existing matching keys deserialization will create CryptoContext if necessary

    param filename:

    path for the file to deserialize from

    type filename:

    str

    param sertype:

    type of serialization

    type sertype:

    SERJSON, SERBINARY

    return:

    bool: true on success

  2. DeserializeEvalMultKey(filename: str, sertype: openfhe.SERJSON) -> bool

    DeserializeEvalMultKey deserialize all keys in the serialization deserialized keys silently replace any existing matching keys deserialization will create CryptoContext if necessary

    param filename:

    path for the file to deserialize from

    type filename:

    str

    param sertype:

    type of serialization

    type sertype:

    SERJSON, SERBINARY

    return:

    bool: true on success

Enable(self: openfhe.CryptoContext, feature: openfhe.PKESchemeFeature) None

Enable a particular feature for use with this CryptoContext

Parameters:

feature (PKESchemeFeature) – the feature that should be enabled. The list of available features is defined in the PKESchemeFeature enum.

Encrypt(self: openfhe.CryptoContext, publicKey: openfhe.PublicKey, plaintext: openfhe.Plaintext) openfhe.Ciphertext

Encrypt a plaintext using a given public key

Parameters:
Returns:

ciphertext (or null on failure)

Return type:

Ciphertext

EvalAdd(*args, **kwargs)

Overloaded function.

  1. EvalAdd(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) -> openfhe.Ciphertext

Homomorphic addition of two ciphertexts

Parameters:
Returns:

the result as a new ciphertext

Return type:

Ciphertext

  1. EvalAdd(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, constant: float) -> openfhe.Ciphertext

EvalAdd - OpenFHE EvalAdd method for a ciphertext and a real number. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • constant (float) – a real number

Returns:

new ciphertext for ciphertext + constant

Return type:

Ciphertext

  1. EvalAdd(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, plaintext: openfhe.Plaintext) -> openfhe.Ciphertext

EvalAdd - OpenFHE EvalAdd method for a ciphertext and plaintext

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • plaintex – input plaintext

Returns:

new ciphertext for ciphertext + constant

Return type:

Ciphertext

EvalAddInPlace(*args, **kwargs)

Overloaded function.

  1. EvalAddInPlace(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) -> None

In-place homomorphic addition of two ciphertexts

Parameters:
Returns:

ciphertext1 contains ciphertext1 + ciphertext2

  1. EvalAddInPlace(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, plaintext: openfhe.Plaintext) -> None

In-place addition for a ciphertext and plaintext

Parameters:
  • ciphertext (Ciphertext) – Input/output ciphertext

  • plaintext (Plaintext) – Input plaintext

Returns:

ciphertext contains ciphertext + plaintext

  1. EvalAddInPlace(self: openfhe.CryptoContext, plaintext: openfhe.Plaintext, ciphertext: openfhe.Ciphertext) -> None

EvalAddManyInPlace(self: openfhe.CryptoContext, ciphertextVec: List[openfhe.Ciphertext]) openfhe.Ciphertext
EvalAddMutable(*args, **kwargs)

Overloaded function.

  1. EvalAddMutable(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) -> openfhe.Ciphertext

Homomorphic addition of two mutable ciphertexts (they can be changed during the operation)

Parameters:
Returns:

the result as a new ciphertext

Return type:

Ciphertext

  1. EvalAddMutable(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, plaintext: openfhe.Plaintext) -> openfhe.Ciphertext

Homomorphic addition a mutable ciphertext and plaintext

Parameters:
Returns:

new ciphertext for ciphertext + plaintext

Return type:

Ciphertext

  1. EvalAddMutable(self: openfhe.CryptoContext, plaintext: openfhe.Plaintext, ciphertext: openfhe.Ciphertext) -> openfhe.Ciphertext

EvalAddMutableInPlace(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) None

Homomorphic addition a mutable ciphertext and plaintext

Parameters:
Returns:

ciphertext1 contains ciphertext1 + ciphertext2

EvalAtIndex(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, index: int) openfhe.Ciphertext

Rotates a ciphertext by an index (positive index is a left shift, negative index is a right shift). Uses a rotation key stored in a crypto context.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • i (int) – rotation index

Returns:

a rotated ciphertext

Return type:

Ciphertext

EvalAtIndexKeyGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, indexList: List[int], publicKey: openfhe.PublicKey = None) None

EvalAtIndexKeyGen generates evaluation keys for a list of rotation indices

Parameters:
  • privateKey (PrivateKey) – the private key

  • indexList (list) – list of indices

  • publicKey (PublicKey) – the public key (used in NTRU schemes). Not used anymore.

Returns:

None

EvalAutomorphismKeyGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, indexList: List[int]) openfhe.EvalKeyMap

Generate automophism keys for a given private key; Uses the private key for encryption

Parameters:
  • privateKey (PrivateKey) – private key.

  • indexList (list) – list of automorphism indices to be computed.

Returns:

returns the evaluation key

Return type:

EvalKeyMap

EvalBootstrap(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, numIterations: int = 1, precision: int = 0) openfhe.Ciphertext

Defines the bootstrapping evaluation of ciphertext using either the FFT-like method or the linear method

Parameters:
  • ciphertext (Ciphertext) – the input ciphertext

  • numIterations (int) – number of iterations to run iterative bootstrapping (Meta-BTS). Increasing the iterations increases the precision of bootstrapping

  • precision (int) – precision of initial bootstrapping algorithm. This value is determined by the user experimentally by first running EvalBootstrap with numIterations = 1 and precision = 0 (unused).

Returns:

Ciphertext: the refreshed ciphertext

Return type:

Ciphertext

EvalBootstrapKeyGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, slots: int) None

Generates all automorphism keys for EvalBootstrap. Supported in CKKS only. EvalBootstrapKeyGen uses the baby-step/giant-step strategy.

Parameters:
  • privateKey (PrivateKey) – private key.

  • slots (int) – number of slots to support permutations on.

Returns:

None

EvalBootstrapSetup(self: openfhe.CryptoContext, levelBudget: List[int] = [5, 4], dim1: List[int] = [0, 0], slots: int = 0, correctionFactor: int = 0, precompute: bool = True) None

Bootstrap functionality: There are three methods that have to be called in this specific order:

  1. EvalBootstrapSetup: computes and encodes the coefficients for encoding and decoding and stores the necessary parameters

  2. EvalBootstrapKeyGen: computes and stores the keys for rotations and conjugation

  3. EvalBootstrap: refreshes the given ciphertext Sets all parameters for both linear and FTT-like methods. Supported in CKKS only.

Parameters:
  • levelBudget (list) – vector of budgets for the amount of levels in encoding and decoding

  • dim1 (list) – vector of inner dimension in the baby-step giant-step routine for encoding and decodingl

  • slots (int) – number of slots to be bootstraped

  • correctionFactor (int) – value to internally rescale message by to improve precision of bootstrapping. If set to 0, we use the default logic. This value is only used when NATIVE_SIZE=64.

Returns:

None

EvalCKKStoFHEW(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, numCtxts: int = 0) List[openfhe.LWECiphertext]
EvalCKKStoFHEWKeyGen(self: openfhe.CryptoContext, keyPair: openfhe.KeyPair, lwesk: openfhe.LWEPrivateKey) None
EvalCKKStoFHEWPrecompute(self: openfhe.CryptoContext, scale: float = 1.0) None
EvalCKKStoFHEWSetup(self: openfhe.CryptoContext, schswchparams: lbcrypto::SchSwchParams) openfhe.LWEPrivateKey
EvalChebyshevFunction(self: openfhe.CryptoContext, func: Callable[[float], float], ciphertext: openfhe.Ciphertext, a: float, b: float, degree: int) openfhe.Ciphertext

Method for calculating Chebyshev evaluation on a ciphertext for a smooth input function over the range [a,b]. Supported only in CKKS.

Parameters:
  • func (function) – the function to be approximated

  • ciphertext (Ciphertext) – input ciphertext

  • a (float) – lower bound of argument for which the coefficients were found

  • b (float) – upper bound of argument for which the coefficients were found

  • degree (int) – Desired degree of approximation

Returns:

the coefficients of the Chebyshev approximation.

Return type:

Ciphertext

EvalChebyshevSeries(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, coefficients: List[float], a: float, b: float) openfhe.Ciphertext

Method for evaluating Chebyshev polynomial interpolation; first the range [a,b] is mapped to [-1,1] using linear transformation 1 + 2 (x-a)/(b-a) If the degree of the polynomial is less than 5, use EvalChebyshevSeriesLinear (naive linear method), otherwise, use EvalChebyshevSeriesPS (Paterson-Stockmeyer method). Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • coefficients (list) – is the vector of coefficients in Chebyshev expansion

  • a (float) – lower bound of argument for which the coefficients were found

  • b (float) – upper bound of argument for which the coefficients were found

Returns:

the result of polynomial evaluation

Return type:

Ciphertext

EvalChebyshevSeriesLinear(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, coefficients: List[float], a: float, b: float) openfhe.Ciphertext

Naive linear method for evaluating Chebyshev polynomial interpolation; first the range [a,b] is mapped to [-1,1] using linear transformation 1 + 2 (x-a)/(b-a). Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • coefficients (list) – is the vector of coefficients in Chebyshev expansion

  • a (float) – lower bound of argument for which the coefficients were found

  • b (float) – upper bound of argument for which the coefficients were found

Returns:

the result of polynomial evaluation

Return type:

Ciphertext

EvalChebyshevSeriesPS(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, coefficients: List[float], a: float, b: float) openfhe.Ciphertext

Paterson-Stockmeyer method for evaluating Chebyshev polynomial interpolation; first the range [a,b] is mapped to [-1,1] using linear transformation 1 + 2 (x-a)/(b-a). Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • coefficients (list) – is the vector of coefficients in Chebyshev expansion

  • a (float) – lower bound of argument for which the coefficients were found

  • b (float) – upper bound of argument for which the coefficients were found

Returns:

the result of polynomial evaluation

Return type:

Ciphertext

EvalCompareSchemeSwitching(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext, numCtxts: int = 0, numSlots: int = 0, pLWE: int = 0, scaleSign: float = 1.0, unit: bool = False) openfhe.Ciphertext
EvalCompareSwitchPrecompute(self: openfhe.CryptoContext, pLWE: int = 0, scaleSign: float = 1.0, unit: bool = False) None
EvalCos(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, a: float, b: float, degree: int) openfhe.Ciphertext

Evaluate approximate cosine function on a ciphertext using the Chebyshev approximation. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • a (float) – lower bound of argument for which the coefficients were found

  • b (float) – upper bound of argument for which the coefficients were found

  • degree (int) – Desired degree of approximation

Returns:

the result of polynomial evaluation.

Return type:

Ciphertext

EvalDivide(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, a: float, b: float, degree: int) openfhe.Ciphertext

Evaluate approximate division function 1/x where x >= 1 on a ciphertext using the Chebyshev approximation. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • a (float) – lower bound of argument for which the coefficients were found

  • b (float) – upper bound of argument for which the coefficients were found

  • degree (int) – Desired degree of approximation

Returns:

the result of polynomial evaluation.

Return type:

Ciphertext

EvalFHEWtoCKKS(self: openfhe.CryptoContext, LWECiphertexts: List[openfhe.LWECiphertext], numCtxts: int = 0, numSlots: int = 0, p: int = 4, pmin: float = 0.0, pmax: float = 2.0, dim1: int = 0) openfhe.Ciphertext
EvalFHEWtoCKKSKeyGen(self: openfhe.CryptoContext, keyPair: openfhe.KeyPair, lwesk: openfhe.LWEPrivateKey, numSlots: int = 0, numCtxts: int = 0, dim1: int = 0, L: int = 0) None
EvalFHEWtoCKKSSetup(self: openfhe.CryptoContext, ccLWE: openfhe.BinFHEContext, numSlotsCKKS: int = 0, logQ: int = 25) None
EvalFastRotation(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, index: int, m: int, digits: openfhe.Ciphertext) openfhe.Ciphertext

EvalFastRotation implements the automorphism and key switching step of hoisted automorphisms.

Please refer to Section 5 of Halevi and Shoup, “Faster Homomorphic linear transformations in HELib.” for more details, link: https://eprint.iacr.org/2018/244.

Generally, automorphisms are performed with three steps: (1) The automorphism is applied to the ciphertext. (2) The automorphed values are decomposed into digits. (3) Key switching is applied to enable further computations on the ciphertext.

Hoisted automorphisms are a technique that performs the digit decomposition for the original ciphertext first, and then performs the automorphism and the key switching on the decomposed digits. The benefit of this is that the digit decomposition is independent of the automorphism rotation index, so it can be reused for multiple different indices. This can greatly improve performance when we have to compute many automorphisms on the same ciphertext. This routinely happens when we do permutations (EvalPermute).

EvalFastRotation implements the automorphism and key switching step of hoisted automorphisms.

This method assumes that all required rotation keys exist. This may not be true if we are using baby-step/giant-step key switching. Please refer to Section 5.1 of the above reference and EvalPermuteBGStepHoisted to see how to deal with this issue.

Parameters:
  • ciphertext (Ciphertext) – the input ciphertext to perform the automorphism on

  • index (int) – the index of the rotation. Positive indices correspond to left rotations and negative indices correspond to right rotations.

  • m (int) – is the cyclotomic order

  • digits (Ciphertext) – the precomputed ciphertext created by EvalFastRotationPrecompute using the digit decomposition at the precomputation step

Returns:

the rotated ciphertext

Return type:

Ciphertext

EvalFastRotationExt(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, index: int, digits: openfhe.Ciphertext, addFirst: bool) openfhe.Ciphertext

Only supported for hybrid key switching. Performs fast (hoisted) rotation and returns the results in the extended CRT basis P*Q

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • index (int) – the rotation index

  • digits (Ciphertext) – the precomputed ciphertext created by EvalFastRotationPrecompute

  • addFirst (bool) – if true, the first element c0 is also computed (otherwise ignored)

Returns:

resulting ciphertext

Return type:

Ciphertext

EvalFastRotationPrecompute(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) openfhe.Ciphertext

EvalFastRotationPrecompute implements the precomputation step of hoisted automorphisms.

Please refer to Section 5 of Halevi and Shoup, “Faster Homomorphic linear transformations in HELib.” for more details, link: https://eprint.iacr.org/2018/244.

Generally, automorphisms are performed with three steps: (1) The automorphism is applied to the ciphertext. (2) The automorphed values are decomposed into digits. (3) Key switching is applied to enable further computations on the ciphertext.

Hoisted automorphisms are a technique that performs the digit decomposition for the original ciphertext first, and then performs the automorphism and the key switching on the decomposed digits. The benefit of this is that the digit decomposition is independent of the automorphism rotation index, so it can be reused for multiple different indices. This can greatly improve performance when we have to compute many automorphisms on the same ciphertext. This routinely happens when we do permutations (EvalPermute).

EvalFastRotationPrecompute implements the digit decomposition step of hoisted automorphisms.

Parameters:

ciphertext (Ciphertext) – the input ciphertext on which to do the precomputation (digit decomposition)

Returns:

the precomputed ciphertext created using the digit decomposition

Return type:

Ciphertext

EvalInnerProduct(*args, **kwargs)

Overloaded function.

  1. EvalInnerProduct(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext, batchSize: int) -> openfhe.Ciphertext

    Evaluates inner product in packed encoding (uses EvalSum)

    param ciphertext1:

    first vector

    type ciphertext1:

    Ciphertext

    param ciphertext2:

    second vector

    type ciphertext2:

    Ciphertext

    param batchSize:

    size of the batch to be summed up

    type batchSize:

    int

    return:

    Ciphertext: resulting ciphertext

    rtype:

    Ciphertext

  2. EvalInnerProduct(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, plaintext: openfhe.Plaintext, batchSize: int) -> openfhe.Ciphertext

    Evaluates inner product in packed encoding (uses EvalSum)

    param ciphertext:

    first vector - ciphertext

    type ciphertext:

    Ciphertext

    param plaintext:

    second vector - plaintext

    type plaintext:

    Plaintext

    param batchSize:

    size of the batch to be summed up

    type batchSize:

    int

    return:

    Ciphertext: resulting ciphertext

    rtype:

    Ciphertext

EvalLinearWSum(self: openfhe.CryptoContext, ciphertext: List[openfhe.Ciphertext], coefficients: List[float]) openfhe.Ciphertext
EvalLinearWSumMutable(self: openfhe.CryptoContext, ciphertext: List[float], coefficients: List[openfhe.Ciphertext]) openfhe.Ciphertext
EvalLogistic(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, a: float, b: float, degree: int) openfhe.Ciphertext

Evaluate approximate logistic function 1/(1 + exp(-x)) on a ciphertext using the Chebyshev approximation. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • a (float) – lower bound of argument for which the coefficients were found

  • b (float) – upper bound of argument for which the coefficients were found

  • degree (int) – Desired degree of approximation

Returns:

the result of polynomial evaluation.

Return type:

Ciphertext

EvalMaxSchemeSwitching(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, publicKey: openfhe.PublicKey, numValues: int = 0, numSlots: int = 0, pLWE: int = 0, scaleSign: float = 1.0) List[openfhe.Ciphertext]
EvalMaxSchemeSwitchingAlt(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, publicKey: openfhe.PublicKey, numValues: int = 0, numSlots: int = 0, pLWE: int = 0, scaleSign: float = 1.0) List[openfhe.Ciphertext]
EvalMerge(self: openfhe.CryptoContext, ciphertextVec: List[openfhe.Ciphertext]) openfhe.Ciphertext

Merges multiple ciphertexts with encrypted results in slot 0 into a single ciphertext. The slot assignment is done based on the order of ciphertexts in the vector. Requires the generation of rotation keys for the indices that are needed.

Parameters:

ciphertextVec (list) – vector of ciphertexts to be merged.

Returns:

resulting ciphertext

Return type:

Ciphertext

EvalMinSchemeSwitching(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, publicKey: openfhe.PublicKey, numValues: int = 0, numSlots: int = 0, pLWE: int = 0, scaleSign: float = 1.0) List[openfhe.Ciphertext]
EvalMinSchemeSwitchingAlt(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, publicKey: openfhe.PublicKey, numValues: int = 0, numSlots: int = 0, pLWE: int = 0, scaleSign: float = 1.0) List[openfhe.Ciphertext]
EvalMult(*args, **kwargs)

Overloaded function.

  1. EvalMult(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) -> openfhe.Ciphertext

EvalMult - OpenFHE EvalMult method for a pair of ciphertexts (uses a relinearization key from the crypto context)

Parameters:
Returns:

new ciphertext for ciphertext1 * ciphertext2

Return type:

Ciphertext

  1. EvalMult(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, constant: float) -> openfhe.Ciphertext

Multiplication of a ciphertext by a real number. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – multiplier

  • constant (float) – multiplicand

Returns:

the result of multiplication

Return type:

Ciphertext

  1. EvalMult(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, plaintext: openfhe.Plaintext) -> openfhe.Ciphertext

Multiplication of a ciphertext by a plaintext

Parameters:
Returns:

the result of multiplication

Return type:

Ciphertext

  1. EvalMult(self: openfhe.CryptoContext, plaintext: openfhe.Plaintext, ciphertext: openfhe.Ciphertext) -> openfhe.Ciphertext

  2. EvalMult(self: openfhe.CryptoContext, constant: float, ciphertext: openfhe.Ciphertext) -> openfhe.Ciphertext

EvalMultAndRelinearize(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) openfhe.Ciphertext

Homomorphic multiplication of two ciphertexts followed by relinearization to the lowest level

Parameters:
  • ciphertext1 (Ciphertext) – first input ciphertext

  • ciphertext2 (Ciphertext) – second input ciphertext

Returns:

new ciphertext

Return type:

Ciphertext

EvalMultKeyGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey) None

EvalMultKeyGen creates a key that can be used with the OpenFHE EvalMult operator. The new evaluation key is stored in cryptocontext.

Parameters:

privateKey (PrivateKey) – the private key

EvalMultKeysGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey) None

EvalMultsKeyGen creates a vector evalmult keys that can be used with the OpenFHE EvalMult operator. The 1st key (for s^2) is used for multiplication of ciphertexts of depth 1. The 2nd key (for s^3) is used for multiplication of ciphertexts of depth 2, etc. A vector of new evaluation keys is stored in cryptocontext.

Parameters:

privateKey (PrivateKey) – the private key

EvalMultMany(self: openfhe.CryptoContext, ciphertextVec: List[openfhe.Ciphertext]) openfhe.Ciphertext
EvalMultMutable(*args, **kwargs)

Overloaded function.

  1. EvalMultMutable(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) -> openfhe.Ciphertext

EvalMult - OpenFHE EvalMult method for a pair of mutable ciphertexts (uses a relinearization key from the crypto context)

Parameters:
Returns:

new ciphertext for ciphertext1 * ciphertext2

Return type:

Ciphertext

  1. EvalMultMutable(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, plaintext: openfhe.Plaintext) -> openfhe.Ciphertext

Multiplication of mutable ciphertext and plaintext :param ciphertext: multiplier :type ciphertext: Ciphertext :param plaintext: multiplicand :type plaintext: Plaintext :return: the result of multiplication :rtype: Ciphertext

  1. EvalMultMutable(self: openfhe.CryptoContext, plaintext: openfhe.Plaintext, ciphertext: openfhe.Ciphertext) -> openfhe.Ciphertext

EvalMultMutableInPlace(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) None

In-place EvalMult method for a pair of mutable ciphertexts (uses a relinearization key from the crypto context)

Parameters:
EvalMultNoRelin(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) openfhe.Ciphertext

Homomorphic multiplication of two ciphertexts without relinearization

Parameters:
Returns:

new ciphertext for ciphertext1 * ciphertext2

Return type:

Ciphertext

EvalNegate(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) openfhe.Ciphertext

Negates a ciphertext

Parameters:

ciphertext (Ciphertext) – input ciphertext

Returns:

new ciphertext: -ciphertext

Return type:

Ciphertext

EvalNegateInPlace(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) None

In-place negation of a ciphertext

Parameters:

ciphertext (Ciphertext) – input ciphertext

EvalPoly(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, coefficients: List[float]) openfhe.Ciphertext

Method for polynomial evaluation for polynomials represented as power series.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • coefficients (list) – vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial + 1

Returns:

Ciphertext: the result of polynomial evaluation.

Return type:

Ciphertext

EvalPolyLinear(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, coefficients: List[float]) openfhe.Ciphertext

Naive method for polynomial evaluation for polynomials represented in the power series (fast only for small-degree polynomials; less than 10). Uses a binary tree computation of the polynomial powers. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • coefficients (list) – is the vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial

Returns:

Ciphertext: the result of polynomial evaluation.

Return type:

Ciphertext

EvalPolyPS(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, coefficients: List[float]) openfhe.Ciphertext

Paterson-Stockmeyer method for evaluation for polynomials represented in the power series. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • coefficients (list) – is the vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial

Returns:

Ciphertext: the result of polynomial evaluation.

Return type:

Ciphertext

EvalRotate(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, index: int) openfhe.Ciphertext

Rotates a ciphertext by an index (positive index is a left shift, negative index is a right shift). Uses a rotation key stored in a crypto context. Calls EvalAtIndex under the hood.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • index (int) – rotation index

Returns:

a rotated ciphertext

Return type:

Ciphertext

EvalRotateKeyGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, indexList: List[int], publicKey: openfhe.PublicKey = None) None

EvalRotateKeyGen generates evaluation keys for a list of indices. Calls EvalAtIndexKeyGen under the hood.

Parameters:
  • privateKey (PrivateKey) – private key

  • indexList (list) – list of integers representing the indices

  • publicKey (PublicKey) – public key (used in NTRU schemes)

EvalSchemeSwitchingKeyGen(self: openfhe.CryptoContext, keyPair: openfhe.KeyPair, lwesk: openfhe.LWEPrivateKey) None
EvalSchemeSwitchingSetup(self: openfhe.CryptoContext, schswchparams: lbcrypto::SchSwchParams) openfhe.LWEPrivateKey
EvalSin(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, a: float, b: float, degree: int) openfhe.Ciphertext

Evaluate approximate sine function on a ciphertext using the Chebyshev approximation. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • a (float) – lower bound of argument for which the coefficients were found

  • b (float) – upper bound of argument for which the coefficients were found

  • degree (int) – Desired degree of approximation

Returns:

the result of polynomial evaluation.

Return type:

Ciphertext

EvalSquare(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) openfhe.Ciphertext

Efficient homomorphic squaring of a ciphertext - uses a relinearization key stored in the crypto context

Parameters:

ciphertext (Ciphertext) – input ciphertext

Returns:

squared ciphertext

Return type:

Ciphertext

EvalSquareInPlace(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) None

In-place homomorphic squaring of a mutable ciphertext - uses a relinearization key stored in the crypto context

Parameters:

ciphertext (Ciphertext) – input ciphertext

Returns:

squared ciphertext

EvalSquareMutable(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) openfhe.Ciphertext

Efficient homomorphic squaring of a mutable ciphertext - uses a relinearization key stored in the crypto context

Parameters:

ciphertext (Ciphertext) – input ciphertext

Returns:

squared ciphertext

Return type:

Ciphertext

EvalSub(*args, **kwargs)

Overloaded function.

  1. EvalSub(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) -> openfhe.Ciphertext

Homomorphic subtraction of two ciphertexts

Parameters:
Returns:

the result as a new ciphertext

Return type:

Ciphertext

  1. EvalSub(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, constant: float) -> openfhe.Ciphertext

Subtraction of a ciphertext and a real number. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • constant (float) – a real number

Returns:

new ciphertext for ciphertext - constant

Return type:

Ciphertext

  1. EvalSub(self: openfhe.CryptoContext, constant: float, ciphertext: openfhe.Ciphertext) -> openfhe.Ciphertext

  2. EvalSub(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, plaintext: openfhe.Plaintext) -> openfhe.Ciphertext

Subtraction of a ciphertext and a real number. Supported only in CKKS.

Parameters:
Returns:

new ciphertext for ciphertext - plaintext

Return type:

Ciphertext

  1. EvalSub(self: openfhe.CryptoContext, plaintext: openfhe.Plaintext, ciphertext: openfhe.Ciphertext) -> openfhe.Ciphertext

EvalSubInPlace(*args, **kwargs)

Overloaded function.

  1. EvalSubInPlace(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) -> None

In-place homomorphic subtraction of two ciphertexts

Parameters:
Returns:

the result as a new ciphertext

  1. EvalSubInPlace(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, constant: float) -> None

In-place subtraction of a ciphertext and a real number. Supported only in CKKS.

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • constant (float) – a real number

  1. EvalSubInPlace(self: openfhe.CryptoContext, constant: float, ciphertext: openfhe.Ciphertext) -> None

EvalSubMutable(*args, **kwargs)

Overloaded function.

  1. EvalSubMutable(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) -> openfhe.Ciphertext

Homomorphic subtraction of two mutable ciphertexts

Parameters:
Returns:

the result as a new ciphertext

  1. EvalSubMutable(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, plaintext: openfhe.Plaintext) -> openfhe.Ciphertext

Homomorphic subtraction of mutable ciphertext and plaintext

Parameters:
Returns:

new ciphertext for ciphertext - plaintext

  1. EvalSubMutable(self: openfhe.CryptoContext, plaintext: openfhe.Plaintext, ciphertext: openfhe.Ciphertext) -> openfhe.Ciphertext

EvalSubMutableInPlace(self: openfhe.CryptoContext, ciphertext1: openfhe.Ciphertext, ciphertext2: openfhe.Ciphertext) None

In-place homomorphic subtraction of two mutable ciphertexts

Parameters:
Returns:

the updated minuend

EvalSum(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, batchSize: int) openfhe.Ciphertext

Function for evaluating a sum of all components in a vector.

Parameters:
  • ciphertext (Ciphertext) – the input ciphertext

  • batchSize (int) – size of the batch

Returns:

resulting ciphertext

Return type:

Ciphertext

EvalSumCols(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, rowSize: int, evalSumKeyMap: openfhe.EvalKeyMap) openfhe.Ciphertext

Sums all elements over column-vectors in a matrix - works only with packed encoding

Parameters:
  • ciphertext (Ciphertext) – the input ciphertext

  • rowSize (int) – size of rows in the matrix

  • evalSumKeyMap (EvalKeyMap) – reference to the map of evaluation keys generated by

Returns:

Ciphertext: resulting ciphertext

Return type:

Ciphertext

EvalSumColsKeyGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, publicKey: openfhe.PublicKey = None) openfhe.EvalKeyMap

Generates the automorphism keys for EvalSumCols; works only for packed encoding

Parameters:
Returns:

returns the evaluation keys

Return type:

EvalKeyMap

EvalSumKeyGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, publicKey: openfhe.PublicKey = None) None

EvalSumKeyGen Generates the key map to be used by EvalSum

Parameters:
  • privateKey (PrivateKey) – private key

  • publicKey (PublicKey) – public key (used in NTRU schemes)

Returns:

None

EvalSumRows(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, rowSize: int, evalSumKeyMap: openfhe.EvalKeyMap, subringDim: int = 0) openfhe.Ciphertext

Sums all elements over row-vectors in a matrix - works only with packed encoding

Parameters:
  • ciphertext (Ciphertext) – the input ciphertext

  • rowSize (int) – size of rows in the matrix

  • evalSumKeyMap (EvalKeyMap) – reference to the map of evaluation keys generated by

  • subringDim (int) – the current cyclotomic order/subring dimension. If set to 0, we use the full cyclotomic order.

Returns:

Ciphertext: resulting ciphertext

Return type:

Ciphertext

EvalSumRowsKeyGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, publicKey: openfhe.PublicKey = None, rowSize: int = 0, subringDim: int = 0) openfhe.EvalKeyMap

Generate the automorphism keys for EvalSumRows; works only for packed encoding

Parameters:
  • privateKey (PrivateKey) – private key

  • publicKey (PublicKey) – public key

  • rowSize (int) – size of rows in the matrix

  • subringDim (int) – subring dimension (set to cyclotomic order if set to 0)

Returns:

returns the evaluation keys

Return type:

EvalKeyMap

FindAutomorphismIndex(self: openfhe.CryptoContext, idx: int) int

Finds an automorphism index for a given vector index using a scheme-specific algorithm

Parameters:

idx (int) – regular vector index

Returns:

the automorphism index

Return type:

int

FindAutomorphismIndices(self: openfhe.CryptoContext, idxList: List[int]) List[int]

Finds automorphism indices for a given list of vector indices using a scheme-specific algorithm

Parameters:

idxList (List[int]) – list of indices

Returns:

a list of automorphism indices

Return type:

List[int]

GetBinCCForSchemeSwitch(self: openfhe.CryptoContext) openfhe.BinFHEContext
GetCyclotomicOrder(self: openfhe.CryptoContext) int

Get the cyclotomic order used for this context

Returns:

The cyclotomic order

Return type:

int

GetDigitSize(self: openfhe.CryptoContext) int
GetEvalSumKeyMap(self: openfhe.CryptoContext, arg0: str) openfhe.EvalKeyMap

Get a map of summation keys (each is composed of several automorphism keys) for a specific secret key tag :return: EvalKeyMap: key map :rtype: EvalKeyMap

GetKeyGenLevel(self: openfhe.CryptoContext) int

For future use: getter for the level at which evaluation keys should be generated

Returns:

The level used for key generation

Return type:

int

GetModulus(self: openfhe.CryptoContext) float

Get the cyclotomic order used for this context

Returns:

The modulus

Return type:

int

GetModulusCKKS(self: openfhe.CryptoContext) int
GetPlaintextModulus(self: openfhe.CryptoContext) int

Get the plaintext modulus used for this context

Returns:

The plaintext modulus

Return type:

int

GetRingDimension(self: openfhe.CryptoContext) int

Get the ring dimension used for this context

Returns:

The ring dimension

Return type:

int

GetScalingFactorReal(self: openfhe.CryptoContext, arg0: int) float

Method to retrieve the scaling factor of level l. For FIXEDMANUAL scaling technique method always returns 2^p, where p corresponds to plaintext modulus

Parameters:

l (int) – For FLEXIBLEAUTO scaling technique the level whose scaling factor we want to learn. Levels start from 0 (no scaling done - all towers) and go up to K-1, where K is the number of towers supported.

Returns:

the scaling factor.

Return type:

float

GetScalingTechnique(self: openfhe.CryptoContext) openfhe.ScalingTechnique
static InsertEvalMultKey(evalKeyVec: List[openfhe.EvalKey]) None

InsertEvalMultKey - add the given vector of keys to the map, replacing the existing vector if there

Parameters:

evalKeyVec (List[EvalKey]) – vector of keys

static InsertEvalSumKey(evalKeyMap: openfhe.EvalKeyMap, keyTag: str = '') None

InsertEvalSumKey - add the given map of keys to the map, replacing the existing map if there

Parameters:

evalKeyMap (EvalKeyMap) – key map

IntMPBootAdd(self: openfhe.CryptoContext, sharePairVec: List[List[openfhe.Ciphertext]]) List[openfhe.Ciphertext]

Threshold FHE: Aggregates a vector of masked decryptions and re-encryotion shares, which is the second step of the interactive multiparty bootstrapping procedure.

Parameters:

sharesPairVec (List[List[Ciphertext]]) – vector of pair of ciphertexts, each element of this vector contains (h_0i, h_1i) - the masked-decryption and encryption shares ofparty i

Returns:

aggregated pair of shares ((h_0, h_1)

Return type:

List[Ciphertext]

IntMPBootAdjustScale(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) openfhe.Ciphertext

Threshold FHE: Prepare a ciphertext for Multi-Party Interactive Bootstrapping.

Parameters:

ciphertext (Ciphertext) – Input Ciphertext

Returns:

Resulting Ciphertext

Return type:

Ciphertext

IntMPBootDecrypt(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, ciphertext: openfhe.Ciphertext, a: openfhe.Ciphertext) List[openfhe.Ciphertext]

Threshold FHE: Does masked decryption as part of Multi-Party Interactive Bootstrapping. Each party calls this function as part of the protocol

Parameters:
  • privateKey (PrivateKey) – secret key share for party i

  • ciphertext (Ciphertext) – input ciphertext

  • a (Ciphertext) – input common random polynomial

Returns:

Resulting masked decryption

Return type:

Ciphertext

IntMPBootEncrypt(self: openfhe.CryptoContext, publicKey: openfhe.PublicKey, sharePair: List[openfhe.Ciphertext], a: openfhe.Ciphertext, ciphertext: openfhe.Ciphertext) openfhe.Ciphertext

Threshold FHE: Does public key encryption of lead party’s masked decryption as part of interactive multi-party bootstrapping, which increases the ciphertext modulus and enables future computations. This operation is done by the lead party as the final step of interactive multi-party bootstrapping.

Parameters:
  • publicKey (PublicKey) – the lead party’s public key

  • sharesPair (List[Ciphertext]) – aggregated decryption and re-encryption shares

  • a (Ciphertext) – common random ring element

  • ciphertext (Ciphertext) – input ciphertext

Returns:

Resulting encryption

Return type:

Ciphertext

IntMPBootRandomElementGen(self: openfhe.CryptoContext, publicKey: openfhe.PublicKey) openfhe.Ciphertext

Threshold FHE: Generate a common random polynomial for Multi-Party Interactive Bootstrapping

Parameters:

publicKey (PublicKey) – the scheme public key (you can also provide the lead party’s public-key)

Returns:

Resulting ring element

Return type:

Ciphertext

KeyGen(self: openfhe.CryptoContext) openfhe.KeyPair

Generate a public and private key pair

Returns:

a public/secret key pair

Return type:

KeyPair

KeySwitchGen(self: openfhe.CryptoContext, oldPrivateKey: openfhe.PrivateKey, newPrivateKey: openfhe.PrivateKey) openfhe.EvalKey

KeySwitchGen creates a key that can be used with the OpenFHE KeySwitch operation

Parameters:
Returns:

new evaluation key

Return type:

EvalKey

MakeCKKSPackedPlaintext(*args, **kwargs)

Overloaded function.

  1. MakeCKKSPackedPlaintext(self: openfhe.CryptoContext, value: List[complex], scaleDeg: int = 1, level: int = 0, params: openfhe.ParmType = None, slots: int = 0) -> openfhe.Plaintext

    COMPLEX ARITHMETIC IS NOT AVAILABLE, AND THIS METHOD BE DEPRECATED. USE THE REAL-NUMBER METHOD INSTEAD. MakeCKKSPackedPlaintext constructs a CKKSPackedEncoding in this context from a vector of complex numbers

    param value:

    input vector of complex numbers

    type value:

    List[complex]

    param scaleDeg:

    degree of scaling factor used to encode the vector

    type scaleDeg:

    int

    param level:

    level at each the vector will get encrypted

    type level:

    int

    param params:

    parameters to be used for the ciphertext (Only accepting params = None in this version)

    type params:

    openfhe.ParmType

    param slots:

    number of slots

    type slots:

    int

    return:

    plaintext

    rtype:

    Plaintext

  2. MakeCKKSPackedPlaintext(self: openfhe.CryptoContext, value: List[float], scaleDeg: int = 1, level: int = 0, params: openfhe.ParmType = None, slots: int = 0) -> openfhe.Plaintext

    MakeCKKSPlaintext constructs a CKKSPackedEncoding in this context from a vector of real numbers

    param value:

    input vector (of floats)

    type value:

    list

    param scaleDeg:

    degree of scaling factor used to encode the vector

    type scaleDeg:

    int

    param level:

    level at each the vector will get encrypted

    type level:

    int

    param params:

    parameters to be used for the ciphertext (Only accepting params = None in this version)

    type params:

    openfhe.ParmType

    param slots:

    number of slots

    type slots:

    int

    return:

    plaintext

    rtype:

    Plaintext

MakeCoefPackedPlaintext(self: openfhe.CryptoContext, value: List[int], noiseScaleDeg: int = 1, level: int = 0) openfhe.Plaintext

MakeCoefPackedPlaintext constructs a CoefPackedEncoding in this context

Parameters:

value (List[int]) – vector of signed integers mod t

:param noiseScaleDeg : is degree of the scaling factor to encode the plaintext at :type noiseScaleDeg : int :param level: is the level to encode the plaintext at :type level: int :return: plaintext :rtype: Plaintext

MakePackedPlaintext(self: openfhe.CryptoContext, value: List[int], noiseScaleDeg: int = 1, level: int = 0) openfhe.Plaintext

MakePackedPlaintext constructs a PackedEncoding in this context

Parameters:
  • value (List[int]) – vector of signed integers mod t

  • noiseScaleDeg (int) – is degree of the scaling factor to encode the plaintext at

  • level (int) – is the level to encode the plaintext at

Returns:

plaintext

Return type:

Plaintext

MakeStringPlaintext(self: openfhe.CryptoContext, str: str) openfhe.Plaintext

MakeStringPlaintext constructs a StringEncoding in this context.

Parameters:

str (str) – string to be encoded

Returns:

plaintext

ModReduce(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) openfhe.Ciphertext

ModReduce - OpenFHE ModReduce method used only for BGV/CKKS.

Parameters:

ciphertext (Ciphertext) – ciphertext

Returns:

Ciphertext: mod reduced ciphertext

Return type:

Ciphertext

ModReduceInPlace(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) None

ModReduce - OpenFHE ModReduceInPlace method used only for BGV/CKKS.

Parameters:

ciphertext (Ciphertext) – ciphertext to be mod-reduced in-place

MultiAddEvalKeys(self: openfhe.CryptoContext, evalKey1: openfhe.EvalKey, evalKey2: openfhe.EvalKey, keyId: str = '') openfhe.EvalKey

Threshold FHE: Adds two prior evaluation keys

Parameters:
  • evalKey1 (EvalKey) – first evaluation key

  • evalKey2 (EvalKey) – second evaluation key

  • keyId (str) – new key identifier used for resulting evaluation key

Returns:

the new joined key

Return type:

EvalKey

MultiAddEvalMultKeys(self: openfhe.CryptoContext, evalKey1: openfhe.EvalKey, evalKey2: openfhe.EvalKey, keyId: str = '') openfhe.EvalKey

Threshold FHE: Adds two prior evaluation key sets for summation

Parameters:
  • evalKey1 (EvalKey) – first evaluation key

  • evalKey2 (EvalKey) – second evaluation key

  • keyId (str) – new key identifier used for resulting evaluation key

Returns:

the new joined key

Return type:

EvalKey

MultiAddEvalSumKeys(self: openfhe.CryptoContext, evalKeyMap1: openfhe.EvalKeyMap, evalKeyMap2: openfhe.EvalKeyMap, keyId: str = '') openfhe.EvalKeyMap

Threshold FHE: Adds two prior evaluation key sets for summation

Parameters:
  • evalKeyMap1 (EvalKeyMap) – first summation key set

  • evalKeyMap2 (EvalKeyMap) – second summation key set

  • keyId (str) – new key identifier used for resulting evaluation key

Returns:

the neew joined key set for summation

Return type:

EvalKeyMap

MultiEvalSumKeyGen(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, evalKeyMap: openfhe.EvalKeyMap, keyId: str = '') openfhe.EvalKeyMap

Threshold FHE: Generates joined summation evaluation keys from the current secret share and prior joined summation keys

Parameters:
  • privateKey (PrivateKey) – secret key share

  • evalKeyMap (EvalKeyMap) – a map with prior joined summation keys

  • keyId (str) – new key identifier used for resulting evaluation key

Returns:

EvalKeyMap: new joined summation keys

Return type:

EvalKeyMap

MultiKeySwitchGen(self: openfhe.CryptoContext, originalPrivateKey: openfhe.PrivateKey, newPrivateKey: openfhe.PrivateKey, evalKey: openfhe.EvalKey) openfhe.EvalKey

Threshold FHE: Generates a joined evaluation key from the current secret share and a prior joined evaluation key

Parameters:
  • originalPrivateKey (PrivateKey) – secret key transformed from.

  • newPrivateKey (PrivateKey) – secret key transformed from.

  • evalKey (EvalKey) – the prior joined evaluation key.

Returns:

EvalKey: the new joined evaluation key.

Return type:

EvalKey

MultiMultEvalKey(self: openfhe.CryptoContext, privateKey: openfhe.PrivateKey, evalKey: openfhe.EvalKey, keyId: str = '') openfhe.EvalKey

Threshold FHE: Generates a partial evaluation key for homomorphic multiplication based on the current secret share and an existing partial evaluation key

Parameters:
  • privateKey (PrivateKey) – current secret share

  • evalKey (EvalKey) – prior evaluation key

  • keyId (str) – new key identifier used for resulting evaluation key

Returns:

the new joined key

Return type:

EvalKey

MultipartyDecryptFusion(self: openfhe.CryptoContext, ciphertextVec: List[openfhe.Ciphertext]) openfhe.Plaintext

Threshold FHE: Method for combining the partially decrypted ciphertexts and getting the final decryption in the clear.

Parameters:

partialCiphertextVec (list) – list of “partial” decryptions

Returns:

Plaintext: resulting plaintext

Return type:

Plaintext

MultipartyDecryptLead(self: openfhe.CryptoContext, ciphertextVec: List[openfhe.Ciphertext], privateKey: openfhe.PrivateKey) List[openfhe.Ciphertext]

Threshold FHE: Method for decryption operation run by the lead decryption client

Parameters:
  • ciphertextVec (list) – a list of ciphertexts

  • privateKey (PrivateKey) – secret key share used for decryption.

Returns:

list of partially decrypted ciphertexts.

Return type:

List[Ciphertext]

MultipartyDecryptMain(self: openfhe.CryptoContext, ciphertextVec: List[openfhe.Ciphertext], privateKey: openfhe.PrivateKey) List[openfhe.Ciphertext]

Threshold FHE: “Partial” decryption computed by all parties except for the lead one

Parameters:
  • ciphertextVec (list) – a list of ciphertexts

  • privateKey (PrivateKey) – secret key share used for decryption.

Returns:

list of partially decrypted ciphertexts.

Return type:

List[Ciphertext]

MultipartyKeyGen(*args, **kwargs)

Overloaded function.

  1. MultipartyKeyGen(self: openfhe.CryptoContext, publicKey: openfhe.PublicKey, makeSparse: bool = False, fresh: bool = False) -> openfhe.KeyPair

    Threshold FHE: Generation of a public key derived from a previous joined public key (for prior secret shares) and the secret key share of the current party.

    param publicKey:

    joined public key from prior parties.

    type publicKey:

    PublicKey

    param makeSparse:

    set to true if ring reduce by a factor of 2 is to be used. NOT SUPPORTED BY ANY SCHEME ANYMORE.

    type makeSparse:

    bool

    param fresh:

    set to true if proxy re-encryption is used in the multi-party protocol or star topology is used

    type fresh:

    bool

    return:

    KeyPair: key pair including the secret share for the current party and joined public key

    rtype:

    KeyPair

  2. MultipartyKeyGen(self: openfhe.CryptoContext, privateKeyVec: List[openfhe.PrivateKey]) -> openfhe.KeyPair

    Threshold FHE: Generates a public key from a vector of secret shares. ONLY FOR DEBUGGIN PURPOSES. SHOULD NOT BE USED IN PRODUCTION.

    param privateKeyVec:

    secret key shares.

    type privateKeyVec:

    List[PrivateKey]

    return KeyPair:

    key pair including the private for the current party and joined public key

    rtype:

    KeyPair

ReEncrypt(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext, evalKey: openfhe.EvalKey, publicKey: openfhe.PublicKey = None) openfhe.Ciphertext

ReEncrypt - Proxy Re-Encryption mechanism for OpenFHE

Parameters:
  • ciphertext (Ciphertext) – input ciphertext

  • evalKey (EvalKey) – evaluation key for PRE keygen method

  • publicKey (PublicKey) – the public key of the recipient of the reencrypted ciphertext

Returns:

the resulting ciphertext

Return type:

Ciphertext

ReKeyGen(self: openfhe.CryptoContext, oldPrivateKey: openfhe.PrivateKey, newPublicKey: openfhe.PublicKey) openfhe.EvalKey

ReKeyGen produces an Eval Key that OpenFHE can use for Proxy Re-Encryption

Parameters:
  • oldPrivateKey – original private key

  • newPublicKey – public key

Returns:

new evaluation key

Return type:

EvalKey

Relinearize(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) openfhe.Ciphertext

Homomorphic multiplication of two ciphertexts withour relinearization

Parameters:

ciphertext (Ciphertext) – input ciphertext

Returns:

relinearized ciphertext

Return type:

Ciphertext

RelinearizeInPlace(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) None

In-place relinearization of a ciphertext to the lowest level (with 2 polynomials per ciphertext).

Parameters:

ciphertext (Ciphertext) – input ciphertext

Rescale(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) openfhe.Ciphertext

Rescale - An alias for OpenFHE ModReduce method. This is because ModReduce is called Rescale in CKKS.

Parameters:

ciphertext (Ciphertext) – ciphertext

Returns:

Ciphertext: rescaled ciphertext

Return type:

Ciphertext

RescaleInPlace(self: openfhe.CryptoContext, ciphertext: openfhe.Ciphertext) None

Rescale - An alias for OpenFHE ModReduceInPlace method. This is because ModReduceInPlace is called RescaleInPlace in CKKS.

Parameters:

ciphertext (Ciphertext) – ciphertext to be rescaled in-place

static SerializeEvalAutomorphismKey(*args, **kwargs)

Overloaded function.

  1. SerializeEvalAutomorphismKey(filename: str, sertype: openfhe.SERBINARY, id: str = ‘’) -> bool

    SerializeEvalAutomorphismKey for a single EvalAuto key or all of the EvalAuto keys

    param filename:

    output file

    type filename:

    str

    param sertype:

    serialization type

    type sertype:

    SERJSON, SERBINARY

    param id:

    key to serialize; empty string means all keys

    type id:

    str

    return:

    bool: true on success

  2. SerializeEvalAutomorphismKey(filename: str, sertype: openfhe.SERJSON, id: str = ‘’) -> bool

    SerializeEvalAutomorphismKey for a single EvalAuto key or all of the EvalAuto keys

    param filename:

    output file

    type filename:

    str

    param sertype:

    serialization type

    type sertype:

    SERJSON, SERBINARY

    param id:

    key to serialize; empty string means all keys

    type id:

    str

    return:

    bool: true on success

static SerializeEvalMultKey(*args, **kwargs)

Overloaded function.

  1. SerializeEvalMultKey(filename: str, sertype: openfhe.SERBINARY, id: str = ‘’) -> bool

    SerializeEvalMultKey for a single EvalMult key or all of the EvalMult keys

    param filename:

    output file to serialize to

    type filename:

    str

    param sertype:

    type of serialization

    type sertype:

    SERJSON, SERBINARY

    param id:

    for key to serialize - if empty string, serialize them all

    type id:

    str

    return:

    bool: true on success (false on failure or no keys found)

  2. SerializeEvalMultKey(filename: str, sertype: openfhe.SERJSON, id: str = ‘’) -> bool

    SerializeEvalMultKey for a single EvalMult key or all of the EvalMult keys

    param filename:

    output file to serialize to

    type filename:

    str

    param sertype:

    type of serialization

    type sertype:

    SERJSON, SERBINARY

    param id:

    for key to serialize - if empty string, serialize them all

    type id:

    str

    return:

    bool: true on success (false on failure or no keys found)

SetKeyGenLevel(self: openfhe.CryptoContext, level: int) None

For future use: setter for the level at which evaluation keys should be generated

Parameters:

level (int) – the level to set the key generation to

get_ptr(self: openfhe.CryptoContext) None