forked from Concordium/electionguard-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TODO.txt
2837 lines (2357 loc) · 235 KB
/
TODO.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
====vvvv====vvvv====vvvv====vvvv====vvvv==== DONE ====vvvv====vvvv====vvvv====vvvv====vvvv====
electionguard.exe: common parameter: election filesystem directory to look for files (%ELECTIONGUARD_ARTIFACTS_DIR%)
electionguard.exe: seed: write random seed to artifact file
electionguard.exe manifest: write ElectionManifest to pretty json file
electionguard.exe manifest: write ElectionManifest to canonical bytes file
electionguard.exe parameters: write ElectionParameters to json file
H_V, H_P, H_M, and H_B updated for 2.0 calculation
Generate joint election public key
Extended base hash H_E
electionguard-test script: implementation in cmd started
electionguard-test script: implementation in cmd exercises all (current) functionality
BigUint values (mod p or q) now left-padded as necessary to avoid leaking value via serialized file size
Hash values now serialized with 'H(upper hex)' format to match spec
exe: Csprng now seeded with more entropy from the operating system RNG
Election-varying parameters (n and k) now checked for validity
Serialization of BigUints now uses base64 encoding
Rename guardian private key to secret key
electionguard.exe: generate guardian secret key
electionguard.exe: write guardian secret key
electionguard.exe: derive guardian public key from secret key
electionguard.exe: write guardian public key
Guardian i uses 1-based indexing
compute H_E extended base hash
compute joint election public key
electionguard.exe: write joint election public key to json file
standardize on 'validate' instead of 'verify' when checking deserialized structures
instead of from_json and to_json implement from_stdioread and to_stdiowrite
every struct that has Self::from_stdioread*() should prefer Self::from_stdioread_validated() and have a self.validate()
electionguard.exe: write H_E extended base hash to json file
convert many uses of if !() { bail!() } to ensure!()
Generate data structure docs from the Reference Implementation in Rust
eg: New constrained numeric type for indices. Convert n, k, and other indices to this type.
build-docs script: initial implementation in cmd
evaluate scripting language 'nu' https://www.nushell.sh/
electionguard-test script: begin rewrite in nu
doc/LICENSE: checked
doc/SECURITY.md: complete
docs/general: begin writing
docs/api: begin writing
Remove link to internal site
VaryingParameters: enum BallotChaining { Prohibited, Allowed, Required, }
remove old EG 1.54 constants
exe: Under artifacts dir, first level dirs are specific to secrecy requirements
Ballot define data type
get fixeduint stuff out of bunna branch
Merge code from Anunay
doc/SUPPORT.md: complete
doc/README.md: complete
doc/CODE_OF_CONDUCT.md: complete
doc/BUILDING.md: complete
Complete all planned code reorganization/renaming
docs/implementation guide/References: complete
====^^^^====^^^^====^^^^====^^^^====^^^^==== DONE merged to main ====^^^^====^^^^====^^^^====^^^^====^^^^====
Add .errorviz-version to .gitignore
incorporate the latex of egds2.0 into todo.txt
add todo.txt to repo
serialize bignums only all as uppercase hex
serialize bignums includes base e.g., "base16:f81e2b3..."
====^^^^====^^^^====^^^^====^^^^====^^^^==== locally committed ====^^^^====^^^^====^^^^====^^^^====^^^^====
====vvvv====vvvv====vvvv====vvvv====vvvv==== TODO general ====vvvv====vvvv====vvvv====vvvv====vvvv====
UG left pad as necessary to ensure length is correct
serialize format wrapped in version
ensure SecretCoefficient is serialized in a fixed-length format
electionguard-test script: finish rewrite in nu
Election parameters: add a type field initally set to 'HomomorphicTallying'
a trait for fn to_canonical_json()
[Security: out of scope] TOCTOU bug with --insecure-deterministic flag electionguard.exe main.rs. Should be fixed, but in practice if that filesystem is writable by a malicious party then you likely have much, much bigger concerns.
build-docs script: finish rewrite in nu
electionguard-test script: incorporate ballots
electionguard-test script: incorporate tally
Build on Linux64
Test on Linux64
new electionguard-testdata.exe tool example_election_manifest
new electionguard-testdata.exe tool generates test data, example_election_manifest
new electionguard-testdata.exe tool does validate-standard-parameters
docs/general: style sheet for markdown, ideally match API docs
If an overvote occurs, the overvote must be captured, encrypted, and never decrypted.
docs/specs/serialization: data formats section
docs/specs/serialization: standards and references section
docs/specs/serialization: election manifest section
docs/specs/serialization: election record section
docs/specs/serialization: vendor data section
docs/implementation guide/Requirements for election systems vendors: complete
docs/implementation guide/Requirements for verifier app authors: complete
docs/implementation guide/roles: consider splitting into separate pages: complete
docs/implementation guide/roles/Election Administrator: complete
docs/implementation guide/roles/Election Guardians: complete
docs/implementation guide/roles/Voters: complete
docs/implementation guide/roles/Political parties and voter-interest organizations: complete
docs/implementation guide/roles/Journalists and other media: complete
docs/implementation guide/Hardware requirements/Gurardian secret key storage: complete
docs/implementation guide/Hardware requirements/Gurardian secret key operations: complete
docs/implementation guide/step-by-step/Advance preparation: complete
docs/implementation guide/step-by-step/Key ceremony: complete
docs/implementation guide/step-by-step/Tally ceremony: complete
docs/implementation guide/step-by-step/Publishing: complete
docs/implementation guide/step-by-step/Verification: complete
docs/implementation guide/step-by-step/Reporting: complete
docs/api: use correct logo
docs/api: complete
docs: complete, #![warn(missing_docs)]
doc: upload docs to github pages (see compliance notes)
security review: ensure that no file leaks info through filesize
====----====----====----====----==== milestone: "alpha" release ====----====----====----====----====
alpha testing
====----====----====----====----==== milestone: "beta" release ====----====----====----====----====
beta testing
#![warn(missing_doc_code_examples)]
#![warn(missing_debug_implementations)]
#![warn(missing_copy_implementations)]
#![warn(unused_doc_comments)]
distinguish between PartySelection, BallotMeasureSelection, CandidateSelection
open issues for any remaining TODO items for 1.0
====----====----====----====----==== milestone: "1.0" release ====----====----====----====----====
BallotDefinition doc for write-in option
would be nice to support a PartySelection type vote, rather than rely on the vendor to give us the correct selections explicitly
many to_stdiowrite() methods have common code that could be factored into a common function
a trait for types that have to_stdiowrite()
a trait for types that have to_stdiowrite() and perhaps _pretty() and _canonical() variants
a trait for types that have pub fn validate(&Self)
a trait for types that have pub fn validate(&Self, &ElectionParameters)
docs: more investigation into using rust modules to build documentation along with api, observe how cargo_crev does it with the include_str! macro: https://github.com/crev-dev/cargo-crev/blob/master/cargo-crev/src/doc/mod.rs
docs: more investigation into using mdbook for all project documentation https://github.com/rust-lang/rust/issues/66249
docs: cargo-external-doc is nice but doesn't support virtual manifests https://github.com/Geal/cargo-external-doc
VaryingParameters (n, k) This isn't really an 'index' (ordinal), it's a cardinal number. Maybe we need a general purpose ranged number type.
exe: common parameter: election filesystem directory to look for files (%ELECTIONGUARD_ARTIFACTS_DIR%)
exe: common parameter: manifest file
exe: common parameter: others
exe: create artifact directories if they don't exist. q: what about permissions on guardian secret directories?
exe: read guardian secret key, print info, suppressing secrets in secret key
exe: read guardian public key, print info
Proof of valid decryption
design: document
design: define standard election directory layout - look at other implementers and users
design: key file represents its kind: guardian, ..., ?
Consider structures defined in JSON schema https://github.com/usnistgov/ElectionResultsReporting/blob/version2/NIST_V2_election_results_reporting.json
if electionguard.exe fails to read or write a file, check the path to see if it has a leading ~. If so, print a good error message.
test on 32-bit target such as x86 or wasm32
test on big-endian target such as powerpc64-unknown-linux-gnu, s390x-unknown-linux-gnu, riscv64gc-unknown-linux-gnu, or loongarch64-unknown-linux-gnu
docs/api: reference NIST CDF where types clearly correspond. E.g., BallotStyle https://github.com/usnistgov/ElectionResultsReporting/blob/nist-pages/index.md#17_0_2_4_78e0236_1389366224561_797289_2360
====vvvv====vvvv====vvvv====vvvv====vvvv==== TODO EG 2.0 Design Specification text ====vvvv====vvvv====vvvv====vvvv====vvvv====
%%%%%%%%%%%%% The plan here is to chop up the specification text and extract statements that can be translate into test cases
\newcommand{\C}{\mathbb{C}}
\newcommand{\F}{\mathbb{F}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Bcal}{\mathcal{B}}
\newcommand{\Ccal}{\mathcal{C}}
\newcommand{\Ecal}{\mathcal{E}}
\newcommand{\Ocal}{\mathcal{O}}
\newcommand{\Scal}{\mathcal{S}}
\newcommand{\Mbar}{\overline{M}}
\newcommand{\len}{\mathrm{len}}
\newcommand{\B}{\mathrm{B}}
\newcommand{\HH}{\mathrm{H}}
\newcommand{\VV}{\mathrm{V}}
\newcommand{\styleScheme}[1]{\textsf{\upshape\mdseries #1}\xspace}
\newcommand{\EG}{\styleScheme{ElectionGuard}}
\newcommand{\KDF}{\styleScheme{KDF}}
\newcommand{\MAC}{\styleScheme{MAC}}
\newcommand{\styleAlgorithm}[1]{\textrm{\upshape\mdseries #1}\xspace}
\newcommand{\HMAC}{\styleAlgorithm{HMAC}}
\newcommand{\SHA}{\styleAlgorithm{SHA-256}}
\newcommand{\HMACSHA}{\styleAlgorithm{HMAC-SHA-256}}
\newcommand{\Enc}{\styleAlgorithm{Enc}}
\newcommand{\byte}{\texttt{byte}}
\newcommand{\str}{\texttt{string}}
\newcommand{\Str}[1]{\mathtt{``#1"}}
\newcommand{\arr}{\texttt{array}}
\newcommand{\Map}[2]{\texttt{finite map} (#1 $\mapsto$ #2)}
\newcommand{\map}{\texttt{finite map}}
\newcommand{\integer}{\texttt{integer}}
\newcommand{\intp}{\texttt{BigInt4096}}
\newcommand{\intq}{\texttt{BigInt256}}
\newcommand{\intr}{\texttt{BigInt3841}}
\newcommand{\bool}{\texttt{bool}}
\newcommand{\bytes}{\mathtt{b}}
\newcommand{\ind}{\mathtt{ind}}
\newcommand{\indc}{\mathtt{ind}_\mathtt{c}}
\newcommand{\indo}{\mathtt{ind}_\mathtt{o}}
\newcommand{\inds}{\mathtt{ind}_\mathtt{s}}
\newcommand\EGverif[2]{
\vspace{5pt}
\noindent\hspace{-7pt}\fcolorbox{darkgreen}{eggreen}{
\begin{minipage}{\textwidth}
\vspace{-4pt}
\setlength{\leftmargini}{0.38in}
\textcolor{egtextgreen}{\begin{verification}[#1] #2 \end{verification}}
\vspace{-4pt}
\end{minipage}
}\vspace{5pt}}
\newcommand\EGverifrepeat[3]{
\setcounterref{verification}{#1}
\addtocounter{verification}{-1}
\EGverif{#2}{#3}}
\newcommand\EGverifBallot[2]{
\vspace{5pt}
\noindent\hspace{-7pt}\fcolorbox{darkblue}{egblue}{
\begin{minipage}{\textwidth}
\vspace{-4pt}
\setlength{\leftmargini}{0.38in}
\textcolor{egtextblue}{\begin{verification}[#1] #2 \end{verification}}
\vspace{-4pt}
\end{minipage}
}\vspace{5pt}}
\newcommand\EGverifBallotrepeat[3]{
\setcounterref{verification}{#1}
\addtocounter{verification}{-1}
\EGverifBallot{#2}{#3}}
\newcommand\EGverifExtended[2]{
\vspace{5pt}
\noindent\hspace{-7pt}\fcolorbox{black}{egorange}{
\begin{minipage}{\textwidth}
\vspace{-4pt}
\setlength{\leftmargini}{0.38in}
\textcolor{egtextblue}{\begin{verification}[#1] #2 \end{verification}}
\vspace{-4pt}
\end{minipage}
}\vspace{5pt}}
\newcommand\EGverifExtendedrepeat[3]{
\setcounterref{verification}{#1}
\addtocounter{verification}{-1}
\EGverifExtended{#2}{#3}}
\newcommand\ertabular[2]{
\begin{center}
\renewcommand{\tabcolsep}{8pt}
\renewcommand{\arraystretch}{1.5}
\begin{tabularx}{\textwidth}{X|l|l|r}
\multicolumn{4}{l}{#1} \\
\toprule
information & key & value & symbol\\
\midrule
#2
\bottomrule
\end{tabularx}
\end{center}}
\newcommand\ertabularnosym[2]{
\begin{center}
\renewcommand{\tabcolsep}{8pt}
\renewcommand{\arraystretch}{1.5}
\begin{tabularx}{\textwidth}{X|l|X}
\multicolumn{3}{l}{#1} \\
\toprule
information & key & value\\
\midrule
#2
\bottomrule
\end{tabularx}
\end{center}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Text for verification boxes is defined here once such that it can be included
% several times in the document and needs to be changed only once here.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\veriftitleParameterValidation}{Parameter validation}
\newcommand{\veriftextParameterValidation}{
An \EG election verifier must verify that it uses the correct version of the \EG specification, that it uses the standard baseline parameters, which may be hardcoded, and that the base hash values have been computed correctly.
\begin{enumerate}
\item[(\theverification.A)] The \EG specification version used to generate the election record is the same as the \EG specification version used to verify the election record.
\item[(\theverification.B)] The large prime is equal to the large modulus $p$ defined in Section~\ref{sec:parameters}.
\item[(\theverification.C)] The small prime is equal to the prime $q$ defined in Section~\ref{sec:parameters}.
\item[(\theverification.D)] The cofactor is equal to the value $r$ defined in Section~\ref{sec:parameters}.
\item[(\theverification.E)] The generator is equal to the generator $g$ defined in Section~\ref{sec:parameters}.
\item[(\theverification.F)] The parameter base hash has been computed correctly as $$\HH_P = H(\mathtt{ver}; \mathtt{0x00}, p, q, g)$$
using the version byte array $\mathtt{ver} = \mathtt{0x76322E302E30} \parallel \bytes(0, 26)$, which is the UTF-8 encoding of the version string $\Str{v2.0.0}$ padded with $\mathtt{0x00}$-bytes to length $32$ bytes.
\item[(\theverification.G)] The manifest hash has been computed correctly from the manifest as $$\HH_M = H(\HH_P; \mathtt{0x01}, \mathtt{manifest}).$$
\item[(\theverification.H)] The base hash has been computed correctly as $$\HH_B = (\HH_P; \mathtt{0x02}, \HH_M, n, k).$$
\end{enumerate}}
\newcommand{\veriftitleGuardianPublicKeyValidation}{Guardian public-key validation}
\newcommand{\veriftextGuardianPublicKeyValidation}{
For each guardian $G_i$, $1\leq i \leq n$, and for each $j\in\Z_k$, an election verifier must compute the value
\begin{enumerate}
\item[(\theverification.1)] $h_{i,j} = g^{v_{i,j}} \cdot K_{i,j}^{c_{i,j}} \bmod p$
\end{enumerate}
and then must confirm the following.
\begin{enumerate}
\item[(\theverification.A)] The value $K_{i,j}$ is in $\Z_p^r$. (A value $x$ is in $\Z_p^r$ if and only if $x$ is an integer such that $0\leq x<p$ and $x^q \bmod p = 1$ is satisfied.)
\item[(\theverification.B)] The value $v_{i,j}$ is in $\Z_q$. (A value $x$ is in $\Z_q$ if and only if $x$ is an integer such that $0\leq x<q$.)
\item[(\theverification.C)] The challenge $c_{i,j}$ is correctly computed as $c_{i,j} = H(\HH_P; \mathtt{0x10}, i, j, K_{i,j}, h_{i,j})$.
\end{enumerate}}
\newcommand{\veriftitleElectionPublicKeyValidation}{Election public-key validation}
\newcommand{\veriftextElectionPublicKeyValidation}{
An election verifier must verify the correct computation of the joint election public key.
\begin{enumerate}
\item[(\theverification.A)] The value $K_{i}$ is in $\Z_p^r$ and $K_i \neq 1 \bmod p$ for all $1 \leq i \leq n$.
\item[(\theverification.B)] $K = \prod_{i=1}^n K_i \bmod p$ and $K \neq 1 \bmod p$.
\end{enumerate}}
\newcommand{\veriftitleExtendedBaseHashValidation}{Extended base hash validation}
\newcommand{\veriftextExtendedBaseHashValidation}{
An election verifier must verify the correct computation of the extended base hash.
\begin{enumerate}
\item[(\theverification.A)] $\HH_E = H(\HH_B; \mathtt{0x12},K)$.
\end{enumerate}}
\newcommand{\veriftitleCorrectnessOfSelectionEncryptions}{Well-formedness of selection encryptions}
\newcommand{\veriftextCorrectnessOfSelectionEncryptions}{
For each selectable option on each cast ballot, an election verifier must compute the values
\begin{enumerate}
\item[(\theverification.1)] $a_j = g^{v_j} \cdot \alpha^{c_j} \bmod p$ for all $0\leq j \leq R$,
\item[(\theverification.2)] $b_j = K^{w_j} \cdot \beta^{c_j}\bmod p$, where $w_j = (v_j-jc_j) \bmod q$ for all $0\leq j \leq R$,
\item[(\theverification.3)] $c = H(\HH_E;\mathtt{0x21},K,\alpha,\beta,a_0,b_0,a_1,b_1,\dots,a_R,b_R)$,
\end{enumerate}
where $R$ is the option selection limit. An election verifier must then confirm the following:
\begin{enumerate}
\item[(\theverification.A)] The given values $\alpha$ and $\beta$ are in the set $\Z_p^r$. \\
(A value $x$ is in $\Z_p^r$ if and only if $x$ is an integer such that $0\leq x<p$ and $x^q \bmod p = 1$.)
\item[(\theverification.B)] The given values $c_j$ each satisfy $0\leq c_j < 2^{256}$ for all $0\leq j \leq R$.
\item[(\theverification.C)] The given values $v_j$ are each in the set $\Z_q$ for all $0\leq j \leq R$. \\(A value $x$ is in $\Z_q$ if and only if $x$ is an integer such that $0\leq x<q$.)
\item[(\theverification.D)] The equation $c = (c_0+c_1 + \dots + c_R) \bmod q$ is satisfied.
\end{enumerate}}
\newcommand{\veriftitleAdherenceToVoteLimits}{Adherence to vote limits}
\newcommand{\veriftextAdherenceToVoteLimits}{
For each contest on each cast ballot, an election verifier must compute the contest totals
\begin{enumerate}
\item[(\theverification.1)] $\bar\alpha = \prod_i\alpha_i \bmod p$,
\item[(\theverification.2)] $\bar\beta = \prod_i\beta_i \bmod p$,
\end{enumerate}
where the $(\alpha_i,\beta_i)$ represent all possible selections for the contest, as well as the values
\begin{enumerate}
\item[(\theverification.3)] $a_j = g^{v_j} \cdot \bar\alpha^{c_j} \bmod p$ for all $0\leq j \leq L$,
\item[(\theverification.4)] $b_j = K^{w_j} \cdot \bar\beta^{c_j}\bmod p$, where $w_j = (v_j-jc_j) \bmod q$ for all $0\leq j \leq L$,
\item[(\theverification.5)] $c = H(\HH_E;\mathtt{0x21},K,\bar\alpha,\bar\beta,a_0,b_0,a_1,b_1,\dots,a_L,b_L)$,
\end{enumerate}
where $L$ is the contest selection limit.
An election verifier must then confirm the following:
\begin{enumerate}
\item[(\theverification.A)] The given values $\alpha_i$ and $\beta_i$ are each in $\Z_p^r$.
\item[(\theverification.B)] The given values $c_j$ each satisfy $0 \leq c_j < 2^{256}$.
\item[(\theverification.C)] The given values $v_j$ are each in $\Z_q$ for all $0\leq j \leq L$.
\item[(\theverification.D)] The equation $c = (c_0 + c_1 + \dots + c_L) \bmod q$ is satisfied.
\end{enumerate}}
\newcommand{\veriftitleValidationOfTrackingCodes}{Validation of confirmation codes}
\newcommand{\veriftextValidationOfTrackingCodes}{
An election verifier must confirm the following for each ballot $B$.
\begin{enumerate}
\item[(\theverification.A)] The contest hash $\chi_l$ for the contest with contest index $l$ for all $1\leq l \leq m_B$ has been correctly computed from the contest selection encryptions $(\alpha_i, \beta_i)$ as
$$\chi_l = H(\HH_E; \mathtt{0x23}, l, K, \alpha_1, \beta_1, \alpha_2, \beta_2\ldots,\alpha_m, \beta_m).$$
\item[(\theverification.B)] The ballot confirmation code $\HH(B)$ has been correctly computed from the contest hashes and if specified in the election manifest file from the additional byte array $\B_{\mathrm{aux}}$ as
$$\HH(B) = H(\HH_E; \mathtt{0x24}, \chi_1, \chi_2, \ldots, \chi_{m_B}, \B_{\mathrm{aux}}).$$
\end{enumerate}
An election verifier must also verify the following.
\begin{enumerate}
\item[(\theverification.C)] There are no duplicate confirmation codes, i.e.\ among the set of submitted (cast and challenged) ballots, no two have the same confirmation code.
\end{enumerate}
Additionally, if the election manifest file specifies a hash chain, an election verifier must confirm the following for each voting device.
\begin{enumerate}
\item[(\theverification.D)] The initial hash code $\HH_0$ satisfies $\HH_0 = H(\HH_E;\mathtt{0x24},\B_{\mathrm{aux},0})$ and $\B_{\mathrm{aux},0}$ contains the unique voting device information.
\item[(\theverification.E)] For all $1\leq j \leq \ell$, the additional input byte array used to compute $\HH_j=\HH(B_j)$ is equal to $\B_{\mathrm{aux},j} = \HH(B_{j-1})\parallel \B_{\mathrm{aux},0}$.
\item[(\theverification.F)] The final additional input byte array is equal to $\overline\B_{\mathrm{aux}} = \HH(B_\ell)\parallel \B_{\mathrm{aux},0} \parallel \bytes(\Str{CLOSE},5)$ and $\HH(B_\ell)$ is the final confirmation code on this device.
\item[(\theverification.G)] The closing hash is correctly computed as $\overline{\HH} = H(\HH_E; \mathtt{0x24}, \overline\B_{\mathrm{aux}})$.
\end{enumerate}
}
\newcommand{\veriftitleCorrectnessOfBallotAggregation}{Correctness of ballot aggregation}
\newcommand{\veriftextCorrectnessOfBallotAggregation}{
An election verifier must confirm for each option in each contest in the election manifest that the aggregate encryption $(A,B)$ satisfies
\begin{enumerate}
\item[(\theverification.A)] $A=(\prod_j\alpha_j) \bmod p$,
\item[(\theverification.B)] $B = (\prod_j \beta_j) \bmod p$,
\end{enumerate}
where the $(\alpha_j,\beta_j)$ are the corresponding encryptions on all cast ballots in the election record.}
\newcommand{\veriftitleCorrectnessOfDecryptions}{Correctness of tally decryptions}
\newcommand{\veriftextCorrectnessOfDecryptions}{
For each option in each contest on each tally, an election verifier must compute the values
\begin{enumerate}
\item[(\theverification.1)] $M = B \cdot T^{-1} \bmod p$,
\item[(\theverification.2)] $a = g^{v} \cdot K^{c} \bmod p$,
\item[(\theverification.3)] $b = A^{v} \cdot M^{c} \bmod p$.
\end{enumerate}
An election verifier must then confirm the following:
\begin{enumerate}
\item[(\theverification.A)] The given value $v$ is in the set $\Z_q$.
\item[(\theverification.B)] The challenge value $c$ satisfies $c = H(\HH_E;\mathtt{0x30},K,A,B,a,b,M)$.
\end{enumerate}}
\newcommand{\veriftitleValidationOfCorrectDecryptionOfTallies}{Validation of correct decryption of tallies}
\newcommand{\veriftextValidationOfCorrectDecryptionOfTallies}{
An election verifier must confirm the following equations for each option in each contest in the election manifest.
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.A)] $T = K^t \bmod p$.
\end{enumerate}
An election verifier must also confirm that the text labels listed in the election record tallies match the corresponding text labels in the election manifest. For each contest in a decrypted tally, an election verifier must confirm the following.
\begin{enumerate}
\item[(\theverification.B)] The contest text label occurs as a contest label in the list of contests in the election manifest.
\item[(\theverification.C)] For each option in the contest, the option text label occurs as an option label for the contest in the election manifest.
\item[(\theverification.D)] For each option text label listed for this contest in the election manifest, the option label occurs for a option in the decrypted tally contest.
\end{enumerate}
An election verifier must also confirm the following.
\begin{enumerate}
\item[(\theverification.E)] For each contest text label that occurs in at least one submitted ballot, that contest text label occurs in the list of contests in the corresponding tally.
\end{enumerate}}
%%%%%%%%%%%%%%%%%%%%%%%%% Contest data
\newcommand{\veriftitleCorrectnessOfDecryptionsOfContestData}{Correctness of decryptions of contest data}
\newcommand{\veriftextCorrectnessOfDecryptionsOfContestData}{
An election verifier must confirm the correct decryption of the contest data field for each contest by verifying the conditions analogous to Verification~\ref{verif:decryption} for the corresponding NIZK proof with $(A,B)$ replaced by $(C_0,C_1,C_2)$ and $M_i$ by $m_i$ as follows. An election verifier must compute the following values.
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.1)] $a = g^{v}\cdot K^{c} \bmod p$,
\item[(\theverification.2)] $b = C_0^{v}\cdot \beta^{c} \bmod p$.
\end{enumerate}
An election verifier must then confirm the following.
\begin{enumerate}
\item[(\theverification.A)] The given value $v$ is in the set $\Z_q$.
\item[(\theverification.B)] The challenge value $c$ satisfies $c = H(\HH_E;\mathtt{0x31},K,C_0,C_1,C_2,a,b,\beta )$.
\end{enumerate}}
%%%%%%%%%%%%%%%%%%%%%%%%% Challenged ballots
\newcommand{\veriftitleCorrectnessOfDecryptionsChallenged}{Correctness of decryptions for challenged ballots}
\newcommand{\veriftextCorrectnessOfDecryptionsChallenged}{
For each challenged ballot, for each option in each contest on the challenged ballot, an election verifier must compute the values
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.1)] $M = \beta \cdot S^{-1} \bmod p$,
\item[(\theverification.2)] $a = g^{v} \cdot K^{c} \bmod p$,
\item[(\theverification.3)] $b = \alpha^{v} \cdot M^{c} \bmod p$.
\end{enumerate}
An election verifier must then confirm the following.
\begin{enumerate}
\item[(\theverification.A)] The given value $v$ is in the set $\Z_q$.
\item[(\theverification.B)] The challenge value $c$ satisfies $c = H(\HH_E;\mathtt{0x30},K,\alpha,\beta,a,b,M )$.
\end{enumerate}}
\newcommand{\veriftitleValidationOfCorrectDecryptionOfChallengedBallots}{Validation of correct decryption of challenged ballots}
\newcommand{\veriftextValidationOfCorrectDecryptionOfChallengedBallots}{
An election verifier must confirm the correct decryption of each selection $\sigma$ in each contest.
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.A)]
$S = K^\sigma \bmod p$.
\end{enumerate}
An election verifier must also confirm that the challenged ballot is well-formed, i.e. for each contest on the challenged ballot, it must confirm the following.
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.B)]
For each option in the contest, the selection $\sigma$ is a valid value --- usually either a $0$ or a $1$.
\item[(\theverification.C)]
The sum of all selections in the contest is at most the selection limit $L$ for that contest.
\end{enumerate}
An election verifier must also confirm that for each decrypted challenged ballot, the selections listed in text match the corresponding text in the election manifest.
\begin{enumerate}
\item[(\theverification.D)] The contest text label occurs as a contest label in the list of contests in the election manifest.
\item[(\theverification.E)] For each option in the contest, the option text label occurs as an option label for the contest in the election manifest.
\item[(\theverification.F)] For each option text label listed for this contest in the election manifest, the option label occurs for a option in the decrypted challenged ballot.
\end{enumerate}
}
\newcommand{\veriftitleCorrectnessOfDecryptionsOfContestDataChallenged}{Correctness of contest data decryptions for challenged ballots}
\newcommand{\veriftextCorrectnessOfDecryptionsOfContestDataChallenged}{
An election verifier must confirm the correct decryption of the contest data field for each contest by verifying the conditions analogous to Verification~\ref{verif:decryption} for the corresponding NIZK proof with $(A,B)$ replaced by $(C_0,C_1,C_2)$ and $M$ by $\beta$ as follows.
This means it must compute the values
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.1)] $a = g^{v} \cdot K^{c} \bmod p$,
\item[(\theverification.2)] $b = C_0^{v} \cdot \beta^{c} \bmod p$.
\end{enumerate}
It must then confirm the following.
\begin{enumerate}
\item[(\theverification.A)] The given value $v$ is in the set $\Z_q$.
\item[(\theverification.B)] The challenge value $c$ satisfies $c = H(\HH_E;\mathtt{0x31},K,C_0,C_1,C_2,a,b,\beta)$.
\end{enumerate}}
%%%%%%%%%%%%%%%%%%%%%%%%% Pre-encrypted ballots
\newcommand{\veriftitlePreEncryptedBallotsCorrectnessOfSelectionEncryptions}{Well-formedness of selection encryptions in pre-encrypted ballots}
\newcommand{\veriftextPreEncryptedBallotsCorrectnessOfSelectionEncryptions}{
For each possible selection on each cast ballot, an election verifier must compute the values
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.1)] $a_0 = g^{v_0} \cdot \alpha^{c_0} \bmod p$,
\item[(\theverification.2)] $a_1 = g^{v_1} \cdot \alpha^{c_1} \bmod p$,
\item[(\theverification.3)] $b_0 = K^{v_0} \cdot \beta^{c_0} \bmod p$,
\item[(\theverification.4)] $b_1 = K^{w_1}\cdot \beta^{c_1} \bmod p$, where $w_1 = (v_1-c_1) \bmod q$,
\item[(\theverification.5)] $c = H(\HH_E;\mathtt{0x21},K,\alpha,\beta,a_0,b_0,a_1,b_1)$.
\end{enumerate}
An election verifier must then confirm the following:
\begin{enumerate}
\item[(\theverification.A)] The given values $\alpha$ and $\beta$ are in the set $\Z_p^r$. (A value $x$ is in $\Z_p^r$ if and only if $x$ is an integer such that $0\leq x<p$ and $x^q \bmod p = 1$ is satisfied.)
\item[(\theverification.B)] The given values $c_0$ and $c_1$ are each in the set $\{0,1,\dots,2^{256}-1\}$.
\item[(\theverification.C)] The given values $v_0$ and $v_1$ are each in the set $\Z_q$. (A value $x$ is in $\Z_q$ if and only if $x$ is an integer such that $0\leq x<q$.)
\item[(\theverification.D)] The equation $c = (c_0+c_1) \bmod q$ is satisfied.
\end{enumerate}}
\newcommand{\veriftitlePreEncryptedBallotsAdherenceToVoteLimits}{Adherence to vote limits in pre-encrypted ballots}
\newcommand{\veriftextPreEncryptedBallotsAdherenceToVoteLimits}{
For each contest on each cast ballot, an election verifier must compute the contest totals
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.1)] $\bar\alpha = \prod_i\alpha_i \bmod p$,
\item[(\theverification.2)] $\bar\beta = \prod_i\beta_i \bmod p$,
\end{enumerate}
where the $(\alpha_i,\beta_i)$ represent all possible selections for the contest, as well as the values
\begin{enumerate}
\item[(\theverification.3)] $a_j = g^{v_j} \cdot \bar\alpha^{c_j} \bmod p$ for all $0\leq j \leq L$,
\item[(\theverification.4)] $b_j = K^{w_j} \cdot \bar\beta^{c_j}\bmod p$, where $w_j = (v_j-jc_j) \bmod q$ for all $0\leq j \leq L$,
\item[(\theverification.5)] $c = H(\HH_E;\mathtt{0x21},K,\bar\alpha,\bar\beta,a_0,b_0,a_1,b_1,\dots,a_L,b_L)$.
\end{enumerate}
An election verifier must then confirm the following:
\begin{enumerate}
\item[(\theverification.A)] The given values $c_j$ each satisfy $0\leq c_j < 2^{256}$ for all $0\leq j \leq L$.
\item[(\theverification.B)] The given values $v_j$ are each in $\Z_q$ for all $0\leq j \leq L$.
\item[(\theverification.C)] The equation $c = c_0 + c_1 + \dots + c_L \bmod q$ is satisfied.
\end{enumerate}}
\newcommand{\veriftitlePreEncryptedValidationOfTrackingCodes}{Validation of confirmation codes in pre-encrypted ballots}
\newcommand{\veriftextPreEncryptedValidationOfTrackingCodes}{
An election verifier must confirm the following for each pre-encrypted ballot $B$.
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.A)] For each selection in each contest on the ballot and the corresponding selection vector $\Psi_{i,m}=\langle E_1,E_2,\ldots,E_m\rangle$ consisting of the selection encryptions $E_j = (\alpha_j, \beta_j)$, the selection hash $\psi_i$ satisfies
$$\psi_i=H(\HH_E;\mathtt{0x40},K,\alpha_1,\beta_1,\alpha_2,\beta_2,\ldots,\alpha_m,\beta_m).$$
\item[(\theverification.B)] The contest hash $\chi_l$ for the contest with context index $l$ for all $1\leq l \leq m_B$ has been correctly computed from the selection hashes $\psi_i$ as
$$\chi_l=H(\HH_E;\mathtt{0x41},l,K,\psi_{\sigma(1)},\psi_{\sigma(2)},\ldots,\psi_{\sigma(m+L)}),$$ where $\sigma$ is a permutation and $\psi_{\sigma(1)}<\psi_{\sigma(2)}<\cdots<\psi_{\sigma(m+L)}$.
\item[(\theverification.C)] The ballot confirmation code $\HH(B)$ has been correctly computed from the (sequentially ordered) contest hashes and if specified in the election manifest file from the additional byte array $\B_{\mathrm{aux}}$ as
$$H(B)=H(\HH_E; \mathtt{0x42}, \chi_1, \chi_2, \ldots, \chi_{m_B}, \B_{\mathrm{aux}}).$$
\end{enumerate}
An election verifier must also verify the following.
\begin{enumerate}
\item[(\theverification.D)] There are no duplicate confirmation codes, i.e.\ among the set of submitted (cast and challenged) ballots, no two have the same confirmation code.
\end{enumerate}
}
\newcommand{\veriftitlePreEncryptedValidationOfShortCodes}{Validation of short codes in pre-encrypted ballots}
\newcommand{\veriftextPreEncryptedValidationOfShortCodes}{
An election verifier must confirm for every selectable option on every pre-encrypted ballot in the election record that the short code $\omega$ displayed with the selectable option satisfies
\setlength{\leftmargini}{0.45in}
\begin{enumerate}
\item[(\theverification.A)] $\omega=\Omega(\psi)$ where $\psi$ is the selection hash associated with the selectable option.
\end{enumerate}
Specifically, for cast ballots, this includes all short codes that are published in the election record whose associated selection hashes correspond to selection vectors that are accumulated to form tallies.
For spoiled ballots, this includes all selection vectors on the ballot.
An election verifier must also confirm that for contests with selection limit greater than 1, the selection vectors published in the election
record match the product of the pre-encryptions associated with the short codes listed as
selected.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{center}
\begin{minipage}{\textwidth}
\centering
\includegraphics[width=5in]{electionguard-banner.png}\\
\vspace{.4in}
{\Huge {Design Specification}}\\
\vspace{.1in}
{\large Version 2.0.0}\\
\vspace{.4in}
{\large \today}\\
\vspace{.4in}
{\large Josh Benaloh and Michael Naehrig}\\
\vspace{.1in}
{\large \textsf{Microsoft Research}}\\
\end{minipage}\vspace{0.1in}
\end{center}
% list notes to address; appears only in draft mode
%\listoffixmes
\pagebreak
\tableofcontents
\pagebreak
\section{Introduction}
This document describes the cryptographic details of the design of \EG which can be used in conjunction with many new and existing voting systems to enable both end-to-end (E2E) verifiability and privacy-enhanced risk-limiting audits (RLAs). \EG is not a complete election system. It instead provides components that are designed to be flexible and to promote innovation by election officials and system developers. When properly used, it can promote voter confidence by empowering voters to independently verify the accuracy of election results.
\subsubsection*{End-to-end (E2E) verifiability}
An E2E-verifiable election provides artifacts which allow voters to confirm that their votes have been accurately recorded and counted. Specifically, an election is End-to-end (E2E) verifiable if two properties are achieved.
\begin{enumerate}
\item Individual voters can verify that their votes have been accurately recorded.
\item Voters and observers can verify that all recorded votes have been accurately counted.
\end{enumerate}
An E2E-verifiable tally can be used as the primary tally in an election or as a verifiable secondary tally alongside traditional methods. \EG is compatible with in-person voting -- either using an electronic ballot-marking device or an optical scanner capable of reading hand-marked or machine-marked ballots, with voting by mail, and even with Internet voting\footnote{
Note that there are many challenges to responsible Internet voting that are mitigated but not fully solved by E2E-verifiability. The 2015 U.S. Vote Foundation report at https://www.usvotefoundation.org/E2E-VIV details many of these issues, and the 2018 National Academies report at https://nap.nationalacademies.org/catalog/25120/securing-the-vote-protecting-american-democracy includes a section on Internet voting (pp. 101--105).
}.
\subsubsection*{Risk-limiting audits (RLAs)}
RLAs offer election administrators efficient methods to validate reported election tallies against physical ballot records. There are several varieties of RLAs, but the most efficient and practical are \emph{ballot-comparison audits} in which electronic \emph{cast-vote records} (CVRs) are individually compared against physical ballots.
The challenge with ballot-comparison audits is that public release of the full set of CVRs can compromise voter privacy while an audit without public disclosure of CVRs offers no basis for public confidence in the outcome. \EG can bridge this gap by enabling public disclosure of encrypted ballots that can be matched directly to physical ballots selected for auditing and can also be proven to match the reported tallies.
\subsubsection*{About this specification}
This specification can be used by expert reviewers to evaluate the details of the \EG process and by independent parties to write \EG implementations. This document is not intended to be a fully detailed implementation specification. It does not specify serialization and data structures for the election record or mappings between the notation used here and the corresponding data types and components of a specific implementation. However, this document, together with a detailed implementation specification or a well-documented \EG implementation, can be used by independent parties to write \EG verifiers to confirm the consistency of election artifacts with announced election results.
\section{Overview}
This section gives a very brief and high-level overview of the \EG system's functionality and how it can be used during an election or in a post-election audit such as an RLA.
To use \EG in an election, a set of \emph{guardians} is enlisted to serve as trustees who manage cryptographic keys. The members of a canvassing board can serve as guardians. Prior to the commencement of voting or auditing, the guardians work together to form a public encryption key that will be used to encrypt individual ballots.
After the conclusion of voting or auditing, a \emph{quorum} of guardians is necessary to produce the artifacts required to enable public verification of the tally.
\subsubsection*{Key generation}
Prior to the start of voting (for an E2E-verifiable election) or auditing (for an RLA), the election guardians participate in a process wherein they generate public keys to be used in the election. Each guardian generates its own public-secret key pair. These public keys will be combined to form a single public key with which votes are encrypted. They are also used individually by guardians to exchange information about their secret keys so that the election record can be produced after voting or auditing is complete -- even if not all guardians are available at that time.
The key generation ceremony begins with each guardian publishing its public keys together with proofs of knowledge of the associated secret keys. Once all public keys are published, each guardian uses each other guardian's public key to encrypt shares of its own secret keys. Finally, each guardian decrypts the shares it receives from other guardians and checks them for consistency. If the received shares verify, the receiving guardian announces its completion. If any shares fail to verify, the receiving guardian challenges the sender. In this case, the sender is obliged to reveal the shares it sent. If all challenged guardians release their challenged shares and these shares all verify, the ceremony concludes and the election proceeds. If a challenged guardian fails to produce key shares that verify, that guardian is removed and the key generation ceremony restarts with a replacement guardian.
\subsubsection*{Ballot encryption}
In most uses, the election system makes a single call to the \EG API after each voter completes the process of making selections or with each ballot to be encrypted for an RLA. \EG will encrypt the selections made by the voter and return a confirmation code which the system should give to the voter.\footnote{The confirmation code is not necessary for RLA usage.}
This is the only point where an existing election system must interface with \EG. In most uses of \EG, voters will have an opportunity to challenge their encrypted ballots and view their decryptions to ensure that the encryptions are correct.\footnote{A ballot that has been decrypted should be regarded as a test ballot and should not be included in an election tally. After a ballot is challenged, the voter should have an opportunity to cast a fresh ballot. In an E2E-verifiable election, a decypted ballot should never be cast. However, in an RLA, some anonymized cast ballots may ultimately be challenged and decrypted.}
In certain vote-by-mail scenarios and when \EG is used within an RLA, cast-vote records can be provided in batch without any interface between the voting equipment and \EG.
The encrypted ballots are published along with non-interactive zero-knowledge (NIZK) proofs of their well-formedness. The proofs assert that an encrypted ballot is well-formed, which means that it is a legitimate ballot and adheres to the limits imposed on selection options and contests. For example, they prove that a selection did not receive more votes than allowed and that no more than the allowed number of votes were received across the selection options in each contest. The encryption method used herein has a homomorphic property which allows the encrypted ballots to be combined into a single aggregate ballot which consists of encryptions of the election tallies.
\subsubsection*{Verifiable decryption}
In the final step, election guardians independently use a share of the secret decryption key, which each guardian computes from the previously shared secret key fragments, to jointly decrypt the election tallies and generate associated verification data. It is not necessary for all guardians to be available to complete this step. If some guardians are missing, a quorum of guardians is sufficient to complete decryption and generate the verification data.
\subsubsection*{Independent verification}
Observers can use this open specification and/or accompanying materials to write independent \emph{election verifiers} that can confirm the well-formedness of each encrypted ballot, the correct aggregation of these ballots, and the accurate decryption of election tallies.
The verification of an election consists of various verification steps that can be separated into three groupings.
\paragraph{Verification of key generation.}
The first group of verification steps pertain to the key generation process. Under normal circumstances, guardians will engage in a key generation ceremony and produce an election public key without controversy, and there is no need for independent verification of this process. However, if one or more parties to the key generation ceremony complain about the process, the associated independent verification steps can help to resolve conflicts.
These steps should therefore be considered to be optional. The integrity of an election record can be fully verified by independent parties without any of the key verification steps. However, a ``premium'' verifier may wish to include these steps to verify the correctness of guardian actions during the key generation ceremony.
The key generation verification steps are highlighted in orange boxes.
\paragraph{Verification of ballot correctness.}
As will be described in detail below, there are instances in both the E2E-verifiability application and the RLA application where it is desirable to verifiably decrypt individual ballots. In the former application, this allows voters to confirm that their selections have been correctly recorded within an encrypted ballot, and in the latter application, this allows encrypted electronic ballots that have been selected for audit to be compared with their associated paper ballots.
The steps required to verify the correct decryption of a ballot are grouped together to allow independent verifiers to be easily constructed whose sole purpose is to allow voters or observers to directly verify correct decryption of individual ballots.
The ballot correctness verification steps are highlighted in blue boxes.
\paragraph{Verification of election record.}
The remaining verification steps apply to the election as a whole. These steps enable independent verification that every ballot in an election record is well-formed, that cast ballots have been correctly aggregated homorphically, and that these aggregated values have been correctly decrypted to produce election tallies.
It is critical that a complete verification of an election record also includes verification of the correct decryption of any individual ballots that have been decrypted as part of the process. A complete election verifier must therefore incorporate an individual ballot generator as described above.
The election record verification steps are highlighted in green boxes.
\subsubsection*{Using this specification}
The principal purposes of this document are to specify the functionality of the \EG toolkit and to provide details necessary for independent parties to write election verifiers that consume the artifacts produced by the toolkit.
\pagebreak
\section{Components}\label{sec:EGcomponents}
This section describes the four principal components of \EG.
\begin{enumerate}
\item \emph{Parameter Requirements:} These are properties required of parameters to securely and efficiently instantiate the cryptographic components of \EG. These \emph{cryptographic parameters} are fixed ahead of every election and the same parameters can be used across multiple elections. A specific, recommended set of standard parameters is provided. In addition, there are properties required of the \emph{election parameters} that define the election contests, selectable options, and ballot styles, among other information.
\item \emph{Key Generation:} Prior to each individual election, guardians must generate individual public-secret key pairs and exchange shares of secret keys to enable completion of an election even if some guardians become unavailable. Although it is preferred to generate new keys for each election, it is permissible to use the same keys for multiple elections so long as the set of guardians remains the same. A complete new set of keys must be generated if even a single guardian is replaced.
\item \emph{Ballot Encryption:} While encrypting the contents of a ballot is a relatively simple operation, most of the work of \EG is the process of creating externally-verifiable artifacts to prove that each encrypted ballot is well-formed (i.e., its decryption is a legitimate ballot without overvotes or improper values).
\item \emph{Verifiable Decryption:} At the conclusion of each election, guardians use their secret key shares to jointly produce election tallies together with verifiable artifacts that prove that the tallies are correct.
\end{enumerate}
\subsubsection*{Notation}
In the remainder of this specification, the following notation will be used.
\begin{itemize}
\item $\Z = \{\dots,-3,-2,-1,0,1,2,3,\dots\}$ is the set of integers.
\item $\Z_n = \{0,1,2,\dots,n-1\}$ is the ring of integers modulo $n$.
\item $\Z_n^*$ is the multiplicative subgroup of $\Z_n$ that consists of all invertible elements modulo $n$. When $p$ is a prime, $\Z_p^* = \{1,2,3,\dots,p-1\}$.
\item $\Z_p^r$ is the set of $r$-th-residues in $\Z_p^*$. Formally, $\Z_p^r = \{y\in\Z_p^* \mbox{ for which there exists } x\in\Z_p^* \mbox{ such that } y=x^r \bmod p\}$. When $p$ is a prime for which $p-1=qr$ with $q$ a prime that is not a divisor of the integer $r$, then $\Z_p^r$ is an order-$q$ cyclic subgroup of $\Z_p^*$ and for each $y\in\Z_p^*$, $y\in\Z_p^r$ if and only if $y^q \bmod p = 1$.
\item $x\equiv_n y$ is the predicate that is true if and only if $x \bmod n=y \bmod n$.
\item The function $\HMAC(\ ,\ )$ shall be used to denote the \HMAC-\SHA keyed Hash Message Authentication Code (as defined in NIST PUB FIPS 198-1\footnote{NIST (2008) The Keyed-Hash Message Authentication Code (HMAC). In: FIPS 198-1. \url{https://csrc.nist.gov/publications/detail/fips/198/1/final}}) instantiated with \SHA (as defined in NIST PUB FIPS 180-4\footnote{NIST (2015) Secure Hash Standard (SHS). In: FIPS 180-4. \url{https://csrc.nist.gov/publications/detail/fips/180/4/final}}). $\HMAC$ takes as input a key $k$ and a message $m$ of arbitrary length and returns a bit string $\HMAC(k,m)$ of length 256 bits.
\item The \EG hash function $H(\ ,\ )$ is instantiated with \HMAC and thus has two inputs, both given as byte arrays. The first input to $H$ is used to bind hash values to a specific election. The second is a byte array of arbitrary length and consists of domain separation bytes and the data being hashed. $H$ outputs a digest of 256 bits, which is interpreted as a byte array of length 32. The detailed specification for $H$ is given in Section~\ref{sec:hashing} below.
\item The symbol $\oplus$ denotes bitwise XOR.
\item The symbol $\parallel$ denotes concatenation.
\item In general, the variable pairs $(\alpha,\beta)$, $(a,b)$, and $(A,B)$ will be used to denote encryptions. Specifically, $(\alpha,\beta)$ will be used to designate encryptions of votes (usually an encryption of a zero or a one), $(A,B)$ will be used to denote aggregations of encryptions -- which may be encryptions of larger values, and $(a,b)$ will be used to denote encryption commitments used to prove properties of other encryptions.
\end{itemize}
\subsubsection*{Encryption of votes}
Encryption of votes in \EG is performed using a public key encryption method suggested by Devillez, Pereira, and Peters,\footnote{Devillez H., Pereira, O., Peters, T. (2022) \emph{How to Verifiably Encrypt Many Bits for an Election?} in ESORICS 2022 Lecture Notes in Computer Science, vol 13555. Springer, Berlin, Heidelberg. \url{https://link.springer.com/chapter/10.1007/978-3-031-17146-8_32}} which is a variant exponential form of the ElGamal cryptosystem,\footnote{ElGamal T. (1985) \emph{A Public Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms}. In: Blakley G.R., Chaum D. (eds) Advances in Cryptology. CRYPTO 1984. Lecture Notes in Computer Science, vol 196. Springer, Berlin, Heidelberg. \url{https://link.springer.com/content/pdf/10.1007/3-540-39568-7_2.pdf}} which is, in turn, a static form of the widely-used Diffie-Hellman(-Merkle) key exchange\footnote{Diffie W., Hellman, M. (1976) \emph{New Directions in Cryptography} IEEE Transactions on Information Theory, vol 22}. This encryption method is called \emph{DPP vote encryption} or simply \emph{vote encryption} in this document and rests on precisely the same security basis as Diffie-Hellman(-Merkle) key exchange---which is used to protect the confidentiality of the vast majority of Internet traffic.
Primes $p$ and $q$ are publicly fixed such that $q$ is not a divisor of $r=(p-1)/q$. A generator $g$ of the order $q$ subgroup $\Z_p^r$ is also fixed. (Any $g=x^r \bmod p$ for which $x\in\Z_p^*$ suffices so long as $g\neq 1$.)
A public-secret key pair can be chosen by selecting a random $s\in\Z_q$ as a secret key and publishing $K=g^s \bmod p$ as the corresponding public key\footnote{As will be seen below, the actual public key used to encrypt votes will be a combination of separately generated public keys. So, no entity will ever be in possession of a secret key that can be used to decrypt votes.}.
A message $m\in\Z_p^r$ is then encrypted by selecting a random nonce $\xi\in\Z_q$ and forming the pair $(\alpha, \beta) = (g^\xi \bmod p, K^m\cdot K^\xi \bmod p) = (g^\xi \bmod p, K^{m+\xi} \bmod p)$. An encryption $(\alpha, \beta)$ can be decrypted by the holder of the secret $s$ as $\beta/\alpha^s\bmod p = K^m \bmod p$ because
\begin{equation}
\frac{\beta}{\alpha^s} \equiv_p \frac{K^m\cdot K^\xi}{(g^\xi)^s} \equiv_p \frac{K^m\cdot (g^s)^\xi}{(g^\xi)^s} \equiv_p \frac{K^m\cdot g^{\xi s}}{g^{\xi s}} \equiv_p K^m.
\end{equation}
The value of $m$ can be computed from $K^m \bmod p$ as long as the message $m$ is limited to a small, known set of options.\footnote{The simplest way to compute $m$ from $K^m \bmod p$ is an exhaustive search through possible values of $m$. Alternatively, a table pairing each possible value of $K^m \bmod p$ with $m$ can be pre-computed. A final option which can accommodate a larger space of possible values for $m$ is to use Shanks's baby-step giant-step method as described in the 1971 paper \emph{Class Number, a Theory of Factorization and Genera}, Proceedings of Symposium in Pure Mathematics, Vol. 20, American Mathematical Society, Providence, 1971, pp. 415-440.}
The value of $K^m$ and therefore $m$ can also be computed from the encryption nonce $\xi$, namely via $\beta/K^\xi \equiv_p K^m$. While the secret key $s$ allows decryption of any ciphertext encrypted to the public key $K$, the encryption nonce only allows decryption of the specific ciphertext it was used to generate. The encryption nonce must therefore be securely protected. Release of an encryption nonce can, when appropriate, serve as a fast and convenient method of verifiable decryption.
Usually, only two possible messages are encrypted in this way by \EG. An encryption of one is used to indicate that an option is selected, and an encryption of zero is used to indicate that an option is not selected. For some voting methods such as cumulative voting, Borda count, and a variety of cardinal voting methods like score voting and STAR-voting, it can be necessary to encrypt other small, positive integers.
\subsubsection*{Homomorphic properties}
A fundamental quality of the DPP vote encryption is its additively homomorphic property. If two messages $m_1$ and $m_2$ are respectively encrypted as $(A_1,B_1 ) = (g^{\xi_1} \bmod p , K^{m_1+\xi_1} \bmod p)$ and $(A_2, B_2) = (g^{\xi_2}\bmod p, K^{m_2+\xi_2} \bmod p)$, then the component-wise product
\begin{equation}
(A,B) = ( A_1 A_2 \bmod p, B_1 B_2 \bmod p) = (g^{\xi_1+\xi_2} \bmod p, K^{(m_1+m_2) + (\xi_1+\xi_2)} \bmod p)
\end{equation}
is an encryption of the sum $m_1+m_2$. (There is an implicit assumption here that $(m_1+m_2) < q$ which is easily satisfied when $m_1$ and $m_2$ are both small. If $(\xi_1+\xi_2)\geq q$, $(\xi_1+\xi_2) \bmod q$ may be substituted without changing the equation since $g^q\equiv_p 1$.)
This additively homomorphic property is used in two important ways in \EG. First, all of the encryptions of a single option across ballots can be multiplied to form an encryption of the sum of the individual values. Since the individual values are one (or some other integer for certain voting methods) on ballots that select that option and zero otherwise, the sum is the tally of votes for that option and the product of the individual encryptions is an encryption of the tally.
The other use is to sum all of the selections made in a single contest on a single ballot. In the simplest case, after demonstrating that each option is an encryption of either zero or one, the product of the encryptions indicates the number of options that are encryptions of one, and this can be used to show that no more ones than permitted are among the encrypted options -- i.e., that no more options were selected than permitted. When larger integers are allowed, i.e. an option can receive multiple votes or weighted votes, the product of the ciphertexts then encrypts the total number of votes or the sum of weights and is used in the same way to ensure only the permitted number of votes or permitted sum of weights were used.
However, as will be described below, it is possible for a holder of a nonce $\xi$ to prove to a third party that a pair $(\alpha, \beta)$ is an encryption of $m$ without revealing the nonce $\xi$ and without access to the secret $s$.
\subsubsection*{Non-interactive zero-knowledge (NIZK) proofs}
\EG provides numerous proofs about encryption keys, encrypted ballots, and election tallies using the following four techniques.
\begin{enumerate}
\item A Schnorr proof\footnote{Schnorr C.P. (1990) Efficient Identification and Signatures for Smart Cards. In: Brassard G. (eds) Advances in Cryptology — CRYPTO' 89 Proceedings. CRYPTO 1989. Lecture Notes in Computer Science, vol 435. Springer, New York, NY. \url{https://link.springer.com/content/pdf/10.1007\%2F0-387-34805-0_22.pdf}} allows the holder of a secret key $s$ to interactively prove possession of $s$ without revealing $s$.
\item A Chaum-Pedersen proof\footnote{Chaum D., Pedersen T.P. (1993) \emph{Wallet Databases with Observers}. In: Brickell E.F. (eds) Advances in Cryptology — CRYPTO' 92. CRYPTO 1992. Lecture Notes in Computer Science, vol 740. Springer, Berlin, Heidelberg. \url{https://link.springer.com/content/pdf/10.1007\%2F3-540-48071-4_7.pdf}} allows an encryption to be interactively proven to decrypt to a particular value without revealing the nonce used for encryption or the secret decryption key $s$. (This proof can be constructed with access to either the nonce used for encryption or the secret decryption key.)
\item The Cramer-Damgård-Schoenmakers technique\footnote{Cramer R., Damgård I., Schoenmakers B. (1994) \emph{Proofs of Partial Knowledge and Simplified Design of Witness Hiding Protocols}. In: Desmedt Y.G. (eds) Advances in Cryptology — CRYPTO' 94. CRYPTO 1994. Lecture Notes in Computer Science, vol 839. Springer, Berlin, Heidelberg. \url{https://link.springer.com/content/pdf/10.1007\%2F3-540-48658-5_19.pdf}} enables a disjunction to be interactively proven without revealing which disjunct is true.
\item The Fiat-Shamir heuristic\footnote{Fiat A., Shamir A. (1987) \emph{How To Prove Yourself: Practical Solutions to Identification and Signature Problems}. In: Odlyzko A.M. (eds) Advances in Cryptology — CRYPTO' 86. CRYPTO 1986. Lecture Notes in Computer Science, vol 263. Springer, Berlin, Heidelberg. \url{https://link.springer.com/content/pdf/10.1007\%2F3-540-47721-7_12.pdf}} allows interactive proofs to be converted into non-interactive proofs.
\end{enumerate}
Using a combination of the above techniques, it is possible for \EG to demonstrate that keys are properly chosen, that ballots are well-formed, and that decryptions match claimed values.\footnote{For all proof variants, \EG uses a compact representation that omits the commitments. Proofs consist of the challenge and response values only. When verifying proofs, the verification equations can be used to recompute the commitments and check their correctness via the challenge hash computation.}
\subsubsection*{Threshold encryption}
Threshold encryption is used for encryption of ballots and other data. This form of encryption makes it very easy to combine individual guardian public keys into a single public key. It also offers a homomorphic property that allows individual encrypted votes to be combined to form encrypted tallies.
The guardians of an election will each generate a public-secret key pair. The public keys will then be combined (as described in the following section) into a single election public key which is used to encrypt all selections made by voters in the election.
At the conclusion of the election, each guardian will compute a verifiable partial decryption of each tally. These partial decryptions will then be combined to form full verifiable decryptions of the election tallies.
To accommodate the possibility that one or more of the guardians will not be available at the conclusion of the election to form their partial decryptions, the guardians will cryptographically share\footnote{Shamir A. (1979) \emph{How to Share a Secret}. Communications of the ACM, vol 22.} their secret keys amongst each other during key generation in a manner to be detailed in Section~\ref{sec:keygen}. Each guardian can then compute a share of the secret decryption key, which they use to form the partial decryptions. A pre-determined threshold quorum value ($k$) out of the ($n$) guardians will be necessary to produce a full decryption.
\subsubsection*{Encryption of other data}
\EG provides means to encrypt data other than votes, which are selections usually encoded as zero or one that need to be homomorphically aggregated. Such data may include the cryptographic shares of a guardian's secret key that are sent to the other guardians and are encrypted to the receiving guardians' public keys, write-in information that needs to be attached to an encrypted selection and is encrypted to the election public key, or other auxiliary data attached to an encrypted ballot, either encrypted to the election public key or to an administrative public key. The non-vote data do not need to be homomorphically encrypted and can use a more standard form of public-key encryption removing the data size restrictions imposed by the vote encryption. \EG encrypts such data with hashed ElGamal encryption, which deploys a key derivation function (\KDF) to generate a key stream that is then XORed with the data. To implement the \KDF and to provide a message authentication code (\MAC), encryption makes use of the keyed Hash Message Authentication Code \HMAC. In \EG, \HMAC is instantiated as \HMAC-\SHA with the hash function \SHA.
\subsection{Parameter requirements}
\EG uses integers to instantiate the encryption rather than elliptic curves in order to make construction of election verifiers as simple as possible without requiring special tools and dependencies. The encryption scheme used to encrypt votes is defined by a prime $p$ and a prime $q$ which divides $(p-1)$. We use $r = (p-1)/q$ to denote the cofactor of $q$, and a generator $g$ of the order $q$ subgroup $\Z_p^r$ is fixed. We also require $r/2$ to be prime. The specific values for a 4096-bit prime $p$ and a 256-bit prime $q$ which divides $(p-1)$ and a generator $g$ that define all standard baseline parameters are given below.
\subsubsection{Standard baseline cryptographic parameters}\label{sec:parameters}
Standard parameters for \EG begin with the largest 256-bit prime $q = 2^{256}-189$. The (big endian) hexadecimal representation of $q$ is as follows.
\begin{equation}
q = \mathtt{0xFFFFFFFF \ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFF43}
\end{equation}
The modulus $p$ is then set to be a 4096-bit prime with the following properties.
\begin{enumerate}
\item The first 256 bits of $p$ are all ones.
\item The last 256 bits of $p$ are all ones.
\item $p-1$ is a multiple of $q$.
\item $(p-1)/2q$ is also prime.
\end{enumerate}
The middle 3584 bits of $p$ are chosen by starting with the first 3584 bits of the constant $\mathrm{ln}(2)$ (the natural logarithm of $2$).\footnote{See \url{https://oeis.org/A068426} for the integer sequence consisting of the bits of $\mathrm{ln}(2)$.} After pre-pending and appending 256 ones, $p$ is determined by finding the smallest prime larger than this value that satisfies the above properties.
This works out to $p = 2^{4096}-2^{3840}+2^{256} (\lfloor2^{3584} \mathrm{ln}(2)\rfloor + \delta) + (2^{256} - 1)$ where the value of $\delta$ is given by
{\small
$$\delta=287975203778583638958138611533602521491887169409704874643524560756486080635197037903.\footnote{Discovering this value $\delta$ required enumerating roughly 2.49 million values satisfying the first three of the above properties to find the first one for which both $p$ and $(p-1)/2q$ are both prime.}
$$
}
The hexadecimal representation of $p$ is as follows.
{\allowdisplaybreaks
\begin{align*}
p \ = \ \mathtt{0x}
& \mathtt{FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF}\\
& \mathtt{B17217F7\ D1CF79AB\ C9E3B398\ 03F2F6AF\ 40F34326\ 7298B62D\ 8A0D175B\ 8BAAFA2B}\\
& \mathtt{E7B87620\ 6DEBAC98\ 559552FB\ 4AFA1B10\ ED2EAE35\ C1382144\ 27573B29\ 1169B825}\\
& \mathtt{3E96CA16\ 224AE8C5\ 1ACBDA11\ 317C387E\ B9EA9BC3\ B136603B\ 256FA0EC\ 7657F74B}\\
& \mathtt{72CE87B1\ 9D6548CA\ F5DFA6BD\ 38303248\ 655FA187\ 2F20E3A2\ DA2D97C5\ 0F3FD5C6}\\
& \mathtt{07F4CA11\ FB5BFB90\ 610D30F8\ 8FE551A2\ EE569D6D\ FC1EFA15\ 7D2E23DE\ 1400B396}\\
& \mathtt{17460775\ DB8990E5\ C943E732\ B479CD33\ CCCC4E65\ 9393514C\ 4C1A1E0B\ D1D6095D}\\
& \mathtt{25669B33\ 3564A337\ 6A9C7F8A\ 5E148E82\ 074DB601\ 5CFE7AA3\ 0C480A54\ 17350D2C}\\
& \mathtt{955D5179\ B1E17B9D\ AE313CDB\ 6C606CB1\ 078F735D\ 1B2DB31B\ 5F50B518\ 5064C18B}\\
& \mathtt{4D162DB3\ B365853D\ 7598A195\ 1AE273EE\ 5570B6C6\ 8F969834\ 96D4E6D3\ 30AF889B}\\
& \mathtt{44A02554\ 731CDC8E\ A17293D1\ 228A4EF9\ 8D6F5177\ FBCF0755\ 268A5C1F\ 9538B982}\\
& \mathtt{61AFFD44\ 6B1CA3CF\ 5E9222B8\ 8C66D3C5\ 422183ED\ C9942109\ 0BBB16FA\ F3D949F2}\\
& \mathtt{36E02B20\ CEE886B9\ 05C128D5\ 3D0BD2F9\ 62136319\ 6AF50302\ 0060E499\ 08391A0C}\\
& \mathtt{57339BA2\ BEBA7D05\ 2AC5B61C\ C4E9207C\ EF2F0CE2\ D7373958\ D7622658\ 90445744}\\
& \mathtt{FB5F2DA4\ B7510058\ 92D35689\ 0DEFE9CA\ D9B9D4B7\ 13E06162\ A2D8FDD0\ DF2FD608}\\
& \mathtt{FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF\ FFFFFFFF}
\end{align*}
The hexadecimal representation of the cofactor $r = (p-1)/q$ is as follows.
\begin{align*}
r \ = \ \mathtt{0x01}\
& \mathtt{00000000\ 00000000\ 00000000\ 00000000\ 00000000\ 00000000\ 00000000\ 000000BC}\\
& \mathtt{B17217F7\ D1CF79AB\ C9E3B398\ 03F2F6AF\ 40F34326\ 7298B62D\ 8A0D175B\ 8BAB857A}\\
& \mathtt{E8F42816\ 5418806C\ 62B0EA36\ 355A3A73\ E0C74198\ 5BF6A0E3\ 130179BF\ 2F0B43E3}\\
& \mathtt{3AD86292\ 3861B8C9\ F768C416\ 9519600B\ AD06093F\ 964B27E0\ 2D868312\ 31A9160D}\\
& \mathtt{E48F4DA5\ 3D8AB5E6\ 9E386B69\ 4BEC1AE7\ 22D47579\ 249D5424\ 767C5C33\ B9151E07}\\
& \mathtt{C5C11D10\ 6AC446D3\ 30B47DB5\ 9D352E47\ A53157DE\ 04461900\ F6FE360D\ B897DF53}\\
& \mathtt{16D87C94\ AE71DAD0\ BE84B647\ C4BCF818\ C23A2D4E\ BB53C702\ A5C8062D\ 19F5E9B5}\\
& \mathtt{033A94F7\ FF732F54\ 12971286\ 9D97B8C9\ 6C412921\ A9D86797\ 70F499A0\ 41C297CF}\\
& \mathtt{F79D4C91\ 49EB6CAF\ 67B9EA3D\ C563D965\ F3AAD137\ 7FF22DE9\ C3E62068\ DD0ED615}\\
& \mathtt{1C37B4F7\ 4634C2BD\ 09DA912F\ D599F433\ 3A8D2CC0\ 05627DCA\ 37BAD43E\ 64A39631}\\
& \mathtt{19C0BFE3\ 4810A21E\ E7CFC421\ D53398CB\ C7A95B3B\ F585E5A0\ 4B790E2F\ E1FE9BC2}\\
& \mathtt{64FDA810\ 9F6454A0\ 82F5EFB2\ F37EA237\ AA29DF32\ 0D6EA860\ C41A9054\ CCD24876}\\
& \mathtt{C6253F66\ 7BFB0139\ B5531FF3\ 01899612\ 02FD2B0D\ 55A75272\ C7FD7334\ 3F7899BC}\\
& \mathtt{A0B36A4C\ 470A64A0\ 09244C84\ E77CEBC9\ 2417D5BB\ 13BF1816\ 7D8033EB\ 6C4DD787}\\
& \mathtt{9FD4A7F5\ 29FD4A7F\ 529FD4A7\ F529FD4A\ 7F529FD4\ A7F529FD\ 4A7F529F\ D4A7F52A}
\end{align*}
Finally, the generator $g$ is chosen to be $g = 2^r \bmod p$ and has the following hexadecimal representation.
\begin{align*}
g \ = \ \mathtt{0x}
& \mathtt{36036FED\ 214F3B50\ DC566D3A\ 312FE413\ 1FEE1C2B\ CE6D02EA\ 39B477AC\ 05F7F885}\\
& \mathtt{F38CFE77\ A7E45ACF\ 4029114C\ 4D7A9BFE\ 058BF2F9\ 95D2479D\ 3DDA618F\ FD910D3C}\\
& \mathtt{4236AB2C\ FDD783A5\ 016F7465\ CF59BBF4\ 5D24A22F\ 130F2D04\ FE93B2D5\ 8BB9C1D1}\\
& \mathtt{D27FC9A1\ 7D2AF49A\ 779F3FFB\ DCA22900\ C14202EE\ 6C996160\ 34BE35CB\ CDD3E7BB}\\
& \mathtt{7996ADFE\ 534B63CC\ A41E21FF\ 5DC778EB\ B1B86C53\ BFBE9998\ 7D7AEA07\ 56237FB4}\\
& \mathtt{0922139F\ 90A62F2A\ A8D9AD34\ DFF799E3\ 3C857A64\ 68D001AC\ F3B681DB\ 87DC4242}\\
& \mathtt{755E2AC5\ A5027DB8\ 1984F033\ C4D17837\ 1F273DBB\ 4FCEA1E6\ 28C23E52\ 759BC776}\\
& \mathtt{5728035C\ EA26B44C\ 49A65666\ 889820A4\ 5C33DD37\ EA4A1D00\ CB62305C\ D541BE1E}\\
& \mathtt{8A92685A\ 07012B1A\ 20A746C3\ 591A2DB3\ 815000D2\ AACCFE43\ DC49E828\ C1ED7387}\\
& \mathtt{466AFD8E\ 4BF19355\ 93B2A442\ EEC271C5\ 0AD39F73\ 3797A1EA\ 11802A25\ 57916534}\\
& \mathtt{662A6B7E\ 9A9E449A\ 24C8CFF8\ 09E79A4D\ 806EB681\ 119330E6\ C57985E3\ 9B200B48}\\
& \mathtt{93639FDF\ DEA49F76\ AD1ACD99\ 7EBA1365\ 7541E79E\ C57437E5\ 04EDA9DD\ 01106151}\\
& \mathtt{6C643FB3\ 0D6D58AF\ CCD28B73\ FEDA29EC\ 12B01A5E\ B86399A5\ 93A9D5F4\ 50DE39CB}\\
& \mathtt{92962C5E\ C6925348\ DB54D128\ FD99C14B\ 457F883E\ C20112A7\ 5A6A0581\ D3D80A3B}\\
& \mathtt{4EF09EC8\ 6F9552FF\ DA1653F1\ 33AA2534\ 983A6F31\ B0EE4697\ 935A6B1E\ A2F75B85}\\
& \mathtt{E7EBA151\ BA486094\ D68722B0\ 54633FEC\ 51CA3F29\ B31E77E3\ 17B178B6\ B9D8AE0F}
\end{align*}
}
Alternative parameter sets are possible and may be allowed in future versions of \EG\footnotemark.
\footnotetext{If alternative parameters are allowed, election verifiers must confirm that $p$, $q$, $r$, and $g$ are such that both $p$ and $q$ are prime (this may be done probabilistically using the Miller-Rabin algorithm), that $p-1 = qr$ is satisfied, that $q$ is not a divisor of $r$, that $1<g<p$, that $g^q \bmod p = 1$, and that generation of the parameters is consistent with the cited standard.}
\EGnote{As an example for alternative parameters, the Appendix provides a set of reduced parameters that offer better performance at a lower security level, and additionally provides various sets of very small and insecure parameters for testing purposes only. A good source for parameter generation is appendix A of FIPS 186-4\footnotemark. Allowing alternate non-standard parameters would force election verifiers to recognize and check that parameters are correctly generated. Since these checks are very different from other checks that are required of a verifier, allowing such parameters would add substantial complexity to election verifiers. For this reason, this version of \EG fixes the parameters as above.}
\footnotetext{NIST (2013) Digital Signature Standard (DSS). In: FIPS 186-4. \url{https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf}}
\subsubsection{Parameter base hash}\label{sec:parameterhash}
The prime modulus $p$, the subgroup order $q$, and the subgroup generator $g$ are hashed using the \EG hash function $H$ (as specified in detail in Section~\ref{sec:hashing}) to form the parameter base hash
\begin{equation}\label{eq:parameterhash}
\HH_P = H(\mathtt{ver}; \mathtt{0x00}, p, q, g).
\end{equation}
The symbol $\mathtt{ver}$ denotes the version byte array that encodes the used version of this specification. The array has length 32 and contains the UTF-8 encoding of the string $\Str{v2.0.0}$ followed by \texttt{0x00}-bytes, i.e. $\mathtt{ver} = \mathtt{0x76322E302E30} \parallel \bytes(0,27)$. The \texttt{0x00}-byte at the beginning of the second argument of $H$ is a domain separation byte (written in hexadecimal notation), see Section~\ref{sec:hashinputdata}. For the baseline parameters specified in Section~\ref{sec:parameters} above, the hexadecimal representation of the parameter base hash is
\begin{equation}
H_P = \mathtt{0x2B3B025E50E09C119CBA7E9448ACD1CABC9447EF39BF06327D81C665CDD86296}.
\end{equation}
This hash value is an input to all subsequent hash computations, either directly or indirectly, which binds all hash outputs to the baseline parameters and the version of the specification used for the election.
\subsubsection{Election parameters and the election manifest}\label{sec:manifest}
Another parameter of an election is a public election manifest. The ElectionGuard manifest is a single file that describes the modalities of the election and must specify a wide range of data about it. Most importantly, the manifest lists, among other information, all the contests in an election, the candidates (selectable options) for each contest together with associations between each option and its representation on a virtual ballot, and the contest selection limit—the number of options that a voter may select in that contest. It is assumed that each contest in the manifest has a unique label and that within each contest, each option also has a unique label. For instance, if Alice, Bob, and Carol are running for governor, and David and Ellen are running for senator, the election manifest file could enable the vector $\langle 0,1,0;0,1\rangle$ to be recognized as a ballot with votes for Bob as governor and Ellen as senator. This section defines how the manifest must uniquely specify the election parameters.
\paragraph{Labels.}
The election objects relevant for \EG such as contests, selectable options, and ballot styles are identified by unique labels. A \emph{label} is a string, it should be a short, concise name or identifier and should therefore not contain any long-form descriptions or line break characters, tabs, and similar special characters. Likewise, a label should not have leading or trailing whitespace characters.
The \EG manifest must contain a label that contains a unique and descriptive identifier for the election.
\paragraph{Indices.} Instead of using the labels directly, \EG handles contests, selectable options, ballot styles, etc. in terms of their position in a unique ordered list. They can therefore be uniquely identified by an index value. An \emph{index} is a $1$-based ordinal in the range $1 \leq i < 2^{31}$.\footnote{The upper bound of $2^{31}-1$ is in consideration of languages and runtimes that do not have full support for unsigned integers.}
\paragraph{Contests and the contest index.}
The election manifest must contain a single ordered list of all the contests that can appear on any ballot generated for the election. Each contest must have a contest label $\lambda_\Ccal$ that is unique within the election. The position of a given contest $\Ccal$ in this list is the \emph{contest index} $\indc(\lambda_\Ccal)$. The contest list provides a bijective mapping between the unique contest labels and the corresponding contest index values. Note that the first contest in the list has contest index $1$.
\paragraph{Selectable options and the option index.}
For each contest in the contest list, the election manifest must also contain a single ordered list of all the selectable options in this contest. Each selectable option $\Ocal$ must have an option label $\lambda_\Ocal$ that is unique within the contest. The position of a given selectable option $\Ocal$ in this list is the \emph{option index} $\indo(\lambda_\Ocal)$. This option list provides a bijective mapping between the unique selectable option labels and the corresponding option index values. The first selectable option in the list has option index $1$.
\paragraph{Ballot styles and the ballot style index.}
A \emph{ballot style} is a single list of contest indices that defines which contests appear on a ballot generated according to this ballot style. If a contest index is contained in this list, the corresponding contest is present, otherwise it is not. The list is not ordered and only specifies whether a contest is present or not on a ballot of this ballot style. Each ballot style $\Scal$ must have a ballot style label $\lambda_\Scal$ that is unique within the election. The election manifest must contain a single, ordered list of all ballot styles that are possible in the election. The position of a given ballot style $\Scal$ in this list is the \emph{ballot style index} $\inds(\lambda_\Scal)$. The ballot style list provides a bijective mapping between the unique ballot styles and the corresponding ballot style index values. Again, the first ballot style in the list has ballot style index $1$.
\paragraph{Selections, option selection limits and contest selection limits.}
A \emph{selection} is the assignment of a value to an option by the voter. This could be the value $1$, meaning that the voter selected this option, or the value $0$, meaning that the voter did not select this option. To allow other voting methods, \EG allows a selection to be the assignment of a value in a range $\{0,1,\dots,R\}$, where $R$ is the \emph{option selection limit}, a positive integer that defines the maximal value allowed to be assigned to this option by the voter. For each contest, the election manifest must specify the option selection limit for the options in this contest, and must also specify a \emph{contest selection limit} $L$, which is the maximal total value for the sum of all selections made in that contest.
\paragraph{Optional data fields.}
The election manifest offers optional data fields for additional data that can be attached to any of the above concepts and to the manifest in general at the top level. They can be used to provide additional information on contests, selectable options, and ballot styles that go beyond the short unique labels described above. In addition, there can be data fields that describe general information about the election, jurisdiction, election device manufacturers, software versions, the date and location, etc. that help to interpret the additional data.
There are many other things that a manifest may specify. Some examples are listed here.
\paragraph{Undervotes.}
An undervote occurs in a contest if the number of selected options (or more generally, the total sum of selections assigned by the voter) is strictly less than the contest selection limit, the number (or total sum) of allowed selections a voter can make in that contest.
\paragraph{Counting undervoted contests.}
A manifest may specify whether the fact that a contest was undervoted should be recorded for public verification. If this is specified, the indicated contest should have an additional field that functions very much like a selectable option field. The value of this field is an encryption of one if the contest was undervoted on the ballot and an encryption of zero otherwise. The undervote field should be set to one only when the number of option fields that are set to one is strictly less than the contest selection limit. This can be enforced by checking that the sum of all field contents should not exceed the contest selection limit for that contest.
This field is an undervote indicator field and is added to all ballots that contain this contest if the occurrence of an undervote is to be verifiably recorded. The field only indicates that an undervote has occurred on the specific ballot in this contest. A tally of this field will contain the total number of ballots that showed an undervote in this contest.
The field does not record by how many votes the contest was undervoted, i.e. by how much the total number of selections by the voter is less than the contest selection limit. This number can be recorded in an undervote difference count field.
\paragraph{Undervote Difference Count.}
A manifest may specify whether the total number of undervotes, i.e. the difference between the number of selections the voter made and the contest selection limit, for each contest should be recorded for public verification. If this is specified, the indicated contest should have an additional field that functions very much like an option field but whose value need not be limited to zero or one. The value of this field is an encryption of the number of undervotes on that ballot for that contest. This can be enforced by checking that the sum of all field contents should exactly match the contest selection limit for that contest.
\paragraph{Overvotes.}
An overvote occurs in a contest if the voter selected more options than allowed, i.e. more than the contest selection limit for that contest specifies.
A manifest may specify whether an overvoted contest should be recorded for public verification. If this is specified, the indicated contest should have an additional field that functions very much like an option field. The value of this field is an encryption of one if the contest was overvoted on the ballot and an encryption of zero otherwise. When the overvote field is set to one, all other selection fields should be set to zero, and this can be enforced by checking that the sum of the other fields---when added to the product of the contest selection limit with the overvote field contents should not exceed the selection limit for that contest.\footnote{An alternative implementation would be to always set the overvote field to either zero or the contest selection limit. This would be slightly more efficient computationally, but the publicly verified number of overvotes for that contest would be scaled up by a factor of the contest selection limit and the selection limit would then need to be divided out for reporting purposes.} Similar to the undervote difference count, the overvote difference count can be verifiably recorded in a separate overvote difference field.
\paragraph{Write-Ins.}
A manifest may specify whether the utilization of each write-in field in each contest is recorded for public verification. If this is specified, the indicated contest should have one or more additional fields (usually matching the contest selection limit) that function very much like option fields. If a single write-in is utilized in a contest, the first write-in field is set to one and all others are set to zero; if two write-ins are utilized in a contest, the first two write-in fields are set to one and all others are set to zero; etc. Range proofs should be included to show that each of these individual write-in fields is an encryption of either zero or one.
\paragraph{Write-Ins Total.}
A manifest may specify whether the total number of write-ins selected in each contest is recorded for public verification. If this is specified, the indicated contest should have a single additional field that functions very much like option fields but whose value need not be limited to zero or one. The value of this field is an encryption of the number of write-ins utilized on that ballot for that contest. Range proofs should be used to demonstrate that in each instance, the value of this field is non-negative and does not exceed the contests selection limit.
\paragraph{A note on selection limit proofs.} In general, a combination of the above fields can be merged into a single selection limit proof per contest per ballot. For example, a contest which includes an undervote field, an overvote field, and two separate write-in fields can include a single range proof that the sum of these fields is non-negative and does not exceed the contest selection limit. The only exceptions are the very unusual cases where a manifest specifies including both an undervote field and an undervote count field or both individual write-in fields and a write-in total field. In these cases, the selection limit proofs should each include only one of the paired fields (e.g., undervote or undervote count) and a second selection limit proof should be included if both paired fields are to be verified.
\subsubsection{Election manifest hash}\label{sec:manifesthash}
The data in the election manifest is written to a file \texttt{manifest} in a canonical representation that may be implementation specific.
The election manifest file \texttt{manifest} is hashed\footnote{The file that constitutes the election manifest is input to $H$ as an entire file. Again the $\mathtt{0x01}$ byte at the beginning of the second argument is a domain separation byte (in hex). In what follows, all uses of the function $H$ include such domain separation bytes.} using the \EG hash function with the parameter hash $\HH_P$ to produce the manifest digest
\begin{equation}\label{eq:manifesthash}
\HH_M = H(\HH_P; \mathtt{0x01}, \mathtt{manifest}).
\end{equation}
\subsubsection{Election base hash}\label{sec:basehash}
The election base hash $\HH_B$ is computed from the parameter base hash $\HH_P$ and the manifest hash $\HH_M$ together with the number $n$ of guardians that participate in the election, and the quorum value $k$, as
\begin{equation}\label{eq:basehash}
\HH_B = H(\HH_P; \mathtt{0x02}, \HH_M, n, k).
\end{equation}
Incorporating the byte array $\HH_B$ into subsequent hash computations binds those hashes to the election parameters, the number of guardians, the threshold value and to a specific election by including the manifest.
\EGverif{\veriftitleParameterValidation}{\label{verif:parameters}
\veriftextParameterValidation}
\subsection{Key Generation}\label{sec:keygen}
Before an election, the number of guardians ($n$) is fixed together with a quorum value ($k$) that describes the number of guardians necessary to decrypt tallies and produce election verification data. The values $n$ and $k$ are integers subject to the constraint that $1\leq k \leq n$. Canvassing board members can often serve the role of election guardians, and typical values for $n$ and $k$ could be 5 and 3 -- indicating that 3 of 5 canvassing board members must cooperate to produce the artifacts that enable election verification. The reason for not setting the quorum value $k$ too low is that it will also be possible for $k$ guardians to decrypt individual ballots.
\EGnote{Decryption of individual ballots does not directly compromise voter privacy since links between encrypted ballots and the voters who cast them are not retained by the system. However, voters receive confirmation codes that can be associated with individual encrypted ballots, so any group that has the ability to decrypt individual ballots can also coerce voters by demanding to see their confirmation codes.}
Threshold encryption is used for encryption of ballots. This form of encryption makes it very easy to combine individual guardian public keys into a single public key for encrypting votes and ballots. It also offers a homomorphic property that allows individual encrypted votes to be combined to form encrypted tallies.
The guardians of an election will each generate a public-secret key pair. The public keys will then be combined (as described in the following section) into a single election public key which is used to encrypt all selections made by voters in the election.
At the conclusion of the election, each guardian will compute a verifiable partial decryption of each tally. These partial decryptions will then be combined to form full verifiable decryptions of the election tallies.
To accommodate the possibility that one or more of the guardians will not be available at the conclusion of the election to form their partial decryptions, the guardians will cryptographically share\footnote{Shamir A. (1979) \emph{How to Share a Secret}. Communications of the ACM, vol 22.} their secret keys amongst each other during key generation in a manner to be detailed in the next section. Each guardian will then compute a share of the secret decryption key, which it uses to form the partial decryptions.
A pre-determined quorum value ($k$) out of the ($n$) guardians will be necessary to produce a full decryption.
If the same set of $n$ guardians support multiple elections using the same threshold value $k$, the generated keys and key shares may be reused across several elections.
\subsubsection{Overview of key generation}
The $n$ guardians of an election are denoted by $G_1,G_2,\dots,G_n$. Each guardian $G_i$ generates an independent public-secret key pair by generating a random integer secret $s_i\in\Z_q$ and forming the public key $K_i = g^{s_i} \bmod p$. Each of these public keys will be published in the election record together with a non-interactive zero-knowledge Schnorr proof of knowledge of the associated secret key.
The joint election public key will be
\begin{equation}
K = \prod_{i=1}^n K_i \bmod p.
\end{equation}
To enable robustness and allow for the possibility of missing guardians at the conclusion of an election, the \EG key generation includes a sharing of secret keys between guardians to enable decryption by any $k$ guardians. This sharing is verifiable, so that receiving guardians can confirm that the shares they receive are correct; and the process allows for decryption without explicitly reconstructing secret keys of missing guardians.