Simple Client

This simple client is designed to showcase the API by demonstrating the correct sequence of function calls used in an elecition.

Warning

This example client does not do any sort of error handling in order to more clearly highlight the “happy path” of an election. Please do not use this code in a real system.

main.c

main.c
  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
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#include <io.h>
#endif

#include <electionguard/max_values.h>

#include "main_decryption.h"
#include "main_keyceremony.h"
#include "main_params.h"
#include "main_voting.h"

/** Create a new temporary file from a template. */
static FILE *fmkstemps(char const *template, const char *mode);

// Election Parameters
uint32_t const NUM_TRUSTEES = 5;
uint32_t const THRESHOLD = 4;
uint32_t const NUM_ENCRYPTERS = 3;
uint32_t const NUM_SELECTIONS = 3;

int main()
{
    // Seed the RNG that we use to generate arbitrary ballots. This
    // relies on the fact that the current implementation of the
    // cryptography does not rely on the built in RNG.
    srand(100);

    bool ok = true;

    // Outputs of the key ceremony
    struct trustee_state trustee_states[MAX_TRUSTEES];
    struct joint_public_key joint_key;

    // Key Ceremony
    if (ok)
        ok = key_ceremony(&joint_key, trustee_states);

    // Open the voting results file
    FILE *voting_results = NULL;

    if (ok)
    {
        voting_results = fmkstemps("voting_results-XXXXXX", "w+x");
        if (voting_results == NULL)
            ok = false;
    }

    // Voting
    if (ok)
        ok = voting(joint_key, voting_results);

    // Open the tally file
    FILE *tally = NULL;

    if (ok)
    {
        tally = fmkstemps("tally-XXXXXX", "wx");
        if (tally == NULL)
            ok = false;
    }

    // Decryption
    if (ok)
        ok = decryption(voting_results, tally, trustee_states);

    // Cleanup

    if (voting_results != NULL)
    {
        fclose(voting_results);
        voting_results = NULL;
    }

    if (tally != NULL)
    {
        fclose(tally);
        tally = NULL;
    }

    for (uint32_t i = 0; i < NUM_TRUSTEES; i++)
        if (trustee_states[i].bytes != NULL)
        {
            free((void *)trustee_states[i].bytes);
            trustee_states[i].bytes = NULL;
        }

    if (joint_key.bytes != NULL)
    {
        free((void *)joint_key.bytes);
        joint_key.bytes = NULL;
    }

    if (ok)
        return EXIT_SUCCESS;
    else
        return EXIT_FAILURE;
}

FILE *fmkstemps(char const *template, const char *mode)
{
    bool ok = true;

    FILE *result = NULL;

    // Duplicate the template. It needs to be mutable for mkstemps.
    char *template_mut = strdup(template);
    if (template_mut == NULL)
        ok = false;

    // Create and open the temporary file
    if (ok)
    {
        template_mut = mktemp(template_mut);
        if (template_mut == NULL)
            ok = false;
    }

    // Convert the file descripter to a FILE*
    if (ok)
    {
        result = fopen(template_mut, mode);
        if (result == NULL)
            ok = false;
    }

    // Free the duplicated template
    if (template_mut != NULL)
    {
        free(template_mut);
        template_mut = NULL;
    }

    return result;
}

main_keyceremony.c

main_keyceremony.c
  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
#include <stdlib.h>
#include <string.h>

#include "main_keyceremony.h"
#include "main_params.h"

// Initialize
static bool initialize_coordinator(void);
static bool initialize_trustees(void);

// Key Generation
static bool generate_keys(void);
static struct all_keys_received_message receive_keys(void);

// Share Generation
static bool generate_shares(struct all_keys_received_message all_keys_received);
static struct all_shares_received_message receive_shares(void);

// Verification
static bool
verify_shares(struct all_shares_received_message all_shares_received);
static struct joint_public_key publish_joint_key(void);

// Export trustees state
static bool export_trustee_states(struct trustee_state *trustee_states);

// Global state
static KeyCeremony_Coordinator coordinator;
static KeyCeremony_Trustee trustees[MAX_TRUSTEES];

bool key_ceremony(struct joint_public_key *joint_key,
                  struct trustee_state *trustee_states)
{
    bool ok = true;

    // Initialize

    if (ok)
        ok = initialize_coordinator();

    if (ok)
        ok = initialize_trustees();

    // Key Ceremony

