diff --git a/thresholdkey_generator.go b/thresholdkey_generator.go index 5e6e1c3..1dab199 100644 --- a/thresholdkey_generator.go +++ b/thresholdkey_generator.go @@ -57,60 +57,59 @@ func GetThresholdKeyGenerator(nbits, TotalNumberOfDecryptionServers, Threshold i return ret } -func (this *ThresholdKeyGenerator) generateSafePrimes() (*big.Int, *big.Int, error) { - return GenerateSafePrimes(this.nbits, this.Random) +func (tkg *ThresholdKeyGenerator) generateSafePrimes() (*big.Int, *big.Int, error) { + return GenerateSafePrimes(tkg.nbits, tkg.Random) } -func (this *ThresholdKeyGenerator) initPandP1() error { +func (tkg *ThresholdKeyGenerator) initPandP1() error { var err error - this.p, this.p1, err = this.generateSafePrimes() + tkg.p, tkg.p1, err = tkg.generateSafePrimes() return err } -func (this *ThresholdKeyGenerator) initQandQ1() error { +func (tkg *ThresholdKeyGenerator) initQandQ1() error { var err error - this.q, this.q1, err = this.generateSafePrimes() + tkg.q, tkg.q1, err = tkg.generateSafePrimes() return err } -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) - this.nm = new(big.Int).Mul(this.n, this.m) - +func (tkg *ThresholdKeyGenerator) initShortcuts() { + tkg.n = new(big.Int).Mul(tkg.p, tkg.q) + tkg.m = new(big.Int).Mul(tkg.p1, tkg.q1) + tkg.nSquare = new(big.Int).Mul(tkg.n, tkg.n) + tkg.nm = new(big.Int).Mul(tkg.n, tkg.m) } -func (this *ThresholdKeyGenerator) arePsAndQsGood() bool { - if this.p.Cmp(this.q) == 0 { +func (tkg *ThresholdKeyGenerator) arePsAndQsGood() bool { + if tkg.p.Cmp(tkg.q) == 0 { return false } - if this.p.Cmp(this.q1) == 0 { + if tkg.p.Cmp(tkg.q1) == 0 { return false } - if this.p1.Cmp(this.q) == 0 { + if tkg.p1.Cmp(tkg.q) == 0 { return false } return true } -func (this *ThresholdKeyGenerator) initPsAndQs() error { - if err := this.initPandP1(); err != nil { +func (tkg *ThresholdKeyGenerator) initPsAndQs() error { + if err := tkg.initPandP1(); err != nil { return err } - if err := this.initQandQ1(); err != nil { + if err := tkg.initQandQ1(); err != nil { return err } - if !this.arePsAndQsGood() { - return this.initPsAndQs() + if !tkg.arePsAndQsGood() { + return tkg.initPsAndQs() } return nil } // v generates a cyclic group of squares in Zn^2. -func (this *ThresholdKeyGenerator) computeV() error { +func (tkg *ThresholdKeyGenerator) computeV() error { var err error - this.v, err = GetRandomGeneratorOfTheQuadraticResidue(this.nSquare, this.Random) + tkg.v, err = GetRandomGeneratorOfTheQuadraticResidue(tkg.nSquare, tkg.Random) return err } @@ -138,18 +137,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() { - mInverse := new(big.Int).ModInverse(this.m, this.n) - this.d = new(big.Int).Mul(mInverse, this.m) +func (tkg *ThresholdKeyGenerator) initD() { + mInverse := new(big.Int).ModInverse(tkg.m, tkg.n) + tkg.d = new(big.Int).Mul(mInverse, tkg.m) } -func (this *ThresholdKeyGenerator) initNumerialValues() error { - if err := this.initPsAndQs(); err != nil { +func (tkg *ThresholdKeyGenerator) initNumerialValues() error { + if err := tkg.initPsAndQs(); err != nil { return err } - this.initShortcuts() - this.initD() - return this.computeV() + tkg.initShortcuts() + tkg.initD() + return tkg.computeV() } // f(X) = a_0 X^0 + a_1 X^1 + ... + a_(w-1) X^(w-1) @@ -158,12 +157,12 @@ func (this *ThresholdKeyGenerator) initNumerialValues() error { // `w` - threshold // `a_i` - random value from {0, ... nm - 1} for 0