ThresholdKey renamed to ThresholdPublicKey

This commit is contained in:
Piotr Dyraga committed 2018-06-01 21:36:04 +02:00
1 parent 86b9f01f99
commit 9d17da0d33
4 files changed
+39 -39

No files matched your search

+19 -19
View File
@@ -23,7 +23,7 @@ import (
// A Generalization of Paillier’s Public-Key System
// with Applications to Electronic Voting
// Aarhus University, Dept. of Computer Science, BRICS
type ThresholdKey struct {
type ThresholdPublicKey struct {
PublicKey
TotalNumberOfDecryptionServers int
Threshold int
@@ -34,21 +34,21 @@ type ThresholdKey struct {
// Returns the value of [(4*delta^2)]^-1 mod n.
// It is a constant value for the given `ThresholdKey` and is used in the last
// step of share combining.
func (tk *ThresholdKey) combineSharesConstant() *big.Int {
func (tk *ThresholdPublicKey) combineSharesConstant() *big.Int {
tmp := new(big.Int).Mul(FOUR, new(big.Int).Mul(tk.delta(), tk.delta()))
return (&big.Int{}).ModInverse(tmp, tk.N)
}
// Returns the factorial of the number of `TotalNumberOfDecryptionServers`.
// It is a contant value for the given `ThresholdKey`.
func (tk *ThresholdKey) delta() *big.Int {
func (tk *ThresholdPublicKey) delta() *big.Int {
return Factorial(tk.TotalNumberOfDecryptionServers)
}
// Checks if the number of received, unique shares is less than the
// required threshold.
// This method does not execute ZKP on received shares.
func (tk *ThresholdKey) makeVerificationBeforeCombiningPartialDecryptions(shares []*PartialDecryption) error {
func (tk *ThresholdPublicKey) makeVerificationBeforeCombiningPartialDecryptions(shares []*PartialDecryption) error {
if len(shares) < tk.Threshold {
return errors.New("Threshold not meet")
}
@@ -62,7 +62,7 @@ func (tk *ThresholdKey) makeVerificationBeforeCombiningPartialDecryptions(shares
return nil
}
func (tk *ThresholdKey) updateLambda(share1, share2 *PartialDecryption, lambda *big.Int) *big.Int {
func (tk *ThresholdPublicKey) updateLambda(share1, share2 *PartialDecryption, lambda *big.Int) *big.Int {
num := new(big.Int).Mul(lambda, big.NewInt(int64(-share2.Id)))
denom := big.NewInt(int64(share1.Id - share2.Id))
return new(big.Int).Div(num, denom)
@@ -70,7 +70,7 @@ func (tk *ThresholdKey) updateLambda(share1, share2 *PartialDecryption, lambda *
// Evaluates lambda parameter for each decrypted share. See second figure in the
// "Share combining" paragraph in [DJK 10], section 5.2.
func (tk *ThresholdKey) computeLambda(share *PartialDecryption, shares []*PartialDecryption) *big.Int {
func (tk *ThresholdPublicKey) computeLambda(share *PartialDecryption, shares []*PartialDecryption) *big.Int {
lambda := tk.delta()
for _, share2 := range shares {
if share2.Id != share.Id {
@@ -90,14 +90,14 @@ func (tk *ThresholdKey) computeLambda(share *PartialDecryption, shares []*Partia
// following property of modulo:
// (AB) mod C = (A mod C * B mod C) mod C
// Note, we need to combine coefficients into single c'.
func (tk *ThresholdKey) updateCprime(cprime, lambda *big.Int, share *PartialDecryption) *big.Int {
func (tk *ThresholdPublicKey) updateCprime(cprime, lambda *big.Int, share *PartialDecryption) *big.Int {
twoLambda := new(big.Int).Mul(TWO, lambda)
ret := tk.exp(share.Decryption, twoLambda, tk.GetNSquare())
ret = new(big.Int).Mul(cprime, ret)
return new(big.Int).Mod(ret, tk.GetNSquare())
}
func (tk *ThresholdKey) exp(a, b, c *big.Int) *big.Int {
func (tk *ThresholdPublicKey) exp(a, b, c *big.Int) *big.Int {
if b.Cmp(ZERO) == -1 {
ret := new(big.Int).Exp(a, new(big.Int).Neg(b), c)
return new(big.Int).ModInverse(ret, c)
@@ -108,7 +108,7 @@ func (tk *ThresholdKey) exp(a, b, c *big.Int) *big.Int {
// Executes the last step of message decryption. Takes `cprime` value computed
// from valid shares provided by decryption servers and multiplies this value
// by `combineSharesContant` which is specific to the given public `ThresholdKey`.
func (tk *ThresholdKey) computeDecryption(cprime *big.Int) *big.Int {
func (tk *ThresholdPublicKey) computeDecryption(cprime *big.Int) *big.Int {
l := L(cprime, tk.N)
return new(big.Int).Mod(new(big.Int).Mul(tk.combineSharesConstant(), l), tk.N)
}
@@ -117,7 +117,7 @@ func (tk *ThresholdKey) computeDecryption(cprime *big.Int) *big.Int {
// decrypted message.
// This function does not verify zero knowledge proofs. Returned message can be
// incorrectly decrypted if an adversary corrupted partial decryption.
func (tk *ThresholdKey) CombinePartialDecryptions(shares []*PartialDecryption) (*big.Int, error) {
func (tk *ThresholdPublicKey) CombinePartialDecryptions(shares []*PartialDecryption) (*big.Int, error) {
if err := tk.makeVerificationBeforeCombiningPartialDecryptions(shares); err != nil {
return nil, err
}
@@ -135,7 +135,7 @@ func (tk *ThresholdKey) CombinePartialDecryptions(shares []*PartialDecryption) (
// decrypted message.
// Function verifies zero knowledge proofs and filters out all shares that failed
// verification.
func (tk *ThresholdKey) CombinePartialDecryptionsZKP(shares []*PartialDecryptionZKP) (*big.Int, error) {
func (tk *ThresholdPublicKey) CombinePartialDecryptionsZKP(shares []*PartialDecryptionZKP) (*big.Int, error) {
ret := make([]*PartialDecryption, 0)
for _, share := range shares {
if share.Verify() {
@@ -149,7 +149,7 @@ func (tk *ThresholdKey) CombinePartialDecryptionsZKP(shares []*PartialDecryption
// It verifies all the zero-knoledge proofs, the value of the encrypted
// and decrypted message. The method returns `nil` if everything is fine.
// Otherwise, it returns an explicative message.
func (tk *ThresholdKey) VerifyDecryption(encryptedMessage, decryptedMessage *big.Int, shares []*PartialDecryptionZKP) error {
func (tk *ThresholdPublicKey) VerifyDecryption(encryptedMessage, decryptedMessage *big.Int, shares []*PartialDecryptionZKP) error {
for _, share := range shares {
if share.C.Cmp(encryptedMessage) != 0 {
return errors.New("The encrypted message is not the same than the one in the shares")
@@ -170,7 +170,7 @@ func (tk *ThresholdKey) VerifyDecryption(encryptedMessage, decryptedMessage *big
// `Id` is the unique identifier of a decryption server and `Share` is a secret
// share generated from hiding polynomial and is used for a partial share decryption.
type ThresholdPrivateKey struct {
ThresholdKey
ThresholdPublicKey
Id int
Share *big.Int
}
@@ -193,8 +193,8 @@ func (tpk *ThresholdPrivateKey) copyVi() []*big.Int {
return ret
}
func (tpk *ThresholdPrivateKey) getThresholdKey() *ThresholdKey {
ret := new(ThresholdKey)
func (tpk *ThresholdPrivateKey) getThresholdKey() *ThresholdPublicKey {
ret := new(ThresholdPublicKey)
ret.Threshold = tpk.Threshold
ret.TotalNumberOfDecryptionServers = tpk.TotalNumberOfDecryptionServers
ret.V = new(big.Int).Add(tpk.V, big.NewInt(0))
@@ -325,10 +325,10 @@ type PartialDecryption struct {
// - Compare ZKP hash with the one just computed
type PartialDecryptionZKP struct {
PartialDecryption
Key *ThresholdKey // the public key used to encrypt
E *big.Int // the challenge
Z *big.Int // the value needed to check to verify the decryption
C *big.Int // the input cypher text
Key *ThresholdPublicKey // the public key used to encrypt
E *big.Int // the challenge
Z *big.Int // the value needed to check to verify the decryption
C *big.Int // the input cypher text
}
func (pd *PartialDecryptionZKP) verifyPart1() *big.Int {