a portable and fast pairing-based cryptography library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
MITSUNARI Shigeo ebc006b7ab add Fr/G1/G2 isValid 8 years ago
bin add .emptydir for empty directory 8 years ago
include/mcl add Fr/G1/G2 isValid 8 years ago
java update java.md to change the order of the arguments of pairing 8 years ago
lib add .emptydir for empty directory 8 years ago
misc compare gmp and llvm of mulPre and sqrPre 8 years ago
obj add .emptydir for empty directory 8 years ago
sample split functions for bls_sig.cpp 8 years ago
src add Fr/G1/G2 isValid 8 years ago
test add Fr/G1/G2 isValid 8 years ago
.gitignore add .gitignore 8 years ago
COPYRIGHT from mie 10 years ago
Makefile add BLS signature sample 8 years ago
common.mk add asm files for macos 8 years ago
common.props change include dir of cybozulib_ext 9 years ago
debug.props change /MD to /MT 9 years ago
mcl.sln add bn_test vc proj 9 years ago
mk.bat add arguments of mk.bat 8 years ago
mklib.bat add how to use mklib.bat and mk.bat for win 8 years ago
readme.md change the order of arguments of G1 and G2 8 years ago
release.props change /MD to /MT 9 years ago

readme.md

mcl

A generic and fast pairing-based cryptography library.

Abstract

mcl is a library for pairing-based cryptography. The current version supports the optimal Ate pairing over BN curves.

Support architecture

  • x86-64 Windows + Visual Studio
  • x86, x86-64 Linux + gcc/clang
  • ARM Linux
  • ARM64 Linux
  • (maybe any platform to be supported by LLVM)

Installation Requirements

apt install libgmp-dev

Create a working directory (e.g., work) and clone the following repositories.

mkdir work
cd work
git clone git://github.com/herumi/mcl
git clone git://github.com/herumi/cybozulib
git clone git://github.com/herumi/xbyak ; for only x86/x64
git clone git://github.com/herumi/cybozulib_ext ; for only Windows
  • Cybozulib_ext is a prerequisite for running OpenSSL and GMP on VC (Visual C++).

Build and test on x86-64 Linux, macOS, ARM and ARM64 Linux

To make lib/libmcl.a and test it:

cod work/mcl
make test

To benchmark a pairing:

bin/bn_test.exe

To make sample programs:

make sample

Build for 32-bit Linux

Build openssl and gmp for 32-bit mode and install <lib32>

make ARCH=x86 CFLAGS_USER="-I <lib32>/include" LDFLAGS_USER="-L <lib32>/lib -Wl,-rpath,<lib32>/lib"

Build for 64-bit Windows

  1. make library
mklib.bat
  1. make exe binary of sample\pairing.cpp
mk sample\pairing.cpp

open mcl.sln and build or if you have msbuild.exe

msbuild /p:Configuration=Release

SELinux

mcl uses Xbyak JIT engine if it is available on x64 architecture, otherwise mcl uses a little slower functions generated by LLVM. The default mode enables SELinux security policy on CentOS, then JIT is disabled.

% sudo setenforce 1
% getenforce
Enforcing
% bin/bn_test.exe
JIT 0
pairing   1.496Mclk
finalExp 581.081Kclk

% sudo setenforce 0
% getenforce
Permissive
% bin/bn_test.exe
JIT 1
pairing   1.394Mclk
finalExp 546.259Kclk

How to initialize pairing library

Call mcl::bn256::bn256init before calling any operations.

#include <mcl/bn256.hpp>
mcl::bn::CurveParam cp = mcl::bn::CurveFp254BNb; // or mcl::bn::CurveSNARK1
mcl::bn256::bn256init(cp);
mcl::bn256::G1 P(...);
mcl::bn256::G2 Q(...);
mcl::bn256::Fp12 e;
mcl::bn256::BN::pairing(e, P, Q);
  1. (CurveFp254BNb) a BN curve over the 254-bit prime p = 36z^4 + 36z^3 + 24z^2 + 6z + 1 where z = -(2^62 + 2^55 + 1).
  2. (CurveSNARK1) a BN curve over a 254-bit prime p such that n := p + 1 - t has high 2-adicity.

See test/bn_test.cpp.

Benchmark

A benchmark of a BN curve CurveFp254BNb.

  • x64, x86 ; Inte Core i7-6700 3.4GHz(Skylake) upto 4GHz on Ubuntu 16.04.
    • sudo cpufreq-set -g performance
  • arm ; 900MHz quad-core ARM Cortex-A7 on Raspberry Pi2, Linux 4.4.11-v7+
  • arm64 ; 1.2GHz ARM Cortex-A53 HiKey
software x64 x86 arm arm64(msec)
ate-pairing 0.21 - - -
mcl 0.31 1.6 22.6 4.0
TEPLA 1.76 3.7 37 17.9
RELIC PRIME=254 1.31 3.5 36 -
MIRACL ake12bnx 4.2 - 78 -
NEONabe - - 16 -

How to make asm files (optional)

The asm files generated by this way are already put in src/asm, then it is not necessary to do this.

Install LLVM.

make MCL_USE_LLVM=1 LLVM_VER=<llvm-version> UPDATE_ASM=1

For example, specify -3.8 for <llvm-version> if opt-3.8 and llc-3.8 are installed.

If you want to use Fp with 1024-bit prime on x86-64, then

make MCL_USE_LLVM=1 LLVM_VER=<llvm-version> UPDATE_ASM=1 MCL_MAX_BIT_SIZE=1024

Java API

See java.md

License

modified new BSD License http://opensource.org/licenses/BSD-3-Clause

The original source of the followings are https://github.com/aistcrypt/Lifted-ElGamal . These files are licensed by BSD-3-Clause and are used for only tests.

include/mcl/elgamal.hpp
include/mcl/window_method.hpp
test/elgamal_test.cpp
test/window_method_test.cpp
sample/vote.cpp

This library contains mie and Lifted-ElGamal.

References

Author

光成滋生 MITSUNARI Shigeo(herumi@nifty.com)