Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge in binary fields from libiop, make API consistent between fields, add tests, etc #44

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f6255ee
Add Field base class for all fields
alexander-zw Feb 12, 2020
6b7e6ff
Put prime fields in one directory
alexander-zw Mar 1, 2020
b59e318
Add binary fields to libff
alexander-zw Mar 2, 2020
fd2bbcc
Fix dependencies for binary fields from libiop and add gtest submodule
alexander-zw Jun 13, 2020
6be85d9
Update README with mac instructions
alexander-zw Apr 8, 2020
9480730
Move prime fields into prime/
alexander-zw Apr 8, 2020
d6eb5b4
Add common api for prime and binary fields individually
alexander-zw Apr 8, 2020
fe74988
Add functions to Fp_model to standardize API
alexander-zw Apr 8, 2020
8414787
Adjust API of Fp and Fp2
alexander-zw Apr 10, 2020
e77f9cf
Adjust API of Fp3 and Fp4
alexander-zw Apr 10, 2020
facf362
Adjust API of fp6_3over2, rename base_field_char() to field_char(), a…
alexander-zw Apr 10, 2020
50eea9c
Make small changes to field API and operator declaration
alexander-zw Apr 10, 2020
8df5acf
Adjust API of Fp6_3over2
alexander-zw Apr 11, 2020
775eb6c
Adjust API of fp12_2over3over2
alexander-zw Apr 11, 2020
9c755a0
Adjust API of binary fields
alexander-zw Apr 11, 2020
b884d75
Add extension_degree() to all fields and make field_char() constexpr
alexander-zw Apr 12, 2020
ce75792
Change all references of size_t to std::size_t
alexander-zw Apr 12, 2020
36c8cc1
Add size_in_bits() to all fields
alexander-zw Apr 12, 2020
7fceef5
Implement some functions in Fp and Fp2
alexander-zw Apr 14, 2020
ca6ceb4
Add test for all fields
alexander-zw Apr 14, 2020
e33a3ad
Change test_all_fields to use gtest
alexander-zw Apr 14, 2020
67d472a
Finish implementing Fp2 and add some API tests in test_all_fields
alexander-zw Apr 15, 2020
d2fc2f1
Add Frobenius_map() to all prime extension fields
alexander-zw Apr 19, 2020
f6f74eb
Add some more tests to all fields
alexander-zw Apr 19, 2020
3b39c93
Rename prime fields directory to prime_base and prime_extension
alexander-zw Apr 19, 2020
d232cb7
Separate alt_bn128 fields into separate file
alexander-zw Apr 21, 2020
885a1c5
Separate fields from init files for rest of the curves
alexander-zw Apr 23, 2020
1a61b14
Merge binary field tests into one file
alexander-zw Apr 24, 2020
bbd44e4
Change all fields test to only initialize fields from alt bn128, mnt4…
alexander-zw Apr 24, 2020
0fb8712
Add squared, inverse, sqrt, and ^ tests (sqrt doesn't pass)
alexander-zw Apr 25, 2020
032e97c
Add tests for mutating functions of fields
alexander-zw Apr 25, 2020
91a2f7e
Finish common api test for all fields
alexander-zw Apr 25, 2020
6e4b42d
Add API tests specific to prime base and extension fields
alexander-zw Apr 26, 2020
3fe1217
Finish implementing functions in prime base/extension fields except s…
alexander-zw Apr 26, 2020
4561a06
Finish implementing functions in binary fields except sqrt() and <<, >>
alexander-zw Apr 27, 2020
d35f33a
Write tests for all binary fields
alexander-zw Apr 29, 2020
4d3dc4e
Add <<, >> to binary fields
alexander-zw Apr 30, 2020
b68e2ab
Add tests for op counts
alexander-zw May 3, 2020
7ae4cf2
Implement op counts in prime extension fields
alexander-zw May 3, 2020
12bc13d
Add operation profiling for binary fields
alexander-zw May 6, 2020
c7c33fb
Change prime fields test to use gtest
alexander-zw May 7, 2020
e2048fd
Change groups test to use gtest
alexander-zw May 7, 2020
3a55a67
Change bilinearity test to use gtest
alexander-zw May 7, 2020
b820247
Put util files in one folder and extract sqrt algorithm into algorith…
alexander-zw May 18, 2020
546f169
Add sqrt for finite fields, including computation of s, t, quadratic …
alexander-zw May 20, 2020
a685e6f
Add test for bigint
alexander-zw May 20, 2020
cdda96b
Implement sqrt for binary fields, remove debug statement, fix test
alexander-zw May 20, 2020
f08f777
Implement initialization of Tonelli-Shanks constants
alexander-zw May 23, 2020
3c84106
Add hardcoded Tonelli-Shanks constants in curves
alexander-zw May 23, 2020
38833e8
Change default profiling option to no output and other small changes
alexander-zw May 25, 2020
3540bd5
Update comments and fix typo
alexander-zw Jun 13, 2020
76d9bcc
Update installation instructions
alexander-zw Jun 13, 2020
ae5b640
Merge branch 'master' of https://github.com/scipr-lab/libff into base…
alexander-zw Jun 13, 2020
e04f2db
Remove commented out code and update gtest commit
alexander-zw Jun 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/build/
/.idea/
/.idea/
.DS_Store
.vscode
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "depends/gtest"]
path = depends/gtest
url = https://github.com/google/googletest.git
[submodule "depends/ate-pairing"]
path = depends/ate-pairing
url = https://github.com/herumi/ate-pairing.git
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ endif()

