ckks

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

CKKS

The package CKKS is an RNS-accelerated version of the Homomorphic Encryption for Arithmetic of Approximate Numbers (HEAAN, a.k.a. CKKS) scheme originally proposed by Cheon, Kim, Kim and Song. It provides approximate arithmetic over complex numbers.

Brief description

This scheme can be used to do arithmetic over equation. The plaintext space and the ciphertext space share the same domain

,

with a power of 2.

The batch encoding of this scheme

.

maps an array of complex numbers to a polynomial with the property:

,

where represents a component-wise product, and represents a nega-cyclic convolution.

Security parameters

equation: the ring dimension, which defines the degree of the cyclotomic polynomial, and the number of coefficients of the plaintext/ciphertext polynomials; it should always be a power of two. This parameter has an impact on both security and performance (security increases with N and performance decreases with N). It should be chosen carefully to suit the intended use of the scheme.

equation: the ciphertext modulus. In Lattigo, it is chosen to be the product of a chain of small coprime moduli equation verifying equation in order to enable both the RNS and NTT representation. The used moduli equation are chosen to be of size 30 to 60 bits for the best performance. This parameter has an impact on both security and performance (for a fixed equation, a higher equation implies both lower security and lower performance). It is closely related to equation and should be chosen carefully to suit the intended use of the scheme.

equation: the variance used for the error polynomials. This parameter is closely tied to the security of the scheme (a higher equation implies higher security).

Other parameters

equation: the plaintext scale. Since complex numbers are encoded on polynomials with integer coefficients, the original values must be scaled during the encoding, before being rounded to the nearest integer. The equation parameter is the power of two by which the values are multiplied during the encoding. It has an impact on the precision of the output and on the amount of operations a fresh encyrption can undergo before overflowing.

Choosing the right parameters for a given application

There are 3 application-dependent parameters:

  • LogN: it determines (a) how many values can be encoded (batched) at once (maximum N/2) in one plaintext, and (b) the maximum total modulus bit size (the product of all the moduli) for a given security parameter.
  • Modulichain: it determines how many consecutive scalar and non-scalar multiplications (the depth of the arithmetic circuit) can be evaluated before requiring decryption. Since Lattigo features an RNS implementation, this parameter requires careful fine-tuning depending on the application; i.e., the rescaling procedure can only rescale by one of the RNS modulus at a time, whose size has to be chosen when creating the ckkscontext. Additionally, the individual size of each of the moduli also has an effect on the error introduced during the rescaling, since they cannot be powers of 2, so they should be chosen as NTT primes as close as possible to a power of 2 instead.
  • Logscale: it determines the scale of the plaintext, affecting both the precision and the maximum allowed depth for a given security parameter.

Configuring parameters for CKKS is very application dependent, requiring a prior analysis of the circuit to be executed under encryption. The following example illustrates how this parametrization can be done, showing that it is possible to come up with different parameter sets for a given circuit, each set having pros and cons.

Let us define the evaluation of an arbitrary smooth function f(x) on an array of ~4000 complex elements contained in a square of side 2 centered at the complex origin (with values ranging between -1-1i and 1+1i). We first need to find a good polynomial approximation for the given range. Lattigo provides an automatic Chebyshev approximation for any given polynomial degree, which can be used for this purpose (it is also possible to define a different polynomial approximation of lower degree with an acceptable error).

Let us assume that we find an approximation of degree 5, i.e., a + bx + cx^3 + dx^5. This function can be evaluated with 3 scalar multiplications, 3 additions and 3 non-scalar multiplications, consuming a total of 4 levels (one for the scalar multiplications and 3 for the non-scalar multiplications).

We then need to chose a scale for the plaintext, that will influence both the bit consumption for the rescaling, and the precision of the computation. If we choose a scale of 2^40, we need to consume at least 160 bits (4 levels) during the evaluation, and we still need some bits left to store the final result with an acceptable precision. Let us assume that the output of the approximation lies always in the square between -20-20i and 20+20i; then, the final modulus must be at least 5 bits larger than the final scale (to preserve the integer precision).

The following parameters will work for the posed example:

  • LogN = 13
  • Modulichain = [45, 40, 40, 40, 40], for a logQ <= 205
  • LogScale = 40

