mirror of
https://github.com/saymrwulf/swisspost-evoting-go-poc.git
synced 2026-05-14 20:58:03 +00:00
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.
25 lines
778 B
Go
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
|
|
}
|