Documentation ¶
Overview ¶
Package bootstrapping implements bootstrapping for fixed-point encrypted approximate homomorphic encryption over the complex/real numbers.
Index ¶
- Constants
- Variables
- func FailureProbability(Xs *ring.Ternary, K, logN, logSlots int) (logfailure float64)
- func FindSuitableK(Xs *ring.Ternary, logN, logSlots int, logfailure float64) (K int)
- func ModifiedIrwinHall(K, h, logSlots int) (logfailure float64)
- type CircuitOrder
- type EvaluationKeys
- type Evaluator
- func (eval Evaluator) Bootstrap(ct *rlwe.Ciphertext) (*rlwe.Ciphertext, error)
- func (eval Evaluator) BootstrapMany(cts []rlwe.Ciphertext) ([]rlwe.Ciphertext, error)
- func (eval Evaluator) CoeffsToSlots(ctIn *rlwe.Ciphertext) (ctReal, ctImag *rlwe.Ciphertext, err error)
- func (eval *Evaluator) CoeffsToSlotsBypass(ctIn *rlwe.Ciphertext) (real0, imag0 *rlwe.Ciphertext, err error)
- func (eval *Evaluator) ComplexToRealNew(ctCmplx *rlwe.Ciphertext) (real0 *rlwe.Ciphertext)
- func (eval Evaluator) Depth() int
- func (eval *Evaluator) EvalMod(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext, err error)
- func (eval *Evaluator) Evaluate(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext, err error)
- func (eval *Evaluator) EvaluateConjugateInvariant(ctLeftN1Q0, ctRightN1Q0 *rlwe.Ciphertext) (ctLeftN1QL, ctRightN1QL *rlwe.Ciphertext, err error)
- func (eval Evaluator) MinimumInputLevel() int
- func (eval *Evaluator) ModUp(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext, err error)
- func (eval Evaluator) OutputLevel() int
- func (eval Evaluator) Pack(cts []rlwe.Ciphertext, params hefloat.Parameters, xPow2 []ring.RNSPoly) ([]rlwe.Ciphertext, error)
- func (eval *Evaluator) PackAndSwitchN1ToN2(cts []rlwe.Ciphertext) ([]rlwe.Ciphertext, error)
- func (eval *Evaluator) RealToComplexNew(real0 *rlwe.Ciphertext) (ctCmplx *rlwe.Ciphertext)
- func (eval *Evaluator) ScaleDown(ctIn *rlwe.Ciphertext) (*rlwe.Ciphertext, *rlwe.Scale, error)
- func (eval Evaluator) ShallowCopy() *Evaluator
- func (eval Evaluator) SlotsToCoeffs(ctReal, ctImag *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext, err error)
- func (eval *Evaluator) SwitchRingDegreeN1ToN2New(ctN1 *rlwe.Ciphertext) (ctN2 *rlwe.Ciphertext)
- func (eval *Evaluator) SwitchRingDegreeN2ToN1New(ctN2 *rlwe.Ciphertext) (ctN1 *rlwe.Ciphertext)
- func (eval Evaluator) UnPack(cts []rlwe.Ciphertext, params hefloat.Parameters, LogSlots, Nb int, ...) ([]rlwe.Ciphertext, error)
- func (eval *Evaluator) UnpackAndSwitchN2Tn1(cts []rlwe.Ciphertext, LogSlots, Nb int) ([]rlwe.Ciphertext, error)
- type Iterations
- type Parameters
- func (p Parameters) C2SDepth() (depth int)
- func (p Parameters) Depth() (depth int)
- func (p Parameters) Equal(other *Parameters) (res bool)
- func (p Parameters) GaloisElements(params hefloat.Parameters) (galEls []uint64)
- func (p Parameters) GenEncapsulationEvaluationKeysNew(skDense *rlwe.SecretKey) (EvkDenseToSparse, EvkSparseToDense *rlwe.EvaluationKey)
- func (p Parameters) GenEvaluationKeys(skN1 *rlwe.SecretKey) (btpkeys *EvaluationKeys, skN2 *rlwe.SecretKey, err error)
- func (p Parameters) GetC2SBypass() hefloat.DFTMatrixLiteral
- func (p Parameters) LogMaxDimensions() ring.Dimensions
- func (p Parameters) LogMaxSlots() int
- func (p Parameters) Mod1Depth() (depth int)
- func (p Parameters) S2CDepth() (depth int)
- type ParametersLiteral
- func (p ParametersLiteral) BinarySize() (size int)
- func (p ParametersLiteral) BitConsumption() (logQ int, err error)
- func (p ParametersLiteral) FailureProbability() (logfailure float64)
- func (p ParametersLiteral) GetCircuitParametersLiteral(params hefloat.Parameters) (C2S, S2C hefloat.DFTMatrixLiteral, Mod1 hefloat.Mod1ParametersLiteral)
- func (p ParametersLiteral) MarshalBinary() (data []byte, err error)
- func (p *ParametersLiteral) ReadFrom(r io.Reader) (n int64, err error)
- func (p *ParametersLiteral) UnmarshalBinary(data []byte) (err error)
- func (p ParametersLiteral) WriteTo(w io.Writer) (n int64, err error)
- type SecretKeyBootstrapper
- func (d *SecretKeyBootstrapper) Bootstrap(ct *rlwe.Ciphertext) (*rlwe.Ciphertext, error)
- func (d SecretKeyBootstrapper) BootstrapMany(cts []rlwe.Ciphertext) ([]rlwe.Ciphertext, error)
- func (d SecretKeyBootstrapper) Depth() int
- func (d SecretKeyBootstrapper) MinimumInputLevel() int
- func (d SecretKeyBootstrapper) OutputLevel() int
Constants ¶
const ( ModUpThenEncode = CircuitOrder(0) // ScaleDown -> ModUp -> CoeffsToSlots -> EvalMod -> SlotsToCoeffs. DecodeThenModUp = CircuitOrder(1) // SlotsToCoeffs -> ScaleDown -> ModUp -> CoeffsToSlots -> EvalMod. Custom = CircuitOrder(2) // Custom order (e.g. partial bootstrapping), disables checks. )
Variables ¶
var F8192 = map[int]float64{}/* 690 elements not displayed */
F8192 is a map[K] = PR[||I(X)|| > K] for H=8192
Functions ¶
func FailureProbability ¶
FailureProbability returns the probability that PR[||I(X)|| > K]. - Xs: secret distribution - K: upper bound for I(X) - logN: log2(ring degree) - logSlots: log2(#complex slots)
func FindSuitableK ¶
FindSuitableK finds the smallest K such that PR[||I(X)|| > K] <= 2^{logfailure}.
func ModifiedIrwinHall ¶
ModifiedIrwinHall estimates PR[||I(X)|| > K] by evaluating equation (1) of https://eprint.iacr.org/2022/024: 1 - (2/(h+1)! * (sum_i=0^{K+0.5(h+1)} (-1)^i * binom(h+1, i) * (K + 0.5(h+1) - i)^{h+1}))-1)^{2n} This method produces accurate results, but is O(h^3).
Types ¶
type CircuitOrder ¶
type CircuitOrder int
type EvaluationKeys ¶
type EvaluationKeys struct { // EvkN1ToN2 is the evaluation key to switch from the residual parameters' // ring degree (N1) to the bootstrapping parameters' ring degree (N2) EvkN1ToN2 *rlwe.EvaluationKey // EvkN2ToN1 is the evaluation key to switch from the bootstrapping parameters' // ring degree (N2) to the residual parameters' ring degree (N1) EvkN2ToN1 *rlwe.EvaluationKey // EvkRealToCmplx is the evaluation key to switch from the standard ring to the // conjugate invariant ring. EvkRealToCmplx *rlwe.EvaluationKey // EvkCmplxToReal is the evaluation key to switch from the conjugate invariant // ring to the standard ring. EvkCmplxToReal *rlwe.EvaluationKey // EvkDenseToSparse is the evaluation key to switch // from the dense secret to the sparse secret. // https://eprint.iacr.org/2022/024 EvkDenseToSparse *rlwe.EvaluationKey // EvkSparseToDense is the evaluation key to switch // from the sparse secret to the dense secret. // https://eprint.iacr.org/2022/024 EvkSparseToDense *rlwe.EvaluationKey // MemEvaluationKeySet is the evaluation key set storing the relinearization // key and the Galois keys necessary for the bootstrapping circuit. *rlwe.MemEvaluationKeySet }
EvaluationKeys is a struct storing the different evaluation keys required by the bootstrapper.
func (EvaluationKeys) BinarySize ¶
func (b EvaluationKeys) BinarySize() (dLen int)
BinarySize returns the total binary size of the bootstrapper's keys.
type Evaluator ¶
type Evaluator struct { Parameters *hefloat.Evaluator *hefloat.DFTEvaluator *hefloat.Mod1Evaluator *EvaluationKeys hefloat.DomainSwitcher Mod1Parameters hefloat.Mod1Parameters S2CDFTMatrix *hefloat.DFTMatrix C2SDFTMatrix *hefloat.DFTMatrix C2SDFTMatrixBypass *hefloat.DFTMatrix SkDebug *rlwe.SecretKey HoistingBuffer rlwe.HoistingBuffer // contains filtered or unexported fields }
Evaluator is a struct to store a memory buffer with the plaintext matrices, the polynomial approximation, and the keys for the bootstrapping. It is used to evaluate the bootstrapping circuit on single ciphertexts.
func NewEvaluator ¶
func NewEvaluator(btpParams Parameters, evk *EvaluationKeys) (eval *Evaluator, err error)
NewEvaluator creates a new Evaluator.
func (Evaluator) Bootstrap ¶
func (eval Evaluator) Bootstrap(ct *rlwe.Ciphertext) (*rlwe.Ciphertext, error)
Bootstrap bootstraps a single ciphertext and returns the bootstrapped ciphertext.
func (Evaluator) BootstrapMany ¶
func (eval Evaluator) BootstrapMany(cts []rlwe.Ciphertext) ([]rlwe.Ciphertext, error)
BootstrapMany bootstraps a list of ciphertext and returns the list of bootstrapped ciphertexts.
func (Evaluator) CoeffsToSlots ¶
func (eval Evaluator) CoeffsToSlots(ctIn *rlwe.Ciphertext) (ctReal, ctImag *rlwe.Ciphertext, err error)
CoeffsToSlots applies the homomorphic decoding
func (*Evaluator) CoeffsToSlotsBypass ¶
func (eval *Evaluator) CoeffsToSlotsBypass(ctIn *rlwe.Ciphertext) (real0, imag0 *rlwe.Ciphertext, err error)
CoeffsToSlotsBypass applies the high precision homomorphic decoding bypass of the EvalRound approach. See https://eprint.iacr.org/2024/1379.
func (*Evaluator) ComplexToRealNew ¶
func (eval *Evaluator) ComplexToRealNew(ctCmplx *rlwe.Ciphertext) (real0 *rlwe.Ciphertext)
func (Evaluator) Depth ¶
Depth returns the multiplicative depth (number of levels consumed) of the bootstrapping circuit.
func (*Evaluator) EvalMod ¶
func (eval *Evaluator) EvalMod(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext, err error)
EvalMod applies the homomorphic modular reduction by q.
func (*Evaluator) Evaluate ¶
func (eval *Evaluator) Evaluate(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext, err error)
Evaluate re-encrypts a ciphertext to a ciphertext at MaxLevel - k where k is the depth of the bootstrapping circuit. If the input ciphertext level is zero, the input scale must be an exact power of two smaller than Q[0]/MessageRatio (it can't be equal since Q[0] is not a power of two). The message ratio is an optional field in the bootstrapping parameters, by default it set to 2^{LogMessageRatio = 8}. See the bootstrapping parameters for more information about the message ratio or other parameters related to the bootstrapping. If the input ciphertext is at level one or more, the input scale does not need to be an exact power of two as one level can be used to do a scale matching.
The circuit consists in 5 steps. 1) ScaleDown: scales the ciphertext to q/|m| and bringing it down to q 2) ModUp: brings the modulus from q to Q 3) CoeffsToSlots: homomorphic encoding 4) EvalMod: homomorphic modular reduction 5) SlotsToCoeffs: homomorphic decoding
func (*Evaluator) EvaluateConjugateInvariant ¶
func (eval *Evaluator) EvaluateConjugateInvariant(ctLeftN1Q0, ctRightN1Q0 *rlwe.Ciphertext) (ctLeftN1QL, ctRightN1QL *rlwe.Ciphertext, err error)
EvaluateConjugateInvariant takes two ciphertext in the Conjugate Invariant ring, repacks them in a single ciphertext in the standard ring using the real and imaginary part, bootstrap both ciphertext, and then extract back the real and imaginary part before repacking them individually in two new ciphertexts in the Conjugate Invariant ring.
func (Evaluator) MinimumInputLevel ¶
MinimumInputLevel returns the minimum level at which a ciphertext must be to be bootstrapped.
func (*Evaluator) ModUp ¶
func (eval *Evaluator) ModUp(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext, err error)
ModUp raise the modulus from q to Q, scales the message and applies the Trace if the ciphertext is sparsely packed.
func (Evaluator) OutputLevel ¶
OutputLevel returns the output level after the evaluation of the bootstrapping circuit.
func (Evaluator) Pack ¶
func (eval Evaluator) Pack(cts []rlwe.Ciphertext, params hefloat.Parameters, xPow2 []ring.RNSPoly) ([]rlwe.Ciphertext, error)
func (*Evaluator) PackAndSwitchN1ToN2 ¶
func (eval *Evaluator) PackAndSwitchN1ToN2(cts []rlwe.Ciphertext) ([]rlwe.Ciphertext, error)
func (*Evaluator) RealToComplexNew ¶
func (eval *Evaluator) RealToComplexNew(real0 *rlwe.Ciphertext) (ctCmplx *rlwe.Ciphertext)
func (*Evaluator) ScaleDown ¶
func (eval *Evaluator) ScaleDown(ctIn *rlwe.Ciphertext) (*rlwe.Ciphertext, *rlwe.Scale, error)
ScaleDown brings the ciphertext level to zero and scaling factor to Q[0]/MessageRatio It multiplies the ciphertexts by round(currentMessageRatio / targetMessageRatio) where: - currentMessageRatio = Q/ctIn.Scale - targetMessageRatio = q/|m| and updates the scale of ctIn accordingly It then rescales the ciphertext down to q if necessary and also returns the rescaling error from this process
func (Evaluator) ShallowCopy ¶
ShallowCopy creates a shallow copy of this Evaluator in which all the read-only data-structures are shared with the receiver and the temporary buffers are reallocated. The receiver and the returned Evaluator can be used concurrently.
func (Evaluator) SlotsToCoeffs ¶
func (eval Evaluator) SlotsToCoeffs(ctReal, ctImag *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext, err error)
func (*Evaluator) SwitchRingDegreeN1ToN2New ¶
func (eval *Evaluator) SwitchRingDegreeN1ToN2New(ctN1 *rlwe.Ciphertext) (ctN2 *rlwe.Ciphertext)
func (*Evaluator) SwitchRingDegreeN2ToN1New ¶
func (eval *Evaluator) SwitchRingDegreeN2ToN1New(ctN2 *rlwe.Ciphertext) (ctN1 *rlwe.Ciphertext)
func (Evaluator) UnPack ¶
func (eval Evaluator) UnPack(cts []rlwe.Ciphertext, params hefloat.Parameters, LogSlots, Nb int, xPow2Inv []ring.RNSPoly) ([]rlwe.Ciphertext, error)
func (*Evaluator) UnpackAndSwitchN2Tn1 ¶
func (eval *Evaluator) UnpackAndSwitchN2Tn1(cts []rlwe.Ciphertext, LogSlots, Nb int) ([]rlwe.Ciphertext, error)
type Iterations ¶
Iterations is a struct storing the iterations parameters of the bootstrapping.
For example: &bootstrapping.Iterations{BootstrappingPrecision: []float64{16}, ReservedPrimeBitSize: 16} will define a two iteration bootstrapping (the first iteration being the initial bootstrapping) with a additional prime close to 2^{16} reserved for the scaling of the error during the second iteration.
Here is an example for a two iterations bootstrapping of an input message mod [logq0=55, logq1=45] with scaling factor 2^{90}:
INPUT: 1) The input is a ciphertext encrypting [2^{90} * M]_{q0, q1} ITERATION N°0 2) Rescale [M^{90}]_{q0, q1} to [M^{90}/q1]_{q0} (ensure that M^{90}/q1 ~ q0/messageratio by additional scaling if necessary) 3) Bootsrap [M^{90}/q1]_{q0} to [M^{90}/q1 + e^{90 - logprec}/q1]_{q0, q1, q2, ...} 4) Scale up [M^{90}/q1 + e^{90 - logprec}/q1]_{q0, q1, q2, ...} to [M^{d} + e^{d - logprec}]_{q0, q1, q2, ...} ITERATION N°1 5) Subtract [M^{d}]_{q0, q1} to [M^{d} + e^{d - logprec}]_{q0, q1, q2, ...} to get [e^{d - logprec}]_{q0, q1} 6) Scale up [e^{90 - logprec}]_{q0, q1} by 2^{logprec} to get [e^{d}]_{q0, q1} 7) Rescale [e^{90}]_{q0, q1} to [{90}/q1]_{q0} 8) Bootsrap [e^{90}/q1]_{q0} to [e^{90}/q1 + e'^{90 - logprec}/q1]_{q0, q1, q2, ...} 9) Scale up [e^{90}/q1 + e'^{90 - logprec}/q0]_{q0, q1, q2, ...} by round(q1/2^{logprec}) to get [e^{90-logprec} + e'^{90 - 2logprec}]_{q0, q1, q2, ...} 10) Subtract [e^{d - logprec} + e'^{d - 2logprec}]_{q0, q1, q2, ...} to [M^{d} + e^{d - logprec}]_{q0, q1, q2, ...} to get [M^{d} + e'^{d - 2logprec}]_{q0, q1, q2, ...} 11) Go back to step 5 for more iterations until 2^{k * logprec} >= 2^{90}
This example can be generalized to input messages of any scaling factor and desired output precision by increasing the input scaling factor and substituting q1 by a larger product of primes.
Notes:
- The bootstrapping precision cannot exceed the original input ciphertext precision.
- Although the rescalings of 2) and 7) are approximate, we can ignore them and treat them as being part of the bootstrapping error
- As long as round(q1/2^{k*logprec}) >= 2^{logprec}, for k the iteration number, we are guaranteed that the error due to the approximate scale up of step 8) is smaller than 2^{logprec}
- The gain in precision for each iteration is proportional to min(round(q1/2^{k*logprec}), 2^{logprec})
- If round(q1/2^{k * logprec}) < 2^{logprec}, where k is the iteration number, then the gain in precision will be less than the expected logprec. This can happen during the last iteration when q1/2^{k * logprec} < 1, and gets rounded to 1 or 0. To solve this issue, we can reduce logprec for the last iterations, but this increases the number of iterations, or reserve a prime of size at least 2^{logprec} to get a proper scaling by q1/2^{k * logprec} (i.e. not a integer rounded scaling).
- If the input ciphertext is at level 0, we must reserve a prime because everything happens within Q[0] and we have no other prime to use for rescaling.
type Parameters ¶
type Parameters struct { EvalRound bool // ResidualParameters: Parameters outside of the bootstrapping circuit ResidualParameters hefloat.Parameters // BootstrappingParameters: Parameters during the bootstrapping circuit BootstrappingParameters hefloat.Parameters // S2C Parameters of the homomorphic decoding linear transformation S2C hefloat.DFTMatrixLiteral // Mod1: Parameters of the homomorphic modular reduction Mod1 hefloat.Mod1ParametersLiteral // C2S: Parameters of the homomorphic encoding linear transformation C2S hefloat.DFTMatrixLiteral // Iterations: Parameters of the bootstrapping iterations (META-BTS) Iterations Iterations // EphemeralSecretWeight: Hamming weight of the ephemeral secret. If 0, no ephemeral secret is used during the bootstrapping. EphemeralSecretWeight int // CircuitOrder: Value indicating the order of the circuit (default: ModUpThenEncode) CircuitOrder CircuitOrder }
Parameters is a struct storing the parameters of the bootstrapping circuit.
func NewParametersFromLiteral ¶
func NewParametersFromLiteral(residualParameters hefloat.Parameters, btpLit ParametersLiteral) (Parameters, error)
NewParametersFromLiteral instantiates a Parameters from the residual hefloat.Parameters and a bootstrapping.ParametersLiteral struct.
The residualParameters corresponds to the hefloat.Parameters that are left after the bootstrapping circuit is evaluated. These are entirely independent of the bootstrapping parameters with one exception: the ciphertext primes Qi must be congruent to 1 mod 2N of the bootstrapping parameters (note that the auxiliary primes Pi do not need to be). This is required because the primes Qi of the residual parameters and the bootstrapping parameters are the same between the two sets of parameters.
The user can ensure that this condition is met by setting the appropriate LogNThRoot in the hefloat.ParametersLiteral before instantiating them.
The method NewParametersFromLiteral will automatically allocate the hefloat.Parameters of the bootstrapping circuit based on the provided residualParameters and the information given in the bootstrapping.ParametersLiteral.
func (Parameters) C2SDepth ¶
func (p Parameters) C2SDepth() (depth int)
C2SDepth returns the depth of the Coeffs to Slots of the bootstrapping.
func (Parameters) Depth ¶
func (p Parameters) Depth() (depth int)
Depth returns the depth of the full bootstrapping circuit.
func (Parameters) Equal ¶
func (p Parameters) Equal(other *Parameters) (res bool)
func (Parameters) GaloisElements ¶
func (p Parameters) GaloisElements(params hefloat.Parameters) (galEls []uint64)
GaloisElements returns the list of Galois elements required to evaluate the bootstrapping.
func (Parameters) GenEncapsulationEvaluationKeysNew ¶
func (p Parameters) GenEncapsulationEvaluationKeysNew(skDense *rlwe.SecretKey) (EvkDenseToSparse, EvkSparseToDense *rlwe.EvaluationKey)
GenEncapsulationEvaluationKeysNew generates the low level encapsulation EvaluationKeys for the bootstrapping.
func (Parameters) GenEvaluationKeys ¶
func (p Parameters) GenEvaluationKeys(skN1 *rlwe.SecretKey) (btpkeys *EvaluationKeys, skN2 *rlwe.SecretKey, err error)
GenEvaluationKeys generates the bootstrapping evaluation keys, which include:
- If the bootstrapping parameters' ring degree > residual parameters' ring degree:
- An evaluation key to switch from the residual parameters' ring to the bootstrapping parameters' ring
- An evaluation key to switch from the bootstrapping parameters' ring to the residual parameters' ring
- If the residual parameters use the Conjugate Invariant ring:
- An evaluation key to switch from the conjugate invariant ring to the standard ring
- An evaluation key to switch from the standard ring to the conjugate invariant ring
- The core bootstrapping circuit evaluation keys:
- Relinearization key
- Galois keys
- The encapsulation evaluation keys (https://eprint.iacr.org/2022/024)
Note:
- These evaluation keys are generated under an ephemeral secret key skN2 using the distribution specified in the bootstrapping parameters.
- The ephemeral key used to generate the bootstrapping keys is returned by this method for debugging purposes.
- !WARNING! The bootstrapping parameters use their own and independent cryptographic parameters (i.e. float.Parameters) and it is the user's responsibility to ensure that these parameters meet the target security and tweak them if necessary.
func (Parameters) GetC2SBypass ¶
func (p Parameters) GetC2SBypass() hefloat.DFTMatrixLiteral
GetC2SBypass returns the hefloat.DFTMatrixLiteral of the high precision CoeffsToSlots bypass for the EvalRound+ approach. See https://eprint.iacr.org/2024/1379).
func (Parameters) LogMaxDimensions ¶
func (p Parameters) LogMaxDimensions() ring.Dimensions
LogMaxDimensions returns the log plaintext dimensions of the target Parameters.
func (Parameters) LogMaxSlots ¶
func (p Parameters) LogMaxSlots() int
LogMaxSlots returns the log of the maximum number of slots.
func (Parameters) Mod1Depth ¶
func (p Parameters) Mod1Depth() (depth int)
Mod1Depth returns the depth of the EvalMod step of the bootstrapping.
func (Parameters) S2CDepth ¶
func (p Parameters) S2CDepth() (depth int)
S2CDepth returns the depth of the Slots to Coeffs step of the bootstrapping.
type ParametersLiteral ¶
type ParametersLiteral struct { // Initialized is boolean flag set to true if the struct // was intantiated with the method [NewParametersLiteral]. Initialized bool // EvalRound is a boolean flag indicating if the circuit // follows the approach of https://eprint.iacr.org/2024/1379. EvalRound bool // LogN is the base two logarithm of the ring degree of the bootstrapping parameters. LogN int // LogSlots is the maximum number of slots of the ciphertext. LogSlots int // LogP is the base two logarithm of the auxiliary primes during the key-switching operation of the bootstrapping parameters. LogP structs.Vector[int] // Xs is the distribution of the secret-key used to generate the bootstrapping evaluation keys. Xs ring.DistributionParameters // Xe is the distribution of the error sampled to generate the bootstrapping evaluation keys. Xe ring.DistributionParameters // C2S: the scaling factor and distribution of the moduli for the SlotsToCoeffs (homomorphic encoding) step. // See [hefloat.DFTMatrix] for additional information. C2S structs.Matrix[int] // S2C: the scaling factor and distribution of the moduli for the CoeffsToSlots (homomorphic decoding) step. // See [hefloat.DFTMatrix] for additional information. S2C structs.Matrix[int] // EphemeralSecretWeight: the Hamming weight of the ephemeral secret. // The user can set this value to 0 to use the regular bootstrapping // circuit without the ephemeral secret encapsulation. // Be aware that doing so will impact the security, precision, // and failure probability of the bootstrapping circuit. // See https://eprint.iacr.org/2022/024 for more information. EphemeralSecretWeight int // Iterations : by treating the bootstrapping as a black box with precision logprec, // we can construct a bootstrapping of precision ~k*logprec by iteration (see https://eprint.iacr.org/2022/1167). // - BootstrappingPrecision: []float64, the list of iterations (after the initial bootstrapping) given by the // expected precision of each previous iteration. // - ReservedPrimeBitSize: the size of the reserved prime for the scaling after the initial bootstrapping. Iterations Iterations // LogMessageRation is Log(Q/Scale). This ratio directly impacts the precision of the bootstrapping. // The homomorphic modular reduction x mod 1 is approximated with by sin(2*pi*x)/(2*pi), // which is a good approximation when x is close to the origin. // Thus a large message ratio (i.e. 2^8) implies that x is small // with respect to Q, and thus close to the origin. // When using a small ratio (i.e. 2^4), for example if ct.Scale // is close to Q[0] is small or if |m| is large, the Mod1InvDegree can be set to // a non zero value (i.e. 5 or 7). This will greatly improve the precision of the // bootstrapping, at the expense of slightly increasing its depth. LogMessageRatio int // Mod1Type: the type of approximation for the modular reduction polynomial. Mod1Type hefloat.Mod1Type // Mod1LogScale: the scaling factor used during the EvalMod step (all primes will have this bit-size). Mod1LogScale int // Mod1Degree is the degree of f: x mod 1. Mod1Degree int // Mod1Interval is the range of the approximation interval of Mod1. Mod1Interval int // DoubleAngle is the number of double angle evaluation. DoubleAngle int // Mod1InvDegree: the degree of f^-1: (x mod 1)^-1. Mod1InvDegree int }
ParametersLiteral is an unchecked struct that is given to the method NewParametersFromLiteral to validate them and create a [Parameter] struct, which is used to instantiate an Evaluator.
The fields can set manually to customize the bootstrapping circuit, but it is recommanded to first instantiate the struct with the method NewParametersLiteral, which will return a new ParametersLiteral struct with the default bootstrapping parameterization (see NewParametersLiteral for information about its performance).
func NewParametersLiteral ¶
func NewParametersLiteral() (p ParametersLiteral)
NewParametersLiteral returns a bootstrapping.ParametersLiteral with default value, ensuring a bootstrapping with the following standardized performance:
Depth: - 2 for CoeffsToSlots - 8 for EvalMod - 3 for SlotsToCoeffs for a total 13 and a bit consumption of 713.
Precision: - 27.25 bits for H=192 - 23.8 bits for H=32768 for complex values with both real and imaginary parts uniformly distributed in [-1, 1].
Failure probability: - 2^{-133} for 2^{15} slots.
func (ParametersLiteral) BinarySize ¶
func (p ParametersLiteral) BinarySize() (size int)
BinarySize returns the serialized size of the object in bytes.
func (ParametersLiteral) BitConsumption ¶
func (p ParametersLiteral) BitConsumption() (logQ int, err error)
BitConsumption returns the expected consumption in bits of bootstrapping circuit of the target ParametersLiteral. The value is rounded up and thus will overestimate the value by up to 1 bit.
func (ParametersLiteral) FailureProbability ¶
func (p ParametersLiteral) FailureProbability() (logfailure float64)
FailureProbability returns the base 2 logarithm of the failure probability of the bootstrapping parameters. This method only supports Xs.(type) = *ring.Ternary and will panic otherwise.
func (ParametersLiteral) GetCircuitParametersLiteral ¶
func (p ParametersLiteral) GetCircuitParametersLiteral(params hefloat.Parameters) (C2S, S2C hefloat.DFTMatrixLiteral, Mod1 hefloat.Mod1ParametersLiteral)
GetCircuitParametersLiteral returns the parameters literal of CoeffsToSlots, SlotsToCoeffs, Mod1. This method will panic if the depth allocated to CoeffsToSlots or SlotsToCoeffs is larger than LogSlots.
func (ParametersLiteral) MarshalBinary ¶
func (p ParametersLiteral) MarshalBinary() (data []byte, err error)
MarshalBinary encodes the object into a binary form on a newly allocated slice of bytes.
func (*ParametersLiteral) ReadFrom ¶
func (p *ParametersLiteral) ReadFrom(r io.Reader) (n int64, err error)
ReadFrom reads on the object from an io.Writer. It implements the io.ReaderFrom interface.
Unless r implements the buffer.Reader interface (see see lattigo/utils/buffer/reader.go), it will be wrapped into a bufio.Reader. Since this requires allocation, it is preferable to pass a buffer.Reader directly:
- When reading multiple values from a io.Reader, it is preferable to first first wrap io.Reader in a pre-allocated bufio.Reader.
- When reading from a var b []byte, it is preferable to pass a buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).
func (*ParametersLiteral) UnmarshalBinary ¶
func (p *ParametersLiteral) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a slice of bytes generated by MarshalBinary or WriteTo on the object.
func (ParametersLiteral) WriteTo ¶
func (p ParametersLiteral) WriteTo(w io.Writer) (n int64, err error)
WriteTo writes the object on an io.Writer. It implements the io.WriterTo interface, and will write exactly object.BinarySize() bytes on w.
Unless w implements the buffer.Writer interface (see lattigo/utils/buffer/writer.go), it will be wrapped into a bufio.Writer. Since this requires allocations, it is preferable to pass a buffer.Writer directly:
- When writing multiple times to a io.Writer, it is preferable to first wrap the io.Writer in a pre-allocated bufio.Writer.
- When writing to a pre-allocated var b []byte, it is preferable to pass buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).
type SecretKeyBootstrapper ¶
type SecretKeyBootstrapper struct { hefloat.Parameters *hefloat.Encoder *rlwe.Decryptor *rlwe.Encryptor Values []bignum.Complex Counter int // records the number of bootstrapping MinLevel int // contains filtered or unexported fields }
SecretKeyBootstrapper is an implementation of the rlwe.Bootstrapping interface that uses the secret-key to decrypt and re-encrypt the bootstrapped ciphertext.
func NewSecretKeyBootstrapper ¶
func NewSecretKeyBootstrapper(params hefloat.Parameters, sk *rlwe.SecretKey) *SecretKeyBootstrapper
func (*SecretKeyBootstrapper) Bootstrap ¶
func (d *SecretKeyBootstrapper) Bootstrap(ct *rlwe.Ciphertext) (*rlwe.Ciphertext, error)
func (SecretKeyBootstrapper) BootstrapMany ¶
func (d SecretKeyBootstrapper) BootstrapMany(cts []rlwe.Ciphertext) ([]rlwe.Ciphertext, error)
func (SecretKeyBootstrapper) Depth ¶
func (d SecretKeyBootstrapper) Depth() int
func (SecretKeyBootstrapper) MinimumInputLevel ¶
func (d SecretKeyBootstrapper) MinimumInputLevel() int
func (SecretKeyBootstrapper) OutputLevel ¶
func (d SecretKeyBootstrapper) OutputLevel() int