From 27dcab18e0360f6d94c998ac9e6a2239572661f5 Mon Sep 17 00:00:00 2001 From: Piotr Dyraga Date: Fri, 25 May 2018 12:57:13 +0200 Subject: [PATCH] Do not export internal threshold generator functions --- thresholdkey_generator.go | 70 +++++++++++++++++----------------- thresholdkey_generator_test.go | 40 +++++++++---------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/thresholdkey_generator.go b/thresholdkey_generator.go index 0451674..3d9a44f 100644 --- a/thresholdkey_generator.go +++ b/thresholdkey_generator.go @@ -44,7 +44,7 @@ type ThresholdKeyGenerator struct { polynomialCoefficients []*big.Int } -// Preferable way to construct the ThresholdKeyGenerator. No verification +// Preferable way to construct the ThresholdKeyGenerator. No verification // is done on the input values. You need to be sure that nbits is big enough // and that Threshold > TotalNumberOfDecryptionServers / 2. // The plaintext space for the key will be Z_n. @@ -57,23 +57,23 @@ func GetThresholdKeyGenerator(nbits, TotalNumberOfDecryptionServers, Threshold i return ret } -func (this *ThresholdKeyGenerator) GenerateSafePrimes() (*big.Int, *big.Int, error) { +func (this *ThresholdKeyGenerator) generateSafePrimes() (*big.Int, *big.Int, error) { return GenerateSafePrimes(this.nbits, this.Random) } -func (this *ThresholdKeyGenerator) InitPandP1() error { +func (this *ThresholdKeyGenerator) initPandP1() error { var err error - this.p, this.p1, err = this.GenerateSafePrimes() + this.p, this.p1, err = this.generateSafePrimes() return err } -func (this *ThresholdKeyGenerator) InitQandQ1() error { +func (this *ThresholdKeyGenerator) initQandQ1() error { var err error - this.q, this.q1, err = this.GenerateSafePrimes() + this.q, this.q1, err = this.generateSafePrimes() return err } -func (this *ThresholdKeyGenerator) InitShortcuts() { +func (this *ThresholdKeyGenerator) initShortcuts() { this.n = new(big.Int).Mul(this.p, this.q) this.m = new(big.Int).Mul(this.p1, this.q1) this.nSquare = new(big.Int).Mul(this.n, this.n) @@ -81,7 +81,7 @@ func (this *ThresholdKeyGenerator) InitShortcuts() { } -func (this *ThresholdKeyGenerator) ArePsAndQsGood() bool { +func (this *ThresholdKeyGenerator) arePsAndQsGood() bool { if this.p.Cmp(this.q) == 0 { return false } @@ -94,21 +94,21 @@ func (this *ThresholdKeyGenerator) ArePsAndQsGood() bool { return true } -func (this *ThresholdKeyGenerator) InitPsAndQs() error { - if err := this.InitPandP1(); err != nil { +func (this *ThresholdKeyGenerator) initPsAndQs() error { + if err := this.initPandP1(); err != nil { return err } - if err := this.InitQandQ1(); err != nil { + if err := this.initQandQ1(); err != nil { return err } - if !this.ArePsAndQsGood() { - return this.InitPsAndQs() + if !this.arePsAndQsGood() { + return this.initPsAndQs() } return nil } // v generates a cyclic group of squares in Zn^2. -func (this *ThresholdKeyGenerator) ComputeV() error { +func (this *ThresholdKeyGenerator) computeV() error { var err error this.v, err = GetRandomGeneratorOfTheQuadraticResidue(this.nSquare, this.Random) return err @@ -138,18 +138,18 @@ func (this *ThresholdKeyGenerator) ComputeV() error { // z2 = m^-1 mod n // // x = a2*y2*z2 = 1 * m * [m^-1 mod n] -func (this *ThresholdKeyGenerator) InitD() { +func (this *ThresholdKeyGenerator) initD() { mInverse := new(big.Int).ModInverse(this.m, this.n) this.d = new(big.Int).Mul(mInverse, this.m) } -func (this *ThresholdKeyGenerator) InitNumerialValues() error { - if err := this.InitPsAndQs(); err != nil { +func (this *ThresholdKeyGenerator) initNumerialValues() error { + if err := this.initPsAndQs(); err != nil { return err } - this.InitShortcuts() - this.InitD() - return this.ComputeV() + this.initShortcuts() + this.initD() + return this.computeV() } // f(X) = a_0 X^0 + a_1 X^1 + ... + a_(w-1) X^(w-1) @@ -158,7 +158,7 @@ func (this *ThresholdKeyGenerator) InitNumerialValues() error { // `w` - threshold // `a_i` - random value from {0, ... nm - 1} for 0