Documentation ¶
Overview ¶
Package bootstrapping implement the bootstrapping for the CKKS scheme.
Index ¶
- Variables
- type Bootstrapper
- type EvaluationKeys
- type Parameters
- func (p *Parameters) GenEncapsulationSwitchingKeys(params ckks.Parameters, skDense *rlwe.SecretKey) (swkDtS, swkStD *rlwe.SwitchingKey)
- func (p *Parameters) MarshalBinary() (data []byte, err error)
- func (p *Parameters) RotationsForBootstrapping(params ckks.Parameters) (rotations []int)
- func (p *Parameters) UnmarshalBinary(data []byte) (err error)
Constants ¶
This section is empty.
Variables ¶
var ( // N16QP1546H192H32 is a default bootstrapping parameters for a main secret with H=192 and an ephemeral secret with H=32. // Residual Q : 420 bits. // Precision : 26.6 bits for 2^{15} slots. // Failure : 2^{-138.7} for 2^{15} slots. N16QP1546H192H32 = defaultParametersLiteral{ ckks.ParametersLiteral{ LogN: 16, Sigma: rlwe.DefaultSigma, H: 192, Q: []uint64{ 0x10000000006e0001, 0x10000140001, 0xffffe80001, 0xffffc40001, 0x100003e0001, 0xffffb20001, 0x10000500001, 0xffff940001, 0xffff8a0001, 0xffff820001, 0x7fffe60001, 0x7fffe40001, 0x7fffe00001, 0xfffffffff840001, 0x1000000000860001, 0xfffffffff6a0001, 0x1000000000980001, 0xfffffffff5a0001, 0x1000000000b00001, 0x1000000000ce0001, 0xfffffffff2a0001, 0x100000000060001, 0xfffffffff00001, 0xffffffffd80001, 0x1000000002a0001, }, P: []uint64{ 0x1fffffffffe00001, 0x1fffffffffc80001, 0x1fffffffffb40001, 0x1fffffffff500001, 0x1fffffffff420001, }, LogSlots: 15, DefaultScale: 1 << 40, }, Parameters{ EphemeralSecretWeight: 32, SlotsToCoeffsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.SlotsToCoeffs, RepackImag2Real: true, LevelStart: 12, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x7fffe60001}, {0x7fffe40001}, {0x7fffe00001}, }, }, EvalModParameters: advanced.EvalModLiteral{ Q: 0x10000000006e0001, LevelStart: 20, SineType: advanced.Cos1, MessageRatio: 256.0, K: 16, SineDeg: 30, DoubleAngle: 3, ArcSineDeg: 0, ScalingFactor: 1 << 60, }, CoeffsToSlotsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.CoeffsToSlots, RepackImag2Real: true, LevelStart: 24, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x100000000060001}, {0xfffffffff00001}, {0xffffffffd80001}, {0x1000000002a0001}, }, }, }, } // N16QP1547H192H32 is a default bootstrapping parameters for a main secret with H=192 and an ephemeral secret with H=32. // Residual Q : 285 bits. // Precision : 32.1 bits for 2^{15} slots. // Failure : 2^{-138.7} for 2^{15} slots. N16QP1547H192H32 = defaultParametersLiteral{ ckks.ParametersLiteral{ LogN: 16, Sigma: rlwe.DefaultSigma, H: 192, Q: []uint64{ 0x10000000006e0001, 0x2000000a0001, 0x2000000e0001, 0x1fffffc20001, 0x200000440001, 0x200000500001, 0x3ffffe80001, 0x3ffffd20001, 0x3ffffca0001, 0xffffffffffc0001, 0xfffffffff240001, 0x1000000000f00001, 0xfffffffff840001, 0x1000000000860001, 0xfffffffff6a0001, 0x1000000000980001, 0xfffffffff5a0001, 0x1000000000b00001, 0x1000000000ce0001, 0xfffffffff2a0001, 0x400000000360001, 0x3ffffffffbe0001, 0x400000000660001, 0x4000000008a0001, }, P: []uint64{ 0x1fffffffffe00001, 0x1fffffffffc80001, 0x1fffffffffb40001, 0x1fffffffff500001, }, LogSlots: 15, DefaultScale: 1 << 45, }, Parameters{ EphemeralSecretWeight: 32, SlotsToCoeffsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.SlotsToCoeffs, RepackImag2Real: true, LevelStart: 8, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x3ffffe80001}, {0x3ffffd20001}, {0x3ffffca0001}, }, }, EvalModParameters: advanced.EvalModLiteral{ Q: 0x10000000006e0001, LevelStart: 19, SineType: advanced.Cos1, MessageRatio: 4.0, K: 16, SineDeg: 30, DoubleAngle: 3, ArcSineDeg: 7, ScalingFactor: 1 << 60, }, CoeffsToSlotsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.CoeffsToSlots, RepackImag2Real: true, LevelStart: 23, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x400000000360001}, {0x3ffffffffbe0001}, {0x400000000660001}, {0x4000000008a0001}, }, }, }, } // N16QP1553H192H32 is a default bootstrapping parameters for a main secret with H=192 and an ephemeral secret with H=32. // Residual Q : 505 bits. // Precision : 19.1 bits for 2^{15} slots. // Failure : 2^{-138.7} for 2^{15} slots. N16QP1553H192H32 = defaultParametersLiteral{ ckks.ParametersLiteral{ LogN: 16, Sigma: rlwe.DefaultSigma, H: 192, Q: []uint64{ 0x80000000080001, 0xffffffffffc0001, 0x10000000006e0001, 0xfffffffff840001, 0x1000000000860001, 0xfffffffff6a0001, 0x1000000000980001, 0xfffffffff5a0001, 0x1000000000b00001, 0x1000000000ce0001, 0x80000000440001, 0x7fffffffba0001, 0x80000000500001, 0x7fffffffaa0001, 0x800000005e0001, 0x7fffffff7e0001, 0x7fffffff380001, 0x80000000ca0001, 0x200000000e0001, 0x20000000140001, 0x20000000280001, 0x1fffffffd80001, }, P: []uint64{ 0x1fffffffffe00001, 0x1fffffffffc80001, 0x1fffffffffb40001, 0x1fffffffff500001, 0x1fffffffff420001, }, LogSlots: 15, DefaultScale: 1 << 30, }, Parameters{ EphemeralSecretWeight: 32, SlotsToCoeffsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.SlotsToCoeffs, RepackImag2Real: true, LevelStart: 9, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {1073741824.0}, {1073741824.0062866, 1073741824.0062866}, }, }, EvalModParameters: advanced.EvalModLiteral{ Q: 0x80000000080001, LevelStart: 17, SineType: advanced.Cos1, MessageRatio: 256.0, K: 16, SineDeg: 30, DoubleAngle: 3, ArcSineDeg: 0, ScalingFactor: 1 << 55, }, CoeffsToSlotsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.CoeffsToSlots, RepackImag2Real: true, LevelStart: 21, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x200000000e0001}, {0x20000000140001}, {0x20000000280001}, {0x1fffffffd80001}, }, }, }, } // N15QP768H192H32 is a default bootstrapping parameters for a main secret with H=192 and an ephemeral secret with H=32. // Residual Q : 110 bits. // Precision : 15.4 bits for 2^{14} slots. // Failure : 2^{-139.7} for 2^{14} slots. N15QP768H192H32 = defaultParametersLiteral{ ckks.ParametersLiteral{ LogN: 15, Sigma: rlwe.DefaultSigma, H: 192, Q: []uint64{ 0x1fff90001, 0x4000000420001, 0x1fc0001, 0xffffffffffc0001, 0x4000000120001, 0x40000001b0001, 0x3ffffffdf0001, 0x4000000270001, 0x3ffffffd20001, 0x3ffffffcd0001, 0x4000000350001, 0x3ffffffc70001, 0x1fffffff50001, 0x1ffffffea0001, }, P: []uint64{ 0x7fffffffe0001, 0x8000000110001, }, LogSlots: 14, DefaultScale: 1 << 25, }, Parameters{ EphemeralSecretWeight: 32, SlotsToCoeffsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.SlotsToCoeffs, RepackImag2Real: true, LevelStart: 3, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {1073741823.9998779, 1073741823.9998779}, }, }, EvalModParameters: advanced.EvalModLiteral{ Q: 0x1fff90001, LevelStart: 11, SineType: advanced.Cos1, MessageRatio: 256.0, K: 16, SineDeg: 30, DoubleAngle: 3, ArcSineDeg: 0, ScalingFactor: 1 << 50, }, CoeffsToSlotsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.CoeffsToSlots, RepackImag2Real: true, LevelStart: 13, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x1fffffff50001}, {0x1ffffffea0001}, }, }, }, } // N16QP1767H32768H32 is a default bootstrapping parameters for a main secret with H=32768 and an ephemeral secret with H=32. // Residual Q : 580 bits. // Precision : 23.0 bits for 2^{15} slots. // Failure : 2^{-138.7} for 2^{15} slots. N16QP1767H32768H32 = defaultParametersLiteral{ ckks.ParametersLiteral{ LogN: 16, Sigma: rlwe.DefaultSigma, H: 32768, Q: []uint64{ 0x10000000006e0001, 0x10000140001, 0xffffe80001, 0xffffc40001, 0x100003e0001, 0xffffb20001, 0x10000500001, 0xffff940001, 0xffff8a0001, 0xffff820001, 0xffff780001, 0x10000960001, 0x10000a40001, 0xffff580001, 0x7fffe60001, 0x7fffe40001, 0x7fffe00001, 0xfffffffff840001, 0x1000000000860001, 0xfffffffff6a0001, 0x1000000000980001, 0xfffffffff5a0001, 0x1000000000b00001, 0x1000000000ce0001, 0xfffffffff2a0001, 0x100000000060001, 0xfffffffff00001, 0xffffffffd80001, 0x1000000002a0001, }, P: []uint64{ 0x1fffffffffe00001, 0x1fffffffffc80001, 0x1fffffffffb40001, 0x1fffffffff500001, 0x1fffffffff420001, 0x1fffffffff380001, }, LogSlots: 15, DefaultScale: 1 << 40, }, Parameters{ EphemeralSecretWeight: 32, SlotsToCoeffsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.SlotsToCoeffs, RepackImag2Real: true, LevelStart: 16, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x7fffe60001}, {0x7fffe40001}, {0x7fffe00001}, }, }, EvalModParameters: advanced.EvalModLiteral{ Q: 0x10000000006e0001, LevelStart: 24, SineType: advanced.Cos1, MessageRatio: 256.0, K: 16, SineDeg: 30, DoubleAngle: 3, ArcSineDeg: 0, ScalingFactor: 1 << 60, }, CoeffsToSlotsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.CoeffsToSlots, RepackImag2Real: true, LevelStart: 28, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x100000000060001}, {0xfffffffff00001}, {0xffffffffd80001}, {0x1000000002a0001}, }, }, }, } // N16QP1788H32768H32 is a default bootstrapping parameters for a main secret with H=32768 and an ephemeral secret with H=32. // Residual Q : 465 bits. // Precision : 29.0 bits for 2^{15} slots. // Failure : 2^{-138.7} for 2^{15} slots. N16QP1788H32768H32 = defaultParametersLiteral{ ckks.ParametersLiteral{ LogN: 16, Sigma: rlwe.DefaultSigma, H: 32768, Q: []uint64{ 0x10000000006e0001, 0x2000000a0001, 0x2000000e0001, 0x1fffffc20001, 0x200000440001, 0x200000500001, 0x200000620001, 0x1fffff980001, 0x2000006a0001, 0x1fffff7e0001, 0x3ffffe80001, 0x3ffffd20001, 0x3ffffca0001, 0xffffffffffc0001, 0xfffffffff240001, 0x1000000000f00001, 0xfffffffff840001, 0x1000000000860001, 0xfffffffff6a0001, 0x1000000000980001, 0xfffffffff5a0001, 0x1000000000b00001, 0x1000000000ce0001, 0xfffffffff2a0001, 0x400000000360001, 0x3ffffffffbe0001, 0x400000000660001, 0x4000000008a0001, }, P: []uint64{ 0x1fffffffffe00001, 0x1fffffffffc80001, 0x1fffffffffb40001, 0x1fffffffff500001, 0x1fffffffff420001, }, LogSlots: 15, DefaultScale: 1 << 45, }, Parameters{ EphemeralSecretWeight: 32, SlotsToCoeffsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.SlotsToCoeffs, RepackImag2Real: true, LevelStart: 12, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x3ffffe80001}, {0x3ffffd20001}, {0x3ffffca0001}, }, }, EvalModParameters: advanced.EvalModLiteral{ Q: 0x10000000006e0001, LevelStart: 23, SineType: advanced.Cos1, MessageRatio: 4.0, K: 16, SineDeg: 30, DoubleAngle: 3, ArcSineDeg: 7, ScalingFactor: 1 << 60, }, CoeffsToSlotsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.CoeffsToSlots, RepackImag2Real: true, LevelStart: 27, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x400000000360001}, {0x3ffffffffbe0001}, {0x400000000660001}, {0x4000000008a0001}, }, }, }, } // N16QP1793H32768H32 is a default bootstrapping parameters for a main secret with H=32768 and an ephemeral secret with H=32. // Residual Q : 745 bits. // Precision : 17.8 bits for 2^{15} slots. // Failure : 2^{-138.7} for 2^{15} slots. N16QP1793H32768H32 = defaultParametersLiteral{ ckks.ParametersLiteral{ LogN: 16, Sigma: rlwe.DefaultSigma, H: 32768, Q: []uint64{ 0x80000000080001, 0xffffffffffc0001, 0x10000000006e0001, 0xfffffffff840001, 0x1000000000860001, 0xfffffffff6a0001, 0x1000000000980001, 0xfffffffff5a0001, 0xfffffffff2a0001, 0xfffffffff240001, 0x1000000000f00001, 0xffffffffefe0001, 0x1000000000b00001, 0x1000000000ce0001, 0x80000000440001, 0x7fffffffba0001, 0x80000000500001, 0x7fffffffaa0001, 0x800000005e0001, 0x7fffffff7e0001, 0x7fffffff380001, 0x80000000ca0001, 0x200000000e0001, 0x20000000140001, 0x20000000280001, 0x1fffffffd80001, }, P: []uint64{ 0x1fffffffffe00001, 0x1fffffffffc80001, 0x1fffffffffb40001, 0x1fffffffff500001, 0x1fffffffff420001, }, LogSlots: 15, DefaultScale: 1 << 30, }, Parameters{ EphemeralSecretWeight: 32, SlotsToCoeffsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.SlotsToCoeffs, RepackImag2Real: true, LevelStart: 13, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {1073741824.0}, {1073741824.0062866, 1073741824.0062866}, }, }, EvalModParameters: advanced.EvalModLiteral{ Q: 0x80000000080001, LevelStart: 21, SineType: advanced.Cos1, MessageRatio: 256.0, K: 16, SineDeg: 30, DoubleAngle: 3, ArcSineDeg: 0, ScalingFactor: 1 << 55, }, CoeffsToSlotsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.CoeffsToSlots, RepackImag2Real: true, LevelStart: 25, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x200000000e0001}, {0x20000000140001}, {0x20000000280001}, {0x1fffffffd80001}, }, }, }, } // N15QP880H16384H32 is a default bootstrapping parameters for a main secret with H=16384 and an ephemeral secret with H=32. // Residual Q : 166 bits. // Precision : 17.3 bits for 2^{14} slots. // Failure : 2^{-139.7} for 2^{14} slots. N15QP880H16384H32 = defaultParametersLiteral{ ckks.ParametersLiteral{ LogN: 15, Sigma: rlwe.DefaultSigma, H: 16384, Q: []uint64{ 0x10000140001, 0x7ffe0001, 0x7ff80001, 0x80140001, 0x7fea0001, 0x1000000000ce0001, 0x80000000080001, 0x80000000440001, 0x7fffffffba0001, 0x80000000500001, 0x7fffffffaa0001, 0x800000005e0001, 0x7fffffff7e0001, 0x7fffffff380001, 0x10000000060001, 0xffffffff00001, }, P: []uint64{ 0x100000000060001, 0x1000000002a0001, }, LogSlots: 14, DefaultScale: 1 << 31, }, Parameters{ EphemeralSecretWeight: 32, SlotsToCoeffsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.SlotsToCoeffs, RepackImag2Real: true, LevelStart: 5, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {1073741824.0062866, 1073741824.0062866}, }, }, EvalModParameters: advanced.EvalModLiteral{ Q: 0x10000140001, LevelStart: 13, SineType: advanced.Cos1, MessageRatio: 256.0, K: 16, SineDeg: 30, DoubleAngle: 3, ArcSineDeg: 0, ScalingFactor: 1 << 55, }, CoeffsToSlotsParameters: advanced.EncodingMatrixLiteral{ LinearTransformType: advanced.CoeffsToSlots, RepackImag2Real: true, LevelStart: 15, BSGSRatio: 2.0, BitReversed: false, ScalingFactor: [][]float64{ {0x10000000060001}, {0xffffffff00001}, }, }, }, } )
var DefaultParametersDense = []defaultParametersLiteral{N16QP1767H32768H32, N16QP1788H32768H32, N16QP1793H32768H32, N15QP880H16384H32}
DefaultParametersDense is a set of default bootstrapping parameters with H=N/2 as main secret and H=32 as ephemeral secret.
var DefaultParametersSparse = []defaultParametersLiteral{N16QP1546H192H32, N16QP1547H192H32, N16QP1553H192H32, N15QP768H192H32}
DefaultParametersSparse is a set of default bootstrapping parameters with H=192 as main secret and H=32 as ephemeral secret.
Functions ¶
This section is empty.
Types ¶
type Bootstrapper ¶
Bootstrapper is a struct to store a memory buffer with the plaintext matrices, the polynomial approximation, and the keys for the bootstrapping.
func NewBootstrapper ¶
func NewBootstrapper(params ckks.Parameters, btpParams Parameters, btpKeys EvaluationKeys) (btp *Bootstrapper, err error)
NewBootstrapper creates a new Bootstrapper.
func (*Bootstrapper) Bootstrap ¶
func (btp *Bootstrapper) Bootstrap(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext)
Bootstrap re-encrypts a ciphertext at lvl Q0 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 or equal to round(Q0/2^{10}). 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.
func (Bootstrapper) CheckKeys ¶
func (bb Bootstrapper) CheckKeys(btpKeys EvaluationKeys) (err error)
CheckKeys checks if all the necessary keys are present in the instantiated Bootstrapper
func (*Bootstrapper) ShallowCopy ¶
func (btp *Bootstrapper) ShallowCopy() *Bootstrapper
ShallowCopy creates a shallow copy of this Bootstrapper in which all the read-only data-structures are shared with the receiver and the temporary buffers are reallocated. The receiver and the returned Bootstrapper can be used concurrently.
type EvaluationKeys ¶
type EvaluationKeys struct { rlwe.EvaluationKey SwkDtS *rlwe.SwitchingKey SwkStD *rlwe.SwitchingKey }
EvaluationKeys is a type for a CKKS bootstrapping key, which regroups the necessary public relinearization and rotation keys.
func GenEvaluationKeys ¶
func GenEvaluationKeys(btpParams Parameters, ckksParams ckks.Parameters, sk *rlwe.SecretKey) EvaluationKeys
GenEvaluationKeys generates the bootstrapping EvaluationKeys, which contain:
Rlk: *rlwe.RelinearizationKey Rtks: *rlwe.RotationKeySet SwkDtS: *rlwe.SwitchingKey SwkStD: *rlwe.SwitchingKey
type Parameters ¶
type Parameters struct { SlotsToCoeffsParameters advanced.EncodingMatrixLiteral EvalModParameters advanced.EvalModLiteral CoeffsToSlotsParameters advanced.EncodingMatrixLiteral EphemeralSecretWeight int // Hamming weight of the ephemeral secret. If 0, no ephemeral secret is used during the bootstrapping. }
Parameters is a struct for the default bootstrapping parameters
func (*Parameters) GenEncapsulationSwitchingKeys ¶
func (p *Parameters) GenEncapsulationSwitchingKeys(params ckks.Parameters, skDense *rlwe.SecretKey) (swkDtS, swkStD *rlwe.SwitchingKey)
GenEncapsulationSwitchingKeys generates the low level encapsulation switching keys for the bootstrapping.
func (*Parameters) MarshalBinary ¶
func (p *Parameters) MarshalBinary() (data []byte, err error)
MarshalBinary encode the target Parameters on a slice of bytes.
func (*Parameters) RotationsForBootstrapping ¶
func (p *Parameters) RotationsForBootstrapping(params ckks.Parameters) (rotations []int)
RotationsForBootstrapping returns the list of rotations performed during the Bootstrapping operation.
func (*Parameters) UnmarshalBinary ¶
func (p *Parameters) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a slice of bytes on the target Parameters.