Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit a2a707e

Browse files
pamtaroechumley-msft
authored andcommitted
Implement return of tally results as uint array
1 parent cf29bdd commit a2a707e

6 files changed

Lines changed: 34 additions & 11 deletions

File tree

examples/api/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,23 @@ int main()
159159
printf("\n--- Tally & Decrypt Votes ---\n");
160160

161161
char *tally_filename;
162+
uint32_t tally_results[config.num_selections];
162163
if (ok)
163164
{
164165
char *output_path = "../"; // This outputs to the directy above the cwd.
165166
char *output_prefix = "tally-";
166167
ok = API_TallyVotes(config, trustee_states, DECRYPTING_TRUSTEES,
167-
ballots_filename, output_path, output_prefix, &tally_filename);
168+
ballots_filename, output_path, output_prefix, &tally_filename, tally_results);
168169

169170
if (ok)
171+
{
172+
for (uint32_t i = 0; i < config.num_selections; i++)
173+
{
174+
printf("Tally %u results = %u\n", i, tally_results[i]);
175+
}
170176
printf("Tally from ballots input successful!\nCheck output file \"%s\"\n",
171177
tally_filename);
178+
}
172179
}
173180

174181
// Cleanup

examples/simple/main_decryption.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,18 @@ bool decryption(FILE *in, FILE *out, struct trustee_state *trustee_states)
6161

6262
if (ok)
6363
{
64+
uint32_t tally_results[NUM_SELECTIONS];
6465
enum Decryption_Coordinator_status status =
65-
Decryption_Coordinator_all_fragments_received(coordinator, out);
66+
Decryption_Coordinator_all_fragments_received(coordinator, out, tally_results);
6667

6768
if (status != DECRYPTION_COORDINATOR_SUCCESS)
6869
ok = false;
70+
71+
72+
for (uint32_t i = 0; i < NUM_SELECTIONS; i++)
73+
{
74+
printf("Tally %u results = %u\n", i, tally_results[i]);
75+
}
6976
}
7077

7178
for (uint32_t i = 0; i < NUM_TRUSTEES; i++)

include/electionguard/api/tally_votes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ bool API_TallyVotes(struct api_config config,
1313
char *ballots_filename,
1414
char *export_path,
1515
char *filename_prefix,
16-
char **output_filename);
16+
char **output_filename,
17+
uint32_t *tally_results_array);
1718

1819
/**
1920
* Free the bytes allocated by TallyVotes */

include/electionguard/decryption/coordinator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Decryption_Coordinator_receive_fragments(Decryption_Coordinator c,
9595
*/
9696
enum Decryption_Coordinator_status
9797
Decryption_Coordinator_all_fragments_received(Decryption_Coordinator c,
98-
FILE *out);
98+
FILE *out,
99+
uint32_t *tally_results_array);
99100

100101
#endif

src/electionguard/api/tally_votes.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ static bool tally_ballots(char *in_ballots_filename);
1515
static bool decrypt_tally_shares(uint32_t num_decrypting_trustees);
1616
static bool decrypt_tally_decryption_fragments(
1717
bool *requests_present, struct decryption_fragments_request *requests);
18-
static bool export_tally_votes(char *export_path, char *filename_prefix, char **output_filename);
18+
static bool export_tally_votes(char *export_path, char *filename_prefix,
19+
char **output_filename, uint32_t *tally_results_array);
1920

2021
// Global state
2122
static struct api_config api_config;
@@ -28,7 +29,8 @@ bool API_TallyVotes(struct api_config config,
2829
char *ballots_filename,
2930
char *export_path,
3031
char *filename_prefix,
31-
char **output_filename)
32+
char **output_filename,
33+
uint32_t *tally_results_array)
3234
{
3335
bool ok = true;
3436

@@ -77,7 +79,7 @@ bool API_TallyVotes(struct api_config config,
7779
ok = decrypt_tally_decryption_fragments(request_present, requests);
7880

7981
if (ok)
80-
ok = export_tally_votes(export_path, filename_prefix, output_filename);
82+
ok = export_tally_votes(export_path, filename_prefix, output_filename, tally_results_array);
8183

8284
// Cleanup
8385

@@ -254,7 +256,8 @@ bool decrypt_tally_decryption_fragments(
254256
return ok;
255257
}
256258

257-
bool export_tally_votes(char *export_path, char *filename_prefix, char **output_filename)
259+
bool export_tally_votes(char *export_path, char *filename_prefix,
260+
char **output_filename, uint32_t *tally_results_array)
258261
{
259262
bool ok = true;
260263
char *default_prefix = "electionguard_tally-";
@@ -269,7 +272,7 @@ bool export_tally_votes(char *export_path, char *filename_prefix, char **output_
269272
FILE *out = fopen(*output_filename, "w+");
270273

271274
enum Decryption_Coordinator_status status =
272-
Decryption_Coordinator_all_fragments_received(coordinator, out);
275+
Decryption_Coordinator_all_fragments_received(coordinator, out, tally_results_array);
273276

274277
if (status != DECRYPTION_COORDINATOR_SUCCESS)
275278
ok = false;

src/electionguard/decryption/coordinator.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ static bool Decryption_Coordinator_all_trustees_seen_or_compensated(
370370

371371
enum Decryption_Coordinator_status
372372
Decryption_Coordinator_all_fragments_received(Decryption_Coordinator c,
373-
FILE *out)
373+
FILE *out,
374+
uint32_t *tally_results_array)
374375
{
375376
enum Decryption_Coordinator_status status = DECRYPTION_COORDINATOR_SUCCESS;
376377

@@ -402,7 +403,10 @@ Decryption_Coordinator_all_fragments_received(Decryption_Coordinator c,
402403

403404
if (status == DECRYPTION_COORDINATOR_SUCCESS)
404405
{
405-
printf("Tally %lu \n", mpz_get_ui(decrypted_tally));
406+
tally_results_array[i] = mpz_get_ui(decrypted_tally);
407+
#ifdef DEBUG_PRINT
408+
printf("Tally %lu: %u \n", i, tally_results_array[i]);
409+
#endif
406410

407411
const char *preamble_format = "tally %" PRIu64 ": ";
408412
const int expected_len = snprintf(NULL, 0, preamble_format, i);

0 commit comments

Comments
 (0)