1 unstable release

new 0.1.2 Sep 5, 2024
0.1.1 Aug 14, 2024
0.1.0 Jul 25, 2024

#1024 in Cryptography

Download history 78/week @ 2024-07-19 55/week @ 2024-07-26 4/week @ 2024-08-02 108/week @ 2024-08-09 19/week @ 2024-08-16

133 downloads per month

MIT AND Apache-2.0

58KB
700 lines

BN254 Hash-to-Curve

This repository provides implementation of the hash-to-curve for the BN254 elliptic curve, compatible with the gnark-crypto as well as constantine library.

Building and Testing

  • To build with gnark-crypto compatibility: cargo build --features "gnark_crypto_compatible"

  • To build withconstantine compatibility: cargo build --features "constantine_compatible"

  • To run tests of gnark-crypto compatibile hash-to-curve: cargo test --features "gnark_crypto_compatible"

  • To run tests of constantine compatibile hash-to-curve: cargo test --features "constantine_compatible"

Usage

Add this library under dependencies in the Cargo.toml of your project:

bn254_hash2curve = { git = "https://github.com/hashcloak/bn254-hash-to-curve.git", features = ["constantine_compatible"]}

OR

bn254_hash2curve ={ git = "https://github.com/hashcloak/bn254-hash-to-curve.git", features = ["gnark_crypto_compatible"]}

and then use it as shown below:

use bn254_hash2curve::hash2g1::HashToG1;
use bn254_hash2curve::hash2g2::HashToG2;

fn main() {

    let msg = b"abc";
    let dst_g1 = b"QUUX-V01-CS02-with-BN254G1_XMD:SHA-256_SVDW_RO_";
    let dst_g2 = b"QUUX-V01-CS02-with-BN254G2_XMD:SHA-256_SVDW_RO_";

    let hash_to_g1_result = HashToG1(msg, dst_g1);
    let hash_to_g2_result = HashToG2(msg, dst_g2);

    println!("hash_to_g1_result: {:?}", hash_to_g1_result);
    println!("hash_to_g2_result: {:?}", hash_to_g2_result);
}

Overview

Hashing to a curve is a crucial operation in cryptographic protocols, enabling the secure mapping of arbitrary data to elliptic curve points. It leverages efficient cryptographic hashing techniques to map arbitrary messages onto points on the elliptic curve

Features

  • Implements the hash-to-curve method for BN254 elliptic curve.
  • Compatible with the gnark-crypto and constantine library.
  • Ensures points are mapped to the r-torsion subgroup.
  • See tests for usage examples.

Dependencies

~7MB
~138K SLoC