BFV¶
- class vfhe.fhe.BFV_Scheme(rings: list[RNSRing] | RNSRing, plaintext_primes: int = 1, module_rank: int = 1, special_primes: int = 0, special_rings: list[RNSRing] | None = None, balanced: bool = True, random: Random | None = None)¶
BFV, with the plaintext modulus taken from the ciphertext ring’s primes.
The plaintext ring is built from the lowest
plaintext_primesprimes of the ciphertext ring, sotdividesqandDelta = q/tis exact rather than a roundedfloor(q/t): encryption is a scaled lift, decryption a round-division, and neither approximates. The level chain drops primes from the top, so the plaintext primes survive every level.tis a ring prime, so it is NTT-friendly andencode()batches for free – but it cannot be a power of two. Noise grows withtat every multiplication, so prefer a small one:prime_size=[17, ...].Create a BFV scheme.
ringsis either a singleRNSRing(the level chain is derived automatically) or an explicit list of per-level rings paired withspecial_ringswhenspecial_primes > 0. SeeMLWE_Schemefor both modes, and forbalanced.- Parameters:
plaintext_primes – How many of the ring’s lowest primes make up the plaintext modulus
t.
- t¶
The plaintext modulus.
- property parameters: SchemeParameters¶
What this scheme is, for equality and for matching a stored scheme to a live one.
- property n_slots: int¶
two rows of
N/2.- Type:
Number of independent plaintext slots
- encode(values: list[int]) RNSPolynomial¶
Encodes one integer per slot into a plaintext polynomial.
The result is an element of the plaintext ring, in the coefficient domain. Pass it to
encrypt(), or multiply a ciphertext by it directly for the plaintext multiplication.
- decode(poly: RNSPolynomial, signed: bool = True) list[int]¶
Decodes a plaintext polynomial back into one integer per slot.
signedreturns each slot as a representative in(-t/2, t/2]rather than in[0, t).
- delta(lvl: int = 0)¶
The scaling factor
q/tatlvl, asscaled_lifttakes it.
- encrypt(message: RNSPolynomial, key: MLWE_Key, lvl: int = 0) MLWE¶
Encrypts a plaintext polynomial, scaled by
Delta, underkey.
- decrypt(ciphertext: MLWE, key: MLWE_Key) RNSPolynomial¶
Decrypts a ciphertext back into a plaintext polynomial.
- mod_switch(ciphertext: MLWE, lvl: int | None = None) MLWE¶
Switches the ciphertext down to level
lvl(the next one by default).The round-division divides the linear decryption and
Deltaalike, so the message is unchanged and the noise shrinks with the modulus.
- rotate(ciphertext: MLWE, k: int, ksk: MLWE_Set | list[MLWE_Set], n_threads: int = 0) MLWE¶
Rotates each of the two rows of
N/2slots bykpositions.
- gen_rotation_key(key: MLWE_Key, k: int, n_threads: int = 0) MLWE_Set | list[MLWE_Set]¶
Generates the key-switching key
rotate()needs fork.
- conjugate(ciphertext: MLWE, ksk: MLWE_Set | list[MLWE_Set], n_threads: int = 0) MLWE¶
Swaps the two rows of slots.
- gen_conjugation_key(key: MLWE_Key, n_threads: int = 0) MLWE_Set | list[MLWE_Set]¶
Generates the key-switching key
conjugate()needs.
- multiply(in1: MLWE, in2: MLWE, ksk: MLWE_Set | list[MLWE_Set] | None = None) MLWE¶
Multiplies two ciphertexts and (optionally) relinearizes.
Two
Delta-scaled linear decryptions multiply to aDelta^2-scaled one, so the product is divided byDeltato come back. That division is over the integers, not moduloq: the operands move up into a ring wide enough to hold the product, are divided there, and come back. Seemul_rings().- Parameters:
in1 – The first ciphertext.
in2 – The second ciphertext.
ksk – The relinearization key, from
gen_rlk. IfNone, relinearization is skipped and the extended product (rankextended_rank) is returned; feed it torelinearize().
- mul_rings(lvl: int) tuple[RNSRing, RNSRing]¶
The two rings
multiply()works in atlvl.The first is level
lvl’s ring plus auxiliary primes: the tensor product is computed there, wide enough not to wrap. The second is the first withoutDelta’s primes, where the round-division byDeltaleaves the result.Both follow from one bound. A product coefficient stays under
N * (ell * q)^2–ell * qrather thanqbecause_lift_ciphertextlifts through the fast base extension. Auxiliary primes are added until the first modulus is four times that, which covers both requirements: the product stays inside half of it, so a coefficient’s centered representative is the integer itself; and the divided value stays inside a quarter of the second modulus, the marginRNSPolynomial.convert_baseneeds.