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

Commit 3115c41

Browse files
Remove assert statements from bignum (#78)
* Remove assert statements from bignum improve logging around bignum computation * remove assert.h update max ballot payload * reset max ballot payload to 2000 * Explicitly break loop on import end of file add log.h to coordinator * modify test selections
1 parent 7f59e71 commit 3115c41

File tree

14 files changed

+342
-142
lines changed

14 files changed

+342
-142
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
1414
IF(CMAKE_BUILD_TYPE MATCHES Debug)
1515
message("setting DEBUG during compile")
1616
add_compile_definitions(DEBUG)
17+
#add_compile_definitions(DEBUG_PRINT)
1718
ENDIF()
1819

1920

examples/api/main.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static bool result_equals_expected_selections(
4848
uint32_t const NUM_TRUSTEES = 3;
4949
uint32_t const THRESHOLD = 2;
5050
uint32_t const NUM_ENCRYPTERS = 3;
51-
uint32_t const NUM_SELECTIONS = 12; // the number of total contest selections for an election
51+
uint32_t const NUM_SELECTIONS = 3; // the number of total contest selections for an election
5252
uint32_t const DECRYPTING_TRUSTEES = 2; // must be >= THRESHOLD && <= NUM_TRUSTEES
5353
uint32_t const NUM_RANDOM_BALLOTS = 5; // the number of ballots to use when executing the test
5454

@@ -74,16 +74,20 @@ int main()
7474

7575
struct trustee_state trustee_states[MAX_TRUSTEES];
7676
ok = API_CreateElection(&config, trustee_states);
77+
if (!ok) printf("Create Election Failed!");
7778

7879
for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
7980
{
8081
if (trustee_states[i].bytes == NULL)
82+
{
83+
printf("trustee_state %d is NULL - FAIL!", i);
8184
ok = false;
85+
}
8286
}
8387

8488
// Encrypt Ballots
8589

86-
printf("\n--- Encrypt Ballots ---\n\n");
90+
if (ok) printf("\n--- Encrypt Ballots ---\n\n");
8791

8892
struct register_ballot_message memory_encrypted_ballots[NUM_RANDOM_BALLOTS];
8993
struct test_ballot testBallots[NUM_RANDOM_BALLOTS];
@@ -105,6 +109,7 @@ int main()
105109

106110
if (ok)
107111
{
112+
printf("Soft Deleting existing file\n");
108113
ok = API_EncryptBallot_soft_delete_file(encrypted_output_path, encrypted_output_prefix);
109114

110115
for (uint32_t i = 0; i < NUM_RANDOM_BALLOTS && ok; i++)
@@ -154,7 +159,7 @@ int main()
154159
// and pass it to the tally functions, but this is not strictly necessary
155160
// from an API Perspective.
156161

157-
printf("\n--- Load Ballots ---\n\n");
162+
if (ok) printf("\n--- Load Ballots ---\n\n");
158163

159164
// load the ballot ID's so we can cast/spoil them
160165
char *loaded_external_identifiers[NUM_RANDOM_BALLOTS];
@@ -166,7 +171,7 @@ int main()
166171
{
167172
ok = API_LoadBallots(
168173
0,
169-
NUM_RANDOM_BALLOTS,
174+
MAX_BALLOT_PAYLOAD,
170175
NUM_SELECTIONS,
171176
encrypted_ballots_filename,
172177
loaded_external_identifiers,
@@ -207,7 +212,7 @@ int main()
207212

208213
// Register & Record Cast/Spoil Multiple Ballots
209214

210-
printf("\n\n--- Randomly Assigning Ballots to be Cast or Spoil Arrays ---\n\n");
215+
if (ok) printf("\n\n--- Randomly Assigning Ballots to be Cast or Spoil Arrays ---\n\n");
211216

212217
uint32_t current_cast_index = 0;
213218
uint32_t current_spoiled_index = 0;
@@ -244,7 +249,7 @@ int main()
244249
ok = false;
245250
}
246251

247-
printf("\n--- Record Ballots (Register, Cast, and Spoil) ---\n\n");
252+
if (ok) printf("\n--- Record Ballots (Register, Cast, and Spoil) ---\n\n");
248253

249254
char *cast_and_spoiled_ballots_filename = NULL;
250255
char *casted_trackers[current_cast_index];
@@ -298,7 +303,7 @@ int main()
298303

299304
// Tally Votes & Decrypt Results
300305

301-
printf("\n--- Tally & Decrypt Votes ---\n\n");
306+
if (ok) printf("\n--- Tally & Decrypt Votes ---\n\n");
302307

303308
char *tally_filename = NULL;
304309
uint32_t tally_results[config.num_selections];
@@ -369,7 +374,15 @@ int main()
369374

370375
API_CreateElection_free(config.joint_key, trustee_states);
371376

372-
printf("\n--- Done! ---\n\n");
377+
if (ok)
378+
{
379+
printf("\n--- Done! ---\n\n");
380+
}
381+
else
382+
{
383+
printf("\n--- FAILED! ---\n\n");
384+
}
385+
373386

374387
if (ok)
375388
return EXIT_SUCCESS;

include/electionguard/keyceremony/trustee.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum KeyCeremony_Trustee_status
2121
KEYCEREMONY_TRUSTEE_INVALID_KEY_SHARE,
2222
KEYCEREMONY_TRUSTEE_SERIALIZE_ERROR,
2323
KEYCEREMONY_TRUSTEE_DESERIALIZE_ERROR,
24+
KEYCEREMONY_TRUSTEE_IO_ERROR
2425
};
2526

2627
/************************** INITIALIZATION & FREEING ***************************/

src/electionguard/api/create_election.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <string.h>
33

44
#include <electionguard/api/create_election.h>
5+
#include <log.h>
56

67
#include "api/base_hash.h"
78

@@ -33,32 +34,37 @@ static KeyCeremony_Trustee trustees[MAX_TRUSTEES];
3334
bool API_CreateElection(struct api_config *config,
3435
struct trustee_state *trustee_states)
3536
{
36-
#ifdef DEBUG_PRINT
37-
printf("API_CreateElection::Config:\n\tnum_trustees: %d\n\tthreshold: %d\n\tsubgroup_order: %d\n\telection_meta: %s\n",
38-
config->num_trustees, config->threshold, config->subgroup_order, config->election_meta);
39-
#endif
37+
DEBUG_PRINT(("API_CreateElection::Config:\n\tnum_trustees: %d\n\tthreshold: %d\n\tsubgroup_order: %d\n\telection_meta: %s\n",
38+
config->num_trustees, config->threshold, config->subgroup_order, config->election_meta));
4039

4140
bool ok = true;
4241

4342
// Set global variables
4443

4544
Crypto_parameters_new();
4645
api_config = *config;
46+
DEBUG_PRINT(("\nCreateElection: Create Base Hash\n"));
4747
create_base_hash_code(api_config);
4848

4949
// Initialize
5050

5151
if (ok)
5252
ok = initialize_coordinator();
5353

54+
if (!ok) DEBUG_PRINT(("\nCreateElection: initialize_coordinator - FAILED!\n"));
55+
5456
if (ok)
5557
ok = initialize_trustees();
5658

59+
if (!ok) DEBUG_PRINT(("\nCreateElection: initialize_trustees - FAILED!\n"));
60+
5761
// Key Ceremony
5862

5963
if (ok)
6064
ok = generate_keys();
6165

66+
if (!ok) DEBUG_PRINT(("\nCreateElection: generate_keys - FAILED!\n"));
67+
6268
struct all_keys_received_message all_keys_received = {.bytes = NULL};
6369

6470
if (ok)
@@ -68,11 +74,15 @@ bool API_CreateElection(struct api_config *config,
6874
ok = false;
6975
}
7076

77+
if (!ok) DEBUG_PRINT(("\nCreateElection: receive_keys - FAILED!\n"));
78+
7179
// Share Generation
7280

7381
if (ok)
7482
ok = generate_shares(all_keys_received);
7583

84+
if (!ok) DEBUG_PRINT(("\nCreateElection: generate_shares - FAILED!\n"));
85+
7686
struct all_shares_received_message all_shares_received = {.bytes = NULL};
7787

7888
if (ok)
@@ -82,11 +92,15 @@ bool API_CreateElection(struct api_config *config,
8292
ok = false;
8393
}
8494

95+
if (!ok) DEBUG_PRINT(("\nCreateElection: receive_shares - FAILED!\n"));
96+
8597
// Verification
8698

8799
if (ok)
88100
ok = verify_shares(all_shares_received);
89101

102+
if (!ok) DEBUG_PRINT(("\nCreateElection: verify_shares - FAILED!\n"));
103+
90104
// Publish joint key
91105

92106
if (ok)
@@ -96,11 +110,15 @@ bool API_CreateElection(struct api_config *config,
96110
ok = false;
97111
}
98112

113+
if (!ok) DEBUG_PRINT(("\nCreateElection: publish_joint_key - FAILED!\n"));
114+
99115
// Export trustee state
100116

101117
if (ok)
102118
ok = export_trustee_states(trustee_states);
103119

120+
if (!ok) DEBUG_PRINT(("\nCreateElection: export_trustee_states - FAILED!\n"));
121+
104122
// Cleanup
105123

106124
if (all_shares_received.bytes != NULL)
@@ -193,12 +211,13 @@ bool generate_keys(void)
193211
for (uint32_t i = 0; i < api_config.num_trustees && ok; i++)
194212
{
195213
struct key_generated_message key_generated = {.bytes = NULL};
196-
197214
struct KeyCeremony_Trustee_generate_key_r result =
198215
KeyCeremony_Trustee_generate_key(trustees[i], base_hash_code);
199216

200217
if (result.status != KEYCEREMONY_TRUSTEE_SUCCESS)
218+
{
201219
ok = false;
220+
}
202221
else
203222
key_generated = result.message;
204223

@@ -210,7 +229,9 @@ bool generate_keys(void)
210229
key_generated
211230
);
212231
if (status != KEYCEREMONY_COORDINATOR_SUCCESS)
213-
ok = false;
232+
{
233+
ok = false;
234+
}
214235
}
215236

216237
if (key_generated.bytes != NULL)

src/electionguard/api/load_ballots.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ API_LoadBallots_status load_ballots(uint64_t start_index,
143143
case VOTING_COORDINATOR_INSUFFICIENT_MEMORY:
144144
return API_LOADBALLOTS_INSUFFICIENT_MEMORY;
145145
// TODO: other cases
146+
case VOTING_COORDINATOR_END_OF_FILE:
146147
case VOTING_COORDINATOR_SUCCESS:
147148
default:
148149
return API_LOADBALLOTS_SUCCESS;

0 commit comments

Comments
 (0)