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

Commit d9dd0a1

Browse files
AddressXceptionechumley-msft
authored andcommitted
Support external_ballot_identifer as a string (#71)
* Support external_ballot_identifer as a string. Export/import ballots from encrypter Add support for encrypter to export ballots to the file system. Import encrypter ballots into coordinator. Add a hashtable implementation that tracks ballot cast/spoil state against the external identifier (ballot_collection.c). Support loading ballots into a buffer. Fix memory leaks in bignum.c, crypto.c, decryption/coordinator.c, decryption/trustee.c, voting/coordinator.c, voting/encrypter.c, etc. Rework the API example to demonstrate the new external id and file system changes. Improve debug logging. Add more api documentation. Modify MAX_BALLOT_PAYLOAD to 2000. Explicitly add // TODO: to track remaining work. Note this commit is a work in progress and currently breaks the simple example. * Remove Simple Example, add api doc stubs Add stubs for the api documentation. Remove the simple example and use the api sample in the PR pipeline workflow * Fix Merge Issue * Verify malloc success * Address PR Feedback * Fix LGTM alerts * Add soft delete of encrypter files * Free CP Proof * Fix windows Makefile * test fix pr workflow on windows * use secure api's * explicitly compile release * flush file write before read * clean up makefile * Document consumers resonsible for free when calling an api that generates a filename as an out parameter, the caller is responsible for managing the memory of the out parameter when the call is successful * Rename static coordinators in API to differentiate local vars add an underscore prefix to static coordinator instance handles to differentiate vars until #62 is complete * add new enum cases to the end on voting coordinator * Add convenience logging * Handle error cases on file access use convenience logging * use consistent file formatting when rebuilding tracker string * optimize null check * explicitly set tracker array positions to NULL on failure * Reformat refactor Decryption_Coordinator_receive_share * guard tallies_initialized when freeing resources explicitly initialize num_tallies * rename _encrypted_ballot_count * don't return early * do not fail soft delete if rename fails * fix assignment * adjust number of ballots to force a rebuild
1 parent 6aa4464 commit d9dd0a1

72 files changed

Lines changed: 3595 additions & 1711 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr-workflow.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ jobs:
2222
cmake --version
2323
cmake -S . -B build
2424
cmake --build build
25-
- name: 'Build Simple Election'
25+
- name: 'Build API Sample Election'
2626
run: |
27-
ElectionGuard_DIR="$PWD/build/ElectionGuard" cmake -S examples/simple -B simple_build
28-
cmake --build simple_build --target simple
29-
- name: 'Test Simple Election'
27+
ElectionGuard_DIR="$PWD/build/ElectionGuard" cmake -S examples/api -B api_build
28+
cmake --build api_build --target api
29+
- name: 'Test API Sample Election'
3030
run: |
31-
cd simple_build
32-
./simple
31+
cd api_build
32+
./api
3333
windows_build:
3434
name: 'Windows Build'
3535
runs-on: 'windows-latest'
@@ -55,15 +55,15 @@ jobs:
5555
cmake --version
5656
cmake -S . -B build -G "MSYS Makefiles"
5757
cmake --build build
58-
- name: 'Build Simple Election'
58+
- name: 'Build API Sample Election'
5959
run: |
6060
$env:CMAKE_PREFIX_PATH="./build/ElectionGuard"
61-
cmake -S examples/simple -B simple_build -G "MSYS Makefiles"
62-
cmake --build simple_build --target simple
63-
- name: 'Test Simple Election'
61+
cmake -S examples/api -B api_build -G "MSYS Makefiles"
62+
cmake --build api_build --target api
63+
- name: 'Test API Sample Election'
6464
run: |
65-
cd simple_build
66-
$outcome = Invoke-Expression ".\simple.exe"
65+
$env:Path+=";.\build\"
66+
$outcome = Invoke-Expression ".\api_build\api.exe"
6767
echo $outcome
6868
macos_build:
6969
name: 'MacOS Build'
@@ -82,11 +82,11 @@ jobs:
8282
cmake --version
8383
cmake -S . -B build
8484
cmake --build build
85-
- name: 'Build Simple Election'
85+
- name: 'Build API Sample Election'
8686
run: |
87-
ElectionGuard_DIR="$PWD/build/ElectionGuard" cmake -S examples/simple -B simple_build
88-
cmake --build simple_build --target simple
89-
- name: 'Test Simple Election'
87+
ElectionGuard_DIR="$PWD/build/ElectionGuard" cmake -S examples/api -B api_build
88+
cmake --build api_build --target api
89+
- name: 'Test API Sample Election'
9090
run: |
91-
cd simple_build
92-
./simple
91+
cd api_build
92+
./api

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ _deps
3434
ElectionGuardConfig.cmake
3535
*_build/
3636
ballots/
37+
38+
ballots_encrypter/
39+
40+
tallies/

CMakeLists.txt

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ set(CMAKE_C_EXTENSIONS OFF)
1212
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
1313

1414
IF(CMAKE_BUILD_TYPE MATCHES Debug)
15-
message("setting DEBUG_PRINT")
16-
add_compile_definitions(DEBUG_PRINT)
15+
message("setting DEBUG during compile")
16+
add_compile_definitions(DEBUG)
1717
ENDIF()
1818

1919

@@ -22,11 +22,13 @@ add_library(electionguard
2222
${PROJECT_SOURCE_DIR}/src/electionguard/api/filename.c
2323
${PROJECT_SOURCE_DIR}/src/electionguard/api/create_election.c
2424
${PROJECT_SOURCE_DIR}/src/electionguard/api/encrypt_ballot.c
25+
${PROJECT_SOURCE_DIR}/src/electionguard/api/load_ballots.c
2526
${PROJECT_SOURCE_DIR}/src/electionguard/api/record_ballots.c
2627
${PROJECT_SOURCE_DIR}/src/electionguard/api/tally_votes.c
2728
${PROJECT_SOURCE_DIR}/src/electionguard/crypto_reps.h
29+
${PROJECT_SOURCE_DIR}/src/electionguard/voting/ballot_collection.c
2830
${PROJECT_SOURCE_DIR}/src/electionguard/voting/coordinator.c
29-
${PROJECT_SOURCE_DIR}/src/electionguard/voting/num_ballots.h
31+
${PROJECT_SOURCE_DIR}/src/electionguard/voting/messages.c
3032
${PROJECT_SOURCE_DIR}/src/electionguard/voting/message_reps.h
3133
${PROJECT_SOURCE_DIR}/src/electionguard/voting/nouns.c
3234
${PROJECT_SOURCE_DIR}/src/electionguard/voting/tracker.c
@@ -54,6 +56,7 @@ add_library(electionguard
5456
${PROJECT_SOURCE_DIR}/src/electionguard/keyceremony/trustee.c
5557
${PROJECT_SOURCE_DIR}/src/electionguard/uint4096.c
5658
${PROJECT_SOURCE_DIR}/src/electionguard/bignum.c
59+
${PROJECT_SOURCE_DIR}/src/electionguard/log.h
5760
${PROJECT_SOURCE_DIR}/src/electionguard/sha2-openbsd.c
5861
${PROJECT_SOURCE_DIR}/src/electionguard/sha2-openbsd.h
5962
${PROJECT_SOURCE_DIR}/src/electionguard/crypto.c
@@ -62,15 +65,15 @@ add_library(electionguard
6265
${PROJECT_SOURCE_DIR}/src/electionguard/random_source.h
6366
${PROJECT_SOURCE_DIR}/src/electionguard/random_source.c
6467
${PROJECT_SOURCE_DIR}/src/electionguard/trustee_state_rep.h
65-
${PROJECT_SOURCE_DIR}/src/electionguard/file.c
6668
${PROJECT_SOURCE_DIR}/src/electionguard/directory.c
6769
${PROJECT_SOURCE_DIR}/src/electionguard/directory.h
70+
${PROJECT_SOURCE_DIR}/src/electionguard/uthash.h
6871
${PROJECT_SOURCE_DIR}/include/electionguard/api/config.h
6972
${PROJECT_SOURCE_DIR}/include/electionguard/api/create_election.h
7073
${PROJECT_SOURCE_DIR}/include/electionguard/api/encrypt_ballot.h
74+
${PROJECT_SOURCE_DIR}/include/electionguard/api/load_ballots.h
7175
${PROJECT_SOURCE_DIR}/include/electionguard/api/record_ballots.h
7276
${PROJECT_SOURCE_DIR}/include/electionguard/api/tally_votes.h
73-
${PROJECT_SOURCE_DIR}/include/electionguard/file.h
7477
${PROJECT_SOURCE_DIR}/include/electionguard/max_values.h
7578
${PROJECT_SOURCE_DIR}/include/electionguard/trustee_state.h
7679
${PROJECT_SOURCE_DIR}/include/electionguard/voting/messages.h
@@ -109,8 +112,8 @@ if (MINGW)
109112
set_target_properties(electionguard PROPERTIES PREFIX "")
110113
endif()
111114

112-
# Set the public include directory depending on if the target is being exported
113-
# or installed
115+
# Set the public include directory depending on
116+
# if the target is being exported or installed
114117
target_include_directories(electionguard
115118
SYSTEM PUBLIC
116119
$<INSTALL_INTERFACE:include>
@@ -148,18 +151,9 @@ install(
148151

149152
add_subdirectory(docs)
150153

151-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/simple_build")
154+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/api_build")
152155
set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE)
153156

154-
add_test(NAME build_simple
155-
COMMAND "${CMAKE_COMMAND}"
156-
-E env ElectionGuard_DIR=${CMAKE_CURRENT_BINARY_DIR}/ElectionGuard
157-
"${CMAKE_CTEST_COMMAND}"
158-
--build-and-test "${PROJECT_SOURCE_DIR}/examples/simple" "${CMAKE_CURRENT_BINARY_DIR}/simple_build"
159-
--build-generator ${CMAKE_GENERATOR}
160-
--test-command simple
161-
)
162-
163157
add_test(NAME build_api
164158
COMMAND "${CMAKE_COMMAND}"
165159
-E env ElectionGuard_DIR=${CMAKE_CURRENT_BINARY_DIR}/ElectionGuard

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If new to the project,
1414
2. Install according to [ReadMe](./README.rst)
1515
OR
1616
refer to [Documentation](https://electionguard.github.io/ElectionGuard-SDK-C-Documentation/)
17-
3. Once you're up and running, be sure to run the simple election test
17+
3. Once you're up and running, be sure to run the API sample election test
1818

1919
⚠ Note: If you get stuck, take a look at our [GitHub Action](./.github/workflows/pr-workflow.yml)
2020

Makefile.mk

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.PHONY: add-dependencies build build-debug clean run-api test
2+
3+
BUILD_DEBUG?=true
4+
5+
.EXPORT_ALL_VARIABLES:
6+
ELECTIONGUARD_DIR="$(realpath .)/build/ElectionGuard"
7+
8+
# Detect operating system
9+
ifeq ($(OS),Windows_NT)
10+
OPERATING_SYSTEM := Windows
11+
else
12+
OPERATING_SYSTEM := $(shell uname 2>/dev/null || echo Unknown)
13+
endif
14+
15+
add-dependencies:
16+
ifeq ($(OPERATING_SYSTEM),Darwin)
17+
18+
endif
19+
ifeq ($(OPERATING_SYSTEM),Linux)
20+
21+
endif
22+
ifeq ($(OPERATING_SYSTEM),Windows)
23+
24+
endif
25+
26+
ifeq ($(BUILD_DEBUG),true)
27+
build: build-debug
28+
else
29+
build: build-release
30+
endif
31+
32+
build-debug: clean
33+
if [ ! -d "build" ]; then mkdir build; fi
34+
ifeq ($(OPERATING_SYSTEM),Windows)
35+
cmake -S . -B build -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug
36+
else
37+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
38+
endif
39+
cmake --build build
40+
41+
build-release: clean
42+
if [ ! -d "build" ]; then mkdir build; fi
43+
ifeq ($(OPERATING_SYSTEM),Windows)
44+
cmake -S . -B build -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
45+
else
46+
cmake -S . -B build -DBUILD_SHARED_LIBS=ON
47+
endif
48+
cmake --build build
49+
50+
clean:
51+
rm -rf ./build/* ./api_build/*
52+
53+
run-api: build
54+
if [ ! -d "api_build" ]; then mkdir api_build; fi
55+
ifeq ($(OPERATING_SYSTEM),Windows)
56+
CMAKE_PREFIX_PATH="./build/ElectionGuard" cmake -S examples/api -B api_build -G "MSYS Makefiles"
57+
cmake --build api_build --target api
58+
PATH=$(PWD)/build:$$PATH; ./api_build/api
59+
else
60+
ElectionGuard_DIR=$(ELECTIONGUARD_DIR) cmake -S examples/api -B api_build
61+
cmake --build api_build --target api
62+
./api_build/api
63+
endif
64+
65+
test: build
66+
cmake --build build --target test
67+

README-windows.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
cmake --build build
2424

2525
3. You should now have a `electionguard.a` or `electionguard.dll` (depending on the how cmake was configured).
26-
3. (Optional) Build the simple example election driver.
26+
3. (Optional) Build the api example election driver.
2727
1. Open a command prompt and navigate to the directory with the ElectionGuard-SDK-C-Implementation repo.
2828
2. Run the following commands:
2929

3030
set PATH=%PATH%;C:\path\to\ElectionGuard-SDK-C-Implementation\build\
3131
set CMAKE_PREFIX_PATH=C:\path\to\ElectionGuard-SDK-C-Implementation\build\ElectionGuard
32-
cmake -S examples/simple -B simple_build -G "MSYS Makefiles"
33-
cmake --build simple_build --target simple
32+
cmake -S examples/api -B api_build -G "MSYS Makefiles"
33+
cmake --build api_build --target api
3434

35-
3. You should now have a `simple.exe` that simulates some random voters and generates election record artifacts.
35+
3. You should now have a `api.exe` that simulates some random voters and generates election record artifacts.

README.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,17 @@ To build the SDK static library ``libelectionguard.a``, run
5353
5454
cmake --build build
5555
56+
Alternatively there is a `Makefile` to wrap the cmake commands:
57+
58+
.. code:: sh
59+
60+
make build
61+
5662
Testing
5763
--------
5864

59-
Currently you can exercise the SDK by running the :doc:`example client
60-
<examples/simple>`. We include a cmake test to do so automatically. You can
65+
Currently you can exercise the SDK by running the :doc:`api client
66+
<examples/api>`. We include a cmake test to do so automatically. You can
6167
also execute the client directly to better examine the output it produces.
6268

6369
.. warning::
@@ -95,11 +101,17 @@ to refer to the built library, and build the client.
95101

96102
.. code:: sh
97103
98-
mkdir simple_build
99-
ElectionGuard_DIR="$PWD/build/ElectionGuard" cmake -S examples/simple -B simple_build
100-
cmake --build simple_build --target simple
104+
mkdir api_build
105+
ElectionGuard_DIR="$PWD/build/ElectionGuard" cmake -S examples/api -B api_build
106+
cmake --build api_build --target api
107+
108+
The built binary should be located at :file:`api_build/api`.
109+
110+
alternatively, you can use the convenience Makefile
111+
112+
.. code:: sh
101113
102-
The built binary should be located at :file:`simple_build/simple`.
114+
make run-api
103115
104116
105117
Debugging

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ let
66
};
77
in with import nixpkgs {}; rec {
88
electionguard = callPackages ./derivation.nix { };
9-
simple = callPackages ./examples/simple { inherit electionguard; };
9+
api = callPackages ./examples/api { inherit electionguard; };
1010
}

docs/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ IF(BUILD_DOCUMENTATION)
4141
${CMAKE_CURRENT_SOURCE_DIR}/examples.rst
4242
${CMAKE_CURRENT_SOURCE_DIR}/voting.rst
4343
${CMAKE_CURRENT_SOURCE_DIR}/keyceremony.rst
44-
${CMAKE_CURRENT_SOURCE_DIR}/examples/simple.rst
44+
${CMAKE_CURRENT_SOURCE_DIR}/examples/api.rst
4545
${CMAKE_CURRENT_SOURCE_DIR}/api/index.rst
4646
${CMAKE_CURRENT_SOURCE_DIR}/api/crypto.rst
4747
${CMAKE_CURRENT_SOURCE_DIR}/api/trustee_state.rst
48+
${CMAKE_CURRENT_SOURCE_DIR}/api/api/config.rst
49+
${CMAKE_CURRENT_SOURCE_DIR}/api/api/create_election.rst
50+
${CMAKE_CURRENT_SOURCE_DIR}/api/api/encrypt_ballot.rst
51+
${CMAKE_CURRENT_SOURCE_DIR}/api/api/load_ballots.rst
52+
${CMAKE_CURRENT_SOURCE_DIR}/api/api/record_ballots.rst
53+
${CMAKE_CURRENT_SOURCE_DIR}/api/api/tally_votes.rst
4854
${CMAKE_CURRENT_SOURCE_DIR}/api/voting/coordinator.rst
4955
${CMAKE_CURRENT_SOURCE_DIR}/api/voting/encrypter.rst
5056
${CMAKE_CURRENT_SOURCE_DIR}/api/voting/messages.rst

docs/api/api/config.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Config
2+
======

0 commit comments

Comments
 (0)