diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 38aebc2..0000000 --- a/.appveyor.yml +++ /dev/null @@ -1,86 +0,0 @@ -version: '{build}' - -cache: -- x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z -> .appveyor.yml -- i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z -> .appveyor.yml -- Nim -> .appveyor.yml - -matrix: - # We always want 32 and 64-bit compilation - fast_finish: false - -platform: - - x86 - - x64 - -install: - - setlocal EnableExtensions EnableDelayedExpansion - - - IF "%PLATFORM%" == "x86" ( - SET "MINGW_ARCHIVE=i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z" & - SET "MINGW_URL=https://sourceforge.net/projects/mingw-w64/files/Toolchains%%20targetting%%20Win32/Personal%%20Builds/mingw-builds/4.9.2/threads-win32/dwarf/i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z" & - SET "MINGW_DIR=mingw32" - ) ELSE ( - IF "%PLATFORM%" == "x64" ( - SET "MINGW_ARCHIVE=x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z" & - SET "MINGW_URL=https://sourceforge.net/projects/mingw-w64/files/Toolchains%%20targetting%%20Win64/Personal%%20Builds/mingw-builds/4.9.2/threads-win32/seh/x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z" & - SET "MINGW_DIR=mingw64" - ) else ( - echo "Unknown platform" - ) - ) - - - SET PATH=%CD%\%MINGW_DIR%\bin;%CD%\Nim\bin;%PATH% - - # Unpack mingw - - IF NOT EXIST "%MINGW_ARCHIVE%" appveyor DownloadFile "%MINGW_URL%" -FileName "%MINGW_ARCHIVE%" - - 7z x -y "%MINGW_ARCHIVE%" > nul - - # build nim from our own branch - this to avoid the day-to-day churn and - # regressions of the fast-paced Nim development while maintaining the - # flexibility to apply patches - - SET "NEED_REBUILD=" - - - IF NOT EXIST "Nim\\.git\\" ( - git clone https://github.com/status-im/Nim.git - ) ELSE ( - ( cd Nim ) & - ( git pull ) & - ( cd .. ) - ) - - # Rebuild Nim if HEAD has moved or if we don't yet have a cached version - - IF NOT EXIST "Nim\\ver.txt" ( - SET NEED_REBUILD=1 - ) ELSE ( - ( CD Nim ) & - ( git rev-parse HEAD > ..\\cur_ver.txt ) & - ( fc ver.txt ..\\cur_ver.txt || SET NEED_REBUILD=1 ) & - ( cd .. ) - ) - - - IF NOT EXIST "Nim\\bin\\nim.exe" SET NEED_REBUILD=1 - - IF NOT EXIST "Nim\\bin\\nimble.exe" SET NEED_REBUILD=1 - - # after building nim, wipe csources to save on cache space - - IF DEFINED NEED_REBUILD ( - cd Nim & - ( IF EXIST "csources" rmdir /s /q csources ) & - git clone --depth 1 https://github.com/nim-lang/csources & - cd csources & - ( IF "%PLATFORM%" == "x64" ( build64.bat ) else ( build.bat ) ) & - cd .. & - bin\nim c koch & - koch boot -d:release & - koch nimble & - git rev-parse HEAD > ver.txt & - rmdir /s /q csources - ) - -build_script: - - cd C:\projects\%APPVEYOR_PROJECT_SLUG% - - nimble install -y -test_script: - - nimble test - -deploy: off diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8e56f7e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -language: c # or other C/C++ variants - -sudo: false - -# https://docs.travis-ci.com/user/caching/ -# -# Caching the whole nim folder is better than relying on ccache - this way, we -# skip the expensive bootstrap process and linking -cache: - directories: - - nim - -os: - - linux - - osx - -install: - # build nim from our own branch - this to avoid the day-to-day churn and - # regressions of the fast-paced Nim development while maintaining the - # flexibility to apply patches - # - # check version of remote branch - - "export NIMVER=$(git ls-remote https://github.com/status-im/nim.git HEAD | cut -f 1)" - - # after building nim, wipe csources to save on cache space - - "{ [ -f nim/$NIMVER/bin/nim ] && [ -f nim/$NIMVER/bin/nimble ] ; } || - { rm -rf nim ; - mkdir -p nim ; - git clone --depth=1 https://github.com/status-im/nim.git nim/$NIMVER ; - cd nim/$NIMVER ; - sh build_all.sh ; - rm -rf csources ; - cd ../.. ; - }" - - "export PATH=$PWD/nim/$NIMVER/bin:$PATH" - -script: - - nimble install -y - - nimble test diff --git a/LICENSE-APACHEv2 b/LICENSE-APACHEv2 index 2e12d5c..ce5b065 100644 --- a/LICENSE-APACHEv2 +++ b/LICENSE-APACHEv2 @@ -1,5 +1,6 @@ constantine is licensed under the Apache License version 2 -Copyright (c) 2018 Status Research & Development GmbH +Copyright (c) 2018-2019 Status Research & Development GmbH +Copyright (c) 2020-Present Mamy André-Ratsimbazafy ----------------------------------------------------- Apache License diff --git a/LICENSE-MIT b/LICENSE-MIT index 042feea..595a268 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,10 +1,12 @@ constantine is licensed under the MIT License -Copyright (c) 2018 Status Research & Development GmbH +Copyright (c) 2018-2019 Status Research & Development GmbH +Copyright (c) 2020-Present Mamy André-Ratsimbazafy ----------------------------------------------------- The MIT License (MIT) -Copyright (c) 2018 Status Research & Development GmbH +Copyright (c) 2018-2019 Status Research & Development GmbH +Copyright (c) 2020-Present Mamy André-Ratsimbazafy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 27ba492..cd8104d 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,19 @@ -# Constantine - Constant time finitie field primitives for Elliptic Curve Cryptography +# Constantine - Constant time finite field primitives for Elliptic Curve Cryptography -[![Build Status (Travis)](https://img.shields.io/travis/status-im/nim-constantine/master.svg?label=Linux%20/%20macOS "Linux/macOS build status (Travis)")](https://travis-ci.org/status-im/nim-constantine) -[![Windows build status (Appveyor)](https://img.shields.io/appveyor/ci/nimbus/nim-constantine/master.svg?label=Windows "Windows build status (Appveyor)")](https://ci.appveyor.com/project/nimbus/nim-constantine) [![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) This library provides constant time finite field primitives for implementation of elliptic curve cryptography. -Warning ⚠️: The library is in development state. +Warning ⚠️: The library is in development state and cannot be used at the moment + except as a showcase or to start a discussion on modular big integers internals. ## Installation You can install the developement version of the library through nimble with the following command ``` -nimble install https://github.com/status-im/nim-constantine@#master +nimble install https://github.com/mratsim/constantine@#master ``` ## License diff --git a/constantine.nim b/constantine.nim index 83ef5ad..1ce2a27 100644 --- a/constantine.nim +++ b/constantine.nim @@ -1,5 +1,6 @@ # Constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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). diff --git a/constantine/bigints.nim b/constantine/bigints.nim index e64ca36..a844a3b 100644 --- a/constantine/bigints.nim +++ b/constantine/bigints.nim @@ -1,5 +1,6 @@ # Constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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). diff --git a/constantine/field_fp.nim b/constantine/field_fp.nim index d5d05cc..d41ae41 100644 --- a/constantine/field_fp.nim +++ b/constantine/field_fp.nim @@ -1,5 +1,6 @@ # Constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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). @@ -82,8 +83,8 @@ template shiftAddImpl(a: var Fp, c: Word) = var q: Word # (hi, lo) = a * 2^63 + c - let hi = a[0] shr 1 # 64 - 63 = 1 - let lo = a[0] shl WordBitSize or c # Assumes most-significant bit in c is not set + let hi = a[0] shr 1 # 64 - 63 = 1 + let lo = (a[0] shl WordBitSize) or c # Assumes most-significant bit in c is not set unsafeDiv2n1n(q, a[0], hi, lo, Fp.P.limbs[0]) # (hi, lo) mod P else: diff --git a/constantine/io.nim b/constantine/io.nim index d048b56..8e734d9 100644 --- a/constantine/io.nim +++ b/constantine/io.nim @@ -1,5 +1,6 @@ # Constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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). @@ -228,10 +229,10 @@ func hexToPaddedByteArray(hexStr: string, output: var openArray[byte], order: st let size = hexStr.len - skip doAssert size <= maxStrSize - + if size < maxStrSize: # include extra byte if odd length - dstIdx = output.len - (size + 1) div 2 + dstIdx = output.len - (size + 1) div 2 # start with shl of 4 if length is even shift = 4 - size mod 2 * 4 @@ -280,7 +281,7 @@ func fromHex*(T: type BigInt, s: string): T = # 2. Convert canonical uint to Big Int result = parseRawUint(bytes, T.bits, littleEndian) - + func dumpHex*(big: BigInt, order: static Endianness = bigEndian): string = ## Stringify an int to hex. ## Note. Leading zeros are not removed. @@ -305,4 +306,3 @@ func dumpHex*(big: BigInt, order: static Endianness = bigEndian): string = # 2 Convert canonical uint to hex result = bytes.toHex(order) - \ No newline at end of file diff --git a/constantine/montgomery.nim b/constantine/montgomery.nim index 27e13a2..2c2cc26 100644 --- a/constantine/montgomery.nim +++ b/constantine/montgomery.nim @@ -1,5 +1,6 @@ # Constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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). diff --git a/constantine/private/word_types_internal.nim b/constantine/private/word_types_internal.nim index dc132c8..a1c4219 100644 --- a/constantine/private/word_types_internal.nim +++ b/constantine/private/word_types_internal.nim @@ -1,5 +1,6 @@ # Constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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). diff --git a/constantine/word_types.nim b/constantine/word_types.nim index 46066c5..f05cab4 100644 --- a/constantine/word_types.nim +++ b/constantine/word_types.nim @@ -1,5 +1,6 @@ # Constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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). diff --git a/tests/all_tests.nim b/tests/all_tests.nim index fe7ee43..1097dff 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -1,5 +1,6 @@ -# constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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). diff --git a/tests/test_io.nim b/tests/test_io.nim index fa16bb1..8412da3 100644 --- a/tests/test_io.nim +++ b/tests/test_io.nim @@ -1,5 +1,6 @@ -# constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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). diff --git a/tests/test_word_types.nim b/tests/test_word_types.nim index 3395be8..d59ee60 100644 --- a/tests/test_word_types.nim +++ b/tests/test_word_types.nim @@ -1,5 +1,6 @@ -# constantine -# Copyright (c) 2018 Status Research & Development GmbH +# 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).