From 48cc4a596f132e4eb004e25a9b8e6161ea03c2e0 Mon Sep 17 00:00:00 2001 From: lehugueni Date: Thu, 20 Feb 2025 14:05:13 +0100 Subject: [PATCH] style: clean up --- core/rlwe/encryptor.go | 28 ++++++++-------------------- core/rlwe/rlwe_test.go | 3 +-- ring/sampler_gaussian.go | 2 +- ring/sampler_ternary.go | 1 + 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/core/rlwe/encryptor.go b/core/rlwe/encryptor.go index 45d9c8cc..7e16c6b9 100644 --- a/core/rlwe/encryptor.go +++ b/core/rlwe/encryptor.go @@ -62,7 +62,10 @@ func (enc Encryptor) GetRLWEParameters() *Parameters { func newEncryptor(params Parameters) *Encryptor { - prng := &sampling.ThreadSafePRNG{} + prng, err := sampling.NewPRNG() + if err != nil { + panic(fmt.Errorf("newEncryptor: %w", err)) + } var bc *ring.BasisExtender if params.PCount() != 0 { @@ -84,11 +87,10 @@ func newEncryptor(params Parameters) *Encryptor { } return &Encryptor{ - params: params, - prng: prng, - xeSampler: xeSampler, - xsSampler: xsSampler, - // encryptorBuffers: newEncryptorBuffers(params), + params: params, + prng: prng, + xeSampler: xeSampler, + xsSampler: xsSampler, uniformSampler: ringqp.NewUniformSampler(prng, *params.RingQP()), basisextender: bc, } @@ -118,20 +120,6 @@ func newTestEncryptorWithKeyedPRNG(params ParameterProvider, key EncryptionKey, return enc } -// type encryptorBuffers struct { -// buffQP [3]ringqp.Poly -// } - -// func newEncryptorBuffers(params Parameters) *encryptorBuffers { -// return &encryptorBuffers{ -// buffQP: [3]ringqp.Poly{ -// params.RingQP().NewPoly(), -// params.RingQP().NewPoly(), -// params.RingQP().NewPoly(), -// }, -// } -// } - // Encrypt encrypts the input plaintext using the stored encryption key and writes the result on ct. // The method currently accepts only *[Ciphertext] as ct. // If a [Plaintext] is given, then the output [Ciphertext] [MetaData] will match the [Plaintext] [MetaData]. diff --git a/core/rlwe/rlwe_test.go b/core/rlwe/rlwe_test.go index 733d4ad9..1dea6762 100644 --- a/core/rlwe/rlwe_test.go +++ b/core/rlwe/rlwe_test.go @@ -39,10 +39,9 @@ func testString(params Parameters, levelQ, levelP, bpw2 int, opname string) stri // If such a modification is intended, this test must be updated and users notified s.t. // old serialized objects can be converted to the new format. func TestRLWEConstSerialization(t *testing.T) { - t.Skip() // Note: changing nbIteration will change the expected value const nbIteration = 10 - const expected = "/mTt2kB+03NdOMoI1msW+glCZmrF1sxEGQkFsC6P1SA=" + const expected = "rlzKK0ti5MY4b2nJ9iPKFGHVoZI2w9Hr9doLdIreahM=" var err error defaultParamsLiteral := testInsecure seedKeyGen := []byte{'l', 'a', 't'} diff --git a/ring/sampler_gaussian.go b/ring/sampler_gaussian.go index b154b2ed..0ca2becc 100644 --- a/ring/sampler_gaussian.go +++ b/ring/sampler_gaussian.go @@ -72,7 +72,7 @@ func (g *GaussianSampler) read(pol Poly, f func(a, b, c uint64) uint64) { r := g.baseRing - randomBufferN := make([]byte, 4*r.N()) + randomBufferN := make([]byte, 1024) var ptr int level := r.level diff --git a/ring/sampler_ternary.go b/ring/sampler_ternary.go index fd3c6d39..0334b5a2 100644 --- a/ring/sampler_ternary.go +++ b/ring/sampler_ternary.go @@ -22,6 +22,7 @@ type TernarySampler struct { // NewTernarySampler creates a new instance of TernarySampler from a PRNG, the ring definition and the distribution // parameters (see type Ternary). If "montgomery" is set to true, polynomials read from this sampler are in Montgomery form. +// WARNING: If the PRNG is deterministic/keyed (of type [sampling.KeyedPRNG]), *concurrent* calls to the sampler will not necessarily result in a deterministic output. func NewTernarySampler(prng sampling.PRNG, baseRing *Ring, X Ternary, montgomery bool) (ts *TernarySampler, err error) { ts = new(TernarySampler) ts.baseSampler = &baseSampler{}