diff --git a/core/rlwe/ciphertext.go b/core/rlwe/ciphertext.go index bfe1d721..d92ad4eb 100644 --- a/core/rlwe/ciphertext.go +++ b/core/rlwe/ciphertext.go @@ -5,7 +5,6 @@ import ( "github.com/tuneinsight/lattigo/v6/ring" "github.com/tuneinsight/lattigo/v6/utils/sampling" - "github.com/tuneinsight/lattigo/v6/utils/structs" ) // Ciphertext is a generic type for RLWE ciphertexts. @@ -71,12 +70,14 @@ func (ct Ciphertext) Equal(other *Ciphertext) bool { return ct.Element.Equal(&other.Element) } -func NewCiphertextFromUintPool(pool structs.BufferPool[*[]uint64], params ParameterProvider, degree int, level int) *Ciphertext { +func NewCiphertextFromUintPool(params ParameterProvider, degree int, levelQ int) *Ciphertext { p := params.GetRLWEParameters() + ringQ := p.RingQ().AtLevel(levelQ) + Value := make([]ring.Poly, degree+1) for i := range Value { - Value[i] = *ring.NewPolyFromUintPool(pool, p.N(), level) + Value[i] = *ringQ.NewPolyFromUintPool() } el := Element[ring.Poly]{ @@ -90,9 +91,10 @@ func NewCiphertextFromUintPool(pool structs.BufferPool[*[]uint64], params Parame return &Ciphertext{el} } -func RecycleCiphertextInUintPool(pool structs.BufferPool[*[]uint64], ct *Ciphertext) { +func RecycleCiphertextInUintPool(params ParameterProvider, ct *Ciphertext) { + ringQ := params.GetRLWEParameters().ringQ for i := range ct.Value { - ring.RecyclePolyInUintPool(pool, &ct.Value[i]) + ringQ.RecyclePolyInUintPool(&ct.Value[i]) } ct = nil return diff --git a/core/rlwe/evaluator.go b/core/rlwe/evaluator.go index 193d4f1a..0bf0a6c2 100644 --- a/core/rlwe/evaluator.go +++ b/core/rlwe/evaluator.go @@ -38,37 +38,33 @@ func newBuffer[T any](f func() T) structs.BufferPool[T] { func NewEvaluatorBuffersWithUintPool(params Parameters) *EvaluatorBuffers { buff := new(EvaluatorBuffers) ringQP := params.RingQP() + ringQ := params.ringQ - buffUint := newBuffer(func() *[]uint64 { - buff := make([]uint64, params.RingQ().N()) - return &buff - }) - - buff.BuffQPPool = structs.NewBuffFromUintPool(buffUint, - func(bp structs.BufferPool[*[]uint64]) *ringqp.Poly { - return ringQP.NewPolyQPFromUintPool(bp) + buff.BuffQPPool = structs.NewBuffFromUintPool( + func() *ringqp.Poly { + return ringQP.NewPolyQPFromUintPool() }, - func(bp structs.BufferPool[*[]uint64], poly *ringqp.Poly) { - ringqp.RecyclePolyQPFromUintPool(bp, poly) + func(poly *ringqp.Poly) { + ringQP.RecyclePolyQPFromUintPool(poly) }, ) - buff.BuffQPool = structs.NewBuffFromUintPool(buffUint, - func(bp structs.BufferPool[*[]uint64]) *ring.Poly { - return ring.NewPolyFromUintPool(bp, params.ringQ.N(), params.ringQ.Level()) + buff.BuffQPool = structs.NewBuffFromUintPool( + func() *ring.Poly { + return ringQ.NewPolyFromUintPool() }, - func(bp structs.BufferPool[*[]uint64], poly *ring.Poly) { - ring.RecyclePolyInUintPool(bp, poly) + func(poly *ring.Poly) { + ringQ.RecyclePolyInUintPool(poly) }, ) - buff.BuffCtPool = structs.NewBuffFromUintPool(buffUint, - func(bp structs.BufferPool[*[]uint64]) *Ciphertext { - return NewCiphertextFromUintPool(bp, params, 2, params.MaxLevel()) + buff.BuffCtPool = structs.NewBuffFromUintPool( + func() *Ciphertext { + return NewCiphertextFromUintPool(params, 2, params.MaxLevel()) }, - func(bp structs.BufferPool[*[]uint64], ct *Ciphertext) { - RecycleCiphertextInUintPool(bp, ct) + func(ct *Ciphertext) { + RecycleCiphertextInUintPool(params, ct) }, ) - buff.BuffBitPool = buffUint + buff.BuffBitPool = ringQ.BufferPool() return buff } diff --git a/core/rlwe/params.go b/core/rlwe/params.go index 18b2467f..bffc52a5 100644 --- a/core/rlwe/params.go +++ b/core/rlwe/params.go @@ -15,6 +15,7 @@ import ( "github.com/tuneinsight/lattigo/v6/ring/ringqp" "github.com/tuneinsight/lattigo/v6/utils" "github.com/tuneinsight/lattigo/v6/utils/buffer" + "github.com/tuneinsight/lattigo/v6/utils/structs" ) // MaxLogN is the log2 of the largest supported polynomial modulus degree. @@ -855,11 +856,16 @@ func GenModuli(LogNthRoot int, logQ, logP []int) (q, p []uint64, err error) { } func (p *Parameters) initRings() (err error) { - if p.ringQ, err = ring.NewRingFromType(1<