But it is also possible to use less levels to have ciphertexts of smaller size and, therefore, a faster evaluation, at the expense of less precision. This can be achieved by using a scale of 30 bits and squeezing two multiplications in a single level, while pre-computing the last scalar multiplication already in the plaintext. Instead of evaluating a + bx + cx^3 + dx^5, we pre-multply the plaintext by d^(1/5) and evaluate a + b/(d^(1/5))x + c/(d^(3/5)) + x^5.

The following parameters are enough to evaluate this modified function:

  • LogN = 13
  • Modulichain = [35, 60, 60], for a logQ <= 155
  • LogScale = 30

To summarize, several parameter sets can be used to evaluate a given function, achieving different trade-offs for space and time versus precision.

Choosing secure parameters

The CKKS scheme supports the standard recommended parameters chosen to offer a security of 128 bits for a secret key with uniform ternary distribution equation, according to the Homomorphic Encryption Standards group (https://homomorphicencryption.org/standard/).

Each set of security parameters is defined by the tuple equation :

  • {11, 54, 3.2}
  • {12, 109, 3.2}
  • {13, 218, 3.2}
  • {14, 438, 3.2}
  • {15, 881, 3.2}

As mentioned, setting parameters for CKKS involves not only choosing this tuple, but also defining the actual moduli chain depending on the application at hand, which is why the provided default parameter sets have to be fine-tuned, preserving the values of the aforementioned tuples, in order to maintain the required security level of 128 bits. That is, Lattigo provides a set of default parameters for CKKS, including example moduli chains, ensuring 128 bit security. The user might want to choose different values in the moduli chain optimized for a specific application. As long as the total modulus is equal or below the above values for a given logN, the scheme will still provide a security of at least 128 bits against the current best known attacks.

Finally, it is worth noting that these security parameters are computed for fully entropic ternary keys (with probability distribution {1/3,1/3,1/3} for values {-1,0,1}). Lattigo uses this fully-entropic key configuration by default. It is possible, though, to generate keys with lower entropy, by modifying their distribution to {(1-p)/2, p, (1-p)/2}, for any p between 0 and 1, which for p>>1/3 can result in low Hamming weight keys (sparse keys). We recall that it has been shown that the security of sparse keys can be considerably lower than that of fully entropic keys, and the CKKS security parameters should be re-evaluated if sparse keys are used.

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.

Index

Constants

View Source
const (
	RotationRight = iota + 1
	RotationLeft
	Conjugate
)

Constants for rotation types

View Source
const (
	PN12QP109 = iota
	PN13QP218
	PN14QP438
	PN15QP880
	PN16QP1761
)
View Source
const GaloisGen uint64 = 5

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). Any other integer or order N/2 modulo M and congruent with 1 modulo 4 could be used instead.

View Source
const MaxLogN = 16

MaxLogN is the log2 of the largest supported polynomial modulus degree.

View Source
const MaxModuliCount = 34

MaxModuliCount is the largest supported number of moduli in the RNS representation.

View Source
const MaxModuliSize = 60

MaxModuliSize is the largest bit-length supported for the moduli in the RNS representation.

Variables

View Source
var DefaultParams = []*Parameters{

	{LogN: 12,
		LogSlots: 11,
		LogModuli: LogModuli{
			LogQi: []uint64{37, 32},
			LogPi: []uint64{38},
		},
		Scale: 1 << 32,
		Sigma: 3.2},

	{LogN: 13,
		LogSlots: 12,
		LogModuli: LogModuli{
			LogQi: []uint64{33, 30, 30, 30, 30, 30},
			LogPi: []uint64{35},
		},
		Scale: 1 << 30,
		Sigma: 3.2},

	{LogN: 14,
		LogSlots: 13,
		LogModuli: LogModuli{
			LogQi: []uint64{45, 34, 34, 34, 34, 34, 34, 34, 34, 34},
			LogPi: []uint64{43, 43},
		},
		Scale: 1 << 34,
		Sigma: 3.2},

	{LogN: 15,
		LogSlots: 14,
		LogModuli: LogModuli{
			LogQi: []uint64{50, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40},
			LogPi: []uint64{50, 50, 50},
		},
		Scale: 1 << 40,
		Sigma: 3.2},

	{LogN: 16,
		LogSlots: 15,
		LogModuli: LogModuli{
			LogQi: []uint64{55, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45},
			LogPi: []uint64{55, 55, 55, 55},
		},
		Scale: 1 << 45,
		Sigma: 3.2},
}

DefaultParams is a set of default CKKS parameters ensuring 128 bit security.

