#hash #library #commitment-schemes

hashcom-rs

A fast, minimal but yet extensible framework for building and using hash commitment schemes

2 unstable releases

0.2.0 Dec 17, 2022
0.1.0 Dec 17, 2022

#993 in Cryptography

23 downloads per month

Custom license

1.5MB
82 lines

hashcom-rs

A DALL-E representation of a 
photo of a computer circuit in cyberpunk style with a dark theme

⚡️ A fast, minimal but yet extensible framework for building and using hash commitment schemes in Rust ⚡️

Cover by DALL-E.

Introduction

Commitment schemes are very powerful cryptographic primitives used in many existing solutions.

I was inspired by the go-ibft to create a framework to easily integrate and customize a hash commitment scheme in a rust application.

This package exposes both a trait for you to build your scheme given a specific hash function, or use an existing one.

Architecture

The hashcom-rs library exposes a HashCommitmentScheme trait that can be implemented with you own hash function. You'll just have to implement the commit and verify methods.

A SHA256 implementation is already provided. Below is an example of how it can be used (here, there's only one party who acts as both the prover and the verifier):

/// Here, one party acts as both the prover and the verifier,
/// assuming that the verifier is not malicious.
fn it_verifies_valid_commitment() {
    let s: [u8; 4] = [52, 50, 52, 50]; // 4242 in string format.
    let r: [u8; 4] = [50, 52, 50, 52]; // 2424 in string format.

    // Commit phase.
    let party = SHA256Commitment::new(&s, &r);
    let commit = party.commit();

    // Verification phase.
    let verification = party.verify(&commit.unwrap(), &s, &r);

    assert_eq!(verification.is_ok(), true);
    assert_eq!(verification.unwrap(), true)
}

Authors

Made with ❤️ by 🤖 0xpanoramix 🤖

Dependencies