-
Notifications
You must be signed in to change notification settings - Fork 0
/
APISimulator.h
147 lines (118 loc) · 5.03 KB
/
APISimulator.h
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define _LARGE_TIME_API
#include <time.h>
#include "./dilithium/ref/api.h"
#include "param.h"
#include "commit.h"
#include "gaussian.h"
#include "fastrandombytes.h"
#include "assert.h"
#include "sha.h"
/*============================================================================*/
/* Constant definitions */
/*============================================================================*/
/* Maximum number of contests in an election */
#define CONTESTS 6
/* Maximum number of voter in an election */
#define VOTERS 600
/* Define TRUE and FALSE as integers */
#define TRUE 1
#define FALSE 0
/* Define Dilithium Parameters */
#define DILITHIUM_MODE 2
#define DILITHIUM_USE_AES
/*============================================================================*/
/* External variables definitions */
/*============================================================================*/
extern uint8_t pubSignKey[pqcrystals_dilithium2_PUBLICKEYBYTES];
extern uint8_t QRCodeTrackingCode[CONTESTS*(SHA512HashSize+sizeof(uint32_t))];
extern uint8_t QRCodeSign[pqcrystals_dilithium2_BYTES];
extern size_t tamSig;
extern uint8_t QRCodeSpoilTrackingCode[CONTESTS*SHA512HashSize];
extern uint8_t QRCodeSpoilNonce[CONTESTS*WIDTH*(DEGREE/4)]; // Degree*2/8
extern uint32_t QRCodeSpoilVotes[CONTESTS];
extern int sizeQRCodeSpoil[3];
/*============================================================================*/
/* Function prototypes */
/*============================================================================*/
/**
* Create commitment key for use in the simulator.
*/
void Setup();
/**
* Start the voting machine simulator for use
* @param[in] infoContest - 6 less significant bits: set if contest is held, clear otherwise.
*/
void onStart (uint8_t infoContest);
/**
* Cast vote for a contest
* @param[in] vote - Candidate number.
* @param[in] cont - Contest, represented as a 8 bit string, where a single bit is set.
*/
void onVoterActive(uint32_t vote, uint8_t cont);
/**
* Create final Tracking Code from all available contests.
* Tracking Code is output in QRCodeTrackingCode variable.
* @return number of bytes written in the Tracking Code.
*/
int createQRTrackingCode();
/**
* Benaloh Challenge: Deposit or challenge Tracking code.
* @param[in] cast -Deposit vote (TRUE) or challenge vote (FALSE).
* For challenge, output the required Challenge QR codes using variables:
* QRCodeSpoilTrackingCode
* QRCodeSpoilNonce
* QRCodeSpoilVotes
* The size of the QR codes for the spoil are output, respectively, in sizeQRCodeSpoil[3].
*/
void onChallenge (bool cast);
/**
* Close the voting machine and create results.
* Results are output in files voteOutput_contX for election public data for contest X.
* ZKPOutput_contX for ZKP data of contest X.
*/
void onFinish ();
/**
* Return the number of voters who deposited their votes.
* @return the total number of voters.
*/
int numberTotalvoters();
/**
* Verify function for the Benaloh Challenge.
* Print the result on screen.
* @param[in] QRTrack - Tracking Code provided before the challenge.
* @param[in] QRSpoilTrack - Tracking Code of the previous voter, provided by the challenge.
* @param[in] QRSpoilNon - Nonce used to create the commitment, provided by the challenge.
* @param[in] QRSpoilVot - Votes used to create the commitment, provided by the challenge.
*/
void verifyVote (uint8_t *QRTrack, uint8_t *QRSpoilTrack, uint8_t *QRSpoilNon, uint32_t *QRSpoilVot);
/**
* Validate the signature of the RDV file.
* Print the result on screen.
* @param[in] RDVOutputName - Name of the RDV file.
* @param[in] RDVSigOutputName - Name of the file that contains the signature for the RDV file.
* @param[in] numVoters - Number of voters.
*/
void validateRDV (char RDVOutputName[20], char RDVSigOutputName[20], int numVoters);
/**
* Validate the signature of the voteOutput file and the Tracking Code chain.
* Print the result on the screeen.
* @param[in] voteOutputName - Name of the voteOutput file.
* @param[in] voteSigOutputName - Name of the file that contains the signature for the voteOutput file.
* @param[in] numVoters - Number of voters.
*/
void validateVoteOutput (char voteOutputName[20], char voteSigOutputName[20], int numVoters);
/**
* Validate the signature of the ZKP file and the ZKPs.
* Print the result on the screen.
* @param[in] ZKPOutputName - Name of the ZKP file.
* @param[in] ZKPSigOutputName - Name of the file that contains the signature for the ZKP file.
* @param[in] RDVOutputName - Name of the RDV file.
* @param[in] voteOutputName - Name of the voteOutput file.
* @param numVoters - Number of voters.
*/
void validateZKPOutput (char ZKPOutputName[20], char ZKPSigOutputName[20],
char RDVOutputName[20], char voteOutputName[20],
int numVoters);