-
Notifications
You must be signed in to change notification settings - Fork 11
/
TODO.txt
2617 lines (2071 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
a trait for fn to_canonical_json()
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
====^^^^====^^^^====^^^^====^^^^====^^^^==== 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
Election parameters: add a type field initally set to 'HomomorphicTallying'
[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
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====
Abbreviations:
RI Reference Implementation
OI Other implementation
%%%%%%%%%%%%% The plan here is to chop up the specification text and extract statements that can be translate into test cases
\pagebreak
\tableofcontents
\pagebreak
-------- Section 1
\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.
---- S1a
\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).
}.
---- S1b
\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.
---- S1c
\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.
S1 Individual voters can verify that their votes have been accurately recorded.
S1 Voters and observers can verify that all recorded votes have been accurately counted.
S1 An E2E-verifiable tally can be used as the primary tally in an election sor as a verifiable secondary tally alongside traditional methods.
S1 ElectionGuard is compatible with in-person voting using an electronic ballot-marking device
S1 ElectionGuard is compatible with in-person voting using an optical scanner capable of reading hand-marked ballots
S1 ElectionGuard is compatible with in-person voting using an optical scanner capable of reading machine-marked ballots
S1 ElectionGuard is compatible with with voting by mail
S1 ElectionGuard is compatible with with Internet voting
S1 ElectionGuard can enable public disclosure of encrypted ballots that can sbe matched directly to physical ballots selected for auditing
S1 ElectionGuard can enable public disclosure of encrypted ballots that can be proven to match the reported tallies.
-------- Section 2
%pagebreak
---- S2a
\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.
S2a A quorum of guardians can produce the artifacts required to enable public verification of the tally.
S2a A quorum of guardians is necessary to produce the artifacts required to enable public verification of the tally.
---- S2b
\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.
S2b Each guardian generates its own public-secret key pair.
S2b The guardian public keys can be combined to form a single public key
S2b The single public key can encrypt votes.
S2b The guardian public keys can be used individually by guardians to exchange information about their secret keys enabling the election record tob be produced after voting or auditing is complete
S2b The guardian public keys can be used individually by guardians to exchange information about their secret keys enabling the election record tob be produced after voting or auditing is complete even if not all guardians are available at that time
S2b Each guardian can publish their public keys together with proofs of knbowledge of the associated secret keys.
S2b Each guardian can use each other guardian's public key to encrypt shares ofb its own secret keys
S2b Each guardian can decrypt the shares it receives from other guardians
S2b Each guardian can check the decrypted shares for consistency
S2b A guardian sender can reveal the shares it sent
S2b If all challenged guardians release their challenged shares and these shbares all verify, the ceremony can conclude and the election proceed.
S2b A guardian can be removed if they are challenged and fail to produce key shbares that verify
S2b the key generation ceremony can be restarted with a replacement guardian.
---- S2c
\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.
S2c The election system can make a single call to the ElectionGuard API after each voter completes the process of making selections
S2c The election system can make a single call to the ElectionGuard API with each ballot to be encrypted for an RLA.
S2c ElectionGuard will encrypt the selections made by the voter and return a confirmation code for the system to give to the voter after they complete the process of making selections. (not relevant to RLA scenario)
S2c No other point at which an existing election system must interface with EG is required.
S2c Voters will have an opportunity to challenge their encrypted ballots and view their decryptions to ensure that the encryptions are correct.
S2c A decypted ballot should never be cast, can EG somehow ensure this?
S2c In an RLA, some anonymized cast ballots may be challenged and decrypted.
S2c In certain vote-by-mail scenarios, cast-vote records can be provided in batch without any interface between the voting equipment and ElectionGuard.
S2c When ElectionGuard is used within an RLA, cast-vote records can be provided in batch without any interface between the voting equipment and ElectionGuard
S2c Encrypted ballots can be published along with non-interactive zero-knowledge (NIZK) proofs of their well-formedness.
S2c The NIZK proofs assert that an encrypted ballot is a legitimate ballot
S2c The NIZK proofs assert that an encrypted ballot adheres to the limits S2c imposed on selection options
S2c The NIZK proofs assert that an encrypted ballot adheres to the limits imposed on contests
S2c The NIZK proofs prove that a selection did not receive more votes than allowed
S2c The NIZK proofs prove that no more than the allowed number of votes were received across the selection options in each contest.
S2c The encryption method allows the encrypted ballots to be combined into a single aggregate ballot
S2c The single aggregate ballot into which the encryption method combined the encrypted ballots consists of encryptions of the election tallies.
---- S2d
\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.
S2d Each guardian can compute from the previously shared secret key fragments a share of the secret decryption key
S2d Guardians can independently use their share of the secret decryption key to jointly decrypt the election tallies
S2d Guardians can independently use their share of the secret decryption key to generate associated verification data
S2d Only a quorum of guardians is sufficient to complete decryption
S2d Only a quorum of guardians is sufficient to generate the verification data
---- S2e
\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.
S2e An observer can use this open specification and/or accompanying materials to write independent election verifiers that can confirm the well-formedness of each encrypted ballot
S2e An observer can use this open specification and/or accompanying materials to write independent election verifiers that can the correct aggregation of these ballots
S2e An observer can use this open specification and/or accompanying materials to write independent election verifiers that can the accurate decryption of election tallies.
\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.
---- S2f
\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 3
---- S3a
\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 ElectionGuard. 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.
S3a2 Guardians can generate individual public-secret key pairs
S3a2 Guardians can exchange shares of secret keys
S3a2 If the set of guardians and parameters k and n remain the same, they can re-use the same keys for multiple elections
S3a2 A complete new set of keys must be generated if k is changed
S3a2 A complete new set of keys must be generated if n is changed
S3a2 A complete new set of keys must be generated if even a single guardian is replaced
S3a2 TODO is this true?: A complete new set of keys must be generated if any of p, q, r, g is changed
\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}
S3a3 Guardians can use their secret key shares to jointly produce election tallies together with verifiable artifacts that prove that the tallies are correct.
---- S3b
\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}
---- S3c
\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.
S3c Encryption of votes in ElectionGuard is performed using the DPP vote encryption method of Devillez, Pereira, and Peters (2022)
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$.)
S3c P is fixed
S3c P is prime
S3c Q is fixed
S3c Q is prime
S3c Q is is not a divisor of r=(p-1)/q
S3c G is fixed.
S3c G is a generator $g$ of the order $q$ subgroup $\Z_p^r$
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.}.
S3c No entity is ever 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}
S3c A message $m\in\Z_p^r$ can be 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)$
S3c An encryption $(\alpha, \beta)$ can be decrypted by the holder of the secret $s$ as $\beta/\alpha^s\bmod p = K^m \bmod p$
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.
S3c The value of $K^m$ can be computed from the encryption nonce $\xi$
S3c The value of $m$ can be computed from the encryption nonce $\xi$
S3c An encryption of one is used to indicate that an option is selected
S3c An encryption of zero is used to indicate that an option is not selected
---- S3d
\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.
S3d All the encryptions of a single option across ballots can be multiplied to form an encryption of the sum of the individual values
S3d An encryption of some other integer is used for certain voting methods
S3d The product of the encryptions of a single option across ballots 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.
S3d Every option can be demonstrated to be an encryption of either zero or one
S3d Every option can be demonstrated to be an encryption of some other integer for certain voting methods
S3d The product of the encrypted options of a single ballot can be used to show that no more options were selected than permitted
S3d When an option can receive multiple or weighted votes, the product of the encrypted options of a single ballot can be used to show that 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$.
S3d A holder of a nonce $\xi$ can prove to a third party that a pair $(\alpha, \beta)$ is an encryption of $m$ without access to the secret $s$ or revealing the nonce $\xi$
---- S3e
\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$.
S3e1 The holder of a secret key $s$ can interactively prove possession of $s$ without revealing $s$ using a Schnorr proof.
\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.)
S3e2 An encryption can be interactively proven to decrypt to a particular value without revealing the nonce used for encryption or the secret decryption key $s$, with access to the nonce used for encryption with a Chaum-Pedersen proof.
S3e2 An encryption can be interactively proven to decrypt to a particular value without revealing the nonce used for encryption or the secret decryption key $s$, with access to $s$ using a Chaum-Pedersen proof.
\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.
S3e3 A disjunction can be interactively proven without revealing which disjunct is true using the Cramer-Damgård-Schoenmakers technique.
\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.
S3e4 An interactive proof can be converted into a non-interactive proof using the Fiat-Shamir heuristic.
\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.}
S3e ElectionGuard can demonstrate that keys are properly chosen.
S3e ElectionGuard can demonstrate that ballots are well-formed.
S3e ElectionGuard can demonstrate that decryptions match claimed values.
---- S3f
\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.
S3f Threshold encryption is used for encryption of ballots and other data.
S3f It is very easy to combine individual guardian public keys into a single public key.
S3f Threshold encryption 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.
S3f Every guardian can generate a public-secret key pair.
S3f The guardians' public keys can be combined into a single election public key.
S3f The single election public key can be 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.
S3f A guardian can compute a verifiable partial decryption of every tally.
S3f Verifiable partial tally decryptions can 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.
S3f During key generation, a guardian can cryptographically share their secret keys with another guardian per Section~\ref{sec:keygen}.
S3f A guardian, having received secret keys from other guardians, can compute a share of the secret decryption key
S3f A guardian, having computed a share of the secret decryption key, can
form a partial decryption.
---- S3g
\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.
S3g EGRI provides a non-homomorphic encryption method known as "hashed ElGamal" for encrypting data other than votes
S3g EGRI provides a way to use the appropriate private key to decrypt data encrypted with hashedElGamal
S3g data encrypted with hashedElGamal cannot be decrypted without the private key
S3g hashed ElGamal encryption does not have the data size restrictions imposed by the vote encryption
S3g hashed ElGamal encryption uses a KDF based on HMAC-SHA-2-256 to generate a key stream XORed with the data
S3g EGRI allows to encrypt the cryptographic shares of a guardian's secret key to the receiving guardians' public keys
S3g EGRI allows to encrypt to the election public key write-in information to be attached to an encrypted selection
S3g EGRI allows to attach to an encrypted selection write-in information that is encrypted to the election public key
S3g EGRI allows to attach to an encrypted ballot other auxiliary data without size restrictions encrypted with hashed-ElGamal to the election public key
S3g EGRI allows to attach to an encrypted ballot other auxiliary data without size restrictions encrypted with hashed-ElGamal to an administrative public key
---- S3.1
\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.
S3.1 EGRI uses integer-based encryption rather than elliptic curves
S3.1 EGRI does not use elliptic curves
S3.1 The encryption scheme used to encrypt votes is defined by primes p and q.
S3.1 q divides p - 1
S3.1 r = (p-1)/q is fixed. We also require $r/2$ to be prim
S3.1 r is a generator g of the order q subgroup Z_p^r
S3.1 subgroup Z_p^r is of order q
S3.1 r/2 is prime
S3.1 The value of p matches the specific value given in EG 2.0 DS section 3.1
S3.1 The value of q matches the specific value given in EG 2.0 DS section 3.1
S3.1 The value of r matches the specific value given in EG 2.0 DS section 3.1
S3.1 The value of g matches the specific value given in EG 2.0 DS section 3.1
---- S3.1.1
\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}}
---- S3.1.2
\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.
S3.1.2 H_P is computed as H("v2.0.0" zero extended to length 32 ; 0x00, p, q, g)
S3.1.2 The value computed for H_P is 0x2B3B025E50E09C119CBA7E9448ACD1CABC9447EF39BF06327D81C665CDD86296
---- S3.1.3
\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.
S3.1.3a The RI provides a parameter for a public election manifest
S3.1.3a The election manifest is a single file
S3.1.3a The election manifest describes the modalities of the election and specifies a wide range of data about it
S3.1.3a The election manifest lists for each contest, the candidates (selectable options)
S3.1.3a The election manifest lists for each contest, associations between each selectable option and its representation on a virtual ballot
S3.1.3a The election manifest lists for each contest, the number of options that a voter may select in that contest (selection limit)
S3.1.3a The election manifest lists for each contest, defines a label unique across all contests in the manifest
S3.1.3a The election manifest lists for each selectable option, defines a label unique across all selectable options in that contest
\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.
S3.1.3b Contests are identified by labels unique within the election manifest
S3.1.3b Selectable options are identified by labels unique within their contest
S3.1.3b The RI rejects labels that contain line break characters, tabs, or similar special characters
S3.1.3b The RI rejects labels that have leading or trailing whitespace
S3.1.3b The election manifest has a unique and descriptive identifier for the election. The RI rejects any manifest without it
\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.}
S3.1.3c Index values are integers in the range 1 <= i < 2^31
S3.1.3c Every contest within the election manifest is uniquely identified by an index value, implied by the order defined in the election manifest.
S3.1.3c Every selectable option within a contest is uniquely identified by an index value, implied by the order defined in the contest election manifest.
S3.1.3c Every ballot style within the election manifest is uniquely identified by an index value implied by the order defined in the election manifest.
S3.1.3c The first ballot style within the election manifest has index value 1.
\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$.
S3.1.3d The election manifest defines a single ordered list of all contests on any ballot
S3.1.3d The first contest within the election manifest has index value 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$.
S3.1.3e Every contest in the election manifest defines a single ordered list of all selectable options.
S3.1.3e The first selectable option within each contest has index value 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$.
S3.1.3f The election manifest defines a single ordered list of all ballot styles
S3.1.3f The first ballot style within the election manifest has index value 1.
S3.1.3f Every ballot style defines a label unique across all ballot styles in the manifest
S3.1.3f Every ballot style defines a single list of contest indices
S3.1.3f Order is not significant in a ballot style contest index list
S3.1.3f The RI rejects the manifest if any contest index does not refer to a contest in the election manifest
S3.1.3f The RI rejects the manifest if any contest index appears more than once in the same ballot style contest index list
\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.
S3.1.3g Every contest in the election manifest may specify a nonnegative integer contest selection limit
S3.1.3g If not specified, the contest selection limit defaults to 1
S3.1.3g The contest selection limit limits the maximum total value that can be assigned all options in that contest
S3.1.3g Every selectable option in every contest may specify a nonnegative integer option selection limit
S3.1.3g If not specified, the option selection limit defaults to 1
S3.1.3g The option selection limit limits the maximum value that can be assigned to that selectable option
S3.1.3g Every selectable option field must be voter-assigned a nonnegative integer value less than or equal to the smaller of the contest and option selection limits.
S3.1.3g RI may warn if any contest selection limit is zero
S3.1.3g RI may warn if any option selection limit is zero
S3.1.3g RI may warn if any option selection limit is greater than the contest selection limit
\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.
S3.1.3h Election manifest allows additional data to describe general information about the election
S3.1.3h Election manifest allows additional data to describe general information about the jurisdiction
S3.1.3h Election manifest allows additional data to describe general information about the election device manufacturers
S3.1.3h Election manifest allows additional data to describe general information about software versions
S3.1.3h Election manifest allows additional data to describe general information about date
S3.1.3h Election manifest allows additional data to describe general information about location
\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.
S3.1.3i 'Undervote condition' or 'undervoted' is a per-contest state in which the sum of the selections is strictly less than the contest selection limit
\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.
S3.1.3j Every contest within the election manifest can specify that an undervote condition is to be recorded for public verification
S3.1.3j If a contest specifies to record undervote conditions, the contest has an additional 'undervoted' field that functions much like a selectable option
S3.1.3j Every contest 'undervoted' field must be system-assigned a value of 0 or 1
S3.1.3j Every contest 'undervoted' field must be system-assigned a value 1 if and only if that contest was undervoted on that ballot
S3.1.3j Every contest 'undervoted' field must include a range proof that the encrypted value is either 0 or 1
S3.1.3j The value of a contest 'undervoted' field does not count against the contest selection limit
\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.
S3.1.3k Every contest within the election manifest can specify that the net undervote is to be recorded for public verification. TODO: Does it make sense to specify this in addition to the S3.1.3j 'undervoted' additional field, or are they mutually exclusive?
S3.1.3k If a contest specifies to record the net undervote, the contest has an additional 'net undervote' field that functions much like a selectable option, but is not voter-assigned
S3.1.3k Every contest 'net undervote' field must be system-assigned a value of 0 through the contest selection limit, according to the net undervote on that ballot
S3.1.3k Every contest 'net undervote' field must include a range proof that the encrypted value is 0 through the contest selection limit, inclusive
S3.1.3k The value that the system assigns to a contest 'net undervote' field must be the contest selection limit minus the sum of the voter-assigned selections
S3.1.3k The value of any 'net undervote' field does not count against the contest selection limit
S3.1.3k TODO: range proof for 'net undervote' field?
\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.
S3.1.3l 'Overvote condition' or 'overvoted' is a per-contest state in which a selection is strictly greater the option selection limit and/or the sum of the selections is strictly greater than the contest selection limit.
S3.1.3l Every contest within the election manifest can specify that an overvote condition is to be recorded for public verification
S3.1.3l If a contest specifies to record overvote conditions, the contest has an additional 'overvoted' field that functions much like a selectable option, but is not voter-assigned
S3.1.3l Every contest 'overvoted' field must be system-assigned a value of 0 or 1
S3.1.3l Every contest 'overvoted' field must be system-assigned a value of 1 if and only if that contest was overvoted on that ballot
S3.1.3l Every contest 'overvoted' field must include a range proof that the encrypted value is either 0 or 1
S3.1.3l The value of an 'overvoted' field does not count against the contest selection limit
S3.1.3l Whenever a contest 'overvoted' field is set to 1, all voter-assigned fields must be set to 0
S3.1.3l RI (tallying? verification?) must verify for every contest that the sum of all voter-assigned fields, 'undervoted', 'net undervote', and (the product of the 'overvoted' field and the contest selection limit) is less than or equal to the contest selection limit.
S3.1.3l Every contest within the election manifest can specify that the net overvote is to be recorded for public verification. TODO: Does it make sense to specify this in addition to the S3.1.3l 'overvoted' additional field, or are they mutually exclusive?
S3.1.3l If a contest specifies to record the net overvote, the contest has an additional 'net overvote' field that functions much like a selectable option, but is not voter-assigned
S3.1.3l Every contest 'net overvote' field must be system-assigned the nonnegative integer value that is the the greater of (each option's voter-assigned selection minus the option selection limit), (the sum of the voter-assigned selections minus the contest selection limit), and 0. I.e., the total selection value that would need to be removed to cure the overvote condition.
S3.1.3l Every contest 'net overvote' field must include a range proof that the encrypted value is a nonnegative integer less than or equal to the greater of [(the sum of the voter-assigned selection option fields minus the contest selection limit) and (the sum of the voter-assigned selection option fields minus the smallest option selection limit)]. TODO could this identify the overvoted field
S3.1.3l The value of any 'net overvote' field does not count against the contest selection limit
\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.
S3.1.3m Every contest within the election manifest can specify the number of write-in fields to be recorded for public verification
S3.1.3m RI may warn if any contest specifies a number of write-in fields greater than the contest selection limit
S3.1.3m If a contest specifies to include a nonzero number of write-in fields, the contest has that number additional 'write-in N' fields as voter-assignable selectable options
S3.1.3m Any such write-in fields are to be labeled as "write-in N", where 'N' is the corresponding 1-based index value within the contest
S3.1.3m "Written-in" means that the election system has recorded some voter-supplied, non-empty, non-blank data in associated with a contest and write-in field index value
S3.1.3m Write-in fields must be written-in in index order. I.e., write-in field N can only be written-in if all write-in fields having lower-valued indexes are also written-in.
S3.1.3m All write-in fields must be assigned a value of 0 or 1
S3.1.3m A write-in field field must be assigned a value of 1 if and only if it was written-in
S3.1.3m The value of an write-in field counts against the contest selection limit
S3.1.3m Every write-in field must supply a range proof that the encrypted value is either 0 or 1
S3.1.3m TODO can we prove they are written-in in order?
\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.
S3.1.3n Every contest within the election manifest can specify that the count of write-in fields written-in is to be recorded for public verification.
S3.1.3n If a contest specifies to record the the count of fields written-in, the contest has an additional system-assigned 'count written-in' field
S3.1.3n Every contest 'count written-in' field must be system-assigned a value of 0 through the contest selection limit
S3.1.3n The value that the system assigns to a contest 'count written-in' field must be the count of write-in fields that were written-in
S3.1.3n The value of any 'count written-in' field does not count against the contest 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.
S3.1.3o TODO Range proofs of the various combinations of fields (selectable options, undervoted, net undervote, overvoted, net overvote, write-in N, count written-in) may be combined under specific conditions
---- S3.1.4
\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}
S3.1.4 A canonical byte representation is defined for the election manifest.
S3.1.4 RI allows to write the election manifest canonical representation to a file.
S3.1.4 RI uses the election manifest canonical representation in the hash computation.
S3.1.4 H_M is computed as H(H_P; 0x01, [election manifest canonical representation])
---- S3.1.5
\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.
S3.1.5 parameter n is the number of guardians
S3.1.5 parameter k is the number of guardians required to form a quorum for decryption
S3.1.5 H_B is computed as H(H_P; 0x02, H_M, n, k)
\EGverif{\veriftitleParameterValidation}{\label{verif:parameters}
\veriftextParameterValidation}
---- S3.2
\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.
ref: S3a2 Guardians can generate individual public-secret key pairs
ref: S3a2 Guardians can exchange shares of secret keys
ref: S3a2 If the set of guardians and parameters k and n remain the same, they can re-use the same keys for multiple elections
ref: S3a2 A complete new set of keys must be generated if even a single guardian is replaced
S3.2 RI rejects any election manifest unless 1 <= k <= n < 2^31
S3.2 Ballots are encrypted using threshold encryption
S3.2 It is straightforward to combine individual guardian public keys into a single election public key
S3.2 Every guardian can Shamir-share their secret key during key generation
S3.2 All selections made by voters can be encrypted to the single election public key
S3.2 After the election, every guardian can compute a verifiable partial decryption of every tally
S3.2 'k' distinct guardian secret keys can produce a full decryption of every tally
S3.2 Fewer than 'k' distinct guardian secret keys can not produce a full decryption of any tally
---- S3.2.1
\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.
Each guardian $G_i$ generates $k-1$ random polynomial coefficients $a_{i,j}$ such that $0<j<k$ and $0\leq a_{i,j} < q$ and forms the polynomial
\begin{equation*}
P_i(x) = \sum_{j=0}^{k-1} a_{i,j} x^j \bmod q
\end{equation*}
by setting $a_{i,0}$ equal to its secret value $s_i$. Guardian $G_i$ then publishes commitments $K_{i,j} = g^{a_{i,j}} \bmod p$ to each of its polynomial coefficients. As with the primary secret keys, each guardian should provide a Schnorr proof of knowledge of the secret coefficient value $a_{i,j}$ associated with each published commitment $K_{i,j}$. Since polynomial coefficients will be generated and managed in precisely the same fashion as secret keys, they will be treated together in a single step below.
At the conclusion of the election, individual encrypted ballots will be homomorphically combined into a single encrypted aggregate ballot -- consisting of an encryption of the tally for each option offered to voters. Each guardian will use its share of the secret decryption key to generate a partial decryption of each encrypted tally value, and these partial decryptions will be combined into full decryptions. If any election guardians are missing during tallying, any set of $k$ guardians who are available can cooperate to complete decryption.
All challenged ballots are individually decrypted in precisely the same fashion.
ref: S3.2 Each guardian can Shamir-share their secret key during key generation
S3.2.1 Receiving guardians can confirm that the key shares they receive are correct
S3.2.1 Every guardian can generate an independent public-secret key pair by generating a random integer secret s_i in Z_q
S3.2.1 Every guardian can form their guardian public key as K_i = g^{s_i} mod p
S3.2.1 The election record contains every guardian's public key
S3.2.1 The election record contains, for every guardian public key, a non-interactive zero-knowledge Schnorr proof of knowledge of the associated secret key
S3.2.1 The joint election public key K is computed as \prod_{i=1}^n K_i mod p
S3.2.1 Every guardian G_i can generate k - 1 random polynomial coefficients a_{i,j} such that 0 < j < k and 0 <= a_{i,j} < q
S3.2.1 Every guardian G_i can generate and publish commitments K_{i,j} = g^{a_{i,j}} mod p to each of its polynomial coefficients
S3.2.1 Guardian polynomial coefficients are generated and managed in precisely the same fashion as secret keys
S3.2.1 Individual encrypted ballots can be homomorphically combined into a single encrypted aggregate ballot
S3.2.1 The single encrypted aggregate ballot consists of an encryption of the tally for each contest (e.g. selection option) field
S3.2.1 Any set of k guardians' private keys is sufficient to complete decryption of the tally for each contest (e.g. selection option) field
S3.2.1 No set of fewer than k guardians' private keys is sufficient to complete decryption of the tally for any contest (e.g. selection option) field
S3.2.1 Any challenged ballot can be individually decrypted in the same fashion as the tally for a contest (e.g. selection option) field
---- S3.2.2
\subsubsection{Details of key generation}\label{sec:keygendetails}
\paragraph{Guardian coefficients and key pair.}
Each guardian $G_i$ in an election with a decryption threshold of $k$ generates $k$ secret polynomial coefficients $a_{i,j}$, for $0 \leq j < k$, by sampling them uniformly, at random in the range $0 < a_{i,j} < q$ and forms the polynomial
\begin{equation}
P_i(x) = \sum_{j=0}^{k-1} a_{i,j} x^j \bmod q.
\end{equation}
Guardian $G_i$ then publishes commitments
\begin{equation}
K_{i,j} = g^{a_{i,j}} \bmod p
\end{equation}
for each of its polynomial coefficients $a_{i,j}$, for $0 \le j <k$. The constant term $a_{i,0}$ of this polynomial will serve as the secret key for guardian $G_i$, and for convenience we denote $s_i = a_{i,0}$, and its commitment $K_{i,0}$ will serve as the public key for guardian $G_i$ and will also be denoted as $K_i = K_{i,0}$.
In order to prove possession of the coefficient associated with each public commitment, for each $K_{i,j}$ with $0\leq j < k$, guardian $G_i$ generates a Schnorr proof of knowledge for each of its coefficients as follows.
S3.2.2a Every guardian i can generate and store k secret polynomial coefficients (indexed as 0 <= j < k) by sampling a CSRNG uniformly as 0 < a_{i,j} < q
S3.2.2a Every guardian i can generate, store, and publish a Schnorr proof of knowledge for each of its k secret polynomial coefficients (indexed as 0 <= j < k).
\paragraph{NIZK Proof:} Guardian $G_i$ proves knowledge of secrets $a_{i,j}$ such that $K_{i,j}= g^{a_{i,j}} \bmod p$.
\noindent For each $0\leq j < k$, Guardian $G_i$ generates random integer values $u_{i,j}$ in $\Z_q$ and computes
\begin{equation}
h_{i,j} = g^{u_{i,j}} \bmod p.
\end{equation}
Then, using the hash function $H$ (as defined in Section~\ref{sec:hashing} below), guardian $G_i$ performs a single hash computation
\begin{equation}\label{eq:hash_nizk_keygen}
c_{i,j} = H(\HH_P; \mathtt{0x10}, i, j, K_{i,j}, h_{i,j})
\end{equation}
and publishes the Schnorr proof $(c_{i,j}, v_{i,j})$ consisting of the challenge value $c_{i,j}$ and the response value $v_{i,j} = (u_{i,j}-c_{i,j} a_{i,j}) \bmod q$ together with $K_{i,j}$.
\EGverifExtended{\veriftitleGuardianPublicKeyValidation}{\label{verif:guardiansPK}\veriftextGuardianPublicKeyValidation}
\footnote{This verification box and some others below contain computation steps as well as verification conditions. The former are numbered with decimal numerals, while the latter are numbered with capital letters alphabetically.}
It is worth noting here that for any fixed constant $\alpha$, the value $g^{P_i(\alpha)} \bmod p$ can be computed entirely from the published commitments as
\begin{equation}
g^{P_i(\alpha)} \bmod p = g^{\sum_{j=0}^{k-1} a_{i,j} \alpha^j}\bmod p
= \prod_{j=0}^{k-1} g^{a_{i,j} \alpha^j}\bmod p
= \prod_{j=0}^{k-1} (g^{a_{i,j}})^{\alpha^j}\bmod p
= \prod_{j=0}^{k-1} K_{i,j}^{\alpha^j} \bmod p.
\end{equation}
\EGnote{Although this formula includes double exponentiation -- raising a given value to the power $\alpha^j$ -- in what follows, $\alpha$ and $j$ will always be small values (bounded by $n$). This can also be reduced since the same result will be achieved if the exponents $\alpha^j$ are reduced to $\alpha^j \bmod q$.}
S3.2.2b [1/7] The Schnorr proof of knowledge for a guardian G_i coefficient 0 <= j < k is formed by
S3.2.2b [2/7] generating a random integer value by sampling a CSRNG uniformly as 0 <= u_{i,j} < q
S3.2.2b [3/7] computing h_{i,j} = g^{u_{i,j}} mod p.
S3.2.2b [4/7] computing challenge value c_{i,j} = H(H_P; 0x10, i, j, K_{i,j}, h_{i,j})
S3.2.2b [5/7] computing response value v_{i,j} = (u_{i,j} - c_{i,j}*a_{i,j}) mod q
S3.2.2b [6/7] the Schnorr proof is then the pair (c_{i,j}, v_{i,j}).
S3.2.2b [7/7] The Schnorr proof of knowledge for a guardian G_i coefficient 0 <= j < k can be published.
\paragraph{Share encryption.}
To share secret values amongst each other, each guardian $G_i$ encrypts its share for each other guardian $G_\ell$ using an encryption function $E_\ell$ that can be instantiated using that guardian's public/secret key pair $(K_\ell = g^{s_\ell} \bmod p, s_\ell)$ as laid out in the section describing the encryption of other data above. This means that each guardian $G_i$ publishes the encryption $E_\ell(P_i(\ell))$ for every other guardian $G_\ell$ as follows.
Guardian $G_i$ uses guardian $G_\ell$'s public key $K_\ell$ and a randomly-selected nonce $\xi_{i,\ell}\in\Z_q$ to compute
\begin{equation}
(\alpha_{i,\ell}, \beta_{i,\ell}) = (g^{\xi_{i,\ell}} \bmod p, K_\ell^{\xi_{i,\ell}} \bmod p)
\end{equation}
and the secret key
\begin{equation}\label{eq:hash_shareenc}
k_{i,\ell} = H(\HH_P; \mathtt{0x11}, i, \ell, K_\ell,\alpha_{i,\ell}, \beta_{i,\ell}).
\end{equation}
Using the keyed Hash Message Authentication Code \HMAC instantiated with \SHA, this key is used to derive\footnote{NIST (2022) \emph{Recommendation for Key Derivation Using Pseudorandom Functions}. In: SP 800-108r1 \url{https://csrc.nist.gov/publications/detail/sp/800-108/rev-1/final}.} the \MAC key
\begin{equation}\label{eq:share_enc_MACkey}
k_0 = \HMAC(k_{i,\ell},\mathtt{0x01}\parallel\mathtt{Label}\parallel\mathtt{0x00}\parallel\mathtt{Context}\parallel\mathtt{0x0200})
\end{equation}
and the encryption key
\begin{equation}\label{eq:share_enc_ENCkey}
k_1 = \HMAC(k_{i,\ell},\mathtt{0x02}\parallel\mathtt{Label}\parallel\mathtt{0x00}\parallel\mathtt{Context}\parallel \mathtt{0x0200}),
\end{equation}
which both are 256 bits (32 bytes) long, and where $\mathtt{Label} = \bytes(\Str{share\_enc\_keys},14)$ and $\mathtt{Context} = \bytes(\Str{share\_encrypt},13)\parallel\bytes(i,4)\parallel\bytes(\ell,4)$.\footnote{This key derivation uses the KDF in counter mode from SP 800-108r1. The second input to \HMAC contains the counter in the first byte, the UTF-8 encoding of the string $\Str{share\_enc\_keys}$ as the \emph{Label} (encoding is denoted by $\bytes(\dots)$, see Section~\ref{sec:stringencoding}), a separation \texttt{0x00} byte, the UTF-8 encoding of the string $\Str{share\_encrypt}$ concatenated with encodings of the numbers $i$ and $\ell$ of the sending and receiving guardians as the \emph{Context}, and the final two bytes specifying the length of the output key material as 512 bits in total.}
Since $P_i(\ell)$ is an integer modulo $q$, it can be encoded as a byte array $\bytes(P_i(\ell),32)$ of exactly 32 bytes as specified in Section~\ref{sec:intmodq}. The encoded value is then encrypted as
\begin{equation}
E_\ell(P_i(\ell)) = (C_{i,\ell,0},C_{i,\ell,1},C_{i,\ell,2}),
\end{equation}
where
\begin{equation}
C_{i,\ell,0} = g^{\xi_{i,\ell}} \bmod p,\quad
C_{i,\ell,1} = \bytes(P_i(\ell),32) \oplus k_1,\quad
C_{i,\ell,2} = \HMAC(k_0, \bytes(C_{i,\ell,0},512)\parallel C_{i,\ell,1}).
\end{equation}
S3.2.2c Every guardian G_i can encrypt its key share for every other guardian G_l to that guardian's public key K_l = g^{s_l} mod p
S3.2.2c [1/12] To encrypt its key share to that other guardian's public key K_l, guardian G_i
S3.2.2c [2/12] randomly-selects a nonce by sampling a CSRNG uniformly as 0 <= xi_{i,l} < q
S3.2.2c [3/12] computes alpha_{i,l} = g^{xi_{i,l}} mod p
S3.2.2c [4/12] computes beta_{i,l} = K_l^{xi_{i,l}} mod p
S3.2.2c [5/12] computes the secret key k_{i,l} = H(H_P; 0x11, i, l, K_l, alpha_{i,l}, beta_{i,l})
S3.2.2c [6/12] computes MAC key k_0(32 bytes) = HMAC(k_{i,l}, 0x01 || "share_enc_keys" (14 bytes) || 0x00 || "share_encrypt" (13 bytes) || i (4 bytes) || l (4 bytes) || 0x0200)
S3.2.2c [7/12] computes encryption key k_1(32 bytes) = HMAC(k_{i,l}, 0x02 || "share_enc_keys" (14 bytes) || 0x00 || "share_encrypt" (13 bytes) || i (4 bytes) || l (4 bytes) || 0x0200)
S3.2.2c [8/12] encodes P_i(l) as a 32 byte array per Section 5.1.2
S3.2.2c [9/12] computes C_{i,l,0}(512 bytes) = g^xi_{i,l} mod p
S3.2.2c [10/12] computes C_{i,l,1}(32 bytes) = P_i xor k_1
S3.2.2c [11/12] computes C_{i,l,2}(32 bytes) = HMAC(k_0, C_{i,l,0}(512 bytes) || C_{i,l,1}).
S3.2.2c [12/12] the encryption of P_i(l) is formed by E_l(P_i(l)) = (C_{i,l,0}, C_{i,l,1}, C_{i,l,2})
\paragraph{Share decryption.}