-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from NilFoundation/directly-include-zk
Directly include algebra, containers, hash, math and zk submodules
- Loading branch information
Showing
800 changed files
with
383,752 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule algebra
deleted from
f4a68e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#---------------------------------------------------------------------------# | ||
# Copyright (c) 2018-2021 Mikhail Komarov <[email protected]> | ||
# | ||
# Distributed under the Boost Software License, Version 1.0 | ||
# See accompanying file LICENSE_1_0.txt or copy at | ||
# http://www.boost.org/LICENSE_1_0.txt | ||
#---------------------------------------------------------------------------# | ||
|
||
cmake_minimum_required(VERSION 2.8.12) | ||
|
||
cmake_policy(SET CMP0028 NEW) | ||
cmake_policy(SET CMP0042 NEW) | ||
cmake_policy(SET CMP0048 NEW) | ||
cmake_policy(SET CMP0057 NEW) | ||
cmake_policy(SET CMP0076 NEW) | ||
|
||
list(APPEND CMAKE_MODULE_PATH | ||
"${CMAKE_CURRENT_LIST_DIR}/cmake" | ||
"${CMAKE_CURRENT_LIST_DIR}/cmake/packages" | ||
"${CMAKE_CURRENT_LIST_DIR}/cmake/modules/share/modules/cmake") | ||
|
||
include(CMConfig) | ||
include(CMSetupVersion) | ||
|
||
if(NOT CMAKE_WORKSPACE_NAME OR NOT ("${CMAKE_WORKSPACE_NAME}" STREQUAL "crypto3")) | ||
cm_workspace(crypto3) | ||
endif() | ||
|
||
cm_project(algebra WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES ASM C CXX) | ||
|
||
include(CMDeploy) | ||
|
||
option(BUILD_BENCH_TESTS "Build performance benchmark tests" FALSE) | ||
option(BUILD_EXAMPLES "Build examples" FALSE) | ||
|
||
# Blurprint components are using point {0, 0} as a point in infinity, while the stadard is {0, 1} | ||
# for most curves. We will use compatibility mode with blueprint as default. Setting this flag to | ||
# TRUE will change the value of inf point for all curves to the standard value. | ||
option(STANDARD_EC_INF_POINTS "Use standard zero points for Eliptic Curves" FALSE) | ||
|
||
if(STANDARD_EC_INF_POINTS) | ||
add_definitions(-DSTANDARD_EC_INF_POINTS_ENABLED) | ||
endif() | ||
|
||
cm_setup_version(VERSION 0.1.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}) | ||
|
||
add_library(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE) | ||
|
||
set_target_properties(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} PROPERTIES | ||
EXPORT_NAME ${CURRENT_PROJECT_NAME}) | ||
|
||
target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>) | ||
|
||
target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE | ||
${CMAKE_WORKSPACE_NAME}::multiprecision | ||
Boost::unit_test_framework) | ||
|
||
cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} | ||
INCLUDE include | ||
NAMESPACE ${CMAKE_WORKSPACE_NAME}::) | ||
|
||
include(CMTest) | ||
cm_add_test_subdirectory(test) | ||
|
||
if(BUILD_EXAMPLES) | ||
add_subdirectory(example) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# =nil; Foundation's Algebraic Constructions Module | ||
|
||
=nil; Foundation's Algebraic Constructions module. | ||
|
||
Contains: | ||
* Finite fields | ||
* Curves | ||
* Pairing | ||
* Constexpr BLAS. | ||
|
||
## Building | ||
|
||
This library uses Boost CMake build modules (https://github.com/BoostCMake/cmake_modules.git). | ||
To actually include this library in a project it is required to: | ||
|
||
1. Add [CMake Modules](https://github.com/BoostCMake/cmake_modules.git) as submodule to target project repository. | ||
2. Add all the internal dependencies using [CMake Modules](https://github.com/BoostCMake/cmake_modules.git) as submodules to target project repository. | ||
3. Initialize parent project with [CMake Modules](https://github.com/BoostCMake/cmake_modules.git) (Look at [crypto3](https://github.com/nilfoundation/crypto3.git) for the example) | ||
|
||
## Dependencies | ||
|
||
### Internal | ||
|
||
* [Multiprecision](https://github.com/nilfoundation/crypto3-multiprecision.git). | ||
|
||
### External | ||
* [Boost](https://boost.org) (>= 1.73) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "crypto3.algebra", | ||
"version": "0.1.0", | ||
"summary": "=nil; Foundation C++ Computer Algebra System Finite Fields and Elliptic Curves", | ||
"description": "Algebra system provides a set of Finite Fields, Elliptic Curves and Pairings evaluation algorithms implemented in way C++ standard library implies: concepts, algorithms, predictable behavior, latest standard features support and clean architecture without compromising security and performance.", | ||
"homepage": "http://crypto3.nil.foundation/projects/crypto3", | ||
"license": "Boost Software License", | ||
"authors": { | ||
"Mikhail Komarov": "[email protected]", | ||
"Nikita Kaskov": "[email protected]" | ||
}, | ||
"platforms": { | ||
"ios": "5.0", | ||
"osx": "10.7" | ||
}, | ||
"source": { | ||
"git": "https://github.com/nilfoundation/algebra.git", | ||
"branch": "master" | ||
}, | ||
"xcconfig": { | ||
"CLANG_CXX_LANGUAGE_STANDARD": "c++14", | ||
"CLANG_CXX_LIBRARY": "libc++", | ||
"HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/include/\"" | ||
}, | ||
"subspecs": [ | ||
{ | ||
"name": "include", | ||
"subspecs": [ | ||
{ | ||
"name": "nil", | ||
"subspecs": [ | ||
{ | ||
"name": "crypto3", | ||
"subspecs": [ | ||
{ | ||
"name": "detail", | ||
"source_files": [ | ||
"include/nil/crypto3/detail/*.{hpp}" | ||
] | ||
}, | ||
{ | ||
"name": "algebra", | ||
"source_files": [ | ||
"include/nil/crypto3/algebra/*.{hpp}" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Concepts # {#algebra_concepts} | ||
|
||
@tableofcontents | ||
|
||
## Algebra Concept ## {#algebra_concept} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# Implementation # {#algebra_impl} | ||
|
||
@tableofcontents | ||
|
||
The key idea of `algebra` is to provide usefull interfaces for basic cryptography math. It's based on NilFoundation fork of | ||
Boost.Multiprecision so that it can be used with boost cpp_int, gmp or other backends. | ||
|
||
We expanded Boost.Multiprecision with `modular_adaptor`, which is actually a multi-precision number by some modular. It contains | ||
modular number-specific algorithms using Montgomery representation. It also supports compile-time computations, because it gives | ||
us opportunity to implement algebra constructions as constexpr. | ||
|
||
For our purposes we needed the opportunity to use field and curve arithmetic in compile time, what became possible thanks to | ||
compile-time `modular_adaptor`. | ||
|
||
Algebra library consists of several modules listed below: | ||
|
||
1. Fields arithmetic | ||
2. Elliptic curves arithmetic | ||
3. Pairings on elliptic curves | ||
4. Multiexponentiation algorithm (will be part of some other module after a while) | ||
5. Matricies and vectors | ||
|
||
This separation defines the implementation architecture. | ||
|
||
|
||
|
||
## Fields Architecture ## {#fields_architecture} | ||
|
||
Fields were meant to be a wrapper over `multiprecision` module and concept of `modular_adaptor` number. So it basically consist | ||
of several parts listed below: | ||
|
||
1. Field Policies | ||
2. Field Extensions (e.g. Fp2, Fp4) | ||
3. Field Parameters | ||
4. Field Element Algorithms, which are actually wrappers over the `multiprecision` operations. | ||
|
||
@dot | ||
digraph fields_arch { | ||
bgcolor="#151515" | ||
rankdir="TB" | ||
node [shape="box"] | ||
|
||
a [label="Field Policies" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica" URL="@ref field_policies"]; | ||
b [label="Field Extensions" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica" URL="@ref field_extensions"]; | ||
c [label="Field Parameters" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica" URL="@ref field_parameters"]; | ||
d [label="Field Element Algorithms" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica" URL="@ref field_element_algorithms"]; | ||
|
||
a -> b; | ||
b -> c; | ||
c -> d; | ||
} | ||
@enddot | ||
|
||
### Field Policies ### {#field_policies} | ||
|
||
A field policy describes its essential parameters such as `modulus`, `arity` or `mul_generator` - multiply generator. | ||
|
||
### Field Extensions ### {#field_extensions} | ||
|
||
For the purposes of effictive field/elliptic curve operations and pairings evaluation fields are arranged as a field tower. | ||
|
||
For example, this is the tower used for `bn128` and `bls12_381` operations and pairings evaluation: | ||
|
||
Fp -> Fp2 -> Fp6 -> Fp12; | ||
|
||
@dot | ||
digraph fp12_2over3over2_arch { | ||
bgcolor="#151515" | ||
rankdir="TB" | ||
node [shape="box"] | ||
|
||
a [label="Fp12" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
b [label="Fp6" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
c [label="Fp2" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
d [label="Fp" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
|
||
a -> b; | ||
b -> c; | ||
c -> d; | ||
} | ||
@enddot | ||
|
||
There are also the following towers implemented: | ||
|
||
Fp -> Fp3 -> Fp6 -> Fp12; | ||
|
||
@dot | ||
digraph fp12_2over2over3_arch { | ||
bgcolor="#151515" | ||
rankdir="TB" | ||
node [shape="box"] | ||
|
||
a [label="Fp12" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
b [label="Fp6" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
c [label="Fp3" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
d [label="Fp"color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
|
||
a -> b; | ||
b -> c; | ||
c -> d; | ||
} | ||
@enddot | ||
|
||
Fp -> Fp2 -> Fp4 -> Fp12; | ||
|
||
@dot | ||
digraph fp12_3over2over2_arch { | ||
bgcolor="#151515" | ||
rankdir="TB" | ||
node [shape="box"] | ||
|
||
a [label="Fp12" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
b [label="Fp4" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
c [label="Fp2" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
d [label="Fp" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica"]; | ||
|
||
a -> b; | ||
b -> c; | ||
c -> d; | ||
} | ||
@enddot | ||
|
||
### Field Parameters ### {#field_parameters} | ||
|
||
Other field parameters are kept in the specific structures. All this structures inherit from basic `params` structure, containing all the | ||
basic parameters. | ||
|
||
For example, `extension_params` structure keeps all the parameters needed for field and field extensions arithmetical operation evaluations. | ||
|
||
### Field Element Algorithms ### {#field_element_algorithms} | ||
|
||
Field element corresponds an element of the field and has all the needed methods and overloaded arithmetic operators. The corresponding | ||
algorithms are also defined here. As the backend they use now Boost::multiprecision, but it can be easily changed. | ||
|
||
## Elliptic Curves Architecture ## {#curves_architecture} | ||
|
||
Curves were build upon the `fields`. So it basically consist of several parts listed below: | ||
|
||
1. Curve Policies | ||
2. Curve g1, g2 group element arithmetic | ||
3. Basic curve policies | ||
|
||
@dot | ||
digraph curves_arch { | ||
bgcolor="#151515" | ||
rankdir="TB" | ||
node [shape="box"] | ||
|
||
a [label="Curve Policies" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica" URL="@ref curve_policies"]; | ||
b [label="Curve Element Algorithms" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica" URL="@ref curve_element_algorithms"]; | ||
c [label="Basic curve policies" color="#f5f2f1" fontcolor="#f5f2f1" fontname="helvetica" URL="@ref basic_curve_policies"]; | ||
|
||
a -> b; | ||
b -> c; | ||
} | ||
@enddot | ||
|
||
### Curve Policies ### {#curve_policies} | ||
|
||
A curve policy describes its parameters such as base field modulus `p`, scalar field modulus `q`, group element types `g1_type` and `g2_type`. | ||
It also contains `pairing_policy` type, needed for comfortable usage of curve pairing. | ||
|
||
### Curve Element Algorithms ### {#curve_element_algorithms} | ||
|
||
Curve element corresponds an point of the curve and has all the needed methods and overloaded arithmetic operators. The corresponding algorithms | ||
are based on the underlying field algorithms are also defined here. | ||
|
||
### Basic Curve Policies ### {#basic_curve_policies} | ||
|
||
Main reason for existence of basic policyis is that we need some of it params using in group element and pairing arithmetic. | ||
So it contains such parameters that are needed by group element arithmetic e.g. coeffs `a` and `b` or generator coordinates `x`, `y`. | ||
It also contains all needed information about the underlying fields. | ||
|
||
## Pairing Architecture ## {#pairing_architecture} | ||
|
||
Pairing module consist of some internal functions and frontend interface templated by Elliptic Curve. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Algebra {#algebra_index} | ||
|
||
@subpage algebra_introduction | ||
|
||
@subpage algebra_manual | ||
|
||
@subpage algebra_concepts | ||
|
||
@subpage algebra_impl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Introduction # {#algebra_introduction} | ||
|
||
@tableofcontents | ||
|
||
Crypto3.Algebra library extends the =nil; Foundation's cryptography suite and provides a set algebraic constructions | ||
being used mostly for public-key schemes | ||
implemented in way C++ standard library implies: concepts, algorithms, predictable behavior, latest standard features support and clean architecture without compromising security and performance. | ||
|
||
Crypto3.Algebra consists of several parts to review: | ||
|
||
* [Manual](@ref algebra_manual). | ||
* [Implementation](@ref algebra_impl). | ||
* [Concepts](@ref algebra_concepts). | ||
|
||
## Dependencies ## {#algebra_dependencies} | ||
|
||
Internal dependencies: | ||
|
||
None | ||
|
||
Outer dependencies: | ||
1. [Boost (optional)](https://boost.org) (>= 1.58) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Manual # {#algebra_manual} | ||
|
||
@tableofcontents |
Oops, something went wrong.