rgsw

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0, BSD-3-Clause, ISC, + 1 more Imports: 7 Imported by: 0

Documentation

Overview

Package rgsw implements an RLWE-based GSW encryption and external product RLWE x RGSW -> RLWE. RSGW ciphertexts are tuples of two rlwe.GadgetCiphertext encrypting (`m(X)`, s*m(X)).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLazy

func AddLazy(rQ, rP ring.RNSRing, op interface{}, opOut *Ciphertext)

AddLazy adds op to opOut, without modular reduction.

func MulByXPowAlphaMinusOneLazy

func MulByXPowAlphaMinusOneLazy(rQ, rP *ring.RNSRing, ctIn *Ciphertext, powXMinusOne [2]ring.RNSPoly, opOut *Ciphertext)

MulByXPowAlphaMinusOneLazy multiplies opOut by (X^alpha - 1) and returns the result on opOut.

func MulByXPowAlphaMinusOneThenAddLazy

func MulByXPowAlphaMinusOneThenAddLazy(rQ, rP *ring.RNSRing, ctIn *Ciphertext, powXMinusOne [2]ring.RNSPoly, opOut *Ciphertext)

MulByXPowAlphaMinusOneThenAddLazy multiplies opOut by (X^alpha - 1) and adds the result on opOut.

func NoiseCiphertext

func NoiseCiphertext(ct *Ciphertext, pt ring.RNSPoly, sk *rlwe.SecretKey, params rlwe.Parameters) (float64, float64)

NoiseCiphertext returns the base two logarithm of the standard deviation of the noise of each component of an rgsw.Ciphertext. pt must be in the NTT and Montgomery domain

func Reduce

func Reduce(rQ, rP *ring.RNSRing, ctIn *Ciphertext, opOut *Ciphertext)

Reduce applies the modular reduction on ctIn and returns the result on opOut.

Types

type Ciphertext

type Ciphertext struct {
	rlwe.DigitDecomposition
	Matrix structs.Matrix[ring.Matrix]
}

Ciphertext is a generic type for RGSW ciphertext.

func NewCiphertext

func NewCiphertext(params rlwe.ParameterProvider, LevelQ, LevelP int, DD rlwe.DigitDecomposition) (ct *Ciphertext)

NewCiphertext allocates a new RGSW ciphertext in the NTT domain.

func (Ciphertext) At

func (ct Ciphertext) At(i int) *rlwe.GadgetCiphertext

func (Ciphertext) BinarySize

func (ct Ciphertext) BinarySize() int

BinarySize returns the serialized size of the object in bytes.

func (*Ciphertext) BufferSize

func (ct *Ciphertext) BufferSize(params rlwe.ParameterProvider, LevelQ, LevelP int, DD rlwe.DigitDecomposition) int

BufferSize returns the minimum buffer size to instantiate the receiver through [FromBuffer].

func (*Ciphertext) FromBuffer

func (ct *Ciphertext) FromBuffer(params rlwe.ParameterProvider, LevelQ, LevelP int, DD rlwe.DigitDecomposition, buf []uint64)

FromBuffer assigns new backing array to the receiver. Method panics if len(buf) is too small. Minimum backing array size can be obtained with [BufferSize].

func (*Ciphertext) FromGadgetCiphertext

func (ct *Ciphertext) FromGadgetCiphertext(eval *Evaluator, gct *rlwe.GadgetCiphertext) (err error)

FromGadgetCiphertext populates the receiver from an rlwe.GadgetCiphertext and an rgsw.Evaluator instantiated with an rlwe.RelinearizationKey.

The receiver rgsw.Ciphertext is constructed as follow:

inputs: - gct = [-as + w*m + e, a] - rlk = [-bs + ws^2 + e, b]

output: - rgsw: [[-as + w*m + e, a], [<a, rlk[0]>, <a, rlk[1]> + -as + w*m + e]]

The first component of the rgsw.Ciphertext shares the backing array of the input rlwe.GadgetCiphertext.

The method will panic if the input rlwe.GadgetCiphertext.LevelP() isn't -1.

func (Ciphertext) LevelP

func (ct Ciphertext) LevelP() int

LevelP returns the level of the modulus P of the target.

func (Ciphertext) LevelQ

func (ct Ciphertext) LevelQ() int

LevelQ returns the level of the modulus Q of the target.

func (Ciphertext) MarshalBinary

func (ct Ciphertext) MarshalBinary() (p []byte, err error)

MarshalBinary encodes the object into a binary form on a newly allocated slice of bytes.

func (*Ciphertext) ReadFrom

func (ct *Ciphertext) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads on the object from an io.Writer. It implements the io.ReaderFrom interface.

Unless r implements the buffer.Reader interface (see see lattigo/utils/buffer/reader.go), it will be wrapped into a bufio.Reader. Since this requires allocation, it is preferable to pass a buffer.Reader directly:

  • When reading multiple values from a io.Reader, it is preferable to first first wrap io.Reader in a pre-allocated bufio.Reader.
  • When reading from a var b []byte, it is preferable to pass a buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

func (*Ciphertext) UnmarshalBinary

func (ct *Ciphertext) UnmarshalBinary(p []byte) (err error)

UnmarshalBinary decodes a slice of bytes generated by MarshalBinary or WriteTo on the object.

func (Ciphertext) WriteTo

func (ct Ciphertext) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the object on an io.Writer. It implements the io.WriterTo interface, and will write exactly object.BinarySize() bytes on w.

Unless w implements the buffer.Writer interface (see lattigo/utils/buffer/writer.go), it will be wrapped into a bufio.Writer. Since this requires allocations, it is preferable to pass a buffer.Writer directly:

  • When writing multiple times to a io.Writer, it is preferable to first wrap the io.Writer in a pre-allocated bufio.Writer.
  • When writing to a pre-allocated var b []byte, it is preferable to pass buffer.NewBuffer(b) as w (see lattigo/utils/buffer/buffer.go).

type Encryptor

type Encryptor struct {
	*rlwe.Encryptor
}

Encryptor is a type for encrypting RGSW ciphertexts. It implements the rlwe.Encryptor interface overriding the `Encrypt` and `EncryptZero` methods to accept rgsw.Ciphertext types in addition to ciphertexts types in the rlwe package.

func NewEncryptor

func NewEncryptor(params rlwe.ParameterProvider, key rlwe.EncryptionKey) *Encryptor

NewEncryptor creates a new Encryptor type. Note that only secret-key encryption is supported at the moment.

func (Encryptor) Encrypt

func (enc Encryptor) Encrypt(pt *rlwe.Plaintext, ct *Ciphertext) (err error)

Encrypt encrypts a plaintext pt into an rgsw.Ciphertext.

func (Encryptor) EncryptZero

func (enc Encryptor) EncryptZero(ct *Ciphertext) (err error)

EncryptZero generates an rgsw.Ciphertext encrypting zero.

func (Encryptor) ShallowCopy

func (enc Encryptor) ShallowCopy() *Encryptor

ShallowCopy creates a shallow copy of this Encryptor in which all the read-only data-structures are shared with the receiver and the temporary buffers are reallocated. The receiver and the returned Encryptors can be used concurrently.

type Evaluator

type Evaluator struct {
	rlwe.Evaluator
}

Evaluator is a type for evaluating homomorphic operations involving RGSW ciphertexts. It currently supports the external product between a RLWE and a RGSW ciphertext (see Evaluator.ExternalProduct).

func NewEvaluator

func NewEvaluator(params rlwe.ParameterProvider, evk rlwe.EvaluationKeySet) *Evaluator

NewEvaluator creates a new Evaluator type supporting RGSW operations in addition to rlwe.Evaluator operations.

func (Evaluator) ExternalProduct

func (eval Evaluator) ExternalProduct(op0 *rlwe.Ciphertext, op1 *Ciphertext, opOut *rlwe.Ciphertext)

ExternalProduct computes RLWE x RGSW -> RLWE

RLWE : (-as + m + e, a)
x
RGSW : [(-as + P*w*m1 + e, a), (-bs + e, b + P*w*m1)]
=
RLWE : (<RLWE, RGSW[0]>, <RLWE, RGSW[1]>)

func (Evaluator) Product

func (eval Evaluator) Product(op0, op1, op2 *Ciphertext) (err error)

Product computes the left to right RGSW (op0) x RGSW (op1) -> RGSW (op2) product.

Product is evaluated as two series of external products: - RLWE[0][i][j] x RGSW -> RLWE[0][i][j] - RLWE[1][i][j] x RGSW -> RLWE[1][i][j]

The method will return an error if - op0.LevelQ() != op2.LevelQ() - op0.LevelP() or op2.LevelP() != -1

func (Evaluator) ShallowCopy

func (eval Evaluator) ShallowCopy() *Evaluator

ShallowCopy creates a shallow copy of this Evaluator in which all the read-only data-structures are shared with the receiver and the temporary buffers are reallocated. The receiver and the returned Evaluators can be used concurrently.

func (Evaluator) WithKey

func (eval Evaluator) WithKey(evk rlwe.EvaluationKeySet) *Evaluator

WithKey creates a shallow copy of the receiver Evaluator for which the new EvaluationKey is evaluationKey and where the temporary buffers are shared. The receiver and the returned Evaluators cannot be used concurrently.

type Plaintext

type Plaintext rlwe.GadgetPlaintext

Plaintext stores an RGSW plaintext value.

func NewPlaintext

func NewPlaintext(params rlwe.Parameters, value interface{}, LevelQ, LevelP int, dd rlwe.DigitDecomposition) (*Plaintext, error)

NewPlaintext creates a new RGSW plaintext from value, which can be either uint64, int64 or *ring.Poly. Plaintext is returned in the NTT and Montgomery domain.

type TestParametersLiteral

type TestParametersLiteral struct {
	rlwe.DigitDecomposition
	rlwe.ParametersLiteral
}

Jump to

Keyboard shortcuts

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