Functions

func GenModuli

func GenModuli(params *Parameters) (Q []uint64, P []uint64)

GenModuli generates the appropriate primes from the parameters using generateCKKSPrimes, such that all the primes are different.

func GenSwitchkeysRescalingParams

func GenSwitchkeysRescalingParams(Q, P []uint64) (params []uint64)

GenSwitchkeysRescalingParams generates the parameters for rescaling the switching keys

Types

type ChebyshevInterpolation

type ChebyshevInterpolation struct {
	// contains filtered or unexported fields
}

ChebyshevInterpolation is a struct storing the coefficients, degree and range of a Chebyshev interpolation polynomial.

func Approximate

func Approximate(function func(complex128) complex128, a, b complex128, degree int) (cheby *ChebyshevInterpolation)

Approximate computes a Chebyshev approximation of the input function, for the range [-a, b] of degree degree. To be used in conjunction with the function EvaluateCheby.

type Ciphertext

type Ciphertext struct {
	// 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 uint64, level uint64, scale float64) (ciphertext *Ciphertext)

NewCiphertext creates a new Ciphertext parameterized by degree, level and scale.

func NewCiphertextRandom

func NewCiphertextRandom(params *Parameters, degree, level uint64, scale float64) (ciphertext *Ciphertext)

NewCiphertextRandom generates a new uniformly distributed Ciphertext of degree, level and scale.

func (Ciphertext) Ciphertext

func (el Ciphertext) Ciphertext() *Ciphertext

Ciphertext sets the target element type to Ciphertext.

func (Ciphertext) Copy

func (el Ciphertext) Copy(ctxCopy *ckksElement) (err error)

Copy copies the input element and its parameters on the target element.

func (Ciphertext) CopyNew

func (el Ciphertext) CopyNew() *ckksElement

CopyNew creates a new element as a copy of the target element.

func (Ciphertext) CopyParams

func (el Ciphertext) CopyParams(ckkselement *ckksElement)

CopyParams copies the input element parameters on the target element

func (Ciphertext) Degree

func (el Ciphertext) Degree() uint64

Degree returns the degree of the target element.

func (Ciphertext) DivScale

func (el Ciphertext) DivScale(scale float64)

DivScale divides the scale of the target element by the input scale.

func (Ciphertext) Element

func (el Ciphertext) Element() *ckksElement

Element sets the target element type to Element.

func (*Ciphertext) GetDataLen

func (ciphertext *Ciphertext) GetDataLen(WithMetaData bool) (dataLen uint64)

GetDataLen returns the length in bytes of the target Ciphertext.

func (Ciphertext) InvNTT

func (el Ciphertext) InvNTT(context *ring.Context, c *ckksElement) error

InvNTT puts the target element outside of the NTT domain, and sets its isNTT flag to false. If it is not in the NTT domain, it does nothing.

func (Ciphertext) IsNTT

func (el Ciphertext) IsNTT() bool

IsNTT returns the value of the NTT flag of the target element.

func (Ciphertext) Level

func (el Ciphertext) Level() uint64

Level returns the level of the target element.

func (*Ciphertext) MarshalBinary

func (ciphertext *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) MulScale

func (el Ciphertext) MulScale(scale float64)

MulScale multiplies the scale of the target element with the input scale.

func (Ciphertext) NTT

func (el Ciphertext) NTT(context *ring.Context, c *ckksElement) error

NTT puts the target element in the NTT domain and sets its isNTT flag to true. If it is already in the NTT domain, it does nothing.

func (Ciphertext) Plaintext

func (el Ciphertext) Plaintext() *Plaintext

Plaintext sets the target element type to Plaintext.

func (Ciphertext) Resize

func (el Ciphertext) Resize(params *Parameters, degree uint64)

Resize resizes the degree of the target element.

func (Ciphertext) Scale

func (el Ciphertext) Scale() float64

Scale returns the scale of the target element.

func (Ciphertext) SetIsNTT

func (el Ciphertext) SetIsNTT(value bool)

SetIsNTT sets the value of the NTT flag of the target element with the input value.

func (Ciphertext) SetScale

func (el Ciphertext) SetScale(scale float64)

SetScale sets the scale of the the target element to the input scale.

func (Ciphertext) SetValue

func (el Ciphertext) SetValue(value []*ring.Poly)

SetValue sets the input slice of polynomials as the value of the target element.

func (*Ciphertext) UnmarshalBinary

func (ciphertext *Ciphertext) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decodes a previously marshaled Ciphertext on the target Ciphertext. The target Ciphertext must be of the appropriate format and size, it can be created with the method NewCiphertext(uint64).

func (Ciphertext) Value

func (el Ciphertext) Value() []*ring.Poly

Value returns the slice of polynomials of the target element.

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context is a struct that contains all the elements required to instantiate the CKKS Scheme. This includes the parameters (polynomial degree, ciphertext modulus, Gaussian sampler, polynomial contexts and other parameters required for the homomorphic operations).

type Decryptor

type Decryptor interface {
	// DecryptNew decrypts the ciphertext and returns a newly created
	// plaintext. A Horner method is used for evaluating the decryption.
	DecryptNew(ciphertext *Ciphertext) (plaintext *Plaintext)

	// Decrypt decrypts the ciphertext and returns the result on the provided
	// receiver plaintext. A Horner method is used for evaluating the
	// decryption.
	Decrypt(ciphertext *Ciphertext, plaintext *Plaintext)
}

Decryptor is an interface for decrypting Ciphertexts. A Decryptor stores the secret-key.

func NewDecryptor

func NewDecryptor(params *Parameters, sk *SecretKey) Decryptor

NewDecryptor instantiates a new Decryptor that will be able to decrypt ciphertexts encrypted under the provided secret-key.

type Encoder

type Encoder interface {
	Encode(plaintext *Plaintext, values []complex128, slots uint64)
	EncodeNew(values []complex128, slots uint64) (plaintext *Plaintext)
	Decode(plaintext *Plaintext, slots uint64) (res []complex128)
}

Encoder is an interface implenting the encoding algorithms.

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 Encryptor

type Encryptor interface {
	// EncryptNew encrypts the input plaintext using the stored key and returns
	// the result on a newly created ciphertext.
	EncryptNew(plaintext *Plaintext) *Ciphertext

	// Encrypt encrypts the input plaintext using the stored key, and returns
	// the result on the reciver ciphertext.
	Encrypt(plaintext *Plaintext, ciphertext *Ciphertext)
}

Encryptor in an interface for encryptors

encrypt with pk : ciphertext = [pk[0]*u + m + e_0, pk[1]*u + e_1] encrypt with sk : ciphertext = [-a*sk + m + e, a]

func NewEncryptorFromPk

func NewEncryptorFromPk(params *Parameters, pk *PublicKey) Encryptor

NewEncryptorFromPk creates a new Encryptor with the provided public-key. This Encryptor can be used to encrypt Plaintexts, using the stored key.

func NewEncryptorFromSk

func NewEncryptorFromSk(params *Parameters, sk *SecretKey) Encryptor

NewEncryptorFromSk creates a new Encryptor with the provided secret-key. This Encryptor can be used to encrypt Plaintexts, using the stored key.

type EvaluationKey

type EvaluationKey struct {
	// contains filtered or unexported fields
}

EvaluationKey is a structure that stores the switching-keys required during the relinearization.

func NewRelinKey

func NewRelinKey(params *Parameters) (evakey *EvaluationKey)

NewRelinKey returns a new EvaluationKey with zero values.

func (*EvaluationKey) Get

func (evk *EvaluationKey) Get() *SwitchingKey

Get returns the slice of switching keys of the evaluation-key.

func (*EvaluationKey) GetDataLen

func (evaluationkey *EvaluationKey) GetDataLen(WithMetaData bool) (dataLen uint64)

GetDataLen returns the length in bytes of the target EvaluationKey.

func (*EvaluationKey) MarshalBinary

func (evaluationkey *EvaluationKey) MarshalBinary() (data []byte, err error)

MarshalBinary encodes an evaluation key in a byte slice.

func (*EvaluationKey) Set

func (evk *EvaluationKey) Set(rlk [][2]*ring.Poly)

Set sets the target Evaluation key with the input polynomials.

func (*EvaluationKey) UnmarshalBinary

func (evaluationkey *EvaluationKey) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decodes a previously marshaled evaluation-key in the target evaluation-key.

type Evaluator

type Evaluator interface {
	Add(op0, op1 Operand, ctOut *Ciphertext)
	AddNoMod(op0, op1 Operand, ctOut *Ciphertext)
	AddNew(op0, op1 Operand) (ctOut *Ciphertext)
	AddNoModNew(op0, op1 Operand) (ctOut *Ciphertext)
	Sub(op0, op1 Operand, ctOut *Ciphertext)
	SubNoMod(op0, op1 Operand, ctOut *Ciphertext)
	SubNew(op0, op1 Operand) (ctOut *Ciphertext)
	SubNoModNew(op0, op1 Operand) (ctOut *Ciphertext)
	Neg(ct0 *Ciphertext, ctOut *Ciphertext)
	NegNew(ct0 *Ciphertext) (ctOut *Ciphertext)
	AddConstNew(ct0 *Ciphertext, constant interface{}) (ctOut *Ciphertext)
	AddConst(ct0 *Ciphertext, constant interface{}, ctOut *Ciphertext)
	MultByConstAndAdd(ct0 *Ciphertext, constant interface{}, ctOut *Ciphertext)
	MultByConstNew(ct0 *Ciphertext, constant interface{}) (ctOut *Ciphertext)
	MultByConst(ct0 *Ciphertext, constant interface{}, ctOut *Ciphertext)
	MultByiNew(ct0 *Ciphertext) (ctOut *Ciphertext)
	MultByi(ct0 *Ciphertext, ct1 *Ciphertext)
	DivByiNew(ct0 *Ciphertext) (ctOut *Ciphertext)
	DivByi(ct0 *Ciphertext, ct1 *Ciphertext)
	ScaleUpNew(ct0 *Ciphertext, scale float64) (ctOut *Ciphertext)
	ScaleUp(ct0 *Ciphertext, scale float64, ctOut *Ciphertext)
	MulByPow2New(ct0 *Ciphertext, pow2 uint64) (ctOut *Ciphertext)
	MulByPow2(ct0 *ckksElement, pow2 uint64, ctOut *ckksElement)
	ReduceNew(ct0 *Ciphertext) (ctOut *Ciphertext)
	Reduce(ct0 *Ciphertext, ctOut *Ciphertext) error
	DropLevelNew(ct0 *Ciphertext, levels uint64) (ctOut *Ciphertext)
	DropLevel(ct0 *Ciphertext, levels uint64) (err error)
	Rescale(ct0 *Ciphertext, threshold float64, c1 *Ciphertext) (err error)
	RescaleMany(ct0 *Ciphertext, nbRescales uint64, c1 *Ciphertext) (err error)
	MulRelinNew(op0, op1 Operand, evakey *EvaluationKey) (ctOut *Ciphertext)
	MulRelin(op0, op1 Operand, evakey *EvaluationKey, ctOut *Ciphertext)
	RelinearizeNew(ct0 *Ciphertext, evakey *EvaluationKey) (ctOut *Ciphertext)
	Relinearize(ct0 *Ciphertext, evakey *EvaluationKey, ctOut *Ciphertext)
	SwitchKeysNew(ct0 *Ciphertext, switchingKey *SwitchingKey) (ctOut *Ciphertext)
	SwitchKeys(ct0 *Ciphertext, switchingKey *SwitchingKey, ctOut *Ciphertext)
	RotateColumnsNew(ct0 *Ciphertext, k uint64, evakey *RotationKeys) (ctOut *Ciphertext)
	RotateColumns(ct0 *Ciphertext, k uint64, evakey *RotationKeys, ctOut *Ciphertext)
	RotateHoisted(ctIn *Ciphertext, rotations []uint64, rotkeys *RotationKeys) (cOut map[uint64]*Ciphertext)
	ConjugateNew(ct0 *Ciphertext, evakey *RotationKeys) (ctOut *Ciphertext)
	Conjugate(ct0 *Ciphertext, evakey *RotationKeys, ctOut *Ciphertext)
	PowerOf2(el0 *Ciphertext, logPow2 uint64, evakey *EvaluationKey, elOut *Ciphertext)
	PowerNew(op *Ciphertext, degree uint64, evakey *EvaluationKey) (opOut *Ciphertext)
	Power(ct0 *Ciphertext, degree uint64, evakey *EvaluationKey, res *Ciphertext)
	InverseNew(ct0 *Ciphertext, steps uint64, evakey *EvaluationKey) (res *Ciphertext)
	EvaluatePolyFast(ct *Ciphertext, coeffs interface{}, evakey *EvaluationKey) (res *Ciphertext)
	EvaluatePolyEco(ct *Ciphertext, coeffs interface{}, evakey *EvaluationKey) (res *Ciphertext)
	EvaluateChebyFast(ct *Ciphertext, cheby *ChebyshevInterpolation, evakey *EvaluationKey) (res *Ciphertext)
	EvaluateChebyEco(ct *Ciphertext, cheby *ChebyshevInterpolation, evakey *EvaluationKey) (res *Ciphertext)
}

Evaluator is an interface implementing the methodes to conduct homomorphic operations between ciphertext and/or plaintexts.

func NewEvaluator

func NewEvaluator(params *Parameters) Evaluator

NewEvaluator creates a new Evaluator, that can be used to do homomorphic operations on the Ciphertexts and/or Plaintexts. It stores a small pool of polynomials and Ciphertexts that will be used for intermediate values.

type KeyGenerator

type KeyGenerator interface {
	GenSecretKey() (sk *SecretKey)
	GenSecretKeyWithDistrib(p float64) (sk *SecretKey)
	GenSecretKeySparse(hw uint64) (sk *SecretKey)
	GenPublicKey(sk *SecretKey) (pk *PublicKey)
	GenKeyPair() (sk *SecretKey, pk *PublicKey)
	GenKeyPairSparse(hw uint64) (sk *SecretKey, pk *PublicKey)
	GenRelinKey(sk *SecretKey) (evakey *EvaluationKey)
	GenSwitchingKey(skInput, skOutput *SecretKey) (newevakey *SwitchingKey)
	GenRotationKeysPow2(skOutput *SecretKey) (rotKey *RotationKeys)
	GenRot(rotType Rotation, sk *SecretKey, k uint64, rotKey *RotationKeys)
}

KeyGenerator is an interface implementing the methods of the KeyGenerator.

func NewKeyGenerator

func NewKeyGenerator(params *Parameters) KeyGenerator

NewKeyGenerator creates a new KeyGenerator, from which the secret and public keys, as well as the evaluation, rotation and switching keys can be generated.

type LogModuli

type LogModuli struct {
	LogQi []uint64 // Ciphertext prime moduli bit-size
	LogPi []uint64 // Keys additional prime moduli bit-size
}

LogModuli stores the bit-length of the NTT primes of the RNS representation.

func (*LogModuli) Copy

func (m *LogModuli) Copy() LogModuli

Copy creates a copy of the target LogModuli.

type Moduli

type Moduli struct {
	Qi []uint64 // Ciphertext prime moduli
	Pi []uint64 // Keys additional prime moduli
}

Moduli stores the NTT primes of the RNS representation.

func (*Moduli) Copy

func (m *Moduli) Copy() Moduli

Copy creates a copy of the target Moduli.

type Operand

type Operand interface {
	Element() *ckksElement
	Degree() uint64
	Level() uint64
	Scale() float64
}

Operand is a common interface for Ciphertext and Plaintext types.

type Parameters

type Parameters struct {
	Moduli
	LogModuli
	LogN     uint64 // Ring degree (power of 2)
	LogSlots uint64
	Scale    float64
	Sigma    float64 // Gaussian sampling variance
	// contains filtered or unexported fields
}

Parameters represents a given parameter set for the BFV cryptosystem.

func NewParametersFromLogModuli

func NewParametersFromLogModuli(LogN, LogSlots uint64, Scale float64, logModuli LogModuli, Sigma float64) (params *Parameters)

NewParametersFromLogModuli generates a new set or bfv parameters from the input parameters.

func NewParametersFromModuli

func NewParametersFromModuli(LogN, LogSlots uint64, Scale float64, moduli Moduli, Sigma float64) (params *Parameters)

NewParametersFromModuli generates a new set or bfv parameters from the input parameters.

func (*Parameters) Alpha

func (p *Parameters) Alpha() uint64

Alpha returns #Pi.

func (*Parameters) Beta

func (p *Parameters) Beta() uint64

Beta returns ceil(#Qi/#Pi).

func (*Parameters) Copy

func (p *Parameters) Copy() (paramsCopy *Parameters)

Copy creates a copy of the target parameters.

func (*Parameters) Equals

func (p *Parameters) Equals(other *Parameters) (res bool)

Equals compares two sets of parameters for equality.

func (*Parameters) GenFromLogModuli

func (p *Parameters) GenFromLogModuli()

GenFromLogModuli generates the parameters using the given bit-size for the moduli.

func (*Parameters) GenFromModuli

func (p *Parameters) GenFromModuli()

GenFromModuli generates the parameters using the provided moduli.

func (*Parameters) IsValid

func (p *Parameters) IsValid() bool

IsValid returns a true if the parameters are complete and valid, else false.

func (*Parameters) LogQP

func (p *Parameters) LogQP() uint64

LogQP returns the bitlength of prod(Qi) * prod(Pi)

func (*Parameters) MarshalBinary

func (p *Parameters) MarshalBinary() ([]byte, error)

MarshalBinary returns a []byte representation of the parameter set.

func (*Parameters) MaxLevel

func (p *Parameters) MaxLevel() uint64

MaxLevel returns #Qi -1

func (*Parameters) NewPolyP

func (p *Parameters) NewPolyP() *ring.Poly

NewPolyP returns a new empty polynomial of degree 2^LogN in basis Pi.

func (*Parameters) NewPolyQ

func (p *Parameters) NewPolyQ() *ring.Poly

NewPolyQ returns a new empty polynomial of degree 2^LogN in basis Qi.

func (*Parameters) NewPolyQP

func (p *Parameters) NewPolyQP() *ring.Poly

NewPolyQP returns a new empty polynomial of degree 2^LogN in basis Qi + Pi.

func (*Parameters) UnmarshalBinary

func (p *Parameters) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a []byte into a parameter set struct

type Plaintext

type Plaintext struct {
	// contains filtered or unexported fields
}

Plaintext is is a ckksElement with only one Poly.

func NewPlaintext

func NewPlaintext(params *Parameters, level uint64, scale float64) *Plaintext

NewPlaintext creates a new Plaintext of level level and scale scale.

func (Plaintext) Ciphertext

func (el Plaintext) Ciphertext() *Ciphertext

Ciphertext sets the target element type to Ciphertext.

func (Plaintext) Copy

func (el Plaintext) Copy(ctxCopy *ckksElement) (err error)

Copy copies the input element and its parameters on the target element.

func (Plaintext) CopyNew

func (el Plaintext) CopyNew() *ckksElement

CopyNew creates a new element as a copy of the target element.

func (Plaintext) CopyParams

func (el Plaintext) CopyParams(ckkselement *ckksElement)

CopyParams copies the input element parameters on the target element

func (Plaintext) Degree

func (el Plaintext) Degree() uint64

Degree returns the degree of the target element.

func (Plaintext) DivScale

func (el Plaintext) DivScale(scale float64)

DivScale divides the scale of the target element by the input scale.

func (Plaintext) Element

func (el Plaintext) Element() *ckksElement

Element sets the target element type to Element.

func (Plaintext) InvNTT

func (el Plaintext) InvNTT(context *ring.Context, c *ckksElement) error

InvNTT puts the target element outside of the NTT domain, and sets its isNTT flag to false. If it is not in the NTT domain, it does nothing.

func (Plaintext) IsNTT

func (el Plaintext) IsNTT() bool

IsNTT returns the value of the NTT flag of the target element.

func (Plaintext) Level

func (el Plaintext) Level() uint64

Level returns the level of the target element.

func (Plaintext) MulScale

func (el Plaintext) MulScale(scale float64)

MulScale multiplies the scale of the target element with the input scale.

func (Plaintext) NTT

func (el Plaintext) NTT(context *ring.Context, c *ckksElement) error

NTT puts the target element in the NTT domain and sets its isNTT flag to true. If it is already in the NTT domain, it does nothing.

func (Plaintext) Plaintext

func (el Plaintext) Plaintext() *Plaintext

Plaintext sets the target element type to Plaintext.

func (Plaintext) Resize

func (el Plaintext) Resize(params *Parameters, degree uint64)

Resize resizes the degree of the target element.

func (Plaintext) Scale

func (el Plaintext) Scale() float64

Scale returns the scale of the target element.

func (Plaintext) SetIsNTT

func (el Plaintext) SetIsNTT(value bool)

SetIsNTT sets the value of the NTT flag of the target element with the input value.

func (Plaintext) SetScale

func (el Plaintext) SetScale(scale float64)

SetScale sets the scale of the the target element to the input scale.

func (Plaintext) SetValue

func (el Plaintext) SetValue(value []*ring.Poly)

SetValue sets the input slice of polynomials as the value of the target element.

func (Plaintext) Value

func (el Plaintext) Value() []*ring.Poly

Value returns the slice of polynomials of the target element.

type PublicKey

type PublicKey struct {
	// contains filtered or unexported fields
}

PublicKey is a structure that stores the PublicKey

func NewPublicKey

func NewPublicKey(params *Parameters) (pk *PublicKey)

NewPublicKey returns a new PublicKey with zero values.

func (*PublicKey) Get

func (pk *PublicKey) Get() [2]*ring.Poly

Get returns the value of the the public key.

func (*PublicKey) GetDataLen

func (pk *PublicKey) GetDataLen(WithMetaData bool) (dataLen uint64)

GetDataLen returns the length in bytes of the target PublicKey.

func (*PublicKey) MarshalBinary

func (pk *PublicKey) MarshalBinary() (data []byte, err error)

MarshalBinary encodes a PublicKey in a byte slice.

func (*PublicKey) Set

func (pk *PublicKey) Set(poly [2]*ring.Poly)

Set sets the value of the public key to the provided value.

func (*PublicKey) UnmarshalBinary

func (pk *PublicKey) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decodes a previously marshaled PublicKey in the target PublicKey.

type Rotation

type Rotation int

Rotation is a type used to represent the rotations types.

type RotationKeys

type RotationKeys struct {
	// contains filtered or unexported fields
}

RotationKeys is a structure that stores the switching-keys required during the homomorphic rotations.

func NewRotationKeys

func NewRotationKeys() (rotKey *RotationKeys)

NewRotationKeys generates a new instance of RotationKeys, with the provided rotation to the left, right and conjugation if requested.

func (*RotationKeys) GetDataLen

func (rotationkey *RotationKeys) GetDataLen(WithMetaData bool) (dataLen uint64)

GetDataLen returns the length in bytes of the target RotationKeys.

func (*RotationKeys) MarshalBinary

func (rotationkey *RotationKeys) MarshalBinary() (data []byte, err error)

MarshalBinary encodes a RotationKeys structure in a byte slice.

func (*RotationKeys) SetRotKey

func (rotKey *RotationKeys) SetRotKey(params *Parameters, evakey [][2]*ring.Poly, rotType Rotation, k uint64)

SetRotKey sets the target RotationKeys' SwitchingKey for the specified rotation type and amount with the input polynomials.

func (*RotationKeys) UnmarshalBinary

func (rotationkey *RotationKeys) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decodes a previously marshaled RotationKeys in the target RotationKeys.

type SecretKey

type SecretKey struct {
	// contains filtered or unexported fields
}

SecretKey is a structure that stores the SecretKey

func NewSecretKey

func NewSecretKey(params *Parameters) *SecretKey

NewSecretKey generates a new SecretKey with zero values.

func (*SecretKey) Get

func (sk *SecretKey) Get() *ring.Poly

Get returns the value of the SecretKey.

func (*SecretKey) GetDataLen

func (sk *SecretKey) GetDataLen(WithMetaData bool) (dataLen uint64)

GetDataLen returns the length in bytes of the target SecretKey.

func (*SecretKey) MarshalBinary

func (sk *SecretKey) MarshalBinary() (data []byte, err error)

MarshalBinary encodes a SecretKey in a byte slice.

func (*SecretKey) Set

func (sk *SecretKey) Set(poly *ring.Poly)

Set sets the value of the SecretKey to the provided value.

func (*SecretKey) UnmarshalBinary

func (sk *SecretKey) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decodes a previously marshaled SecretKey on the target secret-key.

type SwitchingKey

type SwitchingKey struct {
	// contains filtered or unexported fields
}

SwitchingKey is a structure that stores the switching-keys required during the key-switching.

func NewSwitchingKey

func NewSwitchingKey(params *Parameters) (evakey *SwitchingKey)

NewSwitchingKey returns a new SwitchingKey with zero values.

func (*SwitchingKey) Get

func (swk *SwitchingKey) Get() [][2]*ring.Poly

Get returns the switching key backing slice

func (*SwitchingKey) GetDataLen

func (switchkey *SwitchingKey) GetDataLen(WithMetaData bool) (dataLen uint64)

GetDataLen returns the length in bytes of the target SwitchingKey.

func (*SwitchingKey) MarshalBinary

func (switchkey *SwitchingKey) MarshalBinary() (data []byte, err error)

MarshalBinary encodes an SwitchingKey in a byte slice.

func (*SwitchingKey) UnmarshalBinary

func (switchkey *SwitchingKey) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decode a previously marshaled SwitchingKey in the target SwitchingKey.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL