Skip to content

Commit 5af78a7

Browse files
committed
Initial release of libff
0 parents  commit 5af78a7

File tree

107 files changed

+19878
-0
lines changed

Some content is hidden

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

107 files changed

+19878
-0
lines changed

.gitmodules

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "third_party/gtest"]
2+
path = third_party/gtest
3+
url = https://github.com/google/googletest.git
4+
[submodule "third_party/ate-pairing"]
5+
path = third_party/ate-pairing
6+
url = https://github.com/herumi/ate-pairing.git
7+
[submodule "third_party/xbyak"]
8+
path = third_party/xbyak
9+
url = https://github.com/herumi/xbyak.git

AUTHORS

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SCIPR Lab:
2+
Eli Ben-Sasson
3+
Alessandro Chiesa
4+
Eran Tromer
5+
Madars Virza
6+
Howard Wu
7+
8+
External contributors:
9+
Alexander Chernyakhovsky (Google Inc.)

CMakeLists.txt

+231
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
project (libff)
4+
5+
set(
6+
CURVE
7+
"BN128"
8+
CACHE
9+
STRING
10+
"Default curve: one of ALT_BN128, BN128, EDWARDS, MNT4, MNT6"
11+
)
12+
13+
option(
14+
DEBUG
15+
"Enable debugging mode"
16+
OFF
17+
)
18+
option(
19+
LOWMEM
20+
"Limit the size of multi-exponentiation tables, for low-memory platforms"
21+
OFF
22+
)
23+
option(
24+
MULTICORE
25+
"Enable parallelized execution, using OpenMP"
26+
OFF
27+
)
28+
option(
29+
BINARY_OUTPUT
30+
"In serialization, output raw binary data (instead of decimal), which is smaller and faster."
31+
ON
32+
)
33+
option(
34+
MONTGOMERY_OUTPUT
35+
"Serialize Fp elements as their Montgomery representations (faster but not human-readable)"
36+
ON
37+
)
38+
option(
39+
USE_PT_COMPRESSION
40+
"Use point compression"
41+
ON
42+
)
43+
option(
44+
PROFILE_OP_COUNTS
45+
"Collect counts for field and curve operations"
46+
OFF
47+
)
48+
option(
49+
USE_MIXED_ADDITION
50+
"Convert each element of the key pair to affine coordinates"
51+
OFF
52+
)
53+
54+
option(
55+
WITH_PROCPS
56+
"Use procps for memory profiling"
57+
ON
58+
)
59+
60+
option(
61+
CPPDEBUG
62+
"Enable debugging of C++ STL (does not imply DEBUG)"
63+
OFF
64+
)
65+
66+
option(
67+
PERFORMANCE
68+
"Enable link-time and aggressive optimizations"
69+
OFF
70+
)
71+
72+
option(
73+
USE_ASM
74+
"Use architecture-specific optimized assembly code"
75+
ON
76+
)
77+
78+
set(
79+
OPT_FLAGS
80+
""
81+
CACHE
82+
STRING
83+
"Override C++ compiler optimization flags"
84+
)
85+
86+
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
87+
# Common compilation flags and warning configuration
88+
set(
89+
CMAKE_CXX_FLAGS
90+
"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wfatal-errors"
91+
)
92+
if("${MULTICORE}")
93+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
94+
endif()
95+
# Default optimizations flags (to override, use -DOPT_FLAGS=...)
96+
if("${OPT_FLAGS}" STREQUAL "")
97+
set(
98+
OPT_FLAGS
99+
"-ggdb3 -O2 -march=native -mtune=native"
100+
)
101+
endif()
102+
endif()
103+
104+
set(
105+
CMAKE_CXX_FLAGS
106+
"${CMAKE_CXX_FLAGS} ${OPT_FLAGS}"
107+
)
108+
109+
find_path(GMP_INCLUDE_DIR NAMES gmp.h)
110+
find_library(GMP_LIBRARIES NAMES gmp libgmp)
111+
find_library(GMPXX_LIBRARIES NAMES gmpxx libgmpxx)
112+
113+
include(FindPkgConfig)
114+
pkg_check_modules(
115+
CRYPTO
116+
REQUIRED
117+
118+
libcrypto
119+
)
120+
121+
if("${WITH_PROCPS}")
122+
pkg_check_modules(
123+
PROCPS
124+
REQUIRED
125+
126+
libprocps
127+
)
128+
else()
129+
add_definitions(
130+
-DNO_PROCPS
131+
)
132+
endif()
133+
134+
# Enable Boost for program_options
135+
FIND_PACKAGE( Boost 1.40 COMPONENTS program_options REQUIRED )
136+
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
137+
138+
add_definitions(
139+
-DCURVE_${CURVE}
140+
)
141+
142+
enable_testing()
143+
144+
include_directories(.)
145+
146+
if(${CURVE} STREQUAL "BN128")
147+
add_definitions(
148+
-DBN_SUPPORT_SNARK=1
149+
)
150+
endif()
151+
152+
if("${DEBUG}")
153+
add_definitions(-DDEBUG=1)
154+
endif()
155+
156+
if("${LOWMEM}")
157+
add_definitions(-DLOWMEM=1)
158+
endif()
159+
160+
if("${MULTICORE}")
161+
add_definitions(-DMULTICORE=1)
162+
endif()
163+
164+
if("${BINARY_OUTPUT}")
165+
add_definitions(-DBINARY_OUTPUT)
166+
endif()
167+
168+
if("${MONTGOMERY_OUTPUT}")
169+
add_definitions(-DMONTGOMERY_OUTPUT)
170+
endif()
171+
172+
if(NOT "${USE_PT_COMPRESSION}")
173+
add_definitions(-DNO_PT_COMPRESSION=1)
174+
endif()
175+
176+
if("${PROFILE_OP_COUNTS}")
177+
add_definitions(-DPROFILE_OP_COUNTS=1)
178+
endif()
179+
180+
if("${USE_MIXED_ADDITION}")
181+
add_definitions(-DUSE_MIXED_ADDITION=1)
182+
endif()
183+
184+
if("${CPPDEBUG}")
185+
add_definitions(-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC)
186+
endif()
187+
188+
if("${PERFORMANCE}")
189+
add_definitions(-DNDEBUG)
190+
set(
191+
CMAKE_CXX_FLAGS
192+
"${CMAKE_CXX_FLAGS} -flto -fuse-linker-plugin"
193+
)
194+
set(
195+
CMAKE_EXE_LINKER_FLAGS
196+
"${CMAKE_EXE_LINKER_FLAGS} -flto"
197+
)
198+
endif()
199+
200+
if("${USE_ASM}")
201+
add_definitions(-DUSE_ASM)
202+
endif()
203+
204+
find_program(
205+
MARKDOWN
206+
207+
markdown_py
208+
DOC "Path to markdown_py binary"
209+
)
210+
if(MARKDOWN-NOTFOUND)
211+
else()
212+
add_custom_target(
213+
doc
214+
${MARKDOWN} -f ${CMAKE_CURRENT_BINARY_DIR}/README.html -x toc -x extra --noisy ${CMAKE_CURRENT_SOURCE_DIR}/README.md
215+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
216+
COMMENT "Translating from markdown to HTML" VERBATIM
217+
)
218+
endif()
219+
220+
# Configure CCache if available
221+
find_program(CCACHE_FOUND ccache)
222+
if(CCACHE_FOUND)
223+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
224+
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
225+
endif(CCACHE_FOUND)
226+
227+
# Add a `make check` target that builds and tests
228+
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
229+
230+
add_subdirectory(third_party)
231+
add_subdirectory(src)

LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
The libff library is developed by SCIPR Lab (http://scipr-lab.org)
2+
and contributors.
3+
4+
Copyright (c) 2012-2014 SCIPR Lab and contributors (see AUTHORS file).
5+
6+
All files, with the exceptions below, are released under the MIT License:
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in
16+
all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
THE SOFTWARE.

README.md

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<h1 align="center">libff</h1>
2+
<h4 align="center">C++ library for Finite Fields and Elliptic Curves</h4>
3+
4+
___libff___ is a C++ library for finite fields and elliptic curves. The library is developed by [SCIPR Lab] and contributors (see [AUTHORS] file) and is released under the MIT License (see [LICENSE] file).
5+
6+
## Table of contents
7+
8+
- [Directory Structure](#directory-structure)
9+
- [Elliptic curve choices](#elliptic-curve-choices)
10+
- [Build guide](#build-guide)
11+
12+
## Directory structure
13+
14+
The directory structure is as follows:
15+
16+
* [__src__](src): C++ source code, containing the following modules:
17+
* [__algebra__](src/algebra): fields and elliptic curve groups
18+
* [__common__](src/common): miscellaneous utilities
19+
* [__third\_party__](third_party): third party libraries
20+
21+
## Elliptic curve choices
22+
23+
The libsnark library currently provides three options:
24+
25+
* "edwards":
26+
an instantiation based on an Edwards curve, providing 80 bits of security.
27+
28+
* "bn128":
29+
an instantiation based on a Barreto-Naehrig curve, providing 128
30+
bits of security. The underlying curve implementation is
31+
\[ate-pairing], which has incorporated our patch that changes the
32+
BN curve to one suitable for SNARK applications.
33+
34+
* This implementation uses dynamically-generated machine code for the curve
35+
arithmetic. Some modern systems disallow execution of code on the heap, and
36+
will thus block this implementation.
37+
38+
For example, on Fedora 20 at its default settings, you will get the error
39+
`zmInit ERR:can't protect` when running this code. To solve this,
40+
run `sudo setsebool -P allow_execheap 1` to allow execution,
41+
or use `make CURVE=ALT_BN128` instead.
42+
43+
* "alt_bn128":
44+
an alternative to "bn128", somewhat slower but avoids dynamic code generation.
45+
46+
Note that bn128 requires an x86-64 CPU while the other curve choices
47+
should be architecture-independent.
48+
49+
## Build guide
50+
51+
The library has the following dependencies:
52+
53+
* [Boost](http://www.boost.org/)
54+
* [CMake](http://cmake.org/)
55+
* [GMP](http://gmplib.org/)
56+
* libcrypto
57+
* [libprocps](http://packages.ubuntu.com/trusty/libprocps-dev)
58+
59+
The library has been tested on Linux, but it is compatible with Windows and Mac OS X.
60+
61+
### Installation
62+
63+
On Ubuntu 14.04 LTS:
64+
65+
```
66+
sudo apt-get install build-essential git libboost-all-dev cmake libgmp3-dev libssl-dev libprocps3-dev
67+
```
68+
69+
Fetch dependencies from their GitHub repos:
70+
71+
$ git submodule init && git submodule update
72+
73+
Create the Makefile:
74+
75+
$ mkdir build && cd build && cmake ..
76+
77+
Then, to compile the library, tests, and profiling harness, run this within the `build directory:
78+
79+
$ make
80+
81+
### Using libff as a library
82+
83+
To build and install the libff library:
84+
85+
$ DESTDIR=/install/path make install
86+
87+
This will install libff.a into /install/path/lib; so your application should be linked using -L/install/path/lib -lff. It also installs the requisite headers into /install/path/include; so your application should be compiled using -I/install/path/include.
88+
89+
[SCIPR Lab]: http://www.scipr-lab.org/ (Succinct Computational Integrity and Privacy Research Lab)
90+
91+
[LICENSE]: LICENSE (LICENSE file in top directory of libff distribution)
92+
93+
[AUTHORS]: AUTHORS (AUTHORS file in top directory of libff distribution)

0 commit comments

Comments
 (0)