dedis/prifi

Fix the neff shuffle

Opened this issue · 1 comments

We need the kyber v2 library to support it on gopkg.in, then courtesy from Alejandro:

package main

import (
	"encoding/hex"
	"fmt"
	"github.com/dedis/kyber"
	"github.com/dedis/kyber/proof"
	"github.com/dedis/kyber/shuffle"
	"github.com/dedis/kyber/suites"
	"github.com/lbarman/prifi/prifi-lib/crypto"
	//"gopkg.in/dedis/kyber.v2"
	//"gopkg.in/dedis/kyber.v2/suites"
	//"gopkg.in/dedis/kyber.v2/proof/dleq"
)

func main() {
	//var err error
	var suite = suites.MustFind("Ed25519")
	rand := suite.RandomStream()
	k := 5
	N := 10

	H, h := crypto.NewKeyPair()

	c := make([]kyber.Scalar, k) //prv
	C := make([]kyber.Point, k)  // pbl

	for i := 0; i < k; i++ {
		C[i], c[i] = crypto.NewKeyPair()
	}

	X := make([]kyber.Point, k)
	Y := make([]kyber.Point, k)
	r := suite.Scalar() // temporary
	for i := 0; i < k; i++ {
		r.Pick(rand)
		X[i] = suite.Point().Mul(r, nil)
		Y[i] = suite.Point().Mul(r, H) // ElGamal blinding factor
		Y[i].Add(Y[i], C[i])           // Encrypted client public key
	}

	for i := 0; i < N; i++ {
		// Do a key-shuffle
		Xbar, Ybar, prover := shuffle.Shuffle(suite, nil, H, X, Y, rand)
		prf, err := proof.HashProve(suite, "PairShuffle", prover)
		if err != nil {
			panic("Shuffle proof failed: " + err.Error())
		}
		fmt.Printf("proof:\n%s\n", hex.Dump(prf))

		fmt.Printf("%v", h) // here to avoid golang yelling

		// Check it
		verifier := shuffle.Verifier(suite, nil, H, X, Y, Xbar, Ybar)
		err = proof.HashVerify(suite, "PairShuffle", verifier, prf)
		if err != nil {
			panic("Shuffle verify failed: " + err.Error())
		}
	}
}