ring

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: LGPL-3.0 Imports: 11 Imported by: 5

README

ring-go

Implementation of linkable ring signatures using elliptic curve crypto in pure Go. It supports ring signatures over both ed25519 and secp256k1.

Requirements

go 1.22.2

Install

go get github.com/pokt-network/ring-go

References

This implementation is based off of Ring Confidential Transactions, in particular section 2, which defines MLSAG (Multilayered Linkable Spontaneous Anonymous Group signatures).

Usage

See examples/main.go.

package main

import (
    "fmt"

    ring "github.com/pokt-network/ring-go"
    "golang.org/x/crypto/sha3"
)

func signAndVerify(curve ring.Curve) {
    privKey := curve.NewRandomScalar()
    msgHash := sha3.Sum256([]byte("helloworld"))

    // size of the public key ring (anonymity set)
    const size = 16

    // our key's secret index within the set
    const idx = 7

    keyring, err := ring.NewKeyRing(curve, size, privKey, idx)
    if err != nil {
        panic(err)
    }

    sig, err := keyring.Sign(msgHash, privKey)
    if err != nil {
        panic(err)
    }

    ok := sig.Verify(msgHash)
    if !ok {
        fmt.Println("failed to verify :(")
        return
    }

    fmt.Println("verified signature!")
}

func main() {
    fmt.Println("using secp256k1...")
    signAndVerify(ring.Secp256k1())
    fmt.Println("using ed25519...")
    signAndVerify(ring.Ed25519())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ed25519

func Ed25519() types.Curve

Ed25519 returns a new ed25519 curve instance.

func Link(sigA, sigB *RingSig) bool

Link returns true if the two signatures were created by the same signer, false otherwise.

func Secp256k1

func Secp256k1() types.Curve

Secp256k1 returns a new secp256k1 curve instance

Types

type Curve

type Curve = types.Curve

Curve represents an elliptic curve that can be used for signing.

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring represents a group of public keys such that one of the group created a signature.

func NewFixedKeyRingFromPublicKeys

func NewFixedKeyRingFromPublicKeys(curve types.Curve, pubkeys []types.Point) (*Ring, error)

NewFixedKeyRingFromPublicKeys takes public keys and a curve to create a ring

func NewKeyRing

func NewKeyRing(curve types.Curve, size int, privKey types.Scalar, idx int) (*Ring, error)

NewKeyRing creates a ring with size specified by `size` and places the public key corresponding to `privKey` in index idx of the ring. It returns a ring of public keys of length `size`.

func NewKeyRingFromPublicKeys

func NewKeyRingFromPublicKeys(curve types.Curve, pubkeys []types.Point, privKey types.Scalar, idx int) (*Ring, error)

NewKeyRingFromPublicKeys takes public key ring and places the public key corresponding to `privKey` in index idx of the ring. It returns a ring of public keys of length `len(ring)+1`.

func (*Ring) Equals

func (ring *Ring) Equals(other *Ring) bool

Equals checks whether the supplied ring is equal to the current ring. The ring's public keys must be in the same order for the rings to be equal

func (*Ring) Sign

func (r *Ring) Sign(m [32]byte, privKey types.Scalar) (*RingSig, error)

Sign creates a ring signature on the given message using the public key ring and a private key of one of the members of the ring.

func (*Ring) Size

func (r *Ring) Size() int

Size returns the size of the ring, ie. the number of public keys in it.

type RingSig

type RingSig struct {
	// contains filtered or unexported fields
}

RingSig represents a ring signature.

func Sign

func Sign(m [32]byte, ring *Ring, privKey types.Scalar, ourIdx int) (*RingSig, error)

Sign creates a ring signature on the given message using the provided private key and ring of public keys.

func (*RingSig) Deserialize

func (sig *RingSig) Deserialize(curve Curve, in []byte) error

Deserialize converts the byteified signature into a *RingSig.

func (*RingSig) PublicKeys

func (r *RingSig) PublicKeys() []types.Point

PublicKeys returns a copy of the ring signature's public keys.

func (*RingSig) Ring

func (r *RingSig) Ring() *Ring

Ring returns the ring from the RingSig struct

func (*RingSig) Serialize

func (r *RingSig) Serialize() ([]byte, error)

Serialize converts the signature to a byte array.

func (*RingSig) Verify

func (sig *RingSig) Verify(m [32]byte) bool

Verify verifies the ring signature for the given message. It returns true if a valid signature, false otherwise.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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