    if (ok)
        ok = generate_keys();

    struct all_keys_received_message all_keys_received = {.bytes = NULL};

    if (ok)
    {
        all_keys_received = receive_keys();
        if (all_keys_received.bytes == NULL)
            ok = false;
    }

    // Share Generation

    if (ok)
        ok = generate_shares(all_keys_received);

    struct all_shares_received_message all_shares_received = {.bytes = NULL};

    if (ok)
    {
        all_shares_received = receive_shares();
        if (all_shares_received.bytes == NULL)
            ok = false;
    }

    // Verification

    if (ok)
        ok = verify_shares(all_shares_received);

    *joint_key = (struct joint_public_key){.bytes = NULL};

    if (ok)
    {
        *joint_key = publish_joint_key();
        if (joint_key->bytes == NULL)
            ok = false;
    }

    // Export trustee state

    if (ok)
        ok = export_trustee_states(trustee_states);

    // Cleanup

    if (all_shares_received.bytes != NULL)
    {
        free((void *)all_shares_received.bytes);
        all_shares_received.bytes = NULL;
    }

    if (all_keys_received.bytes != NULL)
    {
        free((void *)all_keys_received.bytes);
        all_keys_received.bytes = NULL;
    }

    for (uint32_t i = 0; i < NUM_TRUSTEES; i++)
    {
        if (trustees[i] != NULL)
            KeyCeremony_Trustee_free(trustees[i]);
    }

    if (coordinator != NULL)
        KeyCeremony_Coordinator_free(coordinator);

    return ok;
}

bool initialize_coordinator(void)
{
    bool ok = true;

    struct KeyCeremony_Coordinator_new_r result =
        KeyCeremony_Coordinator_new(NUM_TRUSTEES, THRESHOLD);

    if (result.status != KEYCEREMONY_COORDINATOR_SUCCESS)
        ok = false;
    else
        coordinator = result.coordinator;

    return ok;
}

bool initialize_trustees(void)
{
    bool ok = true;

    for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
    {
        struct KeyCeremony_Trustee_new_r result =
            KeyCeremony_Trustee_new(NUM_TRUSTEES, THRESHOLD, i);

        if (result.status != KEYCEREMONY_TRUSTEE_SUCCESS)
            ok = false;
        else
            trustees[i] = result.trustee;
    }

    return ok;
}

bool generate_keys(void)
{
    bool ok = true;

    for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
    {
        struct key_generated_message key_generated = {.bytes = NULL};

        {
            struct KeyCeremony_Trustee_generate_key_r result =
                KeyCeremony_Trustee_generate_key(trustees[i]);

            if (result.status != KEYCEREMONY_TRUSTEE_SUCCESS)
                ok = false;
            else
                key_generated = result.message;
        }

        if (ok)
        {
            enum KeyCeremony_Coordinator_status status =
                KeyCeremony_Coordinator_receive_key_generated(coordinator,
                                                              key_generated);
            if (status != KEYCEREMONY_COORDINATOR_SUCCESS)
                ok = false;
        }

        if (key_generated.bytes != NULL)
        {
            free((void *)key_generated.bytes);
            key_generated.bytes = NULL;
        }
    }

    return ok;
}

struct all_keys_received_message receive_keys(void)
{
    struct all_keys_received_message message = {.bytes = NULL};

    struct KeyCeremony_Coordinator_all_keys_received_r result =
        KeyCeremony_Coordinator_all_keys_received(coordinator);

    if (result.status == KEYCEREMONY_COORDINATOR_SUCCESS)
        message = result.message;

    return message;
}

bool generate_shares(struct all_keys_received_message all_keys_received)
{
    bool ok = true;

    for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
    {
        struct shares_generated_message shares_generated = {.bytes = NULL};

        {
            struct KeyCeremony_Trustee_generate_shares_r result =
                KeyCeremony_Trustee_generate_shares(trustees[i],
                                                    all_keys_received);

            if (result.status != KEYCEREMONY_TRUSTEE_SUCCESS)
                ok = false;
            else
            {
                shares_generated = result.message;
            }
        }

        if (ok)
        {
            enum KeyCeremony_Coordinator_status cstatus =
                KeyCeremony_Coordinator_receive_shares_generated(
                    coordinator, shares_generated);
            if (cstatus != KEYCEREMONY_COORDINATOR_SUCCESS)
                ok = false;
        }

        if (shares_generated.bytes != NULL)
        {
            free((void *)shares_generated.bytes);
            shares_generated.bytes = NULL;
        }
    }

    return ok;
}

