swisspost-evoting-go-poc/pkg/mixnet/shuffle.go
saymrwulf e8b6f30871 Swiss Post E-Voting Go PoC
Proof-of-concept reimplementation of the Swiss Post e-voting
cryptographic protocol in Go. Single binary, 52 source files,
2 dependencies. Covers ElGamal encryption, Bayer-Groth verifiable
shuffles, zero-knowledge proofs, return codes, and a full
election ceremony demo.
2026-02-13 19:53:09 +01:00

38 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package mixnet
import (
"github.com/user/evote/pkg/elgamal"
emath "github.com/user/evote/pkg/math"
)
// Shuffle holds the result of a re-encrypting shuffle.
type Shuffle struct {
Shuffled *elgamal.CiphertextVector // C' shuffled ciphertexts
Perm Permutation // π permutation used
Rho *emath.ZqVector // ρ re-encryption exponents
}
// GenShuffle performs a re-encrypting shuffle on ciphertexts.
// C'_i = Enc(1; rho_i, pk) * C_{pi(i)}
func GenShuffle(cts *elgamal.CiphertextVector, pk elgamal.PublicKey) Shuffle {
n := cts.Size()
zqGroup := emath.ZqGroupFromGqGroup(pk.Group())
perm := GenPermutation(n)
rhoElems := make([]emath.ZqElement, n)
shuffled := make([]elgamal.Ciphertext, n)
for i := 0; i < n; i++ {
rhoElems[i] = emath.RandomZqElement(zqGroup)
// Enc(1; rho_i, pk)
enc := elgamal.EncryptOnes(rhoElems[i], pk)
// C'_i = enc * C_{pi(i)}
shuffled[i] = enc.Multiply(cts.Get(perm.Apply(i)))
}
return Shuffle{
Shuffled: elgamal.NewCiphertextVector(shuffled),
Perm: perm,
Rho: emath.ZqVectorOf(rhoElems...),
}
}