rebased on dev_revamp_ci, and fixed static checks

This commit is contained in:
Jean-Philippe Bossuat
2022-05-19 16:26:05 +02:00
parent 950cd0ddda
commit f21cf19578
11 changed files with 56 additions and 51 deletions

View File

@@ -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\

View File

@@ -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

View File

@@ -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
}

View File

@@ -1,3 +1,4 @@
// Package bootstrapping implement the bootstrapping for the CKKS scheme.
package bootstrapping
import (

View File

@@ -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])
}

View File

@@ -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 (

View File

@@ -1,3 +1,4 @@
// Package lut implements look-up tables evaluation for R-LWE schemes.
package lut
import (

View File

@@ -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
}

View File

@@ -1,3 +1,4 @@
// Package rlwe implements the general R-LWE arithmetic common to the schemes implemented in this library.
package rlwe
import (

View File

@@ -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 (

View File

@@ -1,3 +1,4 @@
// Package ringqp is implements a wrapper for both the ringQ and ringP.
package ringqp
import (