struct all_shares_received_message receive_shares()
{
    struct all_shares_received_message message = {.bytes = NULL};

    struct KeyCeremony_Coordinator_all_shares_received_r result =
        KeyCeremony_Coordinator_all_shares_received(coordinator);

    if (result.status == KEYCEREMONY_COORDINATOR_SUCCESS)
        message = result.message;

    return message;
}

bool verify_shares(struct all_shares_received_message all_shares_received)
{
    bool ok = true;

    for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
    {
        struct shares_verified_message shares_verified;

        {
            struct KeyCeremony_Trustee_verify_shares_r result =
                KeyCeremony_Trustee_verify_shares(trustees[i],
                                                  all_shares_received);
            if (result.status != KEYCEREMONY_TRUSTEE_SUCCESS)
                ok = false;
            else
                shares_verified = result.message;
        }

        if (ok)
        {
            enum KeyCeremony_Coordinator_status status =
                KeyCeremony_Coordinator_receive_shares_verified(
                    coordinator, shares_verified);
            if (status != KEYCEREMONY_COORDINATOR_SUCCESS)
                ok = false;
        }

        if (shares_verified.bytes != NULL)
        {
            free((void *)shares_verified.bytes);
            shares_verified.bytes = NULL;
        }
    }

    return ok;
}

struct joint_public_key publish_joint_key(void)
{
    struct joint_public_key key = {.bytes = NULL};

    struct KeyCeremony_Coordinator_publish_joint_key_r cresult =
        KeyCeremony_Coordinator_publish_joint_key(coordinator);

    if (cresult.status == KEYCEREMONY_COORDINATOR_SUCCESS)
        key = cresult.key;

    return key;
}

static bool export_trustee_states(struct trustee_state *trustee_states)
{

    bool ok = true;

    for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
    {
        struct KeyCeremony_Trustee_export_state_r result =
            KeyCeremony_Trustee_export_state(trustees[i]);

        if (result.status != KEYCEREMONY_TRUSTEE_SUCCESS)
            ok = false;
        else
            trustee_states[i] = result.state;
    }

    return ok;
}

main_voting.c

main_voting.c
  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
#include <stdlib.h>

#include <electionguard/voting/tracker.h>

#include "main_params.h"
#include "main_voting.h"

static bool initialize_encrypters(struct joint_public_key joint_key);

static bool initialize_coordinator(void);

static bool simulate_random_votes(uint32_t encrypter_ix, uint64_t num_ballots);

static Voting_Encrypter *encrypters;
static Voting_Coordinator coordinator;

bool voting(struct joint_public_key joint_key, FILE *out)
{
    bool ok = true;

    if (ok)
    {
        encrypters = malloc(NUM_ENCRYPTERS * sizeof(Voting_Encrypter));
        if (encrypters == NULL)
            ok = false;
    }

    if (ok)
        ok = initialize_encrypters(joint_key);

    if (ok)
        ok = initialize_coordinator();

    if (ok)
    {
        for (uint32_t i = 0; i < NUM_ENCRYPTERS && ok; i++)
            ok = simulate_random_votes(i, 10);
    }

    if (ok)
    {
        enum Voting_Coordinator_status status =
            Voting_Coordinator_export_ballots(coordinator, out);
        if (status != VOTING_COORDINATOR_SUCCESS)
            ok = false;
    }

    if (coordinator != NULL)
    {
        Voting_Coordinator_free(coordinator);
        coordinator = NULL;
    }

    for (uint32_t i = 0; i < NUM_ENCRYPTERS; i++)
        if (encrypters != NULL && encrypters[i] != NULL)
        {
            Voting_Encrypter_free(encrypters[i]);
            encrypters[i] = NULL;
        }

    if (encrypters != NULL)
    {
        free(encrypters);
        encrypters = NULL;
    }

    return ok;
}

bool initialize_encrypters(struct joint_public_key joint_key)
{
    bool ok = true;

    uint8_t id_buf[1];
    struct uid uid = {
        .len = 1,
        .bytes = id_buf,
    };

    for (uint32_t i = 0; i < NUM_ENCRYPTERS && ok; i++)
    {
        id_buf[0] = i;
        struct Voting_Encrypter_new_r result =
            Voting_Encrypter_new(uid, joint_key, NUM_SELECTIONS);

        if (result.status != VOTING_ENCRYPTER_SUCCESS)
            ok = false;
        else
            encrypters[i] = result.encrypter;
    }

    return ok;
}

