Documentation ¶
Overview ¶
Package mod1 implements a homomorphic mod1 circuit for the CKKS scheme.
Index ¶
Constants ¶
const ( CosDiscrete = Type(0) // Special approximation (Han and Ki) of pow((1/2pi), 1/2^r) * cos(2pi(x-0.25)/2^r); this method requires a minimum degree of 2*(K-1). SinContinuous = Type(1) // Standard Chebyshev approximation of (1/2pi) * sin(2pix) on the full interval CosContinuous = Type(2) // Standard Chebyshev approximation of pow((1/2pi), 1/2^r) * cos(2pi(x-0.25)/2^r) on the full interval )
Sin and Cos are the two proposed functions for Type. These trigonometric functions offer a good approximation of the function x mod 1 when the values are close to the origin.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Evaluator ¶
type Evaluator struct { *ckks.Evaluator PolynomialEvaluator *polynomial.Evaluator Parameters Parameters }
Evaluator is an evaluator providing an API for homomorphic evaluations of scaled x mod 1. All fields of this struct are public, enabling custom instantiations.
func NewEvaluator ¶
func NewEvaluator(eval *ckks.Evaluator, evalPoly *polynomial.Evaluator, Mod1Parameters Parameters) *Evaluator
NewEvaluator instantiates a new Evaluator evaluator from ckks.Evaluator. This method is allocation free.
func (Evaluator) EvaluateAndScaleNew ¶ added in v6.1.0
func (eval Evaluator) EvaluateAndScaleNew(ct *rlwe.Ciphertext, scaling complex128) (res *rlwe.Ciphertext, err error)
EvaluateAndScaleNew calls [EvaluateNew] and scales the output values by `scaling` (without consuming additional depth). If `scaling` set to 1, then this is equivalent to simply calling [EvaluateNew].
func (Evaluator) EvaluateNew ¶
func (eval Evaluator) EvaluateNew(ct *rlwe.Ciphertext) (*rlwe.Ciphertext, error)
EvaluateNew applies an homomorphic mod Q on a vector scaled by Delta, scaled down to mod 1:
- Delta * (Q/Delta * I(X) + m(X)) (Delta = scaling factor, I(X) integer poly, m(X) message)
- Delta * (I(X) + Delta/Q * m(X)) (divide by Q/Delta)
- Delta * (Delta/Q * m(X)) (x mod 1)
- Delta * (m(X)) (multiply back by Q/Delta)
Since Q is not a power of two, but Delta is, then does an approximate division by the closest power of two to Q instead. Hence, it assumes that the input plaintext is already scaled by the correcting factor Q/2^{round(log(Q))}.
!! Assumes that the input is normalized by 1/K for K the range of the approximation.
Scaling back error correction by 2^{round(log(Q))}/Q afterward is included in the polynomial
type Parameters ¶
type Parameters struct { LevelQ int // starting level of the operation LogDefaultScale int // log2 of the default scaling factor Mod1Type Type // type of approximation for the f: x mod 1 function LogMessageRatio int // Log2 of the ratio between Q0 and m, i.e. Q[0]/|m| DoubleAngle int // Number of rescale and double angle formula (only applies for cos and is ignored if sin is used) QDiff float64 // Q / 2^round(Log2(Q)) Sqrt2Pi float64 // (1/2pi)^(1.0/scFac) Mod1Poly bignum.Polynomial // Polynomial for f: x mod 1 Mod1InvPoly *bignum.Polynomial // Polynomial for f^-1: (x mod 1)^-1 K float64 // interval [-K, K] }
Parameters is a struct storing the parameters and polynomials approximating the function x mod Q[0] (the first prime of the moduli chain).
func NewParametersFromLiteral ¶
func NewParametersFromLiteral(params ckks.Parameters, evm ParametersLiteral) (Parameters, error)
NewParametersFromLiteral generates an Parameters struct from the ParametersLiteral struct. The Parameters struct is to instantiates a [Mod1Evaluator], which homomorphically evaluates x mod 1.
func (Parameters) IntervalShrinkFactor ¶ added in v6.1.0
func (evp Parameters) IntervalShrinkFactor() float64
IntervalShrinkFactor returns 2^{DoubleAngle}
func (Parameters) KShrinked ¶ added in v6.1.0
func (evp Parameters) KShrinked() float64
KShrinked returns K / IntervalShrinkFactor()
func (Parameters) MessageRatio ¶
func (evp Parameters) MessageRatio() float64
MessageRatio returns the pre-set ratio Q[0]/|m|.
func (Parameters) ScalingFactor ¶
func (evp Parameters) ScalingFactor() rlwe.Scale
ScalingFactor returns scaling factor used during the x mod 1.
type ParametersLiteral ¶
type ParametersLiteral struct { LevelQ int // Starting level of x mod 1 LogScale int // Log2 of the scaling factor used during x mod 1 Mod1Type Type // Chose between [Sin(2*pi*x)] or [cos(2*pi*x/r) with double angle formula] Scaling float64 // Value by which the output is scaled by LogMessageRatio int // Log2 of the ratio between Q0 and m, i.e. Q[0]/|m| K int // K parameter (interpolation in the range -K to K) Mod1Degree int // Degree of f: x mod 1 DoubleAngle int // Number of rescale and double angle formula (only applies for cos and is ignored if sin is used) Mod1InvDegree int // Degree of f^-1: (x mod 1)^-1 }
ParametersLiteral a struct for the parameters of the mod 1 procedure. The x mod 1 procedure goal is to homomorphically evaluate a modular reduction by Q[0] (the first prime of the moduli chain) on the encrypted plaintext. This struct is consumed by NewParametersFromLiteral to generate the ParametersLiteral struct, which notably stores the coefficient of the polynomial approximating the function x mod Q[0].
func (ParametersLiteral) Depth ¶
func (evm ParametersLiteral) Depth() (depth int)
Depth returns the depth required to evaluate x mod 1.
func (ParametersLiteral) MarshalBinary ¶
func (evm ParametersLiteral) MarshalBinary() (data []byte, err error)
MarshalBinary returns a JSON representation of the the target Mod1ParametersLiteral struct on a slice of bytes. See Marshal from the encoding/json package.
func (*ParametersLiteral) UnmarshalBinary ¶
func (evm *ParametersLiteral) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary reads a JSON representation on the target Mod1ParametersLiteral struct. See Unmarshal from the encoding/json package.