if("${USE_ASM}")
add_definitions(-DUSE_ASM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpclmul -msse4.1") # used for binary fields
endif()

# Configure CCache if available
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The library has the following dependencies:
* [CMake](http://cmake.org/)
* [GMP](http://gmplib.org/)
* [libprocps](http://packages.ubuntu.com/trusty/libprocps-dev)
* [libsodium](https://libsodium.gitbook.io/doc/)

The library has been tested on Linux, but it is compatible with Windows and Mac OS X.

Expand All @@ -65,6 +66,9 @@ On Ubuntu 14.04 LTS:
sudo apt-get install build-essential git libboost-all-dev cmake libgmp3-dev libssl-dev libprocps3-dev pkg-config
```


On Mac OS X, all of the libraries from the previous section can be installed with brew, except for `libprocps`. You will need to turn that off for Mac OS X.

Fetch dependencies from their GitHub repos:

```
Expand All @@ -82,6 +86,11 @@ Optionally, you can specify the install location by providing the desired instal
```
cmake .. -DCMAKE_INSTALL_PREFIX=/install/path
```
On Mac OS X, you may also need to turn off `libprocps` and/or provide the path to openssl (your exact path may vary):
```
cmake -DWITH_PROCPS=OFF -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2s -DOPENSSL_LIBRARIES=/usr/local/Cellar/openssl/1.0.2s/lib ..
```
To enable asserts, use the `-DCMAKE_BUILD_TYPE=Debug` flag.

Then, to compile and install the library, run this within the build directory:
```
Expand All @@ -93,7 +102,7 @@ This will install `libff.a` into `/install/path/lib`; so your application should

## Testing

To execute the tests for this library, run:
To build and execute the tests for this library, run:
```
make check
```
Expand Down
4 changes: 4 additions & 0 deletions depends/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# gtest for binary fields
add_subdirectory(gtest EXCLUDE_FROM_ALL)


if(${CURVE} STREQUAL "BN128")
include_directories(ate-pairing/include)
include_directories(xbyak)
Expand Down
1 change: 1 addition & 0 deletions depends/gtest
Submodule gtest added at a325ad
109 changes: 103 additions & 6 deletions libff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if(${CURVE} STREQUAL "BN128")
FF_EXTRASRCS

${FF_EXTRASRCS}
algebra/curves/bn128/bn128_fields.cpp
algebra/curves/bn128/bn128_g1.cpp
algebra/curves/bn128/bn128_g2.cpp
algebra/curves/bn128/bn128_gt.cpp
Expand All @@ -24,27 +25,32 @@ add_library(
ff
STATIC

algebra/curves/alt_bn128/alt_bn128_fields.cpp
algebra/curves/alt_bn128/alt_bn128_g1.cpp
algebra/curves/alt_bn128/alt_bn128_g2.cpp
algebra/curves/alt_bn128/alt_bn128_init.cpp
algebra/curves/alt_bn128/alt_bn128_pairing.cpp
algebra/curves/alt_bn128/alt_bn128_pp.cpp
algebra/curves/edwards/edwards_fields.cpp
algebra/curves/edwards/edwards_g1.cpp
algebra/curves/edwards/edwards_g2.cpp
algebra/curves/edwards/edwards_init.cpp
algebra/curves/edwards/edwards_pairing.cpp
algebra/curves/edwards/edwards_pp.cpp
algebra/curves/mnt/mnt4/mnt4_fields.cpp
algebra/curves/mnt/mnt4/mnt4_g1.cpp
algebra/curves/mnt/mnt4/mnt4_g2.cpp
algebra/curves/mnt/mnt4/mnt4_init.cpp
algebra/curves/mnt/mnt4/mnt4_pairing.cpp
algebra/curves/mnt/mnt4/mnt4_pp.cpp
algebra/curves/mnt/mnt46_common.cpp
algebra/curves/mnt/mnt6/mnt6_fields.cpp
algebra/curves/mnt/mnt6/mnt6_g1.cpp
algebra/curves/mnt/mnt6/mnt6_g2.cpp
algebra/curves/mnt/mnt6/mnt6_init.cpp
algebra/curves/mnt/mnt6/mnt6_pairing.cpp
algebra/curves/mnt/mnt6/mnt6_pp.cpp

common/double.cpp
common/profiling.cpp
common/utils.cpp
Expand All @@ -63,6 +69,35 @@ target_include_directories(
PUBLIC ..
)

# sodium for binary fields
find_path(
SODIUM_INCLUDE_DIR
sodium.h
HINTS ${LIBSODIUM_INCLUDE_DIRS}
/usr/local/include /opt/local/include /opt/include
)
find_library(
SODIUM_LIBRARY
NAMES sodium
HINTS ${LIBSODIUM_LIBRARY_DIRS}
/usr/local/lib /opt/local/lib /opt/lib
)

target_include_directories(
ff
PUBLIC
${SODIUM_INCLUDE_DIR}
)
target_compile_options(
ff
PUBLIC
${LIBSODIUM_CFLAGS} ${LIBSODIUM_CFLAGS_OTHER}
)
target_link_libraries(
ff
${SODIUM_LIBRARY} ${LIBSODIUM_LDFLAGS_OTHER}
)

install(
DIRECTORY "" DESTINATION "include/libff"
FILES_MATCHING
Expand All @@ -78,6 +113,7 @@ install(

# Tests
if ("${IS_LIBFF_PARENT}")
# Tests for prime fields
add_executable(
algebra_bilinearity_test
EXCLUDE_FROM_ALL
Expand All @@ -88,6 +124,7 @@ if ("${IS_LIBFF_PARENT}")
algebra_bilinearity_test

ff
gtest_main
)

add_executable(
Expand All @@ -100,18 +137,46 @@ if ("${IS_LIBFF_PARENT}")
algebra_groups_test

ff
gtest_main
)

add_executable(
algebra_prime_fields_test
EXCLUDE_FROM_ALL

algebra/fields/tests/test_prime_fields.cpp
)
target_link_libraries(
algebra_prime_fields_test

ff
gtest_main
)

add_executable(
algebra_all_fields_test
EXCLUDE_FROM_ALL

algebra/fields/tests/test_all_fields.cpp
)
target_link_libraries(
algebra_all_fields_test

ff
gtest_main
)

add_executable(
algebra_fields_test
algebra_field_utils_test
EXCLUDE_FROM_ALL

algebra/fields/tests/test_fields.cpp
algebra/field_utils/tests/test_field_utils.cpp
)
target_link_libraries(
algebra_fields_test
algebra_field_utils_test

ff
gtest_main
)

include(CTest)
Expand All @@ -124,14 +189,46 @@ if ("${IS_LIBFF_PARENT}")
COMMAND algebra_groups_test
)
add_test(
NAME algebra_fields_test
COMMAND algebra_fields_test
NAME algebra_prime_fields_test
COMMAND algebra_prime_fields_test
)
add_test(
NAME algebra_all_fields_test
COMMAND algebra_all_fields_test
)
add_test(
NAME algebra_field_utils_test
COMMAND algebra_field_utils_test
)

add_dependencies(check algebra_bilinearity_test)
add_dependencies(check algebra_groups_test)
add_dependencies(check algebra_fields_test)
add_dependencies(check algebra_prime_fields_test)
add_dependencies(check algebra_all_fields_test)
add_dependencies(check algebra_field_utils_test)

# Tests for binary fields
add_executable(
algebra_binary_fields_test
EXCLUDE_FROM_ALL

algebra/fields/tests/test_binary_fields.cpp
)
target_link_libraries(
algebra_binary_fields_test

ff
gtest_main
)

add_test(
NAME algebra_binary_fields_test
COMMAND algebra_binary_fields_test
)

add_dependencies(check algebra_binary_fields_test)

# Profiling for prime fields
add_executable(
multiexp_profile
EXCLUDE_FROM_ALL
Expand Down
Loading