Coder Social home page Coder Social logo

zeta1999 / secp256k1-x64 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from piggypiggy/secp256k1-x64

0.0 0.0 1.0 74 KB

very fast (NOT SECURE) implementation of arithmetic on curve secp256k1 on x86_64

License: Apache License 2.0

CMake 3.75% C 49.68% Raku 3.93% Perl 40.83% Python 1.81%

secp256k1-x64's Introduction

secp256k1-x64

Very efficient (NOT SECURE) implementation of arithmetic on curve secp256k1 on x86_64

This library aims to provide the most efficient implementation of secp256k1 curve arithmetic. To achieve this:

  • I borrow the idea from GmSSL's SM2 assembly code and make all code path work on secp256k1, inluding sse, avx and bmi2.

  • Remove many constant time code.

  • Implement a simple 256bit big number library in assembly to help boost speed(Although it doesn't help currently, I hope it would in the future :) ).

Implementation

  • No heap allocation.
  • Use 4ร—64bit to represent 256bit number.
  • Montmomery multiplication for secp256k1 modular p.
  • Efficient field inversion(257 sqr + 19 mul).
  • Precomputed table for generator, only 37 point addition is needed to do a point multiplication.
  • Replace gather function with memory copy, memory access is NOT uniform and NOT constant-time.
  • Some branch-less code become Not branch-less(e.g. conditional move in point_add).

Build

CMake is used to build this library, see BUILD_UNIX.txt and BUILD_WINDOWS.txt.

Security

As stated above, I sacrifice security for higher efficiency, so DO NOT use it in serious situation it's suitable for "daily" use.

Benchmark

Intel Core i7-6700 3.4GHz(Skylake), Ubuntu 18.04 LTS, gcc-7.5.0

arithmetic cycles / op op / s
montgomery square 43 78125000
montgomery mul 49 68649885
point add affine 557 6121199
point add 791 4305396
point double 424 8027829
scalar mul generator 21527 158310
scalar mul point 148610 22932
jacobian to affine 14621 233080
modular inverse 14785 230505

Note: scalar mul generator is about 6x faster than secp256k1's single-scalar multiplication with window size 15. When secp256k1 uses multi-scalar muliplication with batch size 32768, it can only reach the same speed as single-scalar multiplication of this library, i.e. scalar mul generator 158310 op/s.

Intel Core i3-2328M 2.2GHz(Sandy Bridge), Ubuntu 16.04 LTS, gcc-7.4.0

arithmetic cycles / op op / s
montgomery square 90 24232623
montgomery mul 93 23492560
point add affine 1269 1728007
point add 1670 1313370
point double 882 2487355
scalar mul generator 45214 48533
scalar mul point 304994 7195
jacobian to affine 27813 80730
modular inverse 26668 82291

License

Apache 2.0

secp256k1-x64's People

Contributors

piggypiggy avatar

Forkers

laplacekorea

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.