bool initialize_coordinator(void)
{
    bool ok = true;

    struct Voting_Coordinator_new_r result =
        Voting_Coordinator_new(NUM_SELECTIONS);

    if (result.status != VOTING_COORDINATOR_SUCCESS)
        ok = false;
    else
        coordinator = result.coordinator;

    return ok;
}

static bool random_bit() { return 1 & rand(); }

static void fill_random_ballot(bool *selections)
{
    for (uint32_t i = 0; i < NUM_SELECTIONS; i++)
        selections[i] = random_bit();
}

bool simulate_random_votes(uint32_t encrypter_ix, uint64_t num_ballots)
{
    bool ok = true;

    Voting_Encrypter const encrypter = encrypters[encrypter_ix];

    for (uint64_t i = 0; i < num_ballots && ok; i++)
    {
        bool selections[MAX_SELECTIONS];

        fill_random_ballot(selections);

        struct register_ballot_message message = {.bytes = NULL};
        struct ballot_tracker tracker = {.bytes = NULL};
        struct ballot_identifier identifier = {.bytes = NULL};

        // Encrypt the ballot
        if (ok)
        {
            struct Voting_Encrypter_encrypt_ballot_r result =
                Voting_Encrypter_encrypt_ballot(encrypter, selections);

            if (result.status != VOTING_ENCRYPTER_SUCCESS)
                ok = false;
            else
            {
                message = result.message;
                tracker = result.tracker;
                identifier = result.id;
            }
        }

        // Print the tracker
        if (ok)
        {
            char *tracker_string = display_ballot_tracker(tracker);
            int status = puts(tracker_string);
            free(tracker_string);
            if (status == EOF)
                ok = false;
        }

        // Register the ballot
        if (ok)
        {
            enum Voting_Coordinator_status status =
                Voting_Coordinator_register_ballot(coordinator, message);

            if (status != VOTING_COORDINATOR_SUCCESS)
                ok = false;
        }

        // Randomly cast or spoil the ballot
        if (ok)
        {
            enum Voting_Coordinator_status status;

            if (random_bit())
                status =
                    Voting_Coordinator_cast_ballot(coordinator, identifier);
            else
                status =
                    Voting_Coordinator_spoil_ballot(coordinator, identifier);

            if (status != VOTING_COORDINATOR_SUCCESS)
                ok = false;
        }

        if (message.bytes != NULL)
        {
            free((void *)message.bytes);
            message.bytes = NULL;
        }

        if (tracker.bytes != NULL)
        {
            free((void *)tracker.bytes);
            message.bytes = NULL;
        }

        if (identifier.bytes != NULL)
        {
            free((void *)identifier.bytes);
            identifier.bytes = NULL;
        }
    }

    return ok;
}

main_decryption.c

main_decryption.c
  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
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

#include <electionguard/decryption/coordinator.h>
#include <electionguard/decryption/trustee.h>

#include "main_decryption.h"
#include "main_params.h"

static bool initialize_coordinator(void);

static bool initialize_trustees(struct trustee_state *trustee_states);

static bool tally_voting_records(FILE *in);

static bool decrypt_tally_shares(void);

static bool decrypt_tally_decryption_fragments(
    bool *requests_present, struct decryption_fragments_request *requests);

static Decryption_Trustee trustees[MAX_TRUSTEES];
static Decryption_Coordinator coordinator;

bool decryption(FILE *in, FILE *out, struct trustee_state *trustee_states)
{
    bool ok = true;

    if (ok)
        ok = initialize_coordinator();

    if (ok)
        ok = initialize_trustees(trustee_states);

    if (ok)
        ok = tally_voting_records(in);

    if (ok)
        ok = decrypt_tally_shares();

    struct decryption_fragments_request requests[MAX_TRUSTEES];
    bool request_present[MAX_TRUSTEES];
    for (uint32_t i = 0; i < NUM_TRUSTEES; i++)
        requests[i] = (struct decryption_fragments_request){.bytes = NULL};

    if (ok)
    {
        struct Decryption_Coordinator_all_shares_received_r result =
            Decryption_Coordinator_all_shares_received(coordinator);

        if (result.status != DECRYPTION_COORDINATOR_SUCCESS)
            ok = false;
        else
            for (uint32_t i = 0; i < result.num_trustees; i++)
                requests[i] = result.requests[i],
                request_present[i] = result.request_present[i];
    }

    if (ok)
        ok = decrypt_tally_decryption_fragments(request_present, requests);

    if (ok)
    {
        enum Decryption_Coordinator_status status =
            Decryption_Coordinator_all_fragments_received(coordinator, out);

        if (status != DECRYPTION_COORDINATOR_SUCCESS)
            ok = false;
    }

    for (uint32_t i = 0; i < NUM_TRUSTEES; i++)
        if (requests[i].bytes != NULL)
        {
            free((void *)requests[i].bytes);
            requests[i].bytes = NULL;
        }

    for (uint32_t i = 0; i < NUM_TRUSTEES; i++)
        if (trustees[i] != NULL)
        {
            Decryption_Trustee_free(trustees[i]);
            trustees[i] = NULL;
        }

    if (coordinator != NULL)
    {
        Decryption_Coordinator_free(coordinator);
        coordinator = NULL;
    }

    return ok;
}

bool initialize_coordinator(void)
{
    bool ok = true;

    struct Decryption_Coordinator_new_r result =
        Decryption_Coordinator_new(NUM_TRUSTEES, THRESHOLD);

    if (result.status != DECRYPTION_COORDINATOR_SUCCESS)
        ok = false;
    else
        coordinator = result.coordinator;

    return ok;
}

bool initialize_trustees(struct trustee_state *trustee_states)
{
    bool ok = true;

    for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
    {
        struct Decryption_Trustee_new_r result = Decryption_Trustee_new(
            NUM_TRUSTEES, THRESHOLD, NUM_SELECTIONS, trustee_states[i]);

        if (result.status != DECRYPTION_TRUSTEE_SUCCESS)
            ok = false;
        else
            trustees[i] = result.decryptor;
    }

    return ok;
}

bool tally_voting_records(FILE *in)
{
    bool ok = true;

    for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
    {
        int seek_status = fseek(in, 0L, SEEK_SET);
        if (seek_status != 0)
            ok = false;

        if (ok)
        {
            enum Decryption_Trustee_status status =
                Decryption_Trustee_tally_voting_record(trustees[i], in);

            if (status != DECRYPTION_TRUSTEE_SUCCESS)
                ok = false;
        }
    }

    return ok;
}

bool decrypt_tally_shares(void)
{
    bool ok = true;

    for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
    {
        struct decryption_share share = {.bytes = NULL};

        {
            struct Decryption_Trustee_compute_share_r result =
                Decryption_Trustee_compute_share(trustees[i]);

            if (result.status != DECRYPTION_TRUSTEE_SUCCESS)
                ok = false;
            else
                share = result.share;
        }

        if (ok)
        {
            enum Decryption_Coordinator_status status =
                Decryption_Coordinator_receive_share(coordinator, share);
            if (status != DECRYPTION_COORDINATOR_SUCCESS)
                ok = false;
        }

        if (share.bytes != NULL)
        {
            free((void *)share.bytes);
            share.bytes = NULL;
        }
    }

    return ok;
}

bool decrypt_tally_decryption_fragments(
    bool *requests_present, struct decryption_fragments_request *requests)
{
    bool ok = true;

    for (uint32_t i = 0; i < NUM_TRUSTEES && ok; i++)
    {
        if (requests_present[i])
        {
            struct decryption_fragments decryption_fragments = {.bytes = NULL};

            {
                struct Decryption_Trustee_compute_fragments_r result =
                    Decryption_Trustee_compute_fragments(trustees[i],
                                                         requests[i]);

                if (result.status != DECRYPTION_TRUSTEE_SUCCESS)
                    ok = false;
                else
                    decryption_fragments = result.fragments;
            }

            if (ok)
            {
                enum Decryption_Coordinator_status status =
                    Decryption_Coordinator_receive_fragments(
                        coordinator, decryption_fragments);

                if (status != DECRYPTION_COORDINATOR_SUCCESS)
                    ok = false;
            }

            if (decryption_fragments.bytes != NULL)
            {
                free((void *)decryption_fragments.bytes);
                decryption_fragments.bytes = NULL;
            }
        }
    }

    return ok;
}