swisspost-evoting-go-poc/pkg/returncodes/codes.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

39 lines
1.2 KiB
Go

package returncodes
import (
"encoding/hex"
"math/big"
"github.com/user/evote/pkg/hash"
emath "github.com/user/evote/pkg/math"
)
// GenerateShortCode generates a short human-readable return code from a GqElement.
func GenerateShortCode(value emath.GqElement) string {
hashBytes := hash.RecursiveHash(hash.HashableBigInt{Value: value.Value()})
// Take first 4 bytes and encode as hex for a short code
return hex.EncodeToString(hashBytes[:4])
}
// ComputeLCCValue computes the long choice return code value from partial choice return codes.
// lCC = H(pC, vcID, eeID, tau)
func ComputeLCCValue(pC emath.GqElement, vcID, eeID string, tau *big.Int) *big.Int {
return hash.RecursiveHashToZq(
pC.Group().Q(),
hash.HashableBigInt{Value: pC.Value()},
hash.HashableString{Value: vcID},
hash.HashableString{Value: eeID},
hash.HashableBigInt{Value: tau},
)
}
// ComputeLVCCValue computes the long vote cast return code value.
// lVCC = H(pVCC, vcID, eeID)
func ComputeLVCCValue(pVCC emath.GqElement, vcID, eeID string) *big.Int {
return hash.RecursiveHashToZq(
pVCC.Group().Q(),
hash.HashableBigInt{Value: pVCC.Value()},
hash.HashableString{Value: vcID},
hash.HashableString{Value: eeID},
)
}