From 69c60e90d5c08328dcb08ffee1477244fbe4a24e Mon Sep 17 00:00:00 2001 From: Piotr Dyraga Date: Thu, 24 May 2018 19:02:01 +0200 Subject: [PATCH] Do not cache N^2 value in PublicKey Let's keep this structure clean. Computing N^2 is just a really small piece of encryption/decryption work and if we decide we need to tweak performance, we will need a different approach anyway. --- encoding_test.go | 2 +- paillier.go | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/encoding_test.go b/encoding_test.go index 660a5e2..1bb9a1c 100644 --- a/encoding_test.go +++ b/encoding_test.go @@ -118,6 +118,6 @@ func TestPartialDecryptionZKPBSONification(t *testing.T) { } func TestThresholdKeyBSON(t *testing.T) { - key := &ThresholdKey{PublicKey{b(9), b(8), nil}, 7, 6, b(3), []*big.Int{b(2), b(34)}} + key := &ThresholdKey{PublicKey{b(9), b(8)}, 7, 6, b(3), []*big.Int{b(2), b(34)}} AssertBSONIsGood(key, new(ThresholdKey), t) } diff --git a/paillier.go b/paillier.go index 134a0f4..df22c7d 100644 --- a/paillier.go +++ b/paillier.go @@ -8,7 +8,6 @@ import ( type PublicKey struct { N, G *big.Int // usually G is set to N+1 - n2 *big.Int // the cache value of N^2 } func (this *PublicKey) GetBSON() (interface{}, error) { @@ -19,11 +18,7 @@ func (this *PublicKey) GetBSON() (interface{}, error) { } func (this *PublicKey) GetNSquare() *big.Int { - if this.n2 != nil { - return this.n2 - } - this.n2 = new(big.Int).Mul(this.N, this.N) - return this.n2 + return new(big.Int).Mul(this.N, this.N) } // Encode a plaintext in a cypher one. The plain text must be smaller that