swisspost-evoting-go-poc/pkg/party/phases.go
saymrwulf 127ae61d11 Cast-as-intended return codes: CC extraction + voter check
The return code the voter checks is now genuinely computed by the CCs from the
submitted ciphertext, not looked up from the card:

- returncode_extract.go: after a ballot is accepted, the server asks each CC to
  exponentiate E2 by its return-code key (product over CCs = Enc(vote^Σk)), then
  each CC contributes a partial-decryption factor; the server recovers vote^Σk,
  which equals the card base prime_sel^Σk, and looks up the short code.
- The server returns that code to the voter, who checks it against the card for
  the chosen option; a mismatch aborts with a clear error.

Soundness test: a malicious client that encrypts option A for the tally (E1) but
option B in the return-code channel (E2) is REJECTED by the plaintext-equality
proof — so the code shown always reflects the tallied vote. This closes the
cast-as-intended gap (the old return codes were decorative, finding F16).

Card lCC now uses a fixed tau so extraction can recompute it without learning
the option up front.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 15:52:30 +02:00

59 lines
1.7 KiB
Go

package party
import (
"fmt"
"github.com/user/evote/pkg/transport"
)
// Phase message handlers. These are filled in incrementally (setup, then
// voting, then tally). Until a phase is implemented its handler rejects unknown
// message types cleanly rather than panicking — the transport boundary must
// never crash on an unexpected message.
func (p *SetupComponent) handleSetupMsg(env *transport.Envelope) (*transport.Envelope, error) {
return nil, fmt.Errorf("%s: unhandled message type %q", p.id.Name, env.Type)
}
func (p *ControlComponent) handleCCMsg(env *transport.Envelope) (*transport.Envelope, error) {
switch env.Type {
case MsgGenCCKeys:
return p.handleGenCCKeys(env)
case MsgLongCodeShareReq:
return p.handleLongCodeShare(env)
case MsgVerifyBallot:
return p.handleVerifyBallot(env)
case MsgShuffle:
return p.handleShuffle(env)
case MsgRCExpReq:
return p.handleRCExp(env)
case MsgRCDecReq:
return p.handleRCDec(env)
default:
return nil, fmt.Errorf("%s: unhandled message type %q", p.id.Name, env.Type)
}
}
func (p *ElectoralBoard) handleEBMsg(env *transport.Envelope) (*transport.Envelope, error) {
switch env.Type {
case MsgGenEBKey:
return p.handleGenEBKey(env)
case MsgFinalMix:
return p.handleFinalMix(env)
default:
return nil, fmt.Errorf("%s: unhandled message type %q", p.id.Name, env.Type)
}
}
func (p *VotingServer) handleServerMsg(env *transport.Envelope) (*transport.Envelope, error) {
switch env.Type {
case MsgMappingTable:
return p.handleMappingTable(env)
case MsgCastBallot:
return p.handleCastBallot(env)
case MsgStartTally:
return p.handleStartTally(env)
default:
return nil, fmt.Errorf("%s: unhandled message type %q", p.id.Name, env.Type)
}
}