diff --git a/Makefile b/Makefile index 78cacaad..537c373a 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,19 @@ .PHONY: test_gotest test_gotest: - go test -v -timeout=0 ./utils ./ring ./bfv ./ckks ./dbfv ./dckks + go test -v -timeout=0 ./utils + go test -v -timeout=0 ./ring + go test -v -timeout=0 ./rlwe + go test -v -timeout=0 ./rlwe/ringqp + go test -v -timeout=0 ./rlwe/gadget + go test -v -timeout=0 ./rlwe/rgsw + go test -v -timeout=0 ./rlwe/lut + go test -v -timeout=0 ./bfv + go test -v -timeout=0 ./dbfv + go test -v -timeout=0 ./ckks go test -v -timeout=0 ./ckks/advanced go test -v -timeout=0 ./ckks/bootstrapping -test-bootstrapping -short + go test -v -timeout=0 ./dckks .PHONY: test_examples test_examples: @@ -31,21 +41,6 @@ static_check: check_tools echo $$FMTOUT;\ false;\ fi -.PHONY: test_gotest -test_gotest: - go test -v -timeout=0 ./utils - go test -v -timeout=0 ./ring - go test -v -timeout=0 ./rlwe - go test -v -timeout=0 ./rlwe/ringqp - go test -v -timeout=0 ./rlwe/gadget - go test -v -timeout=0 ./rlwe/rgsw - go test -v -timeout=0 ./rlwe/lut - go test -v -timeout=0 ./bfv - go test -v -timeout=0 ./dbfv - go test -v -timeout=0 ./ckks - go test -v -timeout=0 ./ckks/advanced - go test -v -timeout=0 ./ckks/bootstrapping -test-bootstrapping -short - go test -v -timeout=0 ./dckks @GOVETOUT=$$(go vet ./... 2>&1); \ if [ -z "$$GOVETOUT" ]; then\ diff --git a/ckks/advanced/cosine_approx.go b/ckks/advanced/cosine_approx.go index 10b8816e..deae85b1 100644 --- a/ckks/advanced/cosine_approx.go +++ b/ckks/advanced/cosine_approx.go @@ -1,3 +1,4 @@ +// Package advanced implement advanced operations for the CKKS scheme. package advanced // This is the Go implementation of the approximation polynomial algorithm from Han and Ki in diff --git a/ckks/advanced/marshaler.go b/ckks/advanced/marshaler.go index 6ab8bffc..eb09b7bd 100644 --- a/ckks/advanced/marshaler.go +++ b/ckks/advanced/marshaler.go @@ -59,30 +59,30 @@ func (mParams *EncodingMatrixLiteral) UnmarshalBinary(data []byte) error { } // MarshalBinary encode the target EvalModParameters on a slice of bytes. -func (evmParams *EvalModLiteral) MarshalBinary() (data []byte, err error) { +func (evm *EvalModLiteral) MarshalBinary() (data []byte, err error) { data = make([]byte, 35) - binary.BigEndian.PutUint64(data[:8], evmParams.Q) - data[8] = uint8(evmParams.LevelStart) - binary.BigEndian.PutUint64(data[9:17], math.Float64bits(evmParams.ScalingFactor)) - data[17] = uint8(evmParams.SineType) - binary.BigEndian.PutUint64(data[18:26], math.Float64bits(evmParams.MessageRatio)) - binary.BigEndian.PutUint32(data[26:30], uint32(evmParams.K)) - binary.BigEndian.PutUint16(data[30:32], uint16(evmParams.SineDeg)) - data[33] = uint8(evmParams.DoubleAngle) - data[34] = uint8(evmParams.ArcSineDeg) + binary.BigEndian.PutUint64(data[:8], evm.Q) + data[8] = uint8(evm.LevelStart) + binary.BigEndian.PutUint64(data[9:17], math.Float64bits(evm.ScalingFactor)) + data[17] = uint8(evm.SineType) + binary.BigEndian.PutUint64(data[18:26], math.Float64bits(evm.MessageRatio)) + binary.BigEndian.PutUint32(data[26:30], uint32(evm.K)) + binary.BigEndian.PutUint16(data[30:32], uint16(evm.SineDeg)) + data[33] = uint8(evm.DoubleAngle) + data[34] = uint8(evm.ArcSineDeg) return } // UnmarshalBinary decodes a slice of bytes on the target EvalModParameters. -func (evmParams *EvalModLiteral) UnmarshalBinary(data []byte) (err error) { - evmParams.Q = binary.BigEndian.Uint64(data[:8]) - evmParams.LevelStart = int(data[8]) - evmParams.ScalingFactor = math.Float64frombits(binary.BigEndian.Uint64(data[9:17])) - evmParams.SineType = SineType(int(data[17])) - evmParams.MessageRatio = math.Float64frombits(binary.BigEndian.Uint64(data[18:26])) - evmParams.K = int(binary.BigEndian.Uint32(data[26:30])) - evmParams.SineDeg = int(binary.BigEndian.Uint16(data[30:32])) - evmParams.DoubleAngle = int(data[33]) - evmParams.ArcSineDeg = int(data[34]) +func (evm *EvalModLiteral) UnmarshalBinary(data []byte) (err error) { + evm.Q = binary.BigEndian.Uint64(data[:8]) + evm.LevelStart = int(data[8]) + evm.ScalingFactor = math.Float64frombits(binary.BigEndian.Uint64(data[9:17])) + evm.SineType = SineType(int(data[17])) + evm.MessageRatio = math.Float64frombits(binary.BigEndian.Uint64(data[18:26])) + evm.K = int(binary.BigEndian.Uint32(data[26:30])) + evm.SineDeg = int(binary.BigEndian.Uint16(data[30:32])) + evm.DoubleAngle = int(data[33]) + evm.ArcSineDeg = int(data[34]) return } diff --git a/ckks/bootstrapping/bootstrap.go b/ckks/bootstrapping/bootstrap.go index 5308ebb7..2850640f 100644 --- a/ckks/bootstrapping/bootstrap.go +++ b/ckks/bootstrapping/bootstrap.go @@ -1,3 +1,4 @@ +// Package bootstrapping implement the bootstrapping for the CKKS scheme. package bootstrapping import ( diff --git a/rlwe/elements.go b/rlwe/elements.go index 782d9ae0..1c4c7cb4 100644 --- a/rlwe/elements.go +++ b/rlwe/elements.go @@ -272,11 +272,11 @@ func GetSmallestLargest(el0, el1 *Ciphertext) (smallest, largest *Ciphertext, sa } // Reconstruct reconstructs the degree 1 element of the batch of ciphertexts. -func (scb *SeededCiphertextBatch) Reconstruct(params Parameters) { - prng, _ := utils.NewKeyedPRNG(scb.Seed) +func (ct *SeededCiphertextBatch) Reconstruct(params Parameters) { + prng, _ := utils.NewKeyedPRNG(ct.Seed) ringQ := params.RingQ() sampler := ring.NewUniformSampler(prng, ringQ) - for _, ct := range scb.Value { + for _, ct := range ct.Value { ct.Value[1] = ringQ.NewPoly() sampler.Read(ct.Value[1]) } diff --git a/rlwe/gadget/ciphertext.go b/rlwe/gadget/ciphertext.go index ec177ae4..e14a1f0a 100644 --- a/rlwe/gadget/ciphertext.go +++ b/rlwe/gadget/ciphertext.go @@ -1,3 +1,5 @@ +// Package gadget implements the R-LWE gadget ciphertexts. A gadget ciphertext is a matrix of ciphertexts encrypting plaintexts +// decomposed in the RNS and power of two basis. package gadget import ( diff --git a/rlwe/lut/lut.go b/rlwe/lut/lut.go index 4c0f4bdf..3a32773e 100644 --- a/rlwe/lut/lut.go +++ b/rlwe/lut/lut.go @@ -1,3 +1,4 @@ +// Package lut implements look-up tables evaluation for R-LWE schemes. package lut import ( diff --git a/rlwe/marshaler.go b/rlwe/marshaler.go index c6801ea9..8769a281 100644 --- a/rlwe/marshaler.go +++ b/rlwe/marshaler.go @@ -8,14 +8,14 @@ import ( ) // GetDataLen returns the length in bytes of the target Ciphertext. -func (ciphertext *Ciphertext) GetDataLen(WithMetaData bool) (dataLen int) { +func (el *Ciphertext) GetDataLen(WithMetaData bool) (dataLen int) { // MetaData is : // 1 byte : Degree if WithMetaData { dataLen++ } - for _, el := range ciphertext.Value { + for _, el := range el.Value { dataLen += el.GetDataLen64(WithMetaData) } @@ -24,17 +24,17 @@ func (ciphertext *Ciphertext) GetDataLen(WithMetaData bool) (dataLen int) { // MarshalBinary encodes a Ciphertext on a byte slice. The total size // in byte is 4 + 8* N * numberModuliQ * (degree + 1). -func (ciphertext *Ciphertext) MarshalBinary() (data []byte, err error) { +func (el *Ciphertext) MarshalBinary() (data []byte, err error) { - data = make([]byte, ciphertext.GetDataLen(true)) + data = make([]byte, el.GetDataLen(true)) - data[0] = uint8(ciphertext.Degree() + 1) + data[0] = uint8(el.Degree() + 1) var pointer, inc int pointer = 1 - for _, el := range ciphertext.Value { + for _, el := range el.Value { if inc, err = el.WriteTo64(data[pointer:]); err != nil { return nil, err @@ -47,21 +47,21 @@ func (ciphertext *Ciphertext) MarshalBinary() (data []byte, err error) { } // UnmarshalBinary decodes a previously marshaled Ciphertext on the target Ciphertext. -func (ciphertext *Ciphertext) UnmarshalBinary(data []byte) (err error) { - if len(data) < 10 { // cf. ciphertext.GetDataLen() +func (el *Ciphertext) UnmarshalBinary(data []byte) (err error) { + if len(data) < 10 { // cf. Ciphertext.GetDataLen() return errors.New("too small bytearray") } - ciphertext.Value = make([]*ring.Poly, uint8(data[0])) + el.Value = make([]*ring.Poly, uint8(data[0])) var pointer, inc int pointer = 1 - for i := range ciphertext.Value { + for i := range el.Value { - ciphertext.Value[i] = new(ring.Poly) + el.Value[i] = new(ring.Poly) - if inc, err = ciphertext.Value[i].DecodePoly64(data[pointer:]); err != nil { + if inc, err = el.Value[i].DecodePoly64(data[pointer:]); err != nil { return err } diff --git a/rlwe/params.go b/rlwe/params.go index 1cf9247a..cdd7d816 100644 --- a/rlwe/params.go +++ b/rlwe/params.go @@ -1,3 +1,4 @@ +// Package rlwe implements the general R-LWE arithmetic common to the schemes implemented in this library. package rlwe import ( diff --git a/rlwe/rgsw/ciphertext.go b/rlwe/rgsw/ciphertext.go index 703d39fa..2b70aeba 100644 --- a/rlwe/rgsw/ciphertext.go +++ b/rlwe/rgsw/ciphertext.go @@ -1,3 +1,6 @@ +// Package rgsw implements R-LWE based RGSW ciphertexts. An RGSW ciphertext is a tuple of gadget ciphertexts (see package gadget), where +// the first element is a gadget ciphertext encrypting the message and the second element a gadget ciphertext encryping the message times +// the secret. package rgsw import ( diff --git a/rlwe/ringqp/ringqp.go b/rlwe/ringqp/ringqp.go index 0d8bfa4e..0a533a49 100644 --- a/rlwe/ringqp/ringqp.go +++ b/rlwe/ringqp/ringqp.go @@ -1,3 +1,4 @@ +// Package ringqp is implements a wrapper for both the ringQ and ringP. package ringqp import (