dft

package
v6.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package dft implements a homomorphic DFT circuit for the CKKS scheme.

Index

Constants

View Source
const (
	HomomorphicEncode = Type(0) // Homomorphic Encoding (IDFT)
	HomomorphicDecode = Type(1) // Homomorphic Decoding (DFT)
)

HomomorphicEncode (IDFT) and HomomorphicDecode (DFT) are two available linear transformations for homomorphic encoding and decoding.

View Source
const (
	// Standard: designates the regular DFT.
	// Example: [a+bi, c+di] -> DFT([a+bi, c+di])
	Standard = Format(0)
	// SplitRealAndImag: HomomorphicEncode will return the real and
	// imaginary part into separate ciphertexts, both as real vectors.
	// Example: [a+bi, c+di] -> DFT([a, c]) and DFT([b, d])
	SplitRealAndImag = Format(1)
	// RepackImagAsReal: behaves the same as SplitRealAndImag except that
	// if the ciphertext is sparsely packed (at most N/4 slots), HomomorphicEncode
	// will repacks the real part into the left N/2 slots and the imaginary part
	// into the right N/2 slots. HomomorphicDecode must be specified with the same
	// format for correctness.
	// Example: [a+bi, 0, c+di, 0] -> [DFT([a, b]), DFT([b, d])]
	RepackImagAsReal = Format(2)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Evaluator

type Evaluator struct {
	*ckks.Evaluator
	LTEvaluator *ltcommon.Evaluator
	// contains filtered or unexported fields
}

Evaluator is an evaluator providing an API for homomorphic DFT. All fields of this struct are public, enabling custom instantiations.

func NewEvaluator

func NewEvaluator(params ckks.Parameters, eval *ckks.Evaluator) *Evaluator

NewEvaluator instantiates a new Evaluator from a ckks.Evaluator.

func (*Evaluator) CoeffsToSlots

func (eval *Evaluator) CoeffsToSlots(ctIn *rlwe.Ciphertext, ctsMatrices Matrix, ctReal, ctImag *rlwe.Ciphertext) (err error)

CoeffsToSlots applies the homomorphic encoding and returns the results on the provided ciphertexts. Homomorphically encodes a complex vector vReal + i*vImag of size n on a real vector of size 2n. If the packing is sparse (n < N/2), then returns ctReal = Ecd(vReal || vImag) and ctImag = nil. If the packing is dense (n == N/2), then returns ctReal = Ecd(vReal) and ctImag = Ecd(vImag).

func (*Evaluator) CoeffsToSlotsNew

func (eval *Evaluator) CoeffsToSlotsNew(ctIn *rlwe.Ciphertext, ctsMatrices Matrix) (ctReal, ctImag *rlwe.Ciphertext, err error)

CoeffsToSlotsNew applies the homomorphic encoding and returns the result on new ciphertexts. Homomorphically encodes a complex vector vReal + i*vImag. Given n = current number of slots and N/2 max number of slots (half the ring degree): If the packing is sparse (n < N/2), then returns ctReal = Ecd(vReal || vImag) and ctImag = nil. If the packing is dense (n == N/2), then returns ctReal = Ecd(vReal) and ctImag = Ecd(vImag).

func (*Evaluator) SlotsToCoeffs

func (eval *Evaluator) SlotsToCoeffs(ctReal, ctImag *rlwe.Ciphertext, stcMatrices Matrix, opOut *rlwe.Ciphertext) (err error)

SlotsToCoeffs applies the homomorphic decoding and returns the result on the provided ciphertext. Homomorphically decodes a real vector of size 2n on a complex vector vReal + i*vImag of size n. If the packing is sparse (n < N/2) then ctReal = Ecd(vReal || vImag) and ctImag = nil. If the packing is dense (n == N/2), then ctReal = Ecd(vReal) and ctImag = Ecd(vImag).

func (*Evaluator) SlotsToCoeffsNew

func (eval *Evaluator) SlotsToCoeffsNew(ctReal, ctImag *rlwe.Ciphertext, stcMatrices Matrix) (opOut *rlwe.Ciphertext, err error)

SlotsToCoeffsNew applies the homomorphic decoding and returns the result on a new ciphertext. Homomorphically decodes a real vector of size 2n on a complex vector vReal + i*vImag of size n. If the packing is sparse (n < N/2) then ctReal = Ecd(vReal || vImag) and ctImag = nil. If the packing is dense (n == N/2), then ctReal = Ecd(vReal) and ctImag = Ecd(vImag).

type Format

type Format int

Format is a type used to distinguish between the different input/output formats of the Homomorphic DFT.

type Matrix

type Matrix struct {
	MatrixLiteral
	Matrices []ltcommon.LinearTransformation
}

Matrix is a struct storing the factorized IDFT, DFT matrices, which are used to homomorphically encode and decode a ciphertext respectively.

func NewMatrixFromLiteral

func NewMatrixFromLiteral(params ckks.Parameters, d MatrixLiteral, encoder *ckks.Encoder) (Matrix, error)

NewMatrixFromLiteral generates the factorized DFT/IDFT matrices for the homomorphic encoding/decoding.

type MatrixLiteral

type MatrixLiteral struct {
	// Mandatory
	Type     Type
	LogSlots int
	LevelQ   int
	LevelP   int
	Levels   []int
	// Optional
	Format       Format     // Default: standard.
	Scaling      *big.Float // Default 1.0.
	BitReversed  bool       // Default: False.
	LogBSGSRatio int        // Default: 0.
}

MatrixLiteral is a struct storing the parameters to generate the factorized DFT/IDFT matrices. This struct has mandatory and optional fields.

Mandatory:

  • Type: HomomorphicEncode (a.k.a. CoeffsToSlots) or HomomorphicDecode (a.k.a. SlotsToCoeffs)
  • LogSlots: log2(slots)
  • LevelQ: starting level of the linear transformation
  • LevelP: number of auxiliary primes used during the automorphisms. User must ensure that this value is the same as the one used to generate the Galois keys.
  • Levels: depth of the linear transform (i.e. the degree of factorization of the encoding matrix)

Optional:

  • Format: which post-processing (if any) to apply to the DFT.
  • Scaling: constant by which the matrix is multiplied
  • BitReversed: if true, then applies the transformation bit-reversed and expects bit-reversed inputs
  • LogBSGSRatio: log2 of the ratio between the inner and outer loop of the baby-step giant-step algorithm

func (MatrixLiteral) Depth

func (d MatrixLiteral) Depth(actual bool) (depth int)

Depth returns the number of levels allocated to the linear transform. If actual == true then returns the number of moduli consumed, else returns the factorization depth.

func (MatrixLiteral) GaloisElements

func (d MatrixLiteral) GaloisElements(params ckks.Parameters) (galEls []uint64)

GaloisElements returns the list of rotations performed during the CoeffsToSlot operation.

func (MatrixLiteral) GenMatrices

func (d MatrixLiteral) GenMatrices(LogN int, prec uint) (plainVector []ltcommon.Diagonals[*bignum.Complex])

GenMatrices returns the ordered list of factors of the non-zero diagonals of the IDFT (encoding) or DFT (decoding) matrix.

func (MatrixLiteral) MarshalBinary

func (d MatrixLiteral) MarshalBinary() (data []byte, err error)

MarshalBinary returns a JSON representation of the the target MatrixLiteral on a slice of bytes. See `Marshal` from the `encoding/json` package.

func (*MatrixLiteral) UnmarshalBinary

func (d *MatrixLiteral) UnmarshalBinary(data []byte) error

UnmarshalBinary reads a JSON representation on the target MatrixLiteral struct. See `Unmarshal` from the `encoding/json` package.

type Type

type Type int

Type is a type used to distinguish between different discrete Fourier transformations.

Jump to

Keyboard shortcuts

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