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 GetRootsFloat64(NthRoot int) (roots []complex128)
- func GetRootsbigFloat(NthRoot int, prec uint) (roots []*ring.Complex)
- func NewCiphertext(params Parameters, degree, level int) (ct *rlwe.Ciphertext)
- func NewDecryptor(params Parameters, key *rlwe.SecretKey) rlwe.Decryptor
- func NewEncryptor(params Parameters, key interface{}) rlwe.Encryptor
- func NewKeyGenerator(params Parameters) rlwe.KeyGenerator
- func NewPRNGEncryptor(params Parameters, key *rlwe.SecretKey) rlwe.PRNGEncryptor
- func NewPlaintext(params Parameters, level int) (pt *rlwe.Plaintext)
- 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 DomainSwitcher
- type Encoder
- type EncoderBigComplex
- type Evaluator
- type LinearTransform
- func GenLinearTransform(encoder Encoder, value interface{}, level int, scale rlwe.Scale, logslots int) LinearTransform
- func GenLinearTransformBSGS(encoder Encoder, value interface{}, level int, scale rlwe.Scale, ...) (LT LinearTransform)
- func NewLinearTransform(params Parameters, nonZeroDiags []int, level, logSlots int, BSGSRatio float64) LinearTransform
- type Parameters
- 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) RotationsForLinearTransform(nonZeroDiags interface{}, logSlots int, BSGSratio float64) (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 Polynomial
- type PolynomialBasis
- type PrecisionStats
- type Stats
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 (
DefaultNTTFlag = true
)
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 GetRootsFloat64 ¶
func GetRootsFloat64(NthRoot int) (roots []complex128)
GetRootsFloat64 returns the roots e^{2*pi*i/m *j} for 0 <= j <= NthRoot.
func GetRootsbigFloat ¶
GetRootsbigFloat returns the roots e^{2*pi*i/m *j} for 0 <= j <= NthRoot with prec bits of precision.
func NewCiphertext ¶
func NewCiphertext(params Parameters, degree, level int) (ct *rlwe.Ciphertext)
func NewDecryptor ¶
func NewDecryptor(params Parameters, key *rlwe.SecretKey) rlwe.Decryptor
func NewEncryptor ¶
func NewEncryptor(params Parameters, key interface{}) rlwe.Encryptor
func NewKeyGenerator ¶
func NewKeyGenerator(params Parameters) rlwe.KeyGenerator
func NewPRNGEncryptor ¶
func NewPRNGEncryptor(params Parameters, key *rlwe.SecretKey) rlwe.PRNGEncryptor
func NewPlaintext ¶
func NewPlaintext(params Parameters, level int) (pt *rlwe.Plaintext)
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 DomainSwitcher ¶
type DomainSwitcher struct {
// 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, RealToComplexSwk *rlwe.SwitchingKey) (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 Evaluator, ctIn, ctOut *rlwe.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 Evaluator, ctIn, ctOut *rlwe.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 *rlwe.Plaintext, logSlots int) EncodeNew(values interface{}, level int, scale rlwe.Scale, logSlots int) (plaintext *rlwe.Plaintext) EncodeSlots(values interface{}, plaintext *rlwe.Plaintext, logSlots int) EncodeSlotsNew(values interface{}, level int, scale rlwe.Scale, logSlots int) (plaintext *rlwe.Plaintext) Decode(plaintext *rlwe.Plaintext, logSlots int) (res []complex128) DecodeSlots(plaintext *rlwe.Plaintext, logSlots int) (res []complex128) DecodePublic(plaintext *rlwe.Plaintext, logSlots int, sigma float64) []complex128 DecodeSlotsPublic(plaintext *rlwe.Plaintext, logSlots int, sigma float64) []complex128 // Coeffs Encoding EncodeCoeffs(values []float64, plaintext *rlwe.Plaintext) EncodeCoeffsNew(values []float64, level int, scale rlwe.Scale) (plaintext *rlwe.Plaintext) DecodeCoeffs(plaintext *rlwe.Plaintext) (res []float64) DecodeCoeffsPublic(plaintext *rlwe.Plaintext, bound float64) (res []float64) // Utility Embed(values interface{}, logSlots int, scale rlwe.Scale, montgomery bool, polyOut interface{}) GetErrSTDCoeffDomain(valuesWant, valuesHave []complex128, scale rlwe.Scale) (std float64) GetErrSTDSlotDomain(valuesWant, valuesHave []complex128, scale rlwe.Scale) (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 *rlwe.Plaintext, logSlots int) EncodeNew(values []*ring.Complex, level int, scale rlwe.Scale, logSlots int) (plaintext *rlwe.Plaintext) Decode(plaintext *rlwe.Plaintext, logSlots int) (res []*ring.Complex) DecodePublic(plaintext *rlwe.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, prec uint) EncoderBigComplex
NewEncoderBigComplex creates a new encoder using arbitrary precision complex arithmetic.
type Evaluator ¶
type Evaluator interface { // Addition Add(ctIn *rlwe.Ciphertext, op1 rlwe.Operand, ctOut *rlwe.Ciphertext) AddNew(ctIn *rlwe.Ciphertext, op1 rlwe.Operand) (ctOut *rlwe.Ciphertext) // Subtraction Sub(ctIn *rlwe.Ciphertext, op1 rlwe.Operand, ctOut *rlwe.Ciphertext) SubNew(ctIn *rlwe.Ciphertext, op1 rlwe.Operand) (ctOut *rlwe.Ciphertext) // Negation Neg(ctIn *rlwe.Ciphertext, ctOut *rlwe.Ciphertext) NegNew(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext) // Constant Addition AddConstNew(ctIn *rlwe.Ciphertext, constant interface{}) (ctOut *rlwe.Ciphertext) AddConst(ctIn *rlwe.Ciphertext, constant interface{}, ctOut *rlwe.Ciphertext) // Constant Multiplication MultByConstNew(ctIn *rlwe.Ciphertext, constant interface{}) (ctOut *rlwe.Ciphertext) MultByConst(ctIn *rlwe.Ciphertext, constant interface{}, ctOut *rlwe.Ciphertext) MultByGaussianInteger(ctIn *rlwe.Ciphertext, cReal, cImag interface{}, ctOut *rlwe.Ciphertext) // Constant Multiplication with Addition MultByConstAndAdd(ctIn *rlwe.Ciphertext, constant interface{}, ctOut *rlwe.Ciphertext) MultByGaussianIntegerAndAdd(ctIn *rlwe.Ciphertext, cReal, cImag interface{}, ctOut *rlwe.Ciphertext) // Multiplication by the imaginary unit MultByiNew(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext) MultByi(ctIn *rlwe.Ciphertext, ctOut *rlwe.Ciphertext) DivByiNew(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext) DivByi(ctIn *rlwe.Ciphertext, ctOut *rlwe.Ciphertext) // Conjugation ConjugateNew(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext) Conjugate(ctIn *rlwe.Ciphertext, ctOut *rlwe.Ciphertext) // Multiplication Mul(ctIn *rlwe.Ciphertext, op1 rlwe.Operand, ctOut *rlwe.Ciphertext) MulNew(ctIn *rlwe.Ciphertext, op1 rlwe.Operand) (ctOut *rlwe.Ciphertext) MulRelin(ctIn *rlwe.Ciphertext, op1 rlwe.Operand, ctOut *rlwe.Ciphertext) MulRelinNew(ctIn *rlwe.Ciphertext, op1 rlwe.Operand) (ctOut *rlwe.Ciphertext) MulAndAdd(ctIn *rlwe.Ciphertext, op1 rlwe.Operand, ctOut *rlwe.Ciphertext) MulRelinAndAdd(ctIn *rlwe.Ciphertext, op1 rlwe.Operand, ctOut *rlwe.Ciphertext) // Slot Rotations RotateNew(ctIn *rlwe.Ciphertext, k int) (ctOut *rlwe.Ciphertext) Rotate(ctIn *rlwe.Ciphertext, k int, ctOut *rlwe.Ciphertext) RotateHoistedNew(ctIn *rlwe.Ciphertext, rotations []int) (ctOut map[int]*rlwe.Ciphertext) RotateHoisted(ctIn *rlwe.Ciphertext, rotations []int, ctOut map[int]*rlwe.Ciphertext) RotateHoistedNoModDownNew(level int, rotations []int, c0 *ring.Poly, c2DecompQP []ringqp.Poly) (cOut map[int]rlwe.CiphertextQP) // Polynomial evaluation EvaluatePoly(input interface{}, pol *Polynomial, targetScale rlwe.Scale) (ctOut *rlwe.Ciphertext, err error) EvaluatePolyVector(input interface{}, pols []*Polynomial, encoder Encoder, slotIndex map[int][]int, targetScale rlwe.Scale) (ctOut *rlwe.Ciphertext, err error) // Inversion InverseNew(ctIn *rlwe.Ciphertext, steps int) (ctOut *rlwe.Ciphertext, err error) // Linear Transformations LinearTransformNew(ctIn *rlwe.Ciphertext, linearTransform interface{}) (ctOut []*rlwe.Ciphertext) LinearTransform(ctIn *rlwe.Ciphertext, linearTransform interface{}, ctOut []*rlwe.Ciphertext) MultiplyByDiagMatrix(ctIn *rlwe.Ciphertext, matrix LinearTransform, c2DecompQP []ringqp.Poly, ctOut *rlwe.Ciphertext) MultiplyByDiagMatrixBSGS(ctIn *rlwe.Ciphertext, matrix LinearTransform, c2DecompQP []ringqp.Poly, ctOut *rlwe.Ciphertext) // Inner sum InnerSum(ctIn *rlwe.Ciphertext, batch, n int, ctOut *rlwe.Ciphertext) Average(ctIn *rlwe.Ciphertext, batch int, ctOut *rlwe.Ciphertext) // Replication (inverse of Inner sum) Replicate(ctIn *rlwe.Ciphertext, batch, n int, ctOut *rlwe.Ciphertext) // Trace Trace(ctIn *rlwe.Ciphertext, logSlots int, ctOut *rlwe.Ciphertext) TraceNew(ctIn *rlwe.Ciphertext, logSlots int) (ctOut *rlwe.Ciphertext) // Key-Switching SwitchKeysNew(ctIn *rlwe.Ciphertext, switchingKey *rlwe.SwitchingKey) (ctOut *rlwe.Ciphertext) SwitchKeys(ctIn *rlwe.Ciphertext, switchingKey *rlwe.SwitchingKey, ctOut *rlwe.Ciphertext) // Degree Management RelinearizeNew(ctIn *rlwe.Ciphertext) (ctOut *rlwe.Ciphertext) Relinearize(ctIn *rlwe.Ciphertext, ctOut *rlwe.Ciphertext) // Scale Management ScaleUpNew(ctIn *rlwe.Ciphertext, scale rlwe.Scale) (ctOut *rlwe.Ciphertext) ScaleUp(ctIn *rlwe.Ciphertext, scale rlwe.Scale, ctOut *rlwe.Ciphertext) SetScale(ctIn *rlwe.Ciphertext, scale rlwe.Scale) Rescale(ctIn *rlwe.Ciphertext, minScale rlwe.Scale, ctOut *rlwe.Ciphertext) (err error) // Level Management DropLevelNew(ctIn *rlwe.Ciphertext, levels int) (ctOut *rlwe.Ciphertext) DropLevel(ctIn *rlwe.Ciphertext, levels int) // ============== // === Others === // ============== GetRLWEEvaluator() *rlwe.Evaluator BuffQ() [3]*ring.Poly BuffCt() *rlwe.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 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 rlwe.Scale // 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 rlwe.Scale, 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 rlwe.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 rlwe.Scale)
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 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) (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) 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) 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) 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 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]*rlwe.Ciphertext }
PolynomialBasis is a struct storing powers of a ciphertext.
func NewPolynomialBasis ¶
func NewPolynomialBasis(ct *rlwe.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 rlwe.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
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. |