diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 983c5c4c4..000000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,18 +0,0 @@ -# Uncomment the rustflags for cross Nim-Rust LTO -# Use "CTT_LTO=1 cargo build" to force LTO on the Nim side -# -# Notes: -# -# On MacOS, for Intel targets, -# Apple Clang does not support the Intel assembly syntax. -# Unfortunately the combination Clang + AT&T syntax causes issues -# when LTO propagates constants into inline assembly. -# Upstream Clang/LLVM can be used instead. -# -# Note that Rust LLVM and Clang LLVM might be incompatible -# if the base LLVM versions differ. -# For example before LLVM 15 opaque pointers in IR triggered an error. - -# [build] -# # https://doc.rust-lang.org/rustc/linker-plugin-lto.html -# rustflags="-Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index eeab39bb6..000000000 --- a/.travis.yml +++ /dev/null @@ -1,137 +0,0 @@ -# Travis config for Constantine -language: c - -cache: - directories: - - nim-devel - - nim-stable - -matrix: - include: - # Travis pricing change https://blog.travis-ci.com/2020-11-02-travis-ci-new-billing - # Keep only ARM64 and PPC - - # Constantine only works with Nim devel - # Build and test using both gcc and clang - # Build and test on both x86-64 and ARM64 - # Ubuntu Bionic (18.04) is needed, it includes - # GCC 7 codegen fixes to addcarry_u64. - # Clang 9 (and GCC-6) are needed for inline assembly "flag output constraints" - - - dist: bionic - arch: arm64 - env: - - ARCH=arm64 - - CHANNEL=stable - compiler: gcc - - # - dist: bionic - # arch: ppc64le - # env: - # - ARCH=powerpc64el - # - CHANNEL=stable - # compiler: gcc - - # "Unknown processor s390x" - # - dist: bionic - # arch: s390x - # env: - # - ARCH=s390x - # - CHANNEL=devel - # compiler: gcc - - # - dist: bionic - # arch: amd64 - # env: - # - ARCH=amd64 - # - CHANNEL=devel - # compiler: gcc - # - # - dist: bionic - # arch: amd64 - # env: - # - ARCH=amd64 - # - CHANNEL=devel - # compiler: clang # Need Clang 9 for inline ASM test, but can't easily install it - # # addons: - # # apt: - # # sources: - # # - ubuntu-toolchain-r-test - # # - llvm-toolchain-bionic-9.0 # LLVM 9 repo is disallowed - # # packages: - # # - clang-9.0 - # # env: - # # - MATRIX_EVAL="CC=clang-9.0 && CXX=clang++-9.0" - # - # # On OSX we only test against clang (gcc is mapped to clang by default) - # - os: osx - # osx_image: xcode11.5 # Need xcode 11.4.2 min for Clang 9 - # arch: amd64 - # env: - # - ARCH=amd64 - # - CHANNEL=devel - # compiler: clang - fast_finish: true - -# Submodules are only for benchmarks, don't clone them -git: - submodules: false - -addons: - apt: - packages: - - libgmp-dev - homebrew: - packages: - - gmp - -before_install: - - | - if [ "${CHANNEL}" = stable ]; then - BRANCH="v$(curl https://nim-lang.org/channels/stable)" - else - BRANCH="${CHANNEL}" - fi - -install: - # Detect caching of Nim compiler - - | - if [ ! -x "nim-${CHANNEL}/bin/nim" ]; then - git clone -b "${BRANCH}" https://github.com/nim-lang/nim "nim-${CHANNEL}/" - pushd "nim-${CHANNEL}" - git clone --depth 1 https://github.com/nim-lang/csources csources/ - pushd csources - sh build.sh - popd - rm -rf csources - bin/nim c koch - ./koch boot -d:release - ./koch tools - else - pushd "nim-${CHANNEL}" - git fetch origin "${BRANCH}" - if [[ $(git merge FETCH_HEAD | grep -c "Already up to date.") -ne 1 ]]; then - bin/nim c koch - ./koch boot -d:release - ./koch tools - fi - fi - popd -before_script: - - export PATH="$PWD/nim-${CHANNEL}/bin${PATH:+:$PATH}" -script: - - nimble refresh - - nimble install -y gmp jsony - - # Installing Clang9.0 or later is a pain in Travis - # for inline assembly "flag output constraint" - # Also MacOS build is timing out with 2 series of tests. - - | - if [[ "$TRAVIS_COMPILER" == "clang" ]]; then - nimble test_parallel_no_assembler - else - nimble test_parallel - fi -branches: - except: - - gh-pages diff --git a/README.md b/README.md index 0ab891cd1..7d917b775 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,7 @@ [![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) ![Stability: experimental](https://img.shields.io/badge/stability-experimental-orange.svg)\ -[![Github Actions CI](https://github.com/mratsim/constantine/workflows/Constantine%20CI/badge.svg)](https://github.com/mratsim/constantine/actions?query=workflow%3A%22Constantine+CI%22+branch%3Amaster)\ -[![Build Status: Travis](https://img.shields.io/travis/com/mratsim/constantine/master?label=Travis%20%28Linux%20ARM64%2FPowerPC64%29)](https://travis-ci.com/mratsim/constantine)\ -[![Build Status: Azure](https://img.shields.io/azure-devops/build/numforge/07a2a7a5-995a-45d3-acd5-f5456fe7b04d/4?label=Azure%20%28Linux%2032%2F64-bit%2C%20Windows%2032%2F64-bit%2C%20MacOS%2064-bit%29)](https://dev.azure.com/numforge/Constantine/_build?definitionId=4&branchName=master) +[![Github Actions CI](https://github.com/mratsim/constantine/workflows/Constantine%20CI/badge.svg)](https://github.com/mratsim/constantine/actions?query=workflow%3A%22Constantine+CI%22+branch%3Amaster) > “A cryptographic system should be secure even if everything about the system, except the key, is public knowledge.”\ > — Auguste Kerckhoffs @@ -22,33 +20,32 @@ The implementations are accompanied with SAGE code used as reference implementat - [Constantine - Fast, compact, hardened Pairing-Based Cryptography](#constantine---fast-compact-hardened-pairing-based-cryptography) - - [Table of Contents](#table-of-contents) - - [Target audience](#target-audience) - - [Protocols](#protocols) - - [Installation](#installation) - - [From C](#from-c) - - [From Nim](#from-nim) - - [Dependencies & Requirements](#dependencies--requirements) - - [Curves supported in the backend](#curves-supported-in-the-backend) - - [Security](#security) - - [Disclaimer](#disclaimer) - - [Security disclosure](#security-disclosure) - - [Performance](#performance) - - [In blockchain](#in-blockchain) - - [In zero-knowledge proofs](#in-zero-knowledge-proofs) - - [Measuring performance](#measuring-performance) - - [Ethereum BLS signatures over BLS12-381 G2](#ethereum-bls-signatures-over-bls12-381-g2) - - [BLS12-381 detailed benchmarks](#bls12-381-detailed-benchmarks) - - [BN254-Snarks Multi-Scalar-Multiplication benchmarks](#bn254-snarks-multi-scalar-multiplication-benchmarks) - - [Parallelism](#parallelism) - - [Why Nim](#why-nim) - - [Compiler caveats](#compiler-caveats) - - [Inline assembly](#inline-assembly) - - [Sizes: code size, stack usage](#sizes-code-size-stack-usage) - - [License](#license) + - [Table of Contents](#table-of-contents) + - [Target audience](#target-audience) + - [Protocols](#protocols) + - [Installation](#installation) + - [From C](#from-c) + - [From Nim](#from-nim) + - [Dependencies & Requirements](#dependencies--requirements) + - [Curves supported in the backend](#curves-supported-in-the-backend) + - [Security](#security) + - [Disclaimer](#disclaimer) + - [Security disclosure](#security-disclosure) + - [Performance](#performance) + - [In blockchain](#in-blockchain) + - [In zero-knowledge proofs](#in-zero-knowledge-proofs) + - [Measuring performance](#measuring-performance) + - [Ethereum BLS signatures over BLS12-381 G2](#ethereum-bls-signatures-over-bls12-381-g2) + - [BLS12-381 detailed benchmarks](#bls12-381-detailed-benchmarks) + - [BN254-Snarks Multi-Scalar-Multiplication benchmarks](#bn254-snarks-multi-scalar-multiplication-benchmarks) + - [Parallelism](#parallelism) + - [Why Nim](#why-nim) + - [Compiler caveats](#compiler-caveats) + - [Inline assembly](#inline-assembly) + - [Sizes: code size, stack usage](#sizes-code-size-stack-usage) + - [License](#license) - ## Target audience The library aims to be a fast, compact and hardened library for elliptic curve cryptography needs, in particular for blockchain protocols and zero-knowledge proofs system. diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 081510356..000000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,293 +0,0 @@ -strategy: - maxParallel: 10 - matrix: - # TODO: Broken by OpenSSL not found for nimble - # https://github.com/nim-lang/Nim/blob/bf320ed172f74f60fd274338e82bdc9ce3520dd9/lib/wrappers/openssl.nim#L61 - # could not load: (libcrypto-1_1|libeay32).dll - # (bad format; library may be wrong architecture) - # Windows_devel_32bit: - # VM: 'windows-latest' - # UCPU: i686 - # CHANNEL: devel - # TEST_LANG: c - Windows_stable_noasm_64bit: - VM: 'windows-latest' - UCPU: amd64 - CHANNEL: stable - TEST_LANG: c - BACKEND: NO_ASM - Windows_cpp_stable_noasm_64bit: - VM: 'windows-latest' - UCPU: amd64 - CHANNEL: stable - TEST_LANG: cpp - BACKEND: NO_ASM - Linux_stable_noasm_64bit: - VM: 'ubuntu-18.04' - UCPU: amd64 - CHANNEL: stable - TEST_LANG: c - BACKEND: NO_ASM - Linux_cpp_stable_noasm_64bit: - VM: 'ubuntu-18.04' - UCPU: amd64 - CHANNEL: stable - TEST_LANG: cpp - BACKEND: NO_ASM - - # Deactivated for now, this is cross-compilation and tricky to get right - # Linux_devel_32bit: - # VM: 'ubuntu-16.04' - # UCPU: i686 - # CHANNEL: devel - # TEST_LANG: c - - MacOS_stable_noasm_64bit: - VM: 'macOS-10.15' - UCPU: amd64 - CHANNEL: stable - TEST_LANG: c - BACKEND: NO_ASM - - # ------------------------------- - - # No assembly for windows - # Windows_devel_64bit: - # VM: 'windows-latest' - # UCPU: amd64 - # CHANNEL: stable - # TEST_LANG: c - # BACKEND: ASM - # Windows_cpp_devel_64bit: - # VM: 'windows-latest' - # UCPU: amd64 - # CHANNEL: stable - # TEST_LANG: cpp - # BACKEND: ASM - Linux_stable_asm_64bit: - VM: 'ubuntu-18.04' - UCPU: amd64 - CHANNEL: stable - TEST_LANG: c - BACKEND: ASM - Linux_cpp_stable_asm_64bit: - VM: 'ubuntu-18.04' - UCPU: amd64 - CHANNEL: stable - TEST_LANG: cpp - BACKEND: ASM - MacOS_stable_asm_64bit: - VM: 'macOS-10.15' - UCPU: amd64 - CHANNEL: stable - TEST_LANG: c - BACKEND: ASM - -pool: - vmImage: $(VM) - -steps: - - task: CacheBeta@1 - displayName: 'cache Nim binaries' - inputs: - key: NimBinaries | $(Agent.OS) | $(CHANNEL) | $(UCPU) - path: NimBinaries - - - task: CacheBeta@1 - displayName: 'cache MinGW-w64' - inputs: - key: mingwCache | 8_1_0 | $(UCPU) - path: mingwCache - condition: eq(variables['Agent.OS'], 'Windows_NT') - - - powershell: | - Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 - displayName: 'long path support' - condition: eq(variables['Agent.OS'], 'Windows_NT') - - bash: | - echo "PATH=${PATH}" - set -e - echo "Installing MinGW-w64" - if [[ $UCPU == "i686" ]]; then - MINGW_FILE="i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z" - MINGW_URL="https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/8.1.0/threads-posix/dwarf/${MINGW_FILE}" - MINGW_DIR="mingw32" - else - MINGW_FILE="x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z" - MINGW_URL="https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/${MINGW_FILE}" - MINGW_DIR="mingw64" - fi - mkdir -p mingwCache - pushd mingwCache - if [[ ! -e "$MINGW_FILE" ]]; then - rm -f *.7z - curl -OLsS "$MINGW_URL" - fi - 7z x -y -bd "$MINGW_FILE" >/dev/null - mkdir -p /c/custom - mv "$MINGW_DIR" /c/custom/ - popd - - # Workaround https://developercommunity.visualstudio.com/content/problem/891929/windows-2019-cygheap-base-mismatch-detected-git-ba.html - echo "##vso[task.prependpath]/usr/bin" - echo "##vso[task.prependpath]/mingw64/bin" - echo "##vso[task.setvariable variable=MINGW_DIR;]$MINGW_DIR" - - displayName: 'Install dependencies (Windows)' - condition: eq(variables['Agent.OS'], 'Windows_NT') - - powershell: | - # export custom mingw PATH to other tasks - echo "##vso[task.prependpath]c:\custom\$(MINGW_DIR)\bin" - displayName: 'Mingw PATH (Windows)' - condition: eq(variables['Agent.OS'], 'Windows_NT') - - - bash: | - echo "PATH=${PATH}" - export ncpu= - case '$(Agent.OS)' in - 'Linux') - ncpu=$(nproc) - ;; - 'Darwin') - ncpu=$(sysctl -n hw.ncpu) - ;; - 'Windows_NT') - ncpu=$NUMBER_OF_PROCESSORS - ;; - esac - [[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1 - echo "Found ${ncpu} cores" - echo "##vso[task.setvariable variable=ncpu;]$ncpu" - displayName: 'Detecting number of cores' - - - bash: | - sudo dpkg --add-architecture i386 - - sudo apt-fast update -qq - # `:i386` (e.g. in `libffi-dev:i386`) is needed otherwise you may get: - # `could not load: libffi.so` during dynamic loading. - DEBIAN_FRONTEND='noninteractive' \ - sudo apt-fast install --no-install-recommends --allow-downgrades -yq \ - g++-multilib gcc-multilib libcurl4-openssl-dev:i386 libgc-dev:i386 \ - libffi-dev:i386 - - mkdir -p bin - - cat << EOF > bin/gcc - #!/bin/bash - exec $(which gcc) -m32 "\$@" - EOF - - cat << EOF > bin/g++ - #!/bin/bash - exec $(which g++) -m32 "\$@" - EOF - - chmod 755 bin/gcc - chmod 755 bin/g++ - - # Add to path - echo '##vso[task.prependpath]$(System.DefaultWorkingDirectory)/bin' - displayName: 'Install dependencies (i386 Linux)' - condition: and(eq(variables['Agent.OS'], 'Linux'), eq(variables['UCPU'], 'i686')) - - - bash: | - echo "PATH=${PATH}" - gcc -v - export ucpu=${UCPU} - - if [ "${CHANNEL}" = stable ]; then - BRANCH="v$(curl https://nim-lang.org/channels/stable)" - else - BRANCH="${CHANNEL}" - fi - mkdir -p NimBinaries - pushd NimBinaries - if [ ! -x "nim-${CHANNEL}/bin/nim" ]; then - git clone -b "${BRANCH}" https://github.com/nim-lang/nim "nim-${CHANNEL}/" - pushd "nim-${CHANNEL}" - git clone --depth 1 https://github.com/nim-lang/csources csources/ - pushd csources - - make -j $ncpu ucpu=${UCPU} CC=gcc - popd - rm -rf csources - bin/nim c koch - ./koch boot -d:release - ./koch tools - else - pushd "nim-${CHANNEL}" - git fetch origin "${BRANCH}" - if [[ $(git merge FETCH_HEAD | grep -c "Already up to date.") -ne 1 ]]; then - bin/nim c koch - ./koch boot -d:release - ./koch tools - fi - fi - popd # exit nim-${CHANNEL} - popd # exit NimBinaries - displayName: 'Building Nim' - - # https://forum.nim-lang.org/t/7494 - - powershell: | - bitsadmin.exe /rawreturn /transfer "cURL-certicates" /priority FOREGROUND https://curl.se/ca/cacert.pem $pwd\NimBinaries\nim-$(CHANNEL)\bin\cacert.pem - displayName: 'cURL certificates (Windows)' - condition: eq(variables['Agent.OS'], 'Windows_NT') - - - powershell: | - echo "##vso[task.prependpath]$pwd\NimBinaries\nim-$(CHANNEL)\bin" - displayName: 'Set env variable (Windows)' - condition: eq(variables['Agent.OS'], 'Windows_NT') - - bash: | - echo "##vso[task.prependpath]$PWD/NimBinaries/nim-${CHANNEL}/bin" - displayName: 'Set env variable (Posix)' - condition: ne(variables['Agent.OS'], 'Windows_NT') - - # GMP is preinstalled on Azure - # - bash: | - # echo "PATH=${PATH}" - # sudo apt-get install libgmp-dev - # displayName: 'Downloading GMP (Linux)' - # condition: eq(variables['Agent.OS'], 'Linux') - # - # - bash: | - # echo "PATH=${PATH}" - # brew install gmp - # displayName: 'Downloading GMP (MacOS)' - # condition: eq(variables['Agent.OS'], 'Darwin') - - - bash: | - echo "PATH=${PATH}" - sudo apt-get install libgmp-dev - displayName: 'Downloading GMP (Linux 32-bit)' - condition: and(eq(variables['Agent.OS'], 'Linux'), eq(variables['UCPU'], 'i686')) - - # Workaround #113 and https://github.com/status-im/nim-serialization/issues/33 - # and nimble flaky pinning / dependency resolution, - # json_serialization install would override nim-serialization pinning - - bash: | - echo "PATH=${PATH}" - nimble refresh - nimble install -y gmp jsony - displayName: 'Installing package and testing dependencies' - - - bash: | - echo "PATH=${PATH}" - export ucpu=${UCPU} - nimble test_parallel - displayName: 'Testing Constantine with Assembler and with GMP' - condition: and(ne(variables['Agent.OS'], 'Windows_NT'), eq(variables['BACKEND'], 'ASM')) - - - bash: | - echo "PATH=${PATH}" - export ucpu=${UCPU} - nimble test_parallel_no_assembler - displayName: 'Testing Constantine without Assembler and with GMP' - condition: and(ne(variables['Agent.OS'], 'Windows_NT'), eq(variables['BACKEND'], 'NO_ASM')) - - - bash: | - echo "PATH=${PATH}" - export ucpu=${UCPU} - nimble test_no_gmp - displayName: 'Testing the package (without GMP and ASM on Windows)' - condition: eq(variables['Agent.OS'], 'Windows_NT') diff --git a/bindings/lib_constantine.nim b/bindings/lib_constantine.nim index c9b9df6d6..341ed6302 100644 --- a/bindings/lib_constantine.nim +++ b/bindings/lib_constantine.nim @@ -15,7 +15,7 @@ {.push warning[UnusedImport]: off.} import - ./lib_threadpool, + ../constantine/threadpool, ./lib_hashes, ./lib_curves, # Protocols diff --git a/bindings/lib_threadpool.nim b/bindings/lib_threadpool.nim deleted file mode 100644 index bbbddf712..000000000 --- a/bindings/lib_threadpool.nim +++ /dev/null @@ -1,15 +0,0 @@ -# Constantine -# Copyright (c) 2018-2019 Status Research & Development GmbH -# Copyright (c) 2020-Present Mamy André-Ratsimbazafy -# Licensed and distributed under either of -# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). -# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0). -# at your option. This file may not be copied, modified, or distributed except according to those terms. - -# ############################################################ -# -# Constantine's threadpool -# -# ############################################################ - -import ../constantine/threadpool \ No newline at end of file diff --git a/bindings/lib_threadpool.nim.cfg b/bindings/lib_threadpool.nim.cfg deleted file mode 100644 index 9d57ecf93..000000000 --- a/bindings/lib_threadpool.nim.cfg +++ /dev/null @@ -1 +0,0 @@ ---threads:on \ No newline at end of file diff --git a/helpers/explain_bin_size.sh b/scripts/explain_bin_size.sh similarity index 100% rename from helpers/explain_bin_size.sh rename to scripts/explain_bin_size.sh