mercurial

package module
v0.0.0-...-63dc692 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2024 License: MIT Imports: 2 Imported by: 1

README

go-dl-mercurial-commitments

A pure Go implementation of discrete log based mercurial commitments (using Ristretto prime-order group over Edwards25519). Based on the paper Mercurial Commitments with Applications to Zero-Knowledge Sets by Chase et al. [CHLMR05].

Installing and Usage

To install the package:

go get -u github.com/smarky7CD/go-dl-mercurial-commitments

The package can be imported and used as such:

import(
    "fmt"
    "github.com/smarky7cd/go-dl-mercurial-commitments"
)

func MCexample() {

    	var x,y string
	var pi0, pi1 ristretto.Scalar

    	// hard commitments

	x = "sam"
    	y = "jack"
	h := GeneratePublicParameters()
    	// generate hard commitment for "sam"
	c0, c1 := HardCommit(&h, []byte(x), &pi0, &pi1)

    	// valid tease and open

	// check hard tease
	tau := HardTease(&pi0)
	checktease := VerTease(&c0, &c1, []byte(x), &tau)
    	fmt.Println("Hard tease check is: ", checktease) //true

	// check open
	checkopen := VerOpen(&h, &c0, &c1, []byte("sam"), &pi0, &pi1)
    	fmt.Println("Open check is: ", checkopen) //true

    	// invalid tease and open

    	// check hard tease
	tau = HardTease(&pi0)
	checkTease = VerTease(&c0, &c1, []byte("jack"), &tau)
	fmt.Println("Hard tease check is: ", checktease) //false

	// check open
	checkOpen = VerOpen(&h, &c0, &c1, []byte("jack"), &pi0, &pi1)
	fmt.Println("Open check is: ", checkopen) //true //false

    	// soft commitments
    	// generate soft commitment for "·"
	c0, c1 = SoftCommit(&pi0, &pi1)

	// check soft tease to "jack"
	tau = SoftTease([]byte(y), &pi0, &pi1)
	checktease = VerTease(&c0, &c1, []byte("jack"), &tau)
    	fmt.Println("Soft tease check is: ", checktease) // true
    	// check soft tease for "sam"
	tau = SoftTease([]byte(x), &pi0, &pi1)
	checktease = VerTease(&c0, &c1, []byte("sam"), &tau)
    	fmt.Println("Soft tease check is: ", checktease) // true
}


Tests

We provide a number correctness tests for a valid hard commitment, an invalid hard commitment, and a soft commitment.

They can be ran by using:

go test -v

References

  • [CHLMR05]: Chase, Melissa, et al. "Mercurial commitments with applications to zero-knowledge sets." Advances in Cryptology–EUROCRYPT 2005: 24th Annual International Conference on the Theory and Applications of Cryptographic Techniques, Aarhus, Denmark, May 22-26, 2005. Proceedings 24. Springer Berlin Heidelberg, 2005.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePublicParameters

func GeneratePublicParameters() ristretto.Point

g is Edwards25519 basepoint h (returned here) is a randomly selected point

func HardCommit

Computes a hard commitment (c0,c1) to x given random scalars(r0,r1) and h.

func HardTease

func HardTease(r0 *ristretto.Scalar) ristretto.Scalar

Returns r0 as hard tease of a hard commitment.

func Open

Opens a hard commitment (returns r0,r1).

func SoftCommit

Computes soft commitment (c0,c1) given random scalars(r0,r1).

func SoftTease

func SoftTease(x []byte, r0 *ristretto.Scalar, r1 *ristretto.Scalar) ristretto.Scalar

Returns t as soft tease to value x of a soft commitment.

func VerOpen

func VerOpen(h *ristretto.Point, c0 *ristretto.Point, c1 *ristretto.Point, x []byte, pi0 *ristretto.Scalar, pi1 *ristretto.Scalar) bool

Verifies the opening of a hard commitment for a value x.

func VerTease

func VerTease(c0 *ristretto.Point, c1 *ristretto.Point, x []byte, tau *ristretto.Scalar) bool

Verifies a t value . Returns true if valid, false otherwise.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL