Documentation ¶
Overview ¶
Package ckks implements a RNS-accelerated version of the Homomorphic Encryption for Arithmetic for Approximate Numbers (HEAAN, a.k.a. CKKS) scheme. It provides approximate arithmetic over the complex numbers.package ckks
Index ¶
- Constants
- Variables
- func BsgsIndex(el interface{}, slots, N1 int) (index map[int][]int, rotN1, rotN2 []int)
- func DivideComplex128SliceVec(values []complex128, scaleVal complex128)
- func FindBestBSGSSplit(diagMatrix interface{}, maxN int, maxRatio float64) (minN int)
- func GenSwitchkeysRescalingParams(Q, P []uint64) (params []uint64)
- func NewPublicKey(params Parameters) (pk *rlwe.PublicKey)
- func NewRelinearizationKey(params Parameters) *rlwe.RelinearizationKey
- func NewRotationKeySet(params Parameters, galoisElements []uint64) *rlwe.RotationKeySet
- func NewSecretKey(params Parameters) (sk *rlwe.SecretKey)
- func NewSwitchingKey(params Parameters) *rlwe.SwitchingKey
- func NttAndMontgomeryLvl(level int, logSlots int, ringQ *ring.Ring, montgomery bool, pol *ring.Poly)
- func SliceBitReverseInPlaceComplex128(slice []complex128, N int)
- func SliceBitReverseInPlaceFloat64(slice []float64, N int)
- func SliceBitReverseInPlaceRingComplex(slice []*ring.Complex, N int)
- func SpecialFFTUL8Vec(values []complex128, N, M int, rotGroup []int, roots []complex128)
- func SpecialFFTVec(values []complex128, N, M int, rotGroup []int, roots []complex128)
- func SpecialiFFTUL8Vec(values []complex128, N, M int, rotGroup []int, roots []complex128)
- func SpecialiFFTVec(values []complex128, N, M int, rotGroup []int, roots []complex128)
- func StandardDeviation(vec []float64, scale float64) (std float64)
- type BasisType
- type Ciphertext
- func (ct *Ciphertext) Copy(ctp *Ciphertext)
- func (ct *Ciphertext) CopyNew() (ctc *Ciphertext)
- func (ct *Ciphertext) GetDataLen(WithMetaData bool) (dataLen int)
- func (ct *Ciphertext) MarshalBinary() (data []byte, err error)
- func (ct *Ciphertext) Scale() float64
- func (ct *Ciphertext) SetScale(scale float64)
- func (ct *Ciphertext) UnmarshalBinary(data []byte) (err error)
- type Decryptor
- type DomainSwitcher
- type Encoder
- type EncoderBigComplex
- type Encryptor
- type Evaluator
- type KeyGenerator
- type LinearTransform
- func GenLinearTransform(encoder Encoder, value interface{}, level int, scale float64, logslots int) LinearTransform
- func GenLinearTransformBSGS(encoder Encoder, value interface{}, level int, scale, BSGSRatio float64, ...) (LT LinearTransform)
- func NewLinearTransform(params Parameters, nonZeroDiags []int, level, logSlots int, BSGSRatio float64) LinearTransform
- type Operand
- type PRNGEncryptor
- type Parameters
- func (p Parameters) CopyNew() Parametersdeprecated
- func (p Parameters) DefaultScale() float64
- func (p Parameters) Equals(other Parameters) bool
- func (p Parameters) LogQLvl(level int) int
- func (p Parameters) LogSlots() int
- func (p Parameters) MarshalBinary() ([]byte, error)
- func (p Parameters) MarshalBinarySize() int
- func (p Parameters) MarshalJSON() ([]byte, error)
- func (p Parameters) MaxLevel() int
- func (p Parameters) MaxLogSlots() int
- func (p Parameters) MaxSlots() int
- func (p Parameters) ParametersLiteral() (pLit ParametersLiteral)
- func (p Parameters) QLvl(level int) *big.Int
- func (p Parameters) RotationsForInnerSum(batch, n int) (rotations []int)
- func (p Parameters) RotationsForInnerSumLog(batch, n int) (rotations []int)
- func (p Parameters) RotationsForLinearTransform(nonZeroDiags interface{}, logSlots int, BSGSratio float64) (rotations []int)
- func (p Parameters) RotationsForReplicate(batch, n int) (rotations []int)
- func (p Parameters) RotationsForReplicateLog(batch, n int) (rotations []int)
- func (p Parameters) Slots() int
- func (p Parameters) StandardParameters() (pckks Parameters, err error)
- func (p *Parameters) UnmarshalBinary(data []byte) (err error)
- func (p *Parameters) UnmarshalJSON(data []byte) (err error)
- type ParametersLiteral
- type Plaintext
- type Polynomial
- type PolynomialBasis
- type PrecisionStats
- type Stats
- type SwkComplexToReal
- type SwkRealToComplex
Constants ¶
const ( // Monomial : x^(a+b) = x^a * x^b Monomial = BasisType(0) // Chebyshev : T_(a+b) = 2 * T_a * T_b - T_(|a-b|) Chebyshev = BasisType(1) )
const GaloisGen uint64 = ring.GaloisGen
GaloisGen is an integer of order N/2 modulo M and that spans Z_M with the integer -1. The j-th ring automorphism takes the root zeta to zeta^(5j).
const IsNegligibleThreshold float64 = 1e-14
IsNegligibleThreshold : threshold under which a coefficient of a polynomial is ignored.
Variables ¶
var ( // PN12QP109 is a default parameter set for logN=12 and logQP=109 PN12QP109 = ParametersLiteral{ LogN: 12, Q: []uint64{0x200000e001, 0x100006001}, P: []uint64{0x3ffffea001}, LogSlots: 11, DefaultScale: 1 << 32, } // PN13QP218 is a default parameter set for logN=13 and logQP=218 PN13QP218 = ParametersLiteral{ LogN: 13, Q: []uint64{0x1fffec001, 0x3fff4001, 0x3ffe8001, 0x40020001, 0x40038001, 0x3ffc0001}, P: []uint64{0x800004001}, LogSlots: 12, DefaultScale: 1 << 30, } // PN14QP438 is a default parameter set for logN=14 and logQP=438 PN14QP438 = ParametersLiteral{ LogN: 14, Q: []uint64{0x200000008001, 0x400018001, 0x3fffd0001, 0x400060001, 0x400068001, 0x3fff90001, 0x400080001, 0x4000a8001, 0x400108001, 0x3ffeb8001}, P: []uint64{0x7fffffd8001, 0x7fffffc8001}, LogSlots: 13, DefaultScale: 1 << 34, } // PN15QP880 is a default parameter set for logN=15 and logQP=880 PN15QP880 = ParametersLiteral{ LogN: 15, Q: []uint64{0x4000000120001, 0x10000140001, 0xffffe80001, 0x10000290001, 0xffffc40001, 0x100003e0001, 0x10000470001, 0x100004b0001, 0xffffb20001, 0x10000500001, 0x10000650001, 0xffff940001, 0xffff8a0001, 0xffff820001, 0xffff780001, 0x10000890001, 0xffff750001, 0x10000960001}, P: []uint64{0x40000001b0001, 0x3ffffffdf0001, 0x4000000270001}, LogSlots: 14, DefaultScale: 1 << 40, } // PN16QP1761 is a default parameter set for logN=16 and logQP = 1761 PN16QP1761 = ParametersLiteral{ LogN: 16, Q: []uint64{0x80000000080001, 0x2000000a0001, 0x2000000e0001, 0x1fffffc20001, 0x200000440001, 0x200000500001, 0x200000620001, 0x1fffff980001, 0x2000006a0001, 0x1fffff7e0001, 0x200000860001, 0x200000a60001, 0x200000aa0001, 0x200000b20001, 0x200000c80001, 0x1fffff360001, 0x200000e20001, 0x1fffff060001, 0x200000fe0001, 0x1ffffede0001, 0x1ffffeca0001, 0x1ffffeb40001, 0x200001520001, 0x1ffffe760001, 0x2000019a0001, 0x1ffffe640001, 0x200001a00001, 0x1ffffe520001, 0x200001e80001, 0x1ffffe0c0001, 0x1ffffdee0001, 0x200002480001, 0x1ffffdb60001, 0x200002560001}, P: []uint64{0x80000000440001, 0x7fffffffba0001, 0x80000000500001, 0x7fffffffaa0001}, LogSlots: 15, DefaultScale: 1 << 45, } // PN12QP109CI is a default parameter set for logN=12 and logQP=109 PN12QP109CI = ParametersLiteral{ LogN: 12, Q: []uint64{0x1ffffe0001, 0x100014001}, P: []uint64{0x4000038001}, RingType: ring.ConjugateInvariant, LogSlots: 12, DefaultScale: 1 << 32, } // PN13QP218CI is a default parameter set for logN=13 and logQP=218 PN13QP218CI = ParametersLiteral{ LogN: 13, Q: []uint64{0x200038001, 0x3ffe8001, 0x40020001, 0x40038001, 0x3ffc0001, 0x40080001}, P: []uint64{0x800008001}, RingType: ring.ConjugateInvariant, LogSlots: 13, DefaultScale: 1 << 30, } // PN14QP438CI is a default parameter set for logN=14 and logQP=438 PN14QP438CI = ParametersLiteral{ LogN: 14, Q: []uint64{0x2000000a0001, 0x3fffd0001, 0x400060001, 0x3fff90001, 0x400080001, 0x400180001, 0x3ffd20001, 0x400300001, 0x400360001, 0x4003e0001}, P: []uint64{0x80000050001, 0x7ffffdb0001}, RingType: ring.ConjugateInvariant, LogSlots: 14, DefaultScale: 1 << 34, } // PN15QP880CI is a default parameter set for logN=15 and logQP=880 PN15QP880CI = ParametersLiteral{ LogN: 15, Q: []uint64{0x4000000120001, 0x10000140001, 0xffffe80001, 0xffffc40001, 0x100003e0001, 0xffffb20001, 0x10000500001, 0xffff940001, 0xffff8a0001, 0xffff820001, 0xffff780001, 0x10000960001, 0x10000a40001, 0xffff580001, 0x10000b60001, 0xffff480001, 0xffff420001, 0xffff340001}, P: []uint64{0x3ffffffd20001, 0x4000000420001, 0x3ffffffb80001}, RingType: ring.ConjugateInvariant, LogSlots: 15, DefaultScale: 1 << 40, } // PN16QP1761CI is a default parameter set for logN=16 and logQP = 1761 PN16QP1761CI = ParametersLiteral{ LogN: 16, Q: []uint64{0x80000000080001, 0x200000440001, 0x200000500001, 0x1fffff980001, 0x200000c80001, 0x1ffffeb40001, 0x1ffffe640001, 0x200001a00001, 0x200001e80001, 0x1ffffe0c0001, 0x200002480001, 0x200002800001, 0x1ffffd800001, 0x200002900001, 0x1ffffd700001, 0x2000029c0001, 0x1ffffcf00001, 0x200003140001, 0x1ffffcc80001, 0x1ffffcb40001, 0x1ffffc980001, 0x200003740001, 0x200003800001, 0x200003d40001, 0x1ffffc200001, 0x1ffffc140001, 0x200004100001, 0x200004180001, 0x1ffffbc40001, 0x200004700001, 0x1ffffb900001, 0x200004cc0001, 0x1ffffb240001, 0x200004e80001}, P: []uint64{0x80000000440001, 0x80000000500001, 0x7fffffff380001, 0x80000000e00001}, RingType: ring.ConjugateInvariant, LogSlots: 16, DefaultScale: 1 << 45, } // PN12QP101pq is a default (post quantum) parameter set for logN=12 and logQP=101 PN12QP101pq = ParametersLiteral{ LogN: 12, Q: []uint64{0x800004001, 0x40002001}, P: []uint64{0x1000002001}, LogSlots: 11, DefaultScale: 1 << 30, } // PN13QP202pq is a default (post quantum) parameter set for logN=13 and logQP=202 PN13QP202pq = ParametersLiteral{ LogN: 13, Q: []uint64{0x1fffec001, 0x8008001, 0x8020001, 0x802c001, 0x7fa8001, 0x7f74001}, P: []uint64{0x400018001}, LogSlots: 12, DefaultScale: 1 << 27, } // PN14QP411pq is a default (post quantum) parameter set for logN=14 and logQP=411 PN14QP411pq = ParametersLiteral{ LogN: 14, Q: []uint64{0x10000048001, 0x200038001, 0x1fff90001, 0x200080001, 0x1fff60001, 0x2000b8001, 0x200100001, 0x1fff00001, 0x1ffef0001, 0x200128001}, P: []uint64{0x1ffffe0001, 0x1ffffc0001}, LogSlots: 13, DefaultScale: 1 << 33, } // PN15QP827pq is a default (post quantum) parameter set for logN=15 and logQP=827 PN15QP827pq = ParametersLiteral{ LogN: 15, Q: []uint64{0x400000060001, 0x4000170001, 0x3fffe80001, 0x40002f0001, 0x4000300001, 0x3fffcf0001, 0x40003f0001, 0x3fffc10001, 0x4000450001, 0x3fffb80001, 0x3fffb70001, 0x40004a0001, 0x3fffb20001, 0x4000510001, 0x3fffaf0001, 0x4000540001, 0x4000560001, 0x4000590001}, P: []uint64{0x2000000a0001, 0x2000000e0001, 0x2000001d0001}, LogSlots: 14, DefaultScale: 1 << 38, } // PN16QP1654pq is a default (post quantum) parameter set for logN=16 and logQP=1654 PN16QP1654pq = ParametersLiteral{ LogN: 16, Q: []uint64{0x80000000080001, 0x2000000a0001, 0x2000000e0001, 0x1fffffc20001, 0x200000440001, 0x200000500001, 0x200000620001, 0x1fffff980001, 0x2000006a0001, 0x1fffff7e0001, 0x200000860001, 0x200000a60001, 0x200000aa0001, 0x200000b20001, 0x200000c80001, 0x1fffff360001, 0x200000e20001, 0x1fffff060001, 0x200000fe0001, 0x1ffffede0001, 0x1ffffeca0001, 0x1ffffeb40001, 0x200001520001, 0x1ffffe760001, 0x2000019a0001, 0x1ffffe640001, 0x200001a00001, 0x1ffffe520001, 0x200001e80001, 0x1ffffe0c0001, 0x1ffffdee0001, 0x200002480001}, P: []uint64{0x7fffffffe0001, 0x80000001c0001, 0x80000002c0001, 0x7ffffffd20001}, LogSlots: 15, DefaultScale: 1 << 45, } // PN12QP101pq is a default (post quantum) parameter set for logN=12 and logQP=101 PN12QP101CIpq = ParametersLiteral{ LogN: 12, Q: []uint64{0x800004001, 0x3fff4001}, P: []uint64{0xffffc4001}, RingType: ring.ConjugateInvariant, LogSlots: 12, DefaultScale: 1 << 30, } // PN13QP202CIpq is a default (post quantum) parameter set for logN=13 and logQP=202 PN13QP202CIpq = ParametersLiteral{ LogN: 13, Q: []uint64{0x1ffffe0001, 0x100050001, 0xfff88001, 0x100098001, 0x1000b0001}, P: []uint64{0x1ffffc0001}, RingType: ring.ConjugateInvariant, LogSlots: 13, DefaultScale: 1 << 32, } // PN14QP411CIpq is a default (post quantum) parameter set for logN=14 and logQP=411 PN14QP411CIpq = ParametersLiteral{ LogN: 14, Q: []uint64{0x10000140001, 0x1fff90001, 0x200080001, 0x1fff60001, 0x200100001, 0x1fff00001, 0x1ffef0001, 0x1ffe60001, 0x2001d0001, 0x2002e0001}, P: []uint64{0x1ffffe0001, 0x1ffffc0001}, RingType: ring.ConjugateInvariant, LogSlots: 14, DefaultScale: 1 << 33, } // PN15QP827CIpq is a default (post quantum) parameter set for logN=15 and logQP=827 PN15QP827CIpq = ParametersLiteral{ LogN: 15, Q: []uint64{0x400000060001, 0x3fffe80001, 0x4000300001, 0x3fffb80001, 0x40004a0001, 0x3fffb20001, 0x4000540001, 0x4000560001, 0x3fff900001, 0x4000720001, 0x3fff8e0001, 0x4000800001, 0x40008a0001, 0x3fff6c0001, 0x40009e0001, 0x3fff300001, 0x3fff1c0001, 0x4000fc0001}, P: []uint64{0x2000000a0001, 0x2000000e0001, 0x1fffffc20001}, RingType: ring.ConjugateInvariant, LogSlots: 15, DefaultScale: 1 << 38, } // PN16QP1654CIpq is a default (post quantum) parameter set for logN=16 and logQP=1654 PN16QP1654CIpq = ParametersLiteral{ LogN: 16, Q: []uint64{0x80000000080001, 0x200000440001, 0x200000500001, 0x1fffff980001, 0x200000c80001, 0x1ffffeb40001, 0x1ffffe640001, 0x200001a00001, 0x200001e80001, 0x1ffffe0c0001, 0x200002480001, 0x200002800001, 0x1ffffd800001, 0x200002900001, 0x1ffffd700001, 0x2000029c0001, 0x1ffffcf00001, 0x200003140001, 0x1ffffcc80001, 0x1ffffcb40001, 0x1ffffc980001, 0x200003740001, 0x200003800001, 0x200003d40001, 0x1ffffc200001, 0x1ffffc140001, 0x200004100001, 0x200004180001, 0x1ffffbc40001, 0x200004700001, 0x1ffffb900001, 0x200004cc0001}, P: []uint64{0x80000001c0001, 0x80000002c0001, 0x8000000500001, 0x7ffffff9c0001}, RingType: ring.ConjugateInvariant, LogSlots: 16, DefaultScale: 1 << 45, } )
Name of the different default parameter sets
var DefaultConjugateInvariantParams = []ParametersLiteral{PN12QP109CI, PN13QP218CI, PN14QP438CI, PN15QP880CI, PN16QP1761CI}
DefaultConjugateInvariantParams is a set of default conjugate invariant parameters for encrypting real values and ensuring 128 bit security in a classic setting.
var DefaultParams = []ParametersLiteral{PN12QP109, PN13QP218, PN14QP438, PN15QP880, PN16QP1761}
DefaultParams is a set of default CKKS parameters ensuring 128 bit security in a classic setting.
var DefaultPostQuantumConjugateInvariantParams = []ParametersLiteral{PN12QP101CIpq, PN13QP202CIpq, PN14QP411CIpq, PN15QP827CIpq, PN16QP1654CIpq}
DefaultPostQuantumConjugateInvariantParams is a set of default conjugate invariant parameters for encrypting real values and ensuring 128 bit security in a post-quantum setting.
var DefaultPostQuantumParams = []ParametersLiteral{PN12QP101pq, PN13QP202pq, PN14QP411pq, PN15QP827pq, PN16QP1654pq}
DefaultPostQuantumParams is a set of default CKKS parameters ensuring 128 bit security in a post-quantum setting.
Functions ¶
func BsgsIndex ¶
BsgsIndex returns the index map and needed rotation for the BSGS matrix-vector multiplication algorithm.
func DivideComplex128SliceVec ¶
func DivideComplex128SliceVec(values []complex128, scaleVal complex128)
DivideComplex128SliceVec divides the entries in values by scaleVal in place.
func FindBestBSGSSplit ¶
FindBestBSGSSplit finds the best N1*N2 = N for the baby-step giant-step algorithm for matrix multiplication.
func GenSwitchkeysRescalingParams ¶
GenSwitchkeysRescalingParams generates the parameters for rescaling the switching keys
func NewPublicKey ¶
func NewPublicKey(params Parameters) (pk *rlwe.PublicKey)
NewPublicKey returns an allocated CKKS public with zero values.
func NewRelinearizationKey ¶
func NewRelinearizationKey(params Parameters) *rlwe.RelinearizationKey
NewRelinearizationKey returns an allocated CKKS public relinearization key with zero value.
func NewRotationKeySet ¶
func NewRotationKeySet(params Parameters, galoisElements []uint64) *rlwe.RotationKeySet
NewRotationKeySet returns an allocated set of CKKS public rotation keys with zero values for each galois element (i.e., for each supported rotation).
func NewSecretKey ¶
func NewSecretKey(params Parameters) (sk *rlwe.SecretKey)
NewSecretKey returns an allocated CKKS secret key with zero values.
func NewSwitchingKey ¶
func NewSwitchingKey(params Parameters) *rlwe.SwitchingKey
NewSwitchingKey returns an allocated CKKS public switching key with zero values.
func NttAndMontgomeryLvl ¶
func NttAndMontgomeryLvl(level int, logSlots int, ringQ *ring.Ring, montgomery bool, pol *ring.Poly)
NttAndMontgomeryLvl takes the polynomial polIn Z[Y] outside of the NTT domain to the polynomial Z[X] in the NTT domain where Y = X^(gap). This method is used to accelerate the NTT of polynomials that encode sparse plaintexts.
func SliceBitReverseInPlaceComplex128 ¶
func SliceBitReverseInPlaceComplex128(slice []complex128, N int)
SliceBitReverseInPlaceComplex128 applies an in-place bit-reverse permuation on the input slice.
func SliceBitReverseInPlaceFloat64 ¶
SliceBitReverseInPlaceFloat64 applies an in-place bit-reverse permuation on the input slice.
func SliceBitReverseInPlaceRingComplex ¶
SliceBitReverseInPlaceRingComplex applies an in-place bit-reverse permuation on the input slice.
func SpecialFFTUL8Vec ¶
func SpecialFFTUL8Vec(values []complex128, N, M int, rotGroup []int, roots []complex128)
SpecialFFTUL8Vec performs the CKKS special FFT transform in place with unrolled loops of size 8.
func SpecialFFTVec ¶
func SpecialFFTVec(values []complex128, N, M int, rotGroup []int, roots []complex128)
SpecialFFTVec performs the CKKS special FFT transform in place.
func SpecialiFFTUL8Vec ¶
func SpecialiFFTUL8Vec(values []complex128, N, M int, rotGroup []int, roots []complex128)
SpecialiFFTUL8Vec performs the CKKS special inverse FFT transform in place with unrolled loops of size 8.
func SpecialiFFTVec ¶
func SpecialiFFTVec(values []complex128, N, M int, rotGroup []int, roots []complex128)
SpecialiFFTVec performs the CKKS special inverse FFT transform in place.
func StandardDeviation ¶
StandardDeviation computes the scaled standard deviation of the input vector.
Types ¶
type Ciphertext ¶
type Ciphertext struct { *rlwe.Ciphertext // contains filtered or unexported fields }
Ciphertext is *ring.Poly array representing a polynomial of degree > 0 with coefficients in R_Q.
func NewCiphertext ¶
func NewCiphertext(params Parameters, degree, level int, scale float64) (ciphertext *Ciphertext)
NewCiphertext creates a new Ciphertext parameterized by degree, level and scale.
func NewCiphertextAtLevelFromPoly ¶
func NewCiphertextAtLevelFromPoly(level int, poly [2]*ring.Poly) *Ciphertext
NewCiphertextAtLevelFromPoly construct a new Ciphetext at a specific level where the message is set to the passed poly. No checks are performed on poly and the returned Ciphertext will share its backing array of coefficient.
func NewCiphertextRandom ¶
func NewCiphertextRandom(prng utils.PRNG, params Parameters, degree, level int, scale float64) (ciphertext *Ciphertext)
NewCiphertextRandom generates a new uniformly distributed Ciphertext of degree, level and scale.
func (*Ciphertext) Copy ¶
func (ct *Ciphertext) Copy(ctp *Ciphertext)
Copy copies the given ciphertext ctp into the receiver ciphertext.
func (*Ciphertext) CopyNew ¶
func (ct *Ciphertext) CopyNew() (ctc *Ciphertext)
CopyNew makes a deep copy of the receiver ciphertext and returns it.
func (*Ciphertext) GetDataLen ¶
func (ct *Ciphertext) GetDataLen(WithMetaData bool) (dataLen int)
GetDataLen returns the length in bytes of the target Ciphertext.
func (*Ciphertext) MarshalBinary ¶
func (ct *Ciphertext) MarshalBinary() (data []byte, err error)
MarshalBinary encodes a Ciphertext on a byte slice. The total size in byte is 4 + 8* N * numberModuliQ * (degree + 1).
func (*Ciphertext) Scale ¶
func (ct *Ciphertext) Scale() float64
Scale returns the scaling factor of the ciphertext
func (*Ciphertext) SetScale ¶
func (ct *Ciphertext) SetScale(scale float64)
SetScale sets the scaling factor of the ciphertext
func (*Ciphertext) UnmarshalBinary ¶
func (ct *Ciphertext) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a previously marshaled Ciphertext on the target Ciphertext.
type Decryptor ¶
type Decryptor interface { DecryptNew(ciphertext *Ciphertext) (plaintext *Plaintext) Decrypt(ciphertext *Ciphertext, plaintext *Plaintext) ShallowCopy() Decryptor WithKey(sk *rlwe.SecretKey) Decryptor }
Decryptor is an interface wrapping a rlwe.Decryptor.
func NewDecryptor ¶
func NewDecryptor(params Parameters, sk *rlwe.SecretKey) Decryptor
NewDecryptor instantiates a Decryptor for the CKKS scheme.
type DomainSwitcher ¶
type DomainSwitcher struct { *SwkComplexToReal *SwkRealToComplex // contains filtered or unexported fields }
DomainSwitcher is a type for switching between the standard CKKS domain (which encrypts vectors of complex numbers) and the conjugate invariant variant of CKKS (which encrypts vectors of real numbers).
func NewDomainSwitcher ¶
func NewDomainSwitcher(params Parameters, comlexToRealSwk *SwkComplexToReal, RealToComplexSwk *SwkRealToComplex) (DomainSwitcher, error)
NewDomainSwitcher instantiate a new DomainSwitcher type. It may be instantiated from parameters from either RingType. The method returns an error if the parameters cannot support the switching (e.g., the NTTs are undefined for either of the two ring types).
func (*DomainSwitcher) ComplexToReal ¶
func (switcher *DomainSwitcher) ComplexToReal(eval *rlwe.Evaluator, ctIn, ctOut *Ciphertext)
ComplexToReal switches the provided ciphertext `ctIn` from the standard domain to the conjugate invariant domain and writes the result into `ctOut`. Given ctInCKKS = enc(real(m) + imag(m)) in Z[X](X^N + 1), returns ctOutCI = enc(real(m)) in Z[X+X^-1]/(X^N + 1) in compressed form (N/2 coefficients). The scale of the output ciphertext is twice the scale of the input one. Requires the ring degree of ctOut to be half the ring degree of ctIn. The security is changed from Z[X]/(X^N+1) to Z[X]/(X^N/2+1). The method panics if the DomainSwitcher was not initialized with a SwkComplexToReal key.
func (*DomainSwitcher) RealToComplex ¶
func (switcher *DomainSwitcher) RealToComplex(eval *rlwe.Evaluator, ctIn, ctOut *Ciphertext)
RealToComplex switches the provided ciphertext `ctIn` from the conjugate invariant domain to the standard domain and writes the result into `ctOut`. Given ctInCI = enc(real(m)) in Z[X+X^-1]/(X^2N+1) in compressed form (N coefficients), returns ctOutCKKS = enc(real(m) + imag(0)) in Z[X]/(X^2N+1). Requires the ring degree of ctOut to be twice the ring degree of ctIn. The security is changed from Z[X]/(X^N+1) to Z[X]/(X^2N+1). The method panics if the DomainSwitcher was not initialized with a SwkRealToComplex key.
type Encoder ¶
type Encoder interface { // Slots Encoding Encode(values interface{}, plaintext *Plaintext, logSlots int) EncodeNew(values interface{}, level int, scale float64, logSlots int) (plaintext *Plaintext) EncodeSlots(values interface{}, plaintext *Plaintext, logSlots int) EncodeSlotsNew(values interface{}, level int, scale float64, logSlots int) (plaintext *Plaintext) Decode(plaintext *Plaintext, logSlots int) (res []complex128) DecodeSlots(plaintext *Plaintext, logSlots int) (res []complex128) DecodePublic(plaintext *Plaintext, logSlots int, sigma float64) []complex128 DecodeSlotsPublic(plaintext *Plaintext, logSlots int, sigma float64) []complex128 // Coeffs Encoding EncodeCoeffs(values []float64, plaintext *Plaintext) EncodeCoeffsNew(values []float64, level int, scale float64) (plaintext *Plaintext) DecodeCoeffs(plaintext *Plaintext) (res []float64) DecodeCoeffsPublic(plaintext *Plaintext, bound float64) (res []float64) // Utility Embed(values interface{}, logSlots int, scale float64, montgomery bool, polyOut interface{}) GetErrSTDCoeffDomain(valuesWant, valuesHave []complex128, scale float64) (std float64) GetErrSTDSlotDomain(valuesWant, valuesHave []complex128, scale float64) (std float64) ShallowCopy() Encoder }
Encoder is an interface that implements the encoding and decoding operations. It provides methods to encode/decode []complex128 and []float64 types into/from Plaintext types. Two different encodings are provided:
Coeffs: The coefficients are directly embedded on the plaintext. This encoding only allows to encode []float64 slices, but of size up to N (N being the ring degree) and does not preserve the point-wise multiplication. A ciphertext multiplication will result in a nega- cyclic polynomial convolution in the plaintext domain. This encoding does not provide native slot cyclic rotation. Other operations, like addition or constant multiplication, behave as usual.
Slots: The coefficients are first subjected to a special Fourier transform before being embedded in the plaintext by using Coeffs encoding. This encoding can embed []complex128 and []float64 slices of size at most N/2 (N being the ring degree) and leverages the convolution property of the DFT to preserve point-wise complex multiplication in the plaintext domain, i.e. a ciphertext multiplication will result in an element-wise multiplication in the plaintext domain. It also enables cyclic rotations on plaintext slots. Other operations, like constant multiplication, behave as usual. It is considered the default encoding method for CKKS.
The figure bellow illustrates the relationship between these two encodings:
Real^{N} Z_Q[X]/(X^N+1) EncodeCoeffs: ----------------------------->[]float64 ---------> Plaintext | Complex^{N/2} | EncodeSlots: []complex128/[]float64 -> iDFT ---┘
func NewEncoder ¶
func NewEncoder(params Parameters) Encoder
NewEncoder creates a new Encoder that is used to encode a slice of complex values of size at most N/2 (the number of slots) on a Plaintext.
type EncoderBigComplex ¶
type EncoderBigComplex interface { Encode(values []*ring.Complex, plaintext *Plaintext, logSlots int) EncodeNew(values []*ring.Complex, level int, scale float64, logSlots int) (plaintext *Plaintext) Decode(plaintext *Plaintext, logSlots int) (res []*ring.Complex) DecodePublic(plaintext *Plaintext, logSlots int, sigma float64) (res []*ring.Complex) FFT(values []*ring.Complex, N int) InvFFT(values []*ring.Complex, N int) ShallowCopy() EncoderBigComplex }
EncoderBigComplex is an interface that implements the encoding algorithms with arbitrary precision.
func NewEncoderBigComplex ¶
func NewEncoderBigComplex(params Parameters, logPrecision int) EncoderBigComplex
NewEncoderBigComplex creates a new encoder using arbitrary precision complex arithmetic.
type Encryptor ¶
type Encryptor interface { Encrypt(plaintext *Plaintext, ciphertext *Ciphertext) EncryptNew(plaintext *Plaintext) *Ciphertext EncryptZero(ciphertext *Ciphertext) EncryptZeroNew(level int, scale float64) *Ciphertext ShallowCopy() Encryptor WithKey(key interface{}) Encryptor }
Encryptor an encryption interface for the CKKS scheme.
func NewEncryptor ¶
func NewEncryptor(params Parameters, key interface{}) Encryptor
NewEncryptor instantiates a new Encryptor for the CKKS scheme. The key argument can be *rlwe.PublicKey, *rlwe.SecretKey or nil.
type Evaluator ¶
type Evaluator interface { // Addition Add(ctIn *Ciphertext, op1 Operand, ctOut *Ciphertext) AddNoMod(ctIn *Ciphertext, op1 Operand, ctOut *Ciphertext) AddNew(ctIn *Ciphertext, op1 Operand) (ctOut *Ciphertext) AddNoModNew(ctIn *Ciphertext, op1 Operand) (ctOut *Ciphertext) // Subtraction Sub(ctIn *Ciphertext, op1 Operand, ctOut *Ciphertext) SubNoMod(ctIn *Ciphertext, op1 Operand, ctOut *Ciphertext) SubNew(ctIn *Ciphertext, op1 Operand) (ctOut *Ciphertext) SubNoModNew(ctIn *Ciphertext, op1 Operand) (ctOut *Ciphertext) // Negation Neg(ctIn *Ciphertext, ctOut *Ciphertext) NegNew(ctIn *Ciphertext) (ctOut *Ciphertext) // Constant Addition AddConstNew(ctIn *Ciphertext, constant interface{}) (ctOut *Ciphertext) AddConst(ctIn *Ciphertext, constant interface{}, ctOut *Ciphertext) // Constant Multiplication MultByConstNew(ctIn *Ciphertext, constant interface{}) (ctOut *Ciphertext) MultByConst(ctIn *Ciphertext, constant interface{}, ctOut *Ciphertext) MultByGaussianInteger(ctIn *Ciphertext, cReal, cImag interface{}, ctOut *Ciphertext) // Constant Multiplication with Addition MultByConstAndAdd(ctIn *Ciphertext, constant interface{}, ctOut *Ciphertext) MultByGaussianIntegerAndAdd(ctIn *Ciphertext, cReal, cImag interface{}, ctOut *Ciphertext) // Multiplication by the imaginary unit MultByiNew(ctIn *Ciphertext) (ctOut *Ciphertext) MultByi(ctIn *Ciphertext, ctOut *Ciphertext) DivByiNew(ctIn *Ciphertext) (ctOut *Ciphertext) DivByi(ctIn *Ciphertext, ctOut *Ciphertext) // Conjugation ConjugateNew(ctIn *Ciphertext) (ctOut *Ciphertext) Conjugate(ctIn *Ciphertext, ctOut *Ciphertext) // Multiplication Mul(ctIn *Ciphertext, op1 Operand, ctOut *Ciphertext) MulNew(ctIn *Ciphertext, op1 Operand) (ctOut *Ciphertext) MulRelin(ctIn *Ciphertext, op1 Operand, ctOut *Ciphertext) MulRelinNew(ctIn *Ciphertext, op1 Operand) (ctOut *Ciphertext) MulAndAdd(ctIn *Ciphertext, op1 Operand, ctOut *Ciphertext) MulRelinAndAdd(ctIn *Ciphertext, op1 Operand, ctOut *Ciphertext) // Slot Rotations RotateNew(ctIn *Ciphertext, k int) (ctOut *Ciphertext) Rotate(ctIn *Ciphertext, k int, ctOut *Ciphertext) RotateHoistedNew(ctIn *Ciphertext, rotations []int) (ctOut map[int]*Ciphertext) RotateHoisted(ctIn *Ciphertext, rotations []int, ctOut map[int]*Ciphertext) RotateHoistedNoModDownNew(level int, rotations []int, c0 *ring.Poly, c2DecompQP []ringqp.Poly) (cOut map[int][2]ringqp.Poly) // Multiplication by 2^{s} MulByPow2New(ctIn *Ciphertext, pow2 int) (ctOut *Ciphertext) MulByPow2(ctIn *Ciphertext, pow2 int, ctOut *Ciphertext) // Exponentiation PowerOf2(ctIn *Ciphertext, logPow2 int, ctOut *Ciphertext) Power(ctIn *Ciphertext, degree int, ctOut *Ciphertext) PowerNew(ctIn *Ciphertext, degree int) (ctOut *Ciphertext) // Polynomial evaluation EvaluatePoly(input interface{}, pol *Polynomial, targetScale float64) (ctOut *Ciphertext, err error) EvaluatePolyVector(input interface{}, pols []*Polynomial, encoder Encoder, slotIndex map[int][]int, targetScale float64) (ctOut *Ciphertext, err error) // Inversion InverseNew(ctIn *Ciphertext, steps int) (ctOut *Ciphertext) // Linear Transformations LinearTransformNew(ctIn *Ciphertext, linearTransform interface{}) (ctOut []*Ciphertext) LinearTransform(ctIn *Ciphertext, linearTransform interface{}, ctOut []*Ciphertext) MultiplyByDiagMatrix(ctIn *Ciphertext, matrix LinearTransform, c2DecompQP []ringqp.Poly, ctOut *Ciphertext) MultiplyByDiagMatrixBSGS(ctIn *Ciphertext, matrix LinearTransform, c2DecompQP []ringqp.Poly, ctOut *Ciphertext) // Inner sum InnerSumLog(ctIn *Ciphertext, batch, n int, ctOut *Ciphertext) InnerSum(ctIn *Ciphertext, batch, n int, ctOut *Ciphertext) Average(ctIn *Ciphertext, batch int, ctOut *Ciphertext) // Replication (inverse of Inner sum) ReplicateLog(ctIn *Ciphertext, batch, n int, ctOut *Ciphertext) Replicate(ctIn *Ciphertext, batch, n int, ctOut *Ciphertext) // Trace Trace(ctIn *Ciphertext, logSlots int, ctOut *Ciphertext) TraceNew(ctIn *Ciphertext, logSlots int) (ctOut *Ciphertext) // Key-Switching SwitchKeysNew(ctIn *Ciphertext, switchingKey *rlwe.SwitchingKey) (ctOut *Ciphertext) SwitchKeys(ctIn *Ciphertext, switchingKey *rlwe.SwitchingKey, ctOut *Ciphertext) // Degree Management RelinearizeNew(ctIn *Ciphertext) (ctOut *Ciphertext) Relinearize(ctIn *Ciphertext, ctOut *Ciphertext) // Scale Management ScaleUpNew(ctIn *Ciphertext, scale float64) (ctOut *Ciphertext) ScaleUp(ctIn *Ciphertext, scale float64, ctOut *Ciphertext) SetScale(ctIn *Ciphertext, scale float64) Rescale(ctIn *Ciphertext, minScale float64, ctOut *Ciphertext) (err error) // Level Management DropLevelNew(ctIn *Ciphertext, levels int) (ctOut *Ciphertext) DropLevel(ctIn *Ciphertext, levels int) // Modular Overflow Management ReduceNew(ctIn *Ciphertext) (ctOut *Ciphertext) Reduce(ctIn *Ciphertext, ctOut *Ciphertext) error // ============== // === Others === // ============== GetRLWEEvaluator() *rlwe.Evaluator BuffQ() [3]*ring.Poly BuffCt() *Ciphertext ShallowCopy() Evaluator WithKey(rlwe.EvaluationKey) Evaluator }
Evaluator is an interface implementing the methods to conduct homomorphic operations between ciphertext and/or plaintexts.
func NewEvaluator ¶
func NewEvaluator(params Parameters, evaluationKey rlwe.EvaluationKey) Evaluator
NewEvaluator creates a new Evaluator, that can be used to do homomorphic operations on the Ciphertexts and/or Plaintexts. It stores a memory buffer and Ciphertexts that will be used for intermediate values.
type KeyGenerator ¶
type KeyGenerator interface { rlwe.KeyGenerator GenSwitchingKeysForBridge(skCKKS, skCI *rlwe.SecretKey) (*SwkComplexToReal, *SwkRealToComplex) }
KeyGenerator is an interface for the generation of CKKS keys.
func NewKeyGenerator ¶
func NewKeyGenerator(params Parameters) KeyGenerator
NewKeyGenerator creates a rlwe.KeyGenerator instance from the CKKS parameters.
type LinearTransform ¶
type LinearTransform struct { LogSlots int // Log of the number of slots of the plaintext (needed to compute the appropriate rotation keys) N1 int // N1 is the number of inner loops of the baby-step giant-step algorithm used in the evaluation (if N1 == 0, BSGS is not used). Level int // Level is the level at which the matrix is encoded (can be circuit dependent) Scale float64 // Scale is the scale at which the matrix is encoded (can be circuit dependent) Vec map[int]ringqp.Poly // Vec is the matrix, in diagonal form, where each entry of vec is an indexed non-zero diagonal. }
LinearTransform is a type for linear transformations on ciphertexts. It stores a plaintext matrix diagonalized in diagonal form and can be evaluated on a ciphertext by using the evaluator.LinearTransform method.
func GenLinearTransform ¶
func GenLinearTransform(encoder Encoder, value interface{}, level int, scale float64, logslots int) LinearTransform
GenLinearTransform allocates and encode a new LinearTransform struct from the linear transforms' matrix in diagonal form `value`. values.(type) can be either map[int][]complex128 or map[int][]float64. User must ensure that 1 <= len([]complex128\[]float64) <= 2^logSlots < 2^logN. It can then be evaluated on a ciphertext using evaluator.LinearTransform. Evaluation will use the naive approach (single hoisting and no baby-step giant-step). Faster if there is only a few non-zero diagonals but uses more keys.
func GenLinearTransformBSGS ¶
func GenLinearTransformBSGS(encoder Encoder, value interface{}, level int, scale, BSGSRatio float64, logSlots int) (LT LinearTransform)
GenLinearTransformBSGS allocates and encodes a new LinearTransform struct from the linear transforms' matrix in diagonal form `value` for evaluation with a baby-step giant-step approach. values.(type) can be either map[int][]complex128 or map[int][]float64. User must ensure that 1 <= len([]complex128\[]float64) <= 2^logSlots < 2^logN. LinearTransform types can be be evaluated on a ciphertext using evaluator.LinearTransform. Evaluation will use the optimized approach (double hoisting and baby-step giant-step). Faster if there is more than a few non-zero diagonals. BSGSRatio is the maximum ratio between the inner and outer loop of the baby-step giant-step algorithm used in evaluator.LinearTransform. Optimal BSGSRatio value is between 4 and 16 depending on the sparsity of the matrix.
func NewLinearTransform ¶
func NewLinearTransform(params Parameters, nonZeroDiags []int, level, logSlots int, BSGSRatio float64) LinearTransform
NewLinearTransform allocates a new LinearTransform with zero plaintexts at the specified level. If BSGSRatio == 0, the LinearTransform is set to not use the BSGS approach. Method will panic if BSGSRatio < 0.
func (*LinearTransform) Encode ¶
func (LT *LinearTransform) Encode(encoder Encoder, value interface{}, scale float64)
Encode encodes on a pre-allocated LinearTransform the linear transforms' matrix in diagonal form `value`. values.(type) can be either map[int][]complex128 or map[int][]float64. User must ensure that 1 <= len([]complex128\[]float64) <= 2^logSlots < 2^logN. It can then be evaluated on a ciphertext using evaluator.LinearTransform. Evaluation will use the naive approach (single hoisting and no baby-step giant-step). Faster if there is only a few non-zero diagonals but uses more keys.
func (*LinearTransform) Rotations ¶
func (LT *LinearTransform) Rotations() (rotations []int)
Rotations returns the list of rotations needed for the evaluation of the linear transform.
type Operand ¶
type Operand interface { El() *rlwe.Ciphertext Degree() int Level() int Scale() float64 SetScale(float64) }
Operand is a common interface for Ciphertext and Plaintext types.
type PRNGEncryptor ¶
type PRNGEncryptor interface { Encryptor WithPRNG(prng utils.PRNG) PRNGEncryptor }
PRNGEncryptor is an interface for encrypting BFV ciphertexts from a secret-key and a pre-determined PRNG. An Encryptor constructed from a secret-key complies to this interface.
func NewPRNGEncryptor ¶
func NewPRNGEncryptor(params Parameters, key *rlwe.SecretKey) PRNGEncryptor
NewPRNGEncryptor creates a new PRNGEncryptor instance that encrypts BFV ciphertexts from a secret-key and a PRNG.
type Parameters ¶
type Parameters struct { rlwe.Parameters // contains filtered or unexported fields }
Parameters represents a parameter set for the CKKS cryptosystem. Its fields are private and immutable. See ParametersLiteral for user-specified parameters.
func NewParameters ¶
func NewParameters(rlweParams rlwe.Parameters, logSlots int, defaultScale float64) (p Parameters, err error)
NewParameters instantiate a set of CKKS parameters from the generic RLWE parameters and the CKKS-specific ones. It returns the empty parameters Parameters{} and a non-nil error if the specified parameters are invalid.
func NewParametersFromLiteral ¶
func NewParametersFromLiteral(pl ParametersLiteral) (Parameters, error)
NewParametersFromLiteral instantiate a set of CKKS parameters from a ParametersLiteral specification. It returns the empty parameters Parameters{} and a non-nil error if the specified parameters are invalid.
If the `LogSlots` field is left unset, its value is set to `LogN-1` for the Standard ring and to `LogN` for the conjugate-invariant ring.
See `rlwe.NewParametersFromLiteral` for default values of the other optional fields.
func (Parameters) CopyNew
deprecated
func (p Parameters) CopyNew() Parameters
CopyNew makes a deep copy of the receiver and returns it.
Deprecated: Parameter is now a read-only struct, except for the UnmarshalBinary method: deep copying should only be required to save a Parameter struct before calling its UnmarshalBinary method and it will be deprecated when transitioning to a immutable serialization interface.
func (Parameters) DefaultScale ¶
func (p Parameters) DefaultScale() float64
DefaultScale returns the default plaintext/ciphertext scale
func (Parameters) Equals ¶
func (p Parameters) Equals(other Parameters) bool
Equals compares two sets of parameters for equality.
func (Parameters) LogQLvl ¶
func (p Parameters) LogQLvl(level int) int
LogQLvl returns the size of the modulus Q in bits at a specific level
func (Parameters) LogSlots ¶
func (p Parameters) LogSlots() int
LogSlots returns the log of the number of slots
func (Parameters) MarshalBinary ¶
func (p Parameters) MarshalBinary() ([]byte, error)
MarshalBinary returns a []byte representation of the parameter set.
func (Parameters) MarshalBinarySize ¶
func (p Parameters) MarshalBinarySize() int
MarshalBinarySize returns the length of the []byte encoding of the receiver.
func (Parameters) MarshalJSON ¶
func (p Parameters) MarshalJSON() ([]byte, error)
MarshalJSON returns a JSON representation of this parameter set. See `Marshal` from the `encoding/json` package.
func (Parameters) MaxLevel ¶
func (p Parameters) MaxLevel() int
MaxLevel returns the maximum ciphertext level
func (Parameters) MaxLogSlots ¶
func (p Parameters) MaxLogSlots() int
MaxLogSlots returns the log of the maximum number of slots enabled by the parameters
func (Parameters) MaxSlots ¶
func (p Parameters) MaxSlots() int
MaxSlots returns the theoretical maximum of plaintext slots allowed by the ring degree
func (Parameters) ParametersLiteral ¶
func (p Parameters) ParametersLiteral() (pLit ParametersLiteral)
ParametersLiteral returns the ParametersLiteral of the target Parameters.
func (Parameters) QLvl ¶
func (p Parameters) QLvl(level int) *big.Int
QLvl returns the product of the moduli at the given level as a big.Int
func (Parameters) RotationsForInnerSum ¶
func (p Parameters) RotationsForInnerSum(batch, n int) (rotations []int)
RotationsForInnerSum generates the rotations that will be performed by the `Evaluator.InnerSum` operation when performed with parameters `batch` and `n`.
func (Parameters) RotationsForInnerSumLog ¶
func (p Parameters) RotationsForInnerSumLog(batch, n int) (rotations []int)
RotationsForInnerSumLog generates the rotations that will be performed by the `Evaluator.InnerSumLog` operation when performed with parameters `batch` and `n`.
func (Parameters) RotationsForLinearTransform ¶
func (p Parameters) RotationsForLinearTransform(nonZeroDiags interface{}, logSlots int, BSGSratio float64) (rotations []int)
RotationsForLinearTransform generates the list of rotations needed for the evaluation of a linear transform with the provided list of non-zero diagonals, logSlots encoding and BSGSratio. If BSGSratio == 0, then provides the rotations needed for an evaluation without the BSGS approach.
func (Parameters) RotationsForReplicate ¶
func (p Parameters) RotationsForReplicate(batch, n int) (rotations []int)
RotationsForReplicate generates the rotations that will be performed by the `Evaluator.Replicate` operation when performed with parameters `batch` and `n`.
func (Parameters) RotationsForReplicateLog ¶
func (p Parameters) RotationsForReplicateLog(batch, n int) (rotations []int)
RotationsForReplicateLog generates the rotations that will be performed by the `Evaluator.ReplicateLog` operation when performed with parameters `batch` and `n`.
func (Parameters) Slots ¶
func (p Parameters) Slots() int
Slots returns number of available plaintext slots
func (Parameters) StandardParameters ¶
func (p Parameters) StandardParameters() (pckks Parameters, err error)
StandardParameters returns the CKKS parameters corresponding to the receiver parameter set. If the receiver is already a standard parameter set (i.e., RingType==Standard), then the method returns the receiver.
func (*Parameters) UnmarshalBinary ¶
func (p *Parameters) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a []byte into a parameter set struct
func (*Parameters) UnmarshalJSON ¶
func (p *Parameters) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON reads a JSON representation of a parameter set into the receiver Parameter. See `Unmarshal` from the `encoding/json` package.
type ParametersLiteral ¶
type ParametersLiteral struct { LogN int Q []uint64 P []uint64 LogQ []int `json:",omitempty"` LogP []int `json:",omitempty"` Pow2Base int Sigma float64 H int RingType ring.Type LogSlots int DefaultScale float64 }
ParametersLiteral is a literal representation of BFV parameters. It has public fields and is used to express unchecked user-defined parameters literally into Go programs. The NewParametersFromLiteral function is used to generate the actual checked parameters from the literal representation.
Users must set the polynomial degree (in log_2, LogN) and the coefficient modulus, by either setting the Q and P fields to the desired moduli chain, or by setting the LogQ and LogP fields to the desired moduli sizes (in log_2). Users must also specify a default initial scale for the plaintexts.
Optionally, users may specify the error variance (Sigma), the secrets' density (H), the ring type (RingType) and the number of slots (in log_2, LogSlots). If left unset, standard default values for these field are substituted at parameter creation (see NewParametersFromLiteral).
func (ParametersLiteral) RLWEParameters ¶
func (p ParametersLiteral) RLWEParameters() rlwe.ParametersLiteral
RLWEParameters returns the rlwe.ParametersLiteral from the target ckks.ParameterLiteral.
type Plaintext ¶
Plaintext is is a Element with only one Poly.
func NewPlaintext ¶
func NewPlaintext(params Parameters, level int, scale float64) *Plaintext
NewPlaintext creates a new Plaintext of level level and scale scale.
func NewPlaintextAtLevelFromPoly ¶
NewPlaintextAtLevelFromPoly construct a new Plaintext at a specific level where the message is set to the passed poly. No checks are performed on poly and the returned Plaintext will share its backing array of coefficient.
type Polynomial ¶
Polynomial is a struct storing the coefficients of a polynomial that then can be evaluated on the ciphertext
func Approximate ¶
func Approximate(function interface{}, a, b float64, degree int) (pol *Polynomial)
Approximate computes a Chebyshev approximation of the input function, for the range [-a, b] of degree degree. function.(type) can be either func(complex128)complex128 or func(float64)float64 To be used in conjunction with the function EvaluateCheby.
func NewPoly ¶
func NewPoly(coeffs []complex128) (p *Polynomial)
NewPoly creates a new Poly from the input coefficients
func (*Polynomial) Degree ¶
func (p *Polynomial) Degree() int
Degree returns the degree of the polynomial
func (*Polynomial) Depth ¶
func (p *Polynomial) Depth() int
Depth returns the number of levels needed to evaluate the polynomial.
type PolynomialBasis ¶
type PolynomialBasis struct { BasisType Value map[int]*Ciphertext }
PolynomialBasis is a struct storing powers of a ciphertext.
func NewPolynomialBasis ¶
func NewPolynomialBasis(ct *Ciphertext, basistype BasisType) (p *PolynomialBasis)
NewPolynomialBasis creates a new PolynomialBasis. It takes as input a ciphertext and a basistype. The struct treats the input ciphertext as a monomial X and can be used to generates power of this monomial X^{n} in the given BasisType.
func (*PolynomialBasis) GenPower ¶
GenPower recursively computes X^{n}. If lazy = true, the final X^{n} will not be relinearized. Previous non-relinearized X^{n} that are required to compute the target X^{n} are automatically relinearized. Scale sets the threshold for rescaling (ciphertext won't be rescaled if the rescaling operation would make the scale go under this threshold).
func (*PolynomialBasis) MarshalBinary ¶
func (p *PolynomialBasis) MarshalBinary() (data []byte, err error)
MarshalBinary encodes the target on a slice of bytes.
func (*PolynomialBasis) UnmarshalBinary ¶
func (p *PolynomialBasis) UnmarshalBinary(data []byte) (err error)
UnmarshalBinary decodes a slice of bytes on the target.
type PrecisionStats ¶
type PrecisionStats struct { MaxDelta Stats MinDelta Stats MaxPrecision Stats MinPrecision Stats MeanDelta Stats MeanPrecision Stats MedianDelta Stats MedianPrecision Stats STDFreq float64 STDTime float64 RealDist, ImagDist, L2Dist []struct { Prec float64 Count int } // contains filtered or unexported fields }
PrecisionStats is a struct storing statistic about the precision of a CKKS plaintext
func GetPrecisionStats ¶
func GetPrecisionStats(params Parameters, encoder Encoder, decryptor Decryptor, vWant, element interface{}, logSlots int, sigma float64) (prec PrecisionStats)
GetPrecisionStats generates a PrecisionStats struct from the reference values and the decrypted values vWant.(type) must be either []complex128 or []float64 element.(type) must be either *Plaintext, *Ciphertext, []complex128 or []float64. If not *Ciphertext, then decryptor can be nil.
func (PrecisionStats) String ¶
func (prec PrecisionStats) String() string
type Stats ¶
type Stats struct {
Real, Imag, L2 float64
}
Stats is a struct storing the real, imaginary and L2 norm (modulus) about the precision of a complex value.
type SwkComplexToReal ¶
type SwkComplexToReal struct {
rlwe.SwitchingKey
}
SwkComplexToReal is a SwitchingKey to switch from the standard domain to the conjugate invariant domain.
type SwkRealToComplex ¶
type SwkRealToComplex struct {
rlwe.SwitchingKey
}
SwkRealToComplex is a SwitchingKey to switch from the conjugate invariant domain to the standard domain.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package advanced implements advanced operations for the CKKS scheme.
|
Package advanced implements advanced operations for the CKKS scheme. |
Package bootstrapping implement the bootstrapping for the CKKS scheme.
|
Package bootstrapping implement the bootstrapping for the CKKS scheme. |