swisspost-evoting-go-poc/pkg/hash/hashandsquare.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

25 lines
778 B
Go

package hash
import (
"math/big"
emath "github.com/user/evote/pkg/math"
)
// HashAndSquare hashes a value x to a GqElement by:
// 1. Computing h = RecursiveHashToZq(q, "HashAndSquare", x)
// 2. Adding 1: h_plus_one = h + 1
// 3. Squaring: result = (h+1)^2 mod p (guaranteed to be in G_q)
func HashAndSquare(x *big.Int, group *emath.GqGroup) emath.GqElement {
q := group.Q()
// Hash to Z_q with "HashAndSquare" label
h := RecursiveHashToZq(q, HashableString{Value: "HashAndSquare"}, HashableBigInt{Value: x})
// Add 1
hPlusOne := new(big.Int).Add(h, big.NewInt(1))
// Square mod p to get element of G_q
elem, err := emath.GqElementFromSquareRoot(hPlusOne, group)
if err != nil {
panic("HashAndSquare: failed to create GqElement: " + err.Error())
}
return elem
}