blst
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    [![Build Status](https://travis-ci.org/supranational/blst.svg?branch=master)](https://travis-ci.org/supranational/blst) [![ubuntu-latest](https://github.com/supranational/blst/workflows/ubuntu-latest/badge.svg)](https://github.com/supranational/blst/actions) <div align="left"> <img src=blst_logo_small.png> </div> # blst blst (pronounced 'blast') is a BLS12-381 signature library focused on performance and security. It is written in C and assembly. ## Table of Contents - [blst](#blst) * [Table of Contents](#table-of-contents) * [Status](#status) * [Platform and Language Compatibility](#platform-and-language-compatibility) * [API](#api) * [Build](#build) + [C static library](#c-static-library) * [Bindings](#bindings) + [Go](#-go--bindings-go-) + [Rust](#-rust--bindings-rust-) + [Others](#others) * [Introductory Tutorial](#introductory-tutorial) + [Public Keys and Signatures](#public-keys-and-signatures) + [Signature Verification](#signature-verification) + [Signature Aggregation](#signature-aggregation) * [General notes on implementation](#general-notes-on-implementation) * [Repository Structure](#repository-structure) * [Performance](#performance) * [License](#license) ## Status **This library has not yet been audited. Use at your own risk.** Formal verification of this library is planned and will utilize [Cryptol](https://www.cryptol.net) and [Coq](https://coq.inria.fr/) to verify field, curve, and bulk signature operations. This library is compliant with the following IETF draft specifications: - [IETF BLS Signature V2](https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature) - [IETF Hash-to-Curve V9](https://tools.ietf.org/html/draft-irtf-cfrg-hash-to-curve) ## Platform and Language Compatibility This library supports x86_64 and ARM64 hardware platforms, and Linux, Mac, and Windows operating systems. This repository includes explicit bindings for: - [Go](bindings/go) - [Rust](bindings/rust) Unless deemed appropriate to implement, bindings for other languages will be provided using [SWIG](http://swig.org). Proof of concepts are available for: - [Python](bindings/python) - [Java](bindings/java) ## API The blst API is defined in the C header [bindings/blst.h](bindings/blst.h). The API can be categorized as follows, with some example operations: - Field Operations (add, sub, mul, neg, inv, to/from Montgomery) - Curve Operations (add, double, mul, to/from affine, group check) - Intermediate (hash to curve, pairing, serdes) - BLS12-381 signature (sign, verify, aggregate) Note: there is also an auxiliary header file, [bindings/blst_aux.h](bindings/blst_aux.h), that is used as a staging area for experimental interfaces that may or may not get promoted to blst.h. ## Build The build process is very simple and only requires a C complier. It's integrated into the Go and Rust ecosystems, so that respective users would go about as they would with any other external module. Otherwise, a binary library would have to be compiled. ### C static library A static library called libblst.a can be built in the current working directory of the user's choice: Linux, Mac, and Windows (in MinGW or Cygwin environments) ``` /some/where/build.sh ``` Windows (Visual C) ``` \some\where\build.bat ``` If final application crashes with an "illegal instruction" exception [after copying to another system], pass `‑D__BLST_PORTABLE__` on build.sh command line. If you don't use build.sh, complement the `CFLAGS` environment variable with the said command line option. If you compile a Go application, you will need to modify the `CGO_CFLAGS` variable instead. Alternatively, if you compile a Rust application on an older Intel system, but will execute it on a newer one, consider instead adding `‑D__ADX__` to `CFLAGS` for better performance. ## Bindings Bindings to other languages that implement minimal-signature-size and minimal-pubkey-size variants of the BLS signature specification are provided as follows: ### [Go](bindings/go) There are two primary modes of operation that can be chosen based on type definitions in the application. For minimal-pubkey-size operations: ``` type PublicKey = blst.P1Affine type Signature = blst.P2Affine type AggregateSignature = blst.P2Aggregate type AggregatePublicKey = blst.P1Aggregate ``` For minimal-signature-size operations: ``` type PublicKey = blst.P2Affine type Signature = blst.P1Affine type AggregateSignature = blst.P1Aggregate type AggregatePublicKey = blst.P2Aggregate ``` For more details see the Go binding [readme](bindings/go/README.md). ### [Rust](bindings/rust) [`blst`](https://crates.io/crates/blst) is the Rust binding crate. To use min-pk version: ``` use blst::min_pk::*; ``` To use min-sig version: ``` use blst::min_sig::*; ``` For more details see the Rust binding [readme](bindings/rust/README.md). ### Others blst can also be used with [SWIG](http://swig.org) to produce bindings for other languages such as Java and Python. Examples to build can be found in [Python](bindings/Python) and [Java](bindings/Java) directories ## Introductory Tutorial Programming is understanding, and understanding implies mastering the lingo. So we have a pair of additive groups being mapped to multiplicative one... What does it mean? Well, this tutorial is not about explaining that, but rather about making the connection between what you're supposed to know about [pairing-based cryptography](https://en.wikipedia.org/wiki/Pairing-based_cryptography) and the interface provided by the library. ### Public Keys and Signatures We have two elliptic curves, E1 and E2, points on which are contained in `blst_p1` and `blst_p2`, or `blst_p1_affine` and `blst_p2_affine` structures. Elements in the multiplicative group are held in a `blst_fp12` structure. One of the curves, or more specifically, a subset of points that form a cyclic group, is chosen for public keys, and another, for signatures. The choice is denoted by the subroutines' suffixes, `_pk_in_g1` or `_pk_in_g2`. The most common choice appears to be the former, that is, `blst_p1` for public keys, and `blst_p2` for signatures. But it all starts with a secret key... The secret key is held in a 256-bit `blst_scalar` structure which can be instantiated with either [`blst_keygen`](https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature#section-2.3), or deserialized with `blst_scalar_from_bendian` or `blst_scalar_from_lendian` from a previously serialized byte sequence. It shouldn't come as surprise that there are two uses for a secret key: - generating the associated public key, either with `blst_sk_to_pk_in_g1` or `blst_sk_to_pk_in_g2`; - performing a sign operation, either with `blst_sign_pk_in_g1` or `blst_sign_pk_in_g2`; As for signing, unlike what your intuition might suggest, `blst_sign_*` doesn't sign a message, but rather a point on the corresponding elliptic curve. You can obtain this point from a message by calling `blst_hash_to_g2` or `blst_encode_to_g2` (see the [IETF hash-to-curve](https://tools.ietf.org/html/draft-irtf-cfrg-hash-to-curve#section-3) draft for distinction). Another counter-intuitive aspect is the apparent g1 vs. g2 naming mismatch, in the sense that `blst_sign_pk_in_g1` accepts output from `blst_hash_to_g2`, and `blst_sign_pk_in_g2` accepts output from `blst_hash_to_g1`. This is because, as you should recall, public keys and signatures come from complementary groups. Now that you have a public key and signature, as points on corresponding elliptic curves, you can serialize them with `blst_p1_serialize`/`blst_p1_compress` and `blst_p2_serialize`/`blst_p2_compress` and send the resulting byte sequences over the network for deserialization/uncompression and verification. ### Signature Verification Even though there are "single-shot" `blst_core_verify_pk_in_g1` and `blst_core_verify_pk_in_g2`, you should really familiarize yourself with the more generalized pairing interface. `blst_pairing` is an opaque structure, and the only thing you know about it is `blst_pairing_sizeof`, which is how much memory you're supposed to allocate for it. In order to verify an aggregated signature for a set of public keys and messages, or just one[!], you would: ``` blst_pairing_init(ctx, hash_or_encode, domain_separation_tag); blst_pairing_aggregate_pk_in_g1(ctx, PK[0], aggregated_signature, message[0]); blst_pairing_aggregate_pk_in_g1(ctx, PK[1], NULL, message[1]); ... blst_pairing_commit(ctx); result = blst_pairing_finalverify(ctx, NULL); ``` **The essential point to note** is that it's the caller's responsibility to ensure that public keys are group-checked with `blst_p1_affine_in_g1`. This is because it's a relatively expensive operation and it's naturally assumed that the application would cache the check's outcome. Signatures are group-checked internally. Not shown in the pseudo-code snippet above, but `aggregate` and `commit` calls return `BLST_ERROR` denoting success or failure in performing the operation. Call to `finalverify`, on the other hand, returns boolean. Another, potentially more useful usage pattern is: ``` blst_p2_affine_in_g2(signature); blst_aggregated_in_g2(gtsig, signature); blst_pairing_init(ctx, hash_or_encode, domain_separation_tag); blst_pairing_aggregate_pk_in_g1(ctx, PK[0], NULL, message[0]); blst_pairing_aggregate_pk_in_g1(ctx, PK[1], NULL, message[1]); ... blst_pairing_commit(ctx); result = blst_pairing_finalverify(ctx, gtsig); ``` What is useful about it is that `aggregated_signature` can be handled in a separate thread. And while we are at it, aggregate calls can also be executed in different threads. This naturally implies that each thread will operate on its own `blst_pairing` context, which will have to be combined with `blst_pairing_merge` as threads join. ### Signature Aggregation Aggregation is a trivial operation of performing point additions, with `blst_p2_add_or_double_affine` or `blst_p1_add_or_double_affine`. Note that the accumulator is a non-affine point. --- That's about what you need to know to get started with nitty-gritty of actual function declarations. ## General notes on implementation The goal of the blst library is to provide a foundational component for applications and other libraries that require high performance and formally verified BLS12-381 operations. With that in mind some decisions are made to maximize the public good beyond BLS12-381. For example, the field operations are optimized for general 384-bit usage, as opposed to tuned specifically for the 381-bit BLS12-381 curve parameters. With the formal verification of these foundational components, we believe they can provide a reliable building block for other curves that would like high performance and an extra element of security. The library deliberately abstains from dealing with memory management and multi-threading, with the rationale that these ultimately belong in language-specific bindings. Another responsibility that is left to application is random number generation. All this in the name of run-time neutrality, which makes integration into more stringent environments like Intel SGX or ARM TrustZone trivial. The assembly code is wrapped into Perl scripts which output an assembly file based on the [ABI](https://en.wikipedia.org/wiki/Application_binary_interface) and operating system. In the `build` directory there are pre-built assembly files for elf, mingw64, masm, and macosx. See [build.sh](build.sh) or [refresh.sh](build/refresh.sh) for usage. This method allows for simple reuse of optimized assembly across various platforms with minimal effort. The serialization formatting is implemented according to [Appendix A. BLS12-381](https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-02#appendix-A) of the IETF spec that calls for using the [ZCash definition](https://github.com/zkcrypto/pairing/blob/master/src/bls12_381/README.md#serialization). ## Repository Structure **Root** - Contains various configuration files, documentation, licensing, and a build script * **Bindings** - Contains the files that define the blst interface * Blst_aux.h - contains experimental functions not yet committed for long-term maintenance * Blst.swg - provides definition file for creating blst bindings in Java and Python using SWIG * Blst.h - provides C API to blst library * blst.hpp - provides prototype C++ API to blst library * **Go** - folder containing Go bindings for blst, including tests and benchmarks?= * **Hash_to_curve**: folder containing test for hash_to_curve from IETF specification * **Java** - folder containing an example of how to use SWIG Java bindings for blst * **Python** - folder containing an example of how to use SWIG Python bindings for blst * **Rust** - folder containing Rust bindings for blst, including tests and benchmarks * **Src** - folder containing C code for lower level blst functions such as field operations, extension field operations, hash-to-field, and more * **Asm** - folder containing perl scripts that are used to generate assembly code for different hardware platforms including x86 with ADX instructions, x86 without ADX instructions, and ARMv8 * **Build** - this folder containing a set of pre-generated source files for a variety of operating systems. The purpose of this folder is for users who do not want to go through the build process. * **Coff** - executable code for use on Unix systems * **Elf** - executable code for use on Unix systems * **Mach-o** - executable code for use on MacOS systems * **Win64** - executable code for use on Windows systems ## Performance Currently both the [Go](bindings/go) and [Rust](bindings/rust) bindings provide benchmarks for a variety of signature related operations. ## License The blst library is licensed under the [Apache License Version 2.0](LICENSE